index.js 4.51 KB
/**
 * @fileOverview 视频模块
 * @author:Hbomb(zhouqq@yoho.cn)
 * @date:2013-05-27
 */
define('admin/index',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()
    {
        //绑定上传背景按钮
        upload.init(
        {
            button_placeholder_id:"upload_pic",
            button_width : "58",
            button_height : "30",
            post_params: {'key':$("#res").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;
                        
                        $("#res").val(realPath);
                        $("#res").prev().css("margin-top","-30px");
                        $("#res").next().attr("src",thumbPath);
                    }
                    else
                    {
                        box.alert(response.message);
                    }
                }  
            }
        });
    }
    
    $("#add_index").click(function()
    {
        box.confirm
        (
            form_html, submit,
            {
                title: '添加' + $(".active").eq(1).children().text(), 
                width: '770px', 
                autoClose: false
            }
        );  
        init_upload();
    });
    
    $(".del").click(function()
    {
        var id = $(this).attr('val');
        box.confirm("确定要删除这个Banner吗?",function()
        {
            $.ajax
            ({
                type: "post",
                url: '/admin/index/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: '查看' + $(".active").eq(1).children().text(), 
                width: '770px', 
                autoClose: false
            }
        );
        init_upload();
        var obj = $(this).parents("tr");
        var text = obj.find("td:eq(1)").text();
        var sort = obj.find("td:eq(2)").text();
        var res = obj.find("td:eq(3)").attr("relaurl");
        var res_abs = obj.find("td:eq(3) img").attr("src");
        var url = obj.find("td:eq(4)").text();
        var id = obj.find("td:eq(0)").text();
        
        $("#id").val(id);
        $("#text").val(text);
        $("#res").val(res);
        $("#res").next().attr("src",res_abs);
        $("#url").val(url);
        $("#sort").val(sort);
    });
    
    //提交index
    function submit()
    {
        var text = $("#text").val();
        var res = $("#res").val();
        var url = $("#url").val();
        var id =  $("#id").val();
        var sort = $("#sort").val();
        var type = $("#type").val();
        if(text == "")
        {
            alert("标题不能为空!");
            return;
        }
        if(res == "")
        {
            alert("图片不能为空!");
            return;
        }
        if(url=="")
        {
            alert("地址不能为空!");
            return;
        }
        $.ajax
        ({
            type: "post",
            url: '/admin/index/submit',
            data: "id=" + id+
            "&text="+encodeURIComponent(text)+
            "&res="+encodeURIComponent(res)+
            "&url="+encodeURIComponent(url)+
            "&id="+id+
            "&sort="+sort+
            "&type="+type,
            
            success: function(data)
            {
                if (data.code == 200)
                {
                    window.location.reload();
                }
                else
                {
                    box.alert(data.message);
                }
            }
        });
    }
  
    $(".look_v").click(function()
    {
        $(this).next().toggle();
    });
});