Merge pull request #2599 from tractorcow/pulls/3.1-uploadfield-formchanged

BUG / API - Change tracking for UploadField
This commit is contained in:
Ingo Schommer 2013-10-31 15:28:34 -07:00
commit c547e426dd
2 changed files with 27 additions and 10 deletions

View File

@ -55,6 +55,9 @@
// optional metadata plugin support
if ($.meta) options = $.extend({}, options, this.data());
// Flag indicating this form was dirtied by an external component
var dirty = false;
var onchange = function(e) {
var $field = $(e.target);
var origVal = $field.data('changetracker.origVal'), newVal;
@ -76,8 +79,8 @@
if($field.is(':radio')) {
self.find(':radio[name=' + $field.attr('name') + ']').removeClass(options.changedCssClass);
}
// Only unset form state if no other fields are changed as well
if(!self.getFields().filter('.' + options.changedCssClass).length) {
// Only unset form state if no other fields are changed as well and the form isn't explicitly dirty
if(!dirty && !self.getFields().filter('.' + options.changedCssClass).length) {
self.removeClass(options.changedCssClass);
}
}
@ -96,6 +99,11 @@
$(this).data('changetracker.origVal', origVal);
});
self.bind('dirty.changetracker', function() {
dirty = true;
self.addClass(options.changedCssClass);
});
this.data('changetracker', true);
};
@ -104,7 +112,8 @@
.unbind('.changetracker')
.removeClass(options.changedCssClass)
.removeData('changetracker.origVal');
this.removeData('changetracker');
this.unbind('.changetracker')
.removeData('changetracker');
};
/**

View File

@ -48,6 +48,11 @@
return result;
},
_onDone: function (result, textStatus, jqXHR, options) {
// Mark form as dirty on completion of successful upload
this.element.closest('form').trigger('dirty');
$.blueimpUI.fileupload.prototype._onDone.call(this, result, textStatus, jqXHR, options);
},
_onSend: function (e, data) {
//check the array of existing files to see if we are trying to upload a file that already exists
var that = this;
@ -98,6 +103,7 @@
this._adjustMaxNumberOfFiles(0);
},
attach: function(data) {
this.element.closest('form').trigger('dirty');
// Handles attachment of already uploaded files, similar to add
var self = this,
@ -337,6 +343,7 @@
if(this.is('.ss-uploadfield-item-delete')) {
if(confirm(ss.i18n._t('UploadField.ConfirmDelete'))) {
this.closest('form').trigger('dirty');
fileupload._trigger('destroy', e, {
context: item,
url: this.data('href'),
@ -346,6 +353,7 @@
}
} else {
// Removed files will be applied to object on save
this.closest('form').trigger('dirty');
fileupload._trigger('destroy', e, {context: item});
}