define(function(require) {
	//加载JS库
	var $ = require('jquery');
	var IFA = require('util');
	require('grid')($);
	require('sort')($);
	require('dialog')($);
	require('uriTemplate')($);
	require('../../../styles/cim/jquery-ui-1.8.14.custom.css');
	require('../../../styles/cim/cim-grid.css');   
	$(function(){
		var pv = window.dialogArguments;
		search(pv);
		$(document).bind("keydown",function(){
			if(event.keyCode = 116){
			//event.returnValue = false;
			}
		});
		$("#append").bind("click",append);
		//$("#saveSortResult").bind("click",saveSort);
	});
	function search(p){
	var queryUrl = $("#searchUrl").val();
	var grid = $("#attributeList").grid({
		url:queryUrl,
		root:"attributes",  
  		method:'GET',
  		isREST:true,
  		paging:false,
  		pageSize:50,
  		pageTheme:'Theme1',
  		//sortable:true,
  		filter:function(data){
  		 return p[''+data.id]?true:false;
  		},
  		fields:[
  		        {
  		        	type:'checkbox',id:"id"
  		        },
  		        {
  		        	type:'hidden',id:"showName"
  		        },
  		        {
  					name:i18n['Entity.payMethod.attribute.showName'],id:"showName",style:"width:20%"
  				},
  				{
  					name:i18n['Entity.payMethod.attribute.modelName'],id:"modelName",style:"width:20%"
  				},
  				
  				{
  					name:i18n['Entity.payMethod.attribute.regexs'],id:"regexs",style:"width:20%"
  				},
  				{
  					name:i18n['Entity.payMethod.attribute.domType'],id:"domType",style:"width:20%",render:function(data){
  						return data.domType==0?"INPUT":"TEXTAREA";
  					}
  				},
  				{
  					name:i18n['Entity.payMethod.attribute.domStyle'],id:"domStyle",style:"width:20%"
  				}
  				
  			]
  			
  		
		
	});
	}
	
	function append(){
		var vs = {};
		$("input:checkbox[checked]").each(function(){
			var iv = $(this).val();
			vs[''+iv] =iv; 
		});
		window.returnValue = vs;
		window.close();
	}
	
	function saveSort(){
		//console.log($("#sortForm").serialize()); 
	}
	
});