Commit f6df80aa authored by Sven Franck's avatar Sven Franck

added gadget refresh on state change, put on existing docs vs post

parent f6cc9419
...@@ -25,8 +25,7 @@ ...@@ -25,8 +25,7 @@
"google": "https://accounts.google.com/Logout?continue=REDIRECT_URL", "google": "https://accounts.google.com/Logout?continue=REDIRECT_URL",
"facebook": "https://www.facebook.com/logout.php?next=REDIRECT_URL&access_token=ACCESS_TOKEN" "facebook": "https://www.facebook.com/logout.php?next=REDIRECT_URL&access_token=ACCESS_TOKEN"
}, },
"modernizr": ["sessionStorage", "localStorage"], "modernizr": ["localStorage"],
"preserve_session": "sessionStorage",
"redirect": {"redirect_uri":"http://localhost/sven/slapos-ui/index.html"} "redirect": {"redirect_uri":"http://localhost/sven/slapos-ui/index.html"}
} }
}, },
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
if (i18n) { if (i18n) {
return i18n.t(path); return i18n.t(path);
} else { } else {
util.errorHandler({"error":"Translate NodeList - i18n not defined"}); util.error({"error":"Translate NodeList - i18n not defined"});
return "" return ""
} }
}, },
...@@ -116,7 +116,7 @@ ...@@ -116,7 +116,7 @@
} }
} }
} else { } else {
util.errorHandler({"error":"Translate NodeList - i18n not defined"}); util.error({"error":"Translate NodeList - i18n not defined"});
} }
}, },
...@@ -179,7 +179,7 @@ ...@@ -179,7 +179,7 @@
* @param {object} obj Action Object * @param {object} obj Action Object
**/ **/
"logout_user": function (obj) { "logout_user": function (obj) {
var provider, temp_store = app.default_dict.state_dict.preserve_in; var provider;
hello(obj.id).logout(function(x){ hello(obj.id).logout(function(x){
return; return;
...@@ -194,21 +194,6 @@ ...@@ -194,21 +194,6 @@
} }
} }
// update preserve
if (temp_store) {
switch (temp_store) {
case "sessionStorage":
window.sessionStorage.removeItem("state");
break;
case "localStorage":
window.localStorage.removeItem("state");
break;
case "cookie":
util.cookieHandler.removeItem("state");
break;
};
}
// TODO: Try to log out correctly // TODO: Try to log out correctly
// http://stackoverflow.com/questions/17050575/logout-link-with-return-url-oauth/17127388#17127388 // http://stackoverflow.com/questions/17050575/logout-link-with-return-url-oauth/17127388#17127388
// http://stackoverflow.com/questions/16946798/logout-from-external-login-service-gmail-facebook-using-oauth // http://stackoverflow.com/questions/16946798/logout-from-external-login-service-gmail-facebook-using-oauth
...@@ -225,18 +210,18 @@ ...@@ -225,18 +210,18 @@
* @method login_user * @method login_user
* @param {object} obj Action Object * @param {object} obj Action Object
**/ **/
// TODO: failed login?
"login_user": function (obj) { "login_user": function (obj) {
var signature, match_string, reply, element; var signature, match_string, reply, element, active, hashed_list;
// create signature and ticket // create signature and ticket
element = obj.element; element = obj.element;
signature = util.generateRandomIdentifier(36); signature = util.generateRandomIdentifier(36);
flux[signature] = util.generateUuid(); flux[signature] = util.generateUuid();
// pass to 3rd party // pass to 3rd party and authenticate
// NOTE: normally the signature should be a token from the server!
hello.settings.state = signature; hello.settings.state = signature;
// authenticate
hello(obj.id).login(function(){ hello(obj.id).login(function(){
window.parent.close(); window.parent.close();
}) })
...@@ -255,24 +240,43 @@ ...@@ -255,24 +240,43 @@
// update flux // update flux
app.setLoginStatus(response, undefined); app.setLoginStatus(response, undefined);
} catch (e) { } catch (e) {
util.errorHandler(e); util.error(e);
} }
} }
} else {
util.loader("", "global_dict.status_dict.failed", "ban-circle");
} }
// since we are jquerying, close (all) popups // since we are jquerying, close (all) popups
// TODO: this is also crap... // TODO: this is also crap...
$(".ui-popup").popup("close"); $(".ui-popup").popup("close");
// NOTE: now that we have a authenticated user, check storage
// for user (INSECURE!!!!) and if not found, generate a new user
// with the login credentials accessible.
// TODO: not my problem now, but this must be secure access!
}) })
.then(function() { .then(function() {
app.register(obj.id); util.loader("", "global_dict.status_dict.saving");
return app.register(obj.id)
.then(function() {
// TODO: find a way to access an element that is depending on
// the login status!
// update which would be closest form...
var el = document.getElementsByTagName("form")[0];
var config = {"state": el.state};
// update gadget
app.setContent(
{"generate":"gadget", "id": "person_view", "href": "person_view"},
{"fragment_list": config.state.fragment_list},
false,
true
)
.then(function (answer){
el.parentNode.replaceChild(answer, el);
})
.then(app.setPageBindings)
.fail(util.error);
})
}) })
.fail(util.errorHandler); .fail(util.error);
}, },
/** /**
...@@ -534,7 +538,7 @@ ...@@ -534,7 +538,7 @@
(spec.property_dict.feature_dict.link_identifier || "id")]; (spec.property_dict.feature_dict.link_identifier || "id")];
if (item === undefined) { if (item === undefined) {
util.errorHandler({"error": "mapTableRows: include_docs not set"}); util.error({"error": "mapTableRows: include_docs not set"});
} else { } else {
row = []; row = [];
for (m = 0; m < config.length; m += 1) { for (m = 0; m < config.length; m += 1) {
...@@ -573,7 +577,7 @@ ...@@ -573,7 +577,7 @@
if (layout.footer && layout.footer.length > 0) { if (layout.footer && layout.footer.length > 0) {
util.errorHandler( util.error(
{"error": "mapTableRows: Missing handler for table footer"} {"error": "mapTableRows: Missing handler for table footer"}
); );
} }
...@@ -614,7 +618,7 @@ ...@@ -614,7 +618,7 @@
// if include_docs is not set, item will be undefined! // if include_docs is not set, item will be undefined!
if (item === undefined) { if (item === undefined) {
util.errorHandler({"error": "mapListItems: missing include_docs"}); util.error({"error": "mapListItems: missing include_docs"});
} }
// radio // radio
...@@ -866,7 +870,7 @@ ...@@ -866,7 +870,7 @@
"clear": clear || undefined "clear": clear || undefined
}; };
} else { } else {
util.errorHandler({ util.error({
"error": "mapFormField: No field definition defined" "error": "mapFormField: No field definition defined"
}); });
} }
...@@ -919,23 +923,19 @@ ...@@ -919,23 +923,19 @@
// initialize hellojs // initialize hellojs
hello.init(foreign.initializer_dict, foreign.redirect); hello.init(foreign.initializer_dict, foreign.redirect);
// set login state
if (foreign.preserve_session) {
app.default_dict.state_dict.preserve_in =
foreign.preserve_session;
app.default_dict.state_dict.verification_dict = app.default_dict.state_dict.verification_dict =
foreign.verification_dict; foreign.verification_dict;
}
set_login = true; set_login = true;
} else { } else {
util.errorHandler({"error": "globalConfig: Missing hellojs"}); util.error({"error": "globalConfig: Missing hellojs"});
} }
} }
break; break;
} }
} }
} else { } else {
util.errorHandler({"error": "globalConfig: Missing login dict"}); util.error({"error": "globalConfig: Missing login dict"});
} }
// setup loader // setup loader
...@@ -956,7 +956,7 @@ ...@@ -956,7 +956,7 @@
} }
} }
} else { } else {
util.errorHandler({"error": "globalConfig: Missing path dict"}); util.error({"error": "globalConfig: Missing path dict"});
} }
// i18n // i18n
...@@ -979,7 +979,7 @@ ...@@ -979,7 +979,7 @@
return; return;
}); });
} else { } else {
util.errorHandler( util.error(
{"error": "globalConfig: Missing i18n configuration"} {"error": "globalConfig: Missing i18n configuration"}
); );
} }
...@@ -1061,7 +1061,7 @@ ...@@ -1061,7 +1061,7 @@
app.setGlobalBindings(); app.setGlobalBindings();
}); });
}) })
.fail(util.errorHandler); .fail(util.error);
}, },
/** /**
...@@ -1089,7 +1089,7 @@ ...@@ -1089,7 +1089,7 @@
} }
return RSVP.all(promises); return RSVP.all(promises);
default: default:
util.errorHandler({"error": "setStorage: Missing storage type"}); util.error({"error": "setStorage: Missing storage type"});
return RSVP.all(promises) return RSVP.all(promises)
}; };
}, },
...@@ -1104,7 +1104,7 @@ ...@@ -1104,7 +1104,7 @@
storage[content_dict.property_dict.definition.application_name] = storage[content_dict.property_dict.definition.application_name] =
jIO.createJIO(content_dict.property_dict.definition); jIO.createJIO(content_dict.property_dict.definition);
} else { } else {
util.errorHandler( util.error(
{"error": "makeStorage: Missing storage definition"} {"error": "makeStorage: Missing storage definition"}
); );
} }
...@@ -1123,7 +1123,7 @@ ...@@ -1123,7 +1123,7 @@
.children[url_dict ? (url_dict.layout_level || 0) : 0]; .children[url_dict ? (url_dict.layout_level || 0) : 0];
if (page_dict === undefined) { if (page_dict === undefined) {
util.errorHandler({"error":"Pageindex: Missing page definition"}); util.error({"error":"Pageindex: Missing page definition"});
} else { } else {
// NOTE: 3rd parameter "create" needs to be set to undefined, // NOTE: 3rd parameter "create" needs to be set to undefined,
...@@ -1302,13 +1302,13 @@ ...@@ -1302,13 +1302,13 @@
"fieldlist": function (spec, answer, field_dict, update, url_pointer) { "fieldlist": function (spec, answer, field_dict, update, url_pointer) {
var i, element, target; var i, element, target;
target = document.createDocumentFragment();
// no auth // no auth
if (answer === null) { if (answer === null) {
target = factory.util.wrapInForm(spec);
target.appendChild(app.noItemsFound("auth")); target.appendChild(app.noItemsFound("auth"));
return target; return target;
} } else {
target = document.createDocumentFragment();
if ((answer.data && answer.data.total_rows === 0) || if ((answer.data && answer.data.total_rows === 0) ||
(answer.data === undefined && answer.request_new === undefined)) { (answer.data === undefined && answer.request_new === undefined)) {
...@@ -1323,9 +1323,7 @@ ...@@ -1323,9 +1323,7 @@
if (answer.request_new || answer.data.total_rows === 0) { if (answer.request_new || answer.data.total_rows === 0) {
element.data = {}; element.data = {};
} else if (answer.data.total_rows > 1) { } else if (answer.data.total_rows > 1) {
util.errorHandler({ util.error({"error": "Fieldlist: More than 1 record"});
"error": "Fieldlist: More than 1 record"
});
} else { } else {
element.data = answer.data.rows[0].doc; element.data = answer.data.rows[0].doc;
} }
...@@ -1339,6 +1337,7 @@ ...@@ -1339,6 +1337,7 @@
} }
return target; return target;
} }
}
}; };
/* ====================================================================== */ /* ====================================================================== */
...@@ -1464,18 +1463,26 @@ ...@@ -1464,18 +1463,26 @@
* @param {object} content Content to add * @param {object} content Content to add
*/ */
// TODO: bad targeting, should be depending on the gadget being updated! // TODO: bad targeting, should be depending on the gadget being updated!
// TODO: remove altogether, when figuring out how to store state and target!
factory.util.updatePageSection = function (id, content) { factory.util.updatePageSection = function (id, content) {
var i, target, container = document.getElementById(id); var i, target, container = document.getElementById(id);
// find a target // find a target
target = container.querySelectorAll("[data-update]"); target = container.querySelectorAll("[data-update]");
// ui-content
if (target.length === 0) { if (target.length === 0) {
target = container.querySelectorAll("div.ui-content"); target = container.querySelectorAll("div.ui-content");
} }
// element itself
if (target.length === 0) { if (target.length === 0) {
util.errorHandler({"error": "updatePageSection: No target found"}); target = [container];
}
// no more way
if (target.length === 0) {
util.error({"error": "updatePageSection: No target found"});
} else { } else {
for (i = 0; i < target.length; i += 1) { for (i = 0; i < target.length; i += 1) {
target[i].setAttribute("data-bound", true); target[i].setAttribute("data-bound", true);
...@@ -1501,7 +1508,7 @@ ...@@ -1501,7 +1508,7 @@
// don't reload if same popup is opened // don't reload if same popup is opened
if (state !== reference) { if (state !== reference) {
if (reference === null) { if (reference === null) {
util.errorHandler({"error": "Global Bindings: No handler for popup"}); util.error({"error": "Global Bindings: No handler for popup"});
fragment = factory.element( fragment = factory.element(
"p", {}, {}, {"text": "No handler for popup"} "p", {}, {}, {"text": "No handler for popup"}
); );
...@@ -1546,7 +1553,7 @@ ...@@ -1546,7 +1553,7 @@
// TODO: how to reposition popup right after appending? // TODO: how to reposition popup right after appending?
$(popup).popup("reposition", {"positionto": "window"}); $(popup).popup("reposition", {"positionto": "window"});
}) })
.fail(util.errorHandler); .fail(util.error);
} }
} }
}; };
...@@ -1622,7 +1629,7 @@ ...@@ -1622,7 +1629,7 @@
var i, target, popup, wrap, id, config, container, placeholder; var i, target, popup, wrap, id, config, container, placeholder;
if (config_dict === undefined) { if (config_dict === undefined) {
util.errorHandler({ util.error({
"error": "GeneratePopup: Missing configuration" "error": "GeneratePopup: Missing configuration"
}); });
} else { } else {
...@@ -1735,7 +1742,7 @@ ...@@ -1735,7 +1742,7 @@
target, state; target, state;
if (config_dict === undefined) { if (config_dict === undefined) {
util.errorHandler({ util.error({
"error": "Generate Header: Missing configuration" "error": "Generate Header: Missing configuration"
}); });
} else { } else {
...@@ -1855,7 +1862,7 @@ ...@@ -1855,7 +1862,7 @@
var i, element, config, id, panel, closer, order, target; var i, element, config, id, panel, closer, order, target;
if (config_dict === undefined) { if (config_dict === undefined) {
util.errorHandler({ util.error({
"error": "Generate Panel: Missing configuration" "error": "Generate Panel: Missing configuration"
}); });
} else { } else {
...@@ -1954,7 +1961,7 @@ ...@@ -1954,7 +1961,7 @@
var config, id, footer, i, element, order; var config, id, footer, i, element, order;
if (config_dict === undefined) { if (config_dict === undefined) {
util.errorHandler({ util.error({
"error": "Generate Footer: Missing config" "error": "Generate Footer: Missing config"
}); });
} else { } else {
...@@ -2026,13 +2033,14 @@ ...@@ -2026,13 +2033,14 @@
factory.form = function (spec) { factory.form = function (spec) {
var i, j, k, layout, element, container, area, field, overrides, var i, j, k, layout, element, container, area, field, overrides,
position, doc, config, value, stamp, sauce, encode, secure, position, doc, config, value, stamp, sauce, encode, secure,
safety_box, noscript, fragment, wrap, update; safety_box, noscript, fragment, wrap;
fragment = factory.util.wrapInForm(spec);
secure = spec.property_dict.secure; secure = spec.property_dict.secure;
if (spec.property_dict.update) { if (spec.property_dict.update) {
spec.update = spec.property_dict.update; spec.update = spec.property_dict.update;
} }
fragment = factory.util.wrapInForm(spec);
wrap = function (area, captcha) { wrap = function (area, captcha) {
var keys = {}; var keys = {};
...@@ -2056,8 +2064,11 @@ ...@@ -2056,8 +2064,11 @@
area = layout.position === "center" ? 2 : 1; area = layout.position === "center" ? 2 : 1;
container = wrap(area); container = wrap(area);
// secure if (i === 0) {
if (i === 0 && secure === "default") { // secure form
// TODO: do properly once we have time
if (secure === "default") {
stamp = new Date().getTime(); stamp = new Date().getTime();
encode = window.btoa || window.shim.Base64.encode; encode = window.btoa || window.shim.Base64.encode;
// TODO: include client IP in hash to block submission serverside // TODO: include client IP in hash to block submission serverside
...@@ -2115,6 +2126,18 @@ ...@@ -2115,6 +2126,18 @@
} }
)); ));
} }
// add hidden storage identifier
if (spec.data._id) {
container.appendChild(factory.element(
"input",
{
"type":"hidden",
"value":spec.data._id,
"name": "identifier"
}
));
}
}
for (j = 0; j < layout.fieldlist.length; j += 1) { for (j = 0; j < layout.fieldlist.length; j += 1) {
field = layout.fieldlist[j]; field = layout.fieldlist[j];
...@@ -2122,6 +2145,7 @@ ...@@ -2122,6 +2145,7 @@
config = spec.fields[field.title]; config = spec.fields[field.title];
overrides = field.overrides; overrides = field.overrides;
doc = spec.data || undefined; doc = spec.data || undefined;
value = doc ? (doc[field.title]) : undefined; value = doc ? (doc[field.title]) : undefined;
switch (j) { switch (j) {
...@@ -2138,7 +2162,6 @@ ...@@ -2138,7 +2162,6 @@
position = undefined; position = undefined;
break; break;
} }
// generate and append // generate and append
container.appendChild(factory.formElement( container.appendChild(factory.formElement(
map.utils.mapFormField(config, overrides, value), map.utils.mapFormField(config, overrides, value),
...@@ -2156,7 +2179,7 @@ ...@@ -2156,7 +2179,7 @@
safety_box = wrap(1, true); safety_box = wrap(1, true);
fragment.appendChild(safety_box); fragment.appendChild(safety_box);
} else { } else {
util.errorHandler({"error": "Captcha - No public key supplied"}); util.error({"error": "Captcha - No public key supplied"});
} }
} }
...@@ -2201,7 +2224,7 @@ ...@@ -2201,7 +2224,7 @@
var config, group, direction, controls, i, element, order, state; var config, group, direction, controls, i, element, order, state;
if (spec === undefined) { if (spec === undefined) {
util.errorHandler({ util.error({
"error": "Generate Controlgroup: Missing config" "error": "Generate Controlgroup: Missing config"
}); });
} else { } else {
...@@ -2295,7 +2318,7 @@ ...@@ -2295,7 +2318,7 @@
var navbar, controls, i, element, target, order; var navbar, controls, i, element, target, order;
if (spec === undefined) { if (spec === undefined) {
util.errorHandler({ util.error({
"error": "Generate Navbar: Missing Configuration" "error": "Generate Navbar: Missing Configuration"
}); });
} else { } else {
...@@ -2863,7 +2886,7 @@ ...@@ -2863,7 +2886,7 @@
); );
} }
}) })
.fail(util.errorHandler); .fail(util.error);
}; };
/* ********************************************************************** */ /* ********************************************************************** */
...@@ -3708,14 +3731,16 @@ ...@@ -3708,14 +3731,16 @@
obj[property] = value; obj[property] = value;
} }
// prepare for form submit // prepare for form submit
// NOTE: formData can post CORS!
formData.append(property.replace(replace, ""), value); formData.append(property.replace(replace, ""), value);
} }
} }
util.updateStatus("show", "", "global_dict.status_dict.saving"); util.loader("", "global_dict.status_dict.saving");
// TODO: a post should always include all required fields // TODO: a post should always include all required fields
// TODO: find a way to set default fields, like timestamp etc // TODO: find a way to set default fields, like timestamp etc
// TODO: make sure we put on existing records!
app.postDataToStorage({ app.postDataToStorage({
"response": [obj], "response": [obj],
"pass": {"type": config.gadget.state.type, "reply": true} "pass": {"type": config.gadget.state.type, "reply": true}
...@@ -3727,14 +3752,14 @@ ...@@ -3727,14 +3752,14 @@
case "login_state": case "login_state":
app.setLoginStatus(answer.response, config.portal_type_source); app.setLoginStatus(answer.response, config.portal_type_source);
break; break;
} };
util.updateStatus( util.loader("", "global_dict.status_dict.saved", "check");
"show", "", "global_dict.status_dict.saved", "check"
);
} }
}) })
.fail(util.errorHandler); .fail(util.error);
} }
} else {
util.loader("", "validation_dict.general", "ban-circle");
} }
}; };
...@@ -3794,6 +3819,7 @@ ...@@ -3794,6 +3819,7 @@
*/ */
app.search = function (config) { app.search = function (config) {
// TODO: why do I need the first 2 calls here, without I cannot search.
// gadget config // gadget config
app.fetchConfiguration({ app.fetchConfiguration({
"storage": app.default_dict.storage_dict.settings, "storage": app.default_dict.storage_dict.settings,
...@@ -3831,13 +3857,13 @@ ...@@ -3831,13 +3857,13 @@
.then(function (reply){ .then(function (reply){
factory.util.updatePageSection(config.id, reply); factory.util.updatePageSection(config.id, reply);
}) })
.fail(util.errorHandler); .fail(util.error);
}) })
.fail(util.errorHandler); .fail(util.error);
}; };
/** /**
* Register a user (in localstorage) - requires login module) * Register user (in localstorage) - requires login module)
* @method register * @method register
* @param {string} provider Provider through which register should run * @param {string} provider Provider through which register should run
**/ **/
...@@ -3880,12 +3906,14 @@ ...@@ -3880,12 +3906,14 @@
"response": [user], "response": [user],
"pass": {"type": "Person"} "pass": {"type": "Person"}
}); });
} else {
util.error({"error": "regiser user: need account sync!"});
} }
} }
}) })
.fail(util.errorHandler); .fail(util.error);
}) })
.fail(util.errorHandler); .fail(util.error);
}; };
/** /**
...@@ -3970,7 +3998,7 @@ ...@@ -3970,7 +3998,7 @@
.then(function (reply){ .then(function (reply){
factory.util.updatePageSection(config.id, reply); factory.util.updatePageSection(config.id, reply);
}) })
.fail(util.errorHandler); .fail(util.error);
// reset timer // reset timer
app.timer = 0; app.timer = 0;
...@@ -4124,12 +4152,12 @@ ...@@ -4124,12 +4152,12 @@
.then(function (reply){ .then(function (reply){
factory.util.updatePageSection(config.id, reply); factory.util.updatePageSection(config.id, reply);
}) })
.fail(util.errorHandler); .fail(util.error);
} else { } else {
util.errorHandler({"Error": "No state information stored for gadget"}); util.error({"Error": "No state information stored for gadget"});
} }
} else { } else {
util.errorHandler({ util.error({
"Error": "Action is missing reference gadget" "Error": "Action is missing reference gadget"
}); });
} }
...@@ -4220,9 +4248,8 @@ ...@@ -4220,9 +4248,8 @@
* @param {string} portal_type Portal Type concerned * @param {string} portal_type Portal Type concerned
**/ **/
app.setLoginStatus = function (response, portal_type) { app.setLoginStatus = function (response, portal_type) {
var temp_store, stamp, provider, auth, links, i, login; var stamp, provider, auth, links, i, login;
temp_store = app.default_dict.state_dict.preserve_in;
stamp = Date.now(); stamp = Date.now();
provider = response.network ? response.network.slice(0,2) : "self"; provider = response.network ? response.network.slice(0,2) : "self";
auth = response.authResponse; auth = response.authResponse;
...@@ -4238,26 +4265,6 @@ ...@@ -4238,26 +4265,6 @@
"expires": auth ? auth.expires_in : 3600 "expires": auth ? auth.expires_in : 3600
} }
// if specified store in preserve
if (temp_store) {
switch (temp_store) {
case "sessionStorage":
window.sessionStorage
.setItem("state", JSON.stringify(flux.state));
break;
// WARNING: you should not!
case "localStorage":
window.localStorage
.setItem("state", JSON.stringify(flux.state));
break;
// WARNING: you really should NOT!!!
case "cookie":
util.cookieHandler
.setItem("state", JSON.stringify(flux.state));
break;
};
}
// need to update the .... button // need to update the .... button
// TODO: make a login gadget, store dependend buttons in state // TODO: make a login gadget, store dependend buttons in state
links = util.getHeader().getElementsByTagName("A"); links = util.getHeader().getElementsByTagName("A");
...@@ -4281,16 +4288,17 @@ ...@@ -4281,16 +4288,17 @@
* @return {boolean} true/false * @return {boolean} true/false
**/ **/
// TODO: make this work with a regular login, too!!! // TODO: make this work with a regular login, too!!!
// TODO: refactor, make sure we always pass a pass!
app.checkLoginStatus = function (skip, pass) { app.checkLoginStatus = function (skip, pass) {
var state, temp_store, lookup, logger, provider, verify, url, influx, info, var state, lookup, logger, provider, verify, url, influx, info,
valid, auth_config, stamp, expires, expired, token; valid, auth_config, stamp, expires, expired, token, auth_response,
signee;
if (skip === undefined) { if (skip === undefined) {
// TODO: name collusion! make normal pass object! // TODO: name collusion! make normal pass object!
return RSVP.resolve({"pass": skip}); return RSVP.resolve({"pass": skip});
} else { } else {
logger = app.default_dict.state_dict.login_pointer; logger = app.default_dict.state_dict.login_pointer;
temp_store = app.default_dict.state_dict.preserve_in;
verify = app.default_dict.state_dict.verification_dict; verify = app.default_dict.state_dict.verification_dict;
if (logger) { if (logger) {
...@@ -4298,21 +4306,6 @@ ...@@ -4298,21 +4306,6 @@
// try flux // try flux
state = flux.state; state = flux.state;
// fallback to preserved locations
if (state === undefined) {
switch (temp_store) {
case "sessionStorage":
state = JSON.parse(window.sessionStorage.getItem("state"));
break;
case "localStorage":
state = JSON.parse(window.localStorage.getItem("state"));
break;
case "cookie":
state = JSON.parse(util.cookieHandler.getItem("state"));
break;
};
}
// found state // found state
// TODO: break once first active session is found! For now I would // TODO: break once first active session is found! For now I would
// like to keep one active login only. // like to keep one active login only.
...@@ -4326,9 +4319,11 @@ ...@@ -4326,9 +4319,11 @@
switch (provider) { switch (provider) {
case "go": case "go":
url = verify.google + auth_config.token; url = verify.google + auth_config.token;
signee = "google";
break; break;
case "self": case "self":
url = undefined; url = undefined;
signee = "self";
break; break;
} }
// test for timeout // test for timeout
...@@ -4344,10 +4339,11 @@ ...@@ -4344,10 +4339,11 @@
} }
} }
} }
// token in memory still valid, add it to the pass object // token in memory still valid, add it to the pass object and done
if (valid) { if (valid) {
if (pass) { if (pass) {
pass.active_login = true; pass.active_login = true;
pass.verified_by = signee;
pass.token = auth_config.token; pass.token = auth_config.token;
pass.expires_in = expires; pass.expires_in = expires;
return RSVP.resolve(pass); return RSVP.resolve(pass);
...@@ -4359,23 +4355,37 @@ ...@@ -4359,23 +4355,37 @@
if (url) { if (url) {
return util.ajax({"url": url}) return util.ajax({"url": url})
.then(function(answer) { .then(function(answer) {
auth_response = util.parseIfNeeded(answer.target.response);
if (pass) {
pass.active_login = true;
pass.verified_by = signee;
pass.token = auth_config.token;
pass.expires_in = auth_response.expires_in;
return RSVP.resolve(pass);
}
return auth_response;
return util.parseIfNeeded(answer.target.response); return util.parseIfNeeded(answer.target.response);
}) })
.fail(function(event) { .fail(function(event) {
// invalid session > return 400, so we are back on the then-column // invalid session > return 400, so we are back on the then-column
if (event.target.status === 400) { if (event.target.status === 400) {
return util.parseIfNeeded(event.target.response); auth_response = util.parseIfNeeded(event.target.response);
if (pass) {
return RSVP.resolve(pass);
}
return RSVP.resolve(pass);
} }
throw util.parseIfNeeded(event.target); throw util.parseIfNeeded(event.target);
}); });
} }
// TODO: this should ask to login again!
if (pass) { if (pass) {
pass.active_login = false; pass.active_login = false;
return RSVP.resolve(pass); return RSVP.resolve(pass);
} }
return RSVP.resolve({"error": "no state found/not logged in"}); return RSVP.resolve({"error": "no state found/not logged in"});
} else { } else {
util.errorHandler({"error":"loginStatus: Missing login handler."}); util.error({"error":"loginStatus: Missing login handler."});
} }
} }
}; };
...@@ -4540,12 +4550,12 @@ ...@@ -4540,12 +4550,12 @@
if (handler) { if (handler) {
handler(app.generateActionObject(e), val); handler(app.generateActionObject(e), val);
} else { } else {
util.errorHandler({ util.error({
"Error": "Action: No method defined" "Error": "Action: No method defined"
}); });
} }
} else { } else {
util.errorHandler({ util.error({
"Error": "Action: No action defined for element" "Error": "Action: No action defined for element"
}); });
} }
...@@ -4827,8 +4837,11 @@ ...@@ -4827,8 +4837,11 @@
* @param {object} content_dict content to be generated * @param {object} content_dict content to be generated
* @param {object} url_dict JSON pointers based on parsed link * @param {object} url_dict JSON pointers based on parsed link
* @param {boolean} create Create page/Generate content/Refresh content * @param {boolean} create Create page/Generate content/Refresh content
* @param {boolean} purge Replace existing element/gadget
* @return {object} promise/HTML element
*/ */
app.setContent = function (content_dict, url_dict, create) { // TODO: make this always return a promise. Requires to refactor listview!
app.setContent = function (content_dict, url_dict, create, purge) {
var i, skip, container, target, pass, spec, dependency; var i, skip, container, target, pass, spec, dependency;
spec = url_dict || {}; spec = url_dict || {};
...@@ -4850,6 +4863,7 @@ ...@@ -4850,6 +4863,7 @@
} else { } else {
// this run needs query and dynamic data // this run needs query and dynamic data
pass = { pass = {
"purge": purge || null,
"mode": spec.mode || null, "mode": spec.mode || null,
"create": create, "create": create,
"layout_level": spec.layout_level || null, "layout_level": spec.layout_level || null,
...@@ -4882,7 +4896,7 @@ ...@@ -4882,7 +4896,7 @@
.then(app.fetchDataTotal) .then(app.fetchDataTotal)
.then(app.fetchDataQuery) .then(app.fetchDataQuery)
.then(app.generateGadgetContent) .then(app.generateGadgetContent)
.fail(util.errorHandler); .fail(util.error);
default: default:
switch (content_dict.type) { switch (content_dict.type) {
...@@ -4962,7 +4976,7 @@ ...@@ -4962,7 +4976,7 @@
request_new = pass.mode === "new" ? {"request_new": true} : null; request_new = pass.mode === "new" ? {"request_new": true} : null;
if (constructor === undefined) { if (constructor === undefined) {
util.errorHandler( util.error(
{"error":"generateGadgetContent: Missing constructor"} {"error":"generateGadgetContent: Missing constructor"}
); );
} }
...@@ -4971,7 +4985,6 @@ ...@@ -4971,7 +4985,6 @@
if (pass.skip) { if (pass.skip) {
return constructor(pass.content_dict, pass.url_dict); return constructor(pass.content_dict, pass.url_dict);
} else { } else {
// generate content // generate content
element = constructor( element = constructor(
pass.config, pass.config,
...@@ -4984,11 +4997,8 @@ ...@@ -4984,11 +4997,8 @@
// translate // translate
map.actions.translateNodeList(element); map.actions.translateNodeList(element);
// not auth, no mojo! // NOTE: when purging, we must not set state on the gadget being purged
if (pass.no_auth || (pass.auth && pass.active_login || if (pass.create === false && pass.purge === null) {
pass.mode === "new")) {
if (pass.create === false) {
selector = pass.state.gadget; selector = pass.state.gadget;
} else { } else {
// NOTE: in case of update, element will be the section to update // NOTE: in case of update, element will be the section to update
...@@ -5009,6 +5019,10 @@ ...@@ -5009,6 +5019,10 @@
// WARNING: this should use data(), it is bad practice to store like this // WARNING: this should use data(), it is bad practice to store like this
selector.state = pass.state; selector.state = pass.state;
// not auth, no mojo!
if (pass.no_auth || (pass.auth && pass.active_login ||
pass.mode === "new")) {
app.updateInfoElement( app.updateInfoElement(
pass.create ? element : selector, pass.create ? element : selector,
pass.state.query, pass.state.query,
...@@ -5039,6 +5053,8 @@ ...@@ -5039,6 +5053,8 @@
} }
if (pass.create === false) { if (pass.create === false) {
// make sure include_docs is set, because at this point we want data!
pass.state.query.include_docs = true;
pass.state.query.limit = pass.store_limit; pass.state.query.limit = pass.store_limit;
} else { } else {
pass.state.query = app.generateQueryObject( pass.state.query = app.generateQueryObject(
...@@ -5070,15 +5086,17 @@ ...@@ -5070,15 +5086,17 @@
* @return {object} response object/promise * @return {object} response object/promise
*/ */
app.fetchDataTotal = function (reply) { app.fetchDataTotal = function (reply) {
var pass = reply.pass; var pass = reply.pass, reference;
if (pass.skip === undefined &&
(pass.no_auth || (pass.auth && pass.active_login ||
pass.mode === "new"))) {
if (pass.skip === undefined) {
// create or update state object // create or update state object
if (pass.create === false) { if (pass.create === false) {
pass.state = document.getElementById(pass.id).state; // TODO: horrible, define a pass API!!!!
reference = document.getElementById(pass.id);
if (reference === null) {
reference = document.getElementById(pass.config.id);
}
pass.state = reference.state;
pass.constructor = pass.state.method; pass.constructor = pass.state.method;
pass.store_limit = pass.state.query.limit; pass.store_limit = pass.state.query.limit;
pass.state.query.limit = []; pass.state.query.limit = [];
...@@ -5104,6 +5122,11 @@ ...@@ -5104,6 +5122,11 @@
); );
} }
} }
}
if (pass.skip === undefined &&
(pass.no_auth || (pass.auth && pass.active_login ||
pass.mode === "new"))) {
// skip total for single item layouts! // skip total for single item layouts!
if (pass.config.initial_query) { if (pass.config.initial_query) {
...@@ -5140,10 +5163,11 @@ ...@@ -5140,10 +5163,11 @@
if (reply.response) { if (reply.response) {
store = storage["items"]; store = storage["items"];
items = util.parseIfNeeded(reply.response); items = util.parseIfNeeded(reply.response);
if (store && items.length > 0) { if (store && items.length > 0) {
promises = []; promises = [];
// show some status // show some status
util.updateStatus("show", "", "global_dict.status_dict.storing"); util.loader("", "global_dict.status_dict.storing");
// loop over item and create a JIO record // loop over item and create a JIO record
for (i = 0; i < items.length; i += 1) { for (i = 0; i < items.length; i += 1) {
...@@ -5156,10 +5180,17 @@ ...@@ -5156,10 +5180,17 @@
} }
// add portal type // add portal type
obj.portal_type = pass.type; obj.portal_type = pass.type;
// make sure to overwrite existing files, so try to fetch... console.log(obj)
// TODO: is there no easier way to check whether to put/post console.log(obj.identifier)
promises[i] = store.post(obj) // test for existing file
if (obj.identifier) {
method = "put";
obj._id = obj.identifier;
}
promises[i] = store[method || "post"](obj)
.then(function(answer) { .then(function(answer) {
console.log("DONE")
console.log(answer)
return answer; return answer;
}); });
} }
...@@ -5174,7 +5205,7 @@ ...@@ -5174,7 +5205,7 @@
"pass": pass "pass": pass
}; };
}) })
.fail(util.errorHandler); .fail(util.error);
} }
// we may have no sample data! // we may have no sample data!
return { return {
...@@ -5207,7 +5238,7 @@ ...@@ -5207,7 +5238,7 @@
"pass": pass "pass": pass
}; };
}) })
.fail(util.errorHandler); .fail(util.error);
} }
} }
return { return {
...@@ -5267,7 +5298,8 @@ ...@@ -5267,7 +5298,8 @@
if (pass.skip === undefined && if (pass.skip === undefined &&
(pass.no_auth || (pass.auth && pass.active_login || (pass.no_auth || (pass.auth && pass.active_login ||
pass.mode === "new")) && pass.mode === "new")) &&
pass.create !== false && pass.config.portal_type_fields) { //(pass.create !== false || pass.requires_fields) &&
pass.config.portal_type_fields) {
return app.fetchConfiguration({ return app.fetchConfiguration({
"storage": app.default_dict.storage_dict.settings, "storage": app.default_dict.storage_dict.settings,
...@@ -5305,11 +5337,12 @@ ...@@ -5305,11 +5337,12 @@
if (pass.auth) { if (pass.auth) {
return app.checkLoginStatus(true, pass) return app.checkLoginStatus(true, pass)
.then(function(new_pass) { .then(function(new_pass) {
return { return {
"pass": new_pass "pass": new_pass
} }
}) })
.fail(util.errorHandler); .fail(util.error);
} }
return { return {
"pass": pass "pass": pass
...@@ -5404,7 +5437,7 @@ ...@@ -5404,7 +5437,7 @@
if (property_dict.optional) { if (property_dict.optional) {
return RSVP.all([]); return RSVP.all([]);
} else { } else {
util.errorHandler({"error": "getFromDisk: URL undefined"}); util.error({"error": "getFromDisk: URL undefined"});
} }
} }
...@@ -5424,7 +5457,7 @@ ...@@ -5424,7 +5457,7 @@
undefined); undefined);
if (storage_location === undefined) { if (storage_location === undefined) {
util.errorHandler({"error": "getFromDisk: no storage defined"}); util.error({"error": "getFromDisk: no storage defined"});
return RSVP.all([]); return RSVP.all([]);
} }
return storage_location.put({ return storage_location.put({
...@@ -5448,7 +5481,7 @@ ...@@ -5448,7 +5481,7 @@
} }
return response; return response;
}) })
.fail(util.errorHandler); .fail(util.error);
}; };
/** /**
...@@ -5492,16 +5525,16 @@ ...@@ -5492,16 +5525,16 @@
if (first || (page && base) || raw_url === $.mobile.getDocumentUrl() || if (first || (page && base) || raw_url === $.mobile.getDocumentUrl() ||
data.options.role === "popup") { data.options.role === "popup") {
console.log("STOP us, JQM go") // console.log("STOP us, JQM go")
return; return;
} }
if ((document.getElementById(config.id) && base !== null)) { if ((document.getElementById(config.id) && base !== null)) {
e.preventDefault(); e.preventDefault();
console.log("STOP us, STOP JQM") // console.log("STOP us, STOP JQM")
return; return;
} }
handle = true; handle = true;
console.log("GO us, STOP JQM") // console.log("GO us, STOP JQM")
e.preventDefault(); e.preventDefault();
} else { } else {
...@@ -5547,7 +5580,7 @@ ...@@ -5547,7 +5580,7 @@
return app.setContent(reply, config, create); return app.setContent(reply, config, create);
}) })
.then(app.setPageBindings) .then(app.setPageBindings)
.fail(util.errorHandler); .fail(util.error);
} }
}; };
...@@ -5675,7 +5708,7 @@ ...@@ -5675,7 +5708,7 @@
captcha.id, captcha.id,
{"theme": "red", "callback": Recaptcha.focus_response_field} {"theme": "red", "callback": Recaptcha.focus_response_field}
); );
}).fail(util.errorHandler); }).fail(util.error);
} }
if (form_element.getAttribute("data-bound") === null) { if (form_element.getAttribute("data-bound") === null) {
...@@ -5943,13 +5976,12 @@ ...@@ -5943,13 +5976,12 @@
/** /**
* Show and hide the jQuery Mobile status message (loader/icon/message) * Show and hide the jQuery Mobile status message (loader/icon/message)
* @method loader * @method loader
* @param {boolean} show Whether to show or hide the loader
* @param {string} message The message to display in the loader * @param {string} message The message to display in the loader
* @param {string} msg_i18n lookup for status message * @param {string} msg_i18n lookup for status message
* @param {string} theme background theme * @param {string} theme background theme
* @param {string} icon Which icon to display when overriding the loader * @param {string} icon Which icon to display when overriding the loader
*/ */
util.updateStatus = function (show, message, msg_i18n, icon, theme) { util.loader = function (message, msg_i18n, icon, theme) {
var text_to_display = i18n && msg_i18n ? var text_to_display = i18n && msg_i18n ?
map.actions.translateLookup(msg_i18n) : message; map.actions.translateLookup(msg_i18n) : message;
...@@ -5972,9 +6004,9 @@ ...@@ -5972,9 +6004,9 @@
app.timer = window.setTimeout(function () { app.timer = window.setTimeout(function () {
$.mobile.loading("hide"); $.mobile.loading("hide");
}, 2500); }, 3000);
} else { } else {
util.errorHandler({"error": "showStatus: Loader not enabled"}); util.error({"error": "showStatus: Loader not enabled"});
} }
}; };
...@@ -6182,7 +6214,7 @@ ...@@ -6182,7 +6214,7 @@
} }
if (supported === false) { if (supported === false) {
message = fail.splice(0, -1); message = fail.splice(0, -1);
util.errorHandler( util.error(
{"error": "browser: " + message + " not supported"} {"error": "browser: " + message + " not supported"}
); );
...@@ -6206,7 +6238,7 @@ ...@@ -6206,7 +6238,7 @@
} }
return true; return true;
} else { } else {
util.errorHandler({"error": "testBrowserSupport: Modernizr undefined"}); util.error({"error": "testBrowserSupport: Modernizr undefined"});
return false; return false;
} }
}; };
...@@ -6220,7 +6252,7 @@ ...@@ -6220,7 +6252,7 @@
* @param {object} err Error object * @param {object} err Error object
*/ */
// TODO: update global config so we know where to post a ticket to! // TODO: update global config so we know where to post a ticket to!
util.errorHandler = function (err) { util.error = function (err) {
console.log(err); console.log(err);
}; };
...@@ -6243,7 +6275,6 @@ ...@@ -6243,7 +6275,6 @@
if (window.opener === null) { if (window.opener === null) {
// TODO: don't wipe, sync... // TODO: don't wipe, sync...
window.localStorage.clear(); window.localStorage.clear();
window.sessionStorage.clear();
} }
app.getFromDisk({ app.getFromDisk({
...@@ -6259,7 +6290,7 @@ ...@@ -6259,7 +6290,7 @@
}) })
.then(app.setContent) .then(app.setContent)
.then(app.parsePage) .then(app.parsePage)
.fail(util.errorHandler); .fail(util.error);
}); });
}(window, document, jQuery)); }(window, document, jQuery));
\ No newline at end of file
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
"fetching": "Fetching Data", "fetching": "Fetching Data",
"storing": "Storing Data", "storing": "Storing Data",
"saving": "Saving", "saving": "Saving",
"saved": "Saved" "saved": "Saved",
"failed": "Failed"
}, },
"common_dict": { "common_dict": {
"sign_in": "Sign in using:", "sign_in": "Sign in using:",
...@@ -117,6 +118,7 @@ ...@@ -117,6 +118,7 @@
} }
}, },
"validation_dict": { "validation_dict": {
"general": "Please correct the highlighted fields.",
"requires_auth": "Requires authorization.", "requires_auth": "Requires authorization.",
"external": "The input failed the external validator.", "external": "The input failed the external validator.",
"required": "Field is required but not found.", "required": "Field is required but not found.",
......
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