var controller_url;var controller_id;var operation;var datagrid_selector;var datagrid_param="";var datagrid_param_limit={};$(function(){setGridHeight();controller_id=$("#controller_id").val();if(controller_id.indexOf("/")>0){controller_url=base_path+controller_id+"/"}else{controller_url=base_path+"par/"+controller_id+"/"}datagrid_selector=$("#datagrid-single");if(datagrid_selector.length!=0){datagrid_selector.datagrid({onDblClickRow:updateRecord});if($("#libcode").length==1){datagrid_selector.datagrid({rowStyler:rowStylerLibcode,onSelect:onSelect})}}overLoadInitData()});function overLoadInitData(){var a=getInitJsonArray(getInitCodeArray("record"));_myPage.prototype.initData(a)}_myPage.prototype.onLoadSuccess=function(a,b){_fmtGridDataRows=a;loadGridData()};function loadGridData(){if(datagrid_selector.length==0){return}var a=datagrid_selector.datagrid("options");var c="list.do";if(a.pagination){c="page.do"}var b=0;var d=datagrid_selector.datagrid("getSelected");if(d){b=datagrid_selector.datagrid("getRowIndex",d)}datagrid_selector.datagrid({url:controller_url+c+datagrid_param,queryParams:datagrid_param_limit,onLoadSuccess:function(e){datagrid_selector.datagrid("selectRow",b);loadGridDataSuccess(e)},method:"post"})}function openWin(){cleanJsonData("record");$("#win").window("open")}function loadGridDataSuccess(a){}function closeWin(){$("#win").window("close")}function getRow(){var a=datagrid_selector.datagrid("getSelected");if(!a){openMessageDlg("请先选择一行");return a}return a}function getPKCode(){if($("#id").length!=0){return"id"}if($("#code").length!=0){return"code"}var a=$('[primary-key="true"]');a.each(function(b,c){return c.id});return null}function getPK(a){return a[getPKCode()]}function getRowPK(){var b=getRow();if(!b){return}var a=getPK(b);if(!a){openMessageDlg("未知主键")}return a}function saveRecord(){var a=getJsonData(null,"record");if(!a){openMessageDlg("记录异常");return}if(verifyRequiredFields()){openMessageDlg("必填字段不能为空!");return}if(verifyReasonableData(a)){return}var b=$('[insert-check="repeat"]');if(b.length>0){verifyRepeatData(a,b)}else{saveRecordOk(a)}}function saveRecordOk(a){var b=controller_url+operation;$.post(b,a,function(c){openMessageDlg(c.message);if(c.status=="0"){closeWin(c);loadGridData(c)}},"json")}function verifyRepeatData(b,c){var a=[{name:"名称"},{bcvalue:"数据内容"}];var f=c[0].id;var d=controller_url+"page.do";var e={};e[f]=b[f];$.post(d,e,function(h){if(h.status=="0"&&h.rows.length>0){var k=h.rows[0];if(k.id&&b.id==k.id){saveRecordOk(b)}else{if(k.code&&b.code==k.code){saveRecordOk(b)}else{var j="";for(var g=0;g0){if(!b){b="value"}e=!e?"text":e;var f=$("#"+d).combobox("getData");if(c){for(var a=0;a=0){return false}return true}function isHigherLibcode(b){if(!b){return false}var a=mystorage.get("completecode");if(!a||a.length<2){return false}a=","+a.substr(0,a.length-2);var c=b.indexOf("|");if(c>0){if(a.indexOf(","+b.substr(0,c)+",")>=0){return true}}else{if(a.indexOf(","+b+",")>=0){return true}if(b!=vLibcode){return true}}return false}function rowStylerLibcode(a,b){if(isHigherLibcode(b.libcode)){return"background-color:#aaa;"}}function onSelect(b,a){};