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; } }, emptyMessage: { type: String ,value: _('NoData') } } ,xml: null ,parentBuilder: null ,_alias: 'form' ,initialize: function () { this.createElement ('div'); this.node.className = 'htk-repeater'; } ,loadXml: function (builder, node) { this.xml = node.firstElementChild; this.parentBuilder = builder; this.onModelChange (); } ,buildBox: function (index) { var builder = new Vn.Builder (); 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); } ,onModelChange: function () { if (!this._model || !this.xml) return; Vn.Node.removeChilds (this.node); 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; } } ,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); } });