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},
|
|
|
|
{
|
2015-11-09 17:11:51 +00:00
|
|
|
'status-changed': this._onModelChange
|
|
|
|
,'row-deleted': this._onRowDelete
|
|
|
|
,'row-updated': this._onRowUpdate
|
|
|
|
,'row-inserted': this._onRowInsert
|
2015-03-09 08:36:54 +00:00
|
|
|
});
|
|
|
|
|
2015-11-09 17:11:51 +00:00
|
|
|
this._onModelChange ();
|
2015-03-09 08:36:54 +00:00
|
|
|
}
|
|
|
|
,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');
|
2015-11-09 17:11:51 +00:00
|
|
|
|
|
|
|
this._container = document.createElement ('div');
|
|
|
|
this._container.className = 'htk-repeater';
|
|
|
|
div.appendChild (this._container);
|
2015-11-09 08:14:33 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2015-11-09 17:11:51 +00:00
|
|
|
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)
|
|
|
|
{
|
2015-11-09 17:11:51 +00:00
|
|
|
return this._container.childNodes[index];
|
2015-07-10 12:30:08 +00:00
|
|
|
}
|
|
|
|
|
2015-07-23 15:58:48 +00:00
|
|
|
,getBuilder: function (index)
|
|
|
|
{
|
2015-11-09 17:11:51 +00:00
|
|
|
return this._childsData[index].builder;
|
2015-07-23 15:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,getForm: function (index)
|
|
|
|
{
|
2015-11-09 17:11:51 +00:00
|
|
|
return this._childsData[index].form;
|
2015-07-23 15:58:48 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 17:11:51 +00:00
|
|
|
,_buildBox: function (index)
|
2015-03-15 12:44:57 +00:00
|
|
|
{
|
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-11-17 10:34:33 +00:00
|
|
|
res.link ();
|
2015-07-23 15:58:48 +00:00
|
|
|
|
2015-11-09 17:11:51 +00:00
|
|
|
this._childsData.push ({
|
2015-11-09 08:14:33 +00:00
|
|
|
builder: res,
|
2015-07-28 19:14:26 +00:00
|
|
|
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-11-09 17:11:51 +00:00
|
|
|
|
|
|
|
return res.getMain ();
|
2015-03-15 12:44:57 +00:00
|
|
|
}
|
2015-03-09 08:36:54 +00:00
|
|
|
|
2015-11-09 17:11:51 +00:00
|
|
|
,_onModelChange: function ()
|
2015-03-09 08:36:54 +00:00
|
|
|
{
|
2015-11-09 08:14:33 +00:00
|
|
|
if (!this._model || !this._builder)
|
2015-03-09 08:36:54 +00:00
|
|
|
return;
|
2015-11-09 17:11:51 +00:00
|
|
|
|
|
|
|
this.node.removeChild (this._container);
|
|
|
|
Vn.Node.removeChilds (this._container);
|
|
|
|
|
|
|
|
this._freeChildsData ();
|
|
|
|
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++)
|
2015-11-09 17:11:51 +00:00
|
|
|
this._container.appendChild (this._buildBox (i));
|
2015-03-09 08:36:54 +00:00
|
|
|
|
2015-11-09 17:11:51 +00:00
|
|
|
this._showNoRecordsFound ();
|
2015-03-15 12:44:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Db.Model.Status.LOADING:
|
2015-11-09 17:11:51 +00:00
|
|
|
this._showMessage (_('Loading'), 'loader-black.gif');
|
2015-03-15 12:44:57 +00:00
|
|
|
break;
|
|
|
|
case Db.Model.Status.CLEAN:
|
2015-11-09 17:11:51 +00:00
|
|
|
this._showMessage (this.emptyMessage, 'refresh.svg');
|
2015-03-15 12:44:57 +00:00
|
|
|
break;
|
|
|
|
case Db.Model.Status.ERROR:
|
2015-11-09 17:11:51 +00:00
|
|
|
this._showMessage (_('ErrorLoadingData'), 'error.svg');
|
2015-03-15 12:44:57 +00:00
|
|
|
break;
|
2015-03-09 08:36:54 +00:00
|
|
|
}
|
2015-07-23 15:58:48 +00:00
|
|
|
|
2015-11-09 17:11:51 +00:00
|
|
|
this.node.appendChild (this._container);
|
2015-07-23 15:58:48 +00:00
|
|
|
this.signalEmit ('change');
|
2015-03-09 08:36:54 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 17:11:51 +00:00
|
|
|
,_showNoRecordsFound: function (count)
|
2015-03-09 08:36:54 +00:00
|
|
|
{
|
2015-11-09 17:11:51 +00:00
|
|
|
if (this._model.numRows === 0)
|
2015-11-17 10:34:33 +00:00
|
|
|
this._showMessage (_('EmptyList'), 'clean.svg');
|
2015-03-15 12:44:57 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 17:11:51 +00:00
|
|
|
,_showMessage: function (message, src)
|
2015-03-15 12:44:57 +00:00
|
|
|
{
|
|
|
|
var div = document.createElement ('div');
|
|
|
|
div.className = 'message';
|
2015-11-09 17:11:51 +00:00
|
|
|
this._container.appendChild (div);
|
2015-03-15 12:44:57 +00:00
|
|
|
|
|
|
|
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-11-09 17:11:51 +00:00
|
|
|
,_onRowDelete: function (model, row)
|
2015-03-09 08:36:54 +00:00
|
|
|
{
|
2015-11-09 17:11:51 +00:00
|
|
|
Vn.Node.remove (this._container.childNodes[row]);
|
|
|
|
this._unrefChildData (row);
|
|
|
|
this._showNoRecordsFound ();
|
2015-03-09 08:36:54 +00:00
|
|
|
}
|
|
|
|
|
2015-11-09 17:11:51 +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-11-09 17:11:51 +00:00
|
|
|
,_onRowInsert: function (model, row)
|
2015-03-09 08:36:54 +00:00
|
|
|
{
|
2015-11-09 17:11:51 +00:00
|
|
|
var box = this._buildBox (row);
|
|
|
|
this._container.appendChild (box);
|
2015-03-09 08:36:54 +00:00
|
|
|
}
|
2015-07-28 19:14:26 +00:00
|
|
|
|
2015-11-09 17:11:51 +00:00
|
|
|
,_freeChildsData: function ()
|
2015-07-28 19:14:26 +00:00
|
|
|
{
|
2015-11-09 17:11:51 +00:00
|
|
|
if (this._childsData)
|
|
|
|
for (var i = 0; i < this._childsData.length; i++)
|
|
|
|
this._unrefChildData (i);
|
|
|
|
}
|
|
|
|
|
|
|
|
,_unrefChildData: function (index)
|
|
|
|
{
|
|
|
|
var childData = this._childsData[index];
|
|
|
|
childData.form.unref ();
|
|
|
|
childData.builder.unref ();
|
2015-07-28 19:14:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,destroy: function ()
|
|
|
|
{
|
2015-11-09 17:11:51 +00:00
|
|
|
this._freeChildsData ();
|
2015-07-28 19:14:26 +00:00
|
|
|
this.parent ();
|
|
|
|
}
|
2015-03-09 08:36:54 +00:00
|
|
|
});
|
2015-11-09 17:11:51 +00:00
|
|
|
|