From 7b4ff3b8155af4e548753d4d94f3061d7d717e10 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 9 Nov 2015 09:14:33 +0100 Subject: [PATCH] Backup --- web/forms/account/address-list/ui.xml | 85 ++-- web/forms/account/address/ui.xml | 49 ++- web/forms/cms/home/ui.xml | 14 +- web/forms/cms/training/ui.xml | 14 +- web/forms/ecomerce/catalog/catalog.js | 4 +- web/forms/ecomerce/catalog/ui.xml | 74 ++-- web/forms/ecomerce/checkout/ui.xml | 92 +++-- web/forms/ecomerce/orders/ui.xml | 14 +- web/js/db/model.js | 1 + web/js/hedera/app.js | 4 +- web/js/hedera/login.xml | 3 +- web/js/hedera/module.js | 20 +- web/js/htk/assistant-bar.js | 3 +- web/js/htk/column.js | 12 +- web/js/htk/field/button.js | 3 +- web/js/htk/field/calendar.js | 2 +- web/js/htk/field/check.js | 3 +- web/js/htk/field/date-chooser.js | 2 +- web/js/htk/field/entry.js | 3 +- web/js/htk/field/html.js | 2 +- web/js/htk/field/image.js | 9 +- web/js/htk/field/label.js | 2 +- web/js/htk/field/radio-group.js | 4 +- web/js/htk/field/radio.js | 4 +- web/js/htk/field/select.js | 3 +- web/js/htk/field/spin.js | 2 +- web/js/htk/field/table.js | 3 +- web/js/htk/field/text-area.js | 3 +- web/js/htk/field/text.js | 2 +- web/js/htk/full-image.js | 3 +- web/js/htk/grid.js | 9 +- web/js/htk/image-editor.js | 5 +- web/js/htk/loader.js | 3 +- web/js/htk/popup.js | 27 +- web/js/htk/repeater.js | 59 ++- web/js/htk/widget.js | 12 +- web/js/sql/batch.js | 4 +- web/js/sql/expr.js | 12 - web/js/sql/operation.js | 5 + web/js/vn/builder-new.js | 575 ++++++++++++++++++++++++++ web/js/vn/builder.js | 414 ++----------------- web/js/vn/main.js | 1 + web/js/vn/node.js | 2 +- web/js/vn/object.js | 74 ++-- 44 files changed, 968 insertions(+), 673 deletions(-) create mode 100755 web/js/vn/builder-new.js diff --git a/web/forms/account/address-list/ui.xml b/web/forms/account/address-list/ui.xml index a08b7e6e..e7265523 100755 --- a/web/forms/account/address-list/ui.xml +++ b/web/forms/account/address-list/ui.xml @@ -1,17 +1,22 @@ - - SELECT user_id, default_address - FROM customer_view c + + + SELECT user_id, default_address + FROM customer_view c + - 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 + + 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 +
@@ -32,39 +37,39 @@ column="default_address" form="user-form"/> - +
+ diff --git a/web/forms/account/address/ui.xml b/web/forms/account/address/ui.xml index 5186226f..f5dcce6b 100755 --- a/web/forms/account/address/ui.xml +++ b/web/forms/account/address/ui.xml @@ -1,18 +1,20 @@ - - - + + - - - SELECT a.id, a.name, a.consignee, a.city, a.zip_code, a.province_id, c.Id country_id - FROM address_view a - LEFT JOIN vn2008.province p ON p.province_id = a.province_id - JOIN vn2008.Paises c ON c.Id = p.Paises_Id - WHERE active != FALSE AND a.id = #address + + + SELECT a.id, a.name, a.consignee, a.city, a.zip_code, a.province_id, c.Id country_id + FROM address_view a + LEFT JOIN vn2008.province p ON p.province_id = a.province_id + JOIN vn2008.Paises c ON c.Id = p.Paises_Id + WHERE active != FALSE AND a.id = #address + - + + + @@ -53,10 +55,17 @@
- + + - SELECT Id, Pais FROM vn2008.Paises - ORDER BY Pais + + SELECT Id, Pais FROM vn2008.Paises + ORDER BY Pais +
@@ -64,11 +73,15 @@ - SELECT province_id, name FROM vn2008.province - WHERE Paises_Id = #country - ORDER BY name + + SELECT province_id, name FROM vn2008.province + WHERE Paises_Id = #country + ORDER BY name + - + + + diff --git a/web/forms/cms/home/ui.xml b/web/forms/cms/home/ui.xml index 539e8e03..9aedd6fa 100755 --- a/web/forms/cms/home/ui.xml +++ b/web/forms/cms/home/ui.xml @@ -5,12 +5,14 @@
- - SELECT title, date_time, text, image, id FROM news - WHERE tag != 'course' - ORDER BY priority, date_time DESC + + + SELECT title, date_time, text, image, id FROM news + WHERE tag != 'course' + ORDER BY priority, date_time DESC + - +
diff --git a/web/forms/cms/training/ui.xml b/web/forms/cms/training/ui.xml index 8880d57f..6f20f33c 100755 --- a/web/forms/cms/training/ui.xml +++ b/web/forms/cms/training/ui.xml @@ -5,12 +5,14 @@
- - SELECT title, date_time, text, image, id FROM news - WHERE tag = 'course' - ORDER BY priority, date_time DESC + + + SELECT title, date_time, text, image, id FROM news + WHERE tag = 'course' + ORDER BY priority, date_time DESC + - +
diff --git a/web/forms/ecomerce/catalog/catalog.js b/web/forms/ecomerce/catalog/catalog.js index 8de34492..6c3517c9 100755 --- a/web/forms/ecomerce/catalog/catalog.js +++ b/web/forms/ecomerce/catalog/catalog.js @@ -399,8 +399,6 @@ Vn.Filter = new Class ,initialize: function (props) { - this.parent (props); - this.createElement ('div'); this.node.className = 'vn-filter'; @@ -411,6 +409,8 @@ Vn.Filter = new Class this._ul = document.createElement ('ul'); this.node.appendChild (this._ul); + + this.parent (props); } ,_onClick: function () diff --git a/web/forms/ecomerce/catalog/ui.xml b/web/forms/ecomerce/catalog/ui.xml index 0452aaa6..28de2a31 100755 --- a/web/forms/ecomerce/catalog/ui.xml +++ b/web/forms/ecomerce/catalog/ui.xml @@ -24,13 +24,11 @@ -->
- - - - - - + + + + @@ -52,32 +50,38 @@ GROUP BY warehouse_id - CREATE TEMPORARY TABLE tmp.bionic_calc - (INDEX (item_id)) - ENGINE=MEMORY - SELECT Id_Article item_id FROM vn2008.Articles - WHERE #filter; - CALL bionic_calc (); - SELECT a.Id_Article item_id, t.available, t.price, p.producer, - a.Foto, a.Article, a.Categoria, a.Medida, a.Tallos, a.Color, o.Abreviatura - FROM tmp.bionic_item t - JOIN vn2008.Articles a ON a.Id_Article = t.item_id - LEFT JOIN vn2008.Articles_producer p ON p.Id_Article = a.Id_Article - LEFT JOIN vn2008.Origen o ON a.id_origen = o.id - WHERE t.available > 0 - ORDER BY a.Article, a.Medida - LIMIT 400; + + CREATE TEMPORARY TABLE tmp.bionic_calc + (INDEX (item_id)) + ENGINE=MEMORY + SELECT Id_Article item_id FROM vn2008.Articles + WHERE #filter; + CALL bionic_calc (); + SELECT a.Id_Article item_id, t.available, t.price, p.producer, + a.Foto, a.Article, a.Categoria, a.Medida, a.Tallos, a.Color, o.Abreviatura + FROM tmp.bionic_item t + JOIN vn2008.Articles a ON a.Id_Article = t.item_id + LEFT JOIN vn2008.Articles_producer p ON p.Id_Article = a.Id_Article + LEFT JOIN vn2008.Origen o ON a.id_origen = o.id + WHERE t.available > 0 + ORDER BY a.Article, a.Medida + LIMIT 400; + - + + + - CALL bionic_from_item (#item); - SELECT p.warehouse_id, p.grouping, p.price, p.rate, l.available - FROM tmp.bionic_lot l - JOIN tmp.bionic_price p - ON p.warehouse_id = l.warehouse_id - ORDER BY warehouse_id, grouping; + + CALL bionic_from_item (#item); + SELECT p.warehouse_id, p.grouping, p.price, p.rate, l.available + FROM tmp.bionic_lot l + JOIN tmp.bionic_price p + ON p.warehouse_id = l.warehouse_id + ORDER BY warehouse_id, grouping; + @@ -148,7 +152,7 @@ - +
@@ -222,7 +226,7 @@ - + CALL item_available (); SELECT DISTINCT r.id, r.reino FROM vn2008.reinos r @@ -235,7 +239,7 @@ - + CALL item_available (); SELECT DISTINCT t.tipo_id, LEFT(t.Tipo, 18) type FROM vn2008.Tipos t @@ -246,7 +250,7 @@ - + CALL item_available (); SELECT DISTINCT c.Id_Tinta, c.name FROM vn2008.Tintas c @@ -257,7 +261,7 @@ - + CALL item_available (); SELECT DISTINCT o.id, o.Origen, o.Abreviatura FROM vn2008.Origen o @@ -268,7 +272,7 @@ - + CALL item_available (); SELECT DISTINCT a.Categoria, a.Categoria category FROM vn2008.Articles a diff --git a/web/forms/ecomerce/checkout/ui.xml b/web/forms/ecomerce/checkout/ui.xml index b00d21ee..bd7d7a5c 100755 --- a/web/forms/ecomerce/checkout/ui.xml +++ b/web/forms/ecomerce/checkout/ui.xml @@ -5,46 +5,58 @@ - - SELECT delivery_method, agency_id, address_id - FROM basket_defaults + + + SELECT delivery_method, agency_id, address_id + FROM basket_defaults + - - SELECT v.code delivery_method, o.date_send, o.agency_id, o.address_id - FROM basket o - JOIN vn2008.Vistas v ON o.delivery_method_id = v.vista_id + + + SELECT v.code delivery_method, o.date_send, o.agency_id, o.address_id + FROM basket o + JOIN vn2008.Vistas v ON o.delivery_method_id = v.vista_id + - - CALL agency_list_from_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; + + + CALL agency_list_from_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; + - - + + + + - - CALL agency_list_from_date (#date, #address); - SELECT a.Id_Agencia, SUBSTR(a.description, 5) 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 = 'PICKUP' - ORDER BY a.description; - DROP TEMPORARY TABLE t_agency; + + + CALL agency_list_from_date (#date, #address); + SELECT a.Id_Agencia, SUBSTR(a.description, 5) 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 = 'PICKUP' + ORDER BY a.description; + DROP TEMPORARY TABLE t_agency; + - - + + + + @@ -108,14 +120,16 @@ form-id="iter" on-change="onAddressChange" renderer="addressRenderer"> - - 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 + + + 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 + - +
diff --git a/web/forms/ecomerce/orders/ui.xml b/web/forms/ecomerce/orders/ui.xml index 4cd53c16..89764dce 100755 --- a/web/forms/ecomerce/orders/ui.xml +++ b/web/forms/ecomerce/orders/ui.xml @@ -1,9 +1,11 @@ - CALL customer_get_debt_by_company (); - SELECT * FROM t_customer_debt; - DROP TEMPORARY TABLE t_customer_debt; + + CALL customer_get_debt_by_company (); + SELECT * FROM t_customer_debt; + DROP TEMPORARY TABLE t_customer_debt; +
@@ -31,8 +33,10 @@
- - CALL ticket_list (); + + + CALL ticket_list (); + diff --git a/web/js/db/model.js b/web/js/db/model.js index 2d7cb791..ffbd22a7 100755 --- a/web/js/db/model.js +++ b/web/js/db/model.js @@ -206,6 +206,7 @@ Db.Model.implement } } + ,_conn: null ,_resultIndex: 0 ,_batch: null ,_stmt: null diff --git a/web/js/hedera/app.js b/web/js/hedera/app.js index 2048ad4a..0d64ff29 100644 --- a/web/js/hedera/app.js +++ b/web/js/hedera/app.js @@ -1,7 +1,9 @@ Vn.App = new Class ({ - initialize: function () + Extends: Vn.Object + + ,initialize: function () { window.onerror = this.onWindowError.bind (this); Vn.Hash.initialize (); diff --git a/web/js/hedera/login.xml b/web/js/hedera/login.xml index 768933f0..c5f4e63e 100755 --- a/web/js/hedera/login.xml +++ b/web/js/hedera/login.xml @@ -12,8 +12,7 @@ -
-
+
diff --git a/web/js/hedera/module.js b/web/js/hedera/module.js index 8466c361..c662148d 100755 --- a/web/js/hedera/module.js +++ b/web/js/hedera/module.js @@ -20,7 +20,7 @@ Vn.Module = new Class ,$: function (objectId) { if (this.builder) - return this.builder.get (objectId); + return this.builder.getById (objectId); return null; } @@ -32,24 +32,26 @@ Vn.Module = new Class { this.close (); - 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 builder = new Vn.Builder (); + builder.signalData = this; + builder.loadXml ('forms/'+ this.formInfo.path +'/ui.xml'); - var models = this.builder.getObjects ('db-model'); + var res = this.builder = builder.load (); + this.node = res.$('form'); + + var models = res.getByTagName ('db-model'); for (var i = 0; i < models.length; i++) models[i].conn = this.conn; - var queries = this.builder.getObjects ('db-query'); + var queries = res.getByTagName ('db-query'); for (var i = 0; i < queries.length; i++) queries[i].conn = this.conn; this.gui.formHolder.appendChild (this.node); - this.gui.setTitle (this.builder.$('title')); - this.gui.setActions (this.builder.$('actions')); + this.gui.setTitle (res.$('title')); + this.gui.setActions (res.$('actions')); } /** diff --git a/web/js/htk/assistant-bar.js b/web/js/htk/assistant-bar.js index 9cfc8486..3195bfe4 100644 --- a/web/js/htk/assistant-bar.js +++ b/web/js/htk/assistant-bar.js @@ -40,8 +40,6 @@ Htk.AssitantBar = new Class ,initialize: function (props) { - this.parent (props); - var bar = this.createElement ('div'); bar.className = 'htk-assistant-bar'; @@ -65,6 +63,7 @@ Htk.AssitantBar = new Class this._steps = steps; this._previousButton = previousButton; this._nextButton = nextButton; + this.parent (props); } ,movePrevious: function () diff --git a/web/js/htk/column.js b/web/js/htk/column.js index 7c691d9d..16dc2d87 100755 --- a/web/js/htk/column.js +++ b/web/js/htk/column.js @@ -6,7 +6,6 @@ Htk.Column = new Class ({ Extends: Vn.Object ,Tag: 'htk-column' - ,Parent: 'grid' ,Properties: { value: @@ -50,15 +49,6 @@ Htk.Column = new Class { return this._class; } - }, - grid: - { - type: Htk.Grid - ,set: function (x) - { - if (x) - x.appendColumn (this); - } } } @@ -67,8 +57,8 @@ Htk.Column = new Class **/ ,initialize: function (props) { - this.parent (props); this.td = document.createElement ('td'); + this.parent (props); } /** diff --git a/web/js/htk/field/button.js b/web/js/htk/field/button.js index 3f22a740..b6f575f8 100755 --- a/web/js/htk/field/button.js +++ b/web/js/htk/field/button.js @@ -50,13 +50,14 @@ Htk.Button = new Class ,initialize: function (props) { - this.parent (props); this.createElement ('button'); this.node.className = 'htk-button'; this.node.addEventListener ('click', this.onClick.bind (this)); this.img = document.createElement ('img'); this.node.appendChild (this.img); + + this.parent (props); } ,render: function () diff --git a/web/js/htk/field/calendar.js b/web/js/htk/field/calendar.js index bf758330..e894b017 100755 --- a/web/js/htk/field/calendar.js +++ b/web/js/htk/field/calendar.js @@ -25,7 +25,6 @@ Htk.Calendar = new Class ,initialize: function (props) { - this.parent (props); var len = Vn.Date.WDays.length; this.createElement ('div'); @@ -133,6 +132,7 @@ Htk.Calendar = new Class this.monthNode = monthNode; this.yearNode = yearNode; this.goToCurrentMonth (); + this.parent (props); } ,getMonthDays: function () diff --git a/web/js/htk/field/check.js b/web/js/htk/field/check.js index b2297d9a..313795cc 100755 --- a/web/js/htk/field/check.js +++ b/web/js/htk/field/check.js @@ -5,10 +5,11 @@ Htk.Check = new Class ,initialize: function (props) { - this.parent (props); this.createElement ('input'); this.node.type = 'checkbox'; this.node.addEventListener ('change', this.changed.bind (this)); + + this.parent (props); } ,changed: function () diff --git a/web/js/htk/field/date-chooser.js b/web/js/htk/field/date-chooser.js index 93e824d7..9c35b488 100755 --- a/web/js/htk/field/date-chooser.js +++ b/web/js/htk/field/date-chooser.js @@ -10,7 +10,6 @@ Htk.DateChooser = new Class ,initialize: function (props) { - this.parent (props); this.createElement ('div'); this.node.className = 'htk-date-chooser'; @@ -18,6 +17,7 @@ Htk.DateChooser = new Class this.node.appendChild (this.label); this.setEditable (this._editable); + this.parent (props); } ,putValue: function (value) diff --git a/web/js/htk/field/entry.js b/web/js/htk/field/entry.js index 686230a2..e343b521 100755 --- a/web/js/htk/field/entry.js +++ b/web/js/htk/field/entry.js @@ -5,10 +5,11 @@ Htk.Entry = new Class ,initialize: function (props) { - this.parent (props); this.createElement ('input'); this.node.type = 'text'; this.node.addEventListener ('change', this.onChange.bind (this)); + + this.parent (props); } ,onChange: function (event) diff --git a/web/js/htk/field/html.js b/web/js/htk/field/html.js index 920bc001..ef7b1eee 100755 --- a/web/js/htk/field/html.js +++ b/web/js/htk/field/html.js @@ -5,8 +5,8 @@ Htk.Html = new Class ,initialize: function (props) { - this.parent (props); this.createElement ('div'); + this.parent (props); } ,putValue: function (value) diff --git a/web/js/htk/field/image.js b/web/js/htk/field/image.js index 2730558a..f962fdfa 100755 --- a/web/js/htk/field/image.js +++ b/web/js/htk/field/image.js @@ -5,7 +5,7 @@ var fullImage = null; Htk.Image = new Class ({ - Extends: Htk.Entry + Extends: Htk.Field ,Tag: 'htk-image' ,Properties: { @@ -93,12 +93,13 @@ Htk.Image = new Class ,initialize: function (props) { - this.parent (props); this.createElement ('img'); -// this.node.addEventListener ('error', this.onImageError.bind (this)); +// this.node.addEventListener ('error', this._onImageError.bind (this)); + + this.parent (props); } - ,onImageError: function () + ,_onImageError: function () { if (!this._empty) { diff --git a/web/js/htk/field/label.js b/web/js/htk/field/label.js index a40a3d39..ef9e0086 100755 --- a/web/js/htk/field/label.js +++ b/web/js/htk/field/label.js @@ -26,8 +26,8 @@ Htk.Label = new Class ,initialize: function (props) { - this.parent (props); this.createElement ('label'); + this.parent (props); } ,putValue: function (value) diff --git a/web/js/htk/field/radio-group.js b/web/js/htk/field/radio-group.js index 789ca437..b2b442e5 100755 --- a/web/js/htk/field/radio-group.js +++ b/web/js/htk/field/radio-group.js @@ -7,9 +7,9 @@ Htk.RadioGroup = new Class ,initialize: function (props) { - this.parent (props); this.clear (); - this.on ('changed', this.onRadioGroupChange, this); + this.on ('changed', this.onRadioGroupChange, this); + this.parent (props); } ,clear: function () diff --git a/web/js/htk/field/radio.js b/web/js/htk/field/radio.js index ecb059ef..0ead437b 100755 --- a/web/js/htk/field/radio.js +++ b/web/js/htk/field/radio.js @@ -33,12 +33,12 @@ Htk.Radio = new Class ,initialize: function (props) { - this.parent (props); - var radio = Vn.Browser.createRadio (''); radio.checked = false; radio.addEventListener ('change', this.onChange.bind (this)); this.node = radio; + + this.parent (props); } ,onChange: function () diff --git a/web/js/htk/field/select.js b/web/js/htk/field/select.js index fba68570..6687ea4f 100755 --- a/web/js/htk/field/select.js +++ b/web/js/htk/field/select.js @@ -96,10 +96,11 @@ Htk.Select = new Class ,initialize: function (props) { - this.parent (props); this.createElement ('select'); this.node.addEventListener ('change', this._onChange.bind (this)); this._addPlaceholder (this._placeholder); + + this.parent (props); } ,on: function (id, callback, instance) diff --git a/web/js/htk/field/spin.js b/web/js/htk/field/spin.js index 28c6f01b..265e3b4b 100755 --- a/web/js/htk/field/spin.js +++ b/web/js/htk/field/spin.js @@ -5,9 +5,9 @@ Htk.Spin = new Class ,initialize: function (props) { - this.parent (props); this.unit = null; this.digits = 0; + this.parent (props); } ,changed: function () diff --git a/web/js/htk/field/table.js b/web/js/htk/field/table.js index 4fc8338f..d4525f27 100755 --- a/web/js/htk/field/table.js +++ b/web/js/htk/field/table.js @@ -5,8 +5,6 @@ Htk.Table = new Class ,initialize: function (props) { - this.parent (props); - var tv = new Htk.TreeView (); this.node.appendChild (tv.getNode ()); @@ -18,6 +16,7 @@ Htk.Table = new Class this.treeview = tv; this.rbGroup = rbGroup; + this.parent (props); } ,setModel: function (model) diff --git a/web/js/htk/field/text-area.js b/web/js/htk/field/text-area.js index 007c0916..98c41515 100755 --- a/web/js/htk/field/text-area.js +++ b/web/js/htk/field/text-area.js @@ -5,9 +5,10 @@ Htk.TextArea = new Class ,initialize: function (props) { - this.parent (props); this.createElement ('textarea'); this.node.addEventListener ('change', this.changed.bind (this)); + + this.parent (props); } ,changed: function (event) diff --git a/web/js/htk/field/text.js b/web/js/htk/field/text.js index e092d90d..64cb2026 100755 --- a/web/js/htk/field/text.js +++ b/web/js/htk/field/text.js @@ -26,8 +26,8 @@ Htk.Text = new Class ,initialize: function (props) { - this.parent (props); this.node = document.createTextNode (''); + this.parent (props); } ,putValue: function (value) diff --git a/web/js/htk/full-image.js b/web/js/htk/full-image.js index aab311e3..2655627a 100755 --- a/web/js/htk/full-image.js +++ b/web/js/htk/full-image.js @@ -12,8 +12,6 @@ Htk.FullImage = new Class ,initialize: function (props) { - this.parent (props); - var div = document.createElement ('div'); div.className = 'htk-full-image'; div.addEventListener ('mouseover', this.cancelHide.bind (this)); @@ -30,6 +28,7 @@ Htk.FullImage = new Class this.div = div; this.loadingBox = loadingBox; this.loadingImg = loadingImg; + this.parent (props); } ,getLeft: function (width) diff --git a/web/js/htk/grid.js b/web/js/htk/grid.js index d909f0be..c9b5f514 100755 --- a/web/js/htk/grid.js +++ b/web/js/htk/grid.js @@ -61,8 +61,6 @@ Htk.Grid = new Class ,initialize: function (props) { - this.parent (props); - this.table = this.createElement ('table'); this.table.className = 'htk-grid'; @@ -74,6 +72,13 @@ Htk.Grid = new Class this.tbody = document.createElement ('tbody'); this.table.appendChild (this.tbody); + + this.parent (props); + } + + ,appendChild: function (child) + { + this.appendColumn (child); } ,removeClicked: function (column, value, row) diff --git a/web/js/htk/image-editor.js b/web/js/htk/image-editor.js index ae715b29..3f3e2bf9 100755 --- a/web/js/htk/image-editor.js +++ b/web/js/htk/image-editor.js @@ -11,12 +11,13 @@ Htk.ImageEditor = new Class ,initialize: function (props) { - this.parent (props) this.builderInit (this.constructor.Xml); this.$('max-size').value = 10 /* MB */ * 1048576; this.$('form').action = - '//'+ Vn.Config['image_host'] +'/rest.php?action=image' + '//'+ Vn.Config['image_host'] +'/rest.php?action=image'; + + this.parent (props); } ,onNameChange: function () diff --git a/web/js/htk/loader.js b/web/js/htk/loader.js index 1c42f564..f2c26e9d 100755 --- a/web/js/htk/loader.js +++ b/web/js/htk/loader.js @@ -5,8 +5,9 @@ Htk.Loader = new Class ,initialize: function (props) { - this.parent (props); var loader = this.createElement ('div'); loader.className = 'htk-loader'; + + this.parent (props); } }); diff --git a/web/js/htk/popup.js b/web/js/htk/popup.js index a7983c65..3c31c9af 100755 --- a/web/js/htk/popup.js +++ b/web/js/htk/popup.js @@ -6,13 +6,14 @@ Htk.Popup = new Class Extends: Htk.Widget ,Tag: 'htk-popup' - ,child: null - ,parent: null + ,_parent: null - ,initialize: function () + ,initialize: function (props) { - this.createElement ('div'); - this.node.className = 'htk-popup'; + var div = this.createElement ('div'); + div.className = 'htk-popup'; + + this.parent (props); } ,setChild: function (child) @@ -35,27 +36,27 @@ Htk.Popup = new Class this.hideHandler = this.hide.bind (this); document.addEventListener ('mousedown', this.hideHandler); - this.parent = parent; + this._parent = parent; this.reset (); } ,reset: function () { - if (!this.parent) + if (!this._parent) return; var spacing = 5; - var rect = this.parent.getBoundingClientRect (); + var rect = this._parent.getBoundingClientRect (); var left = rect.left; - var top = rect.top + spacing + this.parent.offsetHeight; + var top = rect.top + spacing + this._parent.offsetHeight; var width = this.node.offsetWidth; var height = this.node.offsetHeight; if (left + width > Vn.Browser.getInnerWidth ()) - left -= width - this.parent.offsetWidth; + left -= width - this._parent.offsetWidth; if (top + height > Vn.Browser.getInnerHeight ()) - top -= height + this.parent.offsetHeight + spacing * 2; + top -= height + this._parent.offsetHeight + spacing * 2; if (left < 0) left = 0; @@ -68,7 +69,7 @@ Htk.Popup = new Class ,showCenter: function () { - this.parent = null; + this._parent = null; this.background = document.createElement ('div'); this.background.className = 'htk-background'; @@ -94,7 +95,7 @@ Htk.Popup = new Class this.node.removeEventListener ('mousedown', this.stopEvent) document.removeEventListener ('mousedown', this.hideHandler); Vn.Node.remove (this.node); - this.parent = null; + this._parent = null; this.signalEmit ('closed'); } diff --git a/web/js/htk/repeater.js b/web/js/htk/repeater.js index f88bd92f..4da6b1fd 100755 --- a/web/js/htk/repeater.js +++ b/web/js/htk/repeater.js @@ -30,11 +30,11 @@ Htk.Repeater = new Class type: String ,set: function (x) { - this._alias = x; + this._formId = x; } ,get: function () { - this._alias; + this._formId; } } ,renderer: @@ -56,29 +56,26 @@ Htk.Repeater = new Class } } - ,xml: null - ,parentBuilder: null - ,_alias: 'form' + ,_builder: null + ,_formId: 'form' - ,initialize: function () + ,initialize: function (props) { - this.createElement ('div'); - this.node.className = 'htk-repeater'; + var div = this.createElement ('div'); + div.className = 'htk-repeater'; + + this.parent (props); } - ,loadXml: function (builder, node) + ,loadXml: function (builderResult, node) { - this.parent (builder, node); - - var template = node.getElementsByTagName ('template')[0]; - //var template = node.querySelector ('template:first-of-type'); + this.parent (builderResult, node); - if (template) - { - this.xml = template.firstElementChild; - this.parentBuilder = builder; - this.onModelChange (); - } + var builder = this._builder = new Vn.Builder (); + builder.setParent (builderResult); + builder.loadXmlFromNode (node.firstElementChild); + + this.onModelChange (); } ,getChild: function (index) @@ -98,30 +95,28 @@ Htk.Repeater = new Class ,buildBox: function (index) { - var builder = new Vn.Builder (); - builder.setParent (this.parentBuilder); - - var form = new Db.Form (); - form.model = this._model; - form.row = index; - builder.add (this._alias, form); + var form = new Db.Form ({ + model: this._model, + row: index + }); + + this._builder.add (this._formId, form); + var res = this._builder.load (); this.childsData.push ({ - builder: builder, + builder: res, form: form }); - - var mainNode = builder.loadXmlFromNode (this.xml); if (this._renderer) - this._renderer (builder, form); + this._renderer (res, form); - this.node.appendChild (mainNode); + this.node.appendChild (res.getMain ()); } ,onModelChange: function () { - if (!this._model || !this.xml) + if (!this._model || !this._builder) return; Vn.Node.removeChilds (this.node); diff --git a/web/js/htk/widget.js b/web/js/htk/widget.js index c4a6a3e5..0fdf7cd7 100755 --- a/web/js/htk/widget.js +++ b/web/js/htk/widget.js @@ -23,10 +23,12 @@ Htk.Widget = new Class ,builderInit: function (path) { - this.builder = new Vn.Builder (); - this.builder.signalData = this; - this.builder.loadXml (Vn.getXml (path)); - this.node = this.builder.get ('main'); + var builder = new Vn.Builder (); + builder.signalData = this; + builder.loadXml (path); + + var res = this.builder = builder.load (); + this.node = res.$('main'); } ,createElement: function (tagName) @@ -43,7 +45,7 @@ Htk.Widget = new Class ,$: function (id) { if (this.builder) - return this.builder.get (id); + return this.builder.getById (id); return null; } diff --git a/web/js/sql/batch.js b/web/js/sql/batch.js index 4209c970..31225ec7 100755 --- a/web/js/sql/batch.js +++ b/web/js/sql/batch.js @@ -38,9 +38,9 @@ Sql.Batch = new Class if (id) { - if (object = builder.get (childs[i].getAttribute ('param'))) + if (object = builder.getById (childs[i].getAttribute ('param'))) this.addParam (id, object); - else if (object = builder.get (childs[i].getAttribute ('object'))) + else if (object = builder.getById (childs[i].getAttribute ('object'))) this.addObject (id, object); } } diff --git a/web/js/sql/expr.js b/web/js/sql/expr.js index 57d0f540..99f76d19 100755 --- a/web/js/sql/expr.js +++ b/web/js/sql/expr.js @@ -5,17 +5,5 @@ Sql.Expr = new Class ({ Extends: Sql.Object ,Tag: 'sql-expr' - ,Parent: 'operation' - ,Properties: - { - operation: - { - type: Sql.Operation - ,set: function (x) - { - x.exprs.add (this); - } - } - } }); diff --git a/web/js/sql/operation.js b/web/js/sql/operation.js index b93e5e15..597f1093 100755 --- a/web/js/sql/operation.js +++ b/web/js/sql/operation.js @@ -42,6 +42,11 @@ Sql.Operation.implement this.parent (props); this.link ({exprs: new Sql.List ()}, {'changed': this.onListChange}); } + + ,appendChild: function (child) + { + this.exprs.add (child); + } ,onListChange: function () { diff --git a/web/js/vn/builder-new.js b/web/js/vn/builder-new.js new file mode 100755 index 00000000..0ec64301 --- /dev/null +++ b/web/js/vn/builder-new.js @@ -0,0 +1,575 @@ +/** + * Creates a object from a XML specification. + **/ +Vn.Builder = new Class +({ + Extends: Vn.Object + ,addedMap: {} + + ,add: function (id, object) + { + this.addedMap[id] = object; + } + + ,setParent: function (parentBuilder) + { + this.parentBuilder = parentBuilder; + + if (parentBuilder && !this.signalData) + this.signalData = parentBuilder.builder.signalData; + } + + ,getMain: function (result) + { + return result.objects[this.mainContext.id]; + } + + ,getById: function (objectId, result) + { + var index = this.contextMap[objectId]; + + if (index !== undefined) + return result.objects[index]; + else if (this.addedMap[objectId]) + return this.addedMap[objectId]; + else if (this.parentBuilder) + this.parentBuilder.getById (objectId); + + return null; + } + + ,getByTagName: function (tagName, result) + { + var tags = this.tags[tagName]; + + if (tags) + { + var arr = new Array (tags.length); + + for (var i = 0; i < tags.length; i++) + arr[i] = result.objects[tags[i]]; + + return arr; + } + + return []; + } + + ,loadXml: function (path, dstDocument) + { + var xmlDoc = Vn.getXml (path); + + if (!xmlDoc) + return false; + + var docElement = xmlDoc.documentElement; + + if (docElement.tagName !== 'vn') + return false; + + this._compileInit (dstDocument); + + var childs = docElement.childNodes; + + if (childs) + for (var i = 0; i < childs.length; i++) + this._compileNode (childs[i]); + + this._compileEnd (); + return true; + } + + ,loadXmlFromNode: function (node, dstDocument) + { + this._compileInit (dstDocument); + this.mainContext = this._compileNode (node); + this._compileEnd (); + } + + ,load: function () + { + var contexts = this.contexts; + var len = contexts.length; + var objects = new Array (len); + + for (var i = 0; i < len; i++) + { + var context = contexts[i]; + objects[i] = + this.textInstantiate (context) + || this.objectInstantiate (context) + || this.elementInstantiate (context); + } + + var res = new BuilderResult (this, objects); + + var addedObject; + + for (var i = this.propLinks.length - 1; i >= 0; i--) + { + var l = this.propLinks[i]; + if (addedObject = this.addedMap[l.value]) + objects[l.context.id][l.prop] = addedObject; + } + + for (var i = this.childLinks.length - 1; i >= 0; i--) + { + var l = this.childLinks[i]; + if (addedObject = this.addedMap[l.value]) + objects[l.context.id].appendChild (addedObject); + } + + for (var i = 0; i < len; i++) + { + var context = contexts[i]; + var object = objects[i]; + + this.objectLink (context, object, objects, res) || + this.elementLink (context, object, objects, res); + } + + return res; + } + + ,_compileInit: function (dstDocument) + { + this.tags = {}; + this.contexts = []; + this.contextMap = {}; + this.propLinks = []; + this.childLinks = []; + this.mainContext = null; + this.document = dstDocument ? dstDocument : document; + } + + ,_compileEnd: function (node) + { + var contextId; + + for (var i = this.propLinks.length - 1; i >= 0; i--) + { + var l = this.propLinks[i]; + + if (contextId = this.contextMap[l.value]) + { + l.context.objectProps[l.prop] = contextId; + this.propLinks.splice (i, 1); + } + else if (this.parentBuilder) + { + var object = this.parentBuilder.getById (l.value); + + if (object) + pl.context.props[pl.prop] = object; + } + } + + for (var i = this.childLinks.length - 1; i >= 0; i--) + { + var l = this.childLinks[i]; + + if (contextId = this.contextMap[l.value]) + { + l.context.childs.push (contextId); + this.childLinks.splice (i, 1); + } + } + } + + ,_compileNode: function (node) + { + var context = null; + var tagName = null; + + if (node.nodeType === Node.ELEMENT_NODE) + tagName = node.tagName.toLowerCase (); + else if (node.nodeType !== Node.TEXT_NODE + || /^\s*$/.test (node.textContent)) + return null; + + var context = + this.textCompile (node, tagName) + || this.objectCompile (node, tagName) + || this.elementCompile (node, tagName); + + context.id = this.contexts.length; + + if (tagName) + { + var nodeId = node.getAttribute ('id'); + + if (nodeId) + this.contextMap[nodeId] = context.id; + + var tags = this.tags[tagName]; + + if (!tags) + this.tags[tagName] = tags = []; + + tags.push (context.id); + } + + this.contexts.push (context); + return context; + } + + /** + * Creates a text node context. + **/ + ,textCompile: function (node, tagName) + { + if (!tagName) + var text = node.textContent; + else if (tagName === 't') + var text = _(node.firstChild.textContent); + else + return null; + + return {text: text}; + } + + ,textInstantiate: function (context) + { + if (!context.text) + return null; + + return this.document.createTextNode (context.text); + } + + /** + * Creates a object context. + **/ + ,objectCompile: function (node, tagName) + { + var handler; + var props = {}; + var objectProps = {}; + var childs = []; + var events = {}; + var klass = Vn.customTags[tagName]; + + if (!klass) + return null; + + var context = { + klass: klass, + props: props, + events: events, + objectProps: objectProps, + childs: childs + }; + + var a = node.attributes; + + for (var i = 0; i < a.length; i++) + { + var attribute = a[i].nodeName; + var value = a[i].nodeValue; + + if ((handler = this._getEventHandler (attribute, value))) + { + events[attribute.substr (3)] = handler; + } + else if (!/^(id|property)$/.test (attribute)) + { + this.propCompile (context, klass, props, + node, attribute, value); + } + } + + var childNodes = node.childNodes; + + if (childNodes) + for (var i = 0; i < childNodes.length; i++) + { + var child = childNodes[i]; + var childTagName = null; + + if (child.tagName) + childTagName = child.tagName.toLowerCase (); + + if (childTagName === 'pointer') + { + this.childLinks.push ({ + context: context, + objectId: child.getAttribute ('object') + }); + } + else if (childTagName === 'custom') + { + context.custom = child; + } + else + { + var childContext = this._compileNode (child); + + if (!childContext) + continue; + + var prop = null; + + if (child.getAttribute) + prop = child.getAttribute ('property'); + + if (prop) + objectProps[prop] = childContext.id; + else + childs.push (childContext.id); + } + } + + return context; + } + + ,propCompile: function (context, klass, props, node, attribute, value) + { + var newValue = null; + var propName = attribute.replace (/-./g, this._replaceFunc); + var propInfo = klass.Properties[propName]; + + if (!propInfo) + { + console.warn ('Vn.Builder: Attribute \'%s\' not valid for tag \'%s\'', + attribute, node.tagName); + return; + } + if (!value) + { + console.warn ('Vn.Builder: Attribute \'%s\' empty on tag \'%s\'', + attribute, node.tagName); + return; + } + + switch (propInfo.type) + { + case Boolean: + newValue = (/^(true|1)$/i).test (value); + break; + case Number: + newValue = 0 + new Number (value); + break; + case String: + newValue = this._translateValue (value); + break; + case Function: + newValue = this._getMethod (value); + break; + default: + if (propInfo.enumType) + newValue = propInfo.enumType[value]; + break; + } + + if (newValue !== null && newValue !== undefined) + { + props[propName] = newValue; + } + else if (propInfo.type instanceof Function) + { + this.propLinks.push ({ + context: context, + prop: attribute, + value: value + }); + } + else + console.warn ('Vn.Builder: Attribute \'%s\' invalid for tag \'%s\'', + attribute, node.tagName); + } + + ,objectInstantiate: function (context) + { + if (!context.klass) + return null; + + return new context.klass (context.props); + } + + ,objectLink: function (context, object, objects, res) + { + if (!context.klass) + return null; + + var objectProps = context.objectProps; + for (var prop in objectProps) + object[prop] = objects[objectProps[prop]]; + + var childs = context.childs; + for (var i = 0; i < childs.length; i++) + object.appendChild (objects[childs[i]]); + + var events = context.events; + for (var event in events) + object.on (event, + events[event].bind (this.signalData)); + + if (context.custom) + object.loadXml (res, context.custom); + } + + /** + * Creates a HTML node context. + **/ + ,elementCompile: function (node, tagName) + { + var handler; + var events = {}; + var childs = []; + var htmlNode = this.document.createElement (tagName); + + var a = node.attributes; + + for (var i = 0; i < a.length; i++) + { + var attribute = a[i].nodeName; + var value = a[i].nodeValue; + + if ((handler = this._getEventHandler (attribute, value))) + { + events[attribute.substr (3)] = handler; + } + else if (attribute !== 'id') + htmlNode.setAttribute (attribute, + this._translateValue (value)); + } + + var childNodes = node.childNodes; + + if (childNodes) + for (var i = 0; i < childNodes.length; i++) + { + var childContext = this._compileNode (childNodes[i]); + + if (childContext) + childs.push (childContext.id); + } + + return { + node: htmlNode, + events: events, + childs: childs + }; + } + + ,elementInstantiate: function (context) + { + if (!context.node) + return null; + + return context.node.cloneNode (false); + } + + ,elementLink: function (context, object, objects) + { + if (!context.node) + return null; + + var childs = context.childs; + for (var i = 0; i < childs.length; i++) + { + var child = objects[childs[i]]; + + if (child instanceof Htk.Widget) + object.appendChild (child.getNode ()); + else if (child instanceof Node) + object.appendChild (child); + } + + var events = context.events; + for (var event in events) + object.addEventListener (event, + events[event].bind (this.signalData)); + } + + ,_translateValue: function (value) + { + var chr = value.charAt (0); + + if (chr == '_') + return _(value.substr (1)); + else if (chr == '\\' && value.charAt (1) == '_') + return value.substr (1); + + return value; + } + + ,_getMethod: function (value) + { + if (this.signalData) + var methodName = 'this.signalData.'+ value; + else + var methodName = value; + + var method; + + try { + method = eval (methodName); + } + catch (e) + { + method = null; + } + + if (method == null) + console.warn ('Vn.Builder: Function \'%s\' not found', + value); + + return method; + } + + ,_getEventHandler: function (attribute, value) + { + if (!(/^on-\w+/.test (attribute))) + return null; + + return this._getMethod (value); + } + + ,_replaceFunc: function (token) + { + return token.charAt(1).toUpperCase (); + } +}); + +var BuilderResult = new Class +({ + Extends: Vn.Object + + ,initialize: function (builder, objects) + { + this.builder = builder; + this.objects = objects; + } + + ,getMain: function () + { + return this.builder.getMain (this); + } + + ,$: function (objectId) + { + return this.builder.getById (objectId, this); + } + + ,getById: function (objectId) + { + return this.builder.getById (objectId, this); + } + + ,getByTagName: function (tagName) + { + return this.builder.getByTagName (tagName, this); + } + + ,_destroy: function () + { + var objects = this.objects; + + for (var i = 0; i < objects.length; i++) + if (objects[i].unref) + objects[i].unref (); + + this.parent (); + } +}); + diff --git a/web/js/vn/builder.js b/web/js/vn/builder.js index 9d7b0c5e..95a9f227 100755 --- a/web/js/vn/builder.js +++ b/web/js/vn/builder.js @@ -1,13 +1,16 @@ /** * Creates a object from a XML specification. **/ -Vn.Builder = new Class +Vn.BuilderOld = new Class ({ Extends: Vn.Object ,objectMap: {} ,tags: {} -//+++++++++++++++++++++++++++++++++++++++++++ Deprecated + ,load: function () + { + return this; + } ,loadXml: function (xmlDoc) { @@ -62,7 +65,7 @@ Vn.Builder = new Class { htmlNode = document.importNode (node, false); } - else if ((customNode = this.loadCustomNode (node, null))) + else if ((customNode = this.loadCustomNode (node, tagName, null))) { if (customNode instanceof Htk.Widget) htmlNode = customNode.getNode (); @@ -108,12 +111,11 @@ Vn.Builder = new Class return htmlNode; } - ,loadCustomNode: function (node, parentContext) + ,loadCustomNode: function (node, tagName, parentContext) { - if (!node.tagName) + if (!tagName) return null; - - var tagName = node.tagName.toLowerCase (); + var klass = Vn.customTags[tagName]; if (!klass) @@ -131,6 +133,7 @@ Vn.Builder = new Class ,parent: parentContext ,object: customNode ,klass: klass + ,custom: null }; this.contexts.push (context); @@ -143,8 +146,21 @@ Vn.Builder = new Class if (childs) for (var i = 0; i < childs.length; i++) - this.loadCustomNode (childs[i], context); + { + var childTagName = childs[i].tagName; + if (!childTagName) + continue; + + childTagName = childTagName.toLowerCase (); + + var customChild = this.loadCustomNode ( + childs[i], childTagName, context); + + if (!customChild && childTagName === 'custom') + context.custom = childs[i]; + } + return customNode; } @@ -158,21 +174,18 @@ Vn.Builder = new Class for (var j = 0; j < a.length; j++) this.setAttribute (c, a[j].nodeName, a[j].nodeValue); + if (c.custom) + c.object.loadXml (this, c.custom); + if (c.parent) { var parentProperty = c.node.getAttribute ('property'); - - if (!parentProperty) - parentProperty = c.parent.klass.Child; - + if (parentProperty) this.setProperty (c.parent, parentProperty, c.object); - - if (c.klass.Parent) - this.setProperty (c, c.klass.Parent, c.parent.object); + else + c.parent.object.appendChild (c.object); } - - c.object.loadXml (this, c.node); } } @@ -240,368 +253,7 @@ Vn.Builder = new Class console.warn ('Vn.Builder: Empty attribute \'%s\' on tag \'%s\'', attribute, c.node.tagName); } - -//+++++++++++++++++++++++++++++++++++++++++++ Alpha - - ,compile: function (node, dstDocument) - { - this.contexts = []; - this.contextMap = {}; - this.propLinks = []; - this.childLinks = []; - this.document = dstDocument ? dstDocument : document; - - this.compileRec (node, null); - - for (var i = 0; i < this.propLinks.length; i++) - { - var pl = this.propLinks[i]; - var contextId = this.contextMap[pl.value]; - - if (contextId) - { - pl.context.objectProps[pl.prop] = contextId; - continue; - } - - var object = this.parentBuilder.get (pl.value); - - if (object) - { - pl.context.props[pl.prop] = object; - continue; - } - - console.warn ('Vn.Builder: Referenced unexistent object with id \'%s\'', - pl.value); - } - - delete this.propLinks; - - for (var i = 0; i < this.childLinks.length; i++) - { - var cl = this.childLinks[i]; - var contextId = this.contextMap[pl.value]; - - if (contextId) - pl.context.childs.push (contextId); - else - console.warn ('Vn.Builder: Referenced unexistent object with id \'%s\'', - pl.value); - } - - delete this.childLinks; - } - ,compileRec: function (node) - { - var tagName = null; - - if (node.tagName) - tagName = node.tagName.toLowerCase (); - - var nextId = this.contexts.length; - var context = - createTextTemplate (nextId, node, tagName) - || createObjectTemplate (nextId, node, tagName) - || createHtmlTemplate (nextId, node, tagName); - - this.contexts.push (context); - return context; - } - - ,load: function (thisData) - { - var contexts = this.contexts; - var objects = new Array (contexts.length); - - for (var i = 0; i < contexts.length; i++) - { - var context = contexts[i]; - - if (context.func) - objects[i] = context.func (context); - } - - for (var i = 0; i < contexts.length; i++) - { - var context = contexts[i]; - - if (context.linkFunc) - context.linkFunc (context, objects[i]); - } - } - - /** - * Creates a text node template. - **/ - ,createTextTemplate: function (contextId, node, tagName) - { - if (tagName === 't') - var text = _(node.firstChild.textContent); - else if (!tagName) - var text = node.textContent; - else - return null; - - return { - id: contextId, - text: text, - func: this.createTextInstance - }; - } - - ,createTextInstance: function (context) - { - return this.document.createTextNode (context.text); - } - - /** - * Creates a object template. - **/ - ,createObjectTemplate: function (contextId, node, tagName) - { - var id = null; - var handler; - var props = {}; - var objectProps = {}; - var childs = []; - var events = null; - var klass = Vn.customTags[tagName]; - - if (!klass) - return null; - - var a = node.attributes; - - for (var i = 0; i < a.length; i++) - { - var attribute = a[i].nodeName; - var value = a[i].nodeValue; - - if (attribute === 'id') - { - this.contextMap[value] = contextId; - } - else if ((handler = this.getEventHandler (attribute, value))) - { - if (!events) - events = {}; - - events[attribute.substr (3)] = handler; - } - else if (attribute !== 'property') - { - this.createPropTemplate (context, klass, props, - node, attribute, value); - } - } - - var context = { - id: contextId, - func: this.createObjectInstance, - linkFunc: this.createObjectLink, - klass: klass, - props: props, - events: events, - objectProps: objectProps, - childs: childs - }; - - var childs = node.childNodes; - - if (childs) - for (var i = 0; i < childs.length; i++) - { - var child = childs[i]; - var childTagName = child.tagName.toLowerCase (); - - if (childTagName === 'pointer') - { - this.childLinks.push ({ - context: context, - objectId: child.getAttribute ('object') - }); - } - else if (childTagName === 'custom') - { - context.custom = child.firstElementChild; - } - else - { - var childContext = this.compileRec (child); - var prop = child.getAttribute ('property'); - - if (prop) - objectProps[prop] = childContext.id; - else - childs.push (childContext.id); - } - } - - return context; - } - - ,createPropTemplate: function (context, klass, props, node, attribute, value) - { - var newValue = null; - var propName = attribute.replace (/-./g, this.replaceFunc); - var propInfo = klass.Properties[propName]; - - if (!propInfo) - { - console.warn ('Vn.Builder: Attribute \'%s\' not valid for tag \'%s\'', - attribute, node.tagName); - return; - } - if (!value) - { - console.warn ('Vn.Builder: Attribute \'%s\' empty on tag \'%s\'', - attribute, node.tagName); - return; - } - - switch (propInfo.type) - { - case Boolean: - newValue = (/^(true|1)$/i).test (value); - break; - case Number: - newValue = 0 + new Number (value); - break; - case String: - newValue = this.translateValue (value); - break; - case Function: - newValue = this.getMethod (value); - break; - case Vn.Enum: - newValue = propInfo.enumType[value]; - break; - } - - if (newValue !== null && newValue !== undefined) - { - props[propName] = newValue; - } - else if (propInfo.type instanceof Function) - { - this.propLinks.push ({ - context: context, - prop: attribute, - value: value - }); - } - else - console.warn ('Vn.Builder: Attribute \'%s\' invalid for tag \'%s\'', - attribute, node.tagName); - } - - ,createObjectInstance: function (context) - { - var object = new context.klass (context.props); - - var events = context.events; - - for (var event in events) - object.on (event, - events[event].bind (this.signalData)); - - return object; - } - - ,createObjectLink: function (context, object) - { - var objectProps = context.objectProps; - - if (objectProps) - for (var prop in objectProps) - object[prop] = this.objects[objectProps[prop].id]; - - var childs = context.childs; - - if (childs) - for (var i = 0; i < childs.length; i++) - object.appendChild (childs[i]); - - if (context.custom) - object.loadXml (context.custom); - } - - /** - * Creates a HTML node template. - **/ - ,createHtmlTemplate: function (contextId, node, tagName) - { - var handler; - var events = null; - var childs = []; - var htmlNode = this.document.createElement (tagName); - - var a = node.attributes; - - for (var i = 0; i < a.length; i++) - { - var attribute = a[i].nodeName; - var value = a[i].nodeValue; - - if (attribute === 'id') - { - this.contextMap[value] = contextId; - } - else if ((handler = this.getEventHandler (attribute, value))) - { - if (!events) - events = {}; - - events[attribute.substr (3)] = handler; - } - else - htmlNode.setAttribute (nodeName, - this.translateValue (nodeValue)); - } - - var childNodes = node.childNodes; - - if (childNodes) - for (var i = 0; i < childNodes.length; i++) - { - var childContext = this.compileRec (childNodes[i]); - childs.push (childContext.id); - } - - return { - id: contextId, - func: this.createHtmlInstance, - linkFunc: this.createHtmlLink, - node: htmlNode, - events: events, - childs: childs - }; - } - - ,createHtmlInstance: function (context) - { - var object = new context.node.cloneNode (false); - - var events = context.events; - - for (var event in events) - object.addEventListener (event, - events[event].bind (this.signalData)); - - return object; - } - - ,createHtmlLink: function (context, object) - { - var childs = context.childs; - - if (childs) - for (var i = 0; i < childs.length; i++) - object.appendChild (this.objects[childs[i]]); - } - //+++++++++++++++++++++++++++++++++++++++++++ Utilities ,translateValue: function (value) @@ -663,10 +315,10 @@ Vn.Builder = new Class ,$: function (objectId) { - return this.get (objectId); + return this.getById (objectId); } - ,get: function (objectId) + ,getById: function (objectId) { var object = this.objectMap[objectId]; @@ -678,7 +330,7 @@ Vn.Builder = new Class return null; } - ,getObjects: function (tagName) + ,getByTagName: function (tagName) { if (this.tags[tagName]) return this.tags[tagName]; diff --git a/web/js/vn/main.js b/web/js/vn/main.js index 0a650f28..9dcac47e 100644 --- a/web/js/vn/main.js +++ b/web/js/vn/main.js @@ -16,6 +16,7 @@ Vn.includeLib ('vn', ,'hash-param' ,'node' ,'builder' + ,'builder-new' ,'http-request' ]); diff --git a/web/js/vn/node.js b/web/js/vn/node.js index cb32ce36..e3452883 100755 --- a/web/js/vn/node.js +++ b/web/js/vn/node.js @@ -11,7 +11,7 @@ Vn.Node = } ,remove: function (node) - { + { if (node.parentNode) node.parentNode.removeChild (node); } diff --git a/web/js/vn/object.js b/web/js/vn/object.js index 4fc6290c..f2820a56 100755 --- a/web/js/vn/object.js +++ b/web/js/vn/object.js @@ -8,9 +8,8 @@ Vn.Object = new Class Tag: 'vn-object' ,Properties: {} - ,signals: {} - ,links: {} - ,refCount: 1 + ,_refCount: 1 + ,_signalData: null ,initialize: function (props) { @@ -20,21 +19,28 @@ Vn.Object = new Class ,ref: function () { - this.refCount++; + this._refCount++; return this; } ,unref: function () { - this.refCount--; + this._refCount--; - if (this.refCount === 0) + if (this._refCount === 0) this._destroy (); } - ,loadXml: function (builder, node) + ,loadXml: function (builder, node) {} + ,appendChild: function (child) {} + + ,_signalInit: function () { - return null; + if (!this._signalData) + this._signalData = { + signals: {}, + links: {} + }; } /** @@ -50,12 +56,15 @@ Vn.Object = new Class { console.warn ('Vn.Object: Invalid callback for signal \'%s\'', id); return; - } - - if (!this.signals[id]) - this.signals[id] = []; + } + + this._signalInit (); + var callbacks = this._signalData.signals[id]; + + if (!callbacks) + callbacks = this._signalData.signals[id] = []; - this.signals[id].push + callbacks.push ({ blocked: false ,callback: callback @@ -72,7 +81,10 @@ Vn.Object = new Class **/ ,blockSignal: function (id, callback, block, instance) { - var callbacks = this.signals[id]; + if (!this._signalData) + return; + + var callbacks = this._signalData.signals[id]; if (!callbacks) return; @@ -90,7 +102,10 @@ Vn.Object = new Class **/ ,signalEmit: function (id) { - var callbacks = this.signals[id]; + if (!this._signalData) + return; + + var callbacks = this._signalData.signals[id]; if (!callbacks) return; @@ -115,7 +130,10 @@ Vn.Object = new Class **/ ,disconnect: function (id, callback, instance) { - var callbacks = this.signals[id]; + if (!this._signalData) + return; + + var callbacks = this._signalData.signals[id]; if (!callbacks) return; @@ -133,9 +151,14 @@ Vn.Object = new Class **/ ,disconnectByInstance: function (instance) { - for (var signalId in this.signals) + if (!this._signalData) + return; + + var signals = this._signalData.signals; + + for (var signalId in signals) { - var callbacks = this.signals[signalId]; + var callbacks = signals[signalId]; for (var i = 0; i < callbacks.length; i++) if (callbacks[i].instance == instance) @@ -149,17 +172,22 @@ Vn.Object = new Class **/ ,_destroy: function () { - var links = this.links; + if (!this._signalData) + return; + + var links = this._signalData.links; for (var key in links) links[key].disconnectByInstance (this); - delete this.links; - delete this.signals; + this._signalData = null; } ,link: function (prop, handlers) { + this._signalInit (); + var links = this._signalData.links; + for (var key in prop) { var newObject = prop[key]; @@ -175,13 +203,13 @@ Vn.Object = new Class if (newObject) { - this.links[key] = newObject.ref (); + links[key] = newObject.ref (); for (var signal in handlers) newObject.on (signal, handlers[signal], this); } else if (oldObject) - delete this.links[key]; + delete links[key]; } } });