mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
UploadField changeDetection optional (fixes #2638)
This commit is contained in:
parent
9d550f8938
commit
61f99fa1ef
@ -193,6 +193,19 @@ selected files that you can then upload manually one by one:
|
||||
:::php
|
||||
$uploadField->setAutoUpload(false);
|
||||
|
||||
### Change Detection
|
||||
|
||||
The CMS interface will automatically notify the form containing
|
||||
an UploadField instance of changes, such as a new upload,
|
||||
or the removal of an existing upload (through a `dirty` event).
|
||||
The UI can then choose an appropriate response (e.g. highlighting the "save" button).
|
||||
If the UploadField doesn't save into a relation, there's
|
||||
technically no saveable change (the upload has already happened),
|
||||
which is why this feature can be disabled on demand.
|
||||
|
||||
:::php
|
||||
$uploadField->setConfig('changeDetection', false);
|
||||
|
||||
### Build a simple gallery
|
||||
|
||||
A gallery most times needs more then simple images. You might want to add a
|
||||
|
@ -118,6 +118,13 @@ class UploadField extends FileField {
|
||||
* @var boolean|string
|
||||
*/
|
||||
'canPreviewFolder' => true,
|
||||
/**
|
||||
* Indicate a change event to the containing form if an upload
|
||||
* or file edit/delete was performed.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
'changeDetection' => true,
|
||||
/**
|
||||
* Maximum width of the preview thumbnail
|
||||
*
|
||||
|
@ -50,7 +50,10 @@
|
||||
},
|
||||
_onDone: function (result, textStatus, jqXHR, options) {
|
||||
// Mark form as dirty on completion of successful upload
|
||||
if(this.options.changeDetection) {
|
||||
this.element.closest('form').trigger('dirty');
|
||||
}
|
||||
|
||||
$.blueimpUI.fileupload.prototype._onDone.call(this, result, textStatus, jqXHR, options);
|
||||
},
|
||||
_onSend: function (e, data) {
|
||||
@ -103,7 +106,9 @@
|
||||
this._adjustMaxNumberOfFiles(0);
|
||||
},
|
||||
attach: function(data) {
|
||||
if(this.options.changeDetection) {
|
||||
this.element.closest('form').trigger('dirty');
|
||||
}
|
||||
|
||||
// Handles attachment of already uploaded files, similar to add
|
||||
var self = this,
|
||||
@ -338,12 +343,16 @@
|
||||
|
||||
$('div.ss-upload .ss-uploadfield-item-remove:not(.ui-state-disabled), .ss-uploadfield-item-delete:not(.ui-state-disabled)').entwine({
|
||||
onclick: function(e) {
|
||||
var fileupload = this.closest('div.ss-upload').data('fileupload'),
|
||||
var field = this.closest('div.ss-upload'),
|
||||
config = field.getConfig('changeDetection'),
|
||||
fileupload = field.data('fileupload'),
|
||||
item = this.closest('.ss-uploadfield-item'), msg = '';
|
||||
|
||||
if(this.is('.ss-uploadfield-item-delete')) {
|
||||
if(confirm(ss.i18n._t('UploadField.ConfirmDelete'))) {
|
||||
if(config.changeDetection) {
|
||||
this.closest('form').trigger('dirty');
|
||||
}
|
||||
fileupload._trigger('destroy', e, {
|
||||
context: item,
|
||||
url: this.data('href'),
|
||||
@ -353,7 +362,9 @@
|
||||
}
|
||||
} else {
|
||||
// Removed files will be applied to object on save
|
||||
if(config.changeDetection) {
|
||||
this.closest('form').trigger('dirty');
|
||||
}
|
||||
fileupload._trigger('destroy', e, {context: item});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user