Commit 7e88f93d authored by Mikolaï Krol's avatar Mikolaï Krol Committed by Mikolaï Krol

erp5_jexcel_editor: changing type in toolbar on mobile

erp5_jexcel_editor: resize table in undo/redo history

erp5_jexcel_editor: load styles from webtable existing app
parent 231ae5b6
/*jslint nomen: true, indent: 2, maxlen: 80 */
/*global window, rJS, RSVP, jexcel, domsugar, document, alert, prompt, confirm*/
(function (window, rJS, jexcel, domsugar, document, alert, prompt, confirm) {
/*global window, rJS, RSVP, jexcel, domsugar, document, alert,
prompt, confirm, navigator*/
(function (window, rJS, jexcel, domsugar, document, alert,
prompt, confirm, navigator) {
"use strict";
function isMobileDevice() {
return (window.orientation !== undefined) ||
(navigator.userAgent.indexOf('IEMobile') !== -1);
}
function format(node, level) {
var indentBefore = new Array(level + 2).join(' '),
indentAfter,
......@@ -426,6 +433,12 @@
return gadget.triggerChangeType("checkbox", child);
}
});
items.push({
title: "Set column type: Calendar",
onclick: function () {
return gadget.triggerChangeType("calendar");
}
});
items.push({
title: "Set column type: Color",
onclick: function () {
......@@ -460,6 +473,53 @@
toolbar_dict.color_picker) {
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") &&
toolbar_dict.add_delete_row_column) {
list.push(dict.add_row, dict.delete_row,
......@@ -496,7 +556,7 @@
add_delete_row_column: true
},
options: {
minDimensions: [15, 30],
minDimensions: [26, 100],
defaultColWidth: 100,
defaultColAlign: "left",
allowExport: true,
......@@ -596,7 +656,6 @@
return setupTable(gadget, tab);
});
} else {
delete toolbar_config.minDimensions;
gadget.state.tables = [];
nodes = createElementFromHTML(gadget.state.value);
for (i = 0; i < nodes.length; i++) {
......@@ -748,7 +807,7 @@
}
});
setHistoryType(state.obj, "endChangeType",
Number(x),
x,
state.obj.options.columns[x].type,
type);
state.obj.options.columns[x].type = type;
......@@ -759,10 +818,43 @@
}
})
.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) {
var r = prompt("Number of rows :", instance.options.data.length);
var c = prompt("Number of columns :", instance.options.columns.length);
if (c > 0 && r > 0) {
instance.setHistory({action: "beginResizeTable"});
if (c > instance.options.columns.length) {
while (instance.options.columns.length < c) {
instance.insertColumn();
......@@ -783,6 +875,7 @@
instance.deleteRow(instance.options.data.length - 1, 1);
}
}
instance.setHistory({action: "endResizeTable"});
}
})
......@@ -1019,4 +1112,4 @@
}
}, false, false);
}(window, rJS, jexcel, domsugar, document, alert, prompt, confirm));
\ No newline at end of file
}(window, rJS, jexcel, domsugar, document, alert, prompt, confirm, navigator));
\ No newline at end of file
......@@ -6305,7 +6305,12 @@ console.log(ret);
// History
var historyRecord = obj.history[obj.historyIndex--];
if (historyRecord.action == 'endChangeType') {
if (historyRecord.action === 'endResizeTable') {
while (obj.history[obj.historyIndex].action !== "beginResizeTable") {
obj.undo();
}
obj.undo();
} else if (historyRecord.action == 'endChangeType') {
obj.options.columns[historyRecord.column].type = historyRecord.oldType;
while (obj.history[obj.historyIndex].action !== "beginChangeType") {
obj.undo();
......@@ -6389,12 +6394,17 @@ console.log(ret);
if (obj.historyIndex < obj.history.length - 1) {
// History
var historyRecord = obj.history[++obj.historyIndex];
if (historyRecord.action == 'beginChangeType') {
if (historyRecord.action == 'beginResizeTable') {
while (obj.history[obj.historyIndex].action !== "endResizeTable") {
obj.redo();
}
obj.redo();
} else if (historyRecord.action == 'beginChangeType') {
obj.options.columns[historyRecord.column].type = historyRecord.newType;
while (obj.history[obj.historyIndex].action !== "endChangeType") {
obj.redo();
}
//obj.undo();
obj.redo();
} else if (historyRecord.action == 'insertRow') {
obj.historyProcessRow(0, historyRecord);
} else if (historyRecord.action == 'deleteRow') {
......@@ -8312,7 +8322,7 @@ console.log(ret);
style[cellName] = s;
}
// Bold
if (content[j].children[i].classList.contains('styleBold')) {
if (content[j].children[i].classList.contains('styleBold') || content[j].children[i].classList.contains('style-bold')) {
if (style[cellName]) {
style[cellName] += '; font-weight:bold;';
} else {
......@@ -8320,7 +8330,7 @@ console.log(ret);
}
}
// Italic
if (content[j].children[i].classList.contains('styleItalics')) {
if (content[j].children[i].classList.contains('styleItalics') || content[j].children[i].classList.contains('style-italics')) {
if (style[cellName]) {
style[cellName] += '; font-style: italic;';
} else {
......@@ -8328,13 +8338,21 @@ console.log(ret);
}
}
// Underlined
if (content[j].children[i].classList.contains('styleUnderline')) {
if (content[j].children[i].classList.contains('styleUnderline') || content[j].children[i].classList.contains('style-underline')) {
if (style[cellName]) {
style[cellName] += '; text-decoration: underline;';
} else {
style[cellName] = 'text-decoration: underline;';
}
}
// Line through
if (content[j].children[i].classList.contains('style-line-through')) {
if (style[cellName]) {
style[cellName] += '; text-decoration: line-through;';
} else {
style[cellName] = 'text-decoration: line-through;';
}
}
// Align left
if (content[j].children[i].classList.contains('styleLeft')) {
if (style[cellName]) {
......
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