Commit 8dfd95fb authored by Sven Franck's avatar Sven Franck

fix setContent-flow: test for purge when refreshing gadgets

parent 971e3536
......@@ -273,12 +273,17 @@
// update gadget
app.setContent(
{"generate":"gadget", "id": id, "href": id},
{
"generate":"gadget",
"id": id,
"href": id,
"type": gadget.state.method
},
{
"fragment_list": gadget.state.fragment_list,
"mode": gadget.state.view
},
false,
undefined,
true
)
.then(function (answer){
......@@ -1185,7 +1190,7 @@
* @return {object} fragment
**/
"listgrid": function (spec, answer, field_dict, update, url_pointer) {
var element, i, empty, target;
var element, i, empty, target, placeholder;
// set update of gadget flag
if (spec.property_dict.depends_on) {
......@@ -1197,6 +1202,16 @@
spec.reset = spec.property_dict.resets;
}
// set placeholders
placeholder = spec.placeholder_dict || {};
// no auth
if (answer === null) {
target = factory.util.wrapInForm(spec);
target.appendChild(app.noItemsFound(placeholder.no_auth));
return target;
}
// when updating we only need a fragment container. Otherwise we
// generate the full gadget
if (update) {
......@@ -1395,7 +1410,6 @@
(answer.data === undefined && answer.request_new === undefined)) {
target.appendChild(app.noItemsFound());
} else {
// set data
if (answer && (answer.data || answer.request_new)) {
if (answer.request_new || answer.data.total_rows === 0) {
......@@ -1407,6 +1421,9 @@
util.error({"error": "Fieldlist: More than 1 record"});
} else {
data = answer.data.rows[0].doc;
if (data === undefined) {
util.errorHandler({"error":"fieldlist: include_docs missing"});
}
}
}
......@@ -2127,7 +2144,7 @@
fragment = factory.util.wrapInForm(spec);
secure = spec.property_dict.secure;
item_id = spec.data._id || undefined;
item_id = spec.data ? (spec.data._id || undefined) : undefined;
wrap = function (area, captcha) {
var keys = {};
......@@ -4799,6 +4816,9 @@
case "new":
config.mode = "new";
break;
case "add":
config.mode = "add";
break;
};
}
......@@ -4934,90 +4954,6 @@
document.title = value;
};
/**
* Create/update elements
* @method setupPageElements
* @param {object} content_dict content to be generated
* @param {object} url_dict JSON pointers based on parsed link
* @param {boolean} create Create page/Generate content/Refresh content
* @param {boolean} purge Replace existing element/gadget
* @return {object} promise/HTML element
*/
// TODO: make this always return a promise. Requires to refactor listview!
// TODO: only pass around what we need. pass.CONFIG is too much!
app.setContent = function (content_dict, url_dict, create, purge) {
var i, skip, container, target, pass, spec, dependency;
spec = url_dict || {};
switch (content_dict.generate) {
case "widget":
return factory[content_dict.type](content_dict, spec, create)
case "gadget":
// no portal_type, no dynamic data
if (content_dict.portal_type_source === undefined &&
content_dict.href === undefined) {
pass = {
"skip": true,
"content_dict": content_dict,
"url_dict": spec
};
} else {
// this run needs query and dynamic data
pass = {
"purge": purge || null,
"mode": spec.mode || null,
"create": create,
"layout_level": spec.layout_level || null,
"fragment_list": spec.fragment_list,
"layout": content_dict,
"id": content_dict.id
};
}
// set content constructor
if (create !== false) {
pass.constructor = content_dict.type;
}
// and go
return app.fetchConfiguration({
"storage": app.default_dict.storage_dict.settings,
"file": pass.id ? app.default_dict.storage_dict.gadgets :
app.default_dict.storage_dict.settings,
"attachment": pass.id || app.default_dict.storage_dict.configuration,
"pass": pass
})
.then(app.parseConfiguration)
.then(app.loadFieldDefinition)
// ===== SAMPLE DATA ========
.then(app.testStorageForData)
.then(app.retrieveSampleData)
// ===== SAMPLE DATA ========
.then(app.store)
.then(app.fetchDataTotal)
.then(app.fetchDataQuery)
.then(app.generateGadgetContent)
.fail(util.error);
default:
switch (content_dict.type) {
case "input":
case "select":
return factory.formElement(content_dict, false)
default:
return factory.element(
content_dict.type,
content_dict.direct,
content_dict.attributes,
content_dict.logic,
content_dict.children
);
}
}
};
/**
* cross-browser wrapper for DOMContentLoaded
......@@ -5208,7 +5144,7 @@
* @return {object} response object/promise
*/
app.fetchDataTotal = function (reply) {
var pass = reply.pass, reference;
var pass = reply.pass, reference, identifier, search_string;
if (pass.skip === undefined) {
// create or update state object
......@@ -5232,8 +5168,8 @@
};
// on deeplinks, we have additional query parameters,
// pass them here!
if (pass.layout_level > 0) {
// but we should not do if pass.mode is set!
if (pass.layout_level > 0 && pass.mode === undefined) {
pass.value = pass.fragment_list[pass.layout_level];
}
......@@ -5250,9 +5186,10 @@
}
}
}
if (pass.skip === undefined &&
(pass.no_auth || (pass.auth && pass.active_login ||
pass.mode === "new"))) {
(pass.mode === "new" || pass.purge)))) {
// skip total for single item layouts!
if (pass.config.initial_query) {
......@@ -5261,6 +5198,7 @@
// store the complete initial query, not only the "query"
pass.state.initial_query = pass.config.initial_query;
return app.fetchData({
"pass": pass,
"storage": "items",
......@@ -5384,10 +5322,10 @@
if (reply.response) {
pass.fields = util.parseIfNeeded(reply.response);
}
// try to get 1 record
if (pass.create !== false && pass.config.initial_query &&
(pass.no_auth || (pass.auth && pass.active_login))) {
// try to get 1 record
if ((pass.create !== false || pass.purge) && pass.config.initial_query &&
(pass.no_auth || (pass.auth && pass.active_login))) {
return app.fetchData({
"storage": "items",
"query": app.generateQueryObject({"limit": [0, 1]}, pass.type),
......@@ -5422,7 +5360,6 @@
if (pass.skip === undefined &&
(pass.no_auth || (pass.auth && pass.active_login ||
pass.mode === "new")) &&
//(pass.create !== false || pass.requires_fields) &&
pass.config.portal_type_fields) {
return app.fetchConfiguration({
......@@ -5473,6 +5410,92 @@
}
};
/**
* Create/update elements
* @method setupPageElements
* @param {object} content_dict content to be generated
* @param {object} url_dict JSON pointers based on parsed link
* @param {boolean} create Create page/Generate content/Refresh content
* @param {boolean} purge Replace existing element/gadget
* @return {object} promise/HTML element
*/
// TODO: make this always return a promise. Requires to refactor listview!
// TODO: only pass around what we need. pass.CONFIG is too much!
app.setContent = function (content_dict, url_dict, create, purge) {
var i, skip, container, target, pass, spec, dependency;
spec = url_dict || {};
switch (content_dict.generate) {
case "widget":
return factory[content_dict.type](content_dict, spec, create)
case "gadget":
// no portal_type, no dynamic data
if (content_dict.portal_type_source === undefined &&
content_dict.href === undefined) {
pass = {
"skip": true,
"content_dict": content_dict,
"url_dict": spec
};
} else {
// this run needs query and dynamic data
pass = {
"purge": purge || null,
"mode": spec.mode || null,
"create": create,
"layout_level": spec.layout_level || null,
"fragment_list": spec.fragment_list,
"layout": content_dict,
"id": content_dict.id
};
}
// set content constructor
if (create !== false) {
pass.constructor = content_dict.type;
}
// and go
return app.fetchConfiguration({
"storage": app.default_dict.storage_dict.settings,
"file": pass.id ? app.default_dict.storage_dict.gadgets :
app.default_dict.storage_dict.settings,
"attachment": pass.id || app.default_dict.storage_dict.configuration,
"pass": pass
})
.then(app.parseConfiguration)
.then(app.loadFieldDefinition)
// ===== SAMPLE DATA ========
.then(app.testStorageForData)
.then(app.retrieveSampleData)
// ===== SAMPLE DATA ========
.then(app.store)
.then(app.fetchDataTotal)
.then(app.fetchDataQuery)
.then(app.generateGadgetContent)
.fail(util.error);
default:
switch (content_dict.type) {
case "input":
case "select":
return factory.formElement(content_dict, false)
default:
return factory.element(
content_dict.type,
content_dict.direct,
content_dict.attributes,
content_dict.logic,
content_dict.children
);
}
}
};
/**
* Fetch a configuration file (attachment) from storage. Fallback to
* disk. Successfull fallback file fetches will be stored in JIO.
......
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