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(){
		search();
		//$("#saveSortResult").bind("click",saveSort);
	});
	function search(){
	var queryUrl = $("#searchUrl").val();
	var editUrl = new $.Template($("#editUrl").val());
	var updateUrl = $("#updateUrl").val();
	var grid = $("#attributeList").grid({
		url:queryUrl,
		root:"attributes",  
  		method:'GET',
  		isREST:true,
  		paging:false,
  		pageSize:50,
  		pageTheme:'Theme1',
  		//sortable:true,
  		fields:[
  		        {
  		        	type:'hidden',id:"id"
  		        },
  		        {
  		        	name:'id',id:"id"
  		        },
  				{
  					name:i18n['Entity.payMethod.attribute.modelName'],id:"modelName",style:"width:20%"
  				},
  				{
  					name:i18n['Entity.payMethod.attribute.showName'],id:"showName",style:"width:20%"
  				},
  				{
  					name:i18n['Entity.payMethod.value'],id:"value",style:"width:10%"
  				},
  				{
  					name:i18n['Entity.payMethod.attribute.regexs'],id:"regexs",style:"width:20%"
  				},
  				{
  					name:i18n['Entity.payMethod.attribute.domType'],id:"domType",style:"width:10%",render:function(data){
  						return data.domType==0?"INPUT":"TEXTAREA";
  					}
  				},
  				{
  					name:i18n['Entity.payMethod.attribute.domStyle'],id:"domStyle",style:"width:20%"
  				},
  				{name:i18n["Entity.Operation"],operation:[{text:i18n['Entity.page.edit'],display:true,action:function(data){
  				   var params = {'id':data.id};
  				   var url = editUrl.expand(params);
  				   location.href=url;
  				}},{text:function(data){
  					return data.available==0?i18n["Entity.payMethod.attribute.recovery"]:i18n['Entity.page.Delete'];
  				},dispaly:true,action:function(data){
  					var grid = this;
  					$.msg.confirm(i18n['Page.Dialog.title'],i18n['Entity.payMethod.attribute.execution.confirm'],function(){},{buttons:
  						IFA.generateJson(i18n['ConditionMap.ok'],function(){
  							$.post(updateUrl,{id:data.id,available:(data.available==0?"1":"0"),_method:'PUT'},function(){
  		  						grid.render();
  		  					});
  							$(this).dialog('close');
  						},
  						i18n['ConditionMap.cancel'],function(){
  							$(this).dialog('close');
  						}
  						)});
  				
  				}}]
  				}
  				
  			]
  			
  		
		
	});
	}
	
	function saveSort(){
		console.log($("#sortForm").serialize()); 
	}
	
});