forked from verdnatura/hedera-web
103 lines
1.5 KiB
JavaScript
103 lines
1.5 KiB
JavaScript
|
Htk.Repeater = new Class
|
||
|
({
|
||
|
Extends: Htk.Widget
|
||
|
,Tag: 'htk-repeater'
|
||
|
,Properties:
|
||
|
{
|
||
|
model:
|
||
|
{
|
||
|
type: Db.Model
|
||
|
,set: function (x)
|
||
|
{
|
||
|
this.link ({_model: x},
|
||
|
{
|
||
|
'status-changed': this.onModelChange
|
||
|
,'row-deleted': this.onRowDelete
|
||
|
,'row-updated': this.onRowUpdate
|
||
|
,'row-inserted': this.onRowInsert
|
||
|
,'updatable-changed': this.onUpdatableChange
|
||
|
});
|
||
|
|
||
|
this.onModelChange ();
|
||
|
}
|
||
|
,get: function ()
|
||
|
{
|
||
|
this._model;
|
||
|
}
|
||
|
}
|
||
|
,formId:
|
||
|
{
|
||
|
type: String
|
||
|
,set: function (x)
|
||
|
{
|
||
|
this._alias = x;
|
||
|
}
|
||
|
,get: function ()
|
||
|
{
|
||
|
this._alias;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
,xml: null
|
||
|
,parentBuilder: null
|
||
|
,_alias: 'form'
|
||
|
|
||
|
,initialize: function ()
|
||
|
{
|
||
|
this.createElement ('div');
|
||
|
}
|
||
|
|
||
|
,loadXml: function (builder, node)
|
||
|
{
|
||
|
this.xml = node.firstElementChild;
|
||
|
this.parentBuilder = builder;
|
||
|
this.onModelChange ();
|
||
|
}
|
||
|
|
||
|
,onModelChange: function ()
|
||
|
{
|
||
|
if (!this._model || !this.xml)
|
||
|
return;
|
||
|
|
||
|
Vn.Node.removeChilds (this.node);
|
||
|
|
||
|
if (!this._model.ready)
|
||
|
return;
|
||
|
|
||
|
for (var i = 0; i < this._model.numRows; i++)
|
||
|
{
|
||
|
var builder = new Vn.Builder ();
|
||
|
|
||
|
var form = new Db.Form ();
|
||
|
form.model = this._model;
|
||
|
form.row = i;
|
||
|
builder.add (this._alias, form);
|
||
|
|
||
|
var mainNode = builder.loadXmlFromNode (this.xml);
|
||
|
this.node.appendChild (mainNode);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
,onRowDelete: function (model, row)
|
||
|
{
|
||
|
var childs = this.node.childNodes;
|
||
|
this.node.removeChild (childs[row]);
|
||
|
}
|
||
|
|
||
|
,onRowUpdate: function ()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
,onRowInsert: function ()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
,onUpdatableChange: function ()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
});
|