Commit 517764ea authored by Mikolaï Krol's avatar Mikolaï Krol

erp5_jexcel_editor: changing type in toolbar on mobile

parent a0744903
/*jslint nomen: true, indent: 2, maxlen: 80 */ /*jslint nomen: true, indent: 2, maxlen: 80 */
/*global window, rJS, RSVP, jexcel, domsugar, document, alert, prompt, confirm*/ /*global window, rJS, RSVP, jexcel, domsugar, document, alert, prompt, confirm,
(function (window, rJS, jexcel, domsugar, document, alert, prompt, confirm) { navigator*/
(function (window, rJS, jexcel, domsugar, document, alert,
prompt, confirm, navigator) {
"use strict"; "use strict";
function isMobileDevice() {
return (window.orientation !== undefined) ||
(navigator.userAgent.indexOf('IEMobile') !== -1);
}
function format(node, level) { function format(node, level) {
var indentBefore = new Array(level + 2).join(' '), var indentBefore = new Array(level + 2).join(' '),
indentAfter, indentAfter,
...@@ -426,6 +433,12 @@ ...@@ -426,6 +433,12 @@
return gadget.triggerChangeType("checkbox", child); return gadget.triggerChangeType("checkbox", child);
} }
}); });
items.push({
title: "Set column type: Calendar",
onclick: function () {
return gadget.triggerChangeType("calendar");
}
});
items.push({ items.push({
title: "Set column type: Color", title: "Set column type: Color",
onclick: function () { onclick: function () {
...@@ -460,6 +473,53 @@ ...@@ -460,6 +473,53 @@
toolbar_dict.color_picker) { toolbar_dict.color_picker) {
list.push(dict.text_color, dict.background_color); list.push(dict.text_color, dict.background_color);
} }
if (isMobileDevice()) {
list.push({
type: "i",
content: "photo_library",
onclick: function (sheet, instance) {
return gadget.triggerChangeTypeInToolbar(sheet, instance, "image");
}
});
list.push({
type: "i",
content: "format_size",
onclick: function (sheet, instance) {
return gadget.triggerChangeTypeInToolbar(sheet, instance, "text");
}
});
list.push({
type: "i",
content: "format_paint",
onclick: function (sheet, instance) {
return gadget.triggerChangeTypeInToolbar(sheet, instance,
"color", null, "square");
}
});
list.push({
type: "i",
content: "format_list_bulleted",
onclick: function (sheet, instance) {
return gadget.triggerChangeTypeInToolbar(sheet, instance, "html");
}
});
list.push({
type: "i",
content: "calendar_today",
onclick: function (sheet, instance) {
return gadget.triggerChangeTypeInToolbar(sheet, instance, "calendar");
}
});
list.push({
type: "i",
content: "check_box",
onclick: function (sheet, instance) {
var child = domsugar("input", {type: "checkbox"});
return gadget.triggerChangeTypeInToolbar(sheet, instance,
"checkbox", child);
}
});
}
if (toolbar_dict.hasOwnProperty("add_delete_row_column") && if (toolbar_dict.hasOwnProperty("add_delete_row_column") &&
toolbar_dict.add_delete_row_column) { toolbar_dict.add_delete_row_column) {
list.push(dict.add_row, dict.delete_row, list.push(dict.add_row, dict.delete_row,
...@@ -496,7 +556,7 @@ ...@@ -496,7 +556,7 @@
add_delete_row_column: true add_delete_row_column: true
}, },
options: { options: {
minDimensions: [15, 30], minDimensions: [26, 100],
defaultColWidth: 100, defaultColWidth: 100,
defaultColAlign: "left", defaultColAlign: "left",
allowExport: true, allowExport: true,
...@@ -596,7 +656,6 @@ ...@@ -596,7 +656,6 @@
return setupTable(gadget, tab); return setupTable(gadget, tab);
}); });
} else { } else {
delete toolbar_config.minDimensions;
gadget.state.tables = []; gadget.state.tables = [];
nodes = createElementFromHTML(gadget.state.value); nodes = createElementFromHTML(gadget.state.value);
for (i = 0; i < nodes.length; i++) { for (i = 0; i < nodes.length; i++) {
...@@ -748,7 +807,7 @@ ...@@ -748,7 +807,7 @@
} }
}); });
setHistoryType(state.obj, "endChangeType", setHistoryType(state.obj, "endChangeType",
Number(x), x,
state.obj.options.columns[x].type, state.obj.options.columns[x].type,
type); type);
state.obj.options.columns[x].type = type; state.obj.options.columns[x].type = type;
...@@ -759,6 +818,38 @@ ...@@ -759,6 +818,38 @@
} }
}) })
.declareJob("triggerChangeTypeInToolbar", function (sheet, instance, type, child, render) {
var cell = sheet.querySelector("td.highlight-selected"),
x = parseInt(cell.dataset.x, 10),
column,
array;
if (cell && instance.options.columns[x].type !== type) {
column = sheet.querySelectorAll("td[data-x='" + x + "']");
array = [...column];
array.shift();
setHistoryType(instance, "beginChangeType",
x,
instance.options.columns[x].type,
type);
array.forEach(function (cell) {
instance.setValue(getCoordinatesFromCell(cell), "");
cell.innerHTML = "";
if (child) {
cell.appendChild(child.cloneNode());
}
});
setHistoryType(instance, "endChangeType",
x,
instance.options.columns[x].type,
type);
instance.options.columns[x].type = type;
if (render) {
instance.options.columns[x].render = render;
}
fireDoubleClick(cell);
}
})
.declareJob("triggerNewDimensions", function (sheet, instance) { .declareJob("triggerNewDimensions", function (sheet, instance) {
var r = prompt("Number of rows :", instance.options.data.length); var r = prompt("Number of rows :", instance.options.data.length);
var c = prompt("Number of columns :", instance.options.columns.length); var c = prompt("Number of columns :", instance.options.columns.length);
...@@ -1019,4 +1110,4 @@ ...@@ -1019,4 +1110,4 @@
} }
}, false, false); }, false, false);
}(window, rJS, jexcel, domsugar, document, alert, prompt, confirm)); }(window, rJS, jexcel, domsugar, document, alert, prompt, confirm, navigator));
\ No newline at end of file \ No newline at end of file
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