hugodias / FileUpload

Jquery File Upload for CakePHP 2.x
68 stars 25 forks source link

Confirm box on file delete #6

Open rooster416 opened 11 years ago

rooster416 commented 11 years ago

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?

hugodias commented 11 years ago

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

rooster416 commented 11 years ago

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 commented 11 years ago

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>';