partner.js 3.38 KB
define('admin/partner',function(require, exports)
{
	var box = require('admin/box'); // 提示框
	var $ = require("jquery");
	var common = require("common");
    var upload = require('admin/upload');
	var form_html = $("#form_pan").html()+'';
	$("#form_pan").remove();
    function init_upload(id, callback)
    {
        //绑定上传背景按钮
        upload.init(
        {
            button_placeholder_id:id,
            button_width : "58",
            button_height : "30",
            post_params: {'key':$('#'+id).attr('key'), 'format':'json'},
            custom_settings:
            {
                saveCallback:callback 
            }
        });
    }
    
	function submit()
	{
		var id = $("#id").val();
		var name = $("#name").val();
		var type = $("#type").val();
		var pic = $("#pic").val();
		var description = $("#description").val();
		var url = $("#url").val();
		$.ajax
		({
			type:"post",
			url:"/admin/partner/setpartner",
			data:{id:id,name:name, pic:pic, description:description, url:url, type:type},
			success:function(data)
			{
				if(data.status)
				{
					window.location.reload();
				}
				else
				{
					box.alert("添加失败");
				}
			}
		});
	}
	function init_pic()
	{
		init_upload("upload_pic", function(response, swf)
    	{
   	         if (response.code == 12)
             {
                 var thumbPath = common.getImages(response.data.file.relaPath, "source", "blogimg");
                 var realPath = response.data.file.relaPath;
                 $("#pic").val(realPath).prev().css("margin-top","0px");
                 $("#img").attr("src",thumbPath);
             }
             else
             {
                 box.alert(response.message);
             }
    	});
	}
	exports.info = function()
	{
		//添加
		$("#add_partner").bind("click",function()
		{
			box.confirm
	        (
	            form_html, submit,
	            {
	                title: '添加合作伙伴', 
	                width: '800px', 
	                autoClose: false
	            }
	        );
			init_pic();
		});
		//编辑
		$(".edit_partner").bind("click", function()
		{
			var obj = $(this).parents("tr");
			var id = obj.find("td:eq(0)").text();
			var name = obj.find("td:eq(1)").text();
			var type = obj.find("td:eq(2)").attr("type");
			var url = obj.find("td:eq(3)").text();
			var pic = obj.find("td:eq(4)").children().attr("pic");
			var description = obj.find("td:eq(5)").text();
			var img = obj.find("td:eq(4)").children().attr("src");
			box.confirm
	        (
	            form_html, submit,
	            {
	                title: '编辑合作伙伴', 
	                width: '800px', 
	                autoClose: false
	            }
	        );
			init_pic();
			$("#id").val(id);
			$("#name").val(name);
			$("#pic").val(pic);//.prev().css('margin-top','-60px');
			$("#img").attr("src", img);
			$("#type").val(type);
			$("#description").val(description);
			$("#url").val(url);
		});
		//删除
		$(".del_partner").bind("click", function()
		{
			var id = $(this).attr("partner_id");
			box.confirm('确定删除?',function()
	    	{
	    		$.ajax
	    		({
	    			type:"post",
	    			url:"/admin/partner/del",
	    			data:{id:id},
	    			success:function(data)
	    			{
	    				if(data.status)
	    				{
	    				 	window.location.reload();
	    				}
	    				else
	    				{
	    					box.alert("操作失败");
	    				}
	    			}
	    		});
	    	});
		});
	};
});