From 78c9dea86b0a120b553b2b9fef672528b4d7c537 Mon Sep 17 00:00:00 2001 From: andris-sevcenko Date: Thu, 12 Jul 2018 16:47:14 +0300 Subject: [PATCH] Fixed #3035 --- CHANGELOG-v3.md | 1 + src/web/assets/cp/dist/js/Craft.js | 26 +++++++++++++++---- src/web/assets/cp/dist/js/Craft.min.js | 2 +- src/web/assets/cp/dist/js/Craft.min.js.map | 2 +- src/web/assets/cp/src/js/AssetEditor.js | 16 ++++++++++-- src/web/assets/cp/src/js/BaseElementEditor.js | 1 + .../assets/cp/src/js/BaseElementIndexView.js | 4 ++- .../assets/cp/src/js/TableElementIndexView.js | 3 ++- 8 files changed, 44 insertions(+), 11 deletions(-) diff --git a/CHANGELOG-v3.md b/CHANGELOG-v3.md index ad9b1531ddc..72c57485017 100644 --- a/CHANGELOG-v3.md +++ b/CHANGELOG-v3.md @@ -14,6 +14,7 @@ ### Fixed - Fixed a bug where you could get an error message sending emails in some environments that did not have the [intl](https://secure.php.net/manual/en/book.intl.php) extension installed. - Fixed an exception that was thrown if the `securityKey` config setting was changed and Craft was set to use either the SMTP or Gmail mailer transport type. ([#3083](https://github.com/craftcms/cms/issues/3083)) +- Fixed a bug where Asset view was not being refreshed in some cases after using Image Editor. ([#3035](https://github.com/craftcms/cms/issues/3035)) ## 3.0.15 - 2018-07-09 diff --git a/src/web/assets/cp/dist/js/Craft.js b/src/web/assets/cp/dist/js/Craft.js index fac2930a42d..26506be2555 100644 --- a/src/web/assets/cp/dist/js/Craft.js +++ b/src/web/assets/cp/dist/js/Craft.js @@ -1,4 +1,4 @@ -/*! - 2018-07-11 */ +/*! - 2018-07-12 */ (function($){ /** global: Craft */ @@ -1673,6 +1673,7 @@ Craft.BaseElementEditor = Garnish.Base.extend( siteId: null, attributes: null, params: null, + elementIndex: null, onShowHud: $.noop, onHideHud: $.noop, @@ -3669,7 +3670,9 @@ Craft.BaseElementIndexView = Garnish.Base.extend( }, createElementEditor: function($element) { - Craft.createElementEditor(this.elementIndex.elementType, $element); + Craft.createElementEditor(this.elementIndex.elementType, $element, { + elementIndex: this.elementIndex + }); }, disable: function() { @@ -4737,6 +4740,8 @@ Craft.AdminTable = Garnish.Base.extend( */ Craft.AssetEditor = Craft.BaseElementEditor.extend( { + reloadIndex: false, + updateForm: function(response) { this.base(response); @@ -4753,11 +4758,21 @@ Craft.AssetEditor = Craft.BaseElementEditor.extend( showImageEditor: function() { new Craft.AssetImageEditor(this.$element.data('id'), { - onSave: $.proxy(this, 'reloadForm'), + onSave: function () { + this.reloadIndex = true; + this.reloadForm(); + }.bind(this), allowDegreeFractions: Craft.isImagick }); - } + }, + onHideHud: function () { + if (this.reloadIndex && this.settings.elementIndex) { + this.settings.elementIndex.updateElements(); + } + + this.base(); + } }); // Register it! @@ -18078,7 +18093,8 @@ Craft.TableElementIndexView = Craft.BaseElementIndexView.extend( if (response.tableAttributes) { this._updateTableAttributes($element, response.tableAttributes); } - }, this) + }, this), + elementIndex: this.elementIndex }); }, diff --git a/src/web/assets/cp/dist/js/Craft.min.js b/src/web/assets/cp/dist/js/Craft.min.js index 2e414f49d79..1a0b762e686 100644 --- a/src/web/assets/cp/dist/js/Craft.min.js +++ b/src/web/assets/cp/dist/js/Craft.min.js @@ -1,2 +1,2 @@ -!function(p){p.extend(Craft,{navHeight:48,t:function(t,e,i){if(void 0!==Craft.translations[t]&&void 0!==Craft.translations[t][e]&&(e=Craft.translations[t][e]),i)for(var s in i)i.hasOwnProperty(s)&&(e=e.replace("{"+s+"}",i[s]));return e},formatDate:function(t){return"object"!=typeof t&&(t=new Date(t)),p.datepicker.formatDate(Craft.datepickerOptions.dateFormat,t)},formatNumber:function(t,e){return void 0===e&&(e=",.0f"),d3.formatLocale(d3FormatLocaleDefinition).format(e)(t)},escapeHtml:function(t){return p("
").text(t).html()},getText:function(t){return p("
").html(t).text()},encodeUriComponent:function(t){t=encodeURIComponent(t);var e={"!":"%21","*":"%2A","'":"%27","(":"%28",")":"%29"};for(var i in e){var s=new RegExp("\\"+i,"g");t=t.replace(s,e[i])}return t},selectFullValue:function(t){var e=p(t),i=e.val();if(void 0!==e[0].setSelectionRange){var s=2*i.length;e[0].setSelectionRange(0,s)}else e.val(i)},formatInputId:function(t){return this.rtrim(t.replace(/[\[\]\\]+/g,"-"),"-")},getUrl:function(t,e,i){if("string"!=typeof t&&(t=""),-1!==t.search("://")||"/"===t[0])return t;t=Craft.trim(t,"/");var s="";if(p.isPlainObject(e)){var n=[];for(var a in e)if(e.hasOwnProperty(a)){var r=e[a];"#"===a?s=r:null!==r&&""!==r&&n.push(a+"="+r)}e=n}e=Garnish.isArray(e)?e.join("&"):Craft.trim(e,"&?");var o,l=t.indexOf("?");if(-1!==l&&(e=t.substr(l+1)+(e?"&"+e:""),t=t.substr(0,l)),i){if(o=i,t){var h=o.match(/[&\?]p=[^&]+/);h&&(o=o.replace(h[0],h[0]+"/"+t),t="")}}else o=Craft.baseUrl;if(-1!==(l=o.indexOf("?"))&&(e=o.substr(l+1)+(e?"&"+e:""),o=o.substr(0,l)),!Craft.omitScriptNameInUrls&&t)if(Craft.usePathInfo)-1===o.search(Craft.scriptName)&&(o=Craft.rtrim(o,"/")+"/"+Craft.scriptName);else{if(e&&"p="===e.substr(0,2)){var d,c=e.indexOf("&");-1!==c?(d=e.substring(2,c),e=e.substr(c+1)):(d=e.substr(2),e=null),t=(d=Craft.rtrim(d))+(t?"/"+t:"")}e="p="+t+(e?"&"+e:""),t=null}return t&&(o=Craft.rtrim(o,"/")+"/"+t),e&&(o+="?"+e),s&&(o+="#"+s),o},getCpUrl:function(t,e){return this.getUrl(t,e,Craft.baseCpUrl)},getSiteUrl:function(t,e){return this.getUrl(t,e,Craft.baseSiteUrl)},getActionUrl:function(t,e){return Craft.getUrl(t,e,Craft.actionUrl)},redirectTo:function(t){document.location.href=this.getUrl(t)},getCsrfInput:function(){return Craft.csrfTokenName?'':""},postActionRequest:function(t,e,i,s){"function"==typeof e&&(s=i,i=e,e={});var n={"X-Registered-Asset-Bundles":Object.keys(Craft.registeredAssetBundles).join(","),"X-Registered-Js-Files":Object.keys(Craft.registeredJsFiles).join(",")};Craft.csrfTokenValue&&Craft.csrfTokenName&&(n["X-CSRF-Token"]=Craft.csrfTokenValue);var a=p.ajax(p.extend({url:Craft.getActionUrl(t),type:"POST",dataType:"json",headers:n,data:e,success:i,error:function(t,e){i&&i(null,e,t)},complete:function(t,e){"success"!==e&&(void 0!==Craft.cp?Craft.cp.displayError():alert(Craft.t("app","An unknown error occurred.")))}},s));return s&&"function"==typeof s.send&&s.send(a),a},_waitingOnAjax:!1,_ajaxQueue:[],queueActionRequest:function(t,e,i,s){"function"==typeof e&&(s=i,i=e,e=void 0),Craft._ajaxQueue.push([t,e,i,s]),Craft._waitingOnAjax||Craft._postNextActionRequestInQueue()},_postNextActionRequestInQueue:function(){Craft._waitingOnAjax=!0;var s=Craft._ajaxQueue.shift();Craft.postActionRequest(s[0],s[1],function(t,e,i){s[2]&&"function"==typeof s[2]&&s[2](t,e,i),Craft._ajaxQueue.length?Craft._postNextActionRequestInQueue():Craft._waitingOnAjax=!1},s[3])},stringToArray:function(t){if("string"!=typeof t)return t;for(var e=t.split(","),i=0;i]*href="(?:'+i.join("|")+')".*?><\/script>',"g");t=t.replace(a,"")}p("head").append(t)}},appendFootHtml:function(t){if(t){var e=p("script[src]");if(e.length){for(var i=[],s=0;s]*src="(?:'+i.join("|")+')".*?><\/script>',"g");t=t.replace(a,"")}Garnish.$bod.append(t)}},initUiElements:function(t){p(".grid",t).grid(),p(".info",t).infoicon(),p(".checkbox-select",t).checkboxselect(),p(".fieldtoggle",t).fieldtoggle(),p(".lightswitch",t).lightswitch(),p(".nicetext",t).nicetext(),p(".pill",t).pill(),p(".formsubmit",t).formsubmit(),p(".menubtn",t).menubtn()},_elementIndexClasses:{},_elementSelectorModalClasses:{},_elementEditorClasses:{},registerElementIndexClass:function(t,e){if(void 0!==this._elementIndexClasses[t])throw"An element index class has already been registered for the element type “"+t+"”.";this._elementIndexClasses[t]=e},registerElementSelectorModalClass:function(t,e){if(void 0!==this._elementSelectorModalClasses[t])throw"An element selector modal class has already been registered for the element type “"+t+"”.";this._elementSelectorModalClasses[t]=e},registerElementEditorClass:function(t,e){if(void 0!==this._elementEditorClasses[t])throw"An element editor class has already been registered for the element type “"+t+"”.";this._elementEditorClasses[t]=e},createElementIndex:function(t,e,i){return new(void 0!==this._elementIndexClasses[t]?this._elementIndexClasses[t]:Craft.BaseElementIndex)(t,e,i)},createElementSelectorModal:function(t,e){return new(void 0!==this._elementSelectorModalClasses[t]?this._elementSelectorModalClasses[t]:Craft.BaseElementSelectorModal)(t,e)},createElementEditor:function(t,e,i){return new(void 0!==this._elementEditorClasses[t]?this._elementEditorClasses[t]:Craft.BaseElementEditor)(e,i)},getLocalStorage:function(t,e){return t="Craft-"+Craft.systemUid+"."+t,"undefined"!=typeof localStorage&&void 0!==localStorage[t]?JSON.parse(localStorage[t]):e},setLocalStorage:function(t,e){if("undefined"!=typeof localStorage){t="Craft-"+Craft.systemUid+"."+t;try{localStorage[t]=JSON.stringify(e)}catch(t){}}},getElementInfo:function(t){var e=p(t);return e.hasClass("element")||(e=e.find(".element:first")),{id:e.data("id"),siteId:e.data("site-id"),label:e.data("label"),status:e.data("status"),url:e.data("url"),hasThumb:e.hasClass("hasthumb"),$element:e}},setElementSize:function(t,e){var i=p(t);if("small"!==e&&"large"!==e&&(e="small"),!i.hasClass(e)){var s="small"===e?"large":"small";if(i.addClass(e).removeClass(s),i.hasClass("hasthumb")){var n=i.find("> .elementthumb > img"),a=p("",{sizes:("small"===e?"30":"100")+"px",srcset:n.attr("srcset")||n.attr("data-pfsrcset")});n.replaceWith(a),picturefill({elements:[a[0]]})}}}}),p.extend(p.fn,{animateLeft:function(t,e,i,s){return"ltr"===Craft.orientation?this.velocity({left:t},e,i,s):this.velocity({right:t},e,i,s)},animateRight:function(t,e,i,s){return"ltr"===Craft.orientation?this.velocity({right:t},e,i,s):this.velocity({left:t},e,i,s)},disable:function(){return this.each(function(){var t=p(this);t.addClass("disabled"),t.data("activatable")&&t.removeAttr("tabindex")})},enable:function(){return this.each(function(){var t=p(this);t.removeClass("disabled"),t.data("activatable")&&t.attr("tabindex","0")})},grid:function(){return this.each(function(){var t=p(this),e={};t.data("item-selector")&&(e.itemSelector=t.data("item-selector")),t.data("cols")&&(e.cols=parseInt(t.data("cols"))),t.data("max-cols")&&(e.maxCols=parseInt(t.data("max-cols"))),t.data("min-col-width")&&(e.minColWidth=parseInt(t.data("min-col-width"))),t.data("mode")&&(e.mode=t.data("mode")),t.data("fill-mode")&&(e.fillMode=t.data("fill-mode")),t.data("col-class")&&(e.colClass=t.data("col-class")),t.data("snap-to-grid")&&(e.snapToGrid=!!t.data("snap-to-grid")),new Craft.Grid(this,e)})},infoicon:function(){return this.each(function(){new Craft.InfoIcon(this)})},checkboxselect:function(){return this.each(function(){p.data(this,"checkboxselect")||new Garnish.CheckboxSelect(this)})},fieldtoggle:function(){return this.each(function(){p.data(this,"fieldtoggle")||new Craft.FieldToggle(this)})},lightswitch:function(e,t,i){return"settings"===e?("string"==typeof t?(e={})[t]=i:e=t,this.each(function(){var t=p.data(this,"lightswitch");t&&t.setSettings(e)})):(p.isPlainObject(e)||(e={}),this.each(function(){var t=p.extend({},e);Garnish.hasAttr(this,"data-value")&&(t.value=p(this).attr("data-value")),p.data(this,"lightswitch")||new Craft.LightSwitch(this,t)}))},nicetext:function(){return this.each(function(){p.data(this,"nicetext")||new Garnish.NiceText(this)})},pill:function(){return this.each(function(){p.data(this,"pill")||new Garnish.Pill(this)})},formsubmit:function(){this.on("click",function(t){var e=p(t.currentTarget);if(!e.attr("data-confirm")||confirm(e.attr("data-confirm"))){var i=e.data("menu")?e.data("menu").$anchor:e,s=i.attr("data-form")?p("#"+i.attr("data-form")):i.closest("form");e.attr("data-action")&&p('').val(e.attr("data-action")).appendTo(s),e.attr("data-redirect")&&p('').val(e.attr("data-redirect")).appendTo(s),e.attr("data-param")&&p('').attr({name:e.attr("data-param"),value:e.attr("data-value")}).appendTo(s),s.trigger("submit")}})},menubtn:function(){return this.each(function(){var t=p(this);if(!t.data("menubtn")&&t.next().hasClass("menu")){var e={};t.data("menu-anchor")&&(e.menuAnchor=t.data("menu-anchor")),new Garnish.MenuBtn(t,e)}})}}),Garnish.$doc.ready(function(){Craft.initUiElements()}),Craft.BaseElementEditor=Garnish.Base.extend({$element:null,elementId:null,siteId:null,$form:null,$fieldsContainer:null,$cancelBtn:null,$saveBtn:null,$spinner:null,$siteSelect:null,$siteSpinner:null,hud:null,init:function(t,e){void 0===e&&p.isPlainObject(t)&&(e=t,t=null),this.$element=p(t),this.setSettings(e,Craft.BaseElementEditor.defaults),this.loadHud()},setElementAttribute:function(t,e){this.settings.attributes||(this.settings.attributes={}),null===e?delete this.settings.attributes[t]:this.settings.attributes[t]=e},getBaseData:function(){var t=p.extend({},this.settings.params);return this.settings.siteId?t.siteId=this.settings.siteId:this.$element&&this.$element.data("site-id")&&(t.siteId=this.$element.data("site-id")),this.settings.elementId?t.elementId=this.settings.elementId:this.$element&&this.$element.data("id")&&(t.elementId=this.$element.data("id")),this.settings.elementType&&(t.elementType=this.settings.elementType),this.settings.attributes&&(t.attributes=this.settings.attributes),t},loadHud:function(){this.onBeginLoading();var t=this.getBaseData();t.includeSites=this.settings.showSiteSwitcher,Craft.postActionRequest("elements/get-editor-html",t,p.proxy(this,"showHud"))},showHud:function(t,e){if(this.onEndLoading(),"success"===e){var i=p();if(t.sites){var s=p('
'),n=p('
').appendTo(s);this.$siteSelect=p("').appendTo(l),this.$spinner=p('