<#macro editGrid id="grid" query="" view_model="" uipk="" onSelectRow="" remoteDataSource="false"  showImport="false" showExport="false" showSearch="false"  entrys="" loadComplete="" rowNum="50" rowList="[50,100,200]" pager="gridPager" hasPager="false" readonly="false" sorterItems="" shrinkToFit="true" datatype="json" multiselect="false" editType="inline" clientFooter="false" sumColModel="[]" serverFooter="false"  rownumbers="true" isShowJumpButton="false">

<#if readonly == "true">
	<#global grid_readonly="true">
<#else>
	<#global grid_readonly="false">
</#if>

<#if editType == "inline">
	<#assign cellEdit="true">
<#elseif editType == "form">
	<#assign cellEdit="false">
</#if>
<#if hasPager == "true">
	<div class="shrPage span3" style="text-align: right;width: 100%;min-height: 30px;box-sizing: border-box;float: inherit;margin-left: 0;max-width: inherit;">	
		<div id="gridPager" style="display:inline-block;"></div>			
	</div>
</#if>
<table id="${id}"></table>
<div id="${id}_editGrid"></div>

<script type="text/javascript">
	function ${id}_gridRemove(rowId){
		if (rowId) {
			waf("#${id}").wafGrid('delRow', rowId);
		}
	}
	function ${id}_gridEdit(rowId){
		 var rowdatas = waf("#${id}").getRowRealData(rowId);
		 waf("#${id}").wafGrid('editForm',rowId,rowdatas);
		 var event = document.createEvent('HTMLEvents');
		 	 event.initEvent("editComplete_${id}", true, true);
			 event.eventType = 'message';
			 document.dispatchEvent(event);
	}
    $(function() {
        var colNames = [],
			colModel = [],
			dataGrid_option = {},
			columnModel = '',
			datatype = 'json',
			cellEdit = ${cellEdit},
			grid_readonly = ${grid_readonly}
		<#nested>
		
		<#if readonly == "false" && editType == "form">
			<@gridColumn name="operatorColumn" label='${freemarkerMultLan.msg068!"freemarkerMultLan.msg068"}' width="120" editable="false" >
				<@linkButton id="editButton" caption='${freemarkerMultLan.msg071!"freemarkerMultLan.msg071"}' onclick="${id}_gridEdit">	</@linkButton>
				<@linkButton id="removeButton" caption='${freemarkerMultLan.msg067!"freemarkerMultLan.msg067"}' onclick="${id}_gridRemove"></@linkButton>
			</@gridColumn>
		<#elseif editType == "inline" && isShowJumpButton == "true">
			<@gridColumn name="operatorColumn" label='${freemarkerMultLan.msg068!"freemarkerMultLan.msg068"}' width="120" editable="false" >
				<@linkButton id="jumpButton" caption='查看模板字段' onclick="jumpPage"></@linkButton>
			</@gridColumn>
		</#if>
		<#if grid_readonly == "false">
			<#local multiselect="true">
		</#if>
				
		var url = shr.getContextPath();
			url += '/dynamic.do?method=getListData&columnModel='+columnModel+"&sorterItems=${sorterItems}";
		<#if query != "">
			url = url + '&query=${query}';
		</#if>
		<#if uipk != "">
			url = url + '&uipk=${uipk}';
		</#if>

		dataGrid_option = {
		   	url:url,
			colNames: colNames,
			jsonReader : {
				 repeatitems: false
			},
			sorterItems:"${sorterItems}",
			colModel: colModel,		
			columnModel: columnModel,	
			rowNum:${rowNum},	
			customPager:'#gridPager',			 
			hasPager:${hasPager},			
			rowList: ${rowList},
			cellEdit : !grid_readonly, 
		   	height: 'auto',
		   	autowidth: true,
		    viewrecords: true,
		    cellsubmit:"clientArray",
		    multiselect: ${multiselect},
		    _type_:"EditGrid",
		    shrinkToFit: ${shrinkToFit},
		    mtype:"post",
		    recordtext:'({0}-{1})/{2}',
		    gridview: true,
		    pginput: true,
		    rownumbers:${rownumbers},
			footerrow: true,
			userDataOnFooter: true,
			clientFooter: ${clientFooter},
			serverFooter: ${serverFooter},
			sumColModel: ${sumColModel},
			pagerpos: 'center',
			recordpos: 'left',
			pginputpos: 'right',
		    keyOptions: {
     				addNewRowForLastCell: false,
     				loop:true
			}
		};
		
		<#if remoteDataSource == "true">
			dataGrid_option.datatype = "local"; 
		<#else>
			<#if entrys != "">
				dataGrid_option.data = ${entrys};
				jsBinder.searchDataForFront = ${entrys};
				dataGrid_option.datatype = "local";
			<#else>
				dataGrid_option.datatype = "${datatype}";
			</#if>
		</#if>
		
		dataGrid_option.loadComplete = function(ret){
			if($("#${pager}").html() == "" && "${hasPager}" == "true"){
				$("#${id}").setCustomPager("#${pager}");
			}
			
			shr.setIframeHeight();
			
			$('#${pager}_left').click(function(){
	        	$('.ui-pg-selbox').show();
	        	$(this).children('.ui-paging-info').hide();
	        });
	        
	        <#if loadComplete != "">
	        	if ($.isFunction(${loadComplete})) {
	        		${loadComplete}.call(this, ret);
	        	}	        	
	        </#if>			
		};
		var $editGrid = waf("#${id}");
		jsBinder.gridId = "#${id}";
		jsBinder.remoteDataSource = "${remoteDataSource}";
        $editGrid.jqGrid(dataGrid_option).jqGrid("setFrozenColumns");
		$editGrid.jqGrid('reloadGrid');		
        $editGrid.jqGrid("resizeGrid",{base:$editGrid,offset:0});
        waf(window).resize(function(){
            waf.ieHack.hackResize(function(e){
                $editGrid.jqGrid("resizeGrid",{base:$editGrid,offset:0});
            },$editGrid);
        });
    });
</script>
</#macro>

<#-- 
-->
<#-- grid列属性配置  
	sensitiveRule 脱敏配置，格式：sensitiveRule="{'isOpen':true|false,'name':''}" name 脱敏规则名称;动态列表配置格式{'sensitiveRule':{'isOpen':true|false,'name':''}}
-->
<#macro gridColumn entryName name label width=150 align="left" frozen="false" hidden="false" key="false" editable="true" formatoptions="" customformatter="" customparam="" formatter="" rowspan="" fieldspan="" required="false" sortKey="" sorttype="" uipk="" ctrl="" sortable="true" thalign="left" sensitiveRule="">
	<#if fieldPermEntrysForm(model, name, entryName)>
	colNames.push("${label}");
	var columnOptions = {name: "${name}",label:"${label}", frozen:${frozen},width: ${width},thalign:"${thalign}", align: "${align}" , hidden: ${hidden}, key:${key},editable:${editable}, sorttype:"${sorttype}"};
	if(cellEdit == false){
		columnOptions.editable = false;
	}
	<#if grid_readonly == "false" && editable == "false">
		columnOptions.classes = 'disabled';
	</#if>
	<#if sensitiveRule != "">
		columnOptions.sensitiveRule = ${sensitiveRule};
	</#if>
	<#if sortable != "">
		columnOptions.sortable = ${sortable};
	</#if>
	<#if customformatter != "">
		columnOptions.formatter = ${customformatter};
	</#if>
	<#if customparam != "">
		columnOptions.customparam = ${customparam};
	</#if>
	<#if formatoptions != "">
		columnOptions.formatoptions = ${formatoptions};
	</#if> 
	<#if formatter != "">
		columnOptions.formatter = "${formatter}";
	</#if>
	<#if rowspan != "">
		columnOptions.rowspan = ${rowspan};
	</#if>
	<#if fieldspan != "">
		columnOptions.fieldspan = ${fieldspan};
	</#if>
	<#if sortKey != "">
		columnOptions.sortKey = ${sortKey};
	</#if>
	<#nested>
	colModel.push(columnOptions);
	if(columnOptions.formatter == "promptBox"){
		if(dataGrid_option.datatype == "json"){
			columnModel += columnOptions.name+".*,";
			columnOptions.name = columnOptions.name+".*";
		}else{
			columnModel += columnOptions.name+",";
		}
	}else{
		columnModel += columnOptions.name + ",";
	}
	</#if>
</#macro>

<#-- 
	新增表格编辑多语言字段解析，对应grid.wafeditor.js celleditor.shrMultiLangBox
  -->
<#macro multiLangBox maxlength="" trimAll="false">
	columnOptions.formatter = "shrMultiLangBox";
	<#if maxlength != "">
		columnOptions.editoptions = {inputJson:{maxlength:${maxlength},trimAll:${trimAll}}};
	<#else>
		columnOptions.editoptions = {};
	</#if>
	columnOptions.edittype = "shrMultiLangBox";
	<#nested>
</#macro>

<#-- 
	新增表格编辑多语言字段解析，对应grid.wafeditor.js celleditor.shrMultiLangArea
  -->
<#macro multiLangArea maxlength="" trimAll="false">
	<#if maxlength != "">
		columnOptions.editoptions = {inputJson:{maxlength:${maxlength},trimAll:${trimAll}}};
	<#else>
		columnOptions.editoptions = {};
	</#if>
	columnOptions.edittype = "shrMultiLangArea";
	<#nested>
</#macro>

<#macro text maxlength="">
	<#if maxlength != "">
		columnOptions.editoptions = {inputJson:{maxlength:${maxlength}}};
	<#else>
		columnOptions.editoptions = {};
	</#if>
	columnOptions.edittype = "shrtext";
	<#nested>
</#macro>
<#macro checkbox>
	columnOptions.formatter = "checkbox";
	columnOptions.edittype = "checkbox";
	columnOptions.editoptions = {};
	<#nested>
</#macro>
<#-- 
	decimalPrecision：视图配置数值小数位，此配置优先
	ignoreDecimalFormatter：忽略数值格式化，显示数据库原始值
	roundType:四舍五入方式
  -->
<#macro numberField decimalPrecision="" formatType="number" ignoreDecimalFormatter="false" roundType="round">
	columnOptions.formatter = "numberfield";
	columnOptions.edittype = "numberfield";
	columnOptions.editoptions = {inputJson:{id:"txt_"+columnOptions.name,name:columnOptions.name,decimalPrecision:${decimalPrecision},formatType:"${formatType}",ignoreDecimalFormatter:${ignoreDecimalFormatter},roundType:"${roundType}"}};
	<#nested>
</#macro>
<#macro textarea maxlength="">
	columnOptions.formatter = "shrTextArea";
	columnOptions.edittype = "shrTextArea";
	<#if maxlength != "">
		columnOptions.editoptions = {inputJson:{maxlength:${maxlength}}};
	<#else>
		columnOptions.editoptions = {};
	</#if>
	<#nested>
</#macro>
<#macro select enumSource="">
	columnOptions.formatter = "shrselect";
	columnOptions.edittype = "shrselect";
	columnOptions.editoptions = {selectJson:{id:"selStatus",name:"status",enumSource:"${enumSource}"},enumSource:{},urlSource:shr.getContextPath() + "/selectEnum.do?method=getSelectEnumData&enumSource=${enumSource}"};
	<#nested>
</#macro>
<#macro datePicker dateFormat="">
	columnOptions.formatter = "datepicker";
	columnOptions.edittype = "shrdatepicker";
	columnOptions.editoptions = {datepickerjson:{id:"dp_autoSize",name:"dp_autoSize",dateFormat:"${dateFormat}"}};
	columnOptions.editoptions.validateJson = {errMsg:"dateISO:'${freemarkerMultLan.msg070!"freemarkerMultLan.msg070"}'",rules:"dateISO:true",validatetrigger:"focus keyup datachange"};
	<#nested>
</#macro>

<#-- 
	showTimeZoneForCtrl: bos提供参数showTimeZoneForCtrl，如果为false，则不转换；不支持视图配置。
	isAutoTimeZoneTrans: 视图配置优先，视图配置为false则不转换；视图未配置，元数据字段扩展属性isAutoTimeZoneTrans配置为false则不转换；其他情况需要转换。
	isShowUTC:时区是否显示isShowUTC
	isReadonlyUTC:时区是否可编辑isReadonlyUTC
	isRemoveSeconds: true,//配置是否去除时间格式化中的秒
	isRemoveDay: false,//配置是否去除日期格式化中的天
	ctrlType:格式化类型 TimeStamp/Date/Time,配合utcUser中pattern使用
  -->
<#macro dateTimePicker dateTimeFormat="yyyy-MM-dd HH:mm" minuteStep ="" showTimeZoneForCtrl="true" isAutoTimeZoneTrans="true" isShowUTC="true" isReadonlyUTC="true"  isRemoveSeconds="true" isRemoveDay="false" ctrlType="">
	<#if ctrlType == "TimeStamp"> 
		columnOptions.width = 255;
	</#if>
	columnOptions.formatter = 'shrDateTimePicker';
	columnOptions.edittype = 'shrDateTimePicker';
	columnOptions.editoptions = {datepickerjson:{id:"dp_autoSize",name:"dp_autoSize",minuteStep:"${minuteStep}",showTimeZoneForCtrl:${showTimeZoneForCtrl},isAutoTimeZoneTrans:${isAutoTimeZoneTrans},isShowUTC:${isShowUTC},isReadonlyUTC:${isReadonlyUTC},isRemoveSeconds:${isRemoveSeconds},isRemoveDay:${isRemoveDay},ctrlType:"${ctrlType}"}};
	<#nested>
</#macro>

<#--
	--集团管控新增参数说明 2017/07/11 tiangang_yang
	-- isHRBaseItem     判断是否是s-HR集团管控基础资料,是：true,不是:false，必须写的参数
	-- filterConfig     过滤配置框 可选
	-- bizFilterFields  业务单据需要过滤的字段属性名称，如：hrOrgUnit,name。多个用逗号隔开 ，可选，不传默认业务组织：hrOrgUnit
	-- f7ReKeyValue     获取F7界面存放key和name的字段，以键值对字符串形式传入，如果不传入，其他类型的F7不变，基础资料默认：BaseInfo.id:BaseInfo.name，可选
	-- isTree ="false"  F7是左树右表，取数逻辑公共
	-- treeUrl = "" F7是左树右表，取数逻辑根据url来取
	-- isEnableExpFilter="" F7默认不启用过滤表达式过滤 add by tiangang_yang on 2021/03/09
	--pgSizes="true" ,为false就隐藏表格的分页控件 add by jacky_xiang on 2021/09/08
	--dataShowMode="layout" ,f7的打开方式，默认为layout即弹出方式，还可配置为下拉方式。 add by jacky_xiang on 2021/11/09
	-->
<#macro promptBox query="" uipk="" filter="" class=""  readonly="" multiselect="false" isTree ="false"  treeUrl = "" searchFields="" isHRBaseItem = "false" bizFilterFields = "" f7ReKeyValue = "" filterConfig="" afterOnchangeClearFields="" displayFormat="" isHROrg="false" isAdminOrg="false" isContainLowerOrg="false" searchLikePattern="any"  isEnableExpFilter="" pgSizes="true" dataShowMode="layout">
	columnOptions.formatter = "promptBox";
	columnOptions.edittype = "promptBox";
	var f7Json = {subWidgetName:"shrPromptGrid",searchFields:"${searchFields}"};
	f7Json.subWidgetOptions = {title:columnOptions.label,uipk:"${uipk}",query:"${query}",filter:"${filter}",multiselect:${multiselect},isTree:${isTree},treeUrl:"${treeUrl}",isContainLowerOrg:${isContainLowerOrg},isAdminOrg:${isAdminOrg},pgSizes:${pgSizes},f7SearchConfig:${getF7SearchConfig(uipk,displayFormat)},dataShowMode:"${dataShowMode}"};
	<#if afterOnchangeClearFields != "">
		f7Json.afterOnchangeClearFields = "${afterOnchangeClearFields}";
	</#if>
	<#if displayFormat != "">
		f7Json.displayFormat = '{${displayFormat}}';
	</#if>
	<#if isHROrg != "">
		f7Json.isHROrg = ${isHROrg};
	</#if>
	<#if isAdminOrg != "">
		f7Json.isAdminOrg = ${isAdminOrg};
	</#if>
	<#if searchLikePattern != "">
		f7Json.searchLikePattern = "${searchLikePattern}";
	</#if>
	<#if isEnableExpFilter != "">
			f7Json.subWidgetOptions.isEnableExpFilter = ${isEnableExpFilter};
		</#if>
	<#if isHRBaseItem == "true">
		f7Json.subWidgetOptions.isHRBaseItem = ${isHRBaseItem};
		<#if filterConfig == "">
			f7Json.subWidgetOptions.filterConfig = [{name:'isComUse',value:true,alias:'${freemarkerMultLan.msg065!"freemarkerMultLan.msg065"}',widgetType:'checkbox'}];
		<#else>
			f7Json.subWidgetOptions.filterConfig = ${filterConfig};
		</#if>
		<#if bizFilterFields == "">
			f7Json.subWidgetOptions.bizFilterFields = "hrOrgUnit";
		<#else>
			f7Json.subWidgetOptions.bizFilterFields = "${bizFilterFields}";
		</#if>
		
		<#if f7ReKeyValue == "">
			f7Json.subWidgetOptions.f7ReKeyValue = "BaseInfo.id:BaseInfo.name";
		<#else>
			f7Json.subWidgetOptions.f7ReKeyValue = "${f7ReKeyValue}";
		</#if>
		f7Json.subWidgetName = 'specialPromptGrid';
	</#if>
	columnOptions.editoptions = {f7Json:f7Json};
	<#--columnOptions.editoptions.f7Json.subWidgetOptions = {title:columnOptions.label,uipk:"${uipk}",query:"${query}",filter:"${filter}"};-->
	<#nested>
</#macro>

<#macro linkButton id="" onclick="" tagClass="" caption="">
	if(columnOptions.formatoptions == null){
		columnOptions.formatoptions = [];
	}
	columnOptions.formatter = "operations";
	columnOptions.formatoptions.push({linkJson:{caption:"${caption}",id:"${id}",onclick:"${onclick}",tagClass:"${tagClass}"},onclick:"${onclick}",visible:true});
	<#nested>
</#macro>

<#macro validator rules="" errMsg="" validatetrigger="focus keyup datachange">
	<#if grid_readonly == "false">
		var validateJson = columnOptions.editoptions.validateJson;
		if(validateJson == null){
			columnOptions.editoptions.validateJson = {errMsg:"${errMsg}",rules:"${rules}",validatetrigger:"${validatetrigger}"};
		}else{
			columnOptions.editoptions.validateJson = {errMsg:validateJson.errMsg+",${errMsg}",rules:validateJson.rules+",${rules}",validatetrigger:"${validatetrigger}"};
		}
		if(columnOptions.editoptions.validateJson.rules.indexOf('required:true') >= 0 && columnOptions.editable && cellEdit){
			columnOptions.classes = 'required';
		}
	</#if>
</#macro>

<#-- 
	rowNum:分录分页显示页数
	rowList:分录分页选项，确定每页数据条数
  -->
<#macro editGridContainer gridId readonly="" entryName="entrys" hasPager="false" shrinkToFit="true" remoteDataSource="false" showImport="false" showExport="false" showSearch="false"  editType="inline" rownumbers="true" rowNum="50" rowList="[50,100,200]" isShowJumpButton="false">	
	<@ctrl.row>
		<@ctrl.cell colSpan=12>
			<div class="editGrid-cont" id="${gridId}_cont">
				<@e.editGridToolbar gridId="${gridId}" showImport="${showImport}" showExport="${showExport}" hasPager="${hasPager}" showSearch="{showSearch}" readonly="${readonly}" />
				<@e.editGrid id="${gridId}" entrys="${collectionFormater(model, entryName,remoteDataSource)}" hasPager="${hasPager}" remoteDataSource="${remoteDataSource}" readonly="${readonly}" shrinkToFit="${shrinkToFit}" editType="${editType}" rownumbers="${rownumbers}" rowNum="${rowNum}" rowList="${rowList}" isShowJumpButton="${isShowJumpButton}">
					<#nested>
				</@e.editGrid>
			</div>
			<script>
				$('#${gridId}_cont').data('editType', '${editType}');
			</script>
		</@ctrl.cell>
		<#-- 占位 -->
		<@ctrl.cell colSpan=1 />
	</@ctrl.row>
</#macro>

<#macro editGridToolbar gridId readonly="" showImport="false" showExport="false" hasPager="false" showSearch="false">
	<#if readonly != "true">	
	<span class=" shr-toolbar">
		<div class="editGrid-toolbar">
			<@ctrl.button id="addRow_${gridId}" name="addRow" value='${freemarkerMultLan.msg058!"freemarkerMultLan.msg058"}' actionBinding="addRowAction" class="shrbtn-primary" />
			<@ctrl.button id="deleteRow_${gridId}" name="deleteRow" value='${freemarkerMultLan.msg067!"freemarkerMultLan.msg067"}' actionBinding="deleteRowAction" />
			<#if showImport == "true">
				<@ctrl.button id="import" name="import" value='${freemarkerMultLan.msg098!"freemarkerMultLan.msg098"}' actionBinding="importAction" />
			</#if> 
			<#if showExport == "true">
				<div class="btn-group">
					<@ctrl.dropDownButton id="export" name="export" value='${freemarkerMultLan.msg099!"freemarkerMultLan.msg099"}' >
						<@ctrl.dropDownBtnLi actionBinding="customAction" name="exportCurrent" subAction="exportCurrentAction" id="exportCurrent${uuid}" permItemId="${getButtonBindPermItemId('exportCurrent','')}" value='${freemarkerMultLan.msg100!"freemarkerMultLan.msg100"}' class="null"  />
	                	<@ctrl.dropDownBtnLi actionBinding="customAction" name="exportToExcelEntry" subAction="exportToExcelEntryAction" id="exportToExcelEntry${uuid}" permItemId="${getButtonBindPermItemId('exportToExcelEntry','')}" value='${freemarkerMultLan.msg101!"freemarkerMultLan.msg101"}' class="null"  />
					</@ctrl.dropDownButton>
				</div>
			</#if>
			<#if showSearch == "true">
				<span style="color:red;margin-left:100px;">注意！修改数据后请先【保存】后再操作"搜索"或"翻页"，否则会造成数据修改不生效！</span>
			</#if>
		</div>
	</span>
	</#if>
</#macro>