favorite.editorial.page.js 1.96 KB
/**
 *
 * @author: jiangfeng<jeff.jiang@yoho.cn>
 * @date: 16/7/20
 */
var dialog = require('../plugins/dialog');
var _confirm = dialog.Confirm;


var FavoriteEditorial = {
    init: function() {
        var $root = $('.favorite-editorials');

        require('./me');
        require('../plugins/check');

        $('.check', $root).check({
            type: 'checkbox',
            onChange: function(ele, checked) {
                if (checked) {
                    $(ele).parent().addClass('choose');
                } else {
                    $(ele).parent().removeClass('choose');
                }
            }
        });

        $('.check-all', $root).check({
            type: 'checkbox',
            onChange: function(ele, checked) {
                if (checked) {
                    $('.check', $root).check('checkAll');
                } else {
                    $('.check', $root).check('unCheckAll');
                }
            }
        });

        $('.fav-cancel', $root).click(function() {
            var id = $(this).parent().data('id');

            FavoriteEditorial.doCancel(id);
        });

        $('.favorite-cancel', $root).click(function() {
            var ids = [];

            $('.editorial-raw.choose', $root).each(function() {
                ids.push($(this).data('id'));
            });

            FavoriteEditorial.doCancel(ids.join(','));
        });
    },
    _showConfirm: function(cb) {
        new _confirm({
            content: '<h1 class="title">确认删除</h1><p>您确定要删除该收藏么?</p>',
            cb: cb
        }).show();
    },
    doCancel: function(ids) {
        this._showConfirm(function() {
            $.post('/me/collection/editorial/cancel', {
                ids: ids
            }, function(data) {
                if (data.code === 200) {
                    location.href = '/me/collection/editorial';
                }
            });
        });
    }
};


$(function() {
    FavoriteEditorial.init();
});