Commit e0036dff authored by Sven Franck's avatar Sven Franck

app: add spawn method to multiply records based on array in record

parent c70ef8b4
......@@ -2882,7 +2882,7 @@
return config;
};
// TODO: remove, should be handled by content.set
// TODO: remove, should be handled by content.set!!!
// TODO: why is this not done on click, when we can get the href > element
// from the link attribute?
/**
......@@ -2928,6 +2928,7 @@
element.appendChild(content);
})
.then(function () {
// need this call otherwise loaded content is not enhanced
$el = $(element).enhanceWithin();
// TODO: un-jQuery eventually...
......@@ -6308,13 +6309,12 @@
};
// TODO: determine value to query based on URL (this stinks...)
if (lib.layout_level > 0) {
// NOTE: picking value from URL if specified
if (lib.layout_level > 0 &&
dict.property_dict.initial_query_url_identifier) {
last = lib.fragment_list.slice(-1)[0];
pass.data_dict.value = lib.fragment_list[lib.layout_level];
if (!lib.mode || last !== lib.mode) {
pass.data_dict.value =
lib.fragment_list[lib.layout_level];
}
}
// generate query object
......@@ -6733,9 +6733,14 @@
if (is_parameter) {
kid = app.util.setParam(kid, wrapper);
}
// ===================================================================
// spawn children based on trigger field (must be array)
if (kid.property_dict && kid.property_dict.spawn_on) {
kid.children = app.util.spawn(kid.children, kid.property_dict.spawn_on);
kid.property_dict.total_rows = kid.children.length;
}
// ===================================================================
if (quirk_dict.update !== true || is_dynamic || quirk_dict.dynamic) {
// for content loaded via href, generate URL dict and undefine kid
......@@ -6960,6 +6965,37 @@
/* ********************************************************************** */
app.util = {};
/** Spawn (multiply children based on an array (so far only used when
* an item returns an array of strings and we need items for every string
* (carousel)
* @method spawn
* @param {Array} kids Original array
* @param {String} trig Trigger field
* @returns {Array} new Array
*/
// TODO: really necessary like this...? Store data differently!
// Like store image urls and make a query on "items"
app.util.spawn = function (kids, trig) {
var i, j, trig_len, len, kid, arr, clone, new_kids, new_kid;
new_kids = [];
for (i = 0, len = kids.length; i < len; i += 1) {
kid = kids[i];
arr = kid.doc[trig];
if (Array.isArray(arr)) {
for (j = 0, trig_len = arr.length; j < trig_len; j += 1) {
new_kid = util.cloneObject(kid);
new_kid.doc[trig] = arr[j];
new_kids.push(new_kid);
}
} else {
new_kids.push(kid);
}
}
return new_kids;
};
/** Fetch a subordinate record to set values of an object
* @method setSubordinate
* @method setParam
......
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