Commit d4a21bcd authored by Sven Franck's avatar Sven Franck

app: setup sinlge page pagination (not working yet)

parent 25947561
......@@ -2762,19 +2762,21 @@
};
/** Generate a pagination toolbar (controlbar)
* @method paginate
* @method paginationBar
* @param {object} spec Pagination configuration
* @return {object} finished config object
**/
// TODO: make this a real widget with methods!
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": ""}];
opts = spec.option_list || [];
props = spec.slot ? {"slot": spec.slot} : {};
class_list = spec.class_list || "";
for (n = 0; n < spec.option_list.length; n += 1) {
option = spec.option_list[n];
for (n = 0, len = opts.length; n < len; n += 1) {
option = opts[n];
option_list.push({
"value": option.value,
"text": option.text,
......@@ -2791,52 +2793,70 @@
"generate": "widget",
"type": "controlgroup",
"property_dict": {"direction": "horizontal"},
"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"}
}]
"children": []
}]
};
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
if (!app.storage_dict.property_dict.skip_total_records) {
config.children[0].children.push({
if (!app.storage_dict.property_dict.skip_total_records && !spec.single) {
pointer.push({
"type": "a",
"direct": {"className": "action", "href": "#"},
"attributes": {
......@@ -2953,22 +2973,6 @@
// content.set..., no need for dynamic content and pointer
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
* @method translateLookup
......@@ -4856,32 +4860,33 @@
* @param {string} value New limit when changing number of records
*/
app.paginate = function (config, type, value) {
var start, records, total, state;
var start, records, total, state, current_limit;
state = config.state;
total = state.total;
current_limit = state.query.limit || state.initial_query.limit;
if (config.gadget) {
if (state) {
if (state && current_limit) {
switch (type) {
case "first":
start = 0;
records = state.query.limit[1];
records = current_limit[1];
break;
case "next":
start = state.query.limit[0] + state.query.limit[1];
records = state.query.limit[1];
start = current_limit[0] + current_limit[1];
records = current_limit[1];
break;
case "prev":
start = state.query.limit[0] - state.query.limit[1];
records = state.query.limit[1];
start = current_limit[0] - current_limit[1];
records = current_limit[1];
break;
case "last":
start = total - state.query.limit[1];
records = state.query.limit[1];
start = total - current_limit[1];
records = current_limit[1];
break;
case "limit":
start = state.query.limit[0];
start = current_limit[0];
records = parseInt(value, null);
break;
}
......@@ -4919,7 +4924,7 @@
.fail(app.util.error);
} else {
app.util.error("No state information stored for gadget");
app.util.error("No state/limit information stored for gadget");
}
} else {
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