sogo/UI/WebServerResources/js/Scheduler.js
2015-12-15 08:37:55 -05:00

3 lines
34 KiB
JavaScript

!function(){"use strict";function a(a,d){a.state("calendars",{url:"/calendar",views:{calendars:{templateUrl:"UIxCalMainView",controller:"CalendarsController",controllerAs:"app"}},resolve:{stateCalendars:b}}).state("calendars.view",{url:"/{view:(?:day|week|month|multicolumnday)}/:day",views:{calendarView:{templateUrl:function(a){return a.view+"view?day="+a.day},controller:"CalendarController",controllerAs:"calendar"}},resolve:{stateEventsBlocks:c}}),d.when("/calendar/day",function(){var a=new Date;return"/calendar/day/"+a.getDayString()}),d.when("/calendar/multicolumnday",function(){var a=new Date;return"/calendar/multicolumnday/"+a.getDayString()}),d.when("/calendar/week",function(){var a=new Date;return"/calendar/week/"+a.getDayString()}),d.when("/calendar/month",function(){var a=new Date;return"/calendar/month/"+a.getDayString()}),d.otherwise("/calendar")}function b(a){return a.$calendars||a.$findAll(window.calendarsData)}function c(a,b,c){return b.$eventsBlocksForView(a.view,a.day.asDate()).then(function(a){return _.forEach(a,function(a){a.id&&(a.calendar=new c({id:a.id,name:a.calendarName}))}),a})}function d(a,b,c,d,e){a.$on("$stateChangeError",function(a,c,e,f,g,h){b.error(h),d.go("calendar")}),a.$on("$routeChangeError",function(a,c,d,e){b.error(a,c,d,e)}),0===c.url().length&&e.ready().then(function(){var a="/calendar/",b=/(.+)view/.exec(e.settings.Calendar.View);a+=b?b[1]:"week",c.replace().url(a)})}angular.module("SOGo.SchedulerUI",["ngSanitize","ui.router","angularFileUpload","SOGo.Common","SOGo.PreferencesUI","SOGo.ContactsUI","SOGo.MailerUI"]).config(a).run(d),a.$inject=["$stateProvider","$urlRouterProvider"],b.$inject=["Calendar"],c.$inject=["$stateParams","Component","Calendar"],d.$inject=["$rootScope","$log","$location","$state","Preferences"]}(),function(){"use strict";function a(a,b,c,d,e,f,g){function h(){f.$eventsBlocksForView(d.view,d.day.asDate()).then(function(a){k.views=a,_.forEach(k.views,function(a){a.id&&(a.calendar=new e({id:a.id,name:a.calendarName}))})})}function i(a){var b=angular.element(a.currentTarget).attr("date");c.go("calendars.view",{view:d.view,day:b})}var j,k=this;k.views=g,k.changeView=i,j=b.$on("calendars:list",h),a.$on("$destroy",j)}a.$inject=["$scope","$rootScope","$state","$stateParams","Calendar","Component","stateEventsBlocks"],angular.module("SOGo.SchedulerUI").controller("CalendarController",a)}(),function(){"use strict";function a(a,b,c,d,e,f,g,h){function i(a,b){(b&&b.reload||z.componentType!=a)&&(angular.isUndefined(h["$"+a])&&h.$filter(a),z.unselectComponents(),z.componentType=a,h.saveSelectedList(a))}function j(){_.each(h["$"+z.componentType],function(a){a.selected=!1})}function k(){_.each(h["$"+z.componentType],function(a){a.selected=!0})}function m(a,b){b.selected=!b.selected,a.preventDefault(),a.stopPropagation()}function n(){e.confirm(l("Warning"),l("Are you sure you want to delete the selected components?")).then(function(){var a=_.filter(h["$"+z.componentType],function(a){return a.selected});g.$deleteComponents(a)},function(a,b){})}function o(a,b){q(a,b,"appointment")}function p(a,b){q(a,b,"task")}function q(a,b,c){if(b.viewable){var e="UIx"+c.capitalize()+"ViewTemplate";d.show({parent:angular.element(document.body),targetEvent:a,clickOutsideToClose:!0,escapeToClose:!0,templateUrl:e,controller:"ComponentController",controllerAs:"editor",locals:{stateComponent:b}})}}function r(a,b){var c,e="appointment";b?(c=b,e=b.type):("tasks"==z.componentType&&(e="task"),c=new h({pid:g.$defaultCalendar(),type:e}));var f="UIx"+e.capitalize()+"EditorTemplate";return d.show({parent:angular.element(document.body),targetEvent:a,clickOutsideToClose:!0,escapeToClose:!0,templateUrl:f,controller:"ComponentEditorController",controllerAs:"editor",locals:{stateComponent:c}})}function s(c){function e(a,b,c,d){a.updateThisOccurrence=function(){c.$adjust(d).then(b.hide,b.cancel)},a.updateAllOccurrences=function(){delete c.occurrenceId,c.$adjust(d).then(b.hide,b.cancel)}}var f,g,i,j,k;f=h.$ghost.component,g=h.$ghost.pointerHandler,f.isNew?(i=g.currentEventCoordinates,f.isAllDay&&(i.duration-=96),f.setDelta(15*i.duration),r(null,f)["finally"](function(){b(function(){h.$ghost.pointerHandler=null,h.$ghost.component=null})})):(j=g.currentEventCoordinates.getDelta(g.originalEventCoordinates),k={days:j.dayNumber,start:15*j.start,duration:15*j.duration},f.isException||!f.occurrenceId?f.$adjust(k).then(function(){a.$emit("calendars:list"),b(function(){h.$ghost={}})}):f.occurrenceId&&d.show({clickOutsideToClose:!0,escapeToClose:!0,locals:{component:f,params:k},template:['<md-dialog flex="50" md-flex="80" sm-flex="90">',' <md-dialog-content class="md-dialog-content">'," <p>"+l("editRepeatingItem")+"</p>"," </md-dialog-content>"," <md-dialog-actions>",' <md-button ng-click="updateThisOccurrence()">'+l("button_thisOccurrenceOnly")+"</md-button>",' <md-button ng-click="updateAllOccurrences()">'+l("button_allOccurrences")+"</md-button>"," </md-dialog-actions>","</md-dialog>"].join(""),controller:e}).then(function(){a.$emit("calendars:list")})["finally"](function(){b(function(){h.$ghost={}})})),e.$inject=["$scope","$mdDialog","component","params"]}function t(a){h.$filter(z.componentType,{filterpopup:a})}function u(a){return h["$query"+z.componentType.capitalize()].filterpopup==a}function v(a){h.$filter(z.componentType,{sort:a})}function w(a){return h["$query"+z.componentType.capitalize()].sort==a}function x(){a.$emit("calendars:list")}function y(){z.mode.search=!1,h.$filter(z.componentType,{value:""})}var z=this;z.component=h,z.componentType="events",z.selectedList=0,z.selectComponentType=i,z.unselectComponents=j,z.selectAll=k,z.toggleComponentSelection=m,z.confirmDeleteSelectedComponents=n,z.openEvent=o,z.openTask=p,z.newComponent=r,z.filter=t,z.filteredBy=u,z.sort=v,z.sortedBy=w,z.reload=x,z.cancelSearch=y,z.mode={search:!1},f.ready().then(function(){var a="events";"tasksListView"==f.settings.Calendar.SelectedList&&(z.selectedList=1,a="tasks"),i(a,{reload:!0})}),a.$on("calendars:list",function(){h.$filter(z.componentType,{reload:!0})}),a.$on("calendar:dragend",s)}a.$inject=["$rootScope","$timeout","$state","$mdDialog","Dialog","Preferences","Calendar","Component"],angular.module("SOGo.SchedulerUI").controller("CalendarListController",a)}(),function(){"use strict";function a(a,b,c,d,e,f,g,h,i,j,k,m,n,o){function p(a){i.prompt(l("New calendar"),l("Name of the Calendar")).then(function(a){var b=new m({name:a,isEditable:!0,isRemote:!1,owner:UserLogin});b.$id().then(function(){m.$add(b)})})}function q(){i.prompt(l("Subscribe to a web calendar..."),l("URL of the Calendar"),{inputType:"url"}).then(function(a){m.$addWebCalendar(a)})}function r(b){b.isSubscription?b.$delete().then(function(){a.$emit("calendars:list")},function(a,c){i.alert(l('An error occured while deleting the calendar "%{0}".',b.name),l(a.error))}):i.confirm(l("Warning"),l("Are you sure you want to delete the calendar <em>%{0}</em>?",b.name)).then(function(){b.$delete().then(function(){a.$emit("calendars:list")},function(a,c){i.alert(l('An error occured while deleting the calendar "%{0}".',b.name),l(a.error))})})}function s(b,c){function e(b,c,d){function e(a){var b=0===a.type.indexOf("text")||/\.(ics)$/.test(a.name);return b||f.show({template:["<md-toast>",' <div class="md-toast-content">',' <md-icon class="md-warn md-hue-1">error_outline</md-icon>'," <span>"+l("Select an iCalendar file (.ics).")+"</span>"," </div>","</md-toast>"].join(""),position:"top right",hideDelay:3e3}),b}var h=this;h.uploader=new g({url:ApplicationBaseURL+[d.id,"import"].join("/"),autoUpload:!0,queueLimit:1,filters:[{name:e,fn:e}],onSuccessItem:function(b,d,e,g){var h;c.hide(),0===d.imported?h=l("No event was imported."):(h=l("A total of %{0} events were imported in the calendar.",d.imported),a.$emit("calendars:list")),f.show(f.simple().content(h).position("top right").hideDelay(3e3))},onErrorItem:function(a,b,c,d){f.show({template:["<md-toast>",' <div class="md-toast-content">',' <md-icon class="md-warn md-hue-1">error_outline</md-icon>'," <span>"+l("An error occurred while importing calendar.")+"</span>"," </div>","</md-toast>"].join(""),position:"top right",hideDelay:3e3})}}),h.close=function(){c.hide()}}d.show({parent:angular.element(document.body),targetEvent:b,clickOutsideToClose:!0,escapeToClose:!0,templateUrl:"UIxCalendarImportDialog",controller:e,controllerAs:"$CalendarImportDialogController",locals:{folder:c}}),e.$inject=["scope","$mdDialog","folder"]}function t(a){window.location.href=ApplicationBaseURL+"/"+a.id+".ics/export"}function u(a){function b(a,b){function c(){a.hide()}var d=this;d.calendar=b,d.close=c}d.show({parent:angular.element(document.body),clickOutsideToClose:!0,escapeToClose:!0,templateUrl:a.id+"/links",controller:b,controllerAs:"links",locals:{calendar:a}}),b.$inject=["$mdDialog","calendar"]}function v(a){function b(a,b,c){function d(){f.calendar.$save(),c.init(f.calendar.$omit()),b.hide()}function e(){b.cancel()}var f=this;f.calendar=new m(c.$omit()),f.saveProperties=d,f.close=e,a.$watch("properties.calendar.color",function(){c.color=f.calendar.color})}var c=a.color;d.show({templateUrl:a.id+"/properties",controller:b,controllerAs:"properties",clickOutsideToClose:!0,escapeToClose:!0,locals:{srcCalendar:a}})["catch"](function(){a.color=c}),b.$inject=["$scope","$mdDialog","srcCalendar"]}function w(a){C.calendarName=a.name,C.editMode=a.id,h("calendarName_"+a.id)}function x(a){a.$reset(),C.editMode=!1}function y(a){a.$rename().then(function(a){C.editMode=!1},function(a,b){i.alert(l("Warning"),a)})}function z(a){a.$acl.$users().then(function(){d.show({templateUrl:a.id+"/UIxAclEditor",controller:"AclController",controllerAs:"acl",clickOutsideToClose:!0,escapeToClose:!0,locals:{usersWithACL:a.$acl.users,User:n,folder:a}})})}function A(a){e.debug("subscribeToFolder "+a.owner+a.name),m.$subscribe(a.owner,a.name).then(function(a){f.show(f.simple().content(l("Sucessfully subscribed to calendar")).position("top right").hideDelay(3e3))})}function B(){var a=c.location.hash.split("/"),b=a[1],d=a[2],e=new Date,f=["#",b,d,e.getDayString()];c.location=f.join("/")}var C=this;C.activeUser=j.activeUser,C.service=m,C.newCalendar=p,C.addWebCalendar=q,C.confirmDelete=r,C.editFolder=w,C.revertEditing=x,C.renameFolder=y,C.share=z,C.importCalendar=s,C.exportCalendar=t,C.showLinks=u,C.showProperties=v,C.subscribeToFolder=A,C.today=B,k.ready().then(function(){C.categories=_.map(k.defaults.SOGoCalendarCategories,function(a){return{id:a.asCSSIdentifier(),name:a,color:k.defaults.SOGoCalendarCategoriesColors[a]}})}),b.$watch(function(){return _.union(_.map(m.$calendars,function(a){return _.pick(a,["id","active","color"])}),_.map(m.$subscriptions,function(a){return _.pick(a,["id","active","color"])}),_.map(m.$webcalendars,function(a){return _.pick(a,["id","active","color"])}))},function(b,c){var d=_.pluck(_.filter(b,function(a,b){return!_.isEqual(a,c[b])}),"id");d.length>0&&(e.debug(d.join(", ")+" changed"),_.each(d,function(b){var c=m.$get(b);c.$setActivation().then(function(){a.$emit("calendars:list")})}))},!0)}a.$inject=["$rootScope","$scope","$window","$mdDialog","$log","$mdToast","FileUploader","sgFocus","Dialog","sgSettings","Preferences","Calendar","User","stateCalendars"],angular.module("SOGo.SchedulerUI").controller("CalendarsController",a)}(),function(){"use strict";function a(a,b,c,d,e,f){function g(){b.hide()}function h(a){return d.$filterAll(a),d.$cards}function i(){var a="vevent"==r.component.component?"Appointment":"Task";b.hide().then(function(){var c="UIx"+a+"EditorTemplate";b.show({parent:angular.element(document.body),clickOutsideToClose:!0,escapeToClose:!0,templateUrl:c,controller:"ComponentEditorController",controllerAs:"editor",locals:{stateComponent:r.component}})})}function j(){q=c.$get(r.component.pid).$getComponent(r.component.id),q.$futureComponentData.then(function(){r.component=q,i()})}function k(c){var d=c||r.component;d.$reply().then(function(){a.$emit("calendars:list"),b.hide(),e.getAlarms()})}function m(){q=c.$get(r.component.pid).$getComponent(r.component.id),q.$futureComponentData.then(function(){q.reply=r.component.reply,q.delegatedTo=r.component.delegatedTo,q.$hasAlarm=r.component.$hasAlarm,q.alarm=r.component.alarm,k(q)})}function n(){r.component.remove(!0).then(function(){a.$emit("calendars:list"),b.hide()})}function o(){r.component.remove().then(function(){a.$emit("calendars:list"),b.hide()})}function p(a){c.$$resource.post(r.component.pid+"/"+r.component.id,"raw").then(function(c){function d(a,b){a.close=function(){b.hide()}}b.hide(),b.show({parent:angular.element(document.body),targetEvent:a,clickOutsideToClose:!0,escapeToClose:!0,template:['<md-dialog flex="80" flex-xs="100" aria-label="'+l("View Raw Source")+'">',' <md-dialog-content class="md-dialog-content">'," <pre>",c," </pre>"," </md-dialog-content>"," <md-dialog-actions>",' <md-button ng-click="close()">'+l("Close")+"</md-button>"," </md-dialog-actions>","</md-dialog>"].join(""),controller:d}),d.$inject=["scope","$mdDialog"]})}var q,r=this;r.component=f,r.close=g,r.cardFilter=h,r.edit=i,r.editAllOccurrences=j,r.reply=k,r.replyAllOccurrences=m,r.deleteOccurrence=n,r.deleteAllOccurrences=o,r.toggleRawSource=p,angular.isUndefined(r.component.$futureComponentData)&&(q=c.$get(r.component.pid).$getComponent(r.component.id,r.component.occurrenceId),q.$futureComponentData.then(function(){r.component=q,r.organizer=[r.component.organizer]}))}function b(a,b,c,d,e,f,g,h,i,j,k,l){function m(){var a=H.component.addAttachUrl("");focus("attachUrl_"+a)}function n(){H.showRecurrenceEditor=!H.showRecurrenceEditor,H.component.$hasCustomRepeat=H.showRecurrenceEditor}function o(){H.showAttendeesEditor=!H.showAttendeesEditor}function p(a){return i.$filterAll(a),i.$cards}function q(a){angular.isString(a)?a.isValidEmail()&&(H.component.addAttendee(new j({emails:[{value:a}]})),H.searchText=""):H.component.addAttendee(a)}function r(b){b.$valid&&H.component.$save().then(function(b){a.$emit("calendars:list"),e.hide(),k.getAlarms()},function(a,b){c.debug("failed")})}function s(){H.component.$reset(),H.component.isNew&&(H.component=null),e.cancel()}function t(){var a=[];return H.component.start&&H.component.end&&(a=H.component.start.daysUpTo(H.component.end)),_.map(a,function(a){return{stringWithSeparator:a.stringWithSeparator(),getDayString:a.getDayString()}})}function u(){for(var a=[],b=0;23>=b;b++)a.push(b.toString());return a}function v(){H.component.$addStartDate(),E=new Date(H.component.start.getTime())}function w(){H.component.$addDueDate(),G=new Date(H.component.due.getTime())}function x(){H.component.start.addMinutes(60*E.getHours()+E.getMinutes()),y()}function y(){var a;a=E.valueOf()-H.component.start.valueOf(),0!==a&&(E=new Date(H.component.start.getTime()),"appointment"===H.component.type&&(H.component.end=new Date(H.component.start.getTime()),H.component.end.addMinutes(H.component.delta),F=new Date(H.component.end.getTime()))),D()}function z(){H.component.end.addMinutes(60*F.getHours()+F.getMinutes()),A()}function A(){var a=H.component.start.minutesTo(H.component.end);0>a?H.component.end=new Date(F.getTime()):(H.component.delta=a,F=new Date(H.component.end.getTime())),D()}function B(){H.component.due.addMinutes(60*G.getHours()+G.getMinutes()),C()}function C(){G=new Date(H.component.due.getTime())}function D(){H.attendeesEditor.days=t(),H.component.updateFreeBusy()}var E,F,G,H=this;H.service=g,H.component=l,H.categories={},H.showRecurrenceEditor=H.component.$hasCustomRepeat,H.toggleRecurrenceEditor=n,H.showAttendeesEditor=angular.isDefined(H.component.attendees),H.toggleAttendeesEditor=o,H.cardFilter=p,H.addAttendee=q,H.addAttachUrl=m,H.cancel=s,H.save=r,H.attendeesEditor={days:t(),hours:u()},H.addStartDate=v,H.addDueDate=w,H.updateStartTime=x,H.adjustStartTime=y,H.updateEndTime=z,H.adjustEndTime=A,H.updateDueTime=B,H.adjustDueTime=C,H.component.start&&(E=new Date(H.component.start.getTime())),H.component.end&&(F=new Date(H.component.end.getTime())),H.component.due&&(G=new Date(H.component.due.getTime()))}a.$inject=["$rootScope","$mdDialog","Calendar","AddressBook","Alarm","stateComponent"],b.$inject=["$rootScope","$scope","$log","$timeout","$mdDialog","User","Calendar","Component","AddressBook","Card","Alarm","stateComponent"],angular.module("SOGo.SchedulerUI").controller("ComponentController",a).controller("ComponentEditorController",b)}(),function(){"use strict";function a(){return{restrict:"E",scope:{day:"@sgDay",dayNumber:"@sgDayNumber",dayString:"@sgDayString"},controller:b}}function b(a){this.day=a.day,this.dayNumber=a.dayNumber,this.dayString=a.dayString}b.$inject=["$scope"],angular.module("SOGo.SchedulerUI").directive("sgCalendarDay",a)}(),function(){"use strict";function a(a){function b(a,b,c){var d,e,f;d=100/a.block.siblings,e=a.block.position*d,f=100-(a.block.position+1)*d,100>d&&(e>0&&(e-=2),f>0&&(f-=2)),0===e&&(e=2),0===f&&(f=2),b.css("left",e+"%"),b.css("right",f+"%"),b.addClass("starts"+a.block.start),b.addClass("lasts"+a.block.length),a.block.component&&b.addClass("bg-folder"+a.block.component.pid)}return{restrict:"E",scope:{block:"=sgBlock",clickBlock:"&sgClick"},replace:!0,template:['<div class="sg-event"'," ng-class=\"{'sg-event--dragging': block.dragging}\">",' <div class="eventInside"',' ng-click="clickBlock({clickEvent: $event, clickComponent: block.component})">',' <div class="sg-category" ng-repeat="category in block.component.categories"'," ng-class=\"'bg-category' + category\""," ng-style=\"{ right: ($index * 3) + 'px' }\"></div>",' <div class="text">{{ block.component.summary }}',' <span class="icons">',' <md-icon ng-if="block.component.occurrenceId" class="material-icons icon-repeat"></md-icon>',' <md-icon ng-if="block.component.c_nextalarm" class="material-icons icon-alarm"></md-icon>',' <md-icon ng-if="block.component.c_classification == 1" class="material-icons icon-visibility-off"></md-icon>',' <md-icon ng-if="block.component.c_classification == 2" class="material-icons icon-vpn-key"></md-icon>'," </span>",' <div class="secondary" ng-if="block.component.c_location">'," <md-icon>place</md-icon> {{block.component.c_location}}"," </div>"," </div>"," </div>","</div>"].join(""),link:b}}a.$inject=["CalendarSettings"],angular.module("SOGo.SchedulerUI").directive("sgCalendarDayBlock",a)}(),function(){"use strict";function a(){return{restrict:"E",scope:{blocks:"=sgBlocks",day:"@sgDay",clickBlock:"&sgClick"},template:["<sg-calendar-day-block",' class="sg-draggable-calendar-block"',' ng-repeat="block in blocks[day]"',' sg-block="block"',' sg-click="clickBlock({event: clickEvent, component: clickComponent})"/>'].join("")}}angular.module("SOGo.SchedulerUI").directive("sgCalendarDayTable",a)}(),function(){"use strict";function a(a,b,c,d,e){function f(f,g,h,i){function j(){f.block=e.$ghost,g.addClass("bg-folder"+f.block.component.pid)}function k(){_.forEachRight(p.classList,function(a){/^bg-folder/.test(a)&&g.removeClass(a)}),g.addClass("ng-hide")}function l(){var a,e,h,i,j,k,l,m,p,s;if(a=!1,s=function(){g.removeClass("sg-event--notransition")},d.$view&&d.$view.type==r.type){if(e="multiday-allday"===r.type,h=f.block.pointerHandler.originalEventCoordinates.dayNumber,i=f.block.pointerHandler.currentEventCoordinates.dayNumber,k=f.block.pointerHandler.currentEventCoordinates.start,m=f.block.pointerHandler.currentEventCoordinates.duration,p=c.EventDragDayLength-k,angular.isUndefined(m))return;for(l=m,l>p&&(l=p),delete f.startHour,delete f.endHour,i>-1&&i==q.dayNumber&&(a=!0,e||(f.startHour=n(k),j=0===parseInt(g.css("top")),j&&g.addClass("sg-event--notransition"),d.$view.quarterHeight?(g.css("top",k*d.$view.quarterHeight+"px"),g.css("height",l*d.$view.quarterHeight+"px")):g.css("top",d.$view.topOffset+"px"),j&&b(s)),g.removeClass("fg-folder"+f.block.component.pid),g.removeClass("sg-event--ghost--last"),g.addClass("sg-event--ghost--first")),m-=l,i++;!a&&m&&i<=q.dayNumber;)l=m,l>c.EventDragDayLength&&(l=c.EventDragDayLength),i>-1&&i==q.dayNumber&&(a=!0,e||(j=0!==parseInt(g.css("top")),j&&g.addClass("sg-event--notransition"),g.css("top",d.$view.topOffset+"px"),d.$view.quarterHeight&&g.css("height",l*d.$view.quarterHeight+"px"),j&&b(s)),g.removeClass("sg-event--ghost--first"),g.removeClass("sg-event--ghost--last"),g.addClass("fg-folder"+f.block.component.pid)),m-=l,i++,k=0;m||(e?g.addClass("sg-event--ghost--last"):f.endHour=o(k,l))}a?g.removeClass("ng-hide"):g.addClass("ng-hide")}function m(a){var b,c,d;return b=15*a,c=Math.floor(b/60),10>c&&(c="0"+c),d=b%60,10>d&&(d="0"+d),""+c+":"+d}function n(a){return m(a)}function o(a,b){var d=(a+b)%c.EventDragDayLength;return m(d)}var p,q,r;p=g[0],q=i[0],r=i[1],g.addClass("sg-event--ghost md-whiteframe-3dp ng-hide");var s=a.$on("calendar:dragstart",j),t=a.$on("calendar:drag",l),u=a.$on("calendar:dragend",k);f.$on("$destroy",function(){s(),t(),u()})}return{restrict:"A",require:["^sgCalendarDay","^sgCalendarScrollView"],link:f}}a.$inject=["$rootScope","$timeout","CalendarSettings","Calendar","Component"],angular.module("SOGo.SchedulerUI").directive("sgCalendarGhost",a)}(),function(){"use strict";function a(){return{restrict:"E",scope:{blocks:"=sgBlocks",day:"@sgDay",clickBlock:"&sgClick"},template:["<sg-calendar-month-event",' class="sg-draggable-calendar-block"',' ng-repeat="block in blocks[day]"',' sg-block="block"',' sg-click="clickBlock({event: clickEvent, component: clickComponent})"/>'].join("")}}angular.module("SOGo.SchedulerUI").directive("sgCalendarMonthDay",a)}(),function(){"use strict";function a(){function a(a,b,c){a.block.component&&b.addClass("bg-folder"+a.block.component.pid)}return{restrict:"E",scope:{block:"=sgBlock",clickBlock:"&sgClick"},replace:!0,template:['<div class="sg-event"'," ng-class=\"{'sg-event--dragging': block.dragging}\"",' ng-click="clickBlock({clickEvent: $event, clickComponent: block.component})">',' <span class="secondary" ng-if="!block.component.c_isallday">{{ block.starthour }}</span>'," {{ block.component.summary }}",' <span class="icons">',' <md-icon ng-if="block.component.occurrenceId" class="material-icons icon-repeat"></md-icon>',' <md-icon ng-if="block.component.c_nextalarm" class="material-icons icon-alarm"></md-icon>',' <md-icon ng-if="block.component.c_classification == 1" class="material-icons icon-visibility-off"></md-icon>',' <md-icon ng-if="block.component.c_classification == 2" class="material-icons icon-vpn-key"></md-icon>'," </span>","</div>"].join(""),link:a}}angular.module("SOGo.SchedulerUI").directive("sgCalendarMonthEvent",a)}(),function(){"use strict";function a(a,c,d,e,f,g,h,i,j){return{restrict:"A",scope:{type:"@sgCalendarScrollView"},controller:b,link:function(b,d,e,g){function k(){var a;a=l(),s={type:u,quarterHeight:a,scrollStep:6*a,maxX:n(),element:t},angular.element(c).on("resize",o),o(),"monthly"!=u&&j.ready().then(function(){var b,c,d;j.defaults.SOGoDayStartTime&&(b=j.defaults.SOGoDayStartTime.split(":"),c=document.getElementById("hour"+parseInt(b[0])),d=parseInt(b[1])*a,t.scrollTop=c.offsetTop+d)})}function l(){var a,b,c=null;return a=document.getElementById("hour0"),b=document.getElementById("hour23"),a&&b&&(c=(b.offsetTop-a.offsetTop)/92),c}function m(a){var b,c,d,e,f,g,h;return c=b=d=e=0,f=t.getElementsByClassName("day0"),f.length>0&&(g=f[0].getBoundingClientRect(),c=g.height,b=g.width,d=g.left-a,h=f[0].getElementsByClassName("sg-calendar-tile-header"),h.length>0&&(e=h[0].clientHeight)),{height:c,width:b,offset:{left:d,top:e}}}function n(){var a=0;return a=t.getElementsByClassName("day").length-1}function o(){var a,b;a=t.getBoundingClientRect(),b=m(a.left),angular.extend(s,{coordinates:{x:a.left,y:a.top},dayHeight:b.height,dayWidth:b.width,daysOffset:b.offset.left,topOffset:b.offset.top})}function p(){d.on("mouseover",r),r()}function q(){d.off("mouseover",r),h.$view=null}function r(){var a,b,c,d,e,f,g;a=s.scrollStep,b=i.$ghost.pointerHandler,b&&(c=b.getContainerBasedCoordinates(s),c&&(h.$view=s,d=(new Date).getTime(),(!v||d>v+100)&&(v=d,e=c.y-a,0>e?(f=-t.scrollTop,f>e&&(e=f),t.scrollTop+=e):(e=c.y+a,g=e-t.clientHeight,g>0&&(t.scrollTop+=g)))))}var s,t,u,v,w,x;t=d[0],u=b.type,v=0,w=a.$on("calendar:dragstart",p),x=a.$on("calendar:dragend",q),f(k),b.$on("$destroy",function(){w(),x(),d.off("mouseover",r),angular.element(c).off("resize",o)})}}}function b(a){this.type=a.type}a.$inject=["$rootScope","$window","$document","$q","$timeout","$mdGesture","Calendar","Component","Preferences"],b.$inject=["$scope"],angular.module("SOGo.SchedulerUI").directive("sgCalendarScrollView",a)}(),function(){"use strict";function a(){return{restrict:"E",scope:{calendars:"=sgCalendars",calendar:"@sgCalendar",blocksType:"@sgBlocksType",day:"@sgDay",clickBlock:"&sgClick"},template:["<sg-calendar-day-table",' sg-blocks="calendars[calendar][blocksType]"',' sg-day="day"',' sg-click="clickBlock({event: clickEvent, component: clickComponent})"/>'].join("")}}angular.module("SOGo.SchedulerUI").directive("sgCalendarTable",a)}(),function(){"use strict";function a(){return{restrict:"E",require:"ngModel",scope:{ngModel:"="},replace:!0,template:['<style type="text/css">'," .bg-category{{ ngModel.id }} {"," background-color: {{ ngModel.color }} !important;"," }"," .bdr-category{{ ngModel.id }} {"," border-color: {{ ngModel.color }} !important;"," }","</style>"].join("")}}angular.module("SOGo.SchedulerUI").directive("sgCategoryStylesheet",a)}(),function(){"use strict";function a(a,b,c,d,e,f){function g(g,h,i,j){function k(){var a,b,c,d,e,f,i,j,k,l;a=g.block.component,b=g.block.dayNumber,c=_.findIndex(a.blocks,_.matchesProperty("dayNumber",b)),d=0===c,e=c===a.blocks.length-1,f=angular.element('<div class="dragGrip"></div>'),f.addClass("bdr-folder"+a.pid),a.c_isallday||"SG-CALENDAR-MONTH-DAY"===h[0].parentNode.tagName?(d&&(i=angular.element('<div class="dragGrip-left"></div>').append(f),h.append(i)),e&&(j=angular.element('<div class="dragGrip-right"></div>').append(f.clone()),h.append(j))):(d&&(k=angular.element('<div class="dragGrip-top"></div>').append(f),h.append(k)),e&&(l=angular.element('<div class="dragGrip-bottom"></div>').append(f.clone()),h.append(l)))}function m(a){var b,c;a.stopPropagation(),b="move-event",g.block&&g.block.component?"dragGrip-top"==a.target.className||"dragGrip-left"==a.target.className?b="change-start":("dragGrip-bottom"==a.target.className||"dragGrip-right"==a.target.className)&&(b="change-end"):b="change-end",c=new s(b),c.initFromEvent(a),f.$ghost.pointerHandler=c,angular.element(document).one("mouseup",p),angular.element(document).on("mousemove",o)}function n(b){var e,i,k,m,n,o,p,q;k=h.hasClass("clickableHourCell"),m="SG-CALENDAR-MONTH-DAY"==h[0].parentNode.tagName||h.hasClass("clickableDayCell"),g.block&&g.block.component?e=g.block:(n=new Date(j.dayString.substring(0,10)+" "+j.dayString.substring(11,16)),o={type:"appointment",pid:d.$defaultCalendar(),summary:l("New Event"),startDate:n,isAllDay:k?0:1},p=new f(o),e={component:p,dayNumber:j.dayNumber,length:0},e.component.blocks=[e]),i="multiday",m?i="monthly":e.component.c_isallday&&(i="multiday-allday"),_.forEach(e.component.blocks,function(a){a.dragging=!0}),q=f.$ghost.pointerHandler,q.prepareWithEventType(i),q.initFromBlock(e),f.$ghost.starthour=e.starthour,f.$ghost.component=e.component,c.debug("emit calendar:dragstart"),a.$emit("calendar:dragstart")}function o(a){var c=f.$ghost.pointerHandler;b(function(){c.updateFromEvent(a)})}function p(b){var c,d;c=g.block,d=f.$ghost.pointerHandler,angular.element(document).off("mousemove",o),d.dragHasStarted&&(a.$emit("calendar:dragend"),d.dragHasStarted=!1),c&&_.forEach(c.component.blocks,function(a){a.dragging=!1})}function q(){}function r(a){this.setEventType(a)}function s(a){this.dragMode=a}if(g.block){if(!g.block.component.editable)return void h.removeClass("sg-draggable-calendar-block");k()}h.on("mousedown",m),g.$on("$destroy",function(){h.off("mousedown",m),h.off("mousemove",o)}),q.prototype={x:-1,y:-1,getDelta:function(a){var b=new q;return b.x=this.x-a.x,b.y=this.y-a.y,b},getDistance:function(a){var b=this.getDelta(a);return Math.sqrt(b.x*b.x+b.y*b.y)},clone:function(){var a=new q;return a.x=this.x,a.y=this.y,a}},r.prototype={dayNumber:-1,start:-1,duration:-1,eventType:null,setEventType:function(a){this.eventType=a},initFromBlock:function(a){"monthly"===this.eventType?(this.start=0,this.duration=96*a.component.blocks.length):(this.start=a.component.blocks[0].start,this.duration=_.sum(a.component.blocks,function(a){return a.length})),this.dayNumber=a.component.blocks[0].dayNumber},getDelta:function(a){var b=new r;return b.dayNumber=this.dayNumber-a.dayNumber,b.start=this.start-a.start,b.duration=this.duration-a.duration,b},_quartersToHM:function(a){var b=15*a,c=Math.floor(b/60);10>c&&(c="0"+c);var d=b%60;return 10>d&&(d="0"+d),""+c+":"+d},getStartTime:function(){return this._quartersToHM(this.start)},getEndTime:function(){var a=(this.start+this.duration)%e.EventDragDayLength;return this._quartersToHM(a)},clone:function(){var a=new r;return a.dayNumber=this.dayNumber,a.start=this.start,a.duration=this.duration,a}},s.prototype={originalCoordinates:null,currentCoordinates:null,originalViewCoordinates:null,currentViewCoordinates:null,originalEventCoordinates:null,currentEventCoordinates:null,dragHasStarted:!1,getEventViewCoordinates:null,initFromBlock:function(a){this.currentEventCoordinates=new r(this.eventType),this.originalEventCoordinates=new r(this.eventType),this.originalEventCoordinates.initFromBlock(a)},initFromEvent:function(a){this.currentCoordinates=new q,this.updateFromEvent(a),this.originalCoordinates=this.currentCoordinates.clone()},updateFromEvent:function(a){if(this.currentCoordinates.x=a.pageX,this.currentCoordinates.y=a.pageY,this.dragHasStarted&&d.$view){var b=this.getEventViewCoordinates(d.$view);this.originalViewCoordinates||(this.originalViewCoordinates=this.getEventViewCoordinates(d.$view,this.originalCoordinates),f.$ghost.component.isNew&&(this.setTimeFromQuarters(f.$ghost.component.start,this.originalViewCoordinates.y),c.debug("new event start date "+f.$ghost.component.start))),this.currentViewCoordinates&&b&&b.x==this.currentViewCoordinates.x&&b.y==this.currentViewCoordinates.y||(this.currentViewCoordinates=b,this.originalViewCoordinates&&(b||(this.currentViewCoordinates=this.originalViewCoordinates.clone()),this.updateEventCoordinates()))}else if(this.originalCoordinates&&this.currentCoordinates&&!this.dragHasStarted){var e=this.getDistance();e>3&&(this.dragHasStarted=!0,n(a))}},updateEventCoordinates:function(){var b,d=this.currentViewCoordinates.getDelta(this.originalViewCoordinates),f=d.x*e.EventDragDayLength+d.y;c.debug("quarters delta "+f),angular.isUndefined(this.originalEventCoordinates.start)&&(this.originalEventCoordinates.dayNumber=this.originalViewCoordinates.x,this.originalEventCoordinates.start=this.originalViewCoordinates.y),this.currentEventCoordinates.dayNumber=this.originalEventCoordinates.dayNumber,"move-event"==this.dragMode?(this.currentEventCoordinates.start=this.originalEventCoordinates.start+f,this.currentEventCoordinates.duration=this.originalEventCoordinates.duration):"change-start"==this.dragMode?(b=this.originalEventCoordinates.duration-f,b>0?(this.currentEventCoordinates.start=this.originalEventCoordinates.start+f,this.currentEventCoordinates.duration=b):0>b&&(this.currentEventCoordinates.start=this.originalEventCoordinates.start+this.originalEventCoordinates.duration,this.currentEventCoordinates.duration=-b)):"change-end"==this.dragMode&&(b=this.originalEventCoordinates.duration+f,b>0?(this.currentEventCoordinates.start=this.originalEventCoordinates.start,this.currentEventCoordinates.duration=b):0>b&&(this.currentEventCoordinates.start=this.originalEventCoordinates.start+b,this.currentEventCoordinates.duration=-b));var g;this.currentEventCoordinates.start<0?(g=Math.ceil(-this.currentEventCoordinates.start/e.EventDragDayLength),
this.currentEventCoordinates.start+=g*e.EventDragDayLength,this.currentEventCoordinates.dayNumber-=g):this.currentEventCoordinates.start>=e.EventDragDayLength&&(g=Math.floor(this.currentEventCoordinates.start/e.EventDragDayLength),this.currentEventCoordinates.start-=g*e.EventDragDayLength,this.currentEventCoordinates.dayNumber+=g),c.debug("event coordinates "+JSON.stringify(this.currentEventCoordinates)),a.$emit("calendar:drag")},getContainerBasedCoordinates:function(a,b){var c=b||this.currentCoordinates,d=c.getDelta(a.coordinates),e=a.element;return(d.x<a.daysOffset||d.x>e.clientWidth||d.y<0||d.y>e.clientHeight)&&(d=null),d},prepareWithEventType:function(a){var b={multiday:this.getEventMultiDayViewCoordinates,"multiday-allday":this.getEventMultiDayAllDayViewCoordinates,monthly:this.getEventMonthlyViewCoordinates,unknown:null},c=b[a];this.eventType=a,this.getEventViewCoordinates=c},getEventMultiDayViewCoordinates:function(a,b){var c=this.getEventMultiDayAllDayViewCoordinates(a,b);if(c){var d=a.quarterHeight,f=this.getContainerBasedCoordinates(a,b);f.y+=a.element.scrollTop,c.y=Math.floor((f.y-e.EventDragHorizontalOffset)/d);var g=e.EventDragDayLength-1;c.y<0?c.y=0:c.y>g&&(c.y=g)}return c},getEventMultiDayAllDayViewCoordinates:function(a,b){var c,e=this.getContainerBasedCoordinates(a,b);if(e){c=new q;var f=a.dayWidth,g=a.daysOffset;c.x=Math.floor((e.x-g)/f);var h=d.$view.maxX;c.x<0?c.x=0:c.x>h&&(c.x=h),c.y=0}else c=null;return c},getEventMonthlyViewCoordinates:function(a,b){var c,d=this.getContainerBasedCoordinates(a,b);if(d){c=new q;var e=0,f=a.dayWidth,g=a.daysOffset,h=a.dayHeight,i=Math.floor((d.y-e)/h);0>i&&(i=0),c.x=Math.floor((d.x-g)/f),c.x<0?c.x=0:c.x>6&&(c.x=6),c.x+=7*i,c.y=0}else c=null;return c},getDistance:function(){return this.currentCoordinates.getDistance(this.originalCoordinates)},setTimeFromQuarters:function(a,b){var c,d;c=Math.floor(b/4),d=b%4*15,a.setHours(c,d)}}}return{restrict:"CA",require:"^sgCalendarDay",link:g}}a.$inject=["$rootScope","$timeout","$log","Calendar","CalendarSettings","Component"],angular.module("SOGo.SchedulerUI").directive("sgDraggableCalendarBlock",a)}(),function(){"use strict";function a(a,b,c,d,e,f){return{restrict:"CA",scope:{onDrop:"&sgOnDrop"},link:function(b,c,d,e){var f=a.$on("calendar:dragend",b.onDrop);b.$on("$destroy",f)}}}a.$inject=["$rootScope","$timeout","$mdGesture","Calendar","CalendarSettings","Component"],angular.module("SOGo.SchedulerUI").directive("sgDroppableBlock",a)}();
//# sourceMappingURL=Scheduler.js.map