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 @@ ...@@ -13,6 +13,7 @@
<script src="jsuites/jsuites.js"></script> <script src="jsuites/jsuites.js"></script>
<link rel="stylesheet" href="jexcel/jexcel.css" type="text/css" /> <link rel="stylesheet" href="jexcel/jexcel.css" type="text/css" />
<link rel="stylesheet" href="jsuites/jsuites.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" /> <link rel="stylesheet" href="icons.css" type="text/css" />
...@@ -20,6 +21,10 @@ ...@@ -20,6 +21,10 @@
</head> </head>
<body> <body>
<div data-gadget-url="gadget.utils.toolbar.html"
data-gadget-scope="toolbar_gadget"
data-gadget-sandbox="public">
</div>
<div class="spreadsheet"></div> <div class="spreadsheet"></div>
</body> </body>
</html> </html>
...@@ -16,7 +16,13 @@ ...@@ -16,7 +16,13 @@
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var gadget = this; var gadget = this;
return gadget.getDeclaredGadget("toolbar_gadget")
.push(function (toolbar_gadget) {
gadget.toolbar_gadget = toolbar_gadget;
})
.push(function () {
return gadget.changeState(options); return gadget.changeState(options);
});
}) })
.declareMethod('getContent', function () { .declareMethod('getContent', function () {
...@@ -49,18 +55,24 @@ ...@@ -49,18 +55,24 @@
selectionCopy: true, selectionCopy: true,
search: true, search: true,
fullscreen: true, fullscreen: true,
//lazyLoading: true,
//loadingSpin: true,
//tableOverflow: true,
autoIncrement: true, autoIncrement: true,
parseFormulas: 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); gadget.deferNotifyChangeBinded = gadget.deferNotifyChange.bind(gadget);
if (modification_dict.hasOwnProperty('value')) { if (modification_dict.hasOwnProperty('value')) {
gadget.state.value = gadget.state.value === "" ? gadget.state.value : JSON.parse(gadget.state.value); gadget.state.value = gadget.state.value === "" ? gadget.state.value : JSON.parse(gadget.state.value);
Object.assign(tmp, template); Object.assign(tmp, template);
Object.assign(tmp, gadget.state.value); Object.assign(tmp, gadget.state.value);
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, { table = jexcel(gadget.element.querySelector(".spreadsheet"), Object.assign(tmp, {
onevent: function (ev) { onevent: function (ev) {
var exluded_events = ["onload", "onfocus", "onblur", "onselection"]; var exluded_events = ["onload", "onfocus", "onblur", "onselection"];
...@@ -72,6 +84,11 @@ ...@@ -72,6 +84,11 @@
} }
} }
}, },
onselection: function (ev) {
var cell = gadget.element.querySelector("td.highlight-selected");
var formula = gadget.element.querySelector("input.jexcel_formula");
formula.value = cell.textContent;
},
toolbar: [ toolbar: [
//undo //undo
{ {
...@@ -137,107 +154,54 @@ ...@@ -137,107 +154,54 @@
onclick: function () { onclick: function () {
table.destroyMerged(); 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; gadget.table = table;
var filter = gadget.element.querySelector(".jexcel_filter"); var filter = gadget.element.querySelector(".jexcel_filter");
gadget.element.querySelector(".jexcel_toolbar").appendChild(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.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)); }(window, rJS, jexcel));
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
.jexcel_container.fullscreen .jexcel_content { .jexcel_container.fullscreen .jexcel_content {
overflow:auto; overflow:auto;
width:100%; width:100%;
height:100%; height:96.5%;
background-color:#ffffff; background-color:#ffffff;
} }
...@@ -609,7 +609,7 @@ ...@@ -609,7 +609,7 @@
background-color:#f3f3f3; background-color:#f3f3f3;
border:1px solid #ccc; border:1px solid #ccc;
padding:4px; padding:4px;
margin:0px 2px 4px 1px; margin:0px 2px 1px 1px;
position:sticky; position:sticky;
top:0px; top:0px;
z-index:21; z-index:21;
......
/** /**
* jExcel v4.1.2 * jExcel v4.2.1
* *
* Author: Paul Hodel <paul.hodel@gmail.com> * Author: Paul Hodel <paul.hodel@gmail.com>
* Website: https://bossanova.uk/jexcel/ * Website: https://bossanova.uk/jexcel/
...@@ -147,6 +147,9 @@ ...@@ -147,6 +147,9 @@
parseFormulas:true, parseFormulas:true,
autoIncrement:true, autoIncrement:true,
autoCasting:true, autoCasting:true,
// Security
secureFormulas:true,
stripHTML:true,
// Filters // Filters
filters:false, filters:false,
footers:null, footers:null,
...@@ -229,7 +232,7 @@ ...@@ -229,7 +232,7 @@
noCellsSelected: 'No cells selected', noCellsSelected: 'No cells selected',
}, },
// About message // 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 // Loading initial configuration from user
...@@ -616,12 +619,15 @@ ...@@ -616,12 +619,15 @@
ads.setAttribute('href', 'https://bossanova.uk/jexcel/'); ads.setAttribute('href', 'https://bossanova.uk/jexcel/');
obj.ads = document.createElement('div'); obj.ads = document.createElement('div');
obj.ads.className = 'jexcel_about'; obj.ads.className = 'jexcel_about';
try {
if (typeof(sessionStorage) !== "undefined" && ! sessionStorage.getItem('jexcel')) { if (typeof(sessionStorage) !== "undefined" && ! sessionStorage.getItem('jexcel')) {
sessionStorage.setItem('jexcel', true); sessionStorage.setItem('jexcel', true);
var img = document.createElement('img'); var img = document.createElement('img');
img.src = '//bossanova.uk/jexcel/logo.png'; img.src = '//bossanova.uk/jexcel/logo.png';
ads.appendChild(img); ads.appendChild(img);
} }
} catch (exception) {
}
var span = document.createElement('span'); var span = document.createElement('span');
span.innerHTML = 'Jexcel spreadsheet'; span.innerHTML = 'Jexcel spreadsheet';
ads.appendChild(span); ads.appendChild(span);
...@@ -1117,9 +1123,22 @@ console.log(ret); ...@@ -1117,9 +1123,22 @@ console.log(ret);
td.setAttribute('data-x', i); td.setAttribute('data-x', i);
td.setAttribute('data-y', j); 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 // Custom column
if (obj.options.columns[i].editor) { if (obj.options.columns[i].editor) {
if (obj.options.stripHTML === false || obj.options.columns[i].stripHTML === false) {
td.innerHTML = value; td.innerHTML = value;
} else {
td.innerText = value;
}
if (typeof(obj.options.columns[i].editor.createCell) == 'function') { if (typeof(obj.options.columns[i].editor.createCell) == 'function') {
td = obj.options.columns[i].editor.createCell(td); td = obj.options.columns[i].editor.createCell(td);
} }
...@@ -1127,7 +1146,7 @@ console.log(ret); ...@@ -1127,7 +1146,7 @@ console.log(ret);
// Hidden column // Hidden column
if (obj.options.columns[i].type == 'hidden') { if (obj.options.columns[i].type == 'hidden') {
td.style.display = 'none'; td.style.display = 'none';
td.innerHTML = value; td.innerText = value;
} else if (obj.options.columns[i].type == 'checkbox' || obj.options.columns[i].type == 'radio') { } else if (obj.options.columns[i].type == 'checkbox' || obj.options.columns[i].type == 'radio') {
// Create input // Create input
var element = document.createElement('input'); var element = document.createElement('input');
...@@ -1150,11 +1169,11 @@ console.log(ret); ...@@ -1150,11 +1169,11 @@ console.log(ret);
// Try formatted date // Try formatted date
var formatted = jSuites.calendar.extractDateFromString(value, obj.options.columns[i].options.format); var formatted = jSuites.calendar.extractDateFromString(value, obj.options.columns[i].options.format);
// Create calendar cell // 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') { } else if (obj.options.columns[i].type == 'dropdown' || obj.options.columns[i].type == 'autocomplete') {
// Create dropdown cell // Create dropdown cell
td.classList.add('jexcel_dropdown'); 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') { } else if (obj.options.columns[i].type == 'color') {
if (obj.options.columns[i].render == 'square') { if (obj.options.columns[i].render == 'square') {
var color = document.createElement('div'); var color = document.createElement('div');
...@@ -1163,7 +1182,7 @@ console.log(ret); ...@@ -1163,7 +1182,7 @@ console.log(ret);
td.appendChild(color); td.appendChild(color);
} else { } else {
td.style.color = value; td.style.color = value;
td.innerHTML = value; td.innerText = value;
} }
} else if (obj.options.columns[i].type == 'image') { } else if (obj.options.columns[i].type == 'image') {
if (value && value.substr(0, 10) == 'data:image') { if (value && value.substr(0, 10) == 'data:image') {
...@@ -1172,7 +1191,15 @@ console.log(ret); ...@@ -1172,7 +1191,15 @@ console.log(ret);
td.appendChild(img); td.appendChild(img);
} }
} else { } 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); ...@@ -1211,7 +1238,7 @@ console.log(ret);
// Create header cell // Create header cell
obj.headers[colNumber] = document.createElement('td'); 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].setAttribute('data-x', colNumber);
obj.headers[colNumber].style.textAlign = colAlign; obj.headers[colNumber].style.textAlign = colAlign;
if (obj.options.columns[colNumber].title) { if (obj.options.columns[colNumber].title) {
...@@ -1235,7 +1262,7 @@ console.log(ret); ...@@ -1235,7 +1262,7 @@ console.log(ret);
obj.updateNestedHeader = function(x, y, title) { obj.updateNestedHeader = function(x, y, title) {
if (obj.options.nestedHeaders[y][x].title) { if (obj.options.nestedHeaders[y][x].title) {
obj.options.nestedHeaders[y][x].title = 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); ...@@ -1282,7 +1309,7 @@ console.log(ret);
td.setAttribute('data-column', column.join(',')); td.setAttribute('data-column', column.join(','));
td.setAttribute('colspan', nestedInformation[i].colspan); td.setAttribute('colspan', nestedInformation[i].colspan);
td.setAttribute('align', nestedInformation[i].align); td.setAttribute('align', nestedInformation[i].align);
td.innerHTML = nestedInformation[i].title; td.innerText = nestedInformation[i].title;
tr.appendChild(td); tr.appendChild(td);
} }
...@@ -1321,7 +1348,7 @@ console.log(ret); ...@@ -1321,7 +1348,7 @@ console.log(ret);
} }
} }
// Append element // Append element
toolbarItem.innerHTML = toolbar[i].content; toolbarItem.innerText = toolbar[i].content;
obj.toolbar.appendChild(toolbarItem); obj.toolbar.appendChild(toolbarItem);
} else if (toolbar[i].type == 'select') { } else if (toolbar[i].type == 'select') {
var toolbarItem = document.createElement('select'); var toolbarItem = document.createElement('select');
...@@ -1344,7 +1371,7 @@ console.log(ret); ...@@ -1344,7 +1371,7 @@ console.log(ret);
for(var j = 0; j < toolbar[i].v.length; j++) { for(var j = 0; j < toolbar[i].v.length; j++) {
var toolbarDropdownOption = document.createElement('option'); var toolbarDropdownOption = document.createElement('option');
toolbarDropdownOption.value = toolbar[i].v[j]; toolbarDropdownOption.value = toolbar[i].v[j];
toolbarDropdownOption.innerHTML = toolbar[i].v[j]; toolbarDropdownOption.innerText = toolbar[i].v[j];
toolbarItem.appendChild(toolbarDropdownOption); toolbarItem.appendChild(toolbarDropdownOption);
} }
obj.toolbar.appendChild(toolbarItem); obj.toolbar.appendChild(toolbarItem);
...@@ -1362,7 +1389,7 @@ console.log(ret); ...@@ -1362,7 +1389,7 @@ console.log(ret);
toolbarItem.onclick = function() { toolbarItem.onclick = function() {
this.color.open(); this.color.open();
} }
toolbarItem.innerHTML = toolbar[i].content; toolbarItem.innerText = toolbar[i].content;
jSuites.color(toolbarItem, { jSuites.color(toolbarItem, {
onchange:function(o, v) { onchange:function(o, v) {
var k = o.getAttribute('data-k'); var k = o.getAttribute('data-k');
...@@ -1648,7 +1675,7 @@ console.log(ret); ...@@ -1648,7 +1675,7 @@ console.log(ret);
obj.filter.children[columnId + 1].innerHTML = ''; obj.filter.children[columnId + 1].innerHTML = '';
obj.filter.children[columnId + 1].appendChild(div); obj.filter.children[columnId + 1].appendChild(div);
obj.filter.children[columnId + 1].style.paddingLeft = '0px'; 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'; obj.filter.children[columnId + 1].style.overflow = 'initial';
// Dynamic dropdown // Dynamic dropdown
...@@ -2221,6 +2248,17 @@ console.log(ret); ...@@ -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 * Update cell content
* *
...@@ -2238,6 +2276,15 @@ console.log(ret); ...@@ -2238,6 +2276,15 @@ console.log(ret);
row: y row: y
} }
} else { } 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 // On change
var val = obj.dispatch('onbeforechange', el, obj.records[y][x], x, y, value); var val = obj.dispatch('onbeforechange', el, obj.records[y][x], x, y, value);
...@@ -2279,13 +2326,13 @@ console.log(ret); ...@@ -2279,13 +2326,13 @@ console.log(ret);
} else if (obj.options.columns[x].type == 'dropdown' || obj.options.columns[x].type == 'autocomplete') { } else if (obj.options.columns[x].type == 'dropdown' || obj.options.columns[x].type == 'autocomplete') {
// Update data and cell // Update data and cell
obj.options.data[y][x] = value; 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') { } else if (obj.options.columns[x].type == 'calendar') {
// Update calendar // Update calendar
var formatted = jSuites.calendar.extractDateFromString(value, obj.options.columns[x].options.format); var formatted = jSuites.calendar.extractDateFromString(value, obj.options.columns[x].options.format);
// Update data and cell // Update data and cell
obj.options.data[y][x] = value; 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') { } else if (obj.options.columns[x].type == 'color') {
// Update color // Update color
obj.options.data[y][x] = value; obj.options.data[y][x] = value;
...@@ -2294,11 +2341,11 @@ console.log(ret); ...@@ -2294,11 +2341,11 @@ console.log(ret);
var color = document.createElement('div'); var color = document.createElement('div');
color.className = 'color'; color.className = 'color';
color.style.backgroundColor = value; color.style.backgroundColor = value;
obj.records[y][x].innerHTML = ''; obj.records[y][x].innerText = '';
obj.records[y][x].appendChild(color); obj.records[y][x].appendChild(color);
} else { } else {
obj.records[y][x].style.color = value; 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') { } else if (obj.options.columns[x].type == 'image') {
value = ''+value; value = ''+value;
...@@ -2313,7 +2360,15 @@ console.log(ret); ...@@ -2313,7 +2360,15 @@ console.log(ret);
// Update data and cell // Update data and cell
obj.options.data[y][x] = value; obj.options.data[y][x] = value;
// Label // 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 // 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)) { 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'; obj.records[y][x].style.whiteSpace = 'pre-wrap';
...@@ -3138,7 +3193,7 @@ console.log(ret); ...@@ -3138,7 +3193,7 @@ console.log(ret);
var colAlign = obj.options.columns[i].align ? obj.options.columns[i].align : 'center'; var colAlign = obj.options.columns[i].align ? obj.options.columns[i].align : 'center';
td.style.textAlign = colAlign; 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); ...@@ -3169,7 +3224,7 @@ console.log(ret);
} }
if (newValue) { if (newValue) {
obj.headers[column].innerHTML = newValue; obj.headers[column].innerText = newValue;
// Keep the title property // Keep the title property
obj.headers[column].setAttribute('title', newValue); obj.headers[column].setAttribute('title', newValue);
// Update title // Update title
...@@ -3526,8 +3581,8 @@ console.log(ret); ...@@ -3526,8 +3581,8 @@ console.log(ret);
// Filter // Filter
Array.prototype.orderBy = function(p, o) { Array.prototype.orderBy = function(p, o) {
return this.slice(0).sort(function(a, b) { return this.slice(0).sort(function(a, b) {
var valueA = a[p] == '' ? '' : Number(a[p]) == a[p] ? Number(a[p]) : a[p].toLowerCase(); var valueA = a[p];
var valueB = b[p] == '' ? '' : Number(b[p]) == b[p] ? Number(b[p]) : b[p].toLowerCase(); var valueB = b[p];
if (! o) { if (! o) {
return (valueA == '' && valueB != '') ? 1 : (valueA != '' && valueB == '') ? -1 : (valueA > valueB) ? 1 : (valueA < valueB) ? -1 : 0; return (valueA == '' && valueB != '') ? 1 : (valueA != '' && valueB == '') ? -1 : (valueA > valueB) ? 1 : (valueA < valueB) ? -1 : 0;
...@@ -3539,15 +3594,17 @@ console.log(ret); ...@@ -3539,15 +3594,17 @@ console.log(ret);
// Test order // Test order
var temp = []; var temp = [];
if (obj.options.columns[column].type == 'calendar' || 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') {
obj.options.columns[column].type == 'checkbox' || for (var j = 0; j < obj.options.data.length; j++) {
obj.options.columns[column].type == 'radio') { 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++) { for (var j = 0; j < obj.options.data.length; j++) {
temp[j] = [ j, obj.options.data[j][column] ]; temp[j] = [ j, obj.options.data[j][column] ];
} }
} else { } else {
for (var j = 0; j < obj.options.data.length; j++) { 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); temp = temp.orderBy(1, order);
...@@ -3622,7 +3679,7 @@ console.log(ret); ...@@ -3622,7 +3679,7 @@ console.log(ret);
obj.updateTableReferences(); obj.updateTableReferences();
// Redo search // Redo search
if (obj.results.length) { if (obj.results && obj.results.length) {
if (obj.searchInput.value) { if (obj.searchInput.value) {
obj.search(obj.searchInput.value); obj.search(obj.searchInput.value);
} else { } else {
...@@ -4782,6 +4839,32 @@ console.log(ret); ...@@ -4782,6 +4839,32 @@ console.log(ret);
return newFormula; 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 * Parse formulas
*/ */
...@@ -5912,6 +5995,9 @@ console.log(ret); ...@@ -5912,6 +5995,9 @@ console.log(ret);
// Keep non visible information // Keep non visible information
obj.hashString = obj.hash(obj.data); obj.hashString = obj.hash(obj.data);
// Any exiting border should go
obj.removeCopyingSelection();
// Border // Border
if (obj.highlighted) { if (obj.highlighted) {
for (var i = 0; i < obj.highlighted.length; i++) { for (var i = 0; i < obj.highlighted.length; i++) {
...@@ -7790,6 +7876,7 @@ console.log(ret); ...@@ -7790,6 +7876,7 @@ console.log(ret);
*/ */
jexcel.tabs = function(tabs, result) { jexcel.tabs = function(tabs, result) {
var instances = [];
// Create tab container // Create tab container
if (! tabs.classList.contains('jexcel_tabs')) { if (! tabs.classList.contains('jexcel_tabs')) {
tabs.innerHTML = ''; tabs.innerHTML = '';
...@@ -7813,7 +7900,7 @@ console.log(ret); ...@@ -7813,7 +7900,7 @@ console.log(ret);
spreadsheet[i].classList.add('jexcel_tab'); spreadsheet[i].classList.add('jexcel_tab');
var worksheet = jexcel(spreadsheet[i], result[i]); var worksheet = jexcel(spreadsheet[i], result[i]);
content.appendChild(spreadsheet[i]); content.appendChild(spreadsheet[i]);
tabs.jexcel.push(worksheet); instances[i] = tabs.jexcel.push(worksheet);
// Tab link // Tab link
link[i] = document.createElement('div'); link[i] = document.createElement('div');
...@@ -7839,6 +7926,8 @@ console.log(ret); ...@@ -7839,6 +7926,8 @@ console.log(ret);
} }
headers.children[headers.children.length - 1].classList.add('selected'); headers.children[headers.children.length - 1].classList.add('selected');
content.children[headers.children.length - 1].style.display = 'block'; content.children[headers.children.length - 1].style.display = 'block';
return instances;
} }
// Compability to older versions // 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