[Rt-commit] rt branch, 4.4/attachment-warning-dropzone, created. rt-4.2.12-353-ge97ff4c
Shawn Moore
shawn at bestpractical.com
Fri Oct 30 18:53:32 EDT 2015
The branch, 4.4/attachment-warning-dropzone has been created
at e97ff4c941ce71b307f8ce16ba0f92e28fef5570 (commit)
- Log -----------------------------------------------------------------
commit e97ff4c941ce71b307f8ce16ba0f92e28fef5570
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Wed Oct 28 22:25:23 2015 +0000
Fix attachment warning to work with dropzone
Fixes: I#31317
diff --git a/share/html/Ticket/Elements/AddAttachments b/share/html/Ticket/Elements/AddAttachments
index d31352d..4eb5c0a 100644
--- a/share/html/Ticket/Elements/AddAttachments
+++ b/share/html/Ticket/Elements/AddAttachments
@@ -121,7 +121,12 @@ jQuery( function() {
' </svg>' +
' </div>' +
'</div>',
+ init: function() {
+ jQuery('#attach-dropzone').triggerHandler('dropzone-init');
+ jQuery('#attach-dropzone').addClass('dropzone-init');
+ },
fallback: function() {
+ jQuery('#attach-dropzone').triggerHandler('dropzone-fallback');
jQuery('#attach-dropzone').addClass('hidden');
jQuery('#attach-dropzone').siblings('div.old-attach').removeClass('hidden');
}
@@ -136,11 +141,15 @@ jQuery( function() {
jQuery('#attach-dropzone').removeClass('scaled');
});
attachDropzone.on('reset', function() {
- jQuery('#attach-dropzone').removeClass('scaled');
+ jQuery('#attach-dropzone').removeClass('scaled has-attachments');
+ jQuery('#attach-dropzone').triggerHandler('attachment-change');
});
var submit_input = jQuery('#attach-dropzone').closest('form').find('div.submit :submit:visible:last');
var submit_input_label = submit_input.attr('value');
attachDropzone.on('addedfile', function() {
+ jQuery('#attach-dropzone').addClass('has-attachments');
+ jQuery('#attach-dropzone').triggerHandler('attachment-change');
+
submit_input.prop('disabled', true).attr('value', <% loc('Uploading...') |n,j %>);
});
attachDropzone.on('queuecomplete', function() {
diff --git a/share/static/js/util.js b/share/static/js/util.js
index aec306f..7b78234 100644
--- a/share/static/js/util.js
+++ b/share/static/js/util.js
@@ -309,10 +309,10 @@ function ReplaceAllTextareas() {
function AddAttachmentWarning() {
var plainMessageBox = jQuery('.messagebox');
- var addFileField = jQuery('input[name=Attach]');
- var existingFileList = jQuery('tr.attachment input[type=checkbox]');
var warningMessage = jQuery('.messagebox-attachment-warning');
var ignoreMessage = warningMessage.find('.ignore');
+ var dropzoneElement = jQuery('#attach-dropzone');
+ var fallbackElement = jQuery('.old-attach');
// there won't be a ckeditor when using the plain <textarea>
var richTextEditor;
@@ -346,8 +346,7 @@ function AddAttachmentWarning() {
// if the word "attach" appears and there are no attachments in flight
var needsWarning = text &&
text.match(regex) &&
- !addFileField.val() &&
- existingFileList.filter(":not(:checked)").length == 0;
+ !dropzoneElement.hasClass('has-attachments');
if (needsWarning) {
warningMessage.show(instant ? 1 : 'fast');
@@ -371,54 +370,73 @@ function AddAttachmentWarning() {
}, 200);
};
- if (richTextEditor) {
- richTextEditor.on('instanceReady', function () {
- // this set of events is imperfect. what I really want is:
- // this.on('change', ...)
- // but ckeditor doesn't seem to provide that out of the box
-
- this.on('blur', function () {
- toggleAttachmentWarning();
- });
-
- // we want to capture ~every keystroke type event; we only do the
- // full checking periodically to avoid overloading the browser
- this.document.on("keyup", function () {
- delayedAttachmentWarning();
- });
- this.document.on("keydown", function () {
- delayedAttachmentWarning();
+ var listenForAttachmentEvents = function () {
+ if (richTextEditor) {
+ richTextEditor.on('instanceReady', function () {
+ // this set of events is imperfect. what I really want is:
+ // this.on('change', ...)
+ // but ckeditor doesn't seem to provide that out of the box
+
+ this.on('blur', function () {
+ toggleAttachmentWarning();
+ });
+
+ // we want to capture ~every keystroke type event; we only do the
+ // full checking periodically to avoid overloading the browser
+ this.document.on("keyup", function () {
+ delayedAttachmentWarning();
+ });
+ this.document.on("keydown", function () {
+ delayedAttachmentWarning();
+ });
+ this.document.on("keypress", function () {
+ delayedAttachmentWarning();
+ });
+
+ // hook into the undo/redo buttons in the ckeditor UI
+ this.getCommand('undo').on('afterUndo', function () {
+ toggleAttachmentWarning();
+ });
+ this.getCommand('redo').on('afterRedo', function () {
+ toggleAttachmentWarning();
+ });
});
- this.document.on("keypress", function () {
+ }
+ else {
+ // the propertychange event is for IE
+ plainMessageBox.bind('input propertychange', function () {
delayedAttachmentWarning();
});
+ }
- // hook into the undo/redo buttons in the ckeditor UI
- this.getCommand('undo').on('afterUndo', function () {
- toggleAttachmentWarning();
- });
- this.getCommand('redo').on('afterRedo', function () {
- toggleAttachmentWarning();
- });
+ dropzoneElement.on('attachment-change', function () {
+ toggleAttachmentWarning();
});
+ };
+
+ // if dropzone has already tried and failed, don't show spurious warnings
+ if (!fallbackElement.hasClass('hidden')) {
+ return;
}
+ // if dropzone has already attached...
+ else if (dropzoneElement.hasClass('dropzone-init')) {
+ listenForAttachmentEvents();
+
+ // also need to display the warning on initial page load
+ toggleAttachmentWarning(1);
+ }
+ // otherwise, wait for dropzone to initialize and then add attachment
+ // warnings
else {
- // the propertychange event is for IE
- plainMessageBox.bind('input propertychange', function () {
- delayedAttachmentWarning();
+ dropzoneElement.on('dropzone-fallback', function () {
+ // do nothing. no dropzone = no attachment warnings
});
- }
- addFileField.bind('change', function () {
- toggleAttachmentWarning();
- });
-
- existingFileList.bind('change', function () {
- toggleAttachmentWarning();
- });
-
- // also need to display the warning on initial page load
- toggleAttachmentWarning(1);
+ dropzoneElement.on('dropzone-init', function () {
+ listenForAttachmentEvents();
+ toggleAttachmentWarning(1);
+ });
+ }
}
function toggle_addprincipal_validity(input, good, title) {
-----------------------------------------------------------------------
More information about the rt-commit
mailing list