Skip to content
Browse files

FIX Not calling updateFromNode on re-opening an image

Inside mediaform updateFromEditor we called $(this).updateFromNode, but this wasnt
pointing to anything useful after a refactor, which resulted in the fields not
being filled in with current data when editing an already-inserted image
  • Loading branch information...
1 parent 2ad56e1 commit 9f822d1e3c679fb3fdf16175c965d4535b5b784f @hafriedlander hafriedlander committed
Showing with 15 additions and 11 deletions.
  1. +15 −11 javascript/HtmlEditorField.js
View
26 javascript/HtmlEditorField.js
@@ -790,8 +790,8 @@ ss.editorWrappers['default'] = ss.editorWrappers.tinyMCE;
// TODO Depends on managed mime type
if(node.is('img')) {
- this.showFileView(node.data('url') || node.attr('src')).complete(function() {
- $(this).updateFromNode(node);
+ this.showFileView(node.data('url') || node.attr('src')).done(function(filefield) {
+ filefield.updateFromNode(node);
self.toggleCloseButton();
self.redraw();
});
@@ -834,25 +834,29 @@ ss.editorWrappers['default'] = ss.editorWrappers.tinyMCE;
getFileView: function(idOrUrl) {
return this.find('.ss-htmleditorfield-file[data-id=' + idOrUrl + ']');
},
- showFileView: function(idOrUrl, successCallback) {
- var self = this, params = (Number(idOrUrl) == idOrUrl) ? {ID: idOrUrl} : {FileURL: idOrUrl},
- item = $('<div class="ss-htmleditorfield-file" />');
+ showFileView: function(idOrUrl) {
+ var self = this, params = (Number(idOrUrl) == idOrUrl) ? {ID: idOrUrl} : {FileURL: idOrUrl};
- item.addClass('loading');
+ var item = $('<div class="ss-htmleditorfield-file loading" />');
this.find('.content-edit').append(item);
- return $.ajax({
- // url: this.data('urlViewfile') + '?ID=' + id,
+
+ var dfr = $.Deferred();
+
+ $.ajax({
url: $.path.addSearchParams(this.attr('action').replace(/MediaForm/, 'viewfile'), params),
success: function(html, status, xhr) {
- var newItem = $(html);
+ var newItem = $(html).filter('.ss-htmleditorfield-file');
item.replaceWith(newItem);
self.redraw();
- if(successCallback) successCallback.call(newItem, html, status, xhr);
+ dfr.resolve(newItem);
},
error: function() {
item.remove();
+ dfr.reject();
}
});
+
+ return dfr.promise();
}
});
@@ -941,7 +945,7 @@ ss.editorWrappers['default'] = ss.editorWrappers.tinyMCE;
if (urlField.validate()) {
container.addClass('loading');
- form.showFileView('http://' + urlField.val()).complete(function() {
+ form.showFileView('http://' + urlField.val()).done(function() {
container.removeClass('loading');
});
form.redraw();

0 comments on commit 9f822d1

Please sign in to comment.
Something went wrong with that request. Please try again.