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

202 lines
3.5 KiB
JavaScript
Raw Normal View History

2015-03-09 08:36:54 +00:00
Htk.Repeater = new Class
({
Extends: Htk.Widget
,Tag: 'htk-repeater'
2015-07-23 15:58:48 +00:00
,Child: 'model'
2015-03-09 08:36:54 +00:00
,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)
{
2015-11-09 08:14:33 +00:00
this._formId = x;
2015-03-09 08:36:54 +00:00
}
,get: function ()
{
2015-11-09 08:14:33 +00:00
this._formId;
2015-03-09 08:36:54 +00:00
}
2015-07-03 05:49:45 +00:00
}
,renderer:
{
type: Function
,set: function (x)
{
this._renderer = x;
}
,get: function ()
{
this._renderer;
}
}
,emptyMessage:
2015-03-15 12:44:57 +00:00
{
type: String
,value: _('NoData')
2015-03-09 08:36:54 +00:00
}
}
2015-11-09 08:14:33 +00:00
,_builder: null
,_formId: 'form'
2015-03-09 08:36:54 +00:00
2015-11-09 08:14:33 +00:00
,initialize: function (props)
2015-03-09 08:36:54 +00:00
{
2015-11-09 08:14:33 +00:00
var div = this.createElement ('div');
div.className = 'htk-repeater';
this.parent (props);
2015-03-09 08:36:54 +00:00
}
2015-11-09 08:14:33 +00:00
,loadXml: function (builderResult, node)
2015-03-09 08:36:54 +00:00
{
2015-11-09 08:14:33 +00:00
this.parent (builderResult, node);
2015-07-23 15:58:48 +00:00
2015-11-09 08:14:33 +00:00
var builder = this._builder = new Vn.Builder ();
builder.setParent (builderResult);
builder.loadXmlFromNode (node.firstElementChild);
this.onModelChange ();
2015-03-09 08:36:54 +00:00
}
2015-03-15 12:44:57 +00:00
2015-07-10 12:30:08 +00:00
,getChild: function (index)
{
return this.node.childNodes[index];
}
2015-07-23 15:58:48 +00:00
,getBuilder: function (index)
{
return this.childsData[index].builder;
}
,getForm: function (index)
{
return this.childsData[index].form;
}
2015-03-15 12:44:57 +00:00
,buildBox: function (index)
{
2015-11-09 08:14:33 +00:00
var form = new Db.Form ({
model: this._model,
row: index
});
this._builder.add (this._formId, form);
var res = this._builder.load ();
2015-07-23 15:58:48 +00:00
this.childsData.push ({
2015-11-09 08:14:33 +00:00
builder: res,
form: form
2015-07-23 15:58:48 +00:00
});
2015-07-03 05:49:45 +00:00
if (this._renderer)
2015-11-09 08:14:33 +00:00
this._renderer (res, form);
2015-07-23 15:58:48 +00:00
2015-11-09 08:14:33 +00:00
this.node.appendChild (res.getMain ());
2015-03-15 12:44:57 +00:00
}
2015-03-09 08:36:54 +00:00
,onModelChange: function ()
{
2015-11-09 08:14:33 +00:00
if (!this._model || !this._builder)
2015-03-09 08:36:54 +00:00
return;
Vn.Node.removeChilds (this.node);
this.freeChildsData ();
2015-07-23 15:58:48 +00:00
this.childsData = [];
2015-03-09 08:36:54 +00:00
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-07-23 15:58:48 +00:00
this.signalEmit ('change');
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
}
,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 ();
}
2015-03-09 08:36:54 +00:00
});