Permalink
Browse files

API Change tracker allows explicit dirty messages

BUG Fixed issue with UploadField not detecting changes
  • Loading branch information...
1 parent ed6e456 commit 415f8a04b243da4dfdbfdd70dcb3807eea6a10ec @tractorcow tractorcow committed Oct 24, 2013
Showing with 27 additions and 10 deletions.
  1. +19 −10 admin/javascript/jquery-changetracker/lib/jquery.changetracker.js
  2. +8 −0 javascript/UploadField.js
@@ -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);
}
}
@@ -95,6 +98,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');
};
/**
@@ -137,13 +146,13 @@
// Support invoking "public" methods as string arguments
if (typeof arguments[0] === 'string') {
- var property = arguments[1];
- var args = Array.prototype.slice.call(arguments);
- args.splice(0, 1);
- return this[arguments[0]].apply(this, args);
- } else {
- return this.initialize();
- }
+ var property = arguments[1];
+ var args = Array.prototype.slice.call(arguments);
+ args.splice(0, 1);
+ return this[arguments[0]].apply(this, args);
+ } else {
+ return this.initialize();
+ }
};
}(jQuery));
@@ -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,
@@ -340,6 +346,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'),
@@ -349,6 +356,7 @@
}
} else {
// Removed files will be applied to object on save
+ this.closest('form').trigger('dirty');
fileupload._trigger('destroy', e, {context: item});
}

0 comments on commit 415f8a0

Please sign in to comment.