消息(警报)要求确认

时间:2019-05-26 12:22:06

标签: php laravel laravel-5

我是JS的初学者。

我有此代码:

            var fileLimit = parseInt(1);

            function refreshFileList() {
                $(".dz-preview").remove();
                $.ajax({
                    url: 'http://test/admin/showFilesDJS?type=SplashImage&id=1',
                    type: 'get',
                    dataType: 'json',
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                    },
                    cache: false,
                    success: function (response) {

                        $.each(response, function (key, value) {
                            var mockFile = {
                                name: value.name,
                                size: value.size
                            };
                            dpzMultipleFiles.emit('addedfile', mockFile);
                            dpzMultipleFiles.emit('thumbnail', mockFile, value.path);
                            dpzMultipleFiles.emit('complete', mockFile)
                        })
                    },
                    error: function (response) {
                        alert('Nastąpił problem z JSON. Proszę o kontakt z administratorem serwisu.');
                    }
                });
            }


            Dropzone.options.dpzMultipleFiles =
                {
                    maxFiles: fileLimit,
                    clickable: true,
                    thumbnailWidth: 250,
                    thumbnailHeight: 250,
                    autoProcessQueue: true,
                    dictDefaultMessage: '',
                    uploadMultiple: true,
                    paramName: "myFile",
                    acceptedFiles: ".jpg,.jpeg",
                    addRemoveLinks: true,
                    timeout: 50000,
                    dictRemoveFile: 'Usuń plik',

                    init: function () {
                        dpzMultipleFiles = this;
                        refreshFileList();

                        this.on("thumbnail", function (file, dataUrl) {
                            $('.dz-image').last().find('img').attr({width: '100%', height: '100%'});
                        }),

                            this.on('completemultiple', function (file, json) {
                                //$('.sortable').sortable('enable');
                            });
                        this.on('success', function (file, json) {
                            //alert('aa');
                        });

                        this.on('addedfile', function (file) {
                            fileLimit = fileLimit - 1;
                        });

                        this.on('drop', function (file) {
                            fileLimit = fileLimit + 1;
                        });

                        this.on("maxfilesexceeded", function (file) {
                            alert('Plik ' + file.name + ' nie został wysłany na serwer. Limit plików został przekroczony!')
                            this.removeFile(file);
                        });
                    },


                    removedfile: function (file) {
                        $.ajax({
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                            },
                            cache: false,
                            type: 'POST',
                            url: 'http://test/admin/deleteDJS?id=' + file.name + 'type=SplashImage',
                            data: {filename: file.name, id: file.name, type: 'SplashImage'},
                            success: function (data) {
                                console.log("File has been successfully removed!!");
                                //refreshFileList();
                            },
                            error: function (e) {
                                console.log(e);
                            }
                        });

                        var fileRef;
                        return (fileRef = file.previewElement) != null ?
                            fileRef.parentNode.removeChild(file.previewElement) : void 0;
                    }
                };
            $(function () {
                $(".dropzone").sortable({
                    items: '.dz-preview',
                    cursor: 'move',
                    opacity: 0.5,
                    containment: '.dropzone',
                    distance: 20,
                    tolerance: 'pointer',
                    update: function (event, ui) {
                        $(".dz-filename span").each(function (index) {
                            $.ajax({
                                headers: {
                                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                                },
                                url: 'http://test/admin/changeOrderFilesDJS?type=SplashImage&id=1&index='+index+'&file='+ $(this).text(),
                                dataType: 'text',
                                type: 'post',
                                cache: false,
                                data: $(this).serialize(),
                                success: function (data, textStatus, jQxhr) {
                                },
                                error: function (jqXhr, textStatus, errorThrown) {
                                    alert('Nastąpił problem z JSON. Proszę o kontakt z administratorem serwisu.');
                                }
                            });
                        });
                    }
                });
            });

这是Dropzone.JS。这段代码可以正常工作。

我想在单击删除按钮后添加(usuńplik)-问题:您真的要删除此文件吗?只有在单击“是”后,该文件才会被删除。

该怎么做?我需要一个有关JS中问题的简单警报

3 个答案:

答案 0 :(得分:2)

您可以在删除功能中添加确认:

                    removedfile: function (file) {
                        if (!confirm('Are you sure?')) {
                            return;
                        } 
                        $.ajax({
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                            },
                            cache: false,
                            type: 'POST',
                            url: 'http://test/admin/deleteDJS?id=' + file.name + 'type=SplashImage',
                            data: {filename: file.name, id: file.name, type: 'SplashImage'},
                            success: function (data) {
                                console.log("File has been successfully removed!!");
                                //refreshFileList();
                            },
                            error: function (e) {
                                console.log(e);
                            }
                        });

                        var fileRef;
                        return (fileRef = file.previewElement) != null ?
                            fileRef.parentNode.removeChild(file.previewElement) : void 0;
                    }

答案 1 :(得分:0)

我认为您正在寻找的是confirm()

if (confirm('Are you sure?')) {
    console.log('confirmed');
} else {
    console.log('declined');
}

答案 2 :(得分:0)

您可以将引导程序模式用于要询问的确认。 链接为here