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