(function(){"use strict";var e=['<div class="resourceplan center">{{ResourcePlan(resourcePlan)}}</div>','<div class="u8-buttons bottom u8-margin-l">',"{{Button(okButton)}}&nbsp;","{{Button(cancelButton)}}","</div>"].join("");u8.Crm.Widgets.SchedulingView=function(e,t){this.Widget(e,$.extend({},u8.Crm.Widgets.SchedulingView.defaults,t));this.commandBindings={Ok:this._onCommandOk.bind(this),Cancel:this._onCommandCancel.bind(this)};this._isCreated=false;u8.using({texts:["net_resources"],types:["ResourcePlan"]},this._create.bind(this))};u8.Crm.Widgets.SchedulingView.defaults={start:null,end:null,repId:null,maxWeeks:3,theme:{css:{root:"u8-schedulingview"}}};u8.Crm.Widgets.SchedulingView.makeClass({name:"SchedulingView",events:["Create","Execute"],deriveFrom:u8.Base.Widgets.Widget});$.extend(u8.Crm.Widgets.SchedulingView,{showAsPopup:function(e,t){var i;u8.Base.Widgets.Popup.openWidgetPopup({type:"SchedulingView",popupOptions:{size:{width:800,height:490},title:"TXT_net_resources_6",onClose:function(e,t){if(i&&!t.executed){i.cancel()}}},widgetOptions:e},function(e,n){var s=n.popup;i=n.widget;i.bind("Execute",s.close.bind(s,{executed:true}));s.bind("Size",i._createView.bind(i));if(t){t(e,n)}})}});$.extend(u8.Crm.Widgets.SchedulingView.prototype,{ok:function(){this.raise("Execute",{reason:"ok"})},cancel:function(){this.raise("Execute",{reason:"cancel"})},_create:function(){this.$(this.element).addClass(this.theme.css.root);this._createModel(this._createView.bind(this))},_createModel:function(e){this._model={};Function.chain(this._createItemModel,this._createViewModel).call(this,e)},_createItemModel:function(e){var t=this,i=this.item;if(i||!this.uid||!u8.isValidRecordUid(this.uid)){return e()}u8.services.resourcePlanning.loadItem(this.uid,function(i,n){if(n.error){e();return false}t.item=n.item;e()})},_createViewModel:function(e){if(!this.item){this.item={}}var i=this.item;i.start=this.start||i.start||new Date;i.end=this.end||i.end||new Date;i.repId=this.repId||i.repId;i.participants=this.participants||i.participants;var n=i.start,s=i.end;var a=n.getFirstDayOfWeek().stripTime();var r=a.clone();for(var o=0;o<this.maxWeeks&&s>=r;o++){r.addDays(7)}var u={start:a,end:r};var c=[],d=i.participants&&u8.services.reps.parseParticipants(i.participants);if(i.repId){c.push(i.repId)}if(d){c=c.concat(d.map(u8._.attr(["repId",">string"])))}c.removeDuplicates();this._model={resourcePlan:{parent:this,showGroupColumn:true,showRepMenu:false,gridOptions:{},viewOptions:{pixelsPerDay:"fit-1.25-days",filterItems:false,marker:i},model:{itemFilter:t(i),range:u,defaultTicksPerDay:true,repSet:u8.Crm.RepSets.createRepSetFromIds(c),scales:{scales:[{ranges:["day",{id:"hour",options:{hoursPerRange:4}}],headerRangesCount:1}]}},header:{parent:this,headerGroupName:"Special",headerName:"SchedulingView"}},okButton:{parent:this,text:$t("TXT_net_resources_2"),command:"Ok"},cancelButton:{parent:this,text:$t("TXT_net_resources_3"),command:"Cancel"}};e()},_createView:function(){var t=this;this.$(this.element).empty().utml({name:"scheduling-view-template",template:e,itemOptions:{parent:this},data:this._model},function(){u8.Base.Dom.layout(t.element,"dock");u8.tools.created(this)}.bind(this))},_onCommandOk:function(){this.ok()},_onCommandCancel:function(){this.cancel()}});function t(e){if(!e){return null}return function(t){return!u8.equalsRecordUid(t.uid,e.uid)}}})();