/*   
 * @Author              : Kazol 
 * @CreatedDate         : 22-07-2017  
 * @ModifiedDate        : 
 * @ModifiedBy          : 
 * @Route               : search-admin-video-course
 * @Description         : The function is used for search language by ajax in video course add
 * @view                : 
 * @redirect            : 
 * @deprecated          : 
 * @exception           : 
 * @inheritDoc          : 
 * @Parameter           : 
 * @Return              :      
 * @value               : 
 * @Status              : active
 * @version             : v2.1         
 */
$(document).ready(function () {

    
    /*   
     * @Author              : Kazol 
     * @CreatedDate         : 26-07-2017  
     * @ModifiedDate        : 
     * @ModifiedBy          : 
     * @Route               : pagination-admin-video-course
     * @Description         : The function is used for pagination the video course
     * @view                : 
     * @redirect            : 
     * @deprecated          : 
     * @exception           : 
     * @inheritDoc          : 
     * @Parameter           : 
     * @Return              :      
     * @value               : 
     * @Status              : active
     * @version             : v2.1         
     */
    $(document).on('click', "a[id^=video_course_pagination]", function () {
        var page_number = this.id.replace('video_course_pagination', '');
        var baseUrl = $('#baseUrl').val();
        var sort_by = $('#sort_by').val();
        //console.log(sort_by);
        var search_value = $('#search_video_course').val();
        
        var video_course_status = $('#video_course_search_by_status').val();
        var video_status = (video_course_status === '') ? 0 : video_course_status;

        var video_course_search_type = $('#video_course_search_type').val();
        var video_course_type = (video_course_search_type === '') ? 0 : video_course_search_type;

        if(search_value != '' || (search_value == '' && video_status != '0') ||(search_value == '' && video_course_type != '0')){
            var searchInput = (search_value.replace(/  +/g, ' ')).trim();
            var url = baseUrl + 'search-admin-video-course';
            
            var formdata = new FormData(); 
            formdata.append("video_course_publication_status", video_status);
            formdata.append("video_course_payment_type", video_course_type);
            formdata.append("video_course_name", searchInput);
            formdata.append("page_number", page_number);
            formdata.append("sort_by", sort_by);
        }
        else{
            var url = baseUrl + 'pagination-admin-video-course';
            var formdata = new FormData(); 
            formdata.append('page_number', page_number);
            formdata.append('sort_by', sort_by);
        }

        $.ajax({
            url: url,
            type: "POST",
            data: formdata,
            contentType: false,
            cache: false,
            processData: false,
            success: function (data)
            {
                $('#view_video_courses').html(data);
            }
        });    
    });

});

/*   
 * @Author              : Kazol 
 * @CreatedDate         : 26-07-2017  
 * @ModifiedDate        : 
 * @ModifiedBy          : 
 * @Route               : search-admin-video-course
 * @Description         : The function is used for search video course
 * @view                : 
 * @redirect            : 
 * @deprecated          : 
 * @exception           : 
 * @inheritDoc          : 
 * @Parameter           : 
 * @Return              :      
 * @value               : 
 * @Status              : active
 * @version             : v2.1         
 */
function getVideoCourseSearchValue(search_value, url) {
    var searchInput = (search_value.replace(/  +/g, ' ')).trim();
    
    var video_course_status = $('#video_course_search_by_status').val();
    var video_status = (video_course_status === '') ? 0 : video_course_status;
    
    var video_course_search_type = $('#video_course_search_type').val();
    var video_course_type = (video_course_search_type === '') ? 0 : video_course_search_type;
    
    var formdata = new FormData(); 
    formdata.append("video_course_publication_status", video_status);
    formdata.append("video_course_payment_type", video_course_type);
    formdata.append("video_course_name", searchInput);
    
    $.ajax({
        url: url,
        type: "POST",
        data: formdata,
        contentType: false,
        cache: false,
        processData: false,
        success: function (data)
        {
            $('#view_video_courses').html(data);
        }
    });
}

function get_video_course_status(video_course_status, url){
    var video_status = (video_course_status === '') ? 0 : video_course_status;
    
    var video_course_search_type = $('#video_course_search_type').val();
    var video_course_type = (video_course_search_type === '') ? 0 : video_course_search_type;
    
    var search_value = $('#search_video_course').val();
    var searchInput = (search_value.replace(/  +/g, ' ')).trim();
    
    var formdata = new FormData(); 
    formdata.append("video_course_publication_status", video_status);
    formdata.append("video_course_payment_type", video_course_type);
    formdata.append("video_course_name", searchInput);
    
    $.ajax({
        url: url,
        type: "POST",
        data: formdata,
        contentType: false,
        cache: false,
        processData: false,
        success: function (data)
        {
            $('#view_video_courses').html(data);
        }
    });
}

function get_video_course_by_type(video_course_search_type, url){
    var video_course_type = (video_course_search_type === '') ? 0 : video_course_search_type;
    
    var video_course_status = $('#video_course_search_by_status').val();
    var video_status = (video_course_status === '') ? 0 : video_course_status;
    
    var search_value = $('#search_video_course').val();
    var searchInput = (search_value.replace(/  +/g, ' ')).trim();
    
    var formdata = new FormData(); 
    formdata.append("video_course_publication_status", video_status);
    formdata.append("video_course_payment_type", video_course_type);
    formdata.append("video_course_name", searchInput);
    
    $.ajax({
        url: url,
        type: "POST",
        data: formdata,
        contentType: false,
        cache: false,
        processData: false,
        success: function (data)
        {
            $('#view_video_courses').html(data);
        }
    });
    
    
}
/*   
 * @Author              : Kazol 
 * @CreatedDate         : 23-08-2017  
 * @ModifiedDate        : 
 * @ModifiedBy          : 
 * @Route               : video-course-status-change
 * @Description         : The function is used for changing the video course status
 * @view                : 
 * @redirect            : 
 * @deprecated          : 
 * @exception           : 
 * @inheritDoc          : 
 * @Parameter           : url, ID, type
 * @Return              :      
 * @value               : 
 * @Status              : active
 * @version             : v2.1         
 */
function changeVideoCourseStatus(url, ID, type) {
    var formdata = new FormData();
    formdata.append("video_course_id", ID);
    formdata.append("change_status", type);
    swal({
        title: "",
        text: "Are you sure you want to " + type + " this Video?",
        showCancelButton: true,
        confirmButtonColor: '#73AE28',
        confirmButtonText: 'Yes',
        cancelButtonText: "No",
        closeOnConfirm: true,
        closeOnCancel: true
    },
    function(isConfirm){
        if(isConfirm){
            $.ajax({
                url: url,
                type: "POST",
                data: formdata,
                contentType: false,
                cache: false,
                processData: false,
                success: function ()
                {
                    location.reload();
                }
            });
        }
    });
}
