From 37236b6bb05f261b3a12452f231eb283862e1ba5 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Sat, 28 Oct 2017 17:13:00 +0200 Subject: [PATCH] Various fixes --- forms/account/conf/conf.js | 22 ++- forms/account/conf/style.css | 3 +- forms/account/conf/ui.xml | 18 +- forms/cms/home/ui.xml | 8 +- forms/cms/location/info.xml | 15 ++ forms/cms/location/location.js | 46 ++--- forms/ecomerce/basket/basket.js | 6 +- forms/ecomerce/catalog/catalog.js | 4 +- forms/ecomerce/catalog/ui.xml | 35 ++-- forms/ecomerce/checkout/checkout.js | 98 ++++----- forms/ecomerce/checkout/style.css | 6 +- forms/ecomerce/checkout/ui.xml | 101 ++++------ forms/ecomerce/confirm/ui.xml | 30 ++- js/db/model.js | 242 ++++++++++++----------- js/db/result-set.js | 46 +++-- js/db/result.js | 27 +-- js/hedera/app.js | 2 +- js/hedera/gui.js | 52 +++-- js/hedera/social-bar.js | 16 +- js/hedera/tpv.js | 2 +- js/htk/assistant.js | 53 ++++- js/htk/field/combo.js | 7 +- js/htk/popup.js | 7 +- js/htk/step.js | 23 +++ js/htk/style.css | 5 +- js/vn/iterator.js | 6 +- js/vn/json-model.js | 90 --------- js/vn/model.js | 118 ++++------- js/vn/scope.js | 10 +- js/vn/vn.js | 1 - reports/shelves-report/shelves-report.js | 51 ++--- webpack.config.js | 3 + 32 files changed, 543 insertions(+), 610 deletions(-) create mode 100644 forms/cms/location/info.xml create mode 100644 js/htk/step.js delete mode 100644 js/vn/json-model.js diff --git a/forms/account/conf/conf.js b/forms/account/conf/conf.js index 3a331c14..4a2d2a2d 100644 --- a/forms/account/conf/conf.js +++ b/forms/account/conf/conf.js @@ -6,6 +6,19 @@ Hedera.Conf = new Class ,activate: function () { this.$.userModel.setInfo ('c', 'customer_view', 'hedera'); + + if (this.hash.$.changePass) + this.onPassChangeClick (); + } + + ,onChangePassOpen: function () + { + this.hash.assign ({changePass: true}); + } + + ,onChangePassClose: function () + { + this.hash.assign ({changePass: undefined}); } ,onPassChangeClick: function () @@ -17,11 +30,16 @@ Hedera.Conf = new Class var recoverPass = this.$.user.get ('recoverPass'); this.$.oldPassword.style.display = recoverPass ? 'none' : 'block'; this.$.changePassword.show (); + + var focusInput; if (recoverPass) - this.$.newPassword.focus (); + focusInput = this.$.newPassword; else - this.$.oldPassword.focus (); + focusInput = this.$.oldPassword; + + focusInput.focus (); + focusInput.select (); } ,onPassModifyClick: function () diff --git a/forms/account/conf/style.css b/forms/account/conf/style.css index 218434b6..8df999ed 100644 --- a/forms/account/conf/style.css +++ b/forms/account/conf/style.css @@ -11,9 +11,10 @@ .pass-info { - width: 15em; + max-width: 17em; } .pass-info ul { list-style-type: none; + padding-left: 1.5em; } diff --git a/forms/account/conf/ui.xml b/forms/account/conf/ui.xml index 4b80144f..73b2d8b4 100755 --- a/forms/account/conf/ui.xml +++ b/forms/account/conf/ui.xml @@ -39,13 +39,17 @@
- - + + + +
@@ -82,19 +86,19 @@
  • - _characters long + {{passwordForm.length}} _characters long
  • - _alphabetic characters + {{passwordForm.nAlpha}} _alphabetic characters
  • - _capital letters + {{passwordForm.nUpper}} _capital letters
  • - _digits + {{passwordForm.nDigits}} _digits
  • - _symbols + {{passwordForm.nPunct}} _symbols
diff --git a/forms/cms/home/ui.xml b/forms/cms/home/ui.xml index b1724c30..6c4f245c 100755 --- a/forms/cms/home/ui.xml +++ b/forms/cms/home/ui.xml @@ -11,7 +11,7 @@
- + SELECT title, text, image, id FROM news WHERE tag != 'course' @@ -21,15 +21,15 @@
-

{{title}}

+

{{new.title}}

- +
diff --git a/forms/cms/location/info.xml b/forms/cms/location/info.xml new file mode 100644 index 00000000..6e4107ab --- /dev/null +++ b/forms/cms/location/info.xml @@ -0,0 +1,15 @@ +
+

{{title}}

+

+ {{address}} +

+

+ {{postcode}} {{city}} +

+

+ {{province}} +

+

+ {{phone}} +

+
\ No newline at end of file diff --git a/forms/cms/location/location.js b/forms/cms/location/location.js index 5d0e7b3c..aaef15b8 100644 --- a/forms/cms/location/location.js +++ b/forms/cms/location/location.js @@ -1,5 +1,8 @@ +var infoTpl = require (__dirname +'/info.xml'); + var gmapsIsLoaded = false; +var gmapsLoadedCallback; Hedera.Location = new Class ({ @@ -10,6 +13,9 @@ Hedera.Location = new Class ,activate: function () { this.gui.loaderPush (); + + this.infoBuilder = new Vn.Builder(); + this.infoBuilder.compileString (infoTpl); var sql = 'SELECT lat, lng, title, address, postcode, city, province, phone, language FROM location'; this.conn.execQuery (sql, this.onLocationsDone.bind (this)); @@ -26,7 +32,7 @@ Hedera.Location = new Class ,onLocationsDone: function (resultSet) { - this.locations = resultSet.fetchResult (); + this.locations = resultSet.fetchArray (); this.allLoaded (); } @@ -50,40 +56,20 @@ Hedera.Location = new Class var div = this.$.form; var gmap = new google.maps.Map (div, options); - var row; - while (row = this.locations.fetchObject ()) - this.createMarker (row, gmap); + locations.forEach (function (location) { + this.createMarker (location, gmap); + }, this); } - ,createMarker: function (row, gmap) + ,createMarker: function (location, gmap) { - var div = document.createElement ('div'); - div.className = 'marker'; - - var h = document.createElement ('h3'); - h.appendChild (document.createTextNode (row.title)); - div.appendChild (h); - - var p = document.createElement ('p'); - p.appendChild (document.createTextNode (row.address)); - div.appendChild (p); - - var p = document.createElement ('p'); - p.appendChild (document.createTextNode (row.postcode +' '+ row.city)); - div.appendChild (p); - - var p = document.createElement ('p'); - p.appendChild (document.createTextNode (row.province)); - div.appendChild (p); - - var p = document.createElement ('p'); - p.appendChild (document.createTextNode (row.phone)); - div.appendChild (p); + var scope = this.infoBuilder.load (this.doc, this, null, null, location); + var div = scope.getMain (); var lat = new google.maps.LatLng ( - row.lat, - row.lng + location.lat, + location.lng ); var marker = new google.maps.Marker ({ @@ -100,7 +86,7 @@ Hedera.Location = new Class this.openInfoWindow.bind (this, infoWindow, gmap, marker)); if (Vn.Locale.language - && Vn.Locale.language == row.language) + && Vn.Locale.language == location.language) this.openInfoWindow (infoWindow, gmap, marker); } diff --git a/forms/ecomerce/basket/basket.js b/forms/ecomerce/basket/basket.js index 7ae1bf06..4a8d6cb6 100644 --- a/forms/ecomerce/basket/basket.js +++ b/forms/ecomerce/basket/basket.js @@ -26,17 +26,17 @@ Hedera.Basket = new Class ,onConfigureClick: function () { Htk.Toast.showWarning (_('RememberReconfiguringImpact')); - this.hash.setAll ({'form': 'ecomerce/checkout'}); + this.hash.setAll ({form: 'ecomerce/checkout'}); } ,onCatalogClick: function () { - this.hash.setAll ({'form': 'ecomerce/catalog'}); + this.hash.setAll ({form: 'ecomerce/catalog'}); } ,onCheckoutClick: function () { - this.hash.setAll ({'form': 'ecomerce/confirm'}); + this.hash.setAll ({form: 'ecomerce/confirm'}); } ,repeaterFunc: function (res, form) diff --git a/forms/ecomerce/catalog/catalog.js b/forms/ecomerce/catalog/catalog.js index 3823e653..2b261668 100644 --- a/forms/ecomerce/catalog/catalog.js +++ b/forms/ecomerce/catalog/catalog.js @@ -52,7 +52,7 @@ Hedera.Catalog = new Class ,deactivate: function () { this.hideMenu (); - this.gui.$.topBar.style.backgroundColor = ''; + this.gui.$.navbar.style.backgroundColor = ''; Vn.Node.remove (this.$.rightPanel); } @@ -161,7 +161,7 @@ Hedera.Catalog = new Class color = '#'+ realms.get (row, 'color'); } - this.gui.$.topBar.style.backgroundColor = color; + this.gui.$.navbar.style.backgroundColor = color; } ,refreshTitle: function () diff --git a/forms/ecomerce/catalog/ui.xml b/forms/ecomerce/catalog/ui.xml index ebdf0cdf..0459ce51 100755 --- a/forms/ecomerce/catalog/ui.xml +++ b/forms/ecomerce/catalog/ui.xml @@ -137,29 +137,28 @@ full-dir="900x900"/>
-

{{Article}}

+

{{item.Article}}

- {{producer}} + {{item.producer}}

- @{{item_id}} + @{{item.item_id}}

- _Size - _Category + _Size {{item.Medida}} + _Category {{item.Categoria}}

- _Color + _Color {{item.color}}

diff --git a/forms/ecomerce/checkout/checkout.js b/forms/ecomerce/checkout/checkout.js index defd2fe2..1021bf16 100644 --- a/forms/ecomerce/checkout/checkout.js +++ b/forms/ecomerce/checkout/checkout.js @@ -1,3 +1,22 @@ +(function () { + +var methodsData = { + AGENCY: { + steps: ['method', 'date', 'address', 'agency', 'confirm'], + isDelivery: true, + textId: 'agencyText' + }, + DELIVERY: { + steps: ['method', 'date', 'address', null, 'confirm'], + isDelivery: true, + textId: 'deliveryText' + }, + PICKUP: { + steps: ['method', 'date', 'address', 'pickup', 'confirm'], + isDelivery: false, + textId: 'pickupText' + } +}; Hedera.Checkout = new Class ({ @@ -28,7 +47,7 @@ Hedera.Checkout = new Class if (orderForm.numRows > 0) { var i = orderForm; - date = i.get ('date_send'); + date = i.$.date_send; } else var i = defaultsForm; @@ -37,7 +56,7 @@ Hedera.Checkout = new Class { date = new Date (); - if (i.get('delivery_method') != 'PICKUP') + if (i.$.delivery_method != 'PICKUP') date.setDate (date.getDate () + 1); date.setHours (0, 0, 0, 0); @@ -45,18 +64,16 @@ Hedera.Checkout = new Class this.$.lot.assign ({ date: date, - method: i.get ('delivery_method'), - agency: i.get ('agency_id'), - address: i.get ('address_id') + method: i.$.delivery_method, + agency: i.$.agency_id, + address: i.$.address_id }); this.autoStepLocked = false; } ,disableButtons: function (disable) { - this.$.confirmAgency.disabled = disable; - this.$.confirmDelivery.disabled = disable; - this.$.confirmPickup.disabled = disable; + this.$.confirmButton.disabled = disable; } ,onConfirmClick: function () @@ -75,10 +92,8 @@ Hedera.Checkout = new Class if (!resultSet.fetchResult ()) return; - if (this.$.orderForm.numRows > 0) - Htk.Toast.showMessage (_('OrderUpdated')); - else - Htk.Toast.showMessage (_('OrderStarted')); + var isUpdated = this.$.orderForm.numRows > 0; + Htk.Toast.showMessage (_(isUpdated ? 'OrderUpdated' : 'OrderStarted')); this.hash.setAll ({form: 'ecomerce/catalog'}); } @@ -88,55 +103,45 @@ Hedera.Checkout = new Class if (this.$.orderForm.numRows > 0) window.history.back(); else - this.hash.setAll ({'form': 'ecomerce/orders'}); + this.hash.setAll ({form: 'ecomerce/orders'}); } - ,agencySteps: ['method', 'date', 'address', 'agency', 'confirm-agency'] - ,deliverySteps: ['method', 'date', 'address', null, 'confirm-delivery'] - ,pickupSteps: ['method', 'date', 'address', 'pickup', 'confirm-pickup'] - ,stepFunc: function (stepIndex) { - var steps; - var isDelivery; - - switch (this.$.rgMethod.value) - { - case 'AGENCY': - steps = this.agencySteps; - isDelivery = true; - break; - case 'DELIVERY': - steps = this.deliverySteps; - isDelivery = true; - break; - case 'PICKUP': - default: - steps = this.pickupSteps; - isDelivery = false; - break; - } + var method = this.$.rgMethod.value; + var methodData = methodsData[method]; + var stepName; - var stepId = steps[stepIndex]; - - if (!stepId) + if (methodData !== undefined) + stepName = methodData.steps[stepIndex]; + else + stepName = 'method'; + + if (!stepName) return null; - switch (stepId) + switch (stepName) { case 'date': - Vn.Node.setText (this.$.dateQuestion, isDelivery ? - _('OrderDateDeliveryQuestion'): - _('OrderDatePickupQuestion')); + var dateQuestion = methodData.isDelivery ? + 'OrderDateDeliveryQuestion' : 'OrderDatePickupQuestion'; + Vn.Node.setText (_(dateQuestion)); this.$.calendar.goToSelectedMonth (); break; case 'agency': case 'pickup': this.$.agencies.refresh (); break; + case 'confirm': + for (var myMethod in methodsData) + { + var display = myMethod == method ? 'block': 'none'; + this.$[methodsData[myMethod].textId].style.display = display; + } + break; } - return this.$[stepId +'Step']; + return stepName; } ,onFieldChange: function () @@ -153,7 +158,7 @@ Hedera.Checkout = new Class ,addressRenderer: function (builder, form) { builder.$.address.addEventListener ('click', - this.onAddressClick.bind (this, form.get ('id'))); + this.onAddressClick.bind (this, form.$.id)); } ,onAddressClick: function (addressId) @@ -167,7 +172,7 @@ Hedera.Checkout = new Class if (this.selectedNode) Vn.Node.removeClass (this.selectedNode, 'selected'); - var row = this.$.addresses.search ('id', this.$.lot.get ('address')); + var row = this.$.addresses.search ('id', this.$.lot.$.address); if (row != -1) { @@ -198,3 +203,4 @@ Hedera.Checkout = new Class } }); +})(); diff --git a/forms/ecomerce/checkout/style.css b/forms/ecomerce/checkout/style.css index 69afe227..37ed975d 100644 --- a/forms/ecomerce/checkout/style.css +++ b/forms/ecomerce/checkout/style.css @@ -71,15 +71,11 @@ .thin-calendar { width: inherit; - max-width: 24em; + max-width: 22em; margin: 0 auto; box-shadow: 0 0.1em 0.3em #ccc; font-size: .7em; } -.thin-calendar tr > th -{ - color: white; -} .htk-assistant .thin { float: right; diff --git a/forms/ecomerce/checkout/ui.xml b/forms/ecomerce/checkout/ui.xml index b0ee96e6..25c71ca3 100755 --- a/forms/ecomerce/checkout/ui.xml +++ b/forms/ecomerce/checkout/ui.xml @@ -14,6 +14,15 @@ JOIN vn.deliveryMethod d ON d.id = o.delivery_method_id + + + SELECT a.id, a.consignee, p.name province, a.zip_code, a.city, a.name, a.active, c.Pais country + FROM address_view a + LEFT JOIN vn2008.province p ON a.province_id = p.province_id + JOIN vn2008.Paises c ON c.Id = p.Paises_Id + WHERE active != FALSE + + -
-
+ step-func="stepFunc"> +

_DeliveryOrPickupQuestion

_PickupInStore
-
-
+ +

_OrderDateDeliveryQuestion

-
-
+ +

_AddressQuestion

-
- - SELECT a.id, a.consignee, p.name province, a.zip_code, a.city, a.name, a.active, c.Pais country - FROM address_view a - LEFT JOIN vn2008.province p ON a.province_id = p.province_id - JOIN vn2008.Paises c ON c.Id = p.Paises_Id - WHERE active != FALSE - + renderer="addressRenderer" + model="addresses">

- + {{consignee}}

- + {{name}}

-
-
+ +

_AgencyQuestion

-
-
+ +

_PickupWarehouseQuestion

-
-
+ +

_ConfirmToAccessCatalog

_Arrival

- + {{addressForm.name}}

-

- _Agency +

+ _Agency {{agency.description}}

- -
-
-
-
-

_ConfirmToAccessCatalog

-
-

- _Arrival -

-

- -

-

+

_ReceiveThroughtRoute

-
-
-
-

_ConfirmToAccessCatalog

-
-

- _Pickup -

-

- _Warehouse -

- -
-
-
-
+ +
diff --git a/forms/ecomerce/confirm/ui.xml b/forms/ecomerce/confirm/ui.xml index 273cb0b0..4ef9d95e 100755 --- a/forms/ecomerce/confirm/ui.xml +++ b/forms/ecomerce/confirm/ui.xml @@ -38,20 +38,18 @@

- _Agency - + _Agency {{order.agency}}

- + {{order.consignee}}

- + {{order.address}}

- , - + {{order.zipCode}}, {{order.city}}

@@ -147,29 +145,29 @@ name="payMethod" on-changed="onPayMethodChange"/>
- - + +
_You have a favorable balance.
- - + +
_You have a favorable credit.
- - + +
_You will be redirected to the payment.
- - + +
_Make a transfer to one account. @@ -195,8 +193,8 @@
- - + +
diff --git a/js/db/model.js b/js/db/model.js index 86b39b07..3a531f47 100644 --- a/js/db/model.js +++ b/js/db/model.js @@ -334,7 +334,11 @@ Klass.implement this.result = result; this.tables = result.tables; this.columns = result.columns; - this.columnMap = result.columnMap; + this.columnMap = {}; + + for (var i = 0; i < this.columns.length; i++) + this.columnMap[this.columns[i].name] = i; + this._repairColumns (); this._refreshMainTable (); @@ -348,19 +352,6 @@ Klass.implement this._setData (result.data); } - - ,_refreshRowIndexes: function (start) - { - this.parent (start); - - if (this._operationsMap) - { - this._operationsMap = {}; - - for (var i = 0; i < this._operations.length; i++) - this._operationsMap[i] = this._operations[i]; - } - } ,_cleanData: function () { @@ -402,58 +393,6 @@ Klass.implement this._refreshUpdatable (); } - /** - * Sets the default value for inserted rows. - * - * @param {String} column The destination column name - * @param {String} table The destination table name - * @param {Sql.Expr} expr The default value expression - */ - ,setDefault: function (column, table, expr) - { - this._defaults.push - ({ - column: column - ,table: table - ,expr: expr - }); - } - - /** - * Sets the default value for inserted rows. - * - * @param {String} column The destination column name - * @param {String} table The destination table name - * @param {*} value The default value - */ - ,setDefaultFromValue: function (column, table, value) - { - this._defaults.push - ({ - column: column - ,table: table - ,value: value - }); - } - - /** - * Sets the default value for inserted rows from another column in the - * model. - * - * @param {String} column The destination column name - * @param {String} table The destination table name - * @param {String} srcColumn The source column - */ - ,setDefaultFromColumn: function (column, table, srcColumn) - { - this._defaults.push - ({ - column: column - ,table: table - ,srcColumn: srcColumn - }); - } - /** * Checks if the column index exists. * @@ -621,6 +560,58 @@ Klass.implement return this.ready ? Object.keys (this._model.columnMap) : null; } + + /** + * Sets the default value for inserted rows. + * + * @param {String} column The destination column name + * @param {String} table The destination table name + * @param {Sql.Expr} expr The default value expression + */ + ,setDefault: function (column, table, expr) + { + this._defaults.push + ({ + column: column + ,table: table + ,expr: expr + }); + } + + /** + * Sets the default value for inserted rows. + * + * @param {String} column The destination column name + * @param {String} table The destination table name + * @param {*} value The default value + */ + ,setDefaultFromValue: function (column, table, value) + { + this._defaults.push + ({ + column: column + ,table: table + ,value: value + }); + } + + /** + * Sets the default value for inserted rows from another column in the + * model. + * + * @param {String} column The destination column name + * @param {String} table The destination table name + * @param {String} srcColumn The source column + */ + ,setDefaultFromColumn: function (column, table, srcColumn) + { + this._defaults.push + ({ + column: column + ,table: table + ,srcColumn: srcColumn + }); + } /** * Deletes a row from the model. @@ -719,6 +710,22 @@ Klass.implement this._sort (columnName, way); } + /** + * Searchs a value on the model and returns the row index of the first + * ocurrence. + * If an index have been built on that column, it will be used, for more + * information see the indexColumn() method. + * + * @param {String} columnIndex The column index + * @param {Object} value The value to search + * @return {Number} The column index + */ + ,searchByIndex: function (columnIndex, value) + { + var columnName = this.getColumnName (columnIndex); + return this.search (columnName, value); + } + /** * Performs all model changes on the database. */ @@ -926,51 +933,6 @@ Klass.implement this.emit ('operations-done'); } - /** - * Undoes all unsaved changes made to the model. - */ - ,reverseOperations: function () - { - for (var i = 0; i < this._operations.length; i++) - { - var op = this._operations[i]; - var row = op.row; - - if (op.type & Operation.DELETE - && !(op.type & Operation.INSERT)) - { - this._data.splice (row.index, 0, row); - this.emit ('row-inserted', row.index); - } - else if (op.type & Operation.UPDATE) - { - this.emit ('row-updated-before', row.index); - - var updatedCols = []; - var cols = this.columns; - - for (var i = 0; i < cols.length; i++) - if (op.oldValues[cols[i].name] !== undefined) - { - var columnName = cols[i].name; - row[columnName] = op.oldValues[columnName]; - updatedCols.push (columnName); - } - - this.emit ('row-updated', row.index, updatedCols); - } - } - - this._resetOperations (); - this._refreshRowIndexes (0); - } - - ,_resetOperations: function () - { - this._operations = []; - this._operationsMap = {}; - } - ,_createTarget: function (tableIndex) { var table = this.tables[tableIndex]; @@ -1033,6 +995,64 @@ Klass.implement return op; } + + /** + * Undoes all unsaved changes made to the model. + */ + ,reverseOperations: function () + { + for (var i = 0; i < this._operations.length; i++) + { + var op = this._operations[i]; + var row = op.row; + + if (op.type & Operation.DELETE + && !(op.type & Operation.INSERT)) + { + this._data.splice (row.index, 0, row); + this.emit ('row-inserted', row.index); + } + else if (op.type & Operation.UPDATE) + { + this.emit ('row-updated-before', row.index); + + var updatedCols = []; + var cols = this.columns; + + for (var i = 0; i < cols.length; i++) + if (op.oldValues[cols[i].name] !== undefined) + { + var columnName = cols[i].name; + row[columnName] = op.oldValues[columnName]; + updatedCols.push (columnName); + } + + this.emit ('row-updated', row.index, updatedCols); + } + } + + this._resetOperations (); + this._refreshRowIndexes (0); + } + + ,_resetOperations: function () + { + this._operations = []; + this._operationsMap = {}; + } + + ,_refreshRowIndexes: function (start) + { + this.parent (start); + + if (this._operationsMap) + { + this._operationsMap = {}; + + for (var i = 0; i < this._operations.length; i++) + this._operationsMap[i] = this._operations[i]; + } + } /** * Overrides information about a table and its columns. If a parameter is diff --git a/js/db/result-set.js b/js/db/result-set.js index ef045553..ecb48fce 100644 --- a/js/db/result-set.js +++ b/js/db/result-set.js @@ -43,7 +43,7 @@ module.exports = new Class /** * Fetchs the next result from the resultset. * - * @return {Db.Result} the result or %null if error or there are no more results + * @return {Db.Result} The result or %null if error or there are no more results */ ,fetchResult: function () { @@ -59,18 +59,23 @@ module.exports = new Class return null; } - + /** - * Fetchs the first row from the next resultset as an object. + * Fetchs the next result from the resultset. * - * @return {Object} the row if success, %null otherwise + * @return {Array} The result or %null if error or there are no more results */ - ,fetchObject: function () + ,fetchArray: function () { - var result = this.fetchResult (); - - if (result instanceof Result) - return result.fetchObject (); + var result = this.fetch (); + + if (result !== null) + { + if (result.data instanceof Array) + return result.data; + else + return true; + } return null; } @@ -82,14 +87,12 @@ module.exports = new Class */ ,fetchRow: function () { - var result = this.fetch (); + var result = this.fetchArray (); - if (result !== null - && result.data instanceof Array - && result.data.length > 0) - return result.data[0]; + if (result === null || result.length === 0) + return null; - return null; + return result[0]; } /** @@ -99,12 +102,13 @@ module.exports = new Class */ ,fetchValue: function () { - var row = this.fetchRow (); + var result = this.fetchResult (); - if (row instanceof Object && row.length > 0) - return row[0]; - - return null; + if (result === null + || result.data.length === 0 + || result.columns.length === 0) + return undefined; + + return result.data[0][result.columns[0].name]; } }); - diff --git a/js/db/result.js b/js/db/result.js index 0750384e..139ad096 100644 --- a/js/db/result.js +++ b/js/db/result.js @@ -10,31 +10,10 @@ module.exports = new Class { Object.assign (this, { data: result.data, - tables: result.tables, + result: result.tables, columns: result.columns, row: -1 }); - - if (this.columns) - { - this.columnMap = {}; - - for (var i = 0; i < this.columns.length; i++) - this.columnMap[this.columns[i].name] = i; - } - else - this.columnMap = null; - } - - /** - * Gets a value from de result. - * - * @param {String} columnName The column name - * @return {Object} The cell value - */ - ,get: function (columnName) - { - return this.data[this.row][columnName]; } /** @@ -42,7 +21,7 @@ module.exports = new Class * * @return {Object} The row or %null if there are no more rows */ - ,fetchObject: function () + ,fetchRow: function () { if (!this.next ()) return null; @@ -56,7 +35,7 @@ module.exports = new Class * @param {number} rowIndex The row index * @return {Object} The row or %null if there are no more rows */ - ,getObject: function (rowIndex) + ,getRow: function (rowIndex) { return this.data[rowIndex]; } diff --git a/js/hedera/app.js b/js/hedera/app.js index 78469ccb..b43b6d04 100644 --- a/js/hedera/app.js +++ b/js/hedera/app.js @@ -118,7 +118,7 @@ module.exports = new Class case 'OutdatedVersion': this._newVersion (); break; - case 'User': + case 'Vn.Lib.User': Htk.Toast.showError (error.message); break; default: diff --git a/js/hedera/gui.js b/js/hedera/gui.js index ee5f6a2f..4df02091 100644 --- a/js/hedera/gui.js +++ b/js/hedera/gui.js @@ -139,11 +139,11 @@ module.exports = new Class { // Retrieving configuration parameters - Object.assign (Vn.Config, resultSet.fetchObject ()); + Object.assign (Vn.Config, resultSet.fetchRow ()); // Retrieving configuration parameters - var row = resultSet.fetchObject (); + var row = resultSet.fetchRow (); if (row && row.test_domain) { @@ -181,56 +181,48 @@ module.exports = new Class { // Retrieving menu sections - var row; - var res = resultSet.fetchResult (); + var sections = resultSet.fetchArray (); var sectionMap = {}; - if (res) - for (var i = 0; row = res.fetchObject (); i++) - { - var parent = row.parent; - - if (!sectionMap[parent]) - sectionMap[parent] = []; + if (sections) + sections.forEach (function (section) { + var parent = section.parent; - sectionMap[parent].push (i); - } + if (!sectionMap[parent]) + sectionMap[parent] = []; + + sectionMap[parent].push (section); + }); Vn.Node.removeChilds (this.$.mainMenu); - this.createMenu (res, sectionMap, null, this.$.mainMenu); + this.createMenu (sectionMap, null, this.$.mainMenu); } //++++++++++++++++++++++++++++++++++++++++++++++++++++++ Menu - ,createMenu: function (res, sectionMap, parent, ul) + ,createMenu: function (sectionMap, parent, ul) { var sections = sectionMap[parent]; - for (var i = 0; i < sections.length; i++) - { - res.row = sections[i]; - var row = res.getObject (res.row); - + sections.forEach (function (section) { var li = this.createElement ('li'); ul.appendChild (li); - var text = this.createTextNode (_(row.description)); + var text = this.createTextNode (_(section.description)); var a = this.createElement ('a'); a.className = 'clickable'; - if (row.path) + if (section.path) { - a.href = this.hash.make ({'form': row.path}); - this._menuOptions[row.path] = a; + a.href = this.hash.make ({form: section.path}); + this._menuOptions[section.path] = a; } a.appendChild (text); li.appendChild (a); - - var formId = row.id; - - if (sectionMap[formId]) + + if (sectionMap[section.id]) { var submenu = this.createElement ('ul'); submenu.className = 'submenu'; @@ -241,9 +233,9 @@ module.exports = new Class li.addEventListener ('mouseout', this._onLiMouseOut.bind (this)); - this.createMenu (res, sectionMap, formId, submenu); + this.createMenu (sectionMap, section.id, submenu); } - } + }, this); } ,_onLiMouseHover: function (submenu, parent) diff --git a/js/hedera/social-bar.js b/js/hedera/social-bar.js index 844f126f..116ba66f 100644 --- a/js/hedera/social-bar.js +++ b/js/hedera/social-bar.js @@ -55,23 +55,21 @@ module.exports = new Class ,_onQueryDone: function (resultSet) { Vn.Node.removeChilds (this._node); - var res = resultSet.fetchResult (); - var row; + var socials = resultSet.fetchArray (); - while (row = res.fetchObject ()) - { + socials.forEach (function (social) { var a = this.createElement ('a'); - a.href = row.link; + a.href = social.link; a.target = '_blank'; a.className = 'clickable-img'; this._node.appendChild (a); var img = this.createElement ('img'); - img.src = 'image/social/'+ row.icon; - img.alt = row.title; - img.title = row.title; + img.src = 'image/social/'+ social.icon; + img.alt = social.title; + img.title = social.title; a.appendChild (img); - } + }, this); } }); diff --git a/js/hedera/tpv.js b/js/hedera/tpv.js index 07c64154..f757122d 100644 --- a/js/hedera/tpv.js +++ b/js/hedera/tpv.js @@ -89,7 +89,7 @@ module.exports = new Class ,_onRetryPayDone: function (resultSet) { - var row = resultSet.fetchObject (); + var row = resultSet.fetchRow (); if (row) this._realPpay (row.amount, row.company_id); diff --git a/js/htk/assistant.js b/js/htk/assistant.js index 08580912..40dec273 100644 --- a/js/htk/assistant.js +++ b/js/htk/assistant.js @@ -1,7 +1,9 @@ +var Step = require ('./step'); + module.exports = new Class ({ - Extends: Vn.Object + Extends: Vn.Component ,Tag: 'htk-assistant' ,Properties: { @@ -57,11 +59,30 @@ module.exports = new Class }, } + ,_steps: [] ,_stepNode: null ,_stepIndex: -1 + ,_stepName: null ,_stepCount: 0 ,_stepFunc: null + ,appendChild: function (step) + { + if (!(step instanceof Step)) + return; + + this._node.appendChild (step.node); + this._steps[step.name] = step; + + if (step.name === this._stepName) + this._showStepNode (); + + } + ,render: function () + { + var node = this.createRoot ('div'); + node.className = 'htk-assistant'; + } ,setStep: function (stepIndex) { if (!(stepIndex >= -1 && stepIndex < this.stepCount)) @@ -69,16 +90,15 @@ module.exports = new Class if (this._stepFunc && stepIndex != -1) { - var stepNode = this._stepFunc (stepIndex); + var stepName = this._stepFunc (stepIndex); - if (stepNode) + if (stepName) { - if (this._stepNode) - this._stepNode.style.display = 'none'; - - this._stepNode = stepNode; - stepNode.style.display = 'block'; + if (this._step) + this._step.node.style.display = 'none'; + this._stepName = stepName; + this._showStepNode () this._setStepIndex (stepIndex); } else if (this._stepIndex < stepIndex) @@ -87,9 +107,26 @@ module.exports = new Class this.setStep (stepIndex - 1); } else + { + if (this._step) + this._step.node.style.display = 'none'; + + this._stepName = null; this._setStepIndex (stepIndex); + } } + ,_showStepNode: function () + { + var step = this._steps[this._stepName]; + + if (step) + { + this._step = step; + step.node.style.display = 'block'; + } + } + ,_setStepIndex: function (stepIndex) { this._stepIndex = stepIndex; diff --git a/js/htk/field/combo.js b/js/htk/field/combo.js index 3a232a76..866a93c1 100644 --- a/js/htk/field/combo.js +++ b/js/htk/field/combo.js @@ -141,13 +141,15 @@ module.exports = new Class var button = this.createRoot ('button'); button.type = 'button'; button.className = 'htk-select input'; - button.addEventListener ('mousedown', this._onButtonMouseDown.bind (this)); + button.addEventListener ('mousedown', + this._onButtonMouseDown.bind (this)); } ,_setRow: function (row) { this._row = row; this._refreshShowText (); + this.rowChanged (); this.changed (); } @@ -168,7 +170,8 @@ module.exports = new Class menu.appendChild (grid.node); var gridNode = grid.node; - gridNode.addEventListener ('click', this._onGridClicked.bind (this, grid)); + gridNode.addEventListener ('click', + this._onGridClicked.bind (this, grid)); var column = new ColumnText ({columnIndex: this.showColumnIndex}); grid.appendColumn (column); diff --git a/js/htk/popup.js b/js/htk/popup.js index 62beb37e..45ea7db2 100644 --- a/js/htk/popup.js +++ b/js/htk/popup.js @@ -85,7 +85,7 @@ module.exports = new Class * Shows the popup relative to another element. * * @param {Node} parent The relative element - * @param {boolean} fitParent Wether to set the width same to the parent + * @param {Boolean} fitParent Wether to set the width same to the parent * @param {HTMLEvent} ignoreEvent An optional event object to ignore */ ,show: function (parent, fitParent, ignoreEvent) @@ -99,7 +99,7 @@ module.exports = new Class * Opens the popup. * * @param {Node} parent The relative element - * @param {boolean} fitParent Wether to set the width same to the parent + * @param {Boolean} fitParent Wether to set the width same to the parent */ ,open: function (ignoreEvent) { @@ -139,13 +139,14 @@ module.exports = new Class setTimeout (this._onOpacityTimeout.bind (this), 10); this._isOpen = true; + this.emit ('open'); } /** * Returns if the popup window shoud be modal based on the modal property * and if the device is mobile. * - * @return {boolean} %true if it's modal, %false otherwise + * @return {Boolean} %true if it's modal, %false otherwise */ ,isModal: function () { diff --git a/js/htk/step.js b/js/htk/step.js new file mode 100644 index 00000000..c9673318 --- /dev/null +++ b/js/htk/step.js @@ -0,0 +1,23 @@ + +module.exports = new Class +({ + Extends: Vn.Component + ,Tag: 'htk-step' + ,Properties: + { + name: { + type: String + ,value: null + } + } + + ,appendChild: function (child) + { + this._node.appendChild (child); + } + ,render: function () + { + var node = this.createRoot ('div'); + node.className = 'htk-step'; + } +}); \ No newline at end of file diff --git a/js/htk/style.css b/js/htk/style.css index 9cd8f30f..92dede95 100644 --- a/js/htk/style.css +++ b/js/htk/style.css @@ -524,6 +524,7 @@ td.cell-image .htk-image .htk-assistant > div { display: none; + color: #555; } .htk-assistant > div > h2 { @@ -535,10 +536,6 @@ td.cell-image .htk-image margin: 0; margin-bottom: 1em; } -.htk-assistant * -{ - color: #555; -} /* Assistant bar */ diff --git a/js/vn/iterator.js b/js/vn/iterator.js index d88e1bc6..d6b34b74 100644 --- a/js/vn/iterator.js +++ b/js/vn/iterator.js @@ -80,7 +80,11 @@ module.exports = new Class { this._rowLock = true; - var row = this._model.getObject (this._row); + var row; + + if (this._model) + row = this._model.getObject (this._row); + this.params = row != null ? row : {}; this._rowLock = false; diff --git a/js/vn/json-model.js b/js/vn/json-model.js deleted file mode 100644 index ec6ae32f..00000000 --- a/js/vn/json-model.js +++ /dev/null @@ -1,90 +0,0 @@ - -var VnObject = require ('./object'); -var ModelIface = require ('./model-iface'); -var ModelProxy = require ('./model-proxy'); - -var Mode = ModelProxy.Mode; - -/** - * Model that holds an array of Javascript objects with - * the same structure. - */ -module.exports = new Class -({ - Extends: VnObject - ,Implements: ModelIface - ,Tag: 'vn-json-model' - ,Properties: - { - numRows: - { - type: Number - }, - status: - { - type: Number - }, - mode: - { - enumType: Mode - ,value: Mode.ON_CHANGE - }, - data: - { - type: Array - ,set: function (x) - { - this.data = x; - } - ,get: function () - { - return this.data; - } - } - } - - ,checkColExists: function () {} - - ,checkRowExists: function () {} - - ,getColumnIndex: function () {} - - ,get: function (rowIndex, columnName) - { - return this.data[rowIndex][columnName]; - } - - ,getByIndex: function (rowIndex, column) - { - var columnName = this.columns[column]; - return this.data[rowIndex][columnName]; - } - - ,getObject: function (rowIndex) - { - return this.data[rowIndex]; - } - - ,sortByName: function () {} - - ,sort: function () {} - - ,search: function () {} - - ,searchByIndex: function () {} - - ,set: function () {} - - ,setByIndex: function () {} - - ,deleteRow: function () {} - - ,insertRow: function () {} - - ,clean: function () {} - - ,performOperations: function () {} - - ,indexColumn: function () {} -}); - diff --git a/js/vn/model.js b/js/vn/model.js index e226e631..2faa47b4 100644 --- a/js/vn/model.js +++ b/js/vn/model.js @@ -1,8 +1,6 @@ var VnObject = require ('./object'); - -// TODO: Remove this dependency -var Type = require ('db/connection').Type; +var simpleEquals = require ('./value').simpleEquals; var Klass = new Class (); module.exports = Klass; @@ -298,17 +296,12 @@ Klass.implement this._buildIndex (column); } - ,getHashFunc: function (type) + ,getHashValue: function (value) { - switch (type) - { - case Type.TIMESTAMP: - case Type.DATE_TIME: - case Type.DATE: - return function (value) { return value.toString (); }; - default: - return function (value) { return value; }; - } + if (value instanceof Date) + return value.getTime(); + else + return value; } ,_buildIndex: function (columnName) @@ -316,30 +309,27 @@ Klass.implement if (this.columnMap[columnName] === undefined) return; - var index = {}; var data = this._data; - var hashFunc = getHashFunc (this.columns[columnName].type); + var values = {}; + var nulls = []; for (var i = 0; i < data.length; i++) - index[hashFunc (data[i][columnName])] = i; + { + var value = data[i][columnName]; - this._indexes[columnName] = index; - } + if (value == null) + { + nulls.push (data[i]); + continue; + } - /** - * Searchs a value on the model and returns the row index of the first - * ocurrence. - * If an index have been built on that column, it will be used, for more - * information see the indexColumn() method. - * - * @param {String} columnIndex The column index - * @param {Object} value The value to search - * @return {Number} The column index - */ - ,searchByIndex: function (columnIndex, value) - { - var columnName = this.columns[columnIndex].name; - return this.search (columnName, value); + index[this.getHashValue (value)] = data[i]; + } + + this._indexes[columnName] = { + values: values, + index: index + }; } /** @@ -352,61 +342,39 @@ Klass.implement */ ,search: function (columnName, value) { - var columnIndex = this.columnMap[columnName]; - - if (columnIndex === undefined) + var data = this._data; + + if (data == null) return -1; - if (value) - switch (this.columns[columnIndex].type) - { - case Type.BOOLEAN: - value = !!value; - break; - case Type.INTEGER: - value = parseInt (value); - break; - case Type.DOUBLE: - value = parseFloat (value); - break; - default: - value = value.toString (); - } - // Searchs the value using an internal index. - + var index = this._indexes[columnName]; if (index) { - if (index[value] !== undefined) - return index[value]; - + if (value == null) + { + if (index.nulls[0] !== undefined) + return index.nulls[0].index; + } + else + { + var row = index.values[this.getHashValue (value)]; + + if (rowIndex !== undefined) + return row.index; + } + return -1; } - + // Searchs the value using a loop. - var data = this._data; - - switch (this.columns[columnIndex].type) - { - case Type.TIMESTAMP: - case Type.DATE_TIME: - case Type.DATE: - { - for (var i = 0; i < data.length; i++) - if (value === data[i][columnName].toString ()) - return i; + for (var i = 0; i < data.length; i++) + if (simpleEquals (data[i][columnName], value)) + return i; - break; - } - default: - for (var i = 0; i < data.length; i++) - if (value === data[i][columnName]) - return i; - } - return -1; } }); diff --git a/js/vn/scope.js b/js/vn/scope.js index f673a049..90628963 100644 --- a/js/vn/scope.js +++ b/js/vn/scope.js @@ -61,17 +61,15 @@ module.exports = new Class ,getMethod: function (value, binded) { if (this.thisArg) - { var method = this.thisArg[value]; - - if (method && binded) - method = method.bind (this.thisArg); - } else var method = window[value]; + + if (method && binded) + method = method.bind (this.thisArg); if (method === undefined) - this.builder._showError ('Function \'%s\' not found', value); + this.builder.showError ('Function \'%s\' not found', value); return method; } diff --git a/js/vn/vn.js b/js/vn/vn.js index e8c497c3..f1e00697 100644 --- a/js/vn/vn.js +++ b/js/vn/vn.js @@ -23,7 +23,6 @@ Vn = module.exports = { ,Spec : require ('./spec') ,ModelIface : require ('./model-iface') ,ModelProxy : require ('./model-proxy') - ,JsonModel : require ('./json-model') ,IteratorIface : require ('./iterator-iface') ,Iterator : require ('./iterator') ,Form : require ('./form') diff --git a/reports/shelves-report/shelves-report.js b/reports/shelves-report/shelves-report.js index 25f11ba9..f5b87698 100644 --- a/reports/shelves-report/shelves-report.js +++ b/reports/shelves-report/shelves-report.js @@ -31,7 +31,7 @@ Hedera.ShelvesReport = new Class { // Fetch query data - var row = resultSet.fetchObject (); + var row = resultSet.fetchRow (); // Calculates the scale @@ -61,9 +61,9 @@ Hedera.ShelvesReport = new Class var items = this.items = []; var remainings = this.remainings = []; - var res = resultSet.fetchResult (); + var res = resultSet.fetchArray (); - if (res.data.length == 0) + if (res.length == 0) { Htk.Toast.showError (_('No items found, check that all fields are correct')); return; @@ -71,28 +71,29 @@ Hedera.ShelvesReport = new Class var boxScale = scale * 10; - while (row = res.fetchObject ()) - if (!this.maxAmount || row.etiquetas <= this.maxAmount) - { - items.push ({ - id: row.Id_Article - ,name: row.Article - ,packing: row.packing - ,amount: row.etiquetas - ,boxHeight: row.z * boxScale - ,boxWidth: row.x * boxScale - ,boxDepth: row.y * boxScale - }); - } - else - { - remainings.push ({ - id: row.Id_Article - ,name: row.Article - ,packing: row.packing - ,amount: row.etiquetas - }); - } + res.forEach (function (row) { + if (!this.maxAmount || row.etiquetas <= this.maxAmount) + { + items.push ({ + id: row.Id_Article + ,name: row.Article + ,packing: row.packing + ,amount: row.etiquetas + ,boxHeight: row.z * boxScale + ,boxWidth: row.x * boxScale + ,boxDepth: row.y * boxScale + }); + } + else + { + remainings.push ({ + id: row.Id_Article + ,name: row.Article + ,packing: row.packing + ,amount: row.etiquetas + }); + } + }, this); // Intializes the allocator diff --git a/webpack.config.js b/webpack.config.js index 63525f35..e3a19003 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -30,6 +30,9 @@ var baseConfig = { '/usr/lib/node_modules' ] }, + node: { + __dirname: true + }, plugins: [ new webpack.DefinePlugin ({ _DEV_MODE: devMode,