Commit e4b52a2a authored by Sven Franck's avatar Sven Franck

started integrating state

parent 0a7d7a24
......@@ -807,171 +807,6 @@
return (reply);
},
/**
* @method subscriptions
* @param {object} reply Object received from previous chain element
* @param {object} response Object object passed on to next element
**/
"servers": function (reply) {
var config, property, query, href, i, reply, pass = reply.pass;
if (storage) {
config = {
"url": storage.items.dict.url,
"type": "GET",
"xhrFields": {
"withCredentials": true
}
};
// access storage
return jIO.util.ajax(config)
.then(function(response) {
return jIO.util.ajax({
"url": util.parse(response.target.responseText)._links.me.href,
"xhrFields": {
"withCredentials": true
}
});
}).then(function (answer) {
reply = util.parse(answer.target.responseText)._links.slapos_jump;
for (i = 0; i < reply.length; i += 1) {
if (reply[i].name === "current_computer") {
query = reply[i]._query;
}
}
if (query === undefined) {
query = reply.href;
}
if (pass.config.initial_query === undefined) {
pass.config.initial_query = {};
}
pass.config.initial_query.query = query;
// pass hacked query back into chain
if (reply.response) {
return {
"response": util.parse(reply.response),
"pass": pass
};
}
return {
"pass": pass
}
}).fail(util.error);
}
return (reply);
},
/**
* @method subscriptions
* @param {object} reply Object received from previous chain element
* @param {object} response Object object passed on to next element
**/
"invoices": function (reply) {
var config, property, query, href, i, reply, pass = reply.pass;
if (storage) {
config = {
"url": storage.items.dict.url,
"type": "GET",
"xhrFields": {
"withCredentials": true
}
};
// access storage
return jIO.util.ajax(config)
.then(function(response) {
return jIO.util.ajax({
"url": util.parse(response.target.responseText)._links.me.href,
"xhrFields": {
"withCredentials": true
}
});
}).then(function (answer) {
reply = util.parse(answer.target.responseText)._links.slapos_jump;
for (i = 0; i < reply.length; i += 1) {
if (reply[i].name === "current_invoice") {
query = reply[i]._query;
}
}
if (query === undefined) {
query = reply.href;
}
if (pass.config.initial_query === undefined) {
pass.config.initial_query = {};
}
pass.config.initial_query.query = query;
// pass hacked query back into chain
if (reply.response) {
return {
"response": util.parse(reply.response),
"pass": pass
};
}
return {
"pass": pass
}
}).fail(util.error);
}
return (reply);
},
/**
* @method subscriptions
* @param {object} reply Object received from previous chain element
* @param {object} response Object object passed on to next element
**/
"networks": function (reply) {
var config, property, query, href, i, reply, pass = reply.pass;
if (storage) {
config = {
"url": storage.items.dict.url,
"type": "GET",
"xhrFields": {
"withCredentials": true
}
};
// access storage
return jIO.util.ajax(config)
.then(function(response) {
return jIO.util.ajax({
"url": util.parse(response.target.responseText)._links.me.href,
"xhrFields": {
"withCredentials": true
}
});
}).then(function (answer) {
reply = util.parse(answer.target.responseText)._links.slapos_jump;
for (i = 0; i < reply.length; i += 1) {
if (reply[i].name === "current_network") {
query = reply[i]._query;
}
}
if (query === undefined) {
query = reply.href;
}
if (pass.config.initial_query === undefined) {
pass.config.initial_query = {};
}
pass.config.initial_query.query = query;
// pass hacked query back into chain
if (reply.response) {
return {
"response": util.parse(reply.response),
"pass": pass
};
}
return {
"pass": pass
}
}).fail(util.error);
}
return (reply);
},
/**
* @method subscriptions
* @param {object} reply Object received from previous chain element
......@@ -1026,62 +861,6 @@
}).fail(util.error);
}
return (reply);
},
/**
* @method person
* @param {object} reply Object received from previous chain element
* @param {object} response Object object passed on to next element
**/
"person": function (reply) {
var config, property, props, pass = reply.pass;
if (storage) {
config = {
"url": storage.items.dict.url,
"type": "GET",
"xhrFields": {
"withCredentials": true
}
};
// access storage
return jIO.util.ajax(config)
.then(function(response) {
return jIO.util.ajax({
"url": util.parse(response.target.responseText)._links.me.href,
"xhrFields": {
"withCredentials": true
}
})
.then(function (answer) {
if (pass.config.initial_query === undefined) {
pass.config.initial_query = {};
}
for (property in pass.config.initial_query) {
if (pass.config.initial_query.hasOwnProperty(property)) {
delete pass.config.initial_query[property];
}
}
pass.config.initial_query.query = {
"_id": util.parse(answer.target.responseText)._relative_url
};
// pass hacked query back into chain
if (reply.response) {
return {
"response": util.parse(reply.response),
"pass": pass
};
}
return {
"pass": pass
}
}).fail(util.error);
}).fail(util.error);
}
return (reply);
}
};
......@@ -2427,10 +2206,10 @@
* @param {object} content_dict JSON configuration for global setup
**/
"setGlobalConfiguration": function (content_dict) {
var i, j, translator, single_path, supported, target, language,
var i, j, k, translator, single_path, supported, target, language,
container, foreign, promises, path_flag, status_flag, set_state,
multi_language_flag, force_browser_language, logger, element,
set_login, skip_restore;
set_login, skip_restore, state, support_state;
promises = [];
path_flag = content_dict.property_dict.path_dict;
......@@ -2440,6 +2219,30 @@
.i18n_force_browser_language;
logger = content_dict.property_dict.login_dict;
// this will manage offline and login states!
state = content_dict.property_dict.state_dict;
// initialize state machine
if (state) {
switch (state.type) {
case "StateMachine":
support_state = true;
if (state.modernizr) {
support_state = util.testBrowserSupport(state.modernizr);
}
if (!window[state.type]) {
util.error("globalConfig: Missing StateMachine");
}
if (support_state) {
for (k = 0; k < state.machine_list.length; k += 1) {
app.default_dict.state_dict[state.machine_list[k].machine_name] =
window[state.type].create(state.machine_list[k].property_dict);
}
}
break;
}
}
// make sure login is only setup if needed
if (logger !== undefined) {
app.default_dict.state_dict.login = true;
......@@ -2645,14 +2448,17 @@
* @param {object} content_dict JSON configuration for specific storage
**/
"makeStorage": function (content_dict) {
if (content_dict.property_dict.definition) {
storage[content_dict.property_dict.definition.application_name] =
jIO.createJIO(content_dict.property_dict.definition);
storage[content_dict.property_dict.definition.application_name].dict =
content_dict.property_dict.definition;
} else {
util.error("makeStorage: Missing storage definition");
var quirk_dict, definition, name;
quirk_dict = content_dict.property_dict;
definition = quirk_dict.definition;
name = definition.application_name || quirk_dict.set_name;
if (!name || !definition) {
util.error("makeStorage: missing storage name/definition");
}
storage[name] = jIO.createJIO(definition);
storage[name].dict = definition;
return RSVP.all([]);
},
......@@ -5744,6 +5550,46 @@
// generate storage object
storage = {};
/**
* First pass at sync
* @method sync
**/
storage.sync = function () {
/*
0. state machine?
> detect offline/online
> detect sync/need_sync
> detect login/logoff (later)
1. when to sync
> whenever we have connection and async is set.
> on application init, async is set
> when offline we always set, tool (because remote and local can change)
2. how to sync
> loop over remote, but how
> hardcode or robot?
> also have a manual sync button and a settings button
> besides records, all other JSON config also needs to be fetched
for offline. This will be in settings.
> sync means POST (+ error handling for storage which already has the file)
> question is whether it's possible to fetch all records of a portal_type
> this must be an allDocs (include_docs) with no-limit
> once all files are fetched...
> loop over
> not exists in local, POST
> exists in local, calculate hash and compare
> different hash needs timestamp to decide what to do...
> where do have information when the file was created... as we have no revisions...
> this is retarded...
> store initial hash of every file so it can be compared against?
>
*/
};
/**
* Generate an array of fields from a dict
* @method makeSelectList
......@@ -7329,23 +7175,23 @@
app.mapToStorage = function (reply) {
var pass = reply.pass, answer;
if (reply.response) {
// mapping required for this portal_type
if (pass.config && pass.config.portal_type_mapper) {
return map.handlers[pass.config.portal_type_mapper](reply);
}
// standard procedure
answer = util.parse(answer);
return {
"response": answer,
"pass": pass
};
}
// mapping
if (pass.config && pass.config.portal_type_mapper) {
return map.handlers[pass.config.portal_type_mapper](reply);
}
// if (reply.response) {
// // mapping required for this portal_type
// if (pass.config && pass.config.portal_type_mapper) {
// return map.handlers[pass.config.portal_type_mapper](reply);
// }
// // standard procedure
// answer = util.parse(answer);
// return {
// "response": answer,
// "pass": pass
// };
//
// }
// // mapping
// if (pass.config && pass.config.portal_type_mapper) {
// return map.handlers[pass.config.portal_type_mapper](reply);
// }
// standard
return {
"pass": pass
......@@ -7919,6 +7765,7 @@
if (select_list && parcel.query.include_docs === undefined) {
convert = "values";
}
console.log(storage)
return storage[parcel.storage][method || "allDocs"](parcel.query, hacked_view)
.then(function (response) {
// TODO: best way?
......@@ -8721,6 +8568,7 @@
}
};
/* ====================================================================== */
/* ENTRY POINT */
/* ====================================================================== */
......
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