Commit d4a21bcd authored by Sven Franck's avatar Sven Franck

app: setup sinlge page pagination (not working yet)

parent 25947561
...@@ -2762,19 +2762,21 @@ ...@@ -2762,19 +2762,21 @@
}; };
/** Generate a pagination toolbar (controlbar) /** Generate a pagination toolbar (controlbar)
* @method paginate * @method paginationBar
* @param {object} spec Pagination configuration * @param {object} spec Pagination configuration
* @return {object} finished config object * @return {object} finished config object
**/ **/
// TODO: make this a real widget with methods!
factory.util.paginationBar = function (spec) { factory.util.paginationBar = function (spec) {
var n, option, props, option_list, class_list, config; var n, option, props, option_list, class_list, config, len, opts, pointer;
option_list = [{"value": "", "text": "", "text_i18n": ""}]; option_list = [{"value": "", "text": "", "text_i18n": ""}];
opts = spec.option_list || [];
props = spec.slot ? {"slot": spec.slot} : {}; props = spec.slot ? {"slot": spec.slot} : {};
class_list = spec.class_list || ""; class_list = spec.class_list || "";
for (n = 0; n < spec.option_list.length; n += 1) { for (n = 0, len = opts.length; n < len; n += 1) {
option = spec.option_list[n]; option = opts[n];
option_list.push({ option_list.push({
"value": option.value, "value": option.value,
"text": option.text, "text": option.text,
...@@ -2791,52 +2793,70 @@ ...@@ -2791,52 +2793,70 @@
"generate": "widget", "generate": "widget",
"type": "controlgroup", "type": "controlgroup",
"property_dict": {"direction": "horizontal"}, "property_dict": {"direction": "horizontal"},
"children": [{ "children": []
"type": "a",
"direct": {"className": "action", "href": "#"},
"attributes": {
"data-i18n": "global_dict.first",
"data-action": "first",
"data-icon": "step-backward",
"data-iconpos": "notext"
},
"logic": {"text": "First"}
}, {
"type": "a",
"direct": {"className": "action", "href": "#"},
"attributes": {
"data-i18n": "global_dict.previous",
"data-action": "prev",
"data-icon": "backward",
"data-iconpos": "notext"
},
"logic": {"text": "Previous"}
}, {
"type": "select",
"direct": {"id": "select_" + util.uuid(), "className": "action"},
"attributes": {
"data-icon": "bars",
"data-action": "limit",
"data-iconpos": "notext"
},
"logic": {"options": option_list}
}, {
"type": "a",
"direct": {"className": "action", "href": "#"},
"attributes": {
"data-i18n": "global_dict.next",
"data-action": "next",
"data-icon": "forward",
"data-iconpos": "notext"
},
"logic": {"text": "Next"}
}]
}] }]
}; };
pointer = config.children[0].children;
// first
if (!spec.single) {
config.children[0].property_dict.class_list = "ui-pagination-single";
pointer.push({
"type": "a",
"direct": {"className": "action", "href": "#"},
"attributes": {
"data-i18n": "global_dict.first",
"data-action": "first",
"data-icon": "step-backward",
"data-iconpos": "notext"
},
"logic": {"text": "First"}
});
}
// always add previous
pointer.push({
"type": "a",
"direct": {"className": "action", "href": "#"},
"attributes": {
"data-i18n": "global_dict.previous",
"data-action": "prev",
"data-icon": "backward",
"data-iconpos": "notext"
},
"logic": {"text": "Previous"}
});
// select
if (len > 0) {
pointer.push({
"type": "select",
"direct": {"id": "select_" + util.uuid(), "className": "action"},
"attributes": {
"data-icon": "bars",
"data-action": "limit",
"data-iconpos": "notext"
},
"logic": {"options": option_list}
});
}
// always add next
pointer.push({
"type": "a",
"direct": {"className": "action", "href": "#"},
"attributes": {
"data-i18n": "global_dict.next",
"data-action": "next",
"data-icon": "forward",
"data-iconpos": "notext"
},
"logic": {"text": "Next"}
});
// only add last button, if total is available // only add last button, if total is available
if (!app.storage_dict.property_dict.skip_total_records) { if (!app.storage_dict.property_dict.skip_total_records && !spec.single) {
config.children[0].children.push({ pointer.push({
"type": "a", "type": "a",
"direct": {"className": "action", "href": "#"}, "direct": {"className": "action", "href": "#"},
"attributes": { "attributes": {
...@@ -2953,22 +2973,6 @@ ...@@ -2953,22 +2973,6 @@
// content.set..., no need for dynamic content and pointer // content.set..., no need for dynamic content and pointer
map.actions = { map.actions = {
"set_search": function (obj) {
factory.util.setDynamicPointer(obj, "ui_panel_detail_search");
},
"set_filter": function (obj) {
factory.util.setDynamicPointer(obj, "ui_panel_groups");
},
"set_sorting": function (obj) {
factory.util.setDynamicPointer(obj, "ui_panel_sort");
},
"set_sales": function (obj) {
factory.util.setDynamicPointer(obj, "ui_panel_sales");
},
/** /**
* Look up single value from dict * Look up single value from dict
* @method translateLookup * @method translateLookup
...@@ -4856,32 +4860,33 @@ ...@@ -4856,32 +4860,33 @@
* @param {string} value New limit when changing number of records * @param {string} value New limit when changing number of records
*/ */
app.paginate = function (config, type, value) { app.paginate = function (config, type, value) {
var start, records, total, state; var start, records, total, state, current_limit;
state = config.state; state = config.state;
total = state.total; total = state.total;
current_limit = state.query.limit || state.initial_query.limit;
if (config.gadget) { if (config.gadget) {
if (state) { if (state && current_limit) {
switch (type) { switch (type) {
case "first": case "first":
start = 0; start = 0;
records = state.query.limit[1]; records = current_limit[1];
break; break;
case "next": case "next":
start = state.query.limit[0] + state.query.limit[1]; start = current_limit[0] + current_limit[1];
records = state.query.limit[1]; records = current_limit[1];
break; break;
case "prev": case "prev":
start = state.query.limit[0] - state.query.limit[1]; start = current_limit[0] - current_limit[1];
records = state.query.limit[1]; records = current_limit[1];
break; break;
case "last": case "last":
start = total - state.query.limit[1]; start = total - current_limit[1];
records = state.query.limit[1]; records = current_limit[1];
break; break;
case "limit": case "limit":
start = state.query.limit[0]; start = current_limit[0];
records = parseInt(value, null); records = parseInt(value, null);
break; break;
} }
...@@ -4919,7 +4924,7 @@ ...@@ -4919,7 +4924,7 @@
.fail(app.util.error); .fail(app.util.error);
} else { } else {
app.util.error("No state information stored for gadget"); app.util.error("No state/limit information stored for gadget");
} }
} else { } else {
app.util.error("Action is missing reference gadget"); app.util.error("Action is missing reference gadget");
......
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