Commit 556f8af9 authored by Sven Franck's avatar Sven Franck

generic pagination working

parent a2ded3ed
......@@ -70,8 +70,36 @@
erp5.map_actions = {
/**
* generic pagination method going forward
* @method next
* generic pagination method changing number of records displayed
* @method limit
* @param {object} e Event
* @param {string} value Value of select
*/
limit: function (e, value) {
init.paginate(e, "limit", value);
},
/**
* generic pagination method going to first page
* @method first
* @param {object} e Event
*/
first: function (e) {
init.paginate(e, "first");
},
/**
* generic pagination method going to last page
* @method last
* @param {object} e Event
*/
last: function (e) {
init.paginate(e, "last");
},
/**
* generic pagination method going backward
* @method prev
* @param {object} e Event
*/
prev: function (e) {
......@@ -2038,8 +2066,9 @@
* @paginate
* @param {object} e Element triggering pagination
* @param {string} type Where to paginate to
* @param {string} value New limit when changing number of records
*/
init.paginate = function (e, type) {
init.paginate = function (e, type, value) {
var element, gadget, state, id, start, records;
element = e.target;
......@@ -2047,28 +2076,35 @@
gadget = document.getElementById(id);
state = ram_cache[init.getActivePageId()].gadgets[id];
// TODO: validate here again?
if (gadget) {
if (state) {
switch (type) {
case "first":
start = 0;
records = state.query.limit[1];
break;
case "next":
start = state.query.limit[0] + state.query.limit[1];
records = state.query.limit[1];
if (start > state.total) {
return;
}
break;
case "prev":
start = state.query.limit[0] - state.query.limit[1];
records = state.query.limit[1];
if (start < 0) {
return;
}
break;
case "last":
start = state.total - state.query.limit[1];
records = state.query.limit[1];
break;
case "limit":
start = state.query.limit[0];
records = parseInt(value);
break;
};
if (start > state.total || start < 0 ) {
return;
}
// set new limits
state.query.limit = [start, records];
......@@ -2252,6 +2288,7 @@
);
// go fetching...
// TODO: almost same as updating (no field definitions). Combine?
init.fetchConfiguration("settings", "gadgets", gadget_id)
.then(function (gadget_configuration) {
gadget_config = gadget_configuration;
......@@ -2603,18 +2640,32 @@
})
// global actions
.on("click", ".action", function (e) {
var action, handler, test, target, href, element, form, valid;
// stop
e.preventDefault();
.on("click change", ".action", function (e) {
var action, handler, test, target, href, element, form, valid, val;
// stop links triggering
if (e.type === "click") {
e.preventDefault();
if (e.type === "click" && e.target.tagName === "SELECT") {
return;
}
}
if (e.type === "change") {
val = e.target.options[e.target.selectedIndex].value;
}
// JQM bug on selects
// TODO: remove once fixed
if (e.target.tagName === "SPAN" || e.target.tagName === "OPTION") {
return;
}
// map
action = e.target.getAttribute("data-action");
handler = factory.map_actions[action];
if (action) {
if (handler) {
handler(e);
handler(e, val);
} else {
throw "No handler defined for this action!";
}
......@@ -2768,7 +2819,6 @@
}
if (init.storages[attachment]) {
console.log("ENDE");
return;
} else {
// actually this is the only case we end up at
......
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