snap.js 5.08 KB
/**
 * @fileOverview snap模块
 * @author:Hbomb(zhouqq@yoho.cn)
 * @date:2013-05-27
 */
define('snap',function(require, exports)
{
    var box = require('box'); // 提示框
    var $ = require("jquery");
    var common = require("common");
    var upload = require('admin/upload');
    var form_html = $("#form_pan").html()+'';
    $("#form_pan").remove();
    $("#add_snap").click(function()
    {
        box.confirm
        (
            form_html, submit,
            {
                title: '添加SNAP', 
                width: '750px', 
                autoClose: false
            }
        );
        $('#create_time').click(function()
        {
            WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'});
        });
        //绑定上传背景按钮
        upload.init(
        {
            button_placeholder_id:"upload_pics",
            button_width : "58",
            button_height : "30",
            post_params: {'key':$("#upload_pics").attr('key'), 'format':'json'},
            custom_settings:
            {
                saveCallback:function(response,swf)
                {
                    if (response.code == 12)
                    {
                        var thumbPath = common.getImages(response.data.file.relaPath, "0200x0150", "blogimg", "primary");
                        var realPath = response.data.file.relaPath;
                        
                        $("#pic").val(realPath);
                        $("#pic").next().attr("src",thumbPath);
                    }
                    else
                    {
                        box.alert(response.message);
                    }
                }  
            }
        });
        
    });
    
    $(".del").click(function()
    {
        var id = $(this).attr('val');
        box.confirm("确定要删除这个SNAP吗?",function()
        {
            $.ajax
            ({
                type: "post",
                url: '/admin/snap/del',
                data: "id="+id,
                success: function(data)
                {
                    if (data.code == 200)
                    {
                        window.location.reload();
                    }
                    else
                    {
                        box.alert(data.message);
                    }
                }
            });
        });
    });
    
    //查看
    $(".look").click(function()
    {
        box.confirm
        (
            form_html, submit,
            {
                title: '查看SNAP', 
                width: '750px', 
                autoClose: false
            }
        );
        
        $('#create_time').click(function()
        {
            WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'});
        });
        
        var obj = $(this).parents("tr");
        var pic = obj.find("td:eq(1) img").attr("rel");
        var pic_abs = obj.find("td:eq(1) img").attr("src");
        var text = obj.find("td:eq(2)").text();
        var id = obj.find("td:eq(0)").text();
        var create_time = obj.find("td:eq(3)").text();
        $("#id").val(id);
        $("#text").val(text);
        $("#pic").val(pic);
        $("#pic").next().attr("src",pic_abs);
        $("#create_time").val(create_time);
        
        //绑定上传背景按钮
        upload.init(
        {
            button_placeholder_id:"upload_pics",
            button_width : "58",
            button_height : "30",
            post_params: {'key':$("#upload_pics").attr('key'), 'format':'json'},
            custom_settings:
            {
                saveCallback:function(response,swf)
                {
                    if (response.code == 12)
                    {
                        var thumbPath = common.getImages(response.data.file.relaPath, "0200x0150", "blogimg", "primary");
                        var realPath = response.data.file.relaPath;
                        
                        $("#pic").val(realPath);
                        $("#pic").next().attr("src",thumbPath);
                    }
                    else
                    {
                        box.alert(response.message);
                    }
                }  
            }
        });
    });
    
    //提交SNAP
    function submit()
    {
        var text = $("#text").val();
        var pic = $("#pic").val();
        var id =  $("#id").val();
        var create_time = $("#create_time").val();
        if(pic=="")
        {
            alert("图片不能为空!");
            return;
        }
        $.ajax
        ({
            type: "post",
            url: '/admin/snap/submit',
            data: "id=" + id+
            "&text="+encodeURIComponent(text)+
            "&pic="+encodeURIComponent(pic)+
            "&create_time="+encodeURIComponent(create_time),
            success: function(data)
            {
                if (data.code == 200)
                {
                    window.location.reload();
                }
                else
                {
                    box.alert(data.message);
                }
            }
        });
    }
  
    $(".look_v").click(function()
    {
        $(this).next().toggle();
    });
});