JueKit.Type.registerNamespace("JueKit.Data");JueKit.Data.UpdateViewType={dataChanged:1,colChanged:2,rowDeleted:4,rowAdded:8,rowRestored:16,rowChanged:32,propChanged:64};JueKit.Data.DataSource=JueKit.Type.createClass("JueKit.Data.DataSource",JueKit.CustomEventControl,{_canUpdate:true,_canDelete:true,_canAdd:true,ctor:function(){this._views=new JueKit.Collection.LinkedList()},bindView:function(view){if(view){this._views.addLast(view);this.updateView(view,JueKit.Data.UpdateViewType.dataChanged)}},unbindView:function(view){this._views.remove(view)},updateAllViews:function(updateViewType,args){var node=this._views.get_first();while(node){this.updateView(node.get_value(),updateViewType,args);node=node.get_next()}},updateView:function(view,updateViewType,args){if(!view){return}if(!updateViewType){updateViewType=JueKit.Data.UpdateViewType.dataChanged}if(view.canUpdateView&&!view.canUpdateView(this,updateViewType,args)){return}view.beginUpdateView&&view.beginUpdateView(this,updateViewType,args);view.updateView&&view.updateView(this,updateViewType,args);view.endUpdateView&&view.endUpdateView(this,updateViewType,args)},get_canUpdate:function(){return this._canUpdate},set_canUpdate:function(value){if(this._canUpdate==value){return}this._canUpdate=value;this.__dispatchMsg("PropertyChanged")},get_canDelete:function(){return this._canDelete},set_canDelete:function(value){if(this._canDelete==value){return}this._canDelete=value;this.__dispatchMsg("PropertyChanged")},get_canAdd:function(){return this._canAdd},set_canAdd:function(value){if(this._canAdd==value){return}this._canAdd=value;this.__dispatchMsg("PropertyChanged")}});JueKit.Type.registerNamespace("JueKit.Data");JueKit.Data.LinkedListDataReader=JueKit.Type.createClass("JueKit.Data.LinkedListDataReader",JueKit.Data.DataSource,{ctor:function(list){this._list=list;JueKit.Data.LinkedListDataReader._base.ctor.call(this)},forEach:function(fCallback,oScope,arrArgs){if(!this._list){return}var item=this._list.get_first();while(item){fCallback.call(oScope,item.get_value(),arrArgs);item=item.get_next()}}});JueKit.Data.LinkedListDataReader.open=function(list){return new JueKit.Data.LinkedListDataReader(list)};JueKit.Type.registerNamespace("JueKit.Data");JueKit.Data.ArrayDataReader=JueKit.Type.createClass("JueKit.Data.ArrayDataReader",JueKit.Data.DataSource,{ctor:function(arr){this._arrs=arguments;JueKit.Data.LinkedListDataReader._base.ctor.call(this)},forEach:function(fCallback,oScope,arrArgs){if(!this._arrs){return}var arr;for(var i=0;i<this._arrs.length;i++){arr=this._arrs[i];if(arr){for(var j=0;j<arr.length;j++){fCallback.call(oScope,arr[j],arrArgs)}}}}});JueKit.Data.ArrayDataReader.open=function(arr){return new JueKit.Data.ArrayDataReader(arr)};JueKit.Type.registerNamespace("JueKit.Data");JueKit.Data.DataType={typeBool:0,typeInt:1,typeFloat:2,typeString:3,typeDateTime:4};JueKit.Data.DataRowState={stateNormal:0,stateChanged:1,stateNew:2,stateDeleted:4};JueKit.Data.EditMode={modeRead:0,modeModify:1,modeAdd:2};JueKit.Data.DataRow=JueKit.Type.createClass("JueKit.Data.DataRow",JueKit.Collection.LinkedListNode,{_state:JueKit.Data.DataRowState.stateNormal,ctor:function(table){this._table=table;this._data={}},get_state:function(){return this._state},set_state:function(value){this._state=value;if(this._state==JueKit.Data.DataRowState.stateNormal){this._orgData=undefined}},get_table:function(){return this._table},getColValue:function(name){return this._data[name]},setColValue:function(name,value){var oldValue=this._data[name];if(oldValue==value){return}if(this._state==JueKit.Data.DataRowState.stateNormal){this._orgData={};JueKit.Type.extend(this._orgData,this._data);this._state=JueKit.Data.DataRowState.stateChanged}this._data[name]=value;if(this._table){var col=this._table.getCol(name);if(col){this._table.notifyColValueChange(this,col,oldValue,value)}}},restore:function(){if(!this._orgData){return}this._data=this._orgData;this._orgData==undefined;this._state=JueKit.Data.DataRowState.stateNormal;if(this._table){this._table.notifyRowRestored(this)}},deleteRow:function(){if(this._table){this._table.deleteRow(this)}}});JueKit.Data.DataRow.getColValue=function(dataRow,colName){if(dataRow.getColValue){return dataRow.getColValue(colName)}return dataRow[colName]};JueKit.Data.DataRow.setColValue=function(dataRow,colName,value){if(dataRow.setColValue){dataRow.setColValue(colName,value)}else{dataRow[colName]=value}};JueKit.Data.DataColumn=JueKit.Type.createClass("JueKit.Data.DataColumn",null,{ctor:function(options){this._name=options.name;this._dataType=options.dataType;if(this._dataType===undefined){this._dataType=JueKit.Data.DataType.typeString}if(options.size!==undefined){this._size=options.size}if(options.defaultValue!==undefined){this._defaultValue=options.defaultValue}},get_name:function(){return this._name},get_dataType:function(){return this._dataType}});JueKit.Data.DataTable=JueKit.Type.createClass("JueKit.Data.DataTable",JueKit.Data.DataSource,{ctor:function(options){this._cols=new JueKit.Collection.Dictionary();this._rows=new JueKit.Collection.LinkedList();this._deletedRows=new JueKit.Collection.LinkedList();if(options){var cols=options.cols;if(cols){for(var i=0;i<cols.length;i++){this.addCol(cols[i])}}}JueKit.Data.DataTable._base.ctor.call(this,options)},addCol:function(options){this._cols.setValue(options.name,new JueKit.Data.DataColumn(options))},getCol:function(name){return this._cols.getValue(name)},get_cols:function(){return this._cols},__addRow:function(dataRow){this._rows.addLast(dataRow)},newRow:function(data){var row;if(data){row=this.__loadRowData(data)}else{row=new JueKit.Data.DataRow(this)}row._state=JueKit.Data.DataRowState.stateNew;this.__addRow(row);var args={dataRow:row};this.updateAllViews(JueKit.Data.UpdateViewType.rowAdded,args);this.fireEvent("rowAdded",args);this.set_currentRow(row);return row},deleteRow:function(dataRow){if(!dataRow){dataRow=this._currentRow}if(!dataRow||dataRow._table!=this||dataRow._state==JueKit.Data.DataRowState.stateDeleted){return}this._rows.remove(dataRow);if(dataRow._state!=JueKit.Data.DataRowState.stateNew){dataRow._state=JueKit.Data.DataRowState.stateDeleted;this._deletedRows.addLast(dataRow)}var args={dataRow:dataRow};this.updateAllViews(JueKit.Data.UpdateViewType.rowDeleted,args);this.fireEvent("rowDeleted",args)},get_rows:function(){return this._rows},get_deletedRows:function(){return this._deletedRows},getFirstRow:function(){return this._rows.get_first()},getLastRow:function(){return this._rows.get_last()},getRowAt:function(index){return this._rows.getAt(index)},getRowCount:function(){return this._rows.get_count()},get_currentRow:function(){return this._currentRow},set_currentRow:function(row,trigger){if(row&&row.get_table()!=this){return}if(this._currentRow==row){return}var oldRow=this._currentRow;this._currentRow=row;var args={oldRow:oldRow,curRow:row,trigger:trigger,result:true};this.fireEvent("rowChanging",args);if(!args.result){this._currentRow=oldRow;return}this.updateAllViews(JueKit.Data.UpdateViewType.rowChanged,args);this.fireEvent("rowChanged",args)},getColValue:function(name){if(this._currentRow){return this._currentRow.getColValue(name)}},setColValue:function(name,value){if(this._currentRow){return this._currentRow.setColValue(name,value)}},loadDataFromArray:function(array){this._rows=new JueKit.Collection.LinkedList();this._deletedRows=new JueKit.Collection.LinkedList();if(array){for(var i=0;i<array.length;i++){this.__addRow(this.__loadRowData(array[i]))}}},__loadRowData:function(data){var dataRow;var cols=this._cols.get_values();var colNode,col,colIndex;colIndex=0;dataRow=new JueKit.Data.DataRow(this);colNode=cols.get_first();if(data instanceof Array){while(colNode){col=colNode.get_value();dataRow._data[col._name]=data[colIndex];colIndex++;colNode=colNode.get_next()}}else{while(colNode){col=colNode.get_value();dataRow._data[col._name]=data[col._name];colNode=colNode.get_next()}}return dataRow},notifyColValueChange:function(row,col,oldValue,curValue){var args={dataRow:row,dataCol:col,oldValue:oldValue,curValue:curValue,result:true};this.fireEvent("colChanging",args);if(!args.result){return}this.updateAllViews(JueKit.Data.UpdateViewType.colChanged,args);this.fireEvent("colChanged",args)},notifyRowRestored:function(row){var args={dataRow:row};this.updateAllViews(JueKit.Data.UpdateViewType.rowRestored,args);this.fireEvent("rowRestored",args)},forEach:function(fCallback,oScope,arrArgs){this._rows.forEach(fCallback,oScope,arrArgs)}});JueKit.Type.registerNamespace("JueKit.Data");JueKit.Data.Renderers={date:function(format){return function(value){return JueKit.DateTime.format(value,format)}},justDate:function(value){return JueKit.DateTime.format(value,"yyyy-MM-dd")},fileSize:function(value){return JueKit.Number.formatSize(value)}};