Commit 2a5f48a1 authored by Sven Franck's avatar Sven Franck

added custom handler for i18n while elements are in memory

parent 6c88b1d1
......@@ -153,6 +153,79 @@
// TODO: remove duplicate code for pagination
erp5.map_actions = {
/** translate a nodeList (which can't be passed into i18n).
* By using this the translations can be done BEFORE appending to the DOM
* saving full DOM traversal and extensive jQuery-ing
* @method translateNodeList
* @param {object} nodeList Nodelist to translate
* @param {string} language Language to translate
*/
// TODO: no solution yet for selectMenu-refesh and input (submit/reset/btn)
"translateNodeList": function (nodeList) {
var i,
l,
element,
lookup,
targets,
target,
elements = nodeList.querySelectorAll(".translate");
if (i18n) {
for (i = 0; i < elements.length; i += 1) {
element = elements[i];
lookup = element.getAttribute("data-i18n");
if (lookup) {
if (lookup.indexOf(";") > -1) {
targets = lookup.split(";");
} else {
targets = [lookup]
}
for (l = 0; l < targets.length; l += 1) {
target = targets[l].split("]");
// all hail performance
switch(target[0]) {
case "[placeholder":
case "[alt":
case "[title":
element.setAttribute(target[0].substr(1), i18n.t(target[1]));
break;
case "[value":
element.value = i18n.t(target[1]);
break;
case "[html":
// NOTE: slow
element.innerHTML = i18n.t(target[1]);
break;
default:
// NOTE: empty - setting .translate on a wrapper will empty it
while (element.hasChildNodes()) {
element.removeChild(element.firstChild);
}
element.appendChild(document.createTextNode(i18n.t(target[0])));
break;
}
}
}
}
} else {
util.errorHandler({"error":"Translate NodeList - i18n not defined"});
}
// .find("select").selectMenu("refresh").end()
// .find("input").filter(function() {
// switch (this.type || this.attr(type)) {
// case "submit":
// case "reset":
// case "button":
// return true;
// break;
// }
// return false;
// }).checkboxRadio("refresh");
},
/** translate the active page
* @method translate
* @param {object} obj Action Object
......@@ -190,19 +263,7 @@
}
$.i18n.setLng(new_language, function () {
// TODO: not really...
$($.makeArray(document.querySelectorAll(".translate"))).i18n();
// .find("select").selectMenu("refresh").end()
// .find("input").filter(function() {
// switch (this.type || this.attr(type)) {
// case "submit":
// case "reset":
// case "button":
// return true;
// break;
// }
// return false;
// }).checkboxRadio("refresh");
factory.map_actions.translateNodeList(document);
});
}
},
......@@ -3476,27 +3537,25 @@
var j,
k,
reference,
info_fields,
info_field,
info,
min,
select_counter;
// WARNING: IE8- and performance?
// WARNING: element = documentFragment, can only be searched via QSA!
info_fields = element.querySelectorAll(".info");
zero_no_show,
select_counter,
// WARNING: IE8- and performance?
// WARNING: element = documentFragment can only be searched via QSA!
info_fields = element.querySelectorAll(".info"),
info = "";
for (j = 0; j < info_fields.length; j += 1) {
info_field = info_fields[j];
// TODO: how to i18n this?
// TODO: what is more costly? repaint or reset values on every call?
// TODO: remove this to ERP5 handler
switch (info_field.getAttribute("data-info")) {
case "records":
if (total && total > 0) {
min = Math.min(total, (options.limit[0] + options.limit[1]));
info = options.limit[0] + "-" + min + "/" + total + " Records";
zero_no_show = options.limit[0] === 0 ? 1 : options.limit[0];
min = Math.min(total, (zero_no_show + options.limit[1]));
info = zero_no_show + "-" + min + "/" + total + " Records";
}
break;
case "selected":
......@@ -4007,7 +4066,6 @@
init.fetchPageLayouts("settings", page.id)
.then(function (reply) {
//init.setPageTitle(page, util.parseIfNeeded(reply.response[0]));
if (!page.querySelectorAll("div.ui-content")[0]
.getAttribute("data-bound")) {
return init.setPageElements({
......@@ -4378,8 +4436,7 @@
}
}
// skip total for single item layouts!
// TODO: What if the first page should only contain an object?
if (baggage.layout_level === 0 && baggage.config.initial_query) {
if (baggage.config.initial_query) {
return util.fetchData({
"baggage": baggage,
"storage": "items",
......@@ -4450,19 +4507,8 @@
(baggage.create === false ? true : null)
);
// TODO: not really...
$($.makeArray(element.querySelectorAll(".translate"))).i18n();
// .find("select").selectMenu("refresh").end()
// .find("input").filter(function() {
// switch (this.type || this.attr(type)) {
// case "submit":
// case "reset":
// case "button":
// return true;
// break;
// }
// return false;
// }).checkboxRadio("refresh");
// translate
factory.map_actions.translateNodeList(element);
if (baggage.create === false) {
selector = baggage.state.gadget;
......@@ -4530,9 +4576,6 @@
} else {
page = document.getElementById(config.id || util.getActivePage());
target = page.querySelectorAll("div.ui-content")[0];
// if (create === undefined) {
// init.setPageTitle(page, layout);
// }
}
// prepare baggage
......@@ -4560,7 +4603,6 @@
gadget.getAttribute("data-gadget-type");
}
// TODO: clear 2x calls like storeSampleData & storeSampleDataInStorage
promises[i] = util.fetchPortalTypeConfiguration({
"storage": "settings",
"file": "gadgets",
......@@ -4744,19 +4786,8 @@
element = config[i];
content = factory.util.forward(element);
// TODO: not really...
$($.makeArray(content.querySelectorAll(".translate"))).i18n();
// .find("select").selectMenu("refresh").end()
// .find("input").filter(function() {
// switch (this.type || this.attr(type)) {
// case "submit":
// case "reset":
// case "button":
// return true;
// break;
// }
// return false;
// }).checkboxRadio("refresh");
// translate
factory.map_actions.translateNodeList(content);
switch (element.type) {
case "panel":
......
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