{"size": 2122, "ext": "js", "max_stars_repo_path": "packages/framework/assets/js/admin/components/fileUploadPreview.js", "max_stars_repo_name": "sspooky13/shopsys", "max_stars_repo_stars_event_min_datetime": "2018-04-12T13:55:14.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-01T11:16:06.000Z", "max_issues_repo_path": "packages/framework/assets/js/admin/components/fileUploadPreview.js", "max_issues_repo_name": "sspooky13/shopsys", "max_issues_repo_issues_event_min_datetime": "2018-04-12T13:12:35.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T19:12:12.000Z", "max_forks_repo_path": "packages/framework/assets/js/admin/components/fileUploadPreview.js", "max_forks_repo_name": "sspooky13/shopsys", "max_forks_repo_forks_event_min_datetime": "2018-04-12T13:55:46.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-24T07:27:30.000Z"}
{"max_stars_count": 296, "max_issues_count": 1906, "max_forks_count": 116, "avg_line_length": 35.3666666667, "max_line_length": 85, "alphanum_fraction": 0.5589066918}
import 'jquery-ui/sortable';
import 'jquery-ui/ui/widgets/mouse';
import 'jquery-ui-touch-punch';
import formChangeInfo from './FormChangeInfo';
import { select, deselect, getSelectedValues } from './choiceControl';
import Register from '../../common/utils/Register';

export default class FileUploadPreview {

    static initDelete () {
        $('.js-file-upload-file').each(function () {
            const $file = $(this);
            const $filePreview = $file.find('.js-file-upload-preview');
            const $deleteButton = $file.find('.js-file-upload-delete-button');
            const $revertButton = $file.find('.js-file-upload-delete-revert-button');
            const $deleteInfo = $file.find('.js-file-upload-file-overlay');
            const fileId = $file.data('id');

            $deleteButton.on('click.deleteFile', () => {
                select($file.data('delete-input'), fileId);
                $filePreview.addClass('list-files__item__in--removed');
                $deleteButton.hide();
                $revertButton.show();
                $deleteInfo.show();
                formChangeInfo.showInfo();
                return false;
            });

            $revertButton.on('click.deleteFile', () => {
                deselect($file.data('delete-input'), fileId);
                $filePreview.removeClass('list-files__item__in--removed');
                $deleteButton.show();
                $revertButton.hide();
                $deleteInfo.hide();
                return false;
            });

            const fileIds = getSelectedValues($file.data('delete-input'));
            if ($.inArray(fileId, fileIds) !== -1) {
                $deleteButton.trigger('click.deleteFile');
            }
        });
    }

    static initSort () {
        $('.js-file-upload').sortable({
            handle: '.js-file-upload-file-handle',
            update: formChangeInfo.showInfo
        });
    }

    static init () {
        FileUploadPreview.initDelete();
        FileUploadPreview.initSort();
    }

}

(new Register()).registerCallback(FileUploadPreview.init, 'FileUploadPreview.init');
