(function(){"use strict";u8.Crm.CalendarProviderManager=function(r){$.extend(this,u8.Crm.CalendarProviderManager.defaults,r);this.id="update/CalendarProvidersSpecial/Manager";if(!this.providers||!this.providers.length){$error("No providers given.")}this.bind();this._providers={};for(var t=0;t<this.providers.length;t++){var i=this.providers[t];var d=typeof i==="string"?i:i.id;var n=e[d];if(!n){$error("Unknown calendar provider: "+d)}if(!this.defaultProviderId){this.defaultProviderId=d}var a=$.extend({},n.options,i.options,{id:d});i=u8.services.factory.createInstance(n.type,[a]);this._providers[d]=i;if(!i.id){i.id=d}["Create","Update","Delete"].forEach(function(e){i.bind(e,{fn:this._onEvent.bind(this,e,d),isBound:this.isBound.bind(this,e)})},this)}};u8.Crm.CalendarProviderManager.makeClass({name:"CalendarProviderManager",events:["Create","Update","Delete"]});u8.Crm.CalendarProviderManager.defaults={};$.extend(u8.Crm.CalendarProviderManager.prototype,{getProvider:function(e){if(!e){$error("No providerId given")}var r=this._providers[e];if(!r){$error("No such provider: "+e)}return r},getProviders:function(){return u8.dict(this._providers).values()},getInfoAreaIds:function(){var e=u8._.attr("infoAreaId");return this.getProviders().filterAndMap(e,e)},dispose:function(){for(var e in this._providers){var r=this._providers[e];if(r&&r.dispose){r.dispose()}}delete this._providers},createItem:function(e,r){this.getProvider(e&&e.providerId||this.defaultProviderId).createItem(e,r)},canCreateItem:function(e,r){this.getProvider(e&&e.providerId||this.defaultProviderId).canCreateItem(r)},cloneItem:function(e,r){this.getProvider(e.item.providerId).cloneItem(e,r)},updateItem:function(e,r){this.getProvider(e.item.providerId).updateItem(e,r)},updateItems:function(e,r){if(!e||e.length==0){return r&&r()}var t=this;var i=e.map(function(e){return t.getProvider(e.item.providerId).getUpdateRequest(e)});u8.services.crud.executeBatch({requests:i},r)},deleteItem:function(e,r){this.getProvider(e.item.providerId).deleteItem(e,r)},deleteItems:function(e,r){if(!e||!e.items||e.items.length==0){return r&&r()}var t=this;var i=e.items.map(function(r){return t.getProvider(r.providerId).getDeleteRequest(r,e)});u8.services.crud.executeBatch({requests:i},this._onExecuteBatchCallback.chain(r).bind(this))},_onEvent:function(e,r,t,i){if(i.item){i.item.providerId=r}i.providerId=r;this.raise(e,this,i)},_onExecuteBatchCallback:function(e,r){if(!r||r.error||!r.results){return}var t=r.results.filterAndMap([u8._.attr("found"),u8._.eq("type","delete")],u8._.attr("uid"),u8._.trueish(),u8.recordUidToString);if(t.length>0){this.raise("Delete",this,{itemIds:t})}}});var e={};u8.Crm.CalendarProviderManager.registerImplementations=function(r){$.extend(e,r)};u8.Crm.CalendarProviderManager.registerImplementations({"update/CalendarProvidersSpecial/Manager":{type:"CalendarProviderManager",options:{}}})})();