Commit fd0b4abf authored by Mikolaï Krol's avatar Mikolaï Krol Committed by Mikolaï Krol

erp5_jexcel_editor: moved toolbar definition to util gadget

erp5_jexcel_editor: formula bar, not working like expected yet

erp5_jexcel_editor: updated jexcel source
parent eb45d105
div.jexcel_formula img{
display: inline-block;
width: 12px;
height: 12px;
margin-left: 4px;
margin-right: 4px;
}
input.jexcel_formula {
margin-left: 2px;
width: 97%;
position:sticky;
top:0px;
z-index:21;
display: inline-block;
}
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__name__</string> </key>
<value> <string>complements.css</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/css</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__name__</string> </key>
<value> <string>fx.png</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>image/png</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Jexcel</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="gadget.utils.toolbar.js"></script>
</head>
<body>
</body>
</html>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__name__</string> </key>
<value> <string>gadget.utils.toolbar.html</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
/*jslint nomen: true, indent: 2 */
/*global window, rJS, RSVP, jexcel*/
(function (window, rJS, jexcel) {
"use strict";
var font_style = {
type: 'select',
k: 'font-family',
v: ['Arial', 'Comic Sans MS', 'Verdana', 'Calibri', 'Tahoma', 'Helvetica', 'DejaVu Sans', 'Times New Roman', 'Georgia', 'Antiqua']
};
var font_size = {
type: 'select',
k: 'font-size',
v: ['9px', '10px', '11px', '12px', '13px', '14px', '15px', '16px', '17px', '18px', '19px', '20px', '22px', '24px', '26px', '28px', '30px']
};
var text_align_left = {
type: 'i',
content: 'format_align_left',
k: 'text-align',
v: 'left'
};
var text_align_center = {
type: 'i',
content: 'format_align_center',
k: 'text-align',
v: 'center'
};
var text_align_right = {
type: 'i',
content: 'format_align_right',
k: 'text-align',
v: 'right'
};
var text_align_justify = {
type: 'i',
content: 'format_align_justify',
k: 'text-align',
v: 'justify'
};
var vertical_align_top = {
type: 'i',
content: 'vertical_align_top',
k: 'vertical-align',
v: 'top'
};
var vertical_align_middle = {
type: 'i',
content: 'vertical_align_center',
k: 'vertical-align',
v: 'middle'
};
var vertical_align_bottom = {
type: 'i',
content: 'vertical_align_bottom',
k: 'vertical-align',
v: 'bottom'
};
var style_bold = {
type: 'i',
content: 'format_bold',
k: 'font-weight',
v: 'bold'
};
var style_underlined = {
type: 'i',
content: 'format_underlined',
k: 'text-decoration',
v: 'underline'
};
var style_italic = {
type: 'i',
content: 'format_italic',
k: 'font-style',
v: 'italic'
};
var text_color = {
type: 'color',
content: 'format_color_text',
k: 'color'
};
var background_color = {
type: 'color',
content: 'format_color_fill',
k: 'background-color'
};
rJS(window)
.declareMethod("getToolbarList", function (dict) {
var list = [];
if (dict.hasOwnProperty("text_font") && dict.text_font) {
list.push(font_style, font_size, style_bold, style_italic, style_underlined);
}
if (dict.hasOwnProperty("text_position") && dict.text_position) {
list.push(text_align_left, text_align_center, text_align_right, text_align_justify, vertical_align_top, vertical_align_middle, vertical_align_bottom);
}
if (dict.hasOwnProperty("color_picker") && dict.color_picker) {
list.push(text_color, background_color);
}
return list;
});
}(window, rJS, jexcel));
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="File" module="OFS.Image"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__name__</string> </key>
<value> <string>gadget.utils.toolbar.js</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/javascript</string> </value>
</item>
<item>
<key> <string>precondition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -13,6 +13,7 @@
<script src="jsuites/jsuites.js"></script>
<link rel="stylesheet" href="jexcel/jexcel.css" type="text/css" />
<link rel="stylesheet" href="jsuites/jsuites.css" type="text/css" />
<link rel="stylesheet" href="complements.css" type="text/css" />
<link rel="stylesheet" href="icons.css" type="text/css" />
......@@ -20,6 +21,10 @@
</head>
<body>
<div data-gadget-url="gadget.utils.toolbar.html"
data-gadget-scope="toolbar_gadget"
data-gadget-sandbox="public">
</div>
<div class="spreadsheet"></div>
</body>
</html>
......@@ -16,7 +16,13 @@
.declareMethod("render", function (options) {
var gadget = this;
return gadget.changeState(options);
return gadget.getDeclaredGadget("toolbar_gadget")
.push(function (toolbar_gadget) {
gadget.toolbar_gadget = toolbar_gadget;
})
.push(function () {
return gadget.changeState(options);
});
})
.declareMethod('getContent', function () {
......@@ -49,195 +55,153 @@
selectionCopy: true,
search: true,
fullscreen: true,
//lazyLoading: true,
//loadingSpin: true,
//tableOverflow: true,
autoIncrement: true,
parseFormulas: true
},
gadget = this, tmp = Object.assign({}, template), table;
gadget = this, tmp = Object.assign({}, template), table, toolbar_list;
gadget.deferNotifyChangeBinded = gadget.deferNotifyChange.bind(gadget);
if (modification_dict.hasOwnProperty('value')) {
gadget.state.value = gadget.state.value === "" ? gadget.state.value : JSON.parse(gadget.state.value);
Object.assign(tmp, template);
Object.assign(tmp, gadget.state.value);
table = jexcel(gadget.element.querySelector(".spreadsheet"), Object.assign(tmp, {
onevent: function (ev) {
var exluded_events = ["onload", "onfocus", "onblur", "onselection"];
if (!exluded_events.includes(ev)) {
if ((ev === "onchangestyle" && gadget.state.saveConfig) || ev !== "onchangestyle") {
gadget.deferNotifyChangeBinded();
} else {
gadget.state.saveConfig = true;
}
}
},
toolbar: [
//undo
{
type: 'i',
content: 'undo',
onclick: function () {
table.undo();
}
},
//redo
{
type: 'i',
content: 'redo',
onclick: function () {
table.redo();
}
},
//merge cells
{
type: 'i',
content: 'table_chart',
onclick: function () {
var cell = gadget.element.querySelector("td.highlight-selected");
var x = Number(cell.dataset.x);
var selected = table.getJson(true);
var colspan = Object.keys(selected[0]).length;
var rowspan = selected.length;
var letter = "";
if (x <= 25) {
letter += String.fromCharCode(97 + x).toUpperCase();
}
else {
letter += String.fromCharCode(97 + Math.trunc(x / 25) - 1).toUpperCase();
letter += String.fromCharCode(97 + (x % 26)).toUpperCase();
return gadget.toolbar_gadget.getToolbarList({
text_font: true,
text_position: true,
color_picker: true
})
.push(function (list) {
toolbar_list = list;
})
.push(function () {
table = jexcel(gadget.element.querySelector(".spreadsheet"), Object.assign(tmp, {
onevent: function (ev) {
var exluded_events = ["onload", "onfocus", "onblur", "onselection"];
if (!exluded_events.includes(ev)) {
if ((ev === "onchangestyle" && gadget.state.saveConfig) || ev !== "onchangestyle") {
gadget.deferNotifyChangeBinded();
} else {
gadget.state.saveConfig = true;
}
}
var coor = letter + (Number(cell.dataset.y) + 1).toString();
table.setMerge(coor, colspan, rowspan);
}
},
//unmerge cell
{
type: 'i',
content: 'close',
onclick: function () {
},
onselection: function (ev) {
var cell = gadget.element.querySelector("td.highlight-selected");
var x = Number(cell.dataset.x);
var letter = "";
if (x <= 25) {
letter += String.fromCharCode(97 + x).toUpperCase();
var formula = gadget.element.querySelector("input.jexcel_formula");
formula.value = cell.textContent;
},
toolbar: [
//undo
{
type: 'i',
content: 'undo',
onclick: function () {
table.undo();
}
},
//redo
{
type: 'i',
content: 'redo',
onclick: function () {
table.redo();
}
},
//merge cells
{
type: 'i',
content: 'table_chart',
onclick: function () {
var cell = gadget.element.querySelector("td.highlight-selected");
var x = Number(cell.dataset.x);
var selected = table.getJson(true);
var colspan = Object.keys(selected[0]).length;
var rowspan = selected.length;
var letter = "";
if (x <= 25) {
letter += String.fromCharCode(97 + x).toUpperCase();
}
else {
letter += String.fromCharCode(97 + Math.trunc(x / 25) - 1).toUpperCase();
letter += String.fromCharCode(97 + (x % 26)).toUpperCase();
}
var coor = letter + (Number(cell.dataset.y) + 1).toString();
table.setMerge(coor, colspan, rowspan);
}
},
//unmerge cell
{
type: 'i',
content: 'close',
onclick: function () {
var cell = gadget.element.querySelector("td.highlight-selected");
var x = Number(cell.dataset.x);
var letter = "";
if (x <= 25) {
letter += String.fromCharCode(97 + x).toUpperCase();
}
else {
letter += String.fromCharCode(97 + Math.trunc(x / 25) - 1).toUpperCase();
letter += String.fromCharCode(97 + (x % 26)).toUpperCase();
}
var coor = letter + (Number(cell.dataset.y) + 1).toString();
table.removeMerge(coor);
}
},
//destroy all merged cells
{
type: 'i',
content: 'cancel',
onclick: function () {
table.destroyMerged();
}
}
else {
letter += String.fromCharCode(97 + Math.trunc(x / 25) - 1).toUpperCase();
letter += String.fromCharCode(97 + (x % 26)).toUpperCase();
}
var coor = letter + (Number(cell.dataset.y) + 1).toString();
table.removeMerge(coor);
}
},
//destroy all merged cells
{
type: 'i',
content: 'cancel',
onclick: function () {
table.destroyMerged();
}
},
//font style
{
type: 'select',
k: 'font-family',
v: ['Arial', 'Comic Sans MS', 'Verdana', 'Calibri', 'Tahoma', 'Helvetica', 'DejaVu Sans', 'Times New Roman', 'Georgia', 'Antiqua']
},
//font size
{
type: 'select',
k: 'font-size',
v: ['9px', '10px', '11px', '12px', '13px', '14px', '15px', '16px', '17px', '18px', '19px', '20px', '22px', '24px', '26px', '28px', '30px']
},
//text align left
{
type: 'i',
content: 'format_align_left',
k: 'text-align',
v: 'left'
},
//text align center
{
type: 'i',
content: 'format_align_center',
k: 'text-align',
v: 'center'
},
//text align right
{
type: 'i',
content: 'format_align_right',
k: 'text-align',
v: 'right'
},
//text align justify
{
type: 'i',
content: 'format_align_justify',
k: 'text-align',
v: 'justify'
},
//vertical align top
{
type: 'i',
content: 'vertical_align_top',
k: 'vertical-align',
v: 'top'
},
//vertical align middle
{
type: 'i',
content: 'vertical_align_center',
k: 'vertical-align',
v: 'middle'
},
//vertical align bottom
{
type: 'i',
content: 'vertical_align_bottom',
k: 'vertical-align',
v: 'bottom'
},
//style bold
{
type: 'i',
content: 'format_bold',
k: 'font-weight',
v: 'bold'
},
//style underlined
{
type: 'i',
content: 'format_underlined',
k: 'text-decoration',
v: 'underline'
},
//style italic
{
type: 'i',
content: 'format_italic',
k: 'font-style',
v: 'italic'
},
//text color
{
type: 'color',
content: 'format_color_text',
k: 'color'
},
//background color
{
type: 'color',
content: 'format_color_fill',
k: 'background-color'
].concat(toolbar_list)
}));
gadget.table = table;
var filter = gadget.element.querySelector(".jexcel_filter");
gadget.element.querySelector(".jexcel_toolbar").appendChild(filter);
var formula_div = document.createElement("div");
formula_div.classList.add("jexcel_formula");
var img = document.createElement("img");
img.src = "fx.png";
var formula_input = document.createElement("input");
formula_input.classList.add("jexcel_formula");
formula_div.appendChild(img);
formula_div.appendChild(formula_input);
gadget.element.querySelector("div.jexcel_toolbar").parentNode.insertBefore(formula_div, gadget.element.querySelector("div.jexcel_toolbar").nextSibling);
console.log(gadget.element.querySelectorAll("i"));
var icon_title = {
"undo": "Undo",
"redo": "Redo",
"table_chart": "Merge cells",
"close": "Destroy merge",
"cancel": "Destroy all merges",
"format_bold": "Bold",
"format_italic": "Italic",
"format_underlined": "Underline",
"format_align_left": "Align left",
"format_align_center": "Align center",
"format_align_right": "Align right",
"format_align_justify": "Align justify",
"vertical_align_top": "Align top",
"vertical_align_center": "Align middle",
"vertical_align_bottom": "Align bottom",
}
]
}));
gadget.table = table;
var filter = gadget.element.querySelector(".jexcel_filter");
gadget.element.querySelector(".jexcel_toolbar").appendChild(filter);
gadget.element.querySelectorAll("i").forEach(i => {
if (i.dataset.k === "color") {i.title = "Color"}
else if (i.dataset.k === "background-color") {i.title = "Background color"}
else {i.title = icon_title[i.textContent]}
});
});
}
});
})
.onEvent("input", function (ev) {
var gadget = this;
var formula = gadget.element.querySelector("input.jexcel_formula");
if (ev.target == gadget.element.querySelector("td.highlight-selected input")) {
formula.value = ev.target.value;
}
}, false, false)
}(window, rJS, jexcel));
......@@ -21,7 +21,7 @@
.jexcel_container.fullscreen .jexcel_content {
overflow:auto;
width:100%;
height:100%;
height:96.5%;
background-color:#ffffff;
}
......@@ -609,7 +609,7 @@
background-color:#f3f3f3;
border:1px solid #ccc;
padding:4px;
margin:0px 2px 4px 1px;
margin:0px 2px 1px 1px;
position:sticky;
top:0px;
z-index:21;
......
/**
* jExcel v4.1.2
* jExcel v4.2.1
*
* Author: Paul Hodel <paul.hodel@gmail.com>
* Website: https://bossanova.uk/jexcel/
......@@ -147,6 +147,9 @@
parseFormulas:true,
autoIncrement:true,
autoCasting:true,
// Security
secureFormulas:true,
stripHTML:true,
// Filters
filters:false,
footers:null,
......@@ -229,7 +232,7 @@
noCellsSelected: 'No cells selected',
},
// About message
about:"jExcel CE Spreadsheet\nVersion 4.1.2\nAuthor: Paul Hodel <paul.hodel@gmail.com>\nWebsite: https://bossanova.uk/jexcel/v3",
about:"jExcel CE Spreadsheet\nVersion 4.2.0\nAuthor: Paul Hodel <paul.hodel@gmail.com>\nWebsite: https://bossanova.uk/jexcel/v3",
};
// Loading initial configuration from user
......@@ -616,11 +619,14 @@
ads.setAttribute('href', 'https://bossanova.uk/jexcel/');
obj.ads = document.createElement('div');
obj.ads.className = 'jexcel_about';
if (typeof(sessionStorage) !== "undefined" && ! sessionStorage.getItem('jexcel')) {
sessionStorage.setItem('jexcel', true);
var img = document.createElement('img');
img.src = '//bossanova.uk/jexcel/logo.png';
ads.appendChild(img);
try {
if (typeof(sessionStorage) !== "undefined" && ! sessionStorage.getItem('jexcel')) {
sessionStorage.setItem('jexcel', true);
var img = document.createElement('img');
img.src = '//bossanova.uk/jexcel/logo.png';
ads.appendChild(img);
}
} catch (exception) {
}
var span = document.createElement('span');
span.innerHTML = 'Jexcel spreadsheet';
......@@ -1117,9 +1123,22 @@ console.log(ret);
td.setAttribute('data-x', i);
td.setAttribute('data-y', j);
// Security
if ((''+value).substr(0,1) == '=' && obj.options.secureFormulas == true) {
var val = secureFormula(value);
if (val != value) {
// Update the data container
value = val;
}
}
// Custom column
if (obj.options.columns[i].editor) {
td.innerHTML = value;
if (obj.options.stripHTML === false || obj.options.columns[i].stripHTML === false) {
td.innerHTML = value;
} else {
td.innerText = value;
}
if (typeof(obj.options.columns[i].editor.createCell) == 'function') {
td = obj.options.columns[i].editor.createCell(td);
}
......@@ -1127,7 +1146,7 @@ console.log(ret);
// Hidden column
if (obj.options.columns[i].type == 'hidden') {
td.style.display = 'none';
td.innerHTML = value;
td.innerText = value;
} else if (obj.options.columns[i].type == 'checkbox' || obj.options.columns[i].type == 'radio') {
// Create input
var element = document.createElement('input');
......@@ -1150,11 +1169,11 @@ console.log(ret);
// Try formatted date
var formatted = jSuites.calendar.extractDateFromString(value, obj.options.columns[i].options.format);
// Create calendar cell
td.innerHTML = jSuites.calendar.getDateString(formatted ? formatted : value, obj.options.columns[i].options.format);
td.innerText = jSuites.calendar.getDateString(formatted ? formatted : value, obj.options.columns[i].options.format);
} else if (obj.options.columns[i].type == 'dropdown' || obj.options.columns[i].type == 'autocomplete') {
// Create dropdown cell
td.classList.add('jexcel_dropdown');
td.innerHTML = obj.getDropDownValue(i, value);
td.innerText = obj.getDropDownValue(i, value);
} else if (obj.options.columns[i].type == 'color') {
if (obj.options.columns[i].render == 'square') {
var color = document.createElement('div');
......@@ -1163,7 +1182,7 @@ console.log(ret);
td.appendChild(color);
} else {
td.style.color = value;
td.innerHTML = value;
td.innerText = value;
}
} else if (obj.options.columns[i].type == 'image') {
if (value && value.substr(0, 10) == 'data:image') {
......@@ -1172,7 +1191,15 @@ console.log(ret);
td.appendChild(img);
}
} else {
td.innerHTML = obj.parseValue(i, j, value);
if (obj.options.columns[i].type == 'html') {
td.innerHTML = stripScript(obj.parseValue(i, j, value));
} else {
if (obj.options.stripHTML === false || obj.options.columns[i].stripHTML === false) {
td.innerHTML = stripScript(obj.parseValue(i, j, value));
} else {
td.innerText = obj.parseValue(i, j, value);
}
}
}
}
......@@ -1211,7 +1238,7 @@ console.log(ret);
// Create header cell
obj.headers[colNumber] = document.createElement('td');
obj.headers[colNumber].innerHTML = obj.options.columns[colNumber].title ? obj.options.columns[colNumber].title : jexcel.getColumnName(colNumber);
obj.headers[colNumber].innerText = obj.options.columns[colNumber].title ? obj.options.columns[colNumber].title : jexcel.getColumnName(colNumber);
obj.headers[colNumber].setAttribute('data-x', colNumber);
obj.headers[colNumber].style.textAlign = colAlign;
if (obj.options.columns[colNumber].title) {
......@@ -1235,7 +1262,7 @@ console.log(ret);
obj.updateNestedHeader = function(x, y, title) {
if (obj.options.nestedHeaders[y][x].title) {
obj.options.nestedHeaders[y][x].title = title;
obj.options.nestedHeaders[y].element.children[x+1].innerHTML = title;
obj.options.nestedHeaders[y].element.children[x+1].innerText = title;
}
}
......@@ -1282,7 +1309,7 @@ console.log(ret);
td.setAttribute('data-column', column.join(','));
td.setAttribute('colspan', nestedInformation[i].colspan);
td.setAttribute('align', nestedInformation[i].align);
td.innerHTML = nestedInformation[i].title;
td.innerText = nestedInformation[i].title;
tr.appendChild(td);
}
......@@ -1321,7 +1348,7 @@ console.log(ret);
}
}
// Append element
toolbarItem.innerHTML = toolbar[i].content;
toolbarItem.innerText = toolbar[i].content;
obj.toolbar.appendChild(toolbarItem);
} else if (toolbar[i].type == 'select') {
var toolbarItem = document.createElement('select');
......@@ -1344,7 +1371,7 @@ console.log(ret);
for(var j = 0; j < toolbar[i].v.length; j++) {
var toolbarDropdownOption = document.createElement('option');
toolbarDropdownOption.value = toolbar[i].v[j];
toolbarDropdownOption.innerHTML = toolbar[i].v[j];
toolbarDropdownOption.innerText = toolbar[i].v[j];
toolbarItem.appendChild(toolbarDropdownOption);
}
obj.toolbar.appendChild(toolbarItem);
......@@ -1362,7 +1389,7 @@ console.log(ret);
toolbarItem.onclick = function() {
this.color.open();
}
toolbarItem.innerHTML = toolbar[i].content;
toolbarItem.innerText = toolbar[i].content;
jSuites.color(toolbarItem, {
onchange:function(o, v) {
var k = o.getAttribute('data-k');
......@@ -1648,7 +1675,7 @@ console.log(ret);
obj.filter.children[columnId + 1].innerHTML = '';
obj.filter.children[columnId + 1].appendChild(div);
obj.filter.children[columnId + 1].style.paddingLeft = '0px';
obj.filter.children[columnId + 1].style.paddingRight = '20px';
obj.filter.children[columnId + 1].style.paddingRight = '0px';
obj.filter.children[columnId + 1].style.overflow = 'initial';
// Dynamic dropdown
......@@ -1882,7 +1909,7 @@ console.log(ret);
editor.setAttribute('data-mask', obj.options.columns[x].mask);
}
}
editor.onblur = function() {
obj.closeEditor(cell, true);
};
......@@ -2221,6 +2248,17 @@ console.log(ret);
}
}
/**
* Strip tags
*/
var stripScript = function(a) {
var b = new Option;
b.innerHTML = a;
var c = null;
for (a = b.getElementsByTagName('script'); c=a[0];) c.parentNode.removeChild(c);
return b.innerHTML;
}
/**
* Update cell content
*
......@@ -2238,6 +2276,15 @@ console.log(ret);
row: y
}
} else {
// Security
if ((''+value).substr(0,1) == '=' && obj.options.secureFormulas == true) {
var val = secureFormula(value);
if (val != value) {
// Update the data container
value = val;
}
}
// On change
var val = obj.dispatch('onbeforechange', el, obj.records[y][x], x, y, value);
......@@ -2279,13 +2326,13 @@ console.log(ret);
} else if (obj.options.columns[x].type == 'dropdown' || obj.options.columns[x].type == 'autocomplete') {
// Update data and cell
obj.options.data[y][x] = value;
obj.records[y][x].innerHTML = obj.getDropDownValue(x, value);
obj.records[y][x].innerText = obj.getDropDownValue(x, value);
} else if (obj.options.columns[x].type == 'calendar') {
// Update calendar
var formatted = jSuites.calendar.extractDateFromString(value, obj.options.columns[x].options.format);
// Update data and cell
obj.options.data[y][x] = value;
obj.records[y][x].innerHTML = jSuites.calendar.getDateString(formatted ? formatted : value, obj.options.columns[x].options.format);
obj.records[y][x].innerText = jSuites.calendar.getDateString(formatted ? formatted : value, obj.options.columns[x].options.format);
} else if (obj.options.columns[x].type == 'color') {
// Update color
obj.options.data[y][x] = value;
......@@ -2294,11 +2341,11 @@ console.log(ret);
var color = document.createElement('div');
color.className = 'color';
color.style.backgroundColor = value;
obj.records[y][x].innerHTML = '';
obj.records[y][x].innerText = '';
obj.records[y][x].appendChild(color);
} else {
obj.records[y][x].style.color = value;
obj.records[y][x].innerHTML = value;
obj.records[y][x].innerText = value;
}
} else if (obj.options.columns[x].type == 'image') {
value = ''+value;
......@@ -2313,7 +2360,15 @@ console.log(ret);
// Update data and cell
obj.options.data[y][x] = value;
// Label
obj.records[y][x].innerHTML = obj.parseValue(x, y, value);
if (obj.options.columns[x].type == 'html') {
obj.records[y][x].innerHTML = stripScript(obj.parseValue(x, y, value));
} else {
if (obj.options.stripHTML === false || obj.options.columns[x].stripHTML === false) {
obj.records[y][x].innerHTML = stripScript(obj.parseValue(x, y, value));
} else {
obj.records[y][x].innerText = obj.parseValue(x, y, value);
}
}
// Handle big text inside a cell
if (obj.options.columns[x].wordWrap != false && (obj.options.wordWrap == true || obj.options.columns[x].wordWrap == true || obj.records[y][x].innerHTML.length > 200)) {
obj.records[y][x].style.whiteSpace = 'pre-wrap';
......@@ -3138,7 +3193,7 @@ console.log(ret);
var colAlign = obj.options.columns[i].align ? obj.options.columns[i].align : 'center';
td.style.textAlign = colAlign;
}
td.innerHTML = obj.parseValue(i, j, obj.options.footers[j][i]);
td.innerText = obj.parseValue(i, j, obj.options.footers[j][i]);
}
}
}
......@@ -3169,7 +3224,7 @@ console.log(ret);
}
if (newValue) {
obj.headers[column].innerHTML = newValue;
obj.headers[column].innerText = newValue;
// Keep the title property
obj.headers[column].setAttribute('title', newValue);
// Update title
......@@ -3526,8 +3581,8 @@ console.log(ret);
// Filter
Array.prototype.orderBy = function(p, o) {
return this.slice(0).sort(function(a, b) {
var valueA = a[p] == '' ? '' : Number(a[p]) == a[p] ? Number(a[p]) : a[p].toLowerCase();
var valueB = b[p] == '' ? '' : Number(b[p]) == b[p] ? Number(b[p]) : b[p].toLowerCase();
var valueA = a[p];
var valueB = b[p];
if (! o) {
return (valueA == '' && valueB != '') ? 1 : (valueA != '' && valueB == '') ? -1 : (valueA > valueB) ? 1 : (valueA < valueB) ? -1 : 0;
......@@ -3539,15 +3594,17 @@ console.log(ret);
// Test order
var temp = [];
if (obj.options.columns[column].type == 'calendar' ||
obj.options.columns[column].type == 'checkbox' ||
obj.options.columns[column].type == 'radio') {
if (obj.options.columns[column].type == 'number' || obj.options.columns[column].type == 'percentage' || obj.options.columns[column].type == 'autonumber' || obj.options.columns[column].type == 'color') {
for (var j = 0; j < obj.options.data.length; j++) {
temp[j] = [ j, Number(obj.options.data[j][column]) ];
}
} else if (obj.options.columns[column].type == 'calendar' || obj.options.columns[column].type == 'checkbox' || obj.options.columns[column].type == 'radio') {
for (var j = 0; j < obj.options.data.length; j++) {
temp[j] = [ j, obj.options.data[j][column] ];
}
} else {
for (var j = 0; j < obj.options.data.length; j++) {
temp[j] = [ j, obj.records[j][column].innerHTML ];
temp[j] = [ j, obj.records[j][column].innerText.toLowerCase() ];
}
}
temp = temp.orderBy(1, order);
......@@ -3622,7 +3679,7 @@ console.log(ret);
obj.updateTableReferences();
// Redo search
if (obj.results.length) {
if (obj.results && obj.results.length) {
if (obj.searchInput.value) {
obj.search(obj.searchInput.value);
} else {
......@@ -4782,6 +4839,32 @@ console.log(ret);
return newFormula;
}
/**
* Secure formula
*/
var secureFormula = function(oldValue) {
var newValue = '';
var inside = 0;
for (var i = 0; i < oldValue.length; i++) {
if (oldValue[i] == '"') {
if (inside == 0) {
inside = 1;
} else {
inside = 0;
}
}
if (inside == 1) {
newValue += oldValue[i];
} else {
newValue += oldValue[i].toUpperCase();
}
}
return newValue;
}
/**
* Parse formulas
*/
......@@ -5912,6 +5995,9 @@ console.log(ret);
// Keep non visible information
obj.hashString = obj.hash(obj.data);
// Any exiting border should go
obj.removeCopyingSelection();
// Border
if (obj.highlighted) {
for (var i = 0; i < obj.highlighted.length; i++) {
......@@ -7790,6 +7876,7 @@ console.log(ret);
*/
jexcel.tabs = function(tabs, result) {
var instances = [];
// Create tab container
if (! tabs.classList.contains('jexcel_tabs')) {
tabs.innerHTML = '';
......@@ -7813,7 +7900,7 @@ console.log(ret);
spreadsheet[i].classList.add('jexcel_tab');
var worksheet = jexcel(spreadsheet[i], result[i]);
content.appendChild(spreadsheet[i]);
tabs.jexcel.push(worksheet);
instances[i] = tabs.jexcel.push(worksheet);
// Tab link
link[i] = document.createElement('div');
......@@ -7839,6 +7926,8 @@ console.log(ret);
}
headers.children[headers.children.length - 1].classList.add('selected');
content.children[headers.children.length - 1].style.display = 'block';
return instances;
}
// Compability to older versions
......
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