0
1
Fork 0

Memory leaks solucionados, beta 3 del bionic

This commit is contained in:
Juan Ferrer Toribio 2015-07-28 21:14:26 +02:00
parent e78a3fdd45
commit e8398ab5c4
39 changed files with 432 additions and 353 deletions

View File

@ -1,7 +1,7 @@
<vn> <vn>
<vn-group> <vn-group>
<vn-param id="address"> <vn-param id="address">
<vn-hash-link key="address"/> <vn-hash-param key="address"/>
</vn-param> </vn-param>
<db-form id="iter" on-status-changed="onStatusChange"> <db-form id="iter" on-status-changed="onStatusChange">
<db-param id="country" one-way="true" column="country_id"/> <db-param id="country" one-way="true" column="country_id"/>

View File

@ -1,7 +1,7 @@
<vn> <vn>
<vn-group> <vn-group>
<vn-param id="user"> <vn-param id="user">
<vn-hash-link key="user"/> <vn-hash-param key="user"/>
</vn-param> </vn-param>
<db-form id="user-form"> <db-form id="user-form">
<db-model> <db-model>

View File

@ -2,5 +2,10 @@
Vn.Provinces = new Class Vn.Provinces = new Class
({ ({
Extends: Vn.Module Extends: Vn.Module
,onReturnClick: function ()
{
window.history.back();
}
}); });

View File

@ -1,15 +1,22 @@
<vn> <vn>
<vn-group> <vn-group>
<vn-param id="agency"> <vn-param id="agency">
<vn-hash-link key="agency"/> <vn-hash-param key="agency"/>
</vn-param> </vn-param>
</vn-group> </vn-group>
<div id="form" class="provinces"> <div id="form" class="provinces">
<div class="box"> <div class="box">
<div class="header"> <div class="header">
<h1><t>ByProvince</t></h1> <h1><t>ByProvince</t></h1>
<div class="action-bar">
<button on-click="onReturnClick">
<img src="image/dark/go-previous.svg" alt=""/>
<t>Return</t>
</button>
</div>
<div class="clear"/>
</div> </div>
<htk-grid empty-message="SelectAgency"> <htk-grid>
<db-model> <db-model>
CALL vn2008.desglose_volume (#agency) CALL vn2008.desglose_volume (#agency)
<sql-batch property="batch"> <sql-batch property="batch">

View File

@ -3,44 +3,36 @@ Vn.Basket = new Class
({ ({
Extends: Vn.Module Extends: Vn.Module
,open: function ()
{
if (this.basketChecked)
this.parent ();
}
,activate: function () ,activate: function ()
{ {
this.conn.execQuery ('CALL basket_check ()', Vn.BasketChecker.check (this.conn,
this.onBasketCheck.bind (this)); this.onBasketCheck.bind (this));
} }
,onBasketCheck: function (resultSet) ,onBasketCheck: function (isOk)
{ {
var res = resultSet.fetchResult (); if (!isOk)
return;
if (res.next ()) this.basketChecked = true;
switch (res.get ('stat')) this.open ();
{
case 'BAD_CONFIG':
case 'NOT_EXISTS':
this.hash.set ({'form': 'ecomerce/checkout'});
break;
case 'UPDATED':
(new Htk.Toast ()).showWarning (_('OrderItemsUpdated'));
this.$('order').value = res.get ('order_id');
break;
case 'OK':
this.$('order').value = res.get ('order_id');
break;
}
} }
,onConfigureClick: function () ,onConfigureClick: function ()
{ {
(new Htk.Toast ()).showWarning (_('RememberReconfiguringImpact'));
this.hash.set ({'form': 'ecomerce/checkout'}); this.hash.set ({'form': 'ecomerce/checkout'});
} }
,onCheckoutClick: function () ,onCheckoutClick: function ()
{ {
this.hash.set ({ this.hash.set ({'form': 'ecomerce/confirm'});
'form': 'ecomerce/confirm',
'order': this.$('order').value
});
} }
,amountRender: function (renderer, form) ,amountRender: function (renderer, form)
@ -56,7 +48,7 @@ Vn.Basket = new Class
,onAmountChange: function (renderer, row, newValue) ,onAmountChange: function (renderer, row, newValue)
{ {
var model = this.$('order-rows'); var model = this.$('items');
model.set (row, 'amount', newValue * model.get (row, 'grouping')); model.set (row, 'amount', newValue * model.get (row, 'grouping'));
} }

View File

@ -1,18 +1,4 @@
<vn> <vn>
<vn-group>
<vn-param id="order"/>
<db-form id="order-form">
<db-model updatable="true">
SELECT id, date_send, agency_id
FROM basket
<sql-batch property="batch">
<item name="id" param="order"/>
</sql-batch>
</db-model>
<db-param column="date_send" id="date"/>
<db-param column="address_id" id="address"/>
</db-form>
</vn-group>
<div id="form" class="basket"> <div id="form" class="basket">
<div class="box"> <div class="box">
<div class="header"> <div class="header">
@ -31,7 +17,7 @@
</div> </div>
<div> <div>
<htk-grid show-header="false"> <htk-grid show-header="false">
<db-model result-index="1" id="order-rows" updatable="true"> <db-model result-index="1" id="items" updatable="true">
CALL bionic_from_basket (@calc); CALL bionic_from_basket (@calc);
SELECT m.id, m.amount, t.available, a.Article, a.Categoria, SELECT m.id, m.amount, t.available, a.Article, a.Categoria,
a.Medida, a.Tallos, a.Color, o.Abreviatura, m.price price, a.Foto a.Medida, a.Tallos, a.Color, o.Abreviatura, m.price price, a.Foto
@ -39,9 +25,6 @@
INNER JOIN vn2008.Articles a ON a.Id_Article = m.item_id INNER JOIN vn2008.Articles a ON a.Id_Article = m.item_id
LEFT JOIN vn2008.Origen o ON a.id_origen = o.id LEFT JOIN vn2008.Origen o ON a.id_origen = o.id
LEFT JOIN cache.bionic t ON m.warehouse_id = t.warehouse_id AND m.item_id = t.item_id AND t.calc_id = @calc; LEFT JOIN cache.bionic t ON m.warehouse_id = t.warehouse_id AND m.item_id = t.item_id AND t.calc_id = @calc;
<sql-batch property="batch">
<item name="order" param="order"/>
</sql-batch>
</db-model> </db-model>
<htk-column-image column="Foto" directory="catalog" subdir="50x50" show-full="true"/> <htk-column-image column="Foto" directory="catalog" subdir="50x50" show-full="true"/>
<htk-column-text title="_Item" column="Article"/> <htk-column-text title="_Item" column="Article"/>
@ -53,7 +36,7 @@
<p> <p>
<t>OrderTotal</t> <t>OrderTotal</t>
<htk-text format="%.2d€"> <htk-text format="%.2d€">
<db-calc-sum func="subtotal" model="order-rows"/> <db-calc-sum func="subtotal" model="items"/>
</htk-text> </htk-text>
</p> </p>
</div> </div>

View File

@ -3,10 +3,26 @@ Vn.Catalog = new Class
({ ({
Extends: Vn.Module Extends: Vn.Module
,realmColor: null ,open: function ()
{
if (this.basketChecked)
this.parent ();
}
,activate: function () ,activate: function ()
{ {
Vn.BasketChecker.check (this.conn,
this.onBasketCheck.bind (this));
}
,onBasketCheck: function (isOk)
{
if (!isOk)
return;
this.basketChecked = true;
this.open ();
this.popup = new Htk.Popup (); this.popup = new Htk.Popup ();
this.popup.setChildNode (this.$('lots-popup')); this.popup.setChildNode (this.$('lots-popup'));
} }
@ -33,7 +49,7 @@ Vn.Catalog = new Class
,onTypeChange: function () ,onTypeChange: function ()
{ {
if (Vn.isMobile ()) if (Vn.isMobile () && this.$('type').value)
this.hideMenu (); this.hideMenu ();
var realms = this.$('realms-model'); var realms = this.$('realms-model');

View File

@ -1,10 +1,10 @@
<vn> <vn>
<vn-group> <vn-group>
<vn-param id="realm" on-changed="onTypeChange"> <vn-param id="realm" on-changed="onTypeChange">
<vn-hash-link key="realm"/> <vn-hash-param key="realm"/>
</vn-param> </vn-param>
<vn-param id="type" on-changed="onTypeChange"> <vn-param id="type" on-changed="onTypeChange">
<vn-hash-link key="type"/> <vn-hash-param key="type"/>
</vn-param> </vn-param>
<vn-param id="search"/> <vn-param id="search"/>
<sql-filter type="AND" id="filter"> <sql-filter type="AND" id="filter">

View File

@ -21,7 +21,6 @@ Vn.Checkout = new Class
if (orderForm.numRows > 0) if (orderForm.numRows > 0)
{ {
(new Htk.Toast ()).showWarning (_('RememberReconfiguringImpact'));
var i = orderForm; var i = orderForm;
var date = i.get ('date_send'); var date = i.get ('date_send');
} }

View File

@ -42,12 +42,12 @@
} }
.address.selected .address.selected
{ {
background-color: rgba(1, 1, 1, .05); background-color: rgba(1, 1, 1, .1);
} }
.address:hover .address:hover
{ {
cursor: pointer; cursor: pointer;
background-color: rgba(1, 1, 1, .1); background-color: rgba(1, 1, 1, .05);
} }
.address p.consignee .address p.consignee
{ {

View File

@ -1,8 +1,5 @@
<vn> <vn>
<vn-group> <vn-group>
<vn-param id="order">
<vn-hash-link key="order"/>
</vn-param>
<vn-param id="method"/> <vn-param id="method"/>
<vn-param id="date"/> <vn-param id="date"/>
<vn-param id="agency"/> <vn-param id="agency"/>

View File

@ -3,11 +3,6 @@ Vn.Confirm = new Class
({ ({
Extends: Vn.Module Extends: Vn.Module
,activate: function ()
{
this.tpv = new Vn.Tpv (this.conn, this.hash);
}
,onOrderReady: function (form) ,onOrderReady: function (form)
{ {
if (form.row < 0) if (form.row < 0)
@ -15,12 +10,12 @@ Vn.Confirm = new Class
if (form.get ('method') != 'PICKUP') if (form.get ('method') != 'PICKUP')
{ {
this.$('address').style.display = 'block'; Vn.Node.show (this.$('address'));
Vn.Node.setText (this.$('method'), _('Agency')); Vn.Node.setText (this.$('method'), _('Agency'));
} }
else else
{ {
this.$('address').style.display = 'none'; Vn.Node.hide (this.$('address'));
Vn.Node.setText (this.$('method'), _('Warehouse')); Vn.Node.setText (this.$('method'), _('Warehouse'));
} }
} }
@ -72,7 +67,7 @@ Vn.Confirm = new Class
this.popup.hide (); this.popup.hide ();
if (this.pay) if (this.pay)
this.tpv.pay (this.$('total').value, Vn.Tpv.pay (this.conn, this.$('total').value,
this.$('order-form').get ('company_id')); this.$('order-form').get ('company_id'));
else else
this.hash.set ({'form': 'ecomerce/orders'}); this.hash.set ({'form': 'ecomerce/orders'});

View File

@ -1,11 +1,8 @@
<vn> <vn>
<vn-group> <vn-group>
<vn-param id="order-id">
<vn-hash-link key="order"/>
</vn-param>
<db-form id="order-form" on-ready="onOrderReady"> <db-form id="order-form" on-ready="onOrderReady">
<db-model> <db-model>
SELECT o.id, o.date_send, o.note, SELECT o.id, o.date_send, o.note, o.company_id,
ag.description agency, v.code method, c.credit, ag.description agency, v.code method, c.credit,
ad.consignee, ad.zip_code, ad.city, ad.name address ad.consignee, ad.zip_code, ad.city, ad.name address
FROM basket o FROM basket o
@ -13,9 +10,6 @@
LEFT JOIN address_view ad ON ad.id = o.address_id LEFT JOIN address_view ad ON ad.id = o.address_id
JOIN vn2008.Vistas v ON v.vista_id = o.delivery_method_id JOIN vn2008.Vistas v ON v.vista_id = o.delivery_method_id
JOIN customer_view c JOIN customer_view c
<sql-batch property="batch">
<item name="order" param="order-id"/>
</sql-batch>
</db-model> </db-model>
</db-form> </db-form>
<db-form id="total-form" on-ready="onImportReady"> <db-form id="total-form" on-ready="onImportReady">
@ -26,17 +20,11 @@
IFNULL(SUM(vat + surcharge), 0) vat IFNULL(SUM(vat + surcharge), 0) vat
FROM t_order_vat; FROM t_order_vat;
DROP TEMPORARY TABLE t_order_vat; DROP TEMPORARY TABLE t_order_vat;
<sql-batch property="batch">
<item name="order" param="order-id"/>
</sql-batch>
</db-model> </db-model>
</db-form> </db-form>
<db-query id="confirm-query" on-ready="onConfirm"> <db-query id="confirm-query" on-ready="onConfirm">
CALL basket_confirm (); CALL basket_confirm ();
SELECT customer_get_debt(); SELECT customer_get_debt();
<sql-batch property="batch">
<item name="order" param="order-id"/>
</sql-batch>
</db-query> </db-query>
</vn-group> </vn-group>
<div id="form" class="confirm"> <div id="form" class="confirm">

View File

@ -8,7 +8,7 @@ Vn.Orders = new Class
this.payPopup = new Htk.Popup (); this.payPopup = new Htk.Popup ();
this.payPopup.setChildNode (this.$('balance-popup')); this.payPopup.setChildNode (this.$('balance-popup'));
this.tpv = new Vn.Tpv (this.conn, this.hash); Vn.Tpv.check (this.conn);
} }
,onBasketClick: function () ,onBasketClick: function ()
@ -24,14 +24,6 @@ Vn.Orders = new Class
}); });
} }
,payRenderer: function (column, form)
{
if (form.get ('company_id') && form.get('total'))
column.td.className = '';
else
column.td.className = 'hide';
}
// TPV // TPV
,balanceConditionalFunc: function (field, value) ,balanceConditionalFunc: function (field, value)
@ -66,7 +58,7 @@ Vn.Orders = new Class
var amount = parseFloat (prompt (_('AmountToPay:'), defaultAmountStr)); var amount = parseFloat (prompt (_('AmountToPay:'), defaultAmountStr));
this.tpv.pay (amount, company); Vn.Tpv.pay (this.conn, amount, company);
} }
}); });

View File

@ -1,7 +1,7 @@
<vn> <vn>
<vn-group> <vn-group>
<vn-param id="ticket-id"> <vn-param id="ticket-id">
<vn-hash-link key="ticket"/> <vn-hash-param key="ticket"/>
</vn-param> </vn-param>
<db-form id="ticket"> <db-form id="ticket">
<db-model id="ticket-data"> <db-model id="ticket-data">

View File

@ -1,7 +1,7 @@
<vn> <vn>
<vn-group> <vn-group>
<vn-param id="new-id"> <vn-param id="new-id">
<vn-hash-link key="new"/> <vn-hash-param key="new"/>
</vn-param> </vn-param>
<db-form id="iter" on-status-changed="onStatusChange"> <db-form id="iter" on-status-changed="onStatusChange">
<db-param column="text" on-changed="onBodyChange"/> <db-param column="text" on-changed="onBodyChange"/>
@ -28,6 +28,7 @@
<t>Accept</t> <t>Accept</t>
</button> </button>
</div> </div>
<div class="clear"/>
</div> </div>
<div class="form"> <div class="form">
<div class="form-group"> <div class="form-group">

View File

@ -21,7 +21,8 @@ Db.Calc = new Class
,'row-inserted': this.onRowInsert ,'row-inserted': this.onRowInsert
}); });
this.form = new Db.Form ({model: x}); var form = new Db.Form ({model: x});
this.link ({form: form});
} }
,get: function () ,get: function ()
{ {

View File

@ -19,7 +19,9 @@ Htk.Grid = new Class
,'updatable-changed': this.onUpdatableChange ,'updatable-changed': this.onUpdatableChange
}); });
this.form = new Db.Form ({model: x}); var form = new Db.Form ({model: x});
this.link ({form: form});
this.onUpdatableChange (); this.onUpdatableChange ();
this.onModelChange (); this.onModelChange ();
} }

View File

@ -68,6 +68,8 @@ Htk.Repeater = new Class
,loadXml: function (builder, node) ,loadXml: function (builder, node)
{ {
this.parent (builder, node);
var template = node.querySelector ('template:first-of-type'); var template = node.querySelector ('template:first-of-type');
if (template) if (template)
@ -105,7 +107,7 @@ Htk.Repeater = new Class
this.childsData.push ({ this.childsData.push ({
builder: builder, builder: builder,
form, form form: form
}); });
var mainNode = builder.loadXmlFromNode (this.xml); var mainNode = builder.loadXmlFromNode (this.xml);
@ -122,6 +124,7 @@ Htk.Repeater = new Class
return; return;
Vn.Node.removeChilds (this.node); Vn.Node.removeChilds (this.node);
this.freeChildsData ();
this.childsData = []; this.childsData = [];
switch (this._model.status) switch (this._model.status)
@ -183,4 +186,20 @@ Htk.Repeater = new Class
{ {
this.buildBox (row); this.buildBox (row);
} }
,freeChildsData: function ()
{
if (this.childsData)
for (var i = 0; i < this.childsData.length; i++)
{
this.childsData[i].form.unref ();
this.childsData[i].builder.unref ();
}
}
,destroy: function ()
{
this.freeChildsData ();
this.parent ();
}
}); });

View File

@ -21,7 +21,7 @@ Sql.Batch = new Class
} }
} }
,params: {} ,objects: {}
,_blocked: false ,_blocked: false
,loadXml: function (builder, node) ,loadXml: function (builder, node)
@ -48,47 +48,52 @@ Sql.Batch = new Class
,get: function (id) ,get: function (id)
{ {
if (this.params[id]) if (this.objects[id])
return this.params[id]; return this.objects[id];
return null; return null;
} }
,add: function (id) ,add: function (id)
{ {
if (!this.params[id]) if (!this.objects[id])
this.params[id] = null; this.objects[id] = null;
} }
,remove: function (id) ,_addObject: function (id, object)
{
if (this.params[id])
{
this.params[id].disconnect ('changed', this.emitChanged, this);
delete this.params[id];
}
}
,addObject: function (id, object)
{ {
this.remove (id); this.remove (id);
this.params[id] = object; this.objects[id] = object;
object.on ('changed', this.emitChanged, this); object.on ('changed', this.emitChanged, this);
this.emitChanged (); this.emitChanged ();
} }
,addObject: function (id, object)
{
this._addObject (id, object.ref ());
}
,addValue: function (id, value) ,addValue: function (id, value)
{ {
this.addObject (id, this._addObject (id,
new Sql.Value ({value: value})); new Sql.Value ({value: value}));
} }
,addParam: function (id, param) ,addParam: function (id, param)
{ {
this.addObject (id, this._addObject (id,
new Sql.Value ({param: param})); new Sql.Value ({param: param}));
} }
,remove: function (id)
{
if (this.objects[id])
{
this._unrefObject (this.objects[id]);
delete this.objects[id];
}
}
,block: function () ,block: function ()
{ {
this._blocked = true; this._blocked = true;
@ -112,12 +117,27 @@ Sql.Batch = new Class
,isReady: function () ,isReady: function ()
{ {
var id; for (var id in this.objects)
if (!(this.objects[id] && this.objects[id].isReady ()))
for (id in this.params)
if (!(this.params[id] && this.params[id].isReady ()))
return false; return false;
return true; return true;
} }
,_unrefObject: function (object)
{
if (object)
{
object.disconnect ('changed', this.emitChanged, this);
object.unref ();
}
}
,destroy: function ()
{
for (var id in this.objects)
this._unrefObject (this.objects[id]);
this.parent ();
}
}); });

View File

@ -9,9 +9,9 @@ Sql.List = new Class
,add: function (object) ,add: function (object)
{ {
this.objects.push (object); this.objects.push (object.ref ());
object.on ('changed', this.onObjectChange, this); object.on ('changed', this._onObjectChange, this);
this.onObjectChange (); this._onObjectChange ();
} }
,get: function (i) ,get: function (i)
@ -26,12 +26,11 @@ Sql.List = new Class
,remove: function (i) ,remove: function (i)
{ {
var object = objects.splice (i, 1); this._unrefObject (this.objects.splice (i, 1));
object.disconnect ('changed', this.onObjectChange, this); this._onObjectChange ();
this.onObjectChange ();
} }
,onObjectChange: function () ,_onObjectChange: function ()
{ {
this.signalEmit ('changed'); this.signalEmit ('changed');
} }
@ -49,5 +48,19 @@ Sql.List = new Class
return true; return true;
} }
,_unrefObject: function (object)
{
object.disconnect ('changed', this._onObjectChange, this);
object.unref ();
}
,destroy: function ()
{
for (var i = 0; i < this.objects.length; i++)
this._unrefObject (this.objects[i]);
this.parent ();
}
}); });

View File

@ -9,7 +9,6 @@ Sql.MultiStmt = new Class
,addStmt: function (stmt) ,addStmt: function (stmt)
{ {
stmt.on ('changed', this.stmtChanged.bind (this));
return this.stmts.push (stmt); return this.stmts.push (stmt);
} }
@ -18,11 +17,6 @@ Sql.MultiStmt = new Class
return this.stmts[index]; return this.stmts[index];
} }
,stmtChanged: function ()
{
this.signalEmit ('changed');
}
,isReady: function () ,isReady: function ()
{ {
if (this.stmts.length == 0) if (this.stmts.length == 0)

View File

@ -3,20 +3,10 @@
**/ **/
Vn.Builder = new Class Vn.Builder = new Class
({ ({
objectMap: {} Extends: Vn.Object
,objectMap: {}
,tags: {} ,tags: {}
,destroy: function ()
{
for (var key in this.objectMap)
{
var object = this.objectMap[key];
if (object.destroy instanceof Function)
this.objectMap[key].destroy ();
}
}
,loadXml: function (xmlDoc) ,loadXml: function (xmlDoc)
{ {
if (!xmlDoc) if (!xmlDoc)
@ -322,5 +312,18 @@ Vn.Builder = new Class
return []; return [];
} }
,destroy: function ()
{
for (var tag in this.tags)
{
var objects = this.tags[tag];
for (var i = 0; i < objects.length; i++)
objects[i].unref ();
}
this.parent ();
}
}); });

View File

@ -1,88 +0,0 @@
Vn.HashLink = new Class
({
Extends: Vn.Object
,Tag: 'vn-hash-link'
,Parent: 'param'
,Properties:
{
param:
{
type: Vn.Param
,set: function (x)
{
this.link ({_param: x}, {'changed': this.onParamChange});
this.onHashChange ();
}
,get: function ()
{
return this._param;
}
},
hash:
{
type: Vn.Hash
,set: function (x)
{
this.link ({_hash: x}, {'changed': this.onHashChange});
this.onHashChange ();
}
,get: function ()
{
return this._hash;
}
},
key:
{
type: String
,set: function (x)
{
this._key = x;
this.onHashChange ();
}
,get: function ()
{
return this._key;
}
}
}
,lock: false
,value: null
,_key: null
,onHashChange: function ()
{
if (!this._key || !this._hash)
return;
var newValue = this._hash.get (this._key);
if (this.value != newValue)
{
this.value = newValue;
this.signalEmit ('changed');
if (this._param && !this.lock)
{
this.lock = true;
this._param.value = newValue;
this.lock = false;
}
}
}
,onParamChange: function ()
{
if (this.lock)
return;
var map = {};
map[this.key] = this._param.value;
this.lock = true;
this._hash.add (map);
this.lock = false;
}
});

View File

@ -1,24 +1,29 @@
/** /**
* Class to handle the URL. * Class to handle the URL.
**/ **/
Vn.Hash = new Class Vn.Hash =
({ {
Extends: Vn.Object _hash: null
,_hashMap: {}
,hash: null ,_listener: null
,hashMap: {}
,initialize: function () ,initialize: function ()
{ {
this.hashChangedHandler = this.hashChanged.bind (this); this._listener = new Vn.HashListener ();
window.addEventListener ('hashchange', this.hashChangedHandler);
this.hashChanged (); this._hashChangedHandler = this._hashChanged.bind (this);
window.addEventListener ('hashchange', this._hashChangedHandler);
this._hashChanged ();
} }
,destroy: function () ,destroy: function ()
{ {
this.parent (); window.removeEventListener ('hashchange', this._hashChangedHandler);
window.removeEventListener ('hashchange', this.hashChangedHandler); }
,getListener: function ()
{
return this._listener;
} }
/** /**
@ -28,7 +33,7 @@ Vn.Hash = new Class
**/ **/
,get: function (key) ,get: function (key)
{ {
return this.hashMap[key]; return this._hashMap[key];
} }
/** /**
@ -38,7 +43,7 @@ Vn.Hash = new Class
**/ **/
,add: function (map) ,add: function (map)
{ {
var newMap = this.hashMap; var newMap = this._hashMap;
for (var key in map) for (var key in map)
newMap[key] = map[key]; newMap[key] = map[key];
@ -59,10 +64,16 @@ Vn.Hash = new Class
var newHash = this.make (map); var newHash = this.make (map);
if (newHash !== this.hash) if (newHash !== this._hash)
{ {
this.hashMap = map; this._hashMap = map;
this.putHash (newHash); this._hash = newHash;
this._blockChanged = true;
location.hash = newHash;
this._blockChanged = false;
this._listener.changed ();
} }
} }
@ -78,9 +89,9 @@ Vn.Hash = new Class
var hash = '#!'; var hash = '#!';
if (add) if (add)
for (var key in this.hashMap) for (var key in this._hashMap)
if (!map[key]) if (!map[key])
map[key] = this.hashMap[key]; map[key] = this._hashMap[key];
for (var key in map) for (var key in map)
{ {
@ -93,21 +104,14 @@ Vn.Hash = new Class
return hash; return hash;
} }
,putHash: function (newHash) ,_hashChanged: function ()
{
location.hash = newHash;
this.hash = location.hash;
this.signalEmit ('changed');
}
,hashChanged: function ()
{ {
var newHash = location.hash; var newHash = location.hash;
if (newHash === this.hash) if (this._blockChanged || newHash === this._hash)
return; return;
this.hashMap = {}; var newMap = hashMap = {};
var kvPairs = newHash.substr(2).split ('&'); var kvPairs = newHash.substr(2).split ('&');
for (var i = 0; i < kvPairs.length; i++) for (var i = 0; i < kvPairs.length; i++)
@ -115,9 +119,11 @@ Vn.Hash = new Class
var kvPair = kvPairs[i].split ('=', 2); var kvPair = kvPairs[i].split ('=', 2);
if (kvPair[0]) if (kvPair[0])
this.hashMap[kvPair[0]] = kvPair[1]; newMap[kvPair[0]] = kvPair[1];
} }
this.putHash (newHash); this._hashMap = newMap;
this._hash = newHash;
this._listener.changed ();
} }
}); };

View File

@ -21,8 +21,9 @@ Js::includeLib ('vn'
,'mutators' ,'mutators'
,'object' ,'object'
,'param' ,'param'
,'hash-listener'
,'hash' ,'hash'
,'hash-link' ,'hash-param'
,'node' ,'node'
,'builder' ,'builder'
,'http-request' ,'http-request'

View File

@ -47,6 +47,16 @@ Vn.Node =
if (found) if (found)
node.className = classes.join (' '); node.className = classes.join (' ');
} }
,hide: function (node)
{
node.style.display = 'none';
}
,show: function (node)
{
node.style.display = '';
}
}; };
function $ (id) function $ (id)

View File

@ -7,7 +7,10 @@ Vn.Object = new Class
({ ({
Tag: 'vn-object' Tag: 'vn-object'
,Properties: {} ,Properties: {}
,signals: {} ,signals: {}
,links: {}
,refCount: 1
,initialize: function (props) ,initialize: function (props)
{ {
@ -15,6 +18,20 @@ Vn.Object = new Class
this[prop] = props[prop]; this[prop] = props[prop];
} }
,ref: function ()
{
this.refCount++;
return this;
}
,unref: function ()
{
this.refCount--;
if (this.refCount === 0)
this._destroy ();
}
,loadXml: function (builder, node) ,loadXml: function (builder, node)
{ {
return null; return null;
@ -53,7 +70,7 @@ Vn.Object = new Class
* @param {Function} callback The callback * @param {Function} callback The callback
* @param {Boolean} block %true for lock the signal, %false for unlock * @param {Boolean} block %true for lock the signal, %false for unlock
**/ **/
,blockSignal: function (id, callback, block) ,blockSignal: function (id, callback, block, instance)
{ {
var callbacks = this.signals[id]; var callbacks = this.signals[id];
@ -61,7 +78,8 @@ Vn.Object = new Class
return; return;
for (var i = 0; i < callbacks.length; i++) for (var i = 0; i < callbacks.length; i++)
if (callbacks[i].callback == callback) if (callbacks[i].callback == callback
&& callbacks[i].instance == instance)
callbacks[i].blocked = block; callbacks[i].blocked = block;
} }
@ -108,12 +126,35 @@ Vn.Object = new Class
callbacks.splice (i--, 1); callbacks.splice (i--, 1);
} }
/**
* Disconnects all signals for the given instance.
*
* @param {Object} instance The instance
**/
,disconnectByInstance: function (instance)
{
for (var signalId in this.signals)
{
var callbacks = this.signals[signalId];
for (var i = 0; i < callbacks.length; i++)
if (callbacks[i].instance == instance)
callbacks.splice (i--, 1);
}
}
/** /**
* Destroys the object, this method should only be called before losing * Destroys the object, this method should only be called before losing
* the last reference to the object. * the last reference to the object.
**/ **/
,destroy: function () ,_destroy: function ()
{ {
var links = this.links;
for (var key in links)
links[key].disconnectByInstance (this);
delete this.links;
delete this.signals; delete this.signals;
} }
@ -125,15 +166,22 @@ Vn.Object = new Class
var oldObject = this[key]; var oldObject = this[key];
if (oldObject) if (oldObject)
for (var signal in handlers) {
oldObject.disconnect (signal, handlers[signal], this); oldObject.disconnectByInstance (this);
oldObject.unref ();
}
this[key] = newObject; this[key] = newObject;
if (newObject) if (newObject)
for (var signal in handlers) {
newObject.on (signal, handlers[signal], this); this.links[key] = newObject.ref ();
for (var signal in handlers)
newObject.on (signal, handlers[signal], this);
}
else if (oldObject)
delete this.links[key];
} }
} }
}); });

View File

@ -39,8 +39,8 @@ Vn.Param = new Class
type: Vn.Param type: Vn.Param
,set: function (x) ,set: function (x)
{ {
this.link ({_master: x}, {'changed': this.onMasterChange}); this.link ({_master: x}, {'changed': this._onMasterChange});
this.onMasterChange (); this._onMasterChange ();
} }
,get: function () ,get: function ()
{ {
@ -53,7 +53,7 @@ Vn.Param = new Class
,_master: null ,_master: null
,masterLock: false ,masterLock: false
,onMasterChange: function () ,_onMasterChange: function ()
{ {
if (this.masterLock) if (this.masterLock)
return; return;

View File

@ -1,6 +1,8 @@
{ {
"ByProvince": "Desglose por provincia" "ByProvince": "Desglose por provincia"
,"Return": "Volver"
,"SelectAgency": "Seleccione una agencia en el listado de la izquierda" ,"SelectAgency": "Seleccione una agencia en el listado de la izquierda"
,"Province": "Provincia" ,"Province": "Provincia"
,"Expeditions": "Exps." ,"Expeditions": "Exps."

View File

@ -25,4 +25,5 @@
,"Subtotal": "Subtotal" ,"Subtotal": "Subtotal"
,"OrderItemsUpdated": "Su pedido lleva demasiado tiempo abierto y ha sido actualizado, los precios o cantidades de sus artículos pueden haber cambiado." ,"OrderItemsUpdated": "Su pedido lleva demasiado tiempo abierto y ha sido actualizado, los precios o cantidades de sus artículos pueden haber cambiado."
,"RememberReconfiguringImpact": "Recuerde que si vuelve a configurar el pedido los precios o cantidades de sus artículos podrían cambiar."
} }

View File

@ -25,5 +25,4 @@
,"OrderStarted": "Pedido empezado" ,"OrderStarted": "Pedido empezado"
,"OrderUpdated": "Pedido actualizado" ,"OrderUpdated": "Pedido actualizado"
,"RememberReconfiguringImpact": "Recuerde que si vuelve a configurar el pedido los precios o cantidades de sus artículos podrían cambiar."
} }

View File

@ -55,6 +55,7 @@ Vn.Locale.add
,"NewVersionAvailable": "Hay una nueva actualización, la página se recargargará automaticamente para descargarla" ,"NewVersionAvailable": "Hay una nueva actualización, la página se recargargará automaticamente para descargarla"
,"ChangeLog": "Cambios recientes" ,"ChangeLog": "Cambios recientes"
,"CookiesNotification": "Al utilizar este sitio web aceptas el uso de cookies para la personalización de contenidos y análisis." ,"CookiesNotification": "Al utilizar este sitio web aceptas el uso de cookies para la personalización de contenidos y análisis."
,"ReturnToOldWebsite": "Ir a web antigua"
,"Home": "Inicio" ,"Home": "Inicio"
,"Orders": "Pedidos" ,"Orders": "Pedidos"

View File

@ -1,4 +1,5 @@
{ {
"Welcome": "Bienvenido/a" "Welcome": "Bienvenido/a"
,"Exit": "Salir" ,"Exit": "Salir"
,"TestTheNewWebsite": "¡Prueba la nueva web!"
} }

View File

@ -29,7 +29,12 @@
<div id="body"> <div id="body">
<div id="content"> <div id="content">
<div id="menu-box"> <div id="menu-box">
<ul id="menu"></ul> <div id="menu-overflow">
<a id="test-link" href="//test-www.verdnatura.es">
<?=s('TestTheNewWebsite')?>
</a>
<ul id="menu"></ul>
</div>
<div id="links"> <div id="links">
<a target="_blank" href="http://verdnaturacomunicacion.blogspot.com.es/"> <a target="_blank" href="http://verdnaturacomunicacion.blogspot.com.es/">
<img alt="Blogger" src="image/blogger.svg" title="Blogger"/> <img alt="Blogger" src="image/blogger.svg" title="Blogger"/>

View File

@ -7,28 +7,6 @@ Vn.Module = new Class
this.conn = gui.conn; this.conn = gui.conn;
this.hash = gui.hash; this.hash = gui.hash;
this.formInfo = formInfo; this.formInfo = formInfo;
this.builder = new Vn.Builder ();
this.builder.signalData = this;
this.builder.loadXml (Vn.getXml ('forms/'+ formInfo.path +'/ui.xml'));
this.node = this.builder.get ('form');
var models = this.builder.getObjects ('db-model');
for (var i = 0; i < models.length; i++)
models[i].conn = this.conn;
var queries = this.builder.getObjects ('db-query');
for (var i = 0; i < queries.length; i++)
queries[i].conn = this.conn;
var hashLinks = this.builder.getObjects ('vn-hash-link');
for (var i = 0; i < hashLinks.length; i++)
hashLinks[i].hash = this.hash;
gui.formHolder.appendChild (this.node);
} }
/** /**
@ -45,6 +23,29 @@ Vn.Module = new Class
/** /**
* Called when the form is opened. * Called when the form is opened.
**/ **/
,open: function ()
{
this.builder = new Vn.Builder ();
this.builder.signalData = this;
this.builder.loadXml (Vn.getXml ('forms/'+ this.formInfo.path +'/ui.xml'));
this.node = this.builder.get ('form');
var models = this.builder.getObjects ('db-model');
for (var i = 0; i < models.length; i++)
models[i].conn = this.conn;
var queries = this.builder.getObjects ('db-query');
for (var i = 0; i < queries.length; i++)
queries[i].conn = this.conn;
this.gui.formHolder.appendChild (this.node);
}
/**
* Called when the form is activated.
**/
,activate: function () {} ,activate: function () {}
/** /**
@ -52,8 +53,11 @@ Vn.Module = new Class
**/ **/
,close: function () ,close: function ()
{ {
Vn.Node.remove (this.node); if (this.node)
this.builder.destroy (); {
Vn.Node.remove (this.node);
this.builder.unref ();
}
} }
}); });

View File

@ -118,7 +118,7 @@ body
background-color: #CE8; background-color: #CE8;
} }
/* Menu */ /* Left panel */
#menu-button #menu-button
{ {
@ -163,18 +163,43 @@ ul.submenu
z-index: 20; z-index: 20;
box-shadow: 0 0.2em 0.2em #AAA; box-shadow: 0 0.2em 0.2em #AAA;
} }
#menu #menu-overflow
{ {
position: absolute; position: absolute;
top: 0; top: 0;
left: 0; left: 0;
right: 0; right: 0;
bottom: 4em; bottom: 4em;
margin: 0;
padding: 1em 0;
list-style-type: none;
overflow: auto; overflow: auto;
} }
/* Test link */
#test-link
{
display: block;
margin: 1em auto;
max-width: 70%;
background-color: #3f51b5;
color: white;
padding: 0 1em;
line-height: 2em;
border-radius: 0.1em;
text-align: center;
}
#test-link:hover
{
background-color: #4f61c5;
}
/* Menu */
#menu
{
list-style-type: none;
padding: 0;
margin: 0;
}
#menu > li #menu > li
{ {
display: block; display: block;

View File

@ -1,26 +1,23 @@
Vn.Tpv = new Class Vn.Tpv =
({ {
initialize: function (conn, hash) check: function (conn)
{ {
this.conn = conn; var tpvStatus = Vn.Hash.get ('tpv_status');
this.hash = hash;
var tpvStatus = this.hash.get ('tpv_status');
if (tpvStatus) if (tpvStatus)
{ {
var batch = new Sql.Batch (); var batch = new Sql.Batch ();
batch.addValue ('transaction', this.hash.get ('tpv_order')); batch.addValue ('transaction', Vn.Hash.get ('tpv_order'));
batch.addValue ('status', tpvStatus); batch.addValue ('status', tpvStatus);
var query = 'CALL transaction_end (#transaction, #status)'; var query = 'CALL transaction_end (#transaction, #status)';
this.conn.execQuery (query, null, batch); conn.execQuery (query, null, batch);
} }
} }
,pay: function (amount, company) ,pay: function (conn, amount, company)
{ {
if (amount > 0) if (amount > 0)
{ {
@ -30,14 +27,14 @@ Vn.Tpv = new Class
batch.addValue ('company', company); batch.addValue ('company', company);
batch.addValue ('amount', parseInt (amount * 100)); batch.addValue ('amount', parseInt (amount * 100));
this.conn.execQuery (query, conn.execQuery (query,
this.onTransactionStart.bind (this), batch); this._onTransactionStart.bind (this), batch);
} }
else if (!isNaN (amount)) else if (!isNaN (amount))
(new Htk.Toast ()).showError (_('AmountError')); (new Htk.Toast ()).showError (_('AmountError'));
} }
,onTransactionStart: function (resultSet) ,_onTransactionStart: function (resultSet)
{ {
var res = resultSet.fetchResult (); var res = resultSet.fetchResult ();
@ -74,27 +71,53 @@ Vn.Tpv = new Class
} }
var transactionId = res.get ('ds_order'); var transactionId = res.get ('ds_order');
form['Ds_Merchant_UrlOK'].value = this.makeUrl ('ok', transactionId); form['Ds_Merchant_UrlOK'].value = this._makeUrl ('ok', transactionId);
form['Ds_Merchant_UrlKO'].value = this.makeUrl ('ko', transactionId); form['Ds_Merchant_UrlKO'].value = this._makeUrl ('ko', transactionId);
form.submit (); form.submit ();
} }
else else
alert (_('PayError')); (new Htk.Toast ()).showWarning (_('PayError'));
} }
,makeUrl: function (status, order) ,_makeUrl: function (status, order)
{ {
var path = location.protocol +'//'+ location.host; var path = location.protocol +'//'+ location.host;
path += location.port ? ':'+ location.port : ''; path += location.port ? ':'+ location.port : '';
path += location.pathname; path += location.pathname;
path += location.search ? location.search : ''; path += location.search ? location.search : '';
path += this.hash.make ({ path += Vn.Hash.make ({
'tpv_status': status, 'tpv_status': status,
'tpv_order': order 'tpv_order': order
}, true); }, true);
return path; return path;
} }
}); };
Vn.BasketChecker =
{
check: function (conn, callback)
{
conn.execQuery ('CALL basket_check ()',
this._onBasketCheck.bind (this, callback));
}
,_onBasketCheck: function (callback, resultSet)
{
var status = resultSet.fetchValue ();
if (!status)
return;
var isOk = status == 'UPDATED' || status == 'OK';
if (status == 'UPDATED')
(new Htk.Toast ()).showWarning (_('OrderItemsUpdated'));
if (callback)
callback (isOk);
if (!isOk)
Vn.Hash.set ({'form': 'ecomerce/checkout'});
}
};

View File

@ -18,18 +18,11 @@ Vn.Web =
this.loader = $('loader'); this.loader = $('loader');
this.formHolder = $('form-holder'); this.formHolder = $('form-holder');
this.hash = new Vn.Hash (); Vn.Hash.initialize ();
this.hashLink = new Vn.HashLink this.hash = Vn.Hash;
({
hash: this.hash
,key: 'form'
});
this.hashLink.on ('changed', this.onFormChange, this);
this.conn = new Db.Conn (); this.hashParam = new Vn.HashParam ({key: 'form'});
this.conn.on ('error', this.onConnError, this); this.hashParam.on ('changed', this.onFormChange, this);
this.conn.on ('loading-changed', this.onConnLoading, this);
this.conn.open (null, null, null, this.connOpened.bind (this));
$('background').onclick = function () {}; $('background').onclick = function () {};
@ -53,22 +46,33 @@ Vn.Web =
Vn.Cookie.set ('hedera_cookies', true); Vn.Cookie.set ('hedera_cookies', true);
(new Htk.Toast ()).showWarning (_('CookiesNotification')); (new Htk.Toast ()).showWarning (_('CookiesNotification'));
} }
this.conn = new Db.Conn ();
this.conn.on ('error', this.onConnError, this);
this.conn.on ('loading-changed', this.onConnLoading, this);
// this.conn.open (null, null, null, this.connOpened.bind (this));
var sql = 'SELECT default_form, image_dir FROM config;'
+'SELECT production_domain, test_domain FROM config;'
+'SELECT name FROM customer_view;'
+'CALL form_list ();';
this.conn.execQuery (sql, this.onMainQueryDone.bind (this));
} }
,showBackground: function () ,showBackground: function ()
{ {
$('background').style.display = 'block'; Vn.Node.show ($('background'));
} }
,hideBackground: function () ,hideBackground: function ()
{ {
$('background').style.display = 'none'; Vn.Node.hide ($('background'));
} }
,showMenu: function () ,showMenu: function ()
{ {
this.showBackground (); this.showBackground ();
$('menu-box').style.display = 'block'; Vn.Node.show ($('menu-box'));
this.menuShown = true; this.menuShown = true;
this.hideMenuCallback = this.hideMenu.bind (this); this.hideMenuCallback = this.hideMenu.bind (this);
@ -78,7 +82,7 @@ Vn.Web =
,hideMenu: function () ,hideMenu: function ()
{ {
this.hideBackground (); this.hideBackground ();
$('menu-box').style.display = 'none'; Vn.Node.hide ($('menu-box'));
$('menu-button').style.display = 'initial'; $('menu-button').style.display = 'initial';
this.menuShown = false; this.menuShown = false;
@ -86,14 +90,6 @@ Vn.Web =
this.hideMenuCallback = null; this.hideMenuCallback = null;
} }
,connOpened: function (conn, success)
{
var sql = 'SELECT default_form, image_dir FROM config;'
+'SELECT name FROM customer_view;'
+'CALL form_list ();';
this.conn.execQuery (sql, this.onMainQueryDone.bind (this));
}
,onMainQueryDone: function (resultSet) ,onMainQueryDone: function (resultSet)
{ {
// Retrieving configuration parameters // Retrieving configuration parameters
@ -105,6 +101,23 @@ Vn.Web =
for (var i = 0; i < res.columns.length; i++) for (var i = 0; i < res.columns.length; i++)
Vn.Config[columns[i].name] = res.get (columns[i].name); Vn.Config[columns[i].name] = res.get (columns[i].name);
// Retrieving configuration parameters
var res = resultSet.fetchResult ();
if (res.next () && res.get ('test_domain'))
{
if (location.host != res.get ('production_domain'))
{
Vn.Node.setText ($('test-link'), _('ReturnToOldWebsite'));
$('test-link').href = res.get ('production_domain');
}
else
$('test-link').href = res.get ('test_domain');
}
else
Vn.Node.hide ($('test-link'));
// Retrieving the user name // Retrieving the user name
var userName = resultSet.fetchValue (); var userName = resultSet.fetchValue ();
@ -221,7 +234,7 @@ Vn.Web =
ul.appendChild (li); ul.appendChild (li);
var a = document.createElement ('a'); var a = document.createElement ('a');
a.href = this.hash.make ({'form': res.get ('path')}); a.href = Vn.Hash.make ({'form': res.get ('path')});
this.menuOptions[res.get ('path')] = a; this.menuOptions[res.get ('path')] = a;
li.appendChild (a); li.appendChild (a);
@ -280,7 +293,7 @@ Vn.Web =
,onFormChange: function () ,onFormChange: function ()
{ {
var formPath = this.hashLink.value; var formPath = this.hashParam.value;
this.openForm (formPath ? formPath : Vn.Config['default_form'], null); this.openForm (formPath ? formPath : Vn.Config['default_form'], null);
} }
@ -399,6 +412,7 @@ Vn.Web =
try { try {
var klass = eval (formInfo.klass); var klass = eval (formInfo.klass);
this.activeForm = new klass (this, formInfo); this.activeForm = new klass (this, formInfo);
this.activeForm.open ();
this.activeForm.activate (); this.activeForm.activate ();
} }
catch (e) { catch (e) {
@ -420,7 +434,7 @@ Vn.Web =
,unload: function () ,unload: function ()
{ {
this.hashLink.disconnect ('changed', this.onFormChange, this); this.hashParam.destroy ();
this.conn.disconnect ('error', this.onConnError, this); this.conn.disconnect ('error', this.onConnError, this);
this.conn.disconnect ('loading-changed', this.onConnLoading, this); this.conn.disconnect ('loading-changed', this.onConnLoading, this);
} }