define(function(require){
	var $ = require('jquery');
	require('grid')($);
    require('uriTemplate')($);
    require('dialog')($);
   // require('datepicker')($);
	var IFA = require('util');
	require("../../../styles/cim/jquery-ui-1.8.14.custom.css");
	require('../../../styles/cim/cim-grid.css');   
	var editAuthority = $("#editAuthority").val();
	var detailAuthority = $("#detailAuthority").val();
	require('globalization');
	$(function(){
		search();
		$("#searchBtn").bind("click",search);
		$("#searchForm :input").bind("keydown",function(e){
			var e = e ? e : window.event;
			if(e.keyCode==13){
			   search();
			}
		});
	});

	function search(){
		var url=$("#searchUrl").val().trim();
		$("#dataList").grid({
			url:url,
			root:"productPriceList",
			pageTheme:'Theme1',
			isREST :false,
			method:"POST",
			defaultParams:{serviceId:$('#serviceKey').val()},
			fields:[{name:i18n["Entity.product.serviceId"],style:{width:"10%"},render:function(data){
					    var serId='';
		                var dataId=data.serviceId;
		                if(dataId.length>20){
		                	serId=dataId.substring(0,20)+"...";
		                }else{
		                	serId=dataId;
		                    }
		 			    if(detailAuthority=="true"){
		 			    return $('<a href="#" title='+data.serviceId+' class="bb"/>').html(serId).click(function(){
		  				    showDetail(data);
		     			    });
		 			    }else{
		 			    return 	serId;
		 			    }
			        }},
			        {name:i18n["Entity.product.serviceDescription"],style:{width:"15%"},id:"serviceDescription"},
			        {name:i18n["Page.workOrder.oilCharge"],style:{width:"15%"},render:function(data){
			        	var oilCharge = 0;
			        	if(data.oilCharge!=null&&data.oilCharge!=""){
			        		oilCharge=data.oilCharge;
			        	}
			        	return Globalize.format(oilCharge,'n2');		;
			        }},
			        {name:i18n["Entity.Operation"],style:{width:"20%"},operation:[
			                                                  {text:i18n["Entity.Operation.edit"],display:function(){
			                                                	  if(editAuthority=="true"){
			                                                		  return true;
			                                                	  }else{
			                                                		  return false;
			                                                	  }
			                                                  },action:function(data){
			                                                	  var id = data.serviceId;
			                                      			      var urlVal = $('#editUrl').val();
			                                      			      var urlStr = new $.Template(urlVal);
			                                      				  var urlParam = {"id":id};
			                                      				  var url = urlStr.expand(urlParam);	
			                                      			      location.replace(url);	
			                                                  }}
			                                                  ]}
			        ]
			});
	}
		      
		function showDetail(data){
		    var id = data.serviceId;
		    var hiddenUrl = $('#detailUrl').val();
			var urlStr = new $.Template(hiddenUrl);
			var urlParam = {"id":id};
			var url = urlStr.expand(urlParam);	
		    location.replace(url);	
}
});