Commit 455efc7d authored by Sven Franck's avatar Sven Franck

fixed bug in login, made gadget updates generic, added auth/empty handler to gadgets

parent 9f25e8c1
...@@ -212,7 +212,8 @@ ...@@ -212,7 +212,8 @@
**/ **/
// TODO: failed login? // TODO: failed login?
"login_user": function (obj) { "login_user": function (obj) {
var signature, match_string, reply, element, active, hashed_list; var signature, match_string, reply, element, active, hashed_list,
gadget_list, i, gadget, id, fragment_list;
// create signature and ticket // create signature and ticket
element = obj.element; element = obj.element;
...@@ -255,28 +256,35 @@ ...@@ -255,28 +256,35 @@
util.loader("", "global_dict.status_dict.saving"); util.loader("", "global_dict.status_dict.saving");
return app.register(obj.id) return app.register(obj.id)
.then(function() { .then(function() {
// TODO: find a way to access an element that is depending on // TODO: find way to get gadget ID... or update all gadgets inside
// the login status! // the page!
// update which would be closest form... gadget_list = document.getElementById(util.getActivePage())
var el = document.getElementsByTagName("form")[0]; .getElementsByTagName("form");
var config = {"state": el.state};
for (i = 0; i < gadget_list.length; i += 1) {
// update gadget gadget = gadget_list[i];
app.setContent( id = gadget.state.id;
{"generate":"gadget", "id": "person_view", "href": "person_view"}, fragment_list = gadget.state.fragment_list;
{"fragment_list": config.state.fragment_list},
false, if (gadget.getAttribute("data-depend") === "login_state") {
true // update gadget
) app.setContent(
.then(function (answer){ {"generate":"gadget", "id": id, "href": id},
el.parentNode.replaceChild(answer, el); {"fragment_list": fragment_list},
}) false,
.then(app.setPageBindings) true
.fail(util.error); )
.then(function (answer){
gadget.parentNode.replaceChild(answer, gadget);
})
.then(app.setPageBindings)
.fail(util.error);
}
}
}) })
.fail(util.error);
}) })
.fail(util.error); .fail(util.error);
}, },
/** /**
...@@ -1154,6 +1162,11 @@ ...@@ -1154,6 +1162,11 @@
"listgrid": function (spec, answer, field_dict, update, url_pointer) { "listgrid": function (spec, answer, field_dict, update, url_pointer) {
var element, i, empty, target; var element, i, empty, target;
// set update of gadget flag
if (spec.property_dict.depends_on) {
spec.depend = spec.property_dict.depends_on;
}
// when updating we only need a fragment container. Otherwise we // when updating we only need a fragment container. Otherwise we
// generate the full gadget // generate the full gadget
if (update) { if (update) {
...@@ -1214,6 +1227,11 @@ ...@@ -1214,6 +1227,11 @@
var element, i, empty, target, container, pack, slot, pop, active, var element, i, empty, target, container, pack, slot, pop, active,
placeholder; placeholder;
// set update of gadget flag
if (spec.property_dict.depends_on) {
spec.depend = spec.property_dict.depends_on;
}
// set placeholders // set placeholders
placeholder = spec.placeholder_dict || {}; placeholder = spec.placeholder_dict || {};
...@@ -1311,20 +1329,24 @@ ...@@ -1311,20 +1329,24 @@
* @return {object} fragment * @return {object} fragment
**/ **/
"fieldlist": function (spec, answer, field_dict, update, url_pointer) { "fieldlist": function (spec, answer, field_dict, update, url_pointer) {
var i, element, target, placeholder; var i, element, target, placeholder, update_gadget;
// set update of gadget flag
if (spec.property_dict.depends_on) {
update_gadget = spec.property_dict.depends_on;
}
// set placeholders // set placeholders
placeholder = spec.placeholder_dict || {}; placeholder = spec.placeholder_dict || {};
// no auth // no auth, no allow
// console.log("so what is answer")
// console.log(answer)
// console.log(answer === null)
if (answer === null) { if (answer === null) {
spec.depend = update_gadget;
target = factory.util.wrapInForm(spec); target = factory.util.wrapInForm(spec);
target.appendChild(app.noItemsFound(placeholder.no_auth)); target.appendChild(app.noItemsFound(placeholder.no_auth));
return target; return target;
// auth or allow
} else { } else {
target = document.createDocumentFragment(); target = document.createDocumentFragment();
...@@ -1335,7 +1357,7 @@ ...@@ -1335,7 +1357,7 @@
for (i = 0; i < spec.children.length; i += 1) { for (i = 0; i < spec.children.length; i += 1) {
element = spec.children[i]; element = spec.children[i];
// new // dynamic form
if (element.type === "form") { if (element.type === "form") {
if (answer && (answer.data || answer.request_new)) { if (answer && (answer.data || answer.request_new)) {
if (answer.request_new || answer.data.total_rows === 0) { if (answer.request_new || answer.data.total_rows === 0) {
...@@ -1349,6 +1371,7 @@ ...@@ -1349,6 +1371,7 @@
element.data = answer.data.rows[0].doc; element.data = answer.data.rows[0].doc;
} }
} }
element.depend = update_gadget;
element.form = spec.form; element.form = spec.form;
element.fields = field_dict; element.fields = field_dict;
element.id = spec.id; element.id = spec.id;
...@@ -1611,7 +1634,7 @@ ...@@ -1611,7 +1634,7 @@
"className": (spec.class_list || "") "className": (spec.class_list || "")
}, },
{"data-ajax": false, "autocomplete":"off"}, {"data-ajax": false, "autocomplete":"off"},
{"data-set": spec.update || null} {"data-depend": spec.depend || null}
); );
} }
return document.createDocumentFragment(); return document.createDocumentFragment();
...@@ -2056,9 +2079,6 @@ ...@@ -2056,9 +2079,6 @@
position, doc, config, value, stamp, sauce, encode, secure, position, doc, config, value, stamp, sauce, encode, secure,
safety_box, noscript, fragment, wrap; safety_box, noscript, fragment, wrap;
if (spec.property_dict.update) {
spec.update = spec.property_dict.update;
}
fragment = factory.util.wrapInForm(spec); fragment = factory.util.wrapInForm(spec);
secure = spec.property_dict.secure; secure = spec.property_dict.secure;
...@@ -3770,7 +3790,7 @@ ...@@ -3770,7 +3790,7 @@
.then(function(answer) { .then(function(answer) {
// TODO: This is not the correct place to run all status updates! // TODO: This is not the correct place to run all status updates!
if (answer.response.result === "success") { if (answer.response.result === "success") {
switch (config.gadget.getAttribute("data-set")) { switch (config.gadget.getAttribute("data-reset")) {
case "login_state": case "login_state":
app.setLoginStatus(answer.response, config.portal_type_source); app.setLoginStatus(answer.response, config.portal_type_source);
break; break;
...@@ -4261,7 +4281,6 @@ ...@@ -4261,7 +4281,6 @@
"issued": stamp, "issued": stamp,
"expires": auth ? auth.expires_in : 3600 "expires": auth ? auth.expires_in : 3600
} }
// 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");
...@@ -4326,7 +4345,7 @@ ...@@ -4326,7 +4345,7 @@
// test for timeout // test for timeout
if (auth_config.issued && auth_config.expires) { if (auth_config.issued && auth_config.expires) {
expires = auth_config.issued + auth_config.expires; expires = auth_config.issued + auth_config.expires;
if (expires < stamp) { if (expires > stamp) {
valid = true; valid = true;
} else { } else {
expired = true; expired = true;
...@@ -4336,6 +4355,7 @@ ...@@ -4336,6 +4355,7 @@
} }
} }
} }
// token in memory still valid, add it to the pass object and done // token in memory still valid, add it to the pass object and done
if (valid) { if (valid) {
if (pass) { if (pass) {
...@@ -4844,7 +4864,6 @@ ...@@ -4844,7 +4864,6 @@
return factory[content_dict.type](content_dict, spec, create) return factory[content_dict.type](content_dict, spec, create)
case "gadget": case "gadget":
console.log("setContent: 'Rendering' a gadget. If no portal type is defined, nothing is loaded");
// no portal_type, no dynamic data // no portal_type, no dynamic data
if (content_dict.portal_type_source === undefined && if (content_dict.portal_type_source === undefined &&
content_dict.href === undefined) { content_dict.href === undefined) {
...@@ -4865,7 +4884,6 @@ ...@@ -4865,7 +4884,6 @@
"id": content_dict.id "id": content_dict.id
}; };
} }
// set content constructor // set content constructor
if (create !== false) { if (create !== false) {
pass.constructor = content_dict.type; pass.constructor = content_dict.type;
...@@ -4961,33 +4979,38 @@ ...@@ -4961,33 +4979,38 @@
* @return {object} response object/promise * @return {object} response object/promise
*/ */
app.generateGadgetContent = function (reply) { app.generateGadgetContent = function (reply) {
var selector, element, pass, constructor, translate, request_new; var selector, element, pass, constructor, translate, data, data_set;
pass = reply.pass; pass = reply.pass;
constructor = map.gadgets[pass.constructor]; constructor = map.gadgets[pass.constructor];
// set answer depending on mode=new and auth
if (pass.mode === "new") {
if (pass.auth && pass.active_login === false) {
request_new = null;
} else {
request_new = {"request_new": true}
}
}
if (constructor === undefined) { if (constructor === undefined) {
util.error( return util.error(
{"error":"generateGadgetContent: Missing constructor"} {"error":"generateGadgetContent: Missing constructor"}
); );
} }
// set data depending on auth
if (pass.no_auth || (pass.auth && pass.active_login)) {
data = reply.response ? util.parseIfNeeded(reply.response) : null;
data_set = true;
} else {
data = null;
}
// overwrite depending on new and allow_new
if (pass.mode === "new" && (data_set || pass.config.property_dict.allow_new)) {
data = {"request_new": true};
}
// no content? Just call constructor and DONE! // no content? Just call constructor and DONE!
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,
(reply.response ? util.parseIfNeeded(reply.response) : request_new), data,
pass.fields, pass.fields,
(pass.create === false ? true : null), (pass.create === false ? true : null),
{"layout": (pass.layout_level || 0), "fragment_list": pass.fragment_list} {"layout": (pass.layout_level || 0), "fragment_list": pass.fragment_list}
...@@ -5100,10 +5123,12 @@ ...@@ -5100,10 +5123,12 @@
pass.store_limit = pass.state.query.limit; pass.store_limit = pass.state.query.limit;
pass.state.query.limit = []; pass.state.query.limit = [];
} else { } else {
pass.state = {}; pass.state = {
pass.state.type = pass.type; "type": pass.type,
pass.state.method = pass.constructor; "method": pass.constructor,
pass.state.fragment_list = pass.fragment_list; "fragment_list": pass.fragment_list,
"id": pass.id
};
// on deeplinks, we have additional query parameters, // on deeplinks, we have additional query parameters,
// pass them here! // pass them here!
...@@ -5185,8 +5210,7 @@ ...@@ -5185,8 +5210,7 @@
method = "put"; method = "put";
obj._id = obj.identifier; obj._id = obj.identifier;
} }
console.log("storing an item, METHOD = "+(method || "post") + " STORAGE = items");
console.log(obj)
promises[i] = store[method || "post"](obj) promises[i] = store[method || "post"](obj)
.then(function(answer) { .then(function(answer) {
return answer; return answer;
...@@ -5361,8 +5385,7 @@ ...@@ -5361,8 +5385,7 @@
// need to make a promise to not break the chain // need to make a promise to not break the chain
return RSVP.resolve({"pass": parcel.pass}); return RSVP.resolve({"pass": parcel.pass});
} }
console.log("app.fetchConfiguration > GETATTACHMENT, STORAGE = " + parcel.storage);
console.log({"_id": parcel.file, "_attachment": parcel.attachment});
store = storage[parcel.storage]; store = storage[parcel.storage];
return store.getAttachment({ return store.getAttachment({
...@@ -5407,8 +5430,6 @@ ...@@ -5407,8 +5430,6 @@
*/ */
// NOTE: until we have real data we load fake data on application init! // NOTE: until we have real data we load fake data on application init!
app.fetchData = function (parcel) { app.fetchData = function (parcel) {
console.log("app.fetchData > trying items, ALLDOCS, STORAGE = " +parcel.storage)
console.log(parcel.query)
return storage[parcel.storage].allDocs(parcel.query) return storage[parcel.storage].allDocs(parcel.query)
.then(function (response) { .then(function (response) {
return { return {
...@@ -5460,19 +5481,11 @@ ...@@ -5460,19 +5481,11 @@
util.error({"error": "getFromDisk: no storage defined"}); util.error({"error": "getFromDisk: no storage defined"});
return RSVP.all([]); return RSVP.all([]);
} }
console.log("getFromDisk: Store sample data, METHOD = put, STORAGE = " + app.default_dict.storage_dict.settings)
console.log({"_id": (property_dict.file || app.default_dict.storage_dict.settings)});
return storage_location.put({ return storage_location.put({
"_id": (property_dict.file || app.default_dict.storage_dict.settings) "_id": (property_dict.file || app.default_dict.storage_dict.settings)
}) })
.then(function () { .then(function () {
console.log("getFromDisk: Store sample data as attachment, METHOD: putAttachment, Storage = "+app.default_dict.storage_dict.settings)
console.log({
"_id": (property_dict.file || app.default_dict.storage_dict.settings),
"_attachment": (property_dict.attachment || app.default_dict.storage_dict.configuration),
"_data": JSON.stringify(response),
"_mimetype": "application/json"
});
return storage_location.putAttachment({ return storage_location.putAttachment({
"_id": (property_dict.file || app.default_dict.storage_dict.settings), "_id": (property_dict.file || app.default_dict.storage_dict.settings),
"_attachment": (property_dict.attachment || app.default_dict.storage_dict.configuration), "_attachment": (property_dict.attachment || app.default_dict.storage_dict.configuration),
......
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