This commit is contained in:
Juan Ferrer Toribio 2017-04-21 12:53:15 +02:00
parent 234566b6af
commit adb651fe69
33 changed files with 421 additions and 436 deletions

View File

@ -36,16 +36,22 @@ Hedera.Catalog = new Class
,activate: function () ,activate: function ()
{ {
this.$('items').setInfo ('a', 'Articles', 'vn2008', ['item_id']);
this.$('lot').assign ({filter: this.$('filter')});
this.$('lot').setProperties ({
type: Vn.LotQuery.Type.EXCLUDE,
fields: []
});
document.body.appendChild (this.$('right-panel')); document.body.appendChild (this.$('right-panel'));
this.$('items').setInfo ('a', 'Articles', 'vn2008', ['item_id']);
if (localStorage.getItem ('hederaView')) if (localStorage.getItem ('hederaView'))
this.setView (parseInt (localStorage.getItem ('hederaView'))); this.setView (parseInt (localStorage.getItem ('hederaView')));
else else
this.setView (View.GRID); this.setView (View.GRID);
this.hash.on ('change', this.onHashChange, this); this.onRealmChange ();
this.refreshTitle ();
} }
,deactivate: function () ,deactivate: function ()
@ -53,7 +59,6 @@ Hedera.Catalog = new Class
this.hideMenu (); this.hideMenu ();
this.gui.$('top-bar').style.backgroundColor = ''; this.gui.$('top-bar').style.backgroundColor = '';
Vn.Node.remove (this.$('right-panel')); Vn.Node.remove (this.$('right-panel'));
this.hash.disconnect ('change', this.onHashChange, this);
} }
,setView: function (view) ,setView: function (view)
@ -96,14 +101,6 @@ Hedera.Catalog = new Class
Vn.Node.setText (this.$('method'), _('Warehouse')); Vn.Node.setText (this.$('method'), _('Warehouse'));
} }
,onItemsChange: function (model, status)
{
if (status !== Db.Model.Status.CLEAN)
this.$('order').style.display = 'block';
else
this.$('order').style.display = 'none';
}
,onOrderChange: function (e) ,onOrderChange: function (e)
{ {
var value = e.target.value; var value = e.target.value;
@ -119,7 +116,7 @@ Hedera.Catalog = new Class
,shouldRefresh: function () ,shouldRefresh: function ()
{ {
var params = this.hash.params; var params = this.$('lot').params;
if (params.search) if (params.search)
return true; return true;
@ -135,13 +132,19 @@ Hedera.Catalog = new Class
return refresh; return refresh;
} }
,onHashChange: function () ,onLotChange: function ()
{ {
if (!this.shouldRefresh ()) if (this.shouldRefresh ())
return; {
this.$('items').refresh ();
this.$('items').refresh (); this.hideMenu ();
this.hideMenu (); this.$('order').style.display = 'block';
}
else
{
this.$('items').clean ();
this.$('order').style.display = 'none';
}
} }
,realmRenderer: function (builder, form) ,realmRenderer: function (builder, form)
@ -158,8 +161,10 @@ Hedera.Catalog = new Class
img.alt = img.title; img.alt = img.title;
} }
,onRealmChange: function (param, newValue) ,onRealmChange: function ()
{ {
var newValue = this.hash.get ('realm');
if (newValue) if (newValue)
{ {
this.$('filters').style.display = 'block'; this.$('filters').style.display = 'block';
@ -170,26 +175,14 @@ Hedera.Catalog = new Class
this.$('filters').style.display = 'none'; this.$('filters').style.display = 'none';
this.$('realm-msg').style.display = 'block'; this.$('realm-msg').style.display = 'block';
} }
this.refreshTitleColor ();
this.refreshFilter (newValue, undefined);
}
,onTypeChange: function (param, newValue) this.refreshTitleColor ();
{
this.refreshTitle ();
this.refreshFilter (undefined, newValue);
}
,refreshFilter: function (realm, type)
{
this.hash.params = { this.hash.params = {
form: this.hash.get ('form'), form: this.hash.get ('form'),
realm: realm, realm: newValue,
type: type
}; };
} }
,refreshTitleColor: function () ,refreshTitleColor: function ()
{ {
var realms = this.$('realms'); var realms = this.$('realms');
@ -373,7 +366,7 @@ Vn.Filter = new Class
{ {
this._model = x; this._model = x;
this._select.model = x; this._select.model = x;
this._refreshLot (); this._refreshModelLot ();
} }
,get: function () ,get: function ()
{ {
@ -400,7 +393,7 @@ Vn.Filter = new Class
{ {
this._filter = x; this._filter = x;
this._modelLot.assign ({filter: x}); this._modelLot.assign ({filter: x});
this._refreshLot (); this._refreshModelLot ();
} }
,get: function () ,get: function ()
{ {
@ -426,7 +419,7 @@ Vn.Filter = new Class
,set: function (x) ,set: function (x)
{ {
this._modelLot.fields = [x]; this._modelLot.fields = [x];
this._onLotChange (); this._setName (x);
} }
,get: function () ,get: function ()
{ {
@ -458,15 +451,10 @@ Vn.Filter = new Class
this.parent (props); this.parent (props);
} }
,_refreshLot: function () ,_refreshModelLot: function ()
{ {
if (!this._model) if (this._model && this._filter)
return;
if (this._filter)
this._model.lot = this._modelLot; this._model.lot = this._modelLot;
else
this._model.lot = null;
} }
,_onMouseDown: function () ,_onMouseDown: function ()
@ -475,10 +463,10 @@ Vn.Filter = new Class
this._model.refresh (); this._model.refresh ();
} }
,_onCloseClick: function () ,_onUnselectClick: function ()
{ {
this._removeSelectionNode (); this._removeSelectionNode ();
this._changeValue (undefined); this.valueChanged (undefined);
} }
,_removeSelectionNode: function () ,_removeSelectionNode: function ()
@ -496,8 +484,10 @@ Vn.Filter = new Class
if (this._select.value === null if (this._select.value === null
|| this._select.value === undefined) || this._select.value === undefined)
return; return;
this._realSetValue (this._select.value); var value = this._select.value;
this._selectValue (value);
this.valueChanged (value);
} }
,_onReady: function () ,_onReady: function ()
@ -506,11 +496,6 @@ Vn.Filter = new Class
this._refreshLabel (); this._refreshLabel ();
} }
,_changeValue: function (newValue)
{
this.value = newValue;
}
,_onTimeout: function () ,_onTimeout: function ()
{ {
this._select.value = null; this._select.value = null;
@ -518,11 +503,10 @@ Vn.Filter = new Class
,putValue: function (value) ,putValue: function (value)
{ {
this._onMouseDown (); this._selectValue (value);
this._realSetValue (value);
} }
,_realSetValue: function (value) ,_selectValue: function (value)
{ {
this._removeSelectionNode (); this._removeSelectionNode ();
@ -534,7 +518,7 @@ Vn.Filter = new Class
var button = this.createElement ('button'); var button = this.createElement ('button');
button.addEventListener ('click', button.addEventListener ('click',
this._onCloseClick.bind (this, li)); this._onUnselectClick.bind (this, li));
li.appendChild (button); li.appendChild (button);
var icon = new Htk.Icon ({ var icon = new Htk.Icon ({
@ -548,7 +532,6 @@ Vn.Filter = new Class
setTimeout (this._onTimeout.bind (this)); setTimeout (this._onTimeout.bind (this));
this._changeValue (value);
this._refreshLabel (); this._refreshLabel ();
} }
@ -559,7 +542,7 @@ Vn.Filter = new Class
var row = -1; var row = -1;
if (this._model.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) if (row != -1)

View File

@ -1,12 +1,13 @@
<vn> <vn>
<vn-group> <vn-group>
<vn-lot-query
id="lot"
source="hash"
on-change="onLotChange"/>
<vn-lot id="card-lot"/> <vn-lot id="card-lot"/>
<vn-param lot="hash" name="realm" on-changed="onRealmChange"/> <vn-param lot="hash" name="realm" on-changed="onRealmChange"/>
<vn-param lot="hash" name="type" on-changed="onTypeChange"/> <vn-param lot="hash" name="type" on-changed="refreshTitle"/>
<sql-filter type="AND" id="filter"> <sql-filter type="AND" id="filter">
<sql-filter-item type="EQUAL"
field="reino_id" target="t"
param="realm"/>
<sql-filter-item type="EQUAL" <sql-filter-item type="EQUAL"
field="tipo_id" target="a" field="tipo_id" target="a"
param="type"/> param="type"/>
@ -34,9 +35,8 @@
<db-model <db-model
id="items" id="items"
result-index="2" result-index="2"
lot="hash" lot="lot"
auto-load="false" auto-load="false">
on-status-changed="onItemsChange">
CREATE TEMPORARY TABLE tmp.bionic_calc CREATE TEMPORARY TABLE tmp.bionic_calc
(INDEX (item_id)) (INDEX (item_id))
ENGINE = MEMORY ENGINE = MEMORY

View File

@ -1,6 +1,6 @@
var Model = require ('./model'); var Model = require ('./model');
var SimpleIterator = require ('./simple-iterator'); var Iterator = require ('./iterator');
/** /**
* Interface for handle foreach operations on the model. * Interface for handle foreach operations on the model.
@ -25,7 +25,7 @@ module.exports = new Class
,'row-inserted': this.onRowInsert ,'row-inserted': this.onRowInsert
}); });
var set = new SimpleIterator ({model: x}); var set = new Iterator ({model: x});
this.link ({_set: set}); this.link ({_set: set});
} }
,get: function () ,get: function ()

View File

@ -42,8 +42,8 @@ Connection.implement
/** /**
* Runs a SQL query on the database. * Runs a SQL query on the database.
* *
* @param {String} sql The SQL statement * @param {string} sql The SQL statement
* @param {Function} callback The function to call when operation is done * @param {function} callback The function to call when operation is done
*/ */
,execSql: function (sql, callback) ,execSql: function (sql, callback)
{ {
@ -55,7 +55,7 @@ Connection.implement
* Runs a stmt on the database. * Runs a stmt on the database.
* *
* @param {Sql.Stmt} stmt The statement * @param {Sql.Stmt} stmt The statement
* @param {Function} callback The function to call when operation is done * @param {function} callback The function to call when operation is done
* @param {Object} params The statement parameters * @param {Object} params The statement parameters
*/ */
,execStmt: function (stmt, callback, params) ,execStmt: function (stmt, callback, params)
@ -66,8 +66,8 @@ Connection.implement
/** /**
* Runs a query on the database. * Runs a query on the database.
* *
* @param {String} query The SQL statement * @param {string} query The SQL statement
* @param {Function} callback The function to call when operation is done * @param {function} callback The function to call when operation is done
* @param {Object} params The statement parameters * @param {Object} params The statement parameters
*/ */
,execQuery: function (query, callback, params) ,execQuery: function (query, callback, params)
@ -78,9 +78,9 @@ Connection.implement
/** /**
* Renders a query. * Renders a query.
* *
* @param {String} query The SQL statement * @param {string} query The SQL statement
* @param {Object} params The statement parameters * @param {Object} params The statement parameters
* @return {String} The rendered statement * @return {string} The rendered statement
*/ */
,renderQuery: function (query, params) ,renderQuery: function (query, params)
{ {

View File

@ -6,8 +6,8 @@ Db = module.exports = {
,Result : require ('./result') ,Result : require ('./result')
,ResultSet : require ('./result-set') ,ResultSet : require ('./result-set')
,Model : require ('./model') ,Model : require ('./model')
,IteratorIface : require ('./iterator-iface')
,Iterator : require ('./iterator') ,Iterator : require ('./iterator')
,SimpleIterator : require ('./simple-iterator')
,Form : require ('./form') ,Form : require ('./form')
,Query : require ('./query') ,Query : require ('./query')
,Calc : require ('./calc') ,Calc : require ('./calc')

View File

@ -57,10 +57,8 @@ module.exports = new Class
type: Number type: Number
,get: function () ,get: function ()
{ {
if (this._model) return this._model ?
return this._model.numRows; this._model.numRows : 0;
return 0;
} }
}, },
/** /**
@ -71,7 +69,8 @@ module.exports = new Class
type: Boolean type: Boolean
,get: function () ,get: function ()
{ {
return this._ready; return this._model ?
this._model.ready : false;
} }
}, },
/** /**
@ -124,4 +123,3 @@ module.exports = new Class
this.changed (); this.changed ();
} }
}); });

145
js/db/iterator-iface.js Normal file
View File

@ -0,0 +1,145 @@
var Model = require ('./model');
module.exports = new Class
({
Implements: Vn.LotIface
,Properties:
{
/**
* The model associated to this form.
*/
model:
{
type: Model
},
/**
* The row where the form positioned, has -1 if the row is unselected.
*/
row:
{
type: Number
},
/**
* The number of rows in the form.
*/
numRows:
{
type: Number
},
/**
* The current row parameters.
*/
params:
{
type: Object
},
/**
* Checks if the form data is ready.
*/
ready:
{
type: Boolean
}
}
,_model: null
,_row: -1
,refresh: function ()
{
if (this._model)
this._model.refresh ();
}
/**
* Get the index of the column from its name.
*
* @param {string} columnName The column name
* @return {integer} The column index or -1 if column not exists
*/
,getColumnIndex: function (columnName)
{
return this._model ?
this._model.getColumnIndex (columnName) : -1;
}
,insertRow: function ()
{
if (this._model)
this.row = this._model.insertRow ();
}
,performOperations: function ()
{
if (this._model)
this._model.performOperations ();
}
/**
* Removes the current row.
*/
,deleteRow: function ()
{
if (this._row >= 0)
this._model.deleteRow (this._row);
}
/**
* Gets a value from the form.
*
* @param {string} columnName The column name
* @return {Object} The value
*/
,get: function (columnName)
{
return this._model ?
this._model.get (this._row, columnName) : undefined;
}
/**
* Sets a value on the form.
*
* @param {string} columnName The column name
* @param {Object} value The new value
*/
,set: function (columnName, value)
{
this._model.set (this._row, columnName, value);
}
/**
* Gets a value from the form using the column index.
*
* @param {string} columnName The column index
* @return {Object} The value
*/
,getByIndex: function (column)
{
return this._model.getByIndex (this._row, column);
}
/**
* Sets a value on the form using the column index.
*
* @param {string} columnName The column index
* @param {Object} value The new value
*/
,setByIndex: function (column, value)
{
return this._model.setByIndex (this._row, column, value);
}
,keys: function ()
{
return this._model ?
this.model.keys () : null;
}
,getParams: function ()
{
return this._model ?
this.model.getObject (this._row) : null;
}
});

View File

@ -1,24 +1,45 @@
var IteratorIface = require ('./iterator-iface');
var Model = require ('./model'); var Model = require ('./model');
/**
* A light iterator for models.
*/
module.exports = new Class module.exports = new Class
({ ({
Implements: Vn.LotIface Extends: Vn.Object
,Implements: IteratorIface
,Properties: ,Properties:
{ {
/** /**
* The model associated to this form. * The model associated to this form.
*/ */
model: model:
{ {
type: Model type: Model
,set: function (x)
{
this._model = x;
}
,get: function ()
{
return this._model;
}
}, },
/** /**
* The row where the form positioned, has -1 if the row is unselected. * The row where the form positioned, has -1 if the row is unselected.
*/ */
row: row:
{ {
type: Number type: Number
,set: function (x)
{
this._row = x;
}
,get: function ()
{
return this._row;
}
}, },
/** /**
* The number of rows in the form. * The number of rows in the form.
@ -26,6 +47,23 @@ module.exports = new Class
numRows: numRows:
{ {
type: Number type: Number
,get: function ()
{
return this._model ?
this._model.numRows : 0;
}
},
/**
* Checks if the form data is ready.
*/
ready:
{
type: Boolean
,get: function ()
{
return this._model ?
this._model.ready : false;
}
}, },
/** /**
* The current row parameters. * The current row parameters.
@ -39,138 +77,8 @@ module.exports = new Class
} }
,get: function () ,get: function ()
{ {
var params = {}; return this.getParams ();
var keys = this.keys ();
for (var i = 0; i < keys.length; i++)
{
var key = keys[i];
params[key] = this.get (key);
}
return params;
} }
},
/**
* Checks if the form data is ready.
*/
ready:
{
type: Boolean
} }
} }
,_model: null
,_row: -1
,refresh: function ()
{
if (this._model)
this._model.refresh ();
}
/**
* Get the index of the column from its name.
*
* @param {String} columnName The column name
* @return {integer} The column index or -1 if column not exists
*/
,getColumnIndex: function (columnName)
{
if (this._model)
return this._model.getColumnIndex (columnName);
return -1;
}
,insertRow: function ()
{
if (this._model)
this.row = this._model.insertRow ();
}
,performOperations: function ()
{
if (this._model)
this._model.performOperations ();
}
/**
* Removes the current row.
*/
,deleteRow: function ()
{
if (this._row >= 0)
this._model.deleteRow (this._row);
}
/**
* Gets a value from the form.
*
* @param {String} columnName The column name
* @return {Object} The value
*/
,get: function (columnName)
{
if (this._model)
return this._model.get (this._row, columnName);
return undefined;
}
/**
* Sets a value on the form.
*
* @param {String} columnName The column name
* @param {Object} value The new value
*/
,set: function (columnName, value)
{
return this._model.set (this._row, columnName, value);
}
/**
* Gets a value from the form using the column index.
*
* @param {String} columnName The column index
* @return {Object} The value
*/
,getByIndex: function (column)
{
return this._model.getByIndex (this._row, column);
}
/**
* Sets a value on the form using the column index.
*
* @param {String} columnName The column index
* @param {Object} value The new value
*/
,setByIndex: function (column, value)
{
return this._model.setByIndex (this._row, column, value);
}
,keys: function ()
{
if (this._model && this._model.ready)
return Object.keys (this._model.columnMap);
return [];
}
,getParams: function ()
{
var params = {};
var keys = this.keys ();
for (var i = 0; i < keys.length; i++)
{
var key = keys[i];
params[key] = this.get (key);
}
return params;
}
}); });

View File

@ -326,7 +326,8 @@ Klass.implement
{ {
this._lastParams = params; this._lastParams = params;
this._setStatus (Status.LOADING); this._setStatus (Status.LOADING);
this._conn.execStmt (this._stmt, this._selectDone.bind (this), params); this._conn.execStmt (this._stmt, this._selectDone.bind (this),
this._lot ? this._lot.params : null);
} }
else else
this.clean (); this.clean ();
@ -442,8 +443,8 @@ Klass.implement
/** /**
* Sets the default value for inserted fields. * Sets the default value for inserted fields.
* *
* @param {String} field The destination field name * @param {string} field The destination field name
* @param {String} table The destination table name * @param {string} table The destination table name
* @param {Sql.Expr} srcColumn The default value expression * @param {Sql.Expr} srcColumn The default value expression
*/ */
,setDefault: function (field, table, expr) ,setDefault: function (field, table, expr)
@ -459,8 +460,8 @@ Klass.implement
/** /**
* Sets the default value for inserted fields. * Sets the default value for inserted fields.
* *
* @param {String} field The destination field name * @param {string} field The destination field name
* @param {String} table The destination table name * @param {string} table The destination table name
* @param {*} value The default value * @param {*} value The default value
*/ */
,setDefaultFromValue: function (field, table, value) ,setDefaultFromValue: function (field, table, value)
@ -477,9 +478,9 @@ Klass.implement
* Sets the default value for inserted fields from another column in the * Sets the default value for inserted fields from another column in the
* model. * model.
* *
* @param {String} field The destination field name * @param {string} field The destination field name
* @param {String} table The destination table name * @param {string} table The destination table name
* @param {String} srcColumn The source column * @param {string} srcColumn The source column
*/ */
,setDefaultFromColumn: function (field, table, srcColumn) ,setDefaultFromColumn: function (field, table, srcColumn)
{ {
@ -495,7 +496,7 @@ Klass.implement
* Checks if the column exists. * Checks if the column exists.
* *
* @param {integer} column The column index * @param {integer} column The column index
* @return {Boolean} %true if column exists, %false otherwise * @return {boolean} %true if column exists, %false otherwise
*/ */
,checkColExists: function (column) ,checkColExists: function (column)
{ {
@ -508,7 +509,7 @@ Klass.implement
* Checks if the row exists. * Checks if the row exists.
* *
* @param {integer} rowIndex The row index * @param {integer} rowIndex The row index
* @return {Boolean} %true if row exists, %false otherwise * @return {boolean} %true if row exists, %false otherwise
*/ */
,checkRowExists: function (rowIndex) ,checkRowExists: function (rowIndex)
{ {
@ -550,7 +551,7 @@ Klass.implement
* Gets a value from the model. * Gets a value from the model.
* *
* @param {number} rowIndex The row index * @param {number} rowIndex The row index
* @param {String} columnName The column name * @param {string} columnName The column name
* @return {*} The value * @return {*} The value
*/ */
,get: function (rowIndex, columnName) ,get: function (rowIndex, columnName)
@ -567,7 +568,7 @@ Klass.implement
* Updates a value on the model. * Updates a value on the model.
* *
* @param {number} rowIndex The row index * @param {number} rowIndex The row index
* @param {String} columnName The column name * @param {string} columnName The column name
* @param {*} value The new value * @param {*} value The new value
*/ */
,set: function (rowIndex, columnName, value) ,set: function (rowIndex, columnName, value)
@ -596,17 +597,26 @@ Klass.implement
} }
/** /**
* Gets a row as an object using the column index. * Gets a row as an object using the column index.
* *
* @param {number} rowIndex The row index * @param {number} rowIndex The row index
* @return {Object} The row as an object * @return {Object} The row as an object
*/ */
,getObject: function (rowIndex) ,getObject: function (rowIndex)
{ {
if (!this.checkRowExists (rowIndex)) return this.checkRowExists (rowIndex) ?
return null; this.result.getObject (rowIndex) : null;
}
return this.result.getObject (rowIndex); /**
* Returns an array with model column names.
*
* @return {Array} The column names
*/
,keys: function ()
{
return this.ready ?
Object.keys (this._model.columnMap) : null;
} }
/** /**
@ -1098,7 +1108,7 @@ Klass.implement
* *
* FIXME: Not fully implemented. * FIXME: Not fully implemented.
* *
* @param {String} column The column name * @param {string} column The column name
*/ */
,indexColumn: function (column) ,indexColumn: function (column)
{ {
@ -1140,7 +1150,7 @@ Klass.implement
* If an index have been built on that column, it will be used, for more * If an index have been built on that column, it will be used, for more
* information see the indexColumn() method. * information see the indexColumn() method.
* *
* @param {String} column The column name * @param {string} column The column name
* @param {Object} value The value to search * @param {Object} value The value to search
* @return {integer} The column index * @return {integer} The column index
*/ */
@ -1296,11 +1306,11 @@ Klass.implement
* - https://bugs.mysql.com/bug.php?id=44660 * - https://bugs.mysql.com/bug.php?id=44660
* - https://bugs.mysql.com/bug.php?id=26894 * - https://bugs.mysql.com/bug.php?id=26894
* *
* @param {String} table The table alias * @param {string} table The table alias
* @param {String} orgtable The original table name * @param {string} orgtable The original table name
* @param {String} schema The original table schema * @param {string} schema The original table schema
* @param {Array} pks Array with the names of primary keys * @param {Array} pks Array with the names of primary keys
* @param {String} ai The autoincrement column name * @param {string} ai The autoincrement column name
*/ */
,setInfo: function (table, orgname, schema, pks, ai) ,setInfo: function (table, orgname, schema, pks, ai)
{ {

View File

@ -29,7 +29,7 @@ module.exports = new Class
/** /**
* Gets a value from de result. * Gets a value from de result.
* *
* @param {String} columnName The column name * @param {string} columnName The column name
* @return {Object} The cell value * @return {Object} The cell value
*/ */
,get: function (columnName) ,get: function (columnName)
@ -48,17 +48,18 @@ module.exports = new Class
if (!this.next ()) if (!this.next ())
return null; return null;
return this.getObject (); return this.getObject (this.row);
} }
/** /**
* Returns the current row as an object. * Returns the current row as an object.
* *
* @param {number} rowIndex The row index
* @return {Object} The row or %null if there are no more rows * @return {Object} The row or %null if there are no more rows
*/ */
,getObject: function () ,getObject: function (rowIndex)
{ {
var row = this.data[this.row]; var row = this.data[rowIndex];
var cols = this.columns; var cols = this.columns;
var object = {}; var object = {};

View File

@ -1,89 +0,0 @@
var Iterator = require ('./iterator');
var Model = require ('./model');
/**
* A light iterator for models.
*/
module.exports = new Class
({
Extends: Vn.Object
,Implements: Iterator
,Properties:
{
/**
* The model associated to this form.
*/
model:
{
type: Model
,set: function (x)
{
this._model = x;
}
,get: function ()
{
return this._model;
}
},
/**
* The row where the form positioned, has -1 if the row is unselected.
*/
row:
{
type: Number
,set: function (x)
{
this._row = x;
}
,get: function ()
{
return this._row;
}
},
/**
* The number of rows in the form.
*/
numRows:
{
type: Number
,get: function ()
{
if (this._model)
return this._model.numRows;
return 0;
}
},
/**
* Checks if the form data is ready.
*/
ready:
{
type: Boolean
,get: function ()
{
if (this._model)
return this._model.ready;
return false;
}
},
/**
* The current row parameters.
*/
params:
{
type: Object
,set: function (x)
{
this.assign (x);
}
,get: function ()
{
return this.getParams ();
}
}
}
});

View File

@ -227,7 +227,7 @@ module.exports = new Class
for (var i = 0; i < sections.length; i++) for (var i = 0; i < sections.length; i++)
{ {
res.row = sections[i]; res.row = sections[i];
var row = res.getObject (); var row = res.getObject (res.row);
var li = this.createElement ('li'); var li = this.createElement ('li');
ul.appendChild (li); ul.appendChild (li);

View File

@ -64,8 +64,7 @@ module.exports = new Class
type: String type: String
,set: function (x) ,set: function (x)
{ {
this._name = x; this._setName (x);
this._onLotChange ();
} }
,get: function () ,get: function ()
{ {
@ -133,7 +132,7 @@ module.exports = new Class
* Virtual method that must be implemented by class childs to set the entry * Virtual method that must be implemented by class childs to set the entry
* editable. * editable.
* *
* @param {Boolean} editable Whether the user is allowed to edit the entry * @param {boolean} editable Whether the user is allowed to edit the entry
*/ */
,setEditable: function () {} ,setEditable: function () {}

View File

@ -25,7 +25,7 @@ module.exports = new Class
,'updatable-changed': this.onUpdatableChange ,'updatable-changed': this.onUpdatableChange
}); });
var set = new Db.SimpleIterator ({model: x}); var set = new Db.Iterator ({model: x});
this.link ({_set: set}); this.link ({_set: set});
this.onUpdatableChange (); this.onUpdatableChange ();

View File

@ -88,7 +88,7 @@ module.exports = new Class
* Shows the popup relative to another element. * Shows the popup relative to another element.
* *
* @param {Node} parent The relative element * @param {Node} parent The relative element
* @param {Boolean} fitParent Wether to set the width same to the parent * @param {boolean} fitParent Wether to set the width same to the parent
* @param {HTMLEvent} ignoreEvent An optional event object to ignore * @param {HTMLEvent} ignoreEvent An optional event object to ignore
*/ */
,show: function (parent, fitParent, ignoreEvent) ,show: function (parent, fitParent, ignoreEvent)
@ -102,7 +102,7 @@ module.exports = new Class
* Opens the popup. * Opens the popup.
* *
* @param {Node} parent The relative element * @param {Node} parent The relative element
* @param {Boolean} fitParent Wether to set the width same to the parent * @param {boolean} fitParent Wether to set the width same to the parent
*/ */
,open: function (ignoreEvent) ,open: function (ignoreEvent)
{ {
@ -148,7 +148,7 @@ module.exports = new Class
* Returns if the popup window shoud be modal based on the modal property * Returns if the popup window shoud be modal based on the modal property
* and if the device is mobile. * and if the device is mobile.
* *
* @return {Boolean} %true if it's modal, %false otherwise * @return {boolean} %true if it's modal, %false otherwise
*/ */
,isModal: function () ,isModal: function ()
{ {

View File

@ -112,7 +112,7 @@ module.exports = new Class
,_buildBox: function (index) ,_buildBox: function (index)
{ {
var set = new Db.SimpleIterator ({ var set = new Db.Iterator ({
model: this._model, model: this._model,
row: index row: index
}); });
@ -172,7 +172,7 @@ module.exports = new Class
this.emit ('change'); this.emit ('change');
} }
,_showNoRecordsFound: function (count) ,_showNoRecordsFound: function ()
{ {
if (this._model.numRows === 0) if (this._model.numRows === 0)
this._showMessage (_('EmptyList'), 'clean'); this._showMessage (_('EmptyList'), 'clean');

View File

@ -12,7 +12,7 @@ module.exports =
/** /**
* Shows a normal toast message. * Shows a normal toast message.
* *
* @param {String} message The message text * @param {string} message The message text
*/ */
,showMessage: function (message) ,showMessage: function (message)
{ {
@ -22,7 +22,7 @@ module.exports =
/** /**
* Shows a warning toast message. * Shows a warning toast message.
* *
* @param {String} message The message text * @param {string} message The message text
*/ */
,showWarning: function (message) ,showWarning: function (message)
{ {
@ -32,7 +32,7 @@ module.exports =
/** /**
* Shows an error toast message. * Shows an error toast message.
* *
* @param {String} message The message text * @param {string} message The message text
*/ */
,showError: function (message) ,showError: function (message)
{ {

View File

@ -9,7 +9,7 @@ module.exports = new Class
* Renders the object as an SQL string. * Renders the object as an SQL string.
* *
* @param {Object} params The params used to render the object * @param {Object} params The params used to render the object
* @return {String} The SQL string * @return {string} The SQL string
*/ */
,render: function () {} ,render: function () {}

View File

@ -1,22 +0,0 @@
var Value = require ('./value');
/**
* The equivalent of a SQL value.
*/
module.exports = new Class
({
Extends: Value
,Tag: 'sql-search-tags'
,render: function ()
{
if (typeof this._value == 'string')
{
var value = this._value.replace (/^|\s+|$/g, '%');
return "'" + value.replace (this.regexp, this.replaceFunc) + "'";
}
else
return this.parent ();
}
});

View File

@ -22,6 +22,5 @@ Sql = module.exports = {
,MultiStmt : require ('./multi-stmt') ,MultiStmt : require ('./multi-stmt')
,Filter : require ('./filter') ,Filter : require ('./filter')
,FilterItem : require ('./filter-item') ,FilterItem : require ('./filter-item')
,SearchTags : require ('./search-tags')
}; };

View File

@ -110,7 +110,7 @@ module.exports = new Class
* *
* @param {Object} object A key-value object * @param {Object} object A key-value object
* @param {boolean} add %true to combine with the current params, %false otherwise * @param {boolean} add %true to combine with the current params, %false otherwise
* @return {String} The URL * @return {string} The URL
*/ */
,make: function (object, add) ,make: function (object, add)
{ {

View File

@ -44,10 +44,10 @@ module.exports = new Class
/** /**
* Opens the connection to the REST service. * Opens the connection to the REST service.
* *
* @param {String} user The user name * @param {string} user The user name
* @param {String} password The user password * @param {string} password The user password
* @param {Boolean} remember Specifies if the user should be remembered * @param {boolean} remember Specifies if the user should be remembered
* @param {Function} openCallback The function to call when operation is done * @param {function} openCallback The function to call when operation is done
*/ */
,open: function (user, pass, remember, callback) ,open: function (user, pass, remember, callback)
{ {
@ -91,7 +91,7 @@ module.exports = new Class
/** /**
* Closes the connection to the REST service. * Closes the connection to the REST service.
* *
* @param {Function} callback The function to call when operation is done * @param {function} callback The function to call when operation is done
*/ */
,close: function (callback) ,close: function (callback)
{ {
@ -120,8 +120,8 @@ module.exports = new Class
/** /**
* Suppants another user. * Suppants another user.
* *
* @param {String} user The user name * @param {string} user The user name
* @param {Function} callback The callback function * @param {function} callback The callback function
*/ */
,supplantUser: function (user, callback) ,supplantUser: function (user, callback)
{ {
@ -151,9 +151,9 @@ module.exports = new Class
* Executes the specified REST service with the given params and calls * Executes the specified REST service with the given params and calls
* the callback when response is received. * the callback when response is received.
* *
* @param {String} restService The service path * @param {string} restService The service path
* @param {Map} params The params to pass to the service * @param {Map} params The params to pass to the service
* @param {Function} callback The response callback * @param {function} callback The response callback
*/ */
,send: function (restService, params, callback) ,send: function (restService, params, callback)
{ {

View File

@ -19,7 +19,7 @@ module.exports = new Class
/** /**
* Gets a value from the set. * Gets a value from the set.
* *
* @param {String} field The field name * @param {string} field The field name
* @return {*} The field value * @return {*} The field value
*/ */
,get: function () {} ,get: function () {}
@ -27,7 +27,7 @@ module.exports = new Class
/** /**
* Sets a value on the set. * Sets a value on the set.
* *
* @param {String} field The field name * @param {string} field The field name
* @param {*} value The new field value * @param {*} value The new field value
*/ */
,set: function () {} ,set: function () {}
@ -41,10 +41,12 @@ module.exports = new Class
/** /**
* Emits the 'change' signal on the set. * Emits the 'change' signal on the set.
*
* @param {Object} changes The changed params and its values
*/ */
,changed: function () ,changed: function (changes)
{ {
this.emit ('change'); this.emit ('change', changes);
} }
/** /**
@ -70,4 +72,3 @@ module.exports = new Class
this.assign (lot.params); this.assign (lot.params);
} }
}); });

View File

@ -66,6 +66,7 @@ Klass.implement
,_fields: null ,_fields: null
,_source: null ,_source: null
,_type: Type.INCLUDE ,_type: Type.INCLUDE
,_sourceFields: null
,_onSourceChange: function () ,_onSourceChange: function ()
{ {
@ -110,12 +111,14 @@ Klass.implement
,typeExclude: function (params) ,typeExclude: function (params)
{ {
var changed = false; var changed = false;
var sourceFields = [];
for (var field in params) for (var field in params)
if (this._fields.indexOf (field) === -1 if (this._fields.indexOf (field) === -1
&& this._params[field] !== params[field]) && this._params[field] !== params[field])
{ {
this._params[field] = params[field]; this._params[field] = params[field];
sourceFields.push (field);
changed = true; changed = true;
} }

View File

@ -65,4 +65,3 @@ module.exports = new Class
this.changed (); this.changed ();
} }
}); });

View File

@ -59,7 +59,7 @@ Klass.implement
* Checks if the column exists. * Checks if the column exists.
* *
* @param {integer} column The column index * @param {integer} column The column index
* @return {Boolean} %true if column exists, %false otherwise * @return {boolean} %true if column exists, %false otherwise
*/ */
,checkColExists: function () {} ,checkColExists: function () {}
@ -67,7 +67,7 @@ Klass.implement
* Checks if the row exists. * Checks if the row exists.
* *
* @param {integer} rowIndex The row index * @param {integer} rowIndex The row index
* @return {Boolean} %true if row exists, %false otherwise * @return {boolean} %true if row exists, %false otherwise
*/ */
,checkRowExists: function () {} ,checkRowExists: function () {}
@ -83,7 +83,7 @@ Klass.implement
* Gets a value from the model. * Gets a value from the model.
* *
* @param {number} rowIndex The row index * @param {number} rowIndex The row index
* @param {String} columnName The column name * @param {string} columnName The column name
* @return {*} The value, or %undefined * @return {*} The value, or %undefined
*/ */
,get: function () {} ,get: function () {}
@ -108,7 +108,7 @@ Klass.implement
/** /**
* Orders the model by the specified column name. * Orders the model by the specified column name.
* *
* @param {Number} column The column name * @param {number} column The column name
* @param {SortWay} way The sort way * @param {SortWay} way The sort way
*/ */
,sortByName: function () {} ,sortByName: function () {}
@ -116,7 +116,7 @@ Klass.implement
/** /**
* Orders the model by the specified column. * Orders the model by the specified column.
* *
* @param {Number} column The column index * @param {number} column The column index
* @param {SortWay} way The sort way * @param {SortWay} way The sort way
*/ */
,sort: function () {} ,sort: function () {}
@ -127,9 +127,9 @@ Klass.implement
* If an index have been built on that column, it will be used, for more * If an index have been built on that column, it will be used, for more
* information see the indexColumn() method. * information see the indexColumn() method.
* *
* @param {String} column The column name * @param {string} column The column name
* @param {Object} value The value to search * @param {Object} value The value to search
* @return {Number} The column index * @return {number} The column index
*/ */
,search: function () {} ,search: function () {}
@ -137,9 +137,9 @@ Klass.implement
* Searchs a value on the model and returns the row index of the first * Searchs a value on the model and returns the row index of the first
* ocurrence. * ocurrence.
* *
* @param {Number} col The column index * @param {number} col The column index
* @param {Object} value The value to search * @param {Object} value The value to search
* @return {Number} The column index * @return {number} The column index
*/ */
,searchByIndex: function () {} ,searchByIndex: function () {}
@ -150,7 +150,7 @@ Klass.implement
* *
* FIXME: Not fully implemented. * FIXME: Not fully implemented.
* *
* @param {String} column The column name * @param {string} column The column name
*/ */
,indexColumn: function () {} ,indexColumn: function () {}
}); });

View File

@ -45,7 +45,7 @@ Klass.implement
* Updates a value on the model. * Updates a value on the model.
* *
* @param {number} rowIndex The row index * @param {number} rowIndex The row index
* @param {String} columnName The column name * @param {string} columnName The column name
* @param {*} value The new value * @param {*} value The new value
*/ */
,set: function () {} ,set: function () {}
@ -53,8 +53,8 @@ Klass.implement
/** /**
* Updates a value on the model using the column index. * Updates a value on the model using the column index.
* *
* @param {Number} rowIndex The row index * @param {number} rowIndex The row index
* @param {Number} col The column index * @param {number} col The column index
* @param {*} value The new value * @param {*} value The new value
*/ */
,setByIndex: function () {} ,setByIndex: function () {}

View File

@ -60,7 +60,7 @@ module.exports =
* function doesn't check if the node already has the class. * function doesn't check if the node already has the class.
* *
* @param {Node} node The HTML Node * @param {Node} node The HTML Node
* @param {String} className The CSS class name * @param {string} className The CSS class name
*/ */
,addClass: function (node, className) ,addClass: function (node, className)
{ {
@ -72,7 +72,7 @@ module.exports =
* removes all ocurrences of the class from the node. * removes all ocurrences of the class from the node.
* *
* @param {Node} node The HTML Node * @param {Node} node The HTML Node
* @param {String} className The CSS class name * @param {string} className The CSS class name
*/ */
,removeClass: function (node, className) ,removeClass: function (node, className)
{ {

View File

@ -1,15 +1,28 @@
/** /**
* The main base class. Manages the signal system. * The main base class. Manages the signal system. Objects based on this class
* * can be instantiated declaratively using XML.
* @param signals Map with all connected signal handlers
*/ */
module.exports = new Class module.exports = new Class
({ ({
/**
* Tag to be used when the class instance is defined via XML.
*/
Tag: 'vn-object' Tag: 'vn-object'
/**
* Class public properties.
*/
,Properties: {} ,Properties: {}
/*
* Reference count.
*/
,_refCount: 1 ,_refCount: 1
/*
* Signal handlers data.
*/
,_signalData: null ,_signalData: null
/** /**
@ -65,7 +78,7 @@ module.exports = new Class
/** /**
* Called from @Vn.Builder when it finds a a child tag that isn't * Called from @Vn.Builder when it finds a a child tag that isn't
* associated to any object property. * associated to any property.
* *
* @param {Object} child The child object instance * @param {Object} child The child object instance
*/ */
@ -74,8 +87,8 @@ module.exports = new Class
/** /**
* Conects a signal with a function. * Conects a signal with a function.
* *
* @param {String} id The signal identifier * @param {string} id The signal identifier
* @param {Function} callback The callback * @param {function} callback The callback
* @param {Object} instance The instance * @param {Object} instance The instance
*/ */
,on: function (id, callback, instance) ,on: function (id, callback, instance)
@ -102,9 +115,9 @@ module.exports = new Class
/** /**
* Locks/Unlocks a signal emission to the specified object. * Locks/Unlocks a signal emission to the specified object.
* *
* @param {String} id The signal identifier * @param {string} id The signal identifier
* @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, instance) ,blockSignal: function (id, callback, block, instance)
{ {
@ -123,9 +136,9 @@ module.exports = new Class
} }
/** /**
* Emits a signal in the current object. * Emits a signal in the object.
* *
* @param {String} id The signal identifier * @param {string} id The signal identifier
*/ */
,emit: function (id) ,emit: function (id)
{ {
@ -151,8 +164,8 @@ module.exports = new Class
/** /**
* Disconnects a signal from current object. * Disconnects a signal from current object.
* *
* @param {String} id The signal identifier * @param {string} id The signal identifier
* @param {Function} callback The connected callback * @param {function} callback The connected callback
* @param {Object} instance The instance * @param {Object} instance The instance
*/ */
,disconnect: function (id, callback, instance) ,disconnect: function (id, callback, instance)
@ -194,7 +207,8 @@ module.exports = new Class
/** /**
* 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. It can be overwritten by child classes
* but should always call the parent method.
*/ */
,_destroy: function () ,_destroy: function ()
{ {
@ -238,7 +252,7 @@ module.exports = new Class
newObject.on (signal, handlers[signal], this); newObject.on (signal, handlers[signal], this);
} }
else if (oldObject) else if (oldObject)
delete links[key]; links[key] = undefined;
} }
} }

View File

@ -1,6 +1,7 @@
var LotIface = require ('./lot-iface'); var LotIface = require ('./lot-iface');
var Type = require ('./type'); var Type = require ('./type');
var Value = require ('./value');
/** /**
* A value holder, it emits the changed signal when value is changed. * A value holder, it emits the changed signal when value is changed.
@ -66,13 +67,10 @@ module.exports = new Class
,_setValue: function (newValue) ,_setValue: function (newValue)
{ {
if (newValue == this._value) if (Value.simpleEquals (newValue, this._value))
return; return;
if (newValue instanceof Date)
newValue = newValue.clone ();
this._value = newValue; this._value = Value.simpleClone (newValue);
this._refreshLot (); this._refreshLot ();
this._refreshParam (); this._refreshParam ();
this.emit ('changed', newValue); this.emit ('changed', newValue);
@ -137,4 +135,10 @@ module.exports = new Class
this._lot.set (this._name, this._value); this._lot.set (this._name, this._value);
this._lotLock = false; this._lotLock = false;
} }
,_setName: function (name)
{
this._name = name;
this._onLotChange ();
}
}); });

View File

@ -67,8 +67,7 @@ module.exports = new Class
type: String type: String
,set: function (x) ,set: function (x)
{ {
this._name = x; this._setName (x);
this._onLotChange ();
} }
,get: function () ,get: function ()
{ {

View File

@ -3,15 +3,15 @@ var VnDate = require ('./date');
/** /**
* Checks if two values are equal, it also checks objects. Basic * Checks if two values are equal, it also checks objects. Basic
* values are compared using the non-strict equality operator. * values are compared using the strict equality operator.
* *
* @param {*} a Value to compare to * @param {*} a Value to compare to
* @param {*} b Value to compare with * @param {*} b Value to compare with
* @return {Boolean} %true if they are equal, %false otherwise * @return {boolean} %true if they are equal, %false otherwise
*/ */
function equals (a, b) function equals (a, b)
{ {
if (a == b) if (a === b)
return true; return true;
if (a instanceof Date && b instanceof Date) if (a instanceof Date && b instanceof Date)
return a.getTime () === b.getTime (); return a.getTime () === b.getTime ();
@ -22,7 +22,7 @@ function equals (a, b)
return false; return false;
for (var key in b) for (var key in b)
if (a[key] === undefined && b[key] != null) if (a[key] === undefined && b[key] !== undefined)
return false; return false;
return true; return true;
@ -32,7 +32,7 @@ function equals (a, b)
} }
/** /**
* Calculates differences of to key-value objects. * Calculates differences of two key-value objects.
* *
* @param {Object} orgObject Value to compare to * @param {Object} orgObject Value to compare to
* @param {Object} newObject Value to compare with * @param {Object} newObject Value to compare with
@ -46,14 +46,14 @@ function diff (orgObject, newObject)
var keys = Object.keys (orgObject); var keys = Object.keys (orgObject);
for (var i = keys.length; --i; key = keys[i]) for (var i = keys.length; --i; key = keys[i])
if (orgObject[key] !== newObject[key]) if (!simpleEquals (orgObject[key], newObject[key]))
diff[key] = newObject[key]; diff[key] = simpleClone (newObject[key]);
var keys = Object.keys (newObject); var keys = Object.keys (newObject);
for (var i = keys.length; --i; key = keys[i]) for (var i = keys.length; --i; key = keys[i])
if (orgObject[key] === undefined) if (orgObject[key] === undefined && newObject[key] !== undefined)
diff[key] = newObject[key]; diff[key] = simpleClone (newObject[key]);
if (Object.keys (diff).length > 0) if (Object.keys (diff).length > 0)
return diff; return diff;
@ -61,12 +61,43 @@ function diff (orgObject, newObject)
return null; return null;
} }
/**
* Copies a simple value.
*
* @param {*} value The value to be copied
* @return {*} The value copy
*/
function simpleClone (value)
{
if (value instanceof Date)
return value.clone ();
return value;
}
/**
* Checks if two simple values are equal using the strict equality operator.
*
* @param {*} a Value to compare to
* @param {*} b Value to compare with
* @return {boolean} %true if they are equal, %false otherwise
*/
function simpleEquals (a, b)
{
if (a === b)
return true;
if (a instanceof Date && b instanceof Date)
return a.getTime () === b.getTime ();
return false;
}
/** /**
* Returns a formated string. * Returns a formated string.
* *
* @param {Object} formatString The base string template * @param {Object} formatString The base string template
* @param {...} arguments Format parameters * @param {...} arguments Format parameters
* @return {String} The formated string * @return {string} The formated string
*/ */
function sprintf (formatString) function sprintf (formatString)
{ {
@ -89,6 +120,8 @@ module.exports =
,equals: equals ,equals: equals
,diff: diff ,diff: diff
,simpleClone: simpleClone
,simpleEquals: simpleEquals
,sprintf: sprintf ,sprintf: sprintf
,compare: function (a, b) ,compare: function (a, b)

View File

@ -150,7 +150,7 @@ Vn = module.exports = {
* includes and its dependencies are resolved. * includes and its dependencies are resolved.
* Should be called on the last statically incuded script. * Should be called on the last statically incuded script.
* *
* @param {Function} callback The main function * @param {function} callback The main function
*/ */
,main: function (callback) ,main: function (callback)
{ {
@ -245,7 +245,7 @@ Vn = module.exports = {
* Sets the function that will be called when current script dependencies * Sets the function that will be called when current script dependencies
* are resolved. * are resolved.
* *
* @param {Function} callback The callback function * @param {function} callback The callback function
*/ */
,define: function (callback) ,define: function (callback)
{ {
@ -271,7 +271,7 @@ Vn = module.exports = {
* is already included, does nothing and calls the callback. * is already included, does nothing and calls the callback.
* *
* @param {string} fileName The script file name * @param {string} fileName The script file name
* @param {Function} callback The function to call when script is * @param {function} callback The function to call when script is
* downloaded and included * downloaded and included
*/ */
,includeJs: function (fileName, callback, skipVersion) ,includeJs: function (fileName, callback, skipVersion)
@ -349,7 +349,7 @@ Vn = module.exports = {
* Request an XML file. * Request an XML file.
* *
* @param {string} path The file path * @param {string} path The file path
* @param {Function} callback The function to call when file is downloaded * @param {function} callback The function to call when file is downloaded
*/ */
,loadXml: function (path, callback) ,loadXml: function (path, callback)
{ {