Commit 96d216bd authored by Sven Franck's avatar Sven Franck

cleanup old files

parent 761440c1
This diff is collapsed.
This diff is collapsed.
/*
* Copyright 2013, Nexedi SA
* Released under the LGPL license.
* http://www.gnu.org/licenses/lgpl.html
*/
// JIO Hateoas Storage Description :
// {
// type: "hateoas"
// url: {string}
// }
/*jslint nomen: true, unparam: true */
/*global jIO, complex_queries, console, UriTemplate, FormData, RSVP */
(function (jIO, complex_queries) {
"use strict";
function HateoasStorage(spec) {
if (typeof spec.url !== 'string' && !spec.url) {
throw new TypeError("Hateoas 'url' must be a string " +
"which contains more than one character.");
}
this._url = spec.url;
}
HateoasStorage.prototype._getSiteDocument = function () {
return jIO.util.ajax({
"type": "GET",
"url": this._url,
"xhrFields": {
withCredentials: true
}
}).then(function (response) {
return JSON.parse(response.target.responseText);
});
};
HateoasStorage.prototype._get = function (param, options) {
return this._getSiteDocument()
.then(function (site_hal) {
return jIO.util.ajax({
"type": "GET",
"url": UriTemplate.parse(site_hal._links.traverse.href)
.expand({
relative_url: param._id,
view: options._view
}),
"xhrFields": {
withCredentials: true
}
});
})
.then(function (response) {
var result = JSON.parse(response.target.responseText);
result._id = param._id;
return result;
});
};
HateoasStorage.prototype.get = function (command, param, options) {
this._get(param, options)
.then(function (response) {
command.success({"data": response});
})
.fail(function (error) {
console.error(error);
// XXX How to propagate the error
command.error(
"not_found",
"missing",
"Cannot find document"
);
});
};
HateoasStorage.prototype.post = function (command, metadata, options) {
return this._getSiteDocument()
// HACK: get me... default _add, otherwise passed through options!
.then(function (site_hal) {
return jIO.util.ajax({
"url": site_hal._links.me.href,
"xhrFields": {
"withCredentials": true
}
})z
})
.then(function (opts) {
var doc_hal, custom_action, post_action, data, key;
doc_hal = JSON.parse(opts.target.responseText);
custom_action = doc_hal._actions[options.call];
post_action = custom_action || site_hal._actions.add;
data = new FormData();
for (key in metadata) {
if (metadata.hasOwnProperty(key)) {
// XXX Not a form dialog in this case but distant script
data.append(key, metadata[key]);
}
}
return jIO.util.ajax({
"type": post_action.method,
"url": post_action.href,
"data": data,
"xhrFields": {
"withCredentials": true
}
});
})
.then(function (doc) {
// XXX Really depend on server response...
var new_document_url = doc.target.getResponseHeader("Location");
return jIO.util.ajax({
"type": "GET",
"url": new_document_url,
"xhrFields": {
"withCredentials": true
}
});
}).then(function (response) {
var doc_hal = JSON.parse(response.target.responseText);
if (doc_hal !== null) {
command.success({"id": doc_hal._relative_url});
} else {
command.error(
"not_found",
"missing",
"Cannot find document"
);
}
}, function (error) {
console.error(error);
command.error(
500,
"Too bad...",
"Unable to post doc"
);
});
};
HateoasStorage.prototype.put = function (command, metadata, options) {
return this._get(metadata, options)
.then(function (result) {
var put_action = result._embedded._view._actions.put,
renderer_form = result._embedded._view,
data = new FormData(),
key;
data.append(renderer_form.form_id.key,
renderer_form.form_id['default']);
for (key in metadata) {
if (metadata.hasOwnProperty(key)) {
if (key !== "_id") {
// Hardcoded my_ ERP5 behaviour
if (renderer_form.hasOwnProperty("my_" + key)) {
data.append(renderer_form["my_" + key].key, metadata[key]);
} else {
throw new Error("Can not save property " + key);
}
}
}
}
return jIO.util.ajax({
"type": put_action.method,
"url": put_action.href,
"data": data,
"xhrFields": {
"withCredentials": true
}
});
})
.then(function (result) {
command.success(result);
})
.fail(function (error) {
console.error(error);
command.error(
"error",
"did not work as expected",
"Unable to call allDocs"
);
});
};
HateoasStorage.prototype.allDocs = function (command, param, options) {
return this._getSiteDocument()
.then(function (site_hal) {
return jIO.util.ajax({
"type": "GET",
"url": UriTemplate.parse(site_hal._links.raw_search.href)
.expand({
query: options.query,
// XXX Force erp5 to return embedded document
select_list: options.select_list || ["title", "reference"],
limit: options.limit
}),
"xhrFields": {
withCredentials: true
}
});
})
.then(function (response) {
return JSON.parse(response.target.responseText);
})
.then(function (catalog_json) {
var data = catalog_json._embedded.contents,
count = data.length,
i,
item,
result = [],
promise_list = [result];
for (i = 0; i < count; i += 1) {
item = data[i];
item._id = item._relative_url;
result.push({
id: item._relative_url,
key: item._relative_url,
doc: {},
value: item
});
// if (options.include_docs) {
// promise_list.push(RSVP.Queue().push(function () {
// return this._get({_id: item.name}, {_view: "View"});
// }).push
// }
}
return RSVP.all(promise_list);
})
.then(function (promise_list) {
var result = promise_list[0],
count = result.length;
command.success({"data": {"rows": result, "total_rows": count}});
})
.fail(function (error) {
console.error(error);
command.error(
"error",
"did not work as expected",
"Unable to call allDocs"
);
});
};
jIO.addStorage("hateoas", HateoasStorage);
}(jIO, complex_queries));
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*! normalize.css v3.0.0 | MIT License | git.io/normalize */
/**
* 1. Set default font family to sans-serif.
* 2. Prevent iOS text size adjust after orientation change, without disabling
* user zoom.
*/
html {
font-family: sans-serif; /* 1 */
-ms-text-size-adjust: 100%; /* 2 */
-webkit-text-size-adjust: 100%; /* 2 */
}
/**
* Remove default margin.
*/
body {
margin: 0;
}
/* HTML5 display definitions
========================================================================== */
/**
* Correct `block` display not defined in IE 8/9.
*/
article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
main,
nav,
section,
summary {
display: block;
}
/**
* 1. Correct `inline-block` display not defined in IE 8/9.
* 2. Normalize vertical alignment of `progress` in Chrome, Firefox, and Opera.
*/
audio,
canvas,
progress,
video {
display: inline-block; /* 1 */
vertical-align: baseline; /* 2 */
}
/**
* Prevent modern browsers from displaying `audio` without controls.
* Remove excess height in iOS 5 devices.
*/
audio:not([controls]) {
display: none;
height: 0;
}
/**
* Address `[hidden]` styling not present in IE 8/9.
* Hide the `template` element in IE, Safari, and Firefox < 22.
*/
[hidden],
template {
display: none;
}
/* Links
========================================================================== */
/**
* Remove the gray background color from active links in IE 10.
*/
a {
background: transparent;
}
/**
* Improve readability when focused and also mouse hovered in all browsers.
*/
a:active,
a:hover {
outline: 0;
}
/* Text-level semantics
========================================================================== */
/**
* Address styling not present in IE 8/9, Safari 5, and Chrome.
*/
abbr[title] {
border-bottom: 1px dotted;
}
/**
* Address style set to `bolder` in Firefox 4+, Safari 5, and Chrome.
*/
b,
strong {
font-weight: bold;
}
/**
* Address styling not present in Safari 5 and Chrome.
*/
dfn {
font-style: italic;
}
/**
* Address variable `h1` font-size and margin within `section` and `article`
* contexts in Firefox 4+, Safari 5, and Chrome.
*/
h1 {
font-size: 2em;
margin: 0.67em 0;
}
/**
* Address styling not present in IE 8/9.
*/
mark {
background: #ff0;
color: #000;
}
/**
* Address inconsistent and variable font size in all browsers.
*/
small {
font-size: 80%;
}
/**
* Prevent `sub` and `sup` affecting `line-height` in all browsers.
*/
sub,
sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline;
}
sup {
top: -0.5em;
}
sub {
bottom: -0.25em;
}
/* Embedded content
========================================================================== */
/**
* Remove border when inside `a` element in IE 8/9.
*/
img {
border: 0;
}
/**
* Correct overflow displayed oddly in IE 9.
*/
svg:not(:root) {
overflow: hidden;
}
/* Grouping content
========================================================================== */
/**
* Address margin not present in IE 8/9 and Safari 5.
*/
figure {
margin: 1em 40px;
}
/**
* Address differences between Firefox and other browsers.
*/
hr {
-moz-box-sizing: content-box;
box-sizing: content-box;
height: 0;
}
/**
* Contain overflow in all browsers.
*/
pre {
overflow: auto;
}
/**
* Address odd `em`-unit font size rendering in all browsers.
*/
code,
kbd,
pre,
samp {
font-family: monospace, monospace;
font-size: 1em;
}
/* Forms
========================================================================== */
/**
* Known limitation: by default, Chrome and Safari on OS X allow very limited
* styling of `select`, unless a `border` property is set.
*/
/**
* 1. Correct color not being inherited.
* Known issue: affects color of disabled elements.
* 2. Correct font properties not being inherited.
* 3. Address margins set differently in Firefox 4+, Safari 5, and Chrome.
*/
button,
input,
optgroup,
select,
textarea {
color: inherit; /* 1 */
font: inherit; /* 2 */
margin: 0; /* 3 */
}
/**
* Address `overflow` set to `hidden` in IE 8/9/10.
*/
button {
overflow: visible;
}
/**
* Address inconsistent `text-transform` inheritance for `button` and `select`.
* All other form control elements do not inherit `text-transform` values.
* Correct `button` style inheritance in Firefox, IE 8+, and Opera
* Correct `select` style inheritance in Firefox.
*/
button,
select {
text-transform: none;
}
/**
* 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio`
* and `video` controls.
* 2. Correct inability to style clickable `input` types in iOS.
* 3. Improve usability and consistency of cursor style between image-type
* `input` and others.
*/
button,
html input[type="button"], /* 1 */
input[type="reset"],
input[type="submit"] {
-webkit-appearance: button; /* 2 */
cursor: pointer; /* 3 */
}
/**
* Re-set default cursor for disabled elements.
*/
button[disabled],
html input[disabled] {
cursor: default;
}
/**
* Remove inner padding and border in Firefox 4+.
*/
button::-moz-focus-inner,
input::-moz-focus-inner {
border: 0;
padding: 0;
}
/**
* Address Firefox 4+ setting `line-height` on `input` using `!important` in
* the UA stylesheet.
*/
input {
line-height: normal;
}
/**
* It's recommended that you don't attempt to style these elements.
* Firefox's implementation doesn't respect box-sizing, padding, or width.
*
* 1. Address box sizing set to `content-box` in IE 8/9/10.
* 2. Remove excess padding in IE 8/9/10.
*/
input[type="checkbox"],
input[type="radio"] {
box-sizing: border-box; /* 1 */
padding: 0; /* 2 */
}
/**
* Fix the cursor style for Chrome's increment/decrement buttons. For certain
* `font-size` values of the `input`, it causes the cursor style of the
* decrement button to change from `default` to `text`.
*/
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
height: auto;
}
/**
* 1. Address `appearance` set to `searchfield` in Safari 5 and Chrome.
* 2. Address `box-sizing` set to `border-box` in Safari 5 and Chrome
* (include `-moz` to future-proof).
*/
input[type="search"] {
-webkit-appearance: textfield; /* 1 */
-moz-box-sizing: content-box;
-webkit-box-sizing: content-box; /* 2 */
box-sizing: content-box;
}
/**
* Remove inner padding and search cancel button in Safari and Chrome on OS X.
* Safari (but not Chrome) clips the cancel button when the search input has
* padding (and `textfield` appearance).
*/
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-decoration {
-webkit-appearance: none;
}
/**
* Define consistent border, margin, and padding.
*/
fieldset {
border: 1px solid #c0c0c0;
margin: 0 2px;
padding: 0.35em 0.625em 0.75em;
}
/**
* 1. Correct `color` not being inherited in IE 8/9.
* 2. Remove padding so people aren't caught out if they zero out fieldsets.
*/
legend {
border: 0; /* 1 */
padding: 0; /* 2 */
}
/**
* Remove default vertical scrollbar in IE 8/9.
*/
textarea {
overflow: auto;
}
/**
* Don't inherit the `font-weight` (applied by a rule above).
* NOTE: the default cannot safely be changed in Chrome and Safari on OS X.
*/
optgroup {
font-weight: bold;
}
/* Tables
========================================================================== */
/**
* Remove most spacing between table cells.
*/
table {
border-collapse: collapse;
border-spacing: 0;
}
td,
th {
padding: 0;
}
This diff is collapsed.
/*
Javascript State Machine Library - https://github.com/jakesgordon/javascript-state-machine
Copyright (c) 2012, 2013 Jake Gordon and contributors
Released under the MIT license - https://github.com/jakesgordon/javascript-state-machine/blob/master/LICENSE
*/
(function (window) {
var StateMachine = {
//---------------------------------------------------------------------------
VERSION: "2.2.0",
//---------------------------------------------------------------------------
Result: {
SUCCEEDED: 1, // the event transitioned successfully from one state to another
NOTRANSITION: 2, // the event was successfull but no state transition was necessary
CANCELLED: 3, // the event was cancelled by the caller in a beforeEvent callback
PENDING: 4 // the event is asynchronous and the caller is in control of when the transition occurs
},
Error: {
INVALID_TRANSITION: 100, // caller tried to fire an event that was innapropriate in the current state
PENDING_TRANSITION: 200, // caller tried to fire an event while an async transition was still pending
INVALID_CALLBACK: 300 // caller provided callback function threw an exception
},
WILDCARD: '*',
ASYNC: 'async',
//---------------------------------------------------------------------------
create: function(cfg, target) {
var initial = (typeof cfg.initial == 'string') ? { state: cfg.initial } : cfg.initial; // allow for a simple string, or an object with { state: 'foo', event: 'setup', defer: true|false }
var terminal = cfg.terminal || cfg['final'];
var fsm = target || cfg.target || {};
var events = cfg.events || [];
var callbacks = cfg.callbacks || {};
var map = {};
var add = function(e) {
var from = (e.from instanceof Array) ? e.from : (e.from ? [e.from] : [StateMachine.WILDCARD]); // allow 'wildcard' transition if 'from' is not specified
map[e.name] = map[e.name] || {};
for (var n = 0 ; n < from.length ; n++)
map[e.name][from[n]] = e.to || from[n]; // allow no-op transition if 'to' is not specified
};
if (initial) {
initial.event = initial.event || 'startup';
add({ name: initial.event, from: 'none', to: initial.state });
}
for(var n = 0 ; n < events.length ; n++)
add(events[n]);
for(var name in map) {
if (map.hasOwnProperty(name))
fsm[name] = StateMachine.buildEvent(name, map[name]);
}
for(var name in callbacks) {
if (callbacks.hasOwnProperty(name))
fsm[name] = callbacks[name]
}
fsm.current = 'none';
fsm.is = function(state) { return (state instanceof Array) ? (state.indexOf(this.current) >= 0) : (this.current === state); };
fsm.can = function(event) { return !this.transition && (map[event].hasOwnProperty(this.current) || map[event].hasOwnProperty(StateMachine.WILDCARD)); }
fsm.cannot = function(event) { return !this.can(event); };
fsm.error = cfg.error || function(name, from, to, args, error, msg, e) { throw e || msg; }; // default behavior when something unexpected happens is to throw an exception, but caller can override this behavior if desired (see github issue #3 and #17)
fsm.isFinished = function() { return this.is(terminal); };
if (initial && !initial.defer)
fsm[initial.event]();
return fsm;
},
//===========================================================================
doCallback: function(fsm, func, name, from, to, args) {
if (func) {
try {
return func.apply(fsm, [name, from, to].concat(args));
}
catch(e) {
return fsm.error(name, from, to, args, StateMachine.Error.INVALID_CALLBACK, "an exception occurred in a caller-provided callback function", e);
}
}
},
beforeAnyEvent: function(fsm, name, from, to, args) { return StateMachine.doCallback(fsm, fsm['onbeforeevent'], name, from, to, args); },
afterAnyEvent: function(fsm, name, from, to, args) { return StateMachine.doCallback(fsm, fsm['onafterevent'] || fsm['onevent'], name, from, to, args); },
leaveAnyState: function(fsm, name, from, to, args) { return StateMachine.doCallback(fsm, fsm['onleavestate'], name, from, to, args); },
enterAnyState: function(fsm, name, from, to, args) { return StateMachine.doCallback(fsm, fsm['onenterstate'] || fsm['onstate'], name, from, to, args); },
changeState: function(fsm, name, from, to, args) { return StateMachine.doCallback(fsm, fsm['onchangestate'], name, from, to, args); },
beforeThisEvent: function(fsm, name, from, to, args) { return StateMachine.doCallback(fsm, fsm['onbefore' + name], name, from, to, args); },
afterThisEvent: function(fsm, name, from, to, args) { return StateMachine.doCallback(fsm, fsm['onafter' + name] || fsm['on' + name], name, from, to, args); },
leaveThisState: function(fsm, name, from, to, args) { return StateMachine.doCallback(fsm, fsm['onleave' + from], name, from, to, args); },
enterThisState: function(fsm, name, from, to, args) { return StateMachine.doCallback(fsm, fsm['onenter' + to] || fsm['on' + to], name, from, to, args); },
beforeEvent: function(fsm, name, from, to, args) {
if ((false === StateMachine.beforeThisEvent(fsm, name, from, to, args)) ||
(false === StateMachine.beforeAnyEvent( fsm, name, from, to, args)))
return false;
},
afterEvent: function(fsm, name, from, to, args) {
StateMachine.afterThisEvent(fsm, name, from, to, args);
StateMachine.afterAnyEvent( fsm, name, from, to, args);
},
leaveState: function(fsm, name, from, to, args) {
var specific = StateMachine.leaveThisState(fsm, name, from, to, args),
general = StateMachine.leaveAnyState( fsm, name, from, to, args);
if ((false === specific) || (false === general))
return false;
else if ((StateMachine.ASYNC === specific) || (StateMachine.ASYNC === general))
return StateMachine.ASYNC;
},
enterState: function(fsm, name, from, to, args) {
StateMachine.enterThisState(fsm, name, from, to, args);
StateMachine.enterAnyState( fsm, name, from, to, args);
},
//===========================================================================
buildEvent: function(name, map) {
return function() {
var from = this.current;
var to = map[from] || map[StateMachine.WILDCARD] || from;
var args = Array.prototype.slice.call(arguments); // turn arguments into pure array
if (this.transition)
return this.error(name, from, to, args, StateMachine.Error.PENDING_TRANSITION, "event " + name + " inappropriate because previous transition did not complete");
if (this.cannot(name))
return this.error(name, from, to, args, StateMachine.Error.INVALID_TRANSITION, "event " + name + " inappropriate in current state " + this.current);
if (false === StateMachine.beforeEvent(this, name, from, to, args))
return StateMachine.Result.CANCELLED;
if (from === to) {
StateMachine.afterEvent(this, name, from, to, args);
return StateMachine.Result.NOTRANSITION;
}
// prepare a transition method for use EITHER lower down, or by caller if they want an async transition (indicated by an ASYNC return value from leaveState)
var fsm = this;
this.transition = function() {
fsm.transition = null; // this method should only ever be called once
fsm.current = to;
StateMachine.enterState( fsm, name, from, to, args);
StateMachine.changeState(fsm, name, from, to, args);
StateMachine.afterEvent( fsm, name, from, to, args);
return StateMachine.Result.SUCCEEDED;
};
this.transition.cancel = function() { // provide a way for caller to cancel async transition if desired (issue #22)
fsm.transition = null;
StateMachine.afterEvent(fsm, name, from, to, args);
}
var leave = StateMachine.leaveState(this, name, from, to, args);
if (false === leave) {
this.transition = null;
return StateMachine.Result.CANCELLED;
}
else if (StateMachine.ASYNC === leave) {
return StateMachine.Result.PENDING;
}
else {
if (this.transition) // need to check in case user manually called transition() but forgot to return StateMachine.ASYNC
return this.transition();
}
};
}
}; // StateMachine
//===========================================================================
if ("function" === typeof define) {
define(function(require) { return StateMachine; });
}
else {
window.StateMachine = StateMachine;
}
}(this));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment