From 1bc8a8a13d7d44af394723851334a61c5e1319fa Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Wed, 13 Apr 2016 15:51:34 +0300 Subject: [PATCH] Fix DB creation, fix treegrid header resize, implement payment viewing and editing --- treegrid.js | 36 ++++++++++++++++++++---------------- util.js | 36 +++++++++++++++++------------------- 2 files changed, 37 insertions(+), 35 deletions(-) diff --git a/treegrid.js b/treegrid.js index c403549..1c33578 100644 --- a/treegrid.js +++ b/treegrid.js @@ -1,7 +1,7 @@ /** * Very simple and fast tree grid/table, compatible with dynamic loading and jQuery fixedHeaderTable * License: MPL 2.0+, (c) Vitaliy Filippov 2016+ - * Version: 2016-04-04 + * Version: 2016-04-13 */ /** @@ -192,6 +192,21 @@ TreeGrid.prototype.initCellSelection = function(restrictToNode) var self = this; + self.selectCell = function(cell) + { + if (!cell.parentNode._node || cell.className.indexOf(' selected') >= 0) + return; + var i = self.getNodeIndex(cell); + if (!self.onCellSelect || self.onCellSelect(cell.parentNode._node, i, cell)) + cell.className += ' selected'; + }; + + self.deselectCell = function(cell) + { + self.onCellDeselect && self.onCellDeselect(cell.parentNode._node, self.getNodeIndex(cell), cell); + cell.className = cell.className.replace(' selected', ''); + }; + addListener(restrictToNode || document.body, 'mousedown', function(evt) { evt = getEventCoord(evt); @@ -199,10 +214,7 @@ TreeGrid.prototype.initCellSelection = function(restrictToNode) { var els = self.table.querySelectorAll('td.selected'); for (var i = 0; i < els.length; i++) - { - self.onCellDeselect && self.onCellDeselect(els[i].parentNode._node, self.getNodeIndex(els[i]), els[i]); - els[i].className = els[i].className.replace(' selected', ''); - } + self.deselectCell(els[i]); } if (evt.which != 1) return; @@ -272,20 +284,12 @@ TreeGrid.prototype.initCellSelection = function(restrictToNode) y1 = t; } startDrag = null; - function doSelect() - { - if (!this.parentNode._node) - return; - var i = self.getNodeIndex(this); - if (!self.onCellSelect || self.onCellSelect(this.parentNode._node, i, this)) - this.className += ' selected'; - } if (x2 > x1+10 && y2 > y1+10) - rectangleSelect(self.table.getElementsByTagName('td'), x1, y1, x2, y2, doSelect); + rectangleSelect(self.table.getElementsByTagName('td'), x1, y1, x2, y2, self.selectCell); else { var t = evt.target || evt.srcElement; - doSelect.apply(t); + self.selectCell(t); } if (x2 > x1+10 && y2 > y1+10 || evt.shiftKey) { @@ -305,7 +309,7 @@ TreeGrid.prototype.initCellSelection = function(restrictToNode) var w = elements[i].offsetWidth; var h = elements[i].offsetHeight; if (offset.left+w >= x1 && offset.top+h >= y1 && offset.left <= x2 && offset.top <= y2) - cb.apply(elements[i]); + cb(elements[i]); } } } diff --git a/util.js b/util.js index fd0f732..3039e34 100644 --- a/util.js +++ b/util.js @@ -153,21 +153,22 @@ var setCallback = function(r, cb) } }; }; -window.http_build_query = function(data) +var build_array_query = function(data, prefix) { - var encoded = ''; + var s = '', k; for (var i in data) { + k = prefix ? prefix+'['+encodeURIComponent(i)+']' : encodeURIComponent(i); if (typeof data[i] == 'object') - { - var ii = encodeURIComponent(i); - for (var k in data[i]) - encoded = encoded+'&'+ii+'['+encodeURIComponent(k)+']='+(data[i][k] === false || data[i] === null ? '' : encodeURIComponent(data[i][k])); - } + s += build_array_query(data[i], k); else - encoded = encoded+'&'+encodeURIComponent(i)+'='+(data[i] === false || data[i] === null ? '' : encodeURIComponent(data[i])); + s = s+'&'+k+'='+(data[i] === false || data[i] === null ? '' : encodeURIComponent(data[i])); } - return encoded.substr(1); + return s; +}; +window.http_build_query = function(data) +{ + return build_array_query(data).substr(1); }; window.GET = function(url, data, cb) @@ -197,19 +198,13 @@ window.cloneObject = function(o) { if (!o || 'object' !== typeof o) return o; - var c = 'function' === typeof o.pop ? [] : {}; + if (o instanceof Date) + return new Date(+o); + var c = o instanceof Array ? [] : {}; var p, v; for (p in o) - { if (o.hasOwnProperty(p)) - { - v = o[p]; - if(v && 'object' === typeof v) - c[p] = cloneObject(v); - else - c[p] = v; - } - } + c[p] = cloneObject(o[p]); return c; } @@ -350,3 +345,6 @@ window.addCSS = function(css) s.innerHTML = css; document.getElementsByTagName('head')[0].appendChild(s); }; + +window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || + window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;