From e460b4595f0abd952e1a17005279fcfdf1963bf1 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Wed, 15 Jul 2015 15:39:07 +0200 Subject: [PATCH] Version alpha3 del bionic --- .../forms/ecomerce/basket/basket.js | 23 +-- .../hedera-web/forms/ecomerce/catalog/ui.xml | 3 +- .../forms/ecomerce/checkout/checkout.js | 118 ++++++++------ .../forms/ecomerce/checkout/style.css | 1 - .../hedera-web/forms/ecomerce/checkout/ui.xml | 100 ++++++------ package/usr/share/hedera-web/global/style.css | 79 +++++++--- package/usr/share/hedera-web/js/db/form.js | 3 + .../usr/share/hedera-web/js/db/iterator.js | 1 - .../share/hedera-web/js/htk/field/calendar.js | 144 ++++++++++++------ package/usr/share/hedera-web/js/sql/value.js | 2 +- package/usr/share/hedera-web/js/vn/node.js | 24 +++ 11 files changed, 314 insertions(+), 184 deletions(-) diff --git a/package/usr/share/hedera-web/forms/ecomerce/basket/basket.js b/package/usr/share/hedera-web/forms/ecomerce/basket/basket.js index c5715677..5c976882 100755 --- a/package/usr/share/hedera-web/forms/ecomerce/basket/basket.js +++ b/package/usr/share/hedera-web/forms/ecomerce/basket/basket.js @@ -5,26 +5,31 @@ Vn.Basket = new Class ,activate: function () { - var query = 'CALL basket_check ()'; - this.conn.execQuery (query, this.onBasketCheck.bind (this)); + this.conn.execQuery ('CALL basket_check ()', + this.onBasketCheck.bind (this)); } ,onBasketCheck: function (resultSet) { var res = resultSet.fetchResult (); - if (!res.next()) + if (!res.next ()) return; - if (res.get ('order_id')) + switch (res.get ('stat')) { - if (res.get ('refresh') && res.get ('nrows') > 0) + case 'BAD_CONFIG': + case 'NOT_EXISTS': + this.onConfigureClick (); + break; + case 'UPDATED': (new Htk.Toast ()).showWarning (_('OrderItemsUpdated')); - - this.$('order').value = res.get ('order_id'); + this.$('order').value = res.get ('order_id'); + break; + case 'OK': + this.$('order').value = res.get ('order_id'); + break; } - else - this.hash.set ({'form': 'ecomerce/checkout'}); } ,onConfigureClick: function () diff --git a/package/usr/share/hedera-web/forms/ecomerce/catalog/ui.xml b/package/usr/share/hedera-web/forms/ecomerce/catalog/ui.xml index a9e29ba9..91d12cf8 100755 --- a/package/usr/share/hedera-web/forms/ecomerce/catalog/ui.xml +++ b/package/usr/share/hedera-web/forms/ecomerce/catalog/ui.xml @@ -20,12 +20,13 @@ CALL bionic_by_type (@calc, #type); - SELECT t.warehouse_id, t.item_id, t.available, t.price, + SELECT t.item_id, SUM(t.available) available, MIN(t.price) price, a.Foto, a.Article, a.Categoria, a.Medida, a.Tallos, a.Color, o.Abreviatura FROM cache.bionic t JOIN vn2008.Articles a ON a.Id_Article = t.item_id LEFT JOIN vn2008.Origen o ON a.id_origen = o.id WHERE t.calc_id = @calc AND t.available > 0 + GROUP BY item_id ORDER BY a.Article, a.Medida LIMIT 400; diff --git a/package/usr/share/hedera-web/forms/ecomerce/checkout/checkout.js b/package/usr/share/hedera-web/forms/ecomerce/checkout/checkout.js index 12206f08..94a3f4df 100755 --- a/package/usr/share/hedera-web/forms/ecomerce/checkout/checkout.js +++ b/package/usr/share/hedera-web/forms/ecomerce/checkout/checkout.js @@ -6,79 +6,88 @@ Vn.Checkout = new Class ,activate: function () { this.autoStepLocked = true; - - this.$('order-model').setDefault ('customer_id', 'o', - new Sql.Func ({schema: 'account', name: 'user_get_id'})); - - if (this.$('order').value == 0) - this.$('defaults').refresh (); - else - (new Htk.Toast ()).showWarning (_('RememberReconfiguringImpact')); } - - ,setDefaults: function () - { - var o = this.$('order-form'); - var d = this.$('defaults'); - if (this.$('order').value == 0 && d.ready && o.ready) + ,onValuesReady: function () + { + var orderForm = this.$('order-form'); + var defaultsForm = this.$('defaults'); + + if (!(orderForm.ready && defaultsForm.ready)) + return; + + if (orderForm.numRows > 0) { - o.insertRow (); -// o.set ('delivery_method_id', d.get ('delivery_method')); - o.set ('date_send', new Date ()); - o.set ('agency_id', d.get ('agency_id')); - o.set ('address_id', d.get ('address_id')); - this.autoStepLocked = false; + (new Htk.Toast ()).showWarning (_('RememberReconfiguringImpact')); + var i = orderForm; + var date = i.get ('date_send'); } - } - - ,onOrderReady: function () - { - if (this.$('order').value != 0) - this.autoStepLocked = false; + else + { + var i = defaultsForm; + var date = new Date (); + + if (i.get('delivery_method') != 'PICKUP') + date.setTime (date.getTime () + 86400000); + } + + this.$('delivery').value = date; + this.$('method').value = i.get ('delivery_method'); + this.$('agency').value = i.get ('agency_id'); + this.$('address').value = i.get ('address_id'); + + this.autoStepLocked = false; } - ,onOperationsDone: function () + ,onConfirmClick: function () { - if (this.$('order').value == 0) + var query = 'CALL basket_configure (#delivery, #method, #agency, #address)'; + + var batch = new Sql.Batch (); + batch.addParam ('method', this.$('method')); + batch.addParam ('delivery', this.$('delivery')); + batch.addParam ('agency', this.$('agency')); + batch.addParam ('address', this.$('address')); + + this.conn.execQuery (query, + this.onBasketConfigured.bind (this), batch); + } + + ,onBasketConfigured: function (resultSet) + { + if (!resultSet.fetchResult ()) + return; + + if (this.$('order-form').numRows > 0) + { + (new Htk.Toast ()).showMessage (_('OrderUpdated')); + window.history.back(); + } + else { (new Htk.Toast ()).showMessage (_('OrderStarted')); this.hash.set ({'form': 'ecomerce/catalog'}); } - else - this.conn.execQuery ('CALL basket_update ()', - this.onBasketUpdated.bind (this)); - } - - ,onBasketUpdated: function () - { - (new Htk.Toast ()).showMessage (_('OrderUpdated')); - window.history.back(); - } - - ,onConfirmClick: function () - { - this.$('order-form').performOperations (); } ,onCancelClick: function () { - if (this.$('order').value == 0) - this.hash.set ({'form': 'ecomerce/orders'}); - else + if (this.$('order-form').numRows > 0) this.hash.set ({'form': 'ecomerce/basket'}); + else + this.hash.set ({'form': 'ecomerce/orders'}); } - ,agencySteps: ['delivery', 'date', 'address', 'agency', 'confirm-agency'] - ,deliverySteps: ['delivery', 'date', 'address', null, 'confirm-delivery'] - ,pickupSteps: ['delivery', 'date', 'pickup', null, 'confirm-pickup'] + ,agencySteps: ['method', 'date', 'address', 'agency', 'confirm-agency'] + ,deliverySteps: ['method', 'date', 'address', null, 'confirm-delivery'] + ,pickupSteps: ['method', 'date', 'pickup', null, 'confirm-pickup'] ,stepFunc: function (stepIndex) { var steps; var isDelivery; - switch (this.$('rg-delivery').value) + switch (this.$('rg-method').value) { case 'AGENCY': steps = this.agencySteps; @@ -115,7 +124,7 @@ Vn.Checkout = new Class this.$('agencies').refresh (); break; case 'pickup': - this.$('warehouses').refresh (); + this.$('agencies').refresh (); break; } @@ -145,5 +154,14 @@ Vn.Checkout = new Class { this.$('assistant').moveNext (); } + + ,calendarRestrict: function (date) + { + var now = new Date (); + now.setHours (0,0,0,0); + + return date.getTime () >= now.getTime () + && date.getDay () != 0; + } }); diff --git a/package/usr/share/hedera-web/forms/ecomerce/checkout/style.css b/package/usr/share/hedera-web/forms/ecomerce/checkout/style.css index f9399233..fc58bc4a 100755 --- a/package/usr/share/hedera-web/forms/ecomerce/checkout/style.css +++ b/package/usr/share/hedera-web/forms/ecomerce/checkout/style.css @@ -13,7 +13,6 @@ /* Step */ .answers button, -.answers span, .answers p, .radio > div { diff --git a/package/usr/share/hedera-web/forms/ecomerce/checkout/ui.xml b/package/usr/share/hedera-web/forms/ecomerce/checkout/ui.xml index b49ae3bf..75cddd23 100755 --- a/package/usr/share/hedera-web/forms/ecomerce/checkout/ui.xml +++ b/package/usr/share/hedera-web/forms/ecomerce/checkout/ui.xml @@ -3,25 +3,40 @@ - - - SELECT delivery_method, address_id, agency_id + + + + + + + SELECT delivery_method, agency_id, address_id FROM order_defaults_view - - - SELECT id, delivery_method_id, date_send, agency_id, address_id, customer_id - FROM order_view o WHERE id = #id - - - + + + SELECT v.code delivery_method, o.date_send, o.agency_id, o.address_id + FROM order_view o + JOIN vn2008.Vistas v ON o.delivery_method_id = v.vista_id + LIMIT 1 - - - - + + CALL agency_list_by_date (#delivery, #address); + SELECT a.Id_Agencia, a.description + FROM t_agency t + JOIN vn2008.Agencias a ON a.Id_Agencia = t.agency_id + JOIN vn2008.Vistas v ON a.Vista = v.vista_id + WHERE a.web != FALSE + AND v.code = #method + ORDER BY a.description; + DROP TEMPORARY TABLE t_agency; + + + + + +
@@ -42,22 +57,23 @@ step-func="stepFunc" node="assistant-node"/>
-
+

DeliveryOrPickupQuestion

- +
- +
- +
@@ -68,7 +84,8 @@
@@ -97,38 +114,21 @@

AgencyQuestion

- - - CALL agency_list_by_date (#date, #address); - SELECT a.Id_Agencia, a.description - FROM t_agency t - JOIN vn2008.Agencias a ON a.Id_Agencia = t.agency_id - JOIN vn2008.Vistas v ON a.Vista = v.vista_id - WHERE a.web != FALSE - AND v.code = 'AGENCY' - ORDER BY a.description; - DROP TEMPORARY TABLE t_agency; - - - - - - +

PickupWarehouseQuestion

- - - SELECT a.Id_Agencia, SUBSTR(a.description, 5) description - FROM vn2008.Agencias a - JOIN vn2008.Vistas v ON a.Vista = v.vista_id - WHERE a.web != FALSE - AND v.code = 'PICKUP' - ORDER BY a.description - - +
@@ -136,7 +136,7 @@

Arrival - +

@@ -156,7 +156,7 @@

Arrival - +

@@ -175,7 +175,7 @@

Pickup - +

Warehouse diff --git a/package/usr/share/hedera-web/global/style.css b/package/usr/share/hedera-web/global/style.css index ae6ce851..b11e6a0d 100755 --- a/package/usr/share/hedera-web/global/style.css +++ b/package/usr/share/hedera-web/global/style.css @@ -225,22 +225,6 @@ img.editable height: 1.5em; } -/* Date chooser */ - -.htk-date-chooser button -{ - border: 1px solid #CCD; - margin: 0.2em; - padding: 0.3em; - border-radius: 0.1em; - box-shadow: 0 0.1em 0.1em #CCC; - background-color: white; - color: black; - text-align: left; - min-width: 9em; - min-height: 2.3em; -} - /* Float */ .clear @@ -496,6 +480,10 @@ img.icon text-align: center; height: 3em; } +.htk-calendar thead span +{ + color: white; +} .htk-calendar thead tr { border-bottom: none; @@ -507,7 +495,7 @@ img.icon .htk-calendar th.button:hover { cursor: pointer; - background-color: #076; + background-color: rgba(1, 1, 1, 0.2); } .htk-calendar col { @@ -520,13 +508,58 @@ img.icon .htk-calendar tbody td { text-align: right; - padding-right: 0.5em; } -.htk-calendar td.highlight, -.htk-calendar td:hover +.htk-calendar tbody td > div +{ + height: 2em; + width: 2em; + line-height: 2em; + text-align: center; + border-radius: 2em; + padding: 0.3em; + margin: 0 auto; + color: #555; +} +.htk-calendar div.disabled +{ + color: #999; +} +.htk-calendar div.today +{ + font-weight: bold; + color: black; +} +.htk-calendar div.selected +{ + color: white; + background-color: #009688; +} +.htk-calendar div.enabled:hover { cursor: pointer; - background-color: #DDE; + background-color: #DDD; + color: #555; +} + +/* Date chooser */ + +.htk-date-chooser > button +{ + margin: 0.2em; + padding: 0.3em; + background-color: white; + color: black; + text-align: left; + min-width: 9em; + min-height: 2.3em; + border: 1px solid #CCD; + border-radius: 0.1em; + box-shadow: 0 0.1em 0.1em #CCC; +} + +.htk-date-chooser > button:hover +{ + background-color: #EEE; } /* Full image */ @@ -728,4 +761,8 @@ img.icon padding: 0.3em 0.2em; width: 1.3em; } +.htk-assistant-bar > div > img:hover +{ + opacity: .7; +} diff --git a/package/usr/share/hedera-web/js/db/form.js b/package/usr/share/hedera-web/js/db/form.js index a8d9c008..9f2b5893 100755 --- a/package/usr/share/hedera-web/js/db/form.js +++ b/package/usr/share/hedera-web/js/db/form.js @@ -93,6 +93,9 @@ Db.Form = new Class if (this._row == -1) this.row = this.lastRow; + + if (ready) + this.signalEmit ('ready'); } } diff --git a/package/usr/share/hedera-web/js/db/iterator.js b/package/usr/share/hedera-web/js/db/iterator.js index 4edf1e4d..b0f66a83 100755 --- a/package/usr/share/hedera-web/js/db/iterator.js +++ b/package/usr/share/hedera-web/js/db/iterator.js @@ -48,7 +48,6 @@ Db.Iterator = new Class ,iterChanged: function () { this.signalEmit ('iter-changed'); - this.signalEmit ('iter-changed-after'); } /** diff --git a/package/usr/share/hedera-web/js/htk/field/calendar.js b/package/usr/share/hedera-web/js/htk/field/calendar.js index d8b59d5f..67d498ef 100755 --- a/package/usr/share/hedera-web/js/htk/field/calendar.js +++ b/package/usr/share/hedera-web/js/htk/field/calendar.js @@ -2,10 +2,24 @@ Htk.Calendar = new Class ({ Extends: Htk.Field ,Tag: 'htk-calendar' + ,Properties: + { + restrictFunc: + { + type: Function + ,set: function (x) + { + this._restrictFunc = x; + } + ,get: function (x) + { + return this._restrictFunc; + } + } + } - ,tds: [] - ,selectedTd: null - ,todayTd: null + ,cells: [] + ,selectedCell: -1 ,year: null ,month: null @@ -38,9 +52,18 @@ Htk.Calendar = new Class th.addEventListener ('click', this.prevMonthClicked.bind (this)); tr.appendChild (th); - var monthNode = document.createElement ('th'); - monthNode.colSpan = 5; - tr.appendChild (monthNode); + var th = document.createElement ('th'); + th.colSpan = 5; + tr.appendChild (th); + + var monthNode = document.createElement ('span'); + th.appendChild (monthNode); + + var space = document.createTextNode (' '); + th.appendChild (space); + + var yearNode = document.createElement ('span'); + th.appendChild (yearNode); var th = document.createElement ('th'); th.appendChild (document.createTextNode ('>')); @@ -59,7 +82,7 @@ Htk.Calendar = new Class var weekday = Vn.Date.AbrWDays [i%len]; th.appendChild (document.createTextNode (weekday)); } - +/* var tfoot = document.createElement ('tfoot'); table.appendChild (tfoot); @@ -81,7 +104,9 @@ Htk.Calendar = new Class th.className = 'button'; th.addEventListener ('click', this.nextYearClicked.bind (this)); tr.appendChild (th); - +*/ + var td, div; + var tbody = document.createElement ('tbody'); table.appendChild (tbody); @@ -95,7 +120,15 @@ Htk.Calendar = new Class td = document.createElement ('td'); td.addEventListener ('click', this.dayClicked.bind (this, td, i*len+j)); tr.appendChild (td); - this.tds.push (td); + + div = document.createElement ('div'); + td.appendChild (div); + + this.cells.push ({ + node: div, + enabled: false, + day: -1 + }); } } @@ -104,12 +137,6 @@ Htk.Calendar = new Class this.goToCurrentMonth (); } - ,getFirstWeekDay: function () - { - var weekDay = new Date (this.year, this.month, 1).getDay (); - return (weekDay != 0) ? weekDay - 1 : 6; - } - ,getMonthDays: function () { if (this.month > 6) @@ -151,34 +178,48 @@ Htk.Calendar = new Class Vn.Node.setText (this.yearNode, this.year); Vn.Node.setText (this.monthNode, Vn.Date.Months[this.month]); - var firstWeekDay = this.getFirstWeekDay (); + var day = 1; + var cellDate = new Date (this.year, this.month, 1); + + var weekDay = cellDate.getDay (); + var firstWeekDay = (weekDay != 0) ? weekDay - 1 : 6; var monthDays = this.getMonthDays (); - var day = 1; - - for (i = 0; i < this.tds.length; i++) + for (i = 0; i < this.cells.length; i++) { + var cell = this.cells[i]; + if (firstWeekDay <= i && day <= monthDays) - Vn.Node.setText (this.tds[i], day++); + { + Vn.Node.setText (cell.node, day); + cell.enabled = true; + cell.day = day++; + + if (this._restrictFunc) + { + cell.enabled = this._restrictFunc (cellDate); + cellDate.setTime (cellDate.getTime () + 86400000); + } + } else - Vn.Node.removeChilds (this.tds[i]); + { + Vn.Node.removeChilds (cell.node); + cell.enabled = false; + cell.day = -1; + } + + cell.node.className = cell.enabled ? 'enabled' : 'disabled'; } - + // Marks the current day - + var today = new Date (); if (this.year == today.getFullYear () && this.month == today.getMonth ()) { - var tdIndex = (firstWeekDay + today.getDate ()) - 1; - this.tds[tdIndex].style.fontWeight = 'bold'; - this.todayTd = this.tds[tdIndex]; - } - else if (this.todayTd) - { - this.todayTd.style.fontWeight = ''; - this.todayTd = null; + var cellIndex = (firstWeekDay + today.getDate ()) - 1; + Vn.Node.addClass (this.cells[cellIndex].node, 'today'); } // Marks the selected day @@ -188,22 +229,25 @@ Htk.Calendar = new Class if (date instanceof Date && this.year == date.getFullYear () && this.month == date.getMonth ()) - { - var tdIndex = (firstWeekDay + date.getDate ()) - 1; - this.selectTd (this.tds[tdIndex]); - } + this.selectCell ((firstWeekDay + date.getDate ()) - 1); else - this.selectTd (null); + this.selectCell (-1); } - ,selectTd: function (td) + ,selectCell: function (cellIndex) { - if (this.selectedTd) - this.selectedTd.className = ''; - if (td) - td.className = 'highlight'; + if (this.selectedCell != -1) + { + var node = this.cells[this.selectedCell].node; + Vn.Node.removeClass (node, 'selected'); + } + if (cellIndex != -1) + { + var node = this.cells[cellIndex].node; + Vn.Node.addClass (node, 'selected'); + } - this.selectedTd = td; + this.selectedCell = cellIndex; } ,putValue: function (value) @@ -211,15 +255,15 @@ Htk.Calendar = new Class this.goToSelectedMonth (); } - ,dayClicked: function (td, tdIndex) + ,dayClicked: function (td, cellIndex) { - var monthDay = (tdIndex - this.getFirstWeekDay ()) + 1; - - if (monthDay >= 1 && monthDay <= this.getMonthDays ()) + var cell = this.cells[cellIndex]; + + if (cell.enabled) { - this.selectTd (td); + this.selectCell (cellIndex); - var newDate = new Date (this.year, this.month, monthDay); + var newDate = new Date (this.year, this.month, cell.day); this.valueChanged (newDate); } } @@ -249,7 +293,7 @@ Htk.Calendar = new Class this.refresh (); } - +/* ,prevYearClicked: function () { this.year--; @@ -260,5 +304,5 @@ Htk.Calendar = new Class { this.year++; this.refresh (); - } + }*/ }); diff --git a/package/usr/share/hedera-web/js/sql/value.js b/package/usr/share/hedera-web/js/sql/value.js index b90a55b3..0e2ce97e 100755 --- a/package/usr/share/hedera-web/js/sql/value.js +++ b/package/usr/share/hedera-web/js/sql/value.js @@ -63,7 +63,7 @@ Sql.Value = new Class ,onParamChange: function () { - if (this.paramLock) + if (this.paramLock || !this._param) return; this.paramLock = true; diff --git a/package/usr/share/hedera-web/js/vn/node.js b/package/usr/share/hedera-web/js/vn/node.js index 75802a3a..d5661c88 100755 --- a/package/usr/share/hedera-web/js/vn/node.js +++ b/package/usr/share/hedera-web/js/vn/node.js @@ -23,6 +23,30 @@ Vn.Node = if (text) node.appendChild (document.createTextNode (text)); } + + ,addClass: function (node, className) + { +/* var classes = node.className.split (' '); + + if (classes.split (' ').indexOf (className) == -1) +*/ node.className = className +' '+ node.className; + } + + ,removeClass: function (node, className) + { + var index = 0; + var found = false; + var classes = node.className.split (' '); + + while ((index = classes.indexOf (className, index)) != -1) + { + classes.splice (index, 1); + found = true; + } + + if (found) + node.className = classes.join (' '); + } }; function $ (id)