2015-03-09 08:36:54 +00:00
|
|
|
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
|
|
|
|
});
|
|
|
|
|
|
|
|
this.onModelChange ();
|
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
this._model;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
,formId:
|
|
|
|
{
|
|
|
|
type: String
|
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
this._alias = x;
|
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
this._alias;
|
|
|
|
}
|
2015-03-15 12:44:57 +00:00
|
|
|
},
|
|
|
|
emptyMessage:
|
|
|
|
{
|
|
|
|
type: String
|
|
|
|
,value: _('NoData')
|
2015-03-09 08:36:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
,xml: null
|
|
|
|
,parentBuilder: null
|
|
|
|
,_alias: 'form'
|
|
|
|
|
|
|
|
,initialize: function ()
|
|
|
|
{
|
|
|
|
this.createElement ('div');
|
2015-03-15 12:44:57 +00:00
|
|
|
this.node.className = 'htk-repeater';
|
2015-03-09 08:36:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,loadXml: function (builder, node)
|
|
|
|
{
|
|
|
|
this.xml = node.firstElementChild;
|
|
|
|
this.parentBuilder = builder;
|
|
|
|
this.onModelChange ();
|
|
|
|
}
|
2015-03-15 12:44:57 +00:00
|
|
|
|
|
|
|
,buildBox: function (index)
|
|
|
|
{
|
|
|
|
var builder = new Vn.Builder ();
|
2015-03-27 19:10:49 +00:00
|
|
|
builder.setParent (this.parentBuilder);
|
2015-03-15 12:44:57 +00:00
|
|
|
|
|
|
|
var form = new Db.Form ();
|
|
|
|
form.model = this._model;
|
|
|
|
form.row = index;
|
|
|
|
builder.add (this._alias, form);
|
|
|
|
|
|
|
|
var mainNode = builder.loadXmlFromNode (this.xml);
|
|
|
|
this.node.appendChild (mainNode);
|
|
|
|
}
|
2015-03-09 08:36:54 +00:00
|
|
|
|
|
|
|
,onModelChange: function ()
|
|
|
|
{
|
|
|
|
if (!this._model || !this.xml)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Vn.Node.removeChilds (this.node);
|
|
|
|
|
2015-03-15 12:44:57 +00:00
|
|
|
switch (this._model.status)
|
2015-03-09 08:36:54 +00:00
|
|
|
{
|
2015-03-15 12:44:57 +00:00
|
|
|
case Db.Model.Status.READY:
|
|
|
|
{
|
|
|
|
for (var i = 0; i < this._model.numRows; i++)
|
|
|
|
this.buildBox (i);
|
2015-03-09 08:36:54 +00:00
|
|
|
|
2015-03-15 12:44:57 +00:00
|
|
|
this.showNoRecordsFound ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Db.Model.Status.LOADING:
|
|
|
|
this.showMessage (_('Loading'), 'loader-black.gif');
|
|
|
|
break;
|
|
|
|
case Db.Model.Status.CLEAN:
|
|
|
|
this.showMessage (this.emptyMessage, 'refresh.svg');
|
|
|
|
break;
|
|
|
|
case Db.Model.Status.ERROR:
|
|
|
|
this.showMessage (_('ErrorLoadingData'), 'error.svg');
|
|
|
|
break;
|
2015-03-09 08:36:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-15 12:44:57 +00:00
|
|
|
,showNoRecordsFound: function (count)
|
2015-03-09 08:36:54 +00:00
|
|
|
{
|
2015-03-15 12:44:57 +00:00
|
|
|
if (this._model.numRows == 0)
|
|
|
|
this.showMessage (_('EmptyList'), 'clean.svg');
|
|
|
|
}
|
|
|
|
|
|
|
|
,showMessage: function (message, src)
|
|
|
|
{
|
|
|
|
var div = document.createElement ('div');
|
|
|
|
div.className = 'message';
|
|
|
|
this.node.appendChild (div);
|
|
|
|
|
|
|
|
var img = document.createElement ('img');
|
|
|
|
img.alt = '';
|
|
|
|
img.src = 'image/'+ src;
|
|
|
|
div.appendChild (img);
|
|
|
|
|
|
|
|
div.appendChild (document.createTextNode (message));
|
2015-03-09 08:36:54 +00:00
|
|
|
}
|
|
|
|
|
2015-03-15 12:44:57 +00:00
|
|
|
,onRowDelete: function (model, row)
|
2015-03-09 08:36:54 +00:00
|
|
|
{
|
2015-03-15 12:44:57 +00:00
|
|
|
Vn.Node.remove (this.node.childNodes[row]);
|
|
|
|
this.showNoRecordsFound ();
|
2015-03-09 08:36:54 +00:00
|
|
|
}
|
|
|
|
|
2015-03-15 12:44:57 +00:00
|
|
|
,onRowUpdate: function (model, row, columns)
|
2015-03-09 08:36:54 +00:00
|
|
|
{
|
2015-03-15 12:44:57 +00:00
|
|
|
// this.form[row].signalEmit ('iter-changed');
|
2015-03-09 08:36:54 +00:00
|
|
|
}
|
|
|
|
|
2015-03-15 12:44:57 +00:00
|
|
|
,onRowInsert: function (model, row)
|
2015-03-09 08:36:54 +00:00
|
|
|
{
|
2015-03-15 12:44:57 +00:00
|
|
|
this.buildBox (row);
|
2015-03-09 08:36:54 +00:00
|
|
|
}
|
|
|
|
});
|