From dca9effec04dd08a00b92f9ce797afc7f69d2a59 Mon Sep 17 00:00:00 2001 From: alekseybobkov Date: Tue, 27 Oct 2015 17:00:14 -0700 Subject: [PATCH] Minor fixes in Inspector --- .../ui/js/inspector.editor.autocomplete.js | 10 +++++++ .../assets/ui/js/inspector.editor.base.js | 7 +++++ .../assets/ui/js/inspector.editor.dropdown.js | 16 +++++++++-- .../assets/ui/js/inspector.editor.set.js | 10 +++++++ modules/system/assets/ui/storm-min.js | 27 ++++++++++++------- 5 files changed, 59 insertions(+), 11 deletions(-) diff --git a/modules/system/assets/ui/js/inspector.editor.autocomplete.js b/modules/system/assets/ui/js/inspector.editor.autocomplete.js index 54ea3290d..4f79a1b6a 100644 --- a/modules/system/assets/ui/js/inspector.editor.autocomplete.js +++ b/modules/system/assets/ui/js/inspector.editor.autocomplete.js @@ -119,6 +119,10 @@ } AutocompleteEditor.prototype.hideLoadingIndicator = function() { + if (this.isDisposed()) { + return + } + var $container = $(this.getContainer()) $container.loadIndicator('hide') @@ -146,6 +150,12 @@ } AutocompleteEditor.prototype.itemsRequestDone = function(data, currentValue, initialization) { + if (this.isDisposed()) { + // Handle the case when the asynchronous request finishes after + // the editor is disposed + return + } + var loadedItems = {} if (data.options) { diff --git a/modules/system/assets/ui/js/inspector.editor.base.js b/modules/system/assets/ui/js/inspector.editor.base.js index a45d63d4d..915ed0d7f 100644 --- a/modules/system/assets/ui/js/inspector.editor.base.js +++ b/modules/system/assets/ui/js/inspector.editor.base.js @@ -30,6 +30,7 @@ this.group = null // Group created by a grouped editor, for example by the set editor this.childInspector = null this.validationSet = null + this.disposed = false Base.call(this) @@ -40,6 +41,8 @@ BaseEditor.prototype.constructor = Base BaseEditor.prototype.dispose = function() { + this.disposed = true // After this point editors can't rely on any DOM references + this.disposeValidation() if (this.childInspector) { @@ -68,6 +71,10 @@ return null } + BaseEditor.prototype.isDisposed = function() { + return this.disposed + } + BaseEditor.prototype.registerHandlers = function() { } diff --git a/modules/system/assets/ui/js/inspector.editor.dropdown.js b/modules/system/assets/ui/js/inspector.editor.dropdown.js index 6a2bf5337..2e97fdbc3 100644 --- a/modules/system/assets/ui/js/inspector.editor.dropdown.js +++ b/modules/system/assets/ui/js/inspector.editor.dropdown.js @@ -202,9 +202,11 @@ // DropdownEditor.prototype.destroyCustomSelect = function() { - var select = this.getSelect() + var $select = $(this.getSelect()) - $(select).select2('destroy') + if ($select.data('select2') != null) { + $select.select2('destroy') + } } DropdownEditor.prototype.unregisterHandlers = function() { @@ -291,6 +293,10 @@ } DropdownEditor.prototype.hideLoadingIndicator = function() { + if (this.isDisposed()) { + return + } + if (!Modernizr.touch) { this.indicatorContainer.loadIndicator('hide') this.indicatorContainer.loadIndicator('destroy') @@ -298,6 +304,12 @@ } DropdownEditor.prototype.optionsRequestDone = function(data, currentValue, initialization) { + if (this.isDisposed()) { + // Handle the case when the asynchronous request finishes after + // the editor is disposed + return + } + var select = this.getSelect() // Without destroying and recreating the custom select diff --git a/modules/system/assets/ui/js/inspector.editor.set.js b/modules/system/assets/ui/js/inspector.editor.set.js index a28d0e304..b63e3f416 100644 --- a/modules/system/assets/ui/js/inspector.editor.set.js +++ b/modules/system/assets/ui/js/inspector.editor.set.js @@ -145,6 +145,10 @@ } SetEditor.prototype.hideLoadingIndicator = function() { + if (this.isDisposed()) { + return + } + var $link = $(this.getLink()) $link.loadIndicator('hide') @@ -170,6 +174,12 @@ } SetEditor.prototype.itemsRequestDone = function(data, currentValue, initialization) { + if (this.isDisposed()) { + // Handle the case when the asynchronous request finishes after + // the editor is disposed + return + } + this.loadedItems = {} if (data.options) { diff --git a/modules/system/assets/ui/storm-min.js b/modules/system/assets/ui/storm-min.js index 9a701ad45..3387a36d1 100644 --- a/modules/system/assets/ui/storm-min.js +++ b/modules/system/assets/ui/storm-min.js @@ -4005,11 +4005,13 @@ this.parentGroup=group this.group=null this.childInspector=null this.validationSet=null +this.disposed=false Base.call(this) this.init()} BaseEditor.prototype=Object.create(BaseProto) BaseEditor.prototype.constructor=Base -BaseEditor.prototype.dispose=function(){this.disposeValidation() +BaseEditor.prototype.dispose=function(){this.disposed=true +this.disposeValidation() if(this.childInspector){this.childInspector.dispose()} this.inspector=null this.propertyDefinition=null @@ -4024,6 +4026,7 @@ BaseEditor.prototype.init=function(){this.build() this.registerHandlers() this.initValidation()} BaseEditor.prototype.build=function(){return null} +BaseEditor.prototype.isDisposed=function(){return this.disposed} BaseEditor.prototype.registerHandlers=function(){} BaseEditor.prototype.onInspectorPropertyChanged=function(property,value){} BaseEditor.prototype.focus=function(){} @@ -4172,8 +4175,8 @@ if(this.propertyDefinition.placeholder!==undefined){return undefined} var select=this.getSelect() if(select){return select.value} return undefined} -DropdownEditor.prototype.destroyCustomSelect=function(){var select=this.getSelect() -$(select).select2('destroy')} +DropdownEditor.prototype.destroyCustomSelect=function(){var $select=$(this.getSelect()) +if($select.data('select2')!=null){$select.select2('destroy')}} DropdownEditor.prototype.unregisterHandlers=function(){var select=this.getSelect() $(select).off('change',this.proxy(this.onSelectionChange))} DropdownEditor.prototype.loadStaticOptions=function(select){var value=this.inspector.getPropertyValue(this.propertyDefinition.property) @@ -4195,9 +4198,11 @@ if(value===undefined){value='';} result+=property+':'+value+'-'} return result} DropdownEditor.prototype.showLoadingIndicator=function(){if(!Modernizr.touch){this.indicatorContainer.loadIndicator()}} -DropdownEditor.prototype.hideLoadingIndicator=function(){if(!Modernizr.touch){this.indicatorContainer.loadIndicator('hide') +DropdownEditor.prototype.hideLoadingIndicator=function(){if(this.isDisposed()){return} +if(!Modernizr.touch){this.indicatorContainer.loadIndicator('hide') this.indicatorContainer.loadIndicator('destroy')}} -DropdownEditor.prototype.optionsRequestDone=function(data,currentValue,initialization){var select=this.getSelect() +DropdownEditor.prototype.optionsRequestDone=function(data,currentValue,initialization){if(this.isDisposed()){return} +var select=this.getSelect() this.destroyCustomSelect() this.clearOptions(select) this.initCustomSelect() @@ -4342,7 +4347,8 @@ this.editors.push[editor]} SetEditor.prototype.isCheckedByDefault=function(value){if(!this.propertyDefinition.default){return false} return this.propertyDefinition.default.indexOf(value)>-1} SetEditor.prototype.showLoadingIndicator=function(){$(this.getLink()).loadIndicator()} -SetEditor.prototype.hideLoadingIndicator=function(){var $link=$(this.getLink()) +SetEditor.prototype.hideLoadingIndicator=function(){if(this.isDisposed()){return} +var $link=$(this.getLink()) $link.loadIndicator('hide') $link.loadIndicator('destroy')} SetEditor.prototype.loadDynamicItems=function(){var link=this.getLink(),data=this.inspector.getValues(),$form=$(link).closest('form') @@ -4351,7 +4357,8 @@ this.showLoadingIndicator() data['inspectorProperty']=this.propertyDefinition.property data['inspectorClassName']=this.inspector.options.inspectorClass $form.request('onInspectableGetOptions',{data:data,}).done(this.proxy(this.itemsRequestDone)).always(this.proxy(this.hideLoadingIndicator))} -SetEditor.prototype.itemsRequestDone=function(data,currentValue,initialization){this.loadedItems={} +SetEditor.prototype.itemsRequestDone=function(data,currentValue,initialization){if(this.isDisposed()){return} +this.loadedItems={} if(data.options){for(var i=data.options.length-1;i>=0;i--){this.buildItemEditor(data.options[i].value,data.options[i].title) this.loadedItems[data.options[i].value]=data.options[i].title}} this.setLinkText(this.getLink())} @@ -4917,7 +4924,8 @@ $(this.getInput()).on('change',this.proxy(this.onInputKeyUp))} AutocompleteEditor.prototype.unregisterHandlers=function(){BaseProto.unregisterHandlers.call(this) $(this.getInput()).off('change',this.proxy(this.onInputKeyUp))} AutocompleteEditor.prototype.showLoadingIndicator=function(){$(this.getContainer()).loadIndicator()} -AutocompleteEditor.prototype.hideLoadingIndicator=function(){var $container=$(this.getContainer()) +AutocompleteEditor.prototype.hideLoadingIndicator=function(){if(this.isDisposed()){return} +var $container=$(this.getContainer()) $container.loadIndicator('hide') $container.loadIndicator('destroy') $container.removeClass('loading-indicator-container')} @@ -4927,7 +4935,8 @@ this.showLoadingIndicator() data['inspectorProperty']=this.propertyDefinition.property data['inspectorClassName']=this.inspector.options.inspectorClass $form.request('onInspectableGetOptions',{data:data,}).done(this.proxy(this.itemsRequestDone)).always(this.proxy(this.hideLoadingIndicator))} -AutocompleteEditor.prototype.itemsRequestDone=function(data,currentValue,initialization){var loadedItems={} +AutocompleteEditor.prototype.itemsRequestDone=function(data,currentValue,initialization){if(this.isDisposed()){return} +var loadedItems={} if(data.options){for(var i=data.options.length-1;i>=0;i--){loadedItems[data.options[i].value]=data.options[i].title}} this.buildAutoComplete(loadedItems)} $.oc.inspector.propertyEditors.autocomplete=AutocompleteEditor}(window.jQuery);+function($){"use strict";if($.oc===undefined)