script.js 3.64 KB
$(function() {
    $(document)
        .on('click', '.export-link', function(e) {
            e.preventDefault();
            var url = $(this)
                .data('url');
            var file = $(this)
                .data('file');
            var interval = showProgress();
            $.get(url, function(data) {
                clearInterval(interval);
                var progressBar = $('#export-progress');
                var progressValueBar = progressBar.find('.progress-bar')
                                                  .first();
                progressValueBar.width('100%');
                progressValueBar.attr('aria-valuenow', 100);
                progressValueBar.removeClass('active');
                if (data.success) {
                    var exportLink = $('#export-link');
                    exportLink.removeClass('hidden');
                    exportLink.find('a')
                              .attr('href', file);
                } else {
                    progressValueBar.addClass('progress-bar-danger');
                }
            })
             .fail(function(xhr, textStatus) {
                 clearInterval(interval);
                 console.log(textStatus);
                 var progressBar = $('#export-progress');
                 var progressValueBar = progressBar.find('.progress-bar')
                                                   .first();
                 progressValueBar.width('100%');
                 progressValueBar.attr('aria-valuenow', 100);
                 progressValueBar.removeClass('active');
                 progressValueBar.addClass('progress-bar-danger');
            });
        });
});
function showProgress() {
    var progressBar = $('#export-progress');
    var progressValueBar = progressBar.find('.progress-bar')
                                      .first();
    progressValueBar.removeClass('progress-bar-danger');
    progressValueBar.addClass('active');
    progressBar.removeClass('hidden');
    var progress = 0;
    progressValueBar.width(0 + '%');
    progressValueBar.attr('aria-valuenow', progress);
    var exportLink = $('#export-link');
    exportLink.addClass('hidden');
    var interval = setInterval(function() {
        progress = progressValueBar.attr('aria-valuenow');
        if (progress < 100) {
            progress = Number(progress) + 5;
            progressValueBar.width(progress + '%');
            progressValueBar.attr('aria-valuenow', progress);
        }
        if (progress > 90) {
            clearInterval(interval);
        }
    }, 1000);
    return interval;
}

$(document)
    .on(
        'click', '#add-category-btn', function() {
            var button = $(this);
            $.ajax(
                {
                    type: "POST",
                    url: "/admin/product-option-group-exclusion/get-row",
                    data: {
                        id: button.attr('data-id'),
                        title: button.attr('data-title')
                    },
                    success: function(data) {
                        $('.jambo_table tbody')
                            .append(data);
                        $('input.flat')
                            .iCheck(
                                {
                                    checkboxClass: 'icheckbox_flat-green',
                                    radioClass: 'iradio_flat-green'
                                }
                            );
                    }
                }
            );
        }
    );

$(document)
    .on(
        'click', '.jambo_table .delete-row', function() {
            $(this)
                .parent()
                .parent()
                .remove();
        }
    );