staticFileManager.js 5.07 KB
/**
 * Created by wangqianjun on 16/5/16.
 * 静态文件管理
 */

var $ = require('jquery');
common = require('../common/common');
datepicker = require('../util/datepicker');

require('../common/umeditor.config');
require('../common/umeditor');
require('../common/zh-cn');

var baidu;

var ENUM = {
    FileTypeEnum: {
        '1': '频道',
        '2': '专题',
        '3': '邮件',
        '4': '推广'
    }
};



new common.dropDown({
    el: "#sel-type"
});

//日期插件
$('.hasDatepicker').fdatepicker({
    format: 'yyyy-mm-dd'
});

var g = new common.grid({
    el: '#basicTable',
    size: 10,
    parms: function () {



        return {

            fileType: $('#sel-type').val(),
            beginTime: common.util.__input('beginTime'),
            endTime: common.util.__input('endTime')

        };
    },
    columns: [{
        display: 'ID',
        name: "id"
    },  {
        display: '标题',
        name: "pageTitle"
    },
        {
            display: '类型',
            render: function (item) {
                return "<p>" + ENUM.FileTypeEnum[item.fileType] + "</p>";
            }
        },
        //{
        //    display: '审核返币',
        //    render: function (item) {
        //        return "<p>" + ENUM.RewardEnum[item.shareReward] + "</p>";
        //    }
        //},
        //{
        //    display: '推荐状态',
        //    render: function (item) {
        //        return "<p>" + ENUM.RecommendEnum[item.recomReward] + "</p>";
        //    }
        //},

        {
            display: "添加时间",

            render: function (item) {
                var t = new Date(item.createTime * 1000);
                var formatted = common.util.__dateFormat(t, "yyyy-MM-dd hh:mm:ss");
                return "<p>" + formatted + "</p>";
            }
        },{
            display: "修改时间",

            render: function (item) {
                var t = new Date(item.updateTime * 1000);
                var formatted = common.util.__dateFormat(t, "yyyy-MM-dd hh:mm:ss");
                return "<p>" + formatted + "</p>";
            }
        },
        {
            display: '操作',
            //}
            render: function (items) {
                var HtmArr = [];

                HtmArr.push('<a data-index="' + items.__index + '"  href="JavaScript:;" class="btn btn-info btn-xs info-modify">编辑</a>');
                HtmArr.push('<a data-index="' + items.__index + '"  href="JavaScript:;" class="btn btn-danger btn-xs info-del">删除</a>');

                return HtmArr.join('');
            }
        }
    ]
});
g.init('/staticFileManage/queryByCondition');


//添加
$(document).on('click', '#add', function () {
    staticFileOP("新增", '/staticFileManage/add', {});

});

//删除
$(document).on('click', '.info-del', function () {
    var item = g.rows[$(this).data("index")];

    common.dialog.confirm("温馨提示", "确定要删除吗?", function () {
        common.util.__ajax({
            url: '/staticFileManage/deleteById',
            data: {
                id: item.id
            }
        }, function (res) {
            if (res.code == 200) {
                g.reload();
            } else {
                common.util.__tip(res.message);
            }
        });
    });
});

// 查询
$(document).on('click', '#filter', function () {
    g.reload();
});


//编辑
$(document).on('click', '.info-modify', function () {
    var item = g.rows[$(this).data("index")];
    staticFileOP("编辑", '/staticFileManage/update', item);
});

function staticFileOP(prefix, url, item) {

    var a = new common.edit(".confirm", {
        //"bucket" : "author"
    });

    var dialog = new common.dialog({
        width: '70%',
        title: prefix + '静态文件',
        content: common.util.__template2($("#template").html(), item),
        button: [{
            value: '提交',
            callback: function () {

                common.util.__ajax({
                    url:url,
                    data:{
                        id: $('#id').val(),
                        fileType: $('#fileType').val(),
                        pageTitle: $('#pageTitle').val(),
                        keyWord: $('#keyWord').val(),
                        pageDesc: $('#pageDesc').val(),
                        content: baidu.getContent()
                    }
                }, function (res) {
                    //res=res.data;
                    if(res.code=="200"){
                        dialog.close();
                        g.reload();
                        return true;
                    }else{
                        return false;
                    }
                });

                return false;
            }
        }]

    });

    ////下拉框
    //new common.dropDown({
    //    el: "#fileType"
    //});

    baidu && baidu.destroy();
    baidu = UM.getEditor('content');

    if (prefix == '编辑') {
        baidu.setContent(item.content);

        //$("#fileType option").each(function() {
        //    return this.text == ENUM.FileTypeEnum[item.fileType];
        //}).prop('selected', true);

    }


    a.init();
}