
/* 
 * @author      : Kazol
 * @createdDate : 21/06/2017
 * @description : for video ordering for video course
 * */
$(document).ready(function () {
    var divID;
    var baseUrl = $('#baseUrl').val();

    /* 
     * @author      : Kazol
     * @createdDate : 21/06/2017
     * @description : for Move Video
     * */
   
    $(document).on('click', 'a[id^="btnMove"]', function () {
        $('#viewVideoOrder').fadeIn('slow');
        var output = '<option value="">Select Order</option>';
        var ID = divID = this.id.replace('btnMove', '');
        var totalDiv = Number($('#viewVideoFile').children('div[id=singleVideoFile]').length);
        var incValue = Number($('#incValue' + ID).val());
        $('#random_number').val(ID);

        if (incValue === 1) {
            output += '<option value="2">After</option><option value="3">Bottom</option>';
        } else if (incValue === totalDiv) {
            output += '<option value="1">Top</option><option value="2">After</option>';
        } else {
            output += '<option value="1">Top</option><option value="2">After</option><option value="3">Bottom</option>';
        }
        $('#order').html(output);
    });

    /* 
     * @author      : Kazol
     * @createdDate : 21/06/2017
     * @description : select video order
     * */
    
    $(document).on('change', 'select[id="order"]', function () {
        $('#order_error').html('').fadeOut('slow');
        var order = Number($('#' + this.id).val());
        var output = '<option value="">Select File Name</option>';

        if (order === 2) {
            $('#VideoNameView').fadeIn('slow');
            var serverUrl = baseUrl + 'user/course/get-work-file/' + divID;

            $.get(serverUrl, function (data) {
                var workFile = JSON.parse(data);

                for (var i = 0; i < workFile.id.length; i++) {
                    output += '<option value="' + workFile.id[i] + '">' + workFile.file_name[i] + '</option>';
                }

                $('#selected_file').html(output);
            });
        } else {
            $('#VideoNameView').fadeOut('slow');
        }
    });

    /* 
     * @author      : Kazol
     * @createdDate : 21/06/2017
     * @description : select video order field validation
     * */
    $(document).on('change', 'select[id="selected_file"]', function () {
        if ($('#selected_file').val() !== '') {
            $('#selected_file_error').fadeIn('slow').html('');
        } else {
            $('#selected_file_error').fadeIn('slow').html('');
        }
    });
   /* 
     * @author      : Kazol
     * @createdDate : 21/06/2017
     * @description : cancel video file process
     * */
    $(document).on('click', 'button[id="CancelBtn"]', function () {
        $('#order').val('');
        $('#selected_file').val('');
        $('#VideoNameView').fadeOut('slow');
        $('#viewVideoOrder').fadeOut('slow');
    });

    /* 
     * @author      : Kazol
     * @createdDate : 21/06/2017
     * @description : delete video
     * */
    $(document).on('click', 'a[id^="btnDelete"]', function () {
        var ID = this.id.replace('btnDelete', '');
        $('#viewDeleteVideoFile' + ID).modal('show');
    }).on('click', 'button[id^="modalNoButton"]', function () {
        var ID = this.id.replace('modalNoButton', '');
        $('#viewDeleteVideoFile' + ID).modal('hide');
    }).on('click', 'button[id^="modalYesButton"]', function () {
        var ID = this.id.replace('modalYesButton', '');
        var serverUrl = baseUrl + '';

        $.post(serverUrl, {id: ID}, function (data) {
            location.reload();
        });
    });
});




