0
1
Fork 0
hedera-web-mindshore/web/js/htk/repeater.js

202 lines
3.5 KiB
JavaScript
Executable File

Htk.Repeater = new Class
({
Extends: Htk.Widget
,Tag: 'htk-repeater'
,Child: 'model'
,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._formId = x;
}
,get: function ()
{
this._formId;
}
}
,renderer:
{
type: Function
,set: function (x)
{
this._renderer = x;
}
,get: function ()
{
this._renderer;
}
}
,emptyMessage:
{
type: String
,value: _('NoData')
}
}
,_builder: null
,_formId: 'form'
,initialize: function (props)
{
var div = this.createElement ('div');
div.className = 'htk-repeater';
this.parent (props);
}
,loadXml: function (builderResult, node)
{
this.parent (builderResult, node);
var builder = this._builder = new Vn.Builder ();
builder.setParent (builderResult);
builder.loadXmlFromNode (node.firstElementChild);
this.onModelChange ();
}
,getChild: function (index)
{
return this.node.childNodes[index];
}
,getBuilder: function (index)
{
return this.childsData[index].builder;
}
,getForm: function (index)
{
return this.childsData[index].form;
}
,buildBox: function (index)
{
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: res,
form: form
});
if (this._renderer)
this._renderer (res, form);
this.node.appendChild (res.getMain ());
}
,onModelChange: function ()
{
if (!this._model || !this._builder)
return;
Vn.Node.removeChilds (this.node);
this.freeChildsData ();
this.childsData = [];
switch (this._model.status)
{
case Db.Model.Status.READY:
{
for (var i = 0; i < this._model.numRows; i++)
this.buildBox (i);
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;
}
this.signalEmit ('change');
}
,showNoRecordsFound: function (count)
{
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));
}
,onRowDelete: function (model, row)
{
Vn.Node.remove (this.node.childNodes[row]);
this.showNoRecordsFound ();
}
,onRowUpdate: function (model, row, columns)
{
// this.form[row].signalEmit ('iter-changed');
}
,onRowInsert: function (model, row)
{
this.buildBox (row);
}
,freeChildsData: function ()
{
if (this.childsData)
for (var i = 0; i < this.childsData.length; i++)
{
this.childsData[i].form.unref ();
this.childsData[i].builder.unref ();
}
}
,destroy: function ()
{
this.freeChildsData ();
this.parent ();
}
});