mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
API Change tracker allows explicit dirty messages
BUG Fixed issue with UploadField not detecting changes
This commit is contained in:
parent
ed6e45610f
commit
415f8a04b2
@ -55,6 +55,9 @@
|
|||||||
// optional metadata plugin support
|
// optional metadata plugin support
|
||||||
if ($.meta) options = $.extend({}, options, this.data());
|
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 onchange = function(e) {
|
||||||
var $field = $(e.target);
|
var $field = $(e.target);
|
||||||
var origVal = $field.data('changetracker.origVal'), newVal;
|
var origVal = $field.data('changetracker.origVal'), newVal;
|
||||||
@ -76,8 +79,8 @@
|
|||||||
if($field.is(':radio')) {
|
if($field.is(':radio')) {
|
||||||
self.find(':radio[name=' + $field.attr('name') + ']').removeClass(options.changedCssClass);
|
self.find(':radio[name=' + $field.attr('name') + ']').removeClass(options.changedCssClass);
|
||||||
}
|
}
|
||||||
// Only unset form state if no other fields are changed as well
|
// Only unset form state if no other fields are changed as well and the form isn't explicitly dirty
|
||||||
if(!self.getFields().filter('.' + options.changedCssClass).length) {
|
if(!dirty && !self.getFields().filter('.' + options.changedCssClass).length) {
|
||||||
self.removeClass(options.changedCssClass);
|
self.removeClass(options.changedCssClass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,6 +99,11 @@
|
|||||||
$(this).data('changetracker.origVal', origVal);
|
$(this).data('changetracker.origVal', origVal);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
self.bind('dirty.changetracker', function() {
|
||||||
|
dirty = true;
|
||||||
|
self.addClass(options.changedCssClass);
|
||||||
|
});
|
||||||
|
|
||||||
this.data('changetracker', true);
|
this.data('changetracker', true);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -104,7 +112,8 @@
|
|||||||
.unbind('.changetracker')
|
.unbind('.changetracker')
|
||||||
.removeClass(options.changedCssClass)
|
.removeClass(options.changedCssClass)
|
||||||
.removeData('changetracker.origVal');
|
.removeData('changetracker.origVal');
|
||||||
this.removeData('changetracker');
|
this.unbind('.changetracker')
|
||||||
|
.removeData('changetracker');
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -137,13 +146,13 @@
|
|||||||
|
|
||||||
// Support invoking "public" methods as string arguments
|
// Support invoking "public" methods as string arguments
|
||||||
if (typeof arguments[0] === 'string') {
|
if (typeof arguments[0] === 'string') {
|
||||||
var property = arguments[1];
|
var property = arguments[1];
|
||||||
var args = Array.prototype.slice.call(arguments);
|
var args = Array.prototype.slice.call(arguments);
|
||||||
args.splice(0, 1);
|
args.splice(0, 1);
|
||||||
return this[arguments[0]].apply(this, args);
|
return this[arguments[0]].apply(this, args);
|
||||||
} else {
|
} else {
|
||||||
return this.initialize();
|
return this.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}(jQuery));
|
}(jQuery));
|
@ -48,6 +48,11 @@
|
|||||||
|
|
||||||
return result;
|
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) {
|
_onSend: function (e, data) {
|
||||||
//check the array of existing files to see if we are trying to upload a file that already exists
|
//check the array of existing files to see if we are trying to upload a file that already exists
|
||||||
var that = this;
|
var that = this;
|
||||||
@ -98,6 +103,7 @@
|
|||||||
this._adjustMaxNumberOfFiles(0);
|
this._adjustMaxNumberOfFiles(0);
|
||||||
},
|
},
|
||||||
attach: function(data) {
|
attach: function(data) {
|
||||||
|
this.element.closest('form').trigger('dirty');
|
||||||
|
|
||||||
// Handles attachment of already uploaded files, similar to add
|
// Handles attachment of already uploaded files, similar to add
|
||||||
var self = this,
|
var self = this,
|
||||||
@ -340,6 +346,7 @@
|
|||||||
|
|
||||||
if(this.is('.ss-uploadfield-item-delete')) {
|
if(this.is('.ss-uploadfield-item-delete')) {
|
||||||
if(confirm(ss.i18n._t('UploadField.ConfirmDelete'))) {
|
if(confirm(ss.i18n._t('UploadField.ConfirmDelete'))) {
|
||||||
|
this.closest('form').trigger('dirty');
|
||||||
fileupload._trigger('destroy', e, {
|
fileupload._trigger('destroy', e, {
|
||||||
context: item,
|
context: item,
|
||||||
url: this.data('href'),
|
url: this.data('href'),
|
||||||
@ -349,6 +356,7 @@
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Removed files will be applied to object on save
|
// Removed files will be applied to object on save
|
||||||
|
this.closest('form').trigger('dirty');
|
||||||
fileupload._trigger('destroy', e, {context: item});
|
fileupload._trigger('destroy', e, {context: item});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user