var tracywindyMultiTable = function(config){ //必要属性 this.objectType = "multiTable"; this.renderTo = config.renderTo; tracywindyObject["multiTable_"+(config.id||this.renderTo)]=this; this.width = config.width; this.height = config.height; this.columns = config.columns; this.datas = config.datas||[]; this.isShowCopyCount = config.isShowCopyCount; //可选 this.id = config.id||("table_"+this.renderTo); this.border = config.border||false; this.isCheck = (false == config.isCheck ) ? false : true; this.isRank = (false == config.isRank) ? false : true; this.showHeader = true; this.checkOnly = true; this.isFit = config.isFit||false; this.loadMode = config.loadMode||'local'; this.callBack = config.callBack||function(){}; this.params = config.params||{}; this.msg = config.msg||"请勾选要操作的数据"; this.tools = ('undefined'==typeof(config.tools)) ? "新增|复制|修改|删除|导出模板|导入模板" : config.tools; this.otherTools = config.otherTools||[]; this.tools = this.tools.replace(/\s/,""); if(config.isNeedTools ==false)this.tools = ""; this.idField = config.idField||"id"; this.windowId = this.id+"Window"; this.windowTop = config.windowTop||20; this.windowWidth = config.windowWidth||400; this.windowHeight = config.windowHeight; this.labelWidth = config.labelWidth||100; //回调 //operType:"add","update" this.resetFromOperCallBack = config.resetFromOperCallBack||function(operType,thisForm,multiTable){}; this.updateFromOperCallBack = config.updateFromOperCallBack||function(operType,thisForm,multiTable,rowData){}; this.operValidate = config.operValidate||function(operType,rowDatas,thisForm,multiTable){return true;}; this.beforeCreateTableWindowCallback = config.beforeCreateTableWindowCallback||function($me){}; //自定义修改更新combobox的数值 //columnConfig["initValue"](combo,rowDatas[0],multiTable,multiTable) //合计 this.isStatistic = (config.isStatistic == false)?false:true; this.isExportTitle = config.isExportTitle||false; //this.inputWidth = config.inputWidth||165; var $me = this; var $toolsMapping = { "新增":"add", "复制":"copy", "修改":"update", "删除":"remove", "导出模板":"export", "导入模板":"import" }; this.commonValidateTableDataPassed = config.commonValidateTableDataPassed||function(rowDatas,$me){ if(this.operValidate){ if(!this.operValidate($me.flag,rowDatas,jQuery("#"+this.windowId+" form")[0],$me)){ return false; } } if("add" !=$me.flag){ if(0 == rowDatas.length) { alert(this.msg); return false; } } return true; }; this.validateForm = config.validateForm||function($me,currentTable){ return Validator.Validate(jQuery("#"+$me.windowId+" form")[0],1,false); }; this.findColumnConfigByName = function($me,currentTable,columnName){ var columns = currentTable.columns; for(var i = 0;i'; tableWindow_html+= '
'; tableWindow_html+='
'; tableWindow_html+=' '; tableWindow_html+='
'; tableWindow_html+=' '; tableWindow_html+=' '; this.comboboxArray = []; //动态填充开始 for(var i=0;i'; break; } case "textarea":{ valueContent = ''; break; } case "number":{ this.statisticColumnNames.push(inputName); otherAttributes+=' dataType="Number" '; valueContent = ''; break; } case "double":{ this.statisticColumnNames.push(inputName); otherAttributes+=' dataType="Double" '; valueContent = ''; break; } case "date":{ if(columnConfig['readOnly']){ valueContent = ''; } else{ var dateFormat = columnConfig['dateFormat']||'yyyy-MM-dd'; valueContent = ''; } break; } case "combobox":{ var config = columnConfig['config']; //新增根据id来查询combobox config["id"] = $me.windowId+"_queryMultiComboBox_"+inputName; config['relativeDisplayInputId'] = relativeDisplayInputId; valueContent = ''; var columnHiddenName = columnConfig['hiddenName']; if(columnHiddenName){ var relativeHiddenInputId = $me.windowId+'_'+columnHiddenName; //valueContent += ''; config['relativeHiddenInputId'] = relativeHiddenInputId; } //模拟下拉框 valueContent += '
'; var comboboxDivContianerId = this.id+'id_combo_'+inputName+'_container'; var defaultRawValue = columnConfig['defaultRawValue']||''; if('undefined' == typeof(columnConfig['isViewHistoryTask'])){ if(window.isViewHistoryTask){ columnConfig['isViewHistoryTask'] = window.isViewHistoryTask; } }else{ config['isViewHistoryTask'] = columnConfig['isViewHistoryTask']; } config['hiddenName'] = columnHiddenName; config['renderTo'] = comboboxDivContianerId; config['otherAttributes'] = oldOtherAttributes; config['value'] = defaultValue; config['rawValue'] = defaultRawValue; config['readOnlyData'] = columnConfig['readOnly'] ? true : false; var topAdd = 0; config['topAdd'] = topAdd; config['leftAdd'] = 1; var oldParams = config["params"]||{}; //modify by tracywindy 20130109 16:45 添加combobox级联 start var cascadeConfig = columnConfig["cascade"]; var multiTable = $me; var currentTable = $me.operationTable; var tempValue = defaultValue||config['value']; var tempRawValue = defaultRawValue||config['rawValue']; var rowDatas =[]; if("update" == multiTable.flag){ rowDatas = currentTable.getCheckedRowDatas(); var hiddenMappingName = multiTable.findColumnMappingByName(multiTable,currentTable,columnHiddenName); tempValue = rowDatas[0][hiddenMappingName]||""; if(!tempValue){ var columnName = columnConfig['name']; var mappingName = multiTable.findColumnMappingByName(multiTable,currentTable,columnName); tempRawValue = rowDatas[0][mappingName]||""; } } config['value'] = tempValue; config['rawValue'] = tempRawValue; if(cascadeConfig && currentTable){ var parentColumnNamesArr = cascadeConfig["parentColumnNames"]||[]; for(var ii =0;ii 0) { if("update" == multiTable.flag) { var hiddenName = columnConfig['hiddenName']; if('local'==columnConfig['config']['loadMode']){ if(columnConfig["initValue"]){ columnConfig["initValue"](combo,rowDatas[0],multiTable,multiTable); } else{ //if(hiddenName) { var hiddenMappingName = multiTable.findColumnMappingByName(multiTable,currentTable,hiddenName); var hiddenValue = rowDatas[0][hiddenMappingName]; if(hiddenValue){ combo.setValue(hiddenValue); } else{ var columnName = columnConfig['name']; var mappingName = multiTable.findColumnMappingByName(multiTable,currentTable,columnName); combo.setRawValue(rowDatas[0][mappingName]); } } } }else{ combo.loadComplete = function(){ if(columnConfig["initValue"]){ columnConfig["initValue"](combo,rowDatas[0],multiTable,multiTable); } else{ //if(hiddenName) { var hiddenMappingName = multiTable.findColumnMappingByName(multiTable,currentTable,hiddenName); var hiddenValue = rowDatas[0][hiddenMappingName]; if(hiddenValue){ combo.setValue(hiddenValue); } else{ var columnName = columnConfig['name']; var mappingName = multiTable.findColumnMappingByName(multiTable,currentTable,columnName); combo.setRawValue(rowDatas[0][mappingName]); } } } }; } } } }; var initLoadCompteteFunc = (function(multiTable,columnConfig,config){ return function(){var combo = this;config['init'](combo,$me.operationTable,multiTable,columnConfig);}; })($me,columnConfig,config); config['comboLoadFunc'] = initLoadCompteteFunc;*/ var $$me = this; var selectFunc = (function($$me,columnConfig,config){ return function(combo,rowData){ if(columnConfig['hiddenName']) { jQuery("#"+$$me.windowId+" form input[name='"+columnConfig['hiddenName']+"']").val(this.getValue()); } jQuery("#"+$$me.windowId+" form input[name='"+columnConfig['name']+"']").val(this.getRawValue()); /*cascade:{ parentColumnNames:[], childrenColumnNames:[] }*/ //modify by tracywindy 20130109 16:45 添加combobox级联 start var cascadeConfig = columnConfig["cascade"]; if(cascadeConfig){ //var parentColumnNamesArr = cascadeConfig["parentColumnNames"]||[]; var childrenColumnNamesArr = cascadeConfig["childrenColumnNames"]||[]; for(var ii =0;ii'; tableWindow_html+='
'; tableWindow_html+=' '; tableWindow_html+=' '; } //动态填充结束 tableWindow_html+='
'+requireContent+labelContent+''+valueContent+'
'; tableWindow_html+='
'; tableWindow_html+='
'; tableWindow_html+='
'; tableWindow_html+=''; //jQuery(document.body).append(tableWindow_html); tableWindow_html+=''; if(this.isShowCopyCount){ if(!jQuery("#"+this.windowId+"_copyCountWindow")[0]){ tableWindow_html+=''; tableWindow_html+=''; } } jQuery(document.body).append(tableWindow_html); if(document.getElementById(this.windowId+"dlg-buttons")) var $$this = this; jQuery(function(){ jQuery("#"+$$this.windowId +" form input.Wdate").click(function(e){ WdatePicker(this,{readOnly:true,dateFmt:this.getAttribute('dateFormat')}); }); $$this.comboboxs = []; for(var i=0;i<$$this.comboboxArray.length;i++) { var combo_select = new tracywindyComboBox($$this.comboboxArray[i]); $$this.comboboxs.push(combo_select); } }); } }; /*迭代配置 column配置:{ cascade:{ parentColumnNames:["contactname"], childrenColumnNames:["custname"] } } */ this.setColumnConfig = function(config,nameOrIndex){ tracywindyTable.prototype.setColumnConfig.call(this,config,nameOrIndex); }; this.setReadOnly = function(isReadOnly,nameOrIndex){ this.setColumnConfig({readOnly:isReadOnly,isViewHistoryTask:isReadOnly},nameOrIndex); }; this.commonCreateTableWindow = commonCreateTableWindow; this.commonCreateTableWindow(); //初始化window var commonTableWindowReset = config.commonTableWindowReset || function(){ if(this.beforeCreateTableWindowCallback){ this.beforeCreateTableWindowCallback(this); } this.commonCreateTableWindow(); var thisForm = jQuery("#"+this.windowId+" form")[0]; var formElements = thisForm.elements; for(var a=0;a'+"新增"+'', iconCls:'icon-'+"add", handler:function(currentTable){ $me.flag = "add"; if(!$me.commonValidateTableDataPassed(null,$me))return; $me.commonTableWindowReset(); var clickFunc = (function($me,currentTable){ return function(e){ if($me.validateForm($me,currentTable)){ $me.addOperCallBack($me,currentTable); } }; })($me,currentTable); jQuery("#"+$me.id+"SubmitButton")[0].onclick = clickFunc; var cancelClickFunc = (function($me,currentTable){ return function(e){ jQuery("#"+$me.windowId).dialog("close"); }; })($me,currentTable); jQuery("#"+$me.id+"CancelButton")[0].onclick = cancelClickFunc; $me.showCommonTableWindow(); } }, "复制":{ html:''+"复制"+'', iconCls:'icon-'+"copy", handler:function(currentTable){ $me.flag = "copy"; var rowDatas = currentTable.getCheckedRowDatas(); if($me.commonValidateTableDataPassed(rowDatas,$me)){ $me.copyOperCallBack($me,currentTable); } } }, "修改":{ html:''+"修改"+'', iconCls:'icon-'+"update", handler:function(currentTable){ $me.flag = "update"; var rowDatas = currentTable.getCheckedRowDatas(); if($me.commonValidateTableDataPassed(rowDatas,$me)){ if(rowDatas.length>1){ alert("只能选择单条记录进行修改"); return; }; $me.commonTableWindowReset(); var realRowData = {}; for(var mappingName in rowDatas[0]){ var columnName = $me.findColumnNameByMapping($me,currentTable,mappingName); if(null == columnName)continue; realRowData[columnName] = rowDatas[0][mappingName]||rowDatas[0][columnName]; } jQuery('#'+$me.windowId+" form").form('load',realRowData); if($me.updateFromOperCallBack){ $me.updateFromOperCallBack("update",jQuery('#'+$me.windowId+" form")[0],$me,realRowData); } var clickFunc = (function($me,currentTable){ return function(e){ if($me.validateForm($me,currentTable)){ $me.updateOperCallBack($me,currentTable); } }; })($me,currentTable); jQuery("#"+$me.id+"SubmitButton")[0].onclick = clickFunc; var cancelClickFunc = (function($me,currentTable){ return function(e){ jQuery("#"+$me.windowId).dialog("close"); }; })($me,currentTable); jQuery("#"+$me.id+"CancelButton")[0].onclick = cancelClickFunc; $me.showCommonTableWindow(); } } }, "删除":{ html:''+"删除"+'', iconCls:'icon-'+"remove", handler:function(currentTable){ $me.flag = "remove"; var rowDatas = currentTable.getCheckedRowDatas(); if($me.commonValidateTableDataPassed(rowDatas,$me)){ $me.removeOperCallBack($me,currentTable); } } }, "导出模板":{ html:''+"导出模板"+'', iconCls:'icon-'+"export", handler:function(currentTable){ exportExcelData(currentTable.id); } }, "导入模板":{ html:''+"导入模板"+'', iconCls:'icon-'+"import", handler:function(currentTable){ importExcelData(currentTable.id); } } }; var $tools = this.otherTools; var toolsArr = this.tools.split("|"); for(var i = 0;i 0, datas:this.datas, isFit:this.isFit, //isPage:false, isExportTitle:this.isExportTitle, statisticColumnNames:this.statisticColumnNames, columns:this.columns, tools:$tools, callBack:this.callBack, params:this.params }; for(var p in $config){ config[p] = $config[p]; } var table = new tracywindyTable(config); this.operationTable = table; return table; };