(function()
{
	//-------------------------------------------------
	//Start: 获取模板路径，并加到helper中
	var __p = $('script:last').attr('src');
	__p = __p.substr(0, __p.lastIndexOf('/js/module.js') + 1);
	_helper.addInit(__p, init);
	//End: 获取模板路径，并加到helper中
	//-------------------------------------------------
	
	//-------------------------------------------------
	//Start: 辅助函数
	//词典中，获取关键字对应的值
	function w(k){return _helper.dict(__p, k);}
	//获取对象名称
	function o(f){return f.toString().match(/^function (\w+)\(/)[1];}
	//获取页面变量值
	function v(p, n){return $('>section', p).data(n);}
	//End: 辅助函数
	//-------------------------------------------------

	//-------------------------------------------------
	//Start: 初始化
	function init(instance, page, panel)
	{
		if (page == 'channel_list')
		{
			//创建对象
			var channel = new Channel(instance, panel);

			//绑定事件
			//$('.recycle,.delete,.recover', panel).click(supplier.update);
		}
		else if (page == 'channel_add')
		{
			//创建对象
			var channel = new Channel(instance, panel);

			//绑定事件
			$('form:first', panel).submit(channel.add);
		}
		else if (page == 'channel_edit')
		{
			//创建对象
			var channel = new Channel(instance, panel);
			
			//绑定事件
			$('form:first', panel).submit(channel.modify);
		}
	}
	//End: 初始化
	//-------------------------------------------------


	//-------------------------------------------------
	//Start: 供应商
	function Channel(instance, panel)
	{
		var __object = o(arguments.callee);

		this.add = function()
		{
			var data = prepareData(this);
			if (data == null)
				return false;

			_helper.post({instance:instance,object:__object,operation:'Add',data:data});

			return false;
		};
		
		this.modify = function()
		{
			var data = prepareData(this);
			if (data == null)
				return false;

			var id = v(panel, 'id');
			_helper.post({instance:instance,object:__object,operation:'Modify',data:data,params:'ID=' + id});

			return false;
		};
		
		function prepareData(form)
		{
			if ($.trim(form.Name.value) == '')
			{
				ali.error(w('name_empty'), $.proxy(function(){form.Name.select();}, this));
				return null;
			}
		
			var data = _helper.serialize(form);
			
			return data;
		}
	}
	//End: 供应商
	//-------------------------------------------------
})();

































