From 22ee7e502030adb3340068f665905eeac158e0cc Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 10 Apr 2017 17:17:56 +0200 Subject: [PATCH] Backup --- forms/admin/items/items.js | 13 ++-- forms/admin/items/ui.xml | 18 ++---- forms/admin/shelves/ui.xml | 4 +- forms/ecomerce/orders/style.css | 2 +- forms/ecomerce/orders/ui.xml | 8 ++- js/db/connection.js | 7 +- js/db/model.js | 66 +++++++++++-------- js/htk/repeater.js | 4 +- js/sql/holder.js | 21 +++--- js/vn/builder.js | 8 +-- js/vn/hash.js | 82 ++++++++++++++++++------ js/vn/object.js | 19 +++--- js/vn/value.js | 32 +++++++++ reports/delivery-note/ui.xml | 14 ++-- reports/shelves-report/shelves-report.js | 10 +-- reports/shelves-report/style.css | 2 +- 16 files changed, 202 insertions(+), 108 deletions(-) diff --git a/forms/admin/items/items.js b/forms/admin/items/items.js index 80f4e900..240a7de3 100644 --- a/forms/admin/items/items.js +++ b/forms/admin/items/items.js @@ -5,16 +5,17 @@ Hedera.Items = new Class ,activate: function () { - var set = this.$('set'); - set.set ('warehouse', 7); - set.set ('realm', null); + this.$('lot').assign ({ + warehouse: 7, + realm: null + }); } ,onShowClick: function () { - var set = this.$('set'); - set.set ('rate', this.$('rate').value); - this.gui.openReport ('items-report', set.params); + var lot = this.$('lot'); + lot.assign ({rate: this.$('rate').value}); + this.gui.openReport ('items-report', lot.params); } }); diff --git a/forms/admin/items/ui.xml b/forms/admin/items/ui.xml index b08753b6..97f8ca06 100755 --- a/forms/admin/items/ui.xml +++ b/forms/admin/items/ui.xml @@ -1,5 +1,5 @@ - +

Item list

@@ -13,23 +13,19 @@
- + - - SELECT id, name FROM vn2008.warehouse - WHERE reserve ORDER BY name - + SELECT id, name FROM vn2008.warehouse + WHERE reserve ORDER BY name
- + - - SELECT id, reino FROM vn2008.reinos - WHERE display != FALSE ORDER BY reino - + SELECT id, reino FROM vn2008.reinos + WHERE display != FALSE ORDER BY reino
diff --git a/forms/admin/shelves/ui.xml b/forms/admin/shelves/ui.xml index 2f2f173b..b366d773 100755 --- a/forms/admin/shelves/ui.xml +++ b/forms/admin/shelves/ui.xml @@ -17,6 +17,8 @@ id="config" placeholder="_Select config" model="configs-model" + lot="hash" + name="config" on-changed="onConfigChange" on-ready="onConfigChange"> @@ -43,7 +45,7 @@
- + SELECT tipo_id, Tipo FROM vn2008.Tipos WHERE reino_id = #realm ORDER BY Tipo diff --git a/forms/ecomerce/orders/style.css b/forms/ecomerce/orders/style.css index 47cbc93c..a91f84f3 100644 --- a/forms/ecomerce/orders/style.css +++ b/forms/ecomerce/orders/style.css @@ -9,7 +9,6 @@ .balance { margin-top: 1.2em; - margin-right: .5em; } .balance > * { @@ -26,6 +25,7 @@ cursor: pointer; height: 1.2em; cursor: pointer; + margin: 0 .3em; } .balance > .negative { diff --git a/forms/ecomerce/orders/ui.xml b/forms/ecomerce/orders/ui.xml index 51bd6b84..1d1b6c22 100755 --- a/forms/ecomerce/orders/ui.xml +++ b/forms/ecomerce/orders/ui.xml @@ -26,7 +26,11 @@ Balance: - +
- + CALL clientTicketList (#from, NULL) diff --git a/js/db/connection.js b/js/db/connection.js index 83cbbf9f..0e61da41 100644 --- a/js/db/connection.js +++ b/js/db/connection.js @@ -72,7 +72,12 @@ Connection.implement */ ,execQuery: function (query, callback, params) { - this.execStmt (new Sql.String ({query: query}), callback, params); + this.execSql (this.renderQuery (query, params), callback); + } + + ,renderQuery: function (query, params) + { + return new Sql.String ({query: query}).render (params); } /* diff --git a/js/db/model.js b/js/db/model.js index fc6c8a8b..d447c452 100644 --- a/js/db/model.js +++ b/js/db/model.js @@ -109,8 +109,8 @@ Model.implement type: Vn.Lot ,set: function (x) { - this.link ({_lot: x}, {'change': this._autoLoad}); - this._autoLoad (); + this.link ({_lot: x}, {'change': this._onLotChange}); + this._onLotChange (); } ,get: function () { @@ -242,6 +242,7 @@ Model.implement ,_conn: null ,_resultIndex: 0 ,_batch: null + ,_lot: null ,_stmt: null ,_status: Status.CLEAN ,data: null @@ -276,7 +277,34 @@ Model.implement if (child.nodeType === Node.TEXT_NODE) this.query = child.textContent; } - + + ,_getParams: function () + { + if (!this._stmt) + return null; + + var ids = this._stmt.findHolders (); + + if (!ids) + return null; + + var lotParams = this._lot ? this._lot.params : {}; + var params = {}; + + for (var i = 0; i < ids.length; i++) + params[ids[i]] = lotParams[ids[i]]; + + return params; + } + + ,_onLotChange: function () + { + var params = this._getParams (); + + if (!Vn.Value.equals (params, this._lastParams)) + this._autoLoad (); + } + ,_autoLoad: function () { if (this.autoLoad) @@ -285,31 +313,15 @@ Model.implement this.clean (); } - /** - * Checks wether the model is ready to execute its query. - * - * @return {Boolean} %true if its ready, %false otherwise - */ - ,isReady: function () + ,_isReady: function (params) { if (!this._stmt || !this._conn) return false; - - var ids = this._stmt.findHolders (); - - if (!ids) + if (!params) return true; - if (!this._lot) - return false; - - var params = this._lot.params; - - if (!params) - return false; - - for (var i = 0; i < ids.length; i++) - if (params[ids[i]] === undefined) + for (var key in params) + if (params[key] === undefined) return false; return true; @@ -320,9 +332,11 @@ Model.implement */ ,refresh: function () { - if (this.isReady ()) + var params = this._getParams (); + + if (this._isReady (params)) { - var params = this._lot ? this._lot.params : null; + this._lastParams = params; this._setStatus (Status.LOADING); this._conn.execStmt (this._stmt, this._selectDone.bind (this), params); } @@ -396,7 +410,7 @@ Model.implement } } - ,_cleanData: function (error) + ,_cleanData: function () { this.data = null; this.tables = null; diff --git a/js/htk/repeater.js b/js/htk/repeater.js index 57260834..5c00690b 100644 --- a/js/htk/repeater.js +++ b/js/htk/repeater.js @@ -237,8 +237,8 @@ module.exports = new Class childData.set.unref (); childData.builder.unref (); } - - ,destroy: function () + + ,_destroy: function () { this._freeChildsData (); this.parent (); diff --git a/js/sql/holder.js b/js/sql/holder.js index 3ca40e0d..cde1b234 100644 --- a/js/sql/holder.js +++ b/js/sql/holder.js @@ -19,18 +19,21 @@ module.exports = new Class ,render: function (params) { - var object; - - if (params && (object = params[this.id])) + if (params) { - if (!(object instanceof SqlObject)) + var object = params[this.id]; + + if (object != null) { - var sqlValue = new Value (); - sqlValue.value = object; - return sqlValue.render (); + if (!(object instanceof SqlObject)) + { + var sqlValue = new Value (); + sqlValue.value = object; + return sqlValue.render (); + } + else + return object.render (params); } - else - return object.render (params); } return '#'+ this.id; diff --git a/js/vn/builder.js b/js/vn/builder.js index 010fff4a..09b07ef7 100644 --- a/js/vn/builder.js +++ b/js/vn/builder.js @@ -1,5 +1,5 @@ -var Object = require ('./object'); +var VnObject = require ('./object'); var Type = require ('./type'); /** @@ -7,7 +7,7 @@ var Type = require ('./type'); */ module.exports = new Class ({ - Extends: Object + Extends: VnObject ,_addedMap: {} ,_contexts: null @@ -577,7 +577,7 @@ module.exports = new Class var BuilderResult = new Class ({ - Extends: Object + Extends: VnObject ,initialize: function (builder, objects) { @@ -615,7 +615,7 @@ var BuilderResult = new Class var objects = this.objects; for (var i = 0; i < objects.length; i++) - if (objects[i] instanceof Object) + if (objects[i] instanceof VnObject) objects[i].unref (); this.parent (); diff --git a/js/vn/hash.js b/js/vn/hash.js index efe28d87..982507d8 100644 --- a/js/vn/hash.js +++ b/js/vn/hash.js @@ -2,6 +2,7 @@ var VnObject = require ('./object'); var VnDate = require ('./date'); var Lot = require ('./lot'); +var Value = require ('./value'); /** * Class to handle the URL. @@ -48,9 +49,9 @@ module.exports = new Class this.parent (props); } - ,get: function (key, type) + ,get: function (key) { - return this.parseValue (this._hashMap[key], type); + return this._hashMap[key]; } ,set: function (key, value) @@ -67,8 +68,10 @@ module.exports = new Class */ ,assign: function (object) { - var newObject = this._hashMap; + var newObject = {}; + for (var key in this._hashMap) + newObject[key] = this._hashMap[key]; for (var key in object) newObject[key] = object[key]; @@ -92,7 +95,7 @@ module.exports = new Class if (!object) object = {}; - if (newHash !== this._hash) + if (!Value.equals (this._hashMap, object)) { this._hashMap = object; this._hash = newHash; @@ -135,8 +138,8 @@ module.exports = new Class ,_hashChanged: function () { var newHash = location.hash; - - if (this._blockChanged || newHash === this._hash) + + if (this._blockChanged || this._hash == newHash) return; var newMap = hashMap = {}; @@ -147,12 +150,15 @@ module.exports = new Class var kvPair = kvPairs[i].split ('=', 2); if (kvPair[0]) - newMap[decodeURIComponent (kvPair[0])] = decodeURIComponent (kvPair[1]); + newMap[decodeURIComponent (kvPair[0])] = this.parseValue (kvPair[1]); } - this._hashMap = newMap; - this._hash = newHash; - this.changed (); + if (!Value.equals (this._hashMap, newMap)) + { + this._hashMap = newMap; + this._hash = newHash; + this.changed (); + } } ,renderValue: function (v) @@ -160,36 +166,70 @@ module.exports = new Class switch (typeof v) { case 'number': - return v; + return '(Number)'+ v; case 'boolean': - return (v) ? 'true' : 'false'; + return '(Boolean)'+ (v ? 'true' : 'false'); case 'object': if (v instanceof Date) - return VnDate.strftime (v, '%Y-%m-%d'); + return '(Date)'+ VnDate.strftime (v, '%Y-%m-%d'); + else + return '(Object)'+ JSON.stringify (v) + } + + switch (v.charAt (0)) + { + case '(': + case '\\': + return '\\'+ v; } return v; } - ,parseValue: function (v, type) + ,parseValue: function (v) { + if (v == null) + return v; + + v = decodeURIComponent (v); + + if (v === '') + return v; + + var typeStr; + + switch (v.charAt(0)) + { + case '(': + var index = v.indexOf (')'); + typeStr = v.substr (1, index - 1); + v = v.substr (index + 1); + break; + case '\\': + v = v.substr (1); + break; + } + if (v === '') return null; + if (!typeStr) + return v; - if (type && v !== undefined && v !== null) - switch (type) + switch (typeStr) { - case Boolean: + case 'Boolean': return (/^(true|1)$/i).test (v); - case Number: + case 'Number': return 0 + new Number (v); - case Date: + case 'Date': var date = new Date (v); date.setHours (0, 0, 0, 0); return date; + case 'Object': + return JSON.parse (v); + default: + return v; } - - return v; } ,_destroy: function () diff --git a/js/vn/object.js b/js/vn/object.js index 7d1e890d..6a308c13 100644 --- a/js/vn/object.js +++ b/js/vn/object.js @@ -156,8 +156,8 @@ module.exports = new Class return; for (var i = 0; i < callbacks.length; i++) - if (callbacks[i].callback == callback - && callbacks[i].instance == instance) + if (callbacks[i].callback === callback + && callbacks[i].instance === instance) callbacks.splice (i--, 1); } @@ -178,7 +178,7 @@ module.exports = new Class var callbacks = signals[signalId]; for (var i = 0; i < callbacks.length; i++) - if (callbacks[i].instance == instance) + if (callbacks[i].instance === instance) callbacks.splice (i--, 1); } } @@ -195,10 +195,16 @@ module.exports = new Class var links = this._signalData.links; for (var key in links) - links[key].disconnectByInstance (this); + this._unlink (links[key]); this._signalData = null; } + + ,_unlink: function (object) + { + object.disconnectByInstance (this); + object.unref (); + } /** * Links the object with another object. @@ -217,10 +223,7 @@ module.exports = new Class var oldObject = this[key]; if (oldObject) - { - oldObject.disconnectByInstance (this); - oldObject.unref (); - } + this._unlink (oldObject); this[key] = newObject; diff --git a/js/vn/value.js b/js/vn/value.js index a4c30c90..c21603ed 100644 --- a/js/vn/value.js +++ b/js/vn/value.js @@ -1,11 +1,43 @@ var VnDate = require ('./date'); +/** + * Checks if two values are equal, it also checks objects. Basic + * values are compared using the non-strict equality operator. + * + * @param {*} a Value to compare to + * @param {*} b Value to compare with + * @return {Boolean} %true if they are equal, %false otherwise + */ +function equals (a, b) +{ + if (a == b) + return true; + if (a instanceof Date && b instanceof Date) + return a.getTime () === b.getTime (); + if (a && b && (typeof a === 'object') && (typeof b === 'object')) + { + for (var key in a) + if (!equals (a[key], b[key])) + return false; + + for (var key in b) + if (a[key] === undefined && b[key] != null) + return false; + + return true; + } + + return false; +} + module.exports = { regexpNumber: /%\.([0-9]+)d/g ,regexpString: /%s/g + ,equals: equals + ,compare: function (a, b) { if (a === b) diff --git a/reports/delivery-note/ui.xml b/reports/delivery-note/ui.xml index 9279c3e7..c63b7b85 100755 --- a/reports/delivery-note/ui.xml +++ b/reports/delivery-note/ui.xml @@ -33,13 +33,13 @@ CALL clientTicketRowGet(#ticket) - - - - - - - + + + + + + +