!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("underscore"),require("polyglot"));else if("function"==typeof define&&define.amd)define(["underscore","polyglot"],t);else{var a="object"==typeof exports?t(require("underscore"),require("polyglot")):t(e.underscore,e.polyglot);for(var l in a)("object"==typeof exports?exports:e)[l]=a[l]}}("undefined"!=typeof self?self:this,function(e,t){return function(e){function t(l){if(a[l])return a[l].exports;var o=a[l]={i:l,l:!1,exports:{}};return e[l].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var a={};return t.m=e,t.c=a,t.d=function(e,a,l){t.o(e,a)||Object.defineProperty(e,a,{configurable:!1,enumerable:!0,get:l})},t.n=function(e){var a=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(a,"a",a),a},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="/dist/bundles",t(t.s=72)}({1:function(e,t,a){"use strict";function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}t.__esModule=!0;var o=a(15),c=function(e){return e&&e.__esModule?e:{default:e}}(o),i=a(16),s=function(){function e(){l(this,e),this.polyglot=new i({phrases:c.default})}return e.prototype.get=function(e,t){return this.polyglot.t(e,t)},e}();t.default=new s},10:function(e,t,a){"use strict";var l,o;l=[a(5)],void 0!==(o=function(e){function t(){return function(){"function"==typeof this.init&&this.init.apply(this,arguments)}}var a=function(){};return a.extend=function(a,l){1===arguments.length&&(l=a,a=null);var o=this.prototype,c=o,i=Object.create(c),s=t();if(a){for(var n=0,r=a.length;n1&&"*"!==l[1])a[e]=t._events[e];else if(l.length>1&&"*"===l[1])for(var o in t._events)0===o.indexOf(l[0]+":")&&(a[o]=t._events[o]);return a}(e,this);for(var o in l){var c=0,i=l[o];if(i)for(;c1&&(l=l.concat(this._events[e]||[]));for(var o=0;o0&&void 0!==arguments[0]?arguments[0]:{};return delete t._paletteRequestPromise[a],t._cachedPalettes[a]=e.data&&e.data.data&&e.data.data[0],d.default.extend({},t._cachedPalettes[a])},function(e){throw delete t._paletteRequestPromise[a],t._logger.error(e),e}),this._paletteRequestPromise[a])},t.prototype.getPalettes=function(e){var t=this;return this._cachedMyPalettes&&this._cachedPublicPalettes?Promise.resolve(this._getCachedPalettes(e)):Promise.all([this.getMyPalettes(),this.getPublicPalettes()]).then(function(){return t._getCachedPalettes(e)})},t.prototype._getCachedPalettes=function(e){var t=this,a=[],l=[];return Object.keys(this._cachedPalettes).forEach(function(o){var c=t._cachedPalettes[o],i=c.content&&c.content.fillType;e&&i!==e||(c.my&&a.push(d.default.extend({},c)),c.public&&l.push(d.default.extend({},c)))}),{my:a,public:l}},t.prototype._cachePalettes=function(e,t){var a=this;e.forEach(function(e){a._cachedPalettes[e.id]||(a._cachedPalettes[e.id]=e),a._cachedPalettes[e.id][t]=!0})},t.prototype.getMyPalettes=function(){var e=this;return this._cachedMyPalettes?Promise.resolve(this._getCachedPalettes().my):this._getPalettes("v1/palettes/my").then(function(t){return e._cachePalettes(t,"my"),e._cachedMyPalettes=!0,t})},t.prototype.getPublicPalettes=function(){var e=this;return this._cachedPublicPalettes?Promise.resolve(this._getCachedPalettes().public):this._getPalettes("v1/palettes/public").then(function(t){return e._cachePalettes(t,"public"),e._cachedPublicPalettes=!0,t})},t.prototype.deletePalette=function(e){var t=this,a=this.getCMSafePaletteId(e);return a||Promise.reject("Need the ID of the palette to update"),this._getPaletteName(a).then(function(e){return t._showConfirmationDlg(n.default.get("deleteDialogTitle"),n.default.get("deleteMessage",{name:e})).then(function(){return t._ajaxService.ajax({url:"v1/palettes/"+encodeURIComponent(a)+"?forced=true",type:"DELETE",headers:{"Content-Type":"application/json"}}).then(function(l){return delete t._cachedPalettes[a],t._showToast(n.default.get("deleteToast",{name:e})),t.trigger("palette:deleted",{paletteId:a}),l},function(e){throw t._showUnknownError(e),e})},function(){})})},t.prototype._getPaletteName=function(e){return this.getPalette(e).then(function(e){return e.defaultName})},t.prototype.createPalette=function(e){var t=this,a=e.palette,l=a.label;if(!l)return Promise.reject("No name specified in the palette definition");var o={defaultName:l,content:a};return void 0!==e.public&&(o.public=e.public),this._ajaxService.ajax({url:"v1/palettes/my",type:"POST",headers:{"Content-Type":"application/json"},data:JSON.stringify(o)}).then(function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},a=e.jqXHR&&e.jqXHR.getResponseHeader("location");if(a){var c=a?a.substring(a.lastIndexOf("/")+1):null;return c&&(o.id=c,o.my=!0,t._cachedPalettes[c]=o),t._showToast(n.default.get("createdToastMessage",{name:l})),t.trigger("palette:created",{paletteId:c}),c}},function(e){throw t._showUnknownError(e),e})},t.prototype.updatePalette=function(e){var t=this,a=e.id,l=e.palette,o=this.getCMSafePaletteId(a),c=void 0===e.public?null:e.public;o||Promise.reject("Need the ID of the palette to update");var i={};return this._applyUpdateToPalette(i,l,c),this._ajaxService.ajax({url:"v1/palettes/"+encodeURIComponent(o),type:"PUT",headers:{"Content-Type":"application/json"},data:JSON.stringify(i)}).then(function(e){var a=t._cachedPalettes[o];return a&&t._applyUpdateToPalette(a,l,c),t.trigger("palette:updated",{paletteId:o}),e},function(e){throw t._showUnknownError(e),e})},t.prototype._applyUpdateToPalette=function(e,t,a){t&&(e.defaultName=t.label,e.content=t),null!=a&&(e.public=a)},t.prototype._showUnknownError=function(e){this._glassContext.appController.showErrorMessage(n.default.get("errorCreatingPalette"),n.default.get("paletteErrorTitle")),this._logger.error(e)},t.prototype._showToast=function(e){this._glassContext.appController.showToast(e)},t.prototype._showConfirmationDlg=function(e,t){var a=this;return new Promise(function(l,o){a._glassContext.appController.showMessage(t,e,"info",["ok","cancel"],void 0,function(e){"ok"===e.btn?l():o()})})},t.prototype._getPalettes=function(e){var t=this;return this._ajaxService.ajax({url:e,type:"GET",headers:{Accept:"application/json"}}).then(function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return e.data&&e.data.data},function(e){return t._logger.error(e),[]})},t.prototype.getCMSafePaletteId=function(e){return e&&0===e.indexOf("__CM__")?e.split("__CM__")[1]:e},t.prototype.getFavoriteColors=function(){var e=this;return this._cachedFavoriteColors?Promise.resolve(d.default.clone(this._cachedFavoriteColors)):this._ajaxService.ajax({url:"v1/users/~/favColors",type:"GET",headers:{Accept:"application/json"}}).then(function(t){return t&&t.data&&t.data[0]&&t.data[0].colors?(e._cachedFavoriteColors=t.data[0].colors,d.default.clone(e._cachedFavoriteColors)):[]},function(t){return e._logger.error(t),[]})},t.prototype.setFavoriteColors=function(e){var t=this;return e?(this._cachedFavoriteColors=e,this._ajaxService.ajax({url:"v1/users/~/favColors/data",type:"PUT",headers:{"Content-Type":"application/json"},data:JSON.stringify({colors:this._cachedFavoriteColors})}).then(function(){},function(e){t._logger.error(e)})):Promise.resolve()},t.prototype.getRecentlyUsedPaletteInfo=function(e){var t=this;return this._cachedMRUPalettes?(this._cachedMRUPalettes[e]||(this._cachedMRUPalettes[e]=[]),Promise.resolve(this._cachedMRUPalettes[e])):this._ajaxService.ajax({url:"v1/users/~/mruPalettes",type:"GET",headers:{Accept:"application/json"}}).then(function(a){return a&&a.data&&a.data[0]?t._cachedMRUPalettes=a.data[0]:t._cachedMRUPalettes={},t._cachedMRUPalettes[e]||(t._cachedMRUPalettes[e]=[]),t._cachedMRUPalettes[e]},function(e){return t._logger.error(e),[]})},t.prototype.addRecentlyUsedPalette=function(e){var t=this,a=e.palette,l=e.component,o=e.isSystem,c=e.propName,i=e.trimSystemByPropName;if(a){var s="ImgPath"===a.content.fillType?"continuous":a.content.fillType;return this.getRecentlyUsedPaletteInfo(s).then(function(e){if(e){for(var s=t.getCMSafePaletteId(a.id),n=!1,r=0;r=3&&o>=3&&!a)e.pop(),c--;else{var i=e[c];i.isSystem&&a&&t!==i.propName||("dashboard"===i.component?(i.isSystem&&l>=3?(e.splice(c,1),c--):l++,i.isSystem||o++):(i.isSystem&&o>=3?(e.splice(c,1),c--):o++,i.isSystem||l++))}for(;e.length>12;)e.pop()},t}(m);t.default=u}})}); //# sourceMappingURL=services.min.js.map