define(function(require){
	var $ = require('jquery');
	require('grid')($);
	var IFA = require('util');
	require('uriTemplate')($);
	require('dialog')($);
    require("../../../styles/cim/jquery-ui-1.8.14.custom.css"); 
    require('../../../styles/cim/cim-grid.css'); 
	$(function(){
		$('#queryRole').bind('click',queryRole);
		$('#createRole').bind('click',createRole);
		queryRole();
	});
	function queryRole()
	{   
		    $('#roleList').grid({
			url: $('#queryUrl').val()+'.json',
			root: 'roleList',
			pageTheme:"Theme1",
			defaultParams: {	                
				'name':$('#name').val().trim()==''?$('#emptyPathVariable').val():$('#name').val().trim(),
				'click': true
				},
			fields: [
	           {id: 'name', name:i18n['System.Role.Name'], width: 200},
	           {id: 'alias', name:i18n['System.Role.Alis'], width: 200},
	           {name:i18n['System.Role.Remark'],width: 450, render: function(data){
		          return $('<div />').html($.abbreviate(data.remark,15)).attr('title', data.remark);
	            }}, 
	           {name:i18n['Entity.Operation'],  width: 180, maxlength: 30, operation: [   
	                                    				{text: i18n['Entity.page.edit'], action: function(data) {
	                                    					var roleCode = data.code;
	                                    					var hiddenUrl = $('#editUrl').val();
	                                    					var urlStr = new $.Template(hiddenUrl);
	                                    					var urlParam = {"code":roleCode};
	                                    					var url = urlStr.expand(urlParam);	
	                                    				    location.replace(url);	
	                                    					}
	                                    				},
	                                    				{text: i18n['Entity.Operation.delete'], confirm:i18n['Entity.Sure.tip'], action: function(data) {
	                                        				var obj = this;
	                                                         //判断是否能删除   
	                                    					var roleCode = data.code;
	                                    					var hiddenUrl = $('#deleteUrl').val();
	                                    					var urlStr = new $.Template(hiddenUrl);
	                                    					var urlParam = {"code":roleCode};
	                                    					var url = urlStr.expand(urlParam);
	                                    					$.ajax({
	                                    						type:"POST",
	                                    						url: url+".json",
	                                    					    data:{_method:'DELETE'},
	                                    						dataType:"json",
	                                    						timeout:5000,
	                                    						success:function(response){
	                                                             if(response.flag)
	                                                             {
	                                                                 $.msg.alert(i18n['Page.Dialog.title'],i18n['System.Role.InUse']);}
	                                                             else
	                                                             {
	                                                            	 $.msg.alert(i18n['Page.Dialog.title'],i18n['Entity.page.Delete.Success'],function(){obj.refresh();});}
	                                    					    },
	                                    						error:function(response){return response;}
	                                    				    });	
	                                    					}
	                                    				}
	                                    			]
	            }
			]
		});
		}
	function createRole()
	{
		var freshUrl = $('#freshUrl').val();
		location.replace(freshUrl);
		}
});