/**
 * Created by Administrator on 2018/7/6.
 */
var _token = LA.token;

(function($){

})(jQuery);

function edit_config(t){
    var id = $(t).attr('en_id');
    var en_obj = $("div.config[en_id="+id+"]");
    var _method = en_obj.find('input[name=_method]').val();
    //var name = en_obj.find('input[name=type]').val();
    var value = en_obj.find('input[name=value]').val();
    var description = en_obj.find('input[name=description]').val();
    var data = {
        id : id,
        _method : _method,
        _token : _token,
        value : value,
        description : description
    };

    $.ajax({
        method: 'POST',
        url: '/admin/smgconfig/'+id,
        data: data,
        success: function (ret) {
            location.reload();
        }
    });


}

function add_config(t){
    var group_id = $(t).attr('group_id');
    var en_obj = $("div.addconfig[group_id="+group_id+"]");
    var name = en_obj.find('input[name=name]').val();
    var value = en_obj.find('input[name=value]').val();
    var description = en_obj.find('input[name=description]').val();
    var data = {
        _token : _token,
        group_id : group_id,
        name : name,
        value : value,
        description : description
    };

    $.ajax({
        method: 'POST',
        url: '/admin/smgconfig',
        data: data,
        success: function (ret) {
            location.reload();
        }
    });

}

function del_config(t){
    var id = parseInt($(t).attr('en_id'));
    var en_obj = $("div.config[en_id="+id+"]");

    if(confirm('确定要删除吗?')) {
        var _token = en_obj.find('input[name=_token]').val();
        var data = {
            _token: _token,
            id: id
        };

        $.ajax({
            method: 'DELETE',
            url: '/admin/smgconfig/' + id,
            data: data,
            success: function (ret) {
                location.reload();
            }
        });

    }
}

function del_category(t){
    var group_id = parseInt($(t).attr('group_id'));
    var en_obj = $("div.addconfig[group_id="+group_id+"]");

    if(confirm('确定要删除吗?')) {

        var data = {
            _token: _token,
            group_id: group_id,
            del:'category'
        };


        $.ajax({
            method: 'DELETE',
            url: '/admin/smgconfig/' + group_id,
            data: data,
            success: function (ret) {
                location.reload();
            }
        });

    }
}


function edit_category(t) {
    var group_id = parseInt($(t).attr('group_id'));
    var en_obj = $("div.edit_category[group_id="+group_id+"]");
    var category_name = en_obj.find('input[name=category_name]').val();
    var data = {
        _token : _token,
        _method : 'PUT',
        edit: 'categorie',
        group_id : group_id,
        category_name : category_name
    };

    $.ajax({
        method: 'POST',
        url: '/admin/smgconfig/'+group_id,
        data: data,
        success: function (ret) {
            location.reload();
        }
    });

}
