FileUpload icon indicating copy to clipboard operation
FileUpload copied to clipboard

Confirm box on file delete

Open rooster416 opened this issue 12 years ago • 3 comments

I have successfully added a simple javascript confirm on the file delete button, but when I press cancel it deletes the file anyway. Is there any other way I can get this to work?

rooster416 avatar Mar 05 '13 19:03 rooster416

Hey @rooster416 can you paste your code in gists ? Will be much easier to help

hugodias avatar Jun 06 '13 16:06 hugodias

Hugo, Here is my code. When I press the delete button, the confirm box successfully shows up, but when I press the cancel button on the popup, it deletes the file anyways.

            ';

rooster416 avatar Jun 06 '13 17:06 rooster416

Sorry, my code did not make it. I will try again.

        <script id="template-download" type="text/x-tmpl">
        {% for (var i=0, file; file=o.files[i]; i++) { %}
            <tr class="template-download fade">
                {% if (file.error) { %}
                    <td></td>
                    <td class="name"><span>{%=file.name%}</span></td>
                    <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
                    <td class="error" colspan="2"><span class="label label-important">{%=locale.fileupload.error%}</span> {%=locale.fileupload.errors[file.error] || file.error%}</td>
                {% } else { %}
                    <td class="preview">{% if (file.thumbnail_url) { %}
                        <a href="{%=file.url%}" title="{%=file.name%}" rel="gallery" download="{%=file.name%}"><img src="{%=file.thumbnail_url%}"></a>
                    {% } %}</td>
                    <td class="name">
                        <a href="{%=file.url%}" title="{%=file.name%}" rel="{%=file.thumbnail_url&&\'gallery\'%}" download="{%=file.name%}">{%=file.name%}</a>
                    </td>
                    <td class="name"><span>{%=file.type%}</span></td>
                    <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td>
                    <td colspan="2"></td>
                {% } %}
                {% if( user_type < 2 ) { %}
                <td class="delete">
                    <button class="btn btn-danger" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}" onclick="if( confirm( \'Are you sure you want to delete this file?\' ) ) return;">
                        <i class="icon-trash icon-white"></i>
                        <span>{%=locale.fileupload.destroy%}</span>

                    </button>
                    <input type="checkbox" name="delete" value="1">
                </td>
                {% } %}
            </tr>
        {% } %}
        </script>';

rooster416 avatar Jun 06 '13 17:06 rooster416