categoryManage.js 2.35 KB
/**
 * Created by ty on 2016/5/26.
 */

var $ = require('jquery'),
    common = require('../common/common');
require('../util/jquery.nestable.js');

new common.dropDown({el: "#status"});
new common.dropDown({el: "#platform"});

var Bll = {
    initGrid: function () {
        common.util.__ajax({
            async: false,
            url: "/category/getCategoryList",
            data: {
                platform: common.util.__input("platform"),
                status: common.util.__input("status")
            }
        },function(res) {
            $("#basicTable").html(common.util.__template2($("#grid-template").html(), res));
            $('#author_id, #article_gender, #status,#tag,#is_hot,#platform').select2();
            $('#nestable').nestable();
            $('.dd').nestable('collapseAll');
            $('div[data-toggle="category"]').on('click', function(){
                var sort_id = $(this).parent().data('id');
                $('#addModalBox').on('click', function(){
                    $.get('/cmsproduct/sortattribute/attribute', {sort_id : sort_id}, function(html){
                        $('.modal-dialog').html(html);
                        $('#addModal').modal();
                        $('#attribute_id').select2();
                        $('#addAttribute').on('click', function(){
                            var attribute_id = $('#attribute_id').val();
                            var _text = $('#attribute_id option:selected').text();
                            var _count = $('#attributeBox tr').length;
                            var _html = '<tr><td>'+_text+'<input type="hidden" name="data['+_count+'][attribute_id]" value="'+attribute_id+'" /></td><td><input type="text" name="data['+_count+'][order_by]" style="height:28px;width:60px;" value="" /></td></tr>';
                            $('#attributeBox').append(_html);
                        });
                    });
                });
            });
        }, true);
    }
}

Bll.initGrid();

$(document).on("click", "#filter-btn", function () {
    Bll.initGrid();
});

$(document).on("click", ".updateStatus", function() {
    var id  = $(this).data("id");
    var status = $(this).data("status");
    common.util.__ajax({
        url: "/category/updateCategoryStatus",
        data: {
            id:id,
            status: status
        }
    },function() {
        Bll.initGrid();
    });
});