Commit 661a7b66 authored by Sven Franck's avatar Sven Franck

bugfix: corrections on JIO text search

parent 5f590283
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
{"type":"a", "direct":{"href":"", "className":"action"}, "attributes":{"data-i18n":"", "data-action":"last", "data-icon":"step-forward", "data-iconpos":"notext"}, "logic":{"text": "Last"}}]} {"type":"a", "direct":{"href":"", "className":"action"}, "attributes":{"data-i18n":"", "data-action":"last", "data-icon":"step-forward", "data-iconpos":"notext"}, "logic":{"text": "Last"}}]}
], ],
"controlbar": [ "controlbar": [
{"global_search": true, "element": {"type": "input", "direct":{"id":"global_search_invoices", "className": ""},"attributes":{"data-action":"search", "data-enhanced":"true", "data-i18n": "","placeholder":"Search Invoices", "data-icon":"search", "data-action-btn":"true", "data-type":"search", "type":"search"},"logic":{"clear":"true", "action":"search"}}, "children":[]}, {"global_search": true, "element": {"type": "input", "direct":{"id":"global_search_invoices", "className": "action"},"attributes":{"data-action":"search", "data-enhanced":"true", "data-i18n": "","placeholder":"Search Invoices", "data-icon":"search", "data-type":"search", "type":"search"},"logic":{"clear":"true"}}, "children":[]},
{"record_info": true, "element": {"type": "div", "direct": {"className":"info"}, "attributes": {"data-info":"records"}}, "children":[]}, {"record_info": true, "element": {"type": "div", "direct": {"className":"info"}, "attributes": {"data-info":"records"}}, "children":[]},
{"select_info": true, "element": {"type": "div", "direct": {"className":"info"}, "attributes": {"data-info":"selected"}}, "children":[]}, {"select_info": true, "element": {"type": "div", "direct": {"className":"info"}, "attributes": {"data-info":"selected"}}, "children":[]},
{"filter_info": true, "element": {"type": "div", "direct": {"className":"info"}, "attributes": {"data-info":"filter"}}, "children":[]} {"filter_info": true, "element": {"type": "div", "direct": {"className":"info"}, "attributes": {"data-info":"filter"}}, "children":[]}
......
...@@ -72,71 +72,73 @@ ...@@ -72,71 +72,73 @@
/** /**
* generic pagination method changing number of records displayed * generic pagination method changing number of records displayed
* @method limit * @method limit
* @param {object} e Event * @param {object} obj Action Object
* @param {string} value Value of select * @param {string} value Value of select
*/ */
limit: function (e, value) { limit: function (obj, value) {
init.paginate(e, "limit", value); init.paginate(obj, "limit", value);
}, },
/** /**
* generic pagination method going to first page * generic pagination method going to first page
* @method first * @method first
* @param {object} e Event * @param {object} obj Action Object
*/ */
first: function (e) { first: function (obj) {
init.paginate(e, "first"); init.paginate(obj, "first");
}, },
/** /**
* generic pagination method going to last page * generic pagination method going to last page
* @method last * @method last
* @param {object} e Event * @param {object} obj Action Object
*/ */
last: function (e) { last: function (obj) {
init.paginate(e, "last"); init.paginate(obj, "last");
}, },
/** /**
* generic pagination method going backward * generic pagination method going backward
* @method prev * @method prev
* @param {object} e Event * @param {object} obj Action Object
*/ */
prev: function (e) { prev: function (obj) {
init.paginate(e, "prev"); init.paginate(obj, "prev");
}, },
/** /**
* generic pagination method going forward * generic pagination method going forward
* @method next * @method next
* @param {object} e Event * @param {object} obj Action Object
*/ */
next: function (e) { next: function (obj) {
init.paginate(e, "next"); init.paginate(obj, "next");
}, },
/** /**
* switch sorting state and trigger update of gadget * switch sorting state and trigger update of gadget
* @method sort * @method sort
* @param {object} e Event * @param {object} obj Action Object
*/ */
sort: function (e) { sort: function (obj) {
// sorting 5-states (none|abc_asc|123_asc|abc_desc|123_desc) // sorting 5-states (none|abc_asc|123_asc|abc_desc|123_desc)
switch (e.target.getAttribute("data-direction")) { switch (obj.element.getAttribute("data-direction")) {
case "desc_abc": case "desc_abc":
init.sort(e, "desc_123", "sort-by-alphabet-alt", "sort-by-order-alt"); init.sort(
obj, "desc_123", "sort-by-alphabet-alt", "sort-by-order-alt"
);
break; break;
case "desc_123": case "desc_123":
init.sort(e, "asc_abc", "sort-by-order-alt", "sort-by-alphabet"); init.sort(obj, "asc_abc", "sort-by-order-alt", "sort-by-alphabet");
break; break;
case "asc_abc": case "asc_abc":
init.sort(e, "asc_123", "sort-by-alphabet", "sort-by-order"); init.sort(obj, "asc_123", "sort-by-alphabet", "sort-by-order");
break; break;
case "asc_123": case "asc_123":
init.sort(e, undefined, "sort-by-order", "sort"); init.sort(obj, undefined, "sort-by-order", "sort");
break; break;
default: default:
init.sort(e, "desc_abc", "sort", "sort-by-alphabet-alt"); init.sort(obj, "desc_abc", "sort", "sort-by-alphabet-alt");
break; break;
} }
}, },
...@@ -144,29 +146,29 @@ ...@@ -144,29 +146,29 @@
/** /**
* selecting single checkbox * selecting single checkbox
* @method check * @method check
* @param {object} e Event * @param {object} obj Action Object
*/ */
check: function (e) { check: function (obj) {
init.check(e, undefined); init.check(obj, undefined);
}, },
/** /**
* select all visible rows (default) * select all visible rows (default)
* @method check_all_visible * @method check_all_visible
* @param {object} e Event * @param {object} obj Action Object
*/ */
check_all_visible: function (e) { check_all_visible: function (obj) {
init.check(e, false); init.check(obj, false);
}, },
/** /**
* select ALL rows (visible and not visible) * select ALL rows (visible and not visible)
* @method check_all * @method check_all
* @param {object} e Event * @param {object} obj Action Object
*/ */
// NOTE: checkbox has 3 states (this hijacks indeterminate state!!!) // NOTE: checkbox has 3 states (this hijacks indeterminate state!!!)
check_all: function (e) { check_all: function (obj) {
var checkbox = e.target, var checkbox = obj.element,
label = checkbox.previousSibling; label = checkbox.previousSibling;
if (checkbox.checked) { if (checkbox.checked) {
...@@ -189,17 +191,17 @@ ...@@ -189,17 +191,17 @@
); );
} }
} }
// create visual and state // create visual and state
init.check(e, true); init.check(obj, true);
}, },
/** /**
* search (default) * search (default)
* @method search * @method search
* @param {object} e Event triggering action * @param {object} obj Action Object
*/ */
search: function (e) { search: function (obj) {
init.search(e); init.search(obj);
} }
}; };
...@@ -1888,8 +1890,6 @@ ...@@ -1888,8 +1890,6 @@
// just block JQM here! We handle this through action! // just block JQM here! We handle this through action!
$(element).on("filterablebeforefilter", function (e) { $(element).on("filterablebeforefilter", function (e) {
e.preventDefault(); e.preventDefault();
// run the search
// init.search(data.input[0]);
}); });
}) })
...@@ -2065,6 +2065,8 @@ ...@@ -2065,6 +2065,8 @@
// TODO: remove this to ERP5 handler // TODO: remove this to ERP5 handler
switch (info_field.getAttribute("data-info")) { switch (info_field.getAttribute("data-info")) {
case "records": case "records":
console.log("SO records..:");
console.log(total);
if (total && total > 0) { if (total && total > 0) {
info = options.limit[0] + "-" + info = options.limit[0] + "-" +
(options.limit[0] + options.limit[1]) + (options.limit[0] + options.limit[1]) +
...@@ -2185,14 +2187,13 @@ ...@@ -2185,14 +2187,13 @@
/** /**
* Highlight checkboxes and set a state on items selected * Highlight checkboxes and set a state on items selected
* @method check * @method check
* @param {object} e Event triggering the check action * @param {object} config Action Object
* @param {boolean} all Boolean determining whether to check all records * @param {boolean} all Boolean determining whether to check all records
*/ */
//TODO: promisable? //TODO: promisable?
init.check = function (e, all) { init.check = function (config, all) {
var i, var i,
j, j,
config,
rows, rows,
checks, checks,
check, check,
...@@ -2202,7 +2203,6 @@ ...@@ -2202,7 +2203,6 @@
state, state,
ids; ids;
config = init.generateActionObject(e);
state = config.state; state = config.state;
checked_or_not = config.element.checked; checked_or_not = config.element.checked;
id = config.element.id.replace("select_",""); id = config.element.id.replace("select_","");
...@@ -2224,7 +2224,7 @@ ...@@ -2224,7 +2224,7 @@
if (checks.length > 0) { if (checks.length > 0) {
check = checks[0]; check = checks[0];
if (check.type === "checkbox") { if (check.type === "checkbox") {
// status is communicated via e // status is communicated via action object
check.checked = checked_or_not; check.checked = checked_or_not;
ids.push(check.id); ids.push(check.id);
// need to JQM refresh... // need to JQM refresh...
...@@ -2281,7 +2281,7 @@ ...@@ -2281,7 +2281,7 @@
return; return;
} }
} }
console.log("RUNNING")
if (type === "change" && tag === "SELECT") { if (type === "change" && tag === "SELECT") {
val = e.target.options[e.target.selectedIndex].value; val = e.target.options[e.target.selectedIndex].value;
} }
...@@ -2296,7 +2296,11 @@ ...@@ -2296,7 +2296,11 @@
if (action) { if (action) {
if (handler) { if (handler) {
handler(e, val); console.log("GO")
console.log(handler)
console.log(init.generateActionObject(e))
console.log(val)
handler(init.generateActionObject(e), val);
} else { } else {
throw "No handler defined for this action!"; throw "No handler defined for this action!";
} }
...@@ -2314,10 +2318,10 @@ ...@@ -2314,10 +2318,10 @@
* @param {string} prev Previous icon * @param {string} prev Previous icon
* @param {string} next Next icon * @param {string} next Next icon
*/ */
init.sort = function (e, direction, prev, next) { // TODO: move this into a common JIO function generateQueryObject!
var config, column, i, in_array; init.sort = function (config, direction, prev, next) {
var i, in_array, column;
config = init.generateActionObject(e);
column = config.element.getAttribute("data-column-title"); column = config.element.getAttribute("data-column-title");
// change button right away // change button right away
...@@ -2327,7 +2331,7 @@ ...@@ -2327,7 +2331,7 @@
util.filterForClass("ui-icon-" + prev), " ui-icon-" + next util.filterForClass("ui-icon-" + prev), " ui-icon-" + next
); );
// trigger sort after 300ms delay, so user can pick sorting criteria // trigger sort after 500ms delay, so user can pick sorting criteria
if (init.timer) { if (init.timer) {
window.clearTimeout(init.timer); window.clearTimeout(init.timer);
init.timer = 0; init.timer = 0;
...@@ -2387,13 +2391,11 @@ ...@@ -2387,13 +2391,11 @@
/** /**
* Handler for search * Handler for search
* @method search * @method search
* @param {object} e Element triggering search * @param {object} config Action Object
*/ */
init.search = function (e) { // TODO: move into JIO method generateQueryObject
var config, value; init.search = function (config) {
var value = config.element.value;
config = init.generateActionObject(e);
value = config.element.value;
// need to search all columns for this value // need to search all columns for this value
init.fetchConfiguration("settings", "gadgets", config.id) init.fetchConfiguration("settings", "gadgets", config.id)
...@@ -2428,6 +2430,8 @@ ...@@ -2428,6 +2430,8 @@
} }
config.state.query.query = query; config.state.query.query = query;
// we only want x records
// update gadget // update gadget
init.updatePageElement( init.updatePageElement(
config.element, config.id, config.gadget, config.state config.element, config.id, config.gadget, config.state
...@@ -2442,14 +2446,13 @@ ...@@ -2442,14 +2446,13 @@
/** /**
* Handler for pagination * Handler for pagination
* @method paginate * @method paginate
* @param {object} e Element triggering pagination * @param {object} config Action Object
* @param {string} type Where to paginate to * @param {string} type Where to paginate to
* @param {string} value New limit when changing number of records * @param {string} value New limit when changing number of records
*/ */
init.paginate = function (e, type, value) { // TODO: move into JIO method generateQueryObject
var config, start, records; init.paginate = function (config, type, value) {
var start, records;
config = init.generateActionObject(e);
if (config.gadget) { if (config.gadget) {
if (config.state) { if (config.state) {
...@@ -2544,24 +2547,26 @@ ...@@ -2544,24 +2547,26 @@
* @param {object} state of this element * @param {object} state of this element
*/ */
init.updatePageElement = function (element, id, gadget, state) { init.updatePageElement = function (element, id, gadget, state) {
var config, items; var config, items, total, actual, all;
// fetch config and items // fetch config and items
init.fetchConfiguration("settings", "gadgets", id) init.fetchConfiguration("settings", "gadgets", id)
.then(function(gadget_config) { .then(function (gadget_config) {
config = gadget_config; config = gadget_config;
actual = state.query.limit;
all = state.query;
all.limit = [];
return init.fetchData("items", all);
}) })
.then(function() { .then(function(total_records) {
total = total_records.data.total_rows;
state.query.limit = actual;
return init.fetchData("items", state.query); return init.fetchData("items", state.query);
}) })
.then(function(query_items) { .then(function(query_items) {
items = query_items; items = query_items;
init.cacheGadgetState( init.cacheGadgetState(
id, id, state.query, state.total, state.method, state.selected
state.query,
state.total,
state.method,
state.selected
); );
}) })
.then(function () { .then(function () {
...@@ -2608,7 +2613,7 @@ ...@@ -2608,7 +2613,7 @@
gadget, gadget,
gadget_id, gadget_id,
gadget_config, gadget_config,
portal_type, type,
fields, fields,
fragment, fragment,
promises = []; promises = [];
...@@ -2662,23 +2667,16 @@ ...@@ -2662,23 +2667,16 @@
gadget.getAttribute("data-gadget") gadget.getAttribute("data-gadget")
); );
// go fetching... // TODO: merge with updatePageElement
// TODO: almost same as updating (no field definitions). Combine?
promises[i] = init.fetchConfiguration("settings", "gadgets", gadget_id) promises[i] = init.fetchConfiguration("settings", "gadgets", gadget_id)
.then(function (gadget_configuration) { .then(function (gadget_configuration) {
gadget_config = gadget_configuration; gadget_config = gadget_configuration;
portal_type = gadget_config.portal_type_source; type = gadget_config.portal_type_source;
options = init.buildQueryObject( options = init.buildQueryObject(
gadget_configuration.initial_query, gadget_configuration.initial_query,
portal_type type
);
})
.then(function() {
return init.fetchConfiguration(
"settings",
"portal_types",
portal_type
); );
return init.fetchConfiguration("settings", "portal_types", type);
}) })
.then(function (field_definitions) { .then(function (field_definitions) {
fields = field_definitions; fields = field_definitions;
...@@ -2687,22 +2685,18 @@ ...@@ -2687,22 +2685,18 @@
// TODO: remove this and all FakeData methods once ERP5 access is ok // TODO: remove this and all FakeData methods once ERP5 access is ok
// ================================================== // ==================================================
.then(function () { .then(function () {
return init.testForFakeDump("items", portal_type); return init.testForFakeDump("items", type);
}) })
.then(function(item_check) { .then(function(item_check) {
if (item_check.data.total_rows === 0) { if (item_check.data.total_rows === 0) {
fetch = true; fetch = true;
} }
})
.then(function() {
return init.fetchFakeData(gadget_id); return init.fetchFakeData(gadget_id);
}) })
.then(function(fake_items) { .then(function(fake_items) {
if (fetch) { if (fetch) {
return init.dumpFakeData( return init.dumpFakeData(
fake_items, fake_items, gadget_config.portal_type_source, "items"
gadget_config.portal_type_source,
"items"
); );
} }
}) })
...@@ -2727,11 +2721,7 @@ ...@@ -2727,11 +2721,7 @@
.then(function() { .then(function() {
// generate gadget contents // generate gadget contents
fragment = factory.map_gadgets[method]( fragment = factory.map_gadgets[method](
gadget_config, gadget_config, items, fields, options, total
items,
fields,
options,
total
); );
$(parent).empty().append( fragment ).enhanceWithin(); $(parent).empty().append( fragment ).enhanceWithin();
}) })
...@@ -2992,7 +2982,6 @@ ...@@ -2992,7 +2982,6 @@
*/ */
init.setGlobalBindings = function () { init.setGlobalBindings = function () {
// need jQuery again...
$(document) $(document)
.enhanceWithin() .enhanceWithin()
...@@ -3016,10 +3005,20 @@ ...@@ -3016,10 +3005,20 @@
// global actions // global actions
.on("click change keyup input", ".action", function (e) { .on("click change keyup input", ".action", function (e) {
//var test, target, href, element, form, valid; var val, last,
element = e.target,
type = element.type;
// delay all input field actions allowing user to type/select
if (element.tagName === "INPUT" &&
(type !== "button" && type !== "checkbox")) {
// delay all input actions allowing user to type/select val = element.value,
if (e.target.tagName === "INPUT" && e.target.type !== "button") { last = element.getAttribute("data-last")
if (last && last === val) {
return;
}
if (init.timer) { if (init.timer) {
window.clearTimeout(init.timer); window.clearTimeout(init.timer);
...@@ -3028,19 +3027,18 @@ ...@@ -3028,19 +3027,18 @@
// give user half second to pick his state // give user half second to pick his state
init.timer = window.setTimeout(function () { init.timer = window.setTimeout(function () {
element.setAttribute("data-last", val);
init.action(e); init.action(e);
init.timer = 0; init.timer = 0;
}, 500); }, 500);
} else { } else {
init.action(e); init.action(e);
} }
// switch (reference) {
//
// // global form submit
// case "submit":
// form = document.getElementById(e.target.getAttribute("data-form")); // form = document.getElementById(e.target.getAttribute("data-form"));
// target = e.target.href; // target = e.target.href;
// //
...@@ -3068,10 +3066,7 @@ ...@@ -3068,10 +3066,7 @@
// // }; // // };
// // // //
// // // stop // // // stop
// //
// //
// //
// //
// // // fetch and proceed // // // fetch and proceed
// // if (valid !== false) { // // if (valid !== false) {
// // $.ajax({ // // $.ajax({
...@@ -3092,20 +3087,10 @@ ...@@ -3092,20 +3087,10 @@
// // }); // // });
// // } // // }
// // }); // // });
// //
// //
// break;
// defaultcase:
// throw "No handler defined for this reference!";
// // break;
// };
// } else {
// // error
// throw "No reference defined for this action!";
// }
}) })
// generate, cache and show popup contents based on pointer // pointer contents
.find("#global_popup, .local_popup") .find("#global_popup, .local_popup")
.on("popupbeforeposition", function(e, ui) { .on("popupbeforeposition", function(e, ui) {
var fragment, var fragment,
...@@ -3235,16 +3220,20 @@ ...@@ -3235,16 +3220,20 @@
// NOTE: // NOTE:
// INSTRUCTIONS // INSTRUCTIONS
// SECTIONS
// util = utilities/helper methods // util = utilities/helper methods
// factory = content generator methods (templating system) // factory = content generator methods (templating system)
// init = initialization methods // init = initialization methods
// erp5 = custom methods for erp5 = "mapped" to factory // erp5 = custom methods for erp5 = "mapped" to factory
// ACTIONS // ACTIONS
// > class "action" data-action="which_action" data-reference="which_id" // > class ".action" data-action="which_action" data-reference="which_id"
// > set these on an element to hook up to handlers // > set these on an element to hook up to a handler
// > in erp5.map_actions, add a method "which_action" // > stored in erp5.map_actions, add a method "which_action"
// > will be run on "click" & "change" // > will be run on "click", "change", "keyup", "input"
// POINTERS
// TODO: run earlier, not on "ready" > http://bit.ly/10Nvgly // TODO: run earlier, not on "ready" > http://bit.ly/10Nvgly
$(document) $(document)
......
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