0
1
Fork 0
This commit is contained in:
Juan Ferrer Toribio 2015-10-14 13:51:43 +02:00
parent fd75840c82
commit b93a39f0a9
18 changed files with 717 additions and 282 deletions

View File

@ -1,8 +1,8 @@
<vn> <vn>
<vn-group> <vn-group>
<vn-param id="address"> <vn-hash-param key="address">
<vn-hash-param key="address"/> <vn-param id="address"/>
</vn-param> </vn-hash-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"/>
<db-model id="model" updatable="true" mode="ON_DEMAND" on-operations-done="onOperationsDone"> <db-model id="model" updatable="true" mode="ON_DEMAND" on-operations-done="onOperationsDone">

View File

@ -1,8 +1,8 @@
<vn> <vn>
<vn-group> <vn-group>
<vn-param id="user"> <vn-hash-param key="user">
<vn-hash-param key="user"/> <vn-param id="user"/>
</vn-param> </vn-hash-param>
<db-form id="user-form"> <db-form id="user-form">
<db-model> <db-model>
SELECT Id_Cliente, Cliente, Telefono, movil SELECT Id_Cliente, Cliente, Telefono, movil

View File

@ -1,8 +1,8 @@
<vn> <vn>
<vn-group> <vn-group>
<vn-param id="agency"> <vn-hash-param key="agency">
<vn-hash-param key="agency"/> <vn-param id="agency"/>
</vn-param> </vn-hash-param>
</vn-group> </vn-group>
<div id="title"> <div id="title">
<h1><t>ByProvince</t></h1> <h1><t>ByProvince</t></h1>

View File

@ -1,7 +1,4 @@
Vn.resource ('forms/ecomerce/catalog/filter-button.xml');
Vn.define (function () {
Vn.Catalog = new Class Vn.Catalog = new Class
({ ({
Extends: Vn.Module Extends: Vn.Module
@ -345,21 +342,12 @@ Vn.Catalog = new Class
if (this.popup) if (this.popup)
this.popup.reset (); this.popup.reset ();
} }
,onSelectClick: function (select, e)
{
console.debug ('Select clicked!');
console.debug (select, e);
if (select.model.status === Db.Model.Status.CLEAN)
select.model.refresh ();
}
}); });
Vn.FilterButton = new Class Vn.Filter = new Class
({ ({
Extends: Htk.Widget Extends: Htk.Widget
,Tag: 'vn-filter-button' ,Tag: 'vn-filter'
,Child: 'model' ,Child: 'model'
,Properties: ,Properties:
{ {
@ -368,7 +356,7 @@ Vn.FilterButton = new Class
type: Db.Model type: Db.Model
,set: function (x) ,set: function (x)
{ {
this._grid.model = x; this._select.model = x;
this._model = x; this._model = x;
} }
,get: function () ,get: function ()
@ -376,17 +364,17 @@ Vn.FilterButton = new Class
return this._model; return this._model;
} }
}, },
text: placeholder:
{ {
type: String type: String
,set: function (x) ,set: function (x)
{ {
Vn.Node.setText (this._button, x);; this._select.placeholder = x;
this._text = x; this._placeholder = x;
} }
,get: function () ,get: function ()
{ {
return this._text; return this._placeholder;
} }
}, },
column: column:
@ -394,41 +382,72 @@ Vn.FilterButton = new Class
type: String type: String
,set: function (x) ,set: function (x)
{ {
this._col.column = x; this._column = x;
} }
,get: function () ,get: function ()
{ {
return this._col.column; return this._column;
} }
}, },
} }
,_columnIndex: 1
,initialize: function (props) ,initialize: function (props)
{ {
this.parent (props); this.parent (props);
this.builderInit ('forms/ecomerce/catalog/filter-button.xml');
this._button = this.createElement ('button'); this.createElement ('div');
this._button.className = 'vn-filter-button thin'; this.node.className = 'vn-filter';
this._button.addEventListener ('click', this._onButtonClick.bind (this));
this._grid = new Htk.Grid (); this._select = new Htk.Select ();
this._grid.showHeader = false; this._select.on ('mousedown', this._onClick.bind (this));
this._select.on ('changed', this._onChange.bind (this));
this.node.appendChild (this._select.getNode ());
this._col = new Htk.ColumnText (); this._ul = document.createElement ('ul');
this._grid.appendColumn (this._col); this.node.appendChild (this._ul);
} }
,_onButtonClick: function () ,_onClick: function ()
{ {
if (!this._model) if (this._model && this._model.status === Db.Model.Status.CLEAN)
return; this._model.refresh ();
}
this._model.refresh ();
var popup = new Htk.Popup (); ,_onCloseClick: function (li)
popup.setChild (this._grid); {
popup.show (this._button); Vn.Node.remove (li);
}
,_onChange: function ()
{
if (this._select.value === null
|| this._select.value === undefined)
return;
var li = document.createElement ('li');
this._ul.appendChild (li);
var button = document.createElement ('button');
button.addEventListener ('click',
this._onCloseClick.bind (this, li));
li.appendChild (button);
var img = document.createElement ('img');
img.src = 'image/close.svg';
button.appendChild (img);
var label = this._select.getByIndex (this._columnIndex);
var text = document.createTextNode (label);
li.appendChild (text);
setTimeout (this._onTimeout.bind (this));
}
,_onTimeout: function ()
{
this._select.value = null;
} }
}); });
@ -459,4 +478,3 @@ Vn.ColumnItem = new Class
} }
}); });
});

View File

@ -1,11 +0,0 @@
<vn>
<button
id="button"
class="vn-filter-button thin"
on-click="_onButtonClick"/>
<htk-repeater id="popup" form-id="form">
<div>
<htk-text form="form" id="cell"/>
</div>
</htk-repeater>
</vn>

View File

@ -59,34 +59,53 @@
/* Right panel */ /* Right panel */
.right-panel > .body
{
text-align: center;
padding: 1em;
overflow: auto;
}
.right-panel
{
position: absolute;
top: 3.9em;
bottom: 0;
right: 0;
width: 17em;
background-color: white;
box-shadow: 0 0.2em 0.2em #AAA;
}
.right-panel select
{
margin: .8em auto;
width: 12em;
/* color: #333;
background-color: #EEE;
border: 0;*/
}
option.placeholder option.placeholder
{ {
color: #999; color: #999;
} }
.right-panel .vn-filter ul
{ {
position: absolute; margin: 0;
z-index: 20; list-style-type: none;
top: 3.9em; text-align: left;
bottom: 0; color: #666;
right: 0; padding-left: 2em;
width: 15em;
background-color: white;
box-shadow: 0 0.2em 0.2em #AAA;
text-align: center;
padding: 1em;
overflow: auto;
} }
.right-panel select, .vn-filter li
.right-panel button
{ {
margin: 1em auto; line-height: 2em;
width: 12em; }
/* color: #333; .vn-filter li > button
background-color: #EEE; {
border: 0;*/ vertical-align: middle;
text-align: center;
padding: .2em;
margin-right: .2em;
} }
button.basket button.basket
@ -314,6 +333,7 @@ td.third-category
{ {
top: 0; top: 0;
right: -17em; right: -17em;
z-index: 20;
} }
.right-panel.show .right-panel.show
{ {

View File

@ -1,21 +1,48 @@
<vn> <vn>
<vn-group> <vn-group>
<vn-param id="realm" on-changed="onTypeChange"> <!--
<vn-hash-param key="realm"/> <sql-filter-item type="EQUAL" id="op-realm">
</vn-param> <sql-field name="reino_id" target="t"/>
<vn-param id="type" on-changed="onTypeChange"> <sql-set param="realm"/>
<vn-hash-param key="type"/> </sql-filter-item>
</vn-param> <sql-filter-item type="EQUAL" id="op-type">
<sql-field name="tipo_id"/>
<sql-set param="type"/>
</sql-filter-item>
<sql-filter-item type="EQUAL" id="op-color">
<sql-field name="Color"/>
<sql-set param="color"/>
</sql-filter-item>
<sql-filter-item type="EQUAL" id="op-origin">
<sql-field name="id_origen"/>
<sql-set param="origin"/>
</sql-filter-item>
<sql-filter-item type="EQUAL" id="op-category">
<sql-field name="Categoria"/>
<sql-set param="category"/>
</sql-filter-item>
-->
</vn-group>
<vn-group>
<vn-hash-param key="realm">
<vn-param id="realm" on-changed="onTypeChange"/>
</vn-hash-param>
<vn-hash-param key="type">
<vn-param id="type" on-changed="onTypeChange"/>
</vn-hash-param>
<vn-param id="search"/> <vn-param id="search"/>
<sql-filter type="AND" id="filter"> <sql-filter type="AND" id="filter">
<sql-filter-item type="EQUAL" id="sql-type"> <sql-filter-item type="LIKE" id="op-name">
<sql-field name="tipo_id"/>
<sql-value param="type"/>
</sql-filter-item>
<sql-filter-item type="LIKE">
<sql-field name="Article"/> <sql-field name="Article"/>
<sql-search-tags param="search"/> <sql-search-tags param="search"/>
</sql-filter-item> </sql-filter-item>
<!--
<pointer object="op-realm"/>
<pointer object="op-type"/>
<pointer object="op-color"/>
<pointer object="op-origin"/>
<pointer object="op-category"/>
-->
</sql-filter> </sql-filter>
<db-query id="basket-lines"> <db-query id="basket-lines">
SELECT item_id, warehouse_id, SUM(amount) amount SELECT item_id, warehouse_id, SUM(amount) amount
@ -29,7 +56,7 @@
SELECT Id_Article item_id FROM vn2008.Articles SELECT Id_Article item_id FROM vn2008.Articles
WHERE #filter; WHERE #filter;
CALL bionic_calc (); CALL bionic_calc ();
SELECT a.Id_Article, t.available, t.price, p.producer, 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 a.Foto, a.Article, a.Categoria, a.Medida, a.Tallos, a.Color, o.Abreviatura
FROM tmp.bionic_item t FROM tmp.bionic_item t
JOIN vn2008.Articles a ON a.Id_Article = t.item_id JOIN vn2008.Articles a ON a.Id_Article = t.item_id
@ -100,9 +127,16 @@
show-full="true" show-full="true"
full-dir="900x900" full-dir="900x900"
editable="true"/> editable="true"/>
<vn-column-item title="_Name" column="Article" renderer="nameRenderer"/> <vn-column-item
<htk-column-text title="_Cat" renderer="featuresRender"/> title="_Name"
<htk-column-spin title="_Aval" column="available"/> column="Article"
renderer="nameRenderer"/>
<htk-column-text
title="_Cat"
renderer="featuresRender"/>
<htk-column-spin
title="_Aval"
column="available"/>
<htk-column-text <htk-column-text
title="_Price" title="_Price"
column="price" column="price"
@ -162,109 +196,129 @@
</div> </div>
</template> </template>
</htk-repeater> </htk-repeater>
<div id="realm-popup">
<htk-grid show-header="false">
<db-model property="model" id="filter-model">
SELECT id, reino, color FROM vn2008.reinos
WHERE display != FALSE ORDER BY reino
</db-model>
<htk-column-text column="reino"/>
</htk-grid>
</div>
<div id="right-panel" class="right-panel" on-click="onRightPanelClick"> <div id="right-panel" class="right-panel" on-click="onRightPanelClick">
<select> <div class="body">
<option value="" disabled="true" selected="true"> <select>
<t>Order by</t> <option value="" disabled="true" selected="true">
</option> <t>Order by</t>
<option value="Article"> </option>
<t>Item</t> <option value="Article">
</option> <t>Item</t>
<option value="price"> </option>
<t>Price</t> <option value="price">
</option> <t>Price</t>
<option value="available"> </option>
<t>Available</t> <option value="available">
</option> <t>Available</t>
<option value="Color"> </option>
<t>Color</t> <option value="Color">
</option> <t>Color</t>
<option value="producer"> </option>
<t>Producer</t> <option value="producer">
</option> <t>Producer</t>
<option value="Medida"> </option>
<t>Size</t> <option value="Medida">
</option> <t>Size</t>
<option value="Categoria"> </option>
<t>Category</t> <option value="Categoria">
</option> <t>Category</t>
<option value="Abreviatura"> </option>
<t>Origin</t> <option value="Abreviatura">
</option> <t>Origin</t>
</select> </option>
<htk-combo placeholder="_Realm" on-click="onSelectClick"> </select>
<db-model property="model" result-index="1" auto-load="false"> <vn-filter placeholder="_Realm">
SELECT SLEEP(2); <db-model auto-load="false" result-index="1">
CALL item_available ();
SELECT DISTINCT r.id, r.reino
FROM vn2008.reinos r
JOIN vn2008.Tipos t ON t.reino_id = r.id
JOIN vn2008.Articles a ON a.tipo_id = t.tipo_id
JOIN tmp.item_available i ON i.item_id = a.Id_Article
WHERE /*#filter
AND*/ r.display
ORDER BY r.reino
</db-model>
</vn-filter>
<vn-filter placeholder="_Subtype">
<db-model auto-load="false" result-index="1">
CALL item_available ();
SELECT DISTINCT t.tipo_id, LEFT(t.Tipo, 18) type
FROM vn2008.Tipos t
JOIN vn2008.Articles a ON a.tipo_id = t.tipo_id
JOIN tmp.item_available i ON i.item_id = a.Id_Article
/*WHERE #filter*/
ORDER BY t.Tipo
</db-model>
</vn-filter>
<vn-filter placeholder="_Color">
<db-model auto-load="false" result-index="1">
CALL item_available ();
SELECT DISTINCT c.Id_Tinta, c.name
FROM vn2008.Tintas c
JOIN vn2008.Articles a ON a.Color = c.Id_Tinta
JOIN tmp.item_available i ON i.item_id = a.Id_Article
/*WHERE #filter*/
ORDER BY c.name
</db-model>
</vn-filter>
<vn-filter placeholder="_Origin">
<db-model auto-load="false" result-index="1">
CALL item_available ();
SELECT DISTINCT o.id, o.Origen, o.Abreviatura
FROM vn2008.Origen o
JOIN vn2008.Articles a ON a.id_origen = o.id
JOIN tmp.item_available i ON i.item_id = a.Id_Article
/*WHERE #filter*/
ORDER BY o.Origen
</db-model>
</vn-filter>
<vn-filter placeholder="_Category">
<db-model auto-load="false" result-index="1">
CALL item_available ();
SELECT DISTINCT a.Categoria, a.Categoria category
FROM vn2008.Articles a
JOIN tmp.item_available i ON i.item_id = a.Id_Article
/*WHERE #filter*/
ORDER BY a.Categoria
</db-model>
</vn-filter>
</div>
<!--
<htk-repeater
model="realms-model"
form-id="realm-form"
renderer="realmRenderer"
class="realms-box">
<db-model id="realms-model" on-status-changed="onTypeChange">
SELECT id, reino, color FROM vn2008.reinos SELECT id, reino, color FROM vn2008.reinos
WHERE display != FALSE ORDER BY reino WHERE display != FALSE ORDER BY reino
</db-model> </db-model>
</htk-combo> <template>
<vn-filter-button text="_Subtype" column="Tipo"> <a id="link">
<db-model> <img id="image"/>
CALL type_list (1) </a>
</template>
</htk-repeater>
<htk-repeater
model="types-model"
form-id="type-form"
renderer="typeRenderer"
empty-message="_SelectFamily"
class="types-box">
<db-model id="types-model" on-status-changed="refreshTitle">
CALL type_list (#realm)
<sql-batch property="batch">
<item name="realm" param="realm"/>
</sql-batch>
</db-model> </db-model>
</vn-filter-button> <template>
<vn-filter-button text="_Color" column="Color"> <a id="link">
<db-model> <htk-text form="type-form" column="Tipo"/>
SELECT Id_Color, Color </a>
FROM vn2008.Colores ORDER BY Color </template>
</db-model> </htk-repeater>
</vn-filter-button> -->
<vn-filter-button text="_Origin" column="Origen">
<db-model>
SELECT id, Abreviatura, Origen
FROM vn2008.Origen ORDER BY Origen
</db-model>
</vn-filter-button>
<vn-filter-button text="_Category" column="category">
<db-model>
SELECT 'A1' category UNION SELECT 'A2' UNION SELECT 'B1'
</db-model>
</vn-filter-button>
<div style="display: none">
<htk-repeater
model="realms-model"
form-id="realm-form"
renderer="realmRenderer"
class="realms-box">
<db-model id="realms-model" on-status-changed="onTypeChange">
SELECT id, reino, color FROM vn2008.reinos
WHERE display != FALSE ORDER BY reino
</db-model>
<template>
<a id="link">
<img id="image"/>
</a>
</template>
</htk-repeater>
<htk-repeater
model="types-model"
form-id="type-form"
renderer="typeRenderer"
empty-message="_SelectFamily"
class="types-box">
<db-model id="types-model" on-status-changed="refreshTitle">
CALL type_list (#realm)
<sql-batch property="batch">
<item name="realm" param="realm"/>
</sql-batch>
</db-model>
<template>
<a id="link">
<htk-text form="type-form" column="Tipo"/>
</a>
</template>
</htk-repeater>
</div>
</div> </div>
<div id="lots-popup" class="lots-popup"> <div id="lots-popup" class="lots-popup">
<htk-grid class="lots-grid" model="item-lots" show-header="false"> <htk-grid class="lots-grid" model="item-lots" show-header="false">

View File

@ -65,21 +65,17 @@ Vn.Checkout = new Class
return; return;
if (this.$('order-form').numRows > 0) if (this.$('order-form').numRows > 0)
{
Htk.Toast.showMessage (_('OrderUpdated')); Htk.Toast.showMessage (_('OrderUpdated'));
window.history.back();
}
else else
{
Htk.Toast.showMessage (_('OrderStarted')); Htk.Toast.showMessage (_('OrderStarted'));
this.hash.set ({'form': 'ecomerce/catalog'});
} this.hash.set ({'form': 'ecomerce/catalog'});
} }
,onCancelClick: function () ,onCancelClick: function ()
{ {
if (this.$('order-form').numRows > 0) if (this.$('order-form').numRows > 0)
this.hash.set ({'form': 'ecomerce/basket'}); window.history.back();
else else
this.hash.set ({'form': 'ecomerce/orders'}); this.hash.set ({'form': 'ecomerce/orders'});
} }

View File

@ -1,8 +1,8 @@
<vn> <vn>
<vn-group> <vn-group>
<vn-param id="ticket-id"> <vn-hash-param key="ticket">
<vn-hash-param key="ticket"/> <vn-param id="ticket-id"/>
</vn-param> </vn-hash-param>
<db-form id="ticket"> <db-form id="ticket">
<db-model id="ticket-data"> <db-model id="ticket-data">
SELECT t.id, date, a.Agencia, note, p.name province, SELECT t.id, date, a.Agencia, note, p.name province,

View File

@ -1,8 +1,8 @@
<vn> <vn>
<vn-group> <vn-group>
<vn-param id="new-id"> <vn-hash-param key="new">
<vn-hash-param key="new"/> <vn-param id="new-id"/>
</vn-param> </vn-hash-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"/>
<db-model id="model" updatable="true" on-operations-done="onOperationsDone"> <db-model id="model" updatable="true" on-operations-done="onOperationsDone">

View File

@ -123,6 +123,8 @@ if (file_exists ($basePath))
require ($basePath .'/html.php'); require ($basePath .'/html.php');
} }
else
header ('Location: ./');
myExitHandler (); myExitHandler ();

View File

@ -76,7 +76,7 @@ Htk.Select = new Class
,set: function (x) ,set: function (x)
{ {
this._placeholder = x; this._placeholder = x;
if (this._placeholderNode) if (this._placeholderNode)
Vn.Node.setText (this._placeholderNode, x); Vn.Node.setText (this._placeholderNode, x);
} }
@ -98,7 +98,8 @@ Htk.Select = new Class
{ {
this.parent (props); this.parent (props);
this.createElement ('select'); this.createElement ('select');
this.node.addEventListener ('change', this.changed.bind (this)); this.node.addEventListener ('change', this._onChange.bind (this));
this._addPlaceholder (this._placeholder);
} }
,on: function (id, callback, instance) ,on: function (id, callback, instance)
@ -106,6 +107,8 @@ Htk.Select = new Class
switch (id) switch (id)
{ {
case 'click': case 'click':
case 'mousedown':
case 'focusout':
this.node.addEventListener (id, this.node.addEventListener (id,
callback.bind (instance, this)); callback.bind (instance, this));
break; break;
@ -116,11 +119,16 @@ Htk.Select = new Class
,setRow: function (row) ,setRow: function (row)
{ {
if (row != -1)
this.node.selectedIndex = row + 1;
else
this.node.selectedIndex = 0;
this._row = row; this._row = row;
this.iterChanged (); this.iterChanged ();
} }
,changed: function (event) ,_onChange: function (event)
{ {
var value; var value;
var row = this.node.selectedIndex - 1; var row = this.node.selectedIndex - 1;
@ -130,8 +138,8 @@ Htk.Select = new Class
else else
value = null; value = null;
this.valueChanged (value);
this.setRow (row); this.setRow (row);
this.valueChanged (value);
} }
,addOption: function (value, text) ,addOption: function (value, text)
@ -145,23 +153,21 @@ Htk.Select = new Class
this.node.appendChild (option); this.node.appendChild (option);
} }
,addPlaceholder: function (text) ,_addPlaceholder: function (text)
{ {
var option = document.createElement ('option'); var option = document.createElement ('option');
option.className = 'htk-option';
option.disabled = true; option.disabled = true;
option.selected = true; option.selected = true;
option.value = null; option.value = null;
Vn.Node.setText (option, text ? text : '');
if (text)
option.appendChild (document.createTextNode (text));
this.node.appendChild (option); this.node.appendChild (option);
this._placeholderNode = option; this._placeholderNode = option;
} }
,onModelChange: function () ,onModelChange: function ()
{ {
var placeholder = ''; var placeholder = null;
var model = this._model; var model = this._model;
this.signalEmit ('status-changed'); this.signalEmit ('status-changed');
@ -169,26 +175,49 @@ Htk.Select = new Class
switch (model.status) switch (model.status)
{ {
case Db.Model.Status.READY:
{
var data = model.data;
this.addPlaceholder (this._placeholder);
for (var i = 0; i < data.length; i++)
this.addOption (data[i][this.showColumnIndex], data[i][1]);
this.selectOption ();
break;
}
case Db.Model.Status.ERROR: case Db.Model.Status.ERROR:
placeholder = 'Error'; placeholder = _('Error');
break; break;
case Db.Model.Status.LOADING: case Db.Model.Status.LOADING:
placeholder = 'Loading...'; placeholder = _('Loading...');
break;
default: default:
this.addPlaceholder (_(placeholder)); placeholder = this._placeholder;
this.setRow (-1);
} }
if (placeholder)
this._addPlaceholder (placeholder);
if (model.ready)
{
var data = model.data;
for (var i = 0; i < data.length; i++)
this.addOption (data[i][this.showColumnIndex], data[i][1]);
this.selectOption ();
this._onTimeout ();
}
else
this.setRow (-1);
}
,_onTimeout: function ()
{
if (this._blockMouseDown || !navigator.userAgent.match (/WebKit/))
return;
this._blockMouseDown = true;
this.node.blur();
var e = document.createEvent('MouseEvents');
e.initMouseEvent ('mousedown',
true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
this.node.dispatchEvent(e);
this._blockMouseDown = false;
this.node.focus ();
} }
,setEditable: function (editable) ,setEditable: function (editable)
@ -200,13 +229,8 @@ Htk.Select = new Class
{ {
var row; var row;
if (this._model && this._model.status == Db.Model.Status.READY) if (this._model && this._model.ready)
{
row = this._model.searchByIndex (this.valueColumnIndex, this._value); row = this._model.searchByIndex (this.valueColumnIndex, this._value);
if (row != -1)
this.node.selectedIndex = row + 1;
}
else else
row = -1; row = -1;

View File

@ -103,6 +103,13 @@
margin: auto; margin: auto;
} }
/* Combo */
.htk-option
{
/* color: #999;*/
}
/* Button */ /* Button */
.htk-button > span .htk-button > span

View File

@ -8,10 +8,11 @@ Sql.Operation = new Class ().extend
({ ({
Type: Type:
{ {
EQUAL : 0 EQUAL : 0
,LIKE : 1 ,LIKE : 1
,AND : 2 ,AND : 2
,OR : 3 ,OR : 3
,REGEXP : 4
} }
,Operators: ,Operators:
[ [
@ -19,6 +20,7 @@ Sql.Operation = new Class ().extend
,'LIKE' ,'LIKE'
,'AND' ,'AND'
,'OR' ,'OR'
,'REGEXP'
] ]
}); });

View File

@ -10,7 +10,7 @@ Sql.SearchTags = new Class
{ {
if (typeof this._value == 'string') if (typeof this._value == 'string')
{ {
var value = this._value.replace (/^| +|$/g, '%'); var value = this._value.replace (/^|\s+|$/g, '%');
return "'" + value.replace (this.regexp, this.replaceFunc) + "'"; return "'" + value.replace (this.regexp, this.replaceFunc) + "'";
} }
else else

View File

@ -6,6 +6,8 @@ Vn.Builder = new Class
Extends: Vn.Object Extends: Vn.Object
,objectMap: {} ,objectMap: {}
,tags: {} ,tags: {}
//+++++++++++++++++++++++++++++++++++++++++++ Deprecated
,loadXml: function (xmlDoc) ,loadXml: function (xmlDoc)
{ {
@ -145,47 +147,6 @@ Vn.Builder = new Class
return customNode; return customNode;
} }
,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;
}
,replaceFunc: function (token)
{
return token.charAt(1).toUpperCase ();
}
,resolveProperties: function () ,resolveProperties: function ()
{ {
@ -280,6 +241,365 @@ Vn.Builder = new Class
attribute, c.node.tagName); attribute, c.node.tagName);
} }
//+++++++++++++++++++++++++++++++++++++++++++ Alpha
,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];
objects[i] = context.func (context.template);
}
var links = this.links;
for (var i = 0; i < links.length; i++)
{
var link = links[i];
objects[link.contextId][link.propName] = objects[link.valueContext];
}
}
,compile: function (node, dstDocument)
{
this.contexts = [];
this.contextMap = {};
this.pointers = [];
this.links = [];
this.document = dstDocument ? dstDocument : document;
this.compileRec (node, null);
for (var i = 0; i < this.pointers.length; i++)
{
var pointerId = this.pointers[i].template;
var refContext = this.contextMap[pointerId];
}
}
,compileRec: function (node, parentContext)
{
var tagName = null;
if (node.tagName)
tagName = node.tagName.toLowerCase ();
var context = {
node: node
,parent: parentContext
,template: template
,id: this.contexts.length
,func: null
};
this.contexts.push (context);
var template =
createTextTemplate (context, node, tagName)
|| createPointerTemplate (context, node, tagName)
|| createObjectTemplate (context, node, tagName)
|| createHtmlTemplate (context, node, tagName);
var id = node.getAttribute ('id');
if (id)
this.contextMap[id] = context;
if (parentContext)
{
var parentProperty = node.getAttribute ('property');
if (!parentProperty && parentContext.template.klass)
parentProperty = parentContext.template.klass.Child;
if (parentProperty)
{
this.links.push ({
contextId: context.id,
propName: propName,
valueContext: valueContext.id
});
}
this.registerLink (parentContext, parentProperty, context);
if (klass.Parent)
this.registerLink (context, klass.Parent, parentContext);
}
var childs = node.childNodes;
if (childs)
for (var i = 0; i < childs.length; i++)
this.compileRec (childs[i], context);
return context;
}
/**
* Creates a text node template.
**/
,createTextTemplate: function (context, node, tagName)
{
if (tagName === 't')
var text = _(node.firstChild.textContent);
else if (!tagName)
var text = node.textContent;
else
return null;
return
context.func = createTextInstance;
return text;
}
,createTextInstance: function (template)
{
return this.document.createTextNode (template);
}
/**
* Creates a object pointer template.
**/
,createPointerTemplate: function (context, node, tagName)
{
if (tagName !== 'pointer')
return null;
this.pointers.push (context);
return node.getAttribute ('object');
}
,createPointerInstance: function (template)
{
return this.objectMap[template];
}
/**
* Creates a object template.
**/
,createObjectTemplate: function (context, node, tagName)
{
var id = null;
var handler;
var props = {};
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')
{
id = value;
}
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);
}
}
context.func = createObjectInstance;
return {
klass: klass,
events: events,
id: id
};
}
,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.registerLink (context, attribute, value);
}
else
console.warn ('Vn.Builder: Attribute \'%s\' invalid for tag \'%s\'',
attribute, node.tagName);
}
,createObjectInstance: function (template)
{
var object = new template.klass (template.props);
var events = template.events;
for (var event in events)
object.on (event,
events[event].bind (this.signalData));
if (template.id)
this.objectMap[id] = object;
return object;
}
/**
* Creates a HTML node template.
**/
,createHtmlTemplate: function (context, node, tagName)
{
var id = null;
var handler;
var events = null;
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')
{
id = value;
}
else if ((handler = this.getEventHandler (attribute, value)))
{
if (!events)
events = {};
events[attribute.substr (3)] = handler;
}
else
htmlNode.setAttribute (nodeName,
this.translateValue (nodeValue));
}
context.func = createHtmlInstance;
return {
node: htmlNode,
events: events,
id: id
};
}
,createHtmlInstance: function (template)
{
var node = new template.node.cloneNode (false);
var events = template.events;
for (var event in events)
node.addEventListener (event,
events[event].bind (this.signalData));
if (template.id)
this.objectMap[id] = node;
return node;
}
//+++++++++++++++++++++++++++++++++++++++++++ Utilities
,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 ();
}
,setParent: function (parentBuilder) ,setParent: function (parentBuilder)
{ {
this.parentBuilder = parentBuilder; this.parentBuilder = parentBuilder;

View File

@ -3,7 +3,7 @@ Vn.HashParam = new Class
({ ({
Extends: Vn.Object Extends: Vn.Object
,Tag: 'vn-hash-param' ,Tag: 'vn-hash-param'
,Parent: 'param' ,Child: 'param'
,Properties: ,Properties:
{ {
param: param:

View File

@ -185,3 +185,6 @@ Vn.Object = new Class
} }
} }
}); });
Vn.Enum = function () {};