[13754] | 1 |
|
---|
[13758] | 2 | angular.module('wjm', ['ui.bootstrap', 'ui.calendar', 'angularTreeview', 'ngDialog']).
|
---|
[13754] | 3 |
|
---|
[13768] | 4 | controller('resourceCtrl', function ($rootScope, $scope, uiCalendarConfig, $compile, ngDialog, $timeout) {
|
---|
[13754] | 5 | var vm = $scope;
|
---|
| 6 |
|
---|
| 7 | var date = new Date();
|
---|
| 8 |
|
---|
| 9 | var d = date.getDate();
|
---|
| 10 | var m = date.getMonth();
|
---|
| 11 | var y = date.getFullYear();
|
---|
| 12 | var hubber = $.connection.calendarHub;
|
---|
[13775] | 13 |
|
---|
[13754] | 14 | vm.alertMessage = "No alerts";
|
---|
| 15 | vm.currentcal = [];
|
---|
| 16 | vm.selectedEventId = -1;
|
---|
[13782] | 17 | vm.groups = [];
|
---|
| 18 | vm.clients = [];
|
---|
[13754] | 19 | vm.init = function () {
|
---|
| 20 |
|
---|
| 21 | // $.connection.hub.logging = true;
|
---|
| 22 |
|
---|
| 23 |
|
---|
| 24 | var v = document.getElementById("userId").innerHTML;
|
---|
| 25 | $.connection.hub.qs = { 'userid': v };
|
---|
| 26 | $.connection.hub.start().done(function () {
|
---|
| 27 | hubber.server.requestInfo();
|
---|
| 28 | });
|
---|
| 29 | hubber.client.processData = function (data) {
|
---|
| 30 | vm.data = JSON.parse(data);
|
---|
| 31 | $scope.buildTree();
|
---|
| 32 |
|
---|
| 33 | $scope.$apply();
|
---|
| 34 | };
|
---|
[13768] | 35 | hubber.client.savingCurrentDone = function () {
|
---|
[13782] | 36 | vm.calendarSaver = false;
|
---|
[13768] | 37 | $scope.clearCurrentCalendar();
|
---|
| 38 | $scope.$apply();
|
---|
| 39 | };
|
---|
| 40 | hubber.client.savingAllDone = function () {
|
---|
[13782] | 41 | vm.calendarSaver = false;
|
---|
[13768] | 42 | clearAllCalendarsFunc();
|
---|
| 43 | $scope.$apply();
|
---|
| 44 | };
|
---|
[13782] | 45 | hubber.client.processDispose = function (disp) {
|
---|
| 46 | vm.treeview.currentNode.IsDisposable = disp;
|
---|
| 47 | $scope.calendarDispose = false;
|
---|
| 48 | $scope.$apply();
|
---|
| 49 | }
|
---|
[13754] | 50 | hubber.client.processDowntime = function (id, down) {
|
---|
| 51 | var json = JSON.parse(down);
|
---|
| 52 | var arrdown = [];
|
---|
[13758] | 53 | var str = "";
|
---|
[13754] | 54 | for (var i = 0; i < json.length; i++) {
|
---|
[13758] | 55 | if (json[i].DowntimeType === 0) {
|
---|
| 56 | str = "Unavailable";
|
---|
| 57 | col = "#006080";
|
---|
| 58 | }
|
---|
| 59 | else {
|
---|
| 60 | str = "Shutdown";
|
---|
| 61 | col = "#993300";
|
---|
| 62 | }
|
---|
[13754] | 63 | arrdown.push({
|
---|
| 64 | id: json[i].Id,
|
---|
[13758] | 65 | title: str,
|
---|
| 66 | start: new Date(json[i].StartDate),
|
---|
| 67 | end: new Date(json[i].EndDate),
|
---|
| 68 | allDay: json[i].AllDayEvent,
|
---|
[13768] | 69 | color: col,
|
---|
[13775] | 70 | rec: {
|
---|
| 71 | recurrence: json[i].Recurring,
|
---|
| 72 | recid: json[i].RecurringId,
|
---|
| 73 | days: [false, false, false, false, false, false, false],
|
---|
| 74 | start: new Date(json[i].StartDate),
|
---|
| 75 | end: new Date(json[i].EndDate)
|
---|
| 76 |
|
---|
| 77 | },
|
---|
[13768] | 78 | changed: false
|
---|
[13754] | 79 | });
|
---|
| 80 | }
|
---|
| 81 | var dat = { 'id': id, 'down': [arrdown] };
|
---|
| 82 | $scope.treeview.currentNode.calendar = dat;
|
---|
[13758] | 83 |
|
---|
[13754] | 84 | $scope.currentcal = $scope.treeview.currentNode.calendar;
|
---|
[13775] | 85 | $("#resourcecalendar").fullCalendar('refresh');
|
---|
[13754] | 86 | $scope.$apply();
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | $scope.$watch("treeview.currentNode", function (newValue, oldValue) {
|
---|
| 90 | $scope.currentcal = [];
|
---|
[13758] | 91 | $(".selected.ng-binding").addClass('loaded');
|
---|
[13754] | 92 | $scope.selectedEventId = -1;
|
---|
[13782] | 93 | if ($scope.treeview.currentNode != null && $scope.treeview.currentNode.Id != undefined) {
|
---|
[13754] | 94 | if ($scope.treeview.currentNode.calendar.length === 0) {
|
---|
| 95 | hubber.server.requestDownTime(vm.treeview.currentNode.Id);
|
---|
[13758] | 96 |
|
---|
[13754] | 97 | }
|
---|
| 98 | else {
|
---|
| 99 | $timeout(function () {
|
---|
| 100 | $scope.currentcal = $scope.treeview.currentNode.calendar;
|
---|
[13758] | 101 |
|
---|
[13754] | 102 | }, 0);
|
---|
[13758] | 103 |
|
---|
[13754] | 104 | }
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | });
|
---|
| 108 | }
|
---|
[13782] | 109 | $scope.clearTreeSelect = function () {
|
---|
| 110 | if (vm.treeview.currentNode != undefined) {
|
---|
| 111 | vm.treeview.currentNode.selected = undefined;
|
---|
| 112 | vm.treeview.currentNode = undefined;
|
---|
| 113 | vm.selectedEventId = -1;
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
[13754] | 116 | $scope.buildTree = function () {
|
---|
| 117 | vm.tree = [];
|
---|
| 118 | vm.temptree = [];
|
---|
| 119 | vm.top = false;
|
---|
[13782] | 120 | var ungrouped = {
|
---|
| 121 | children: [],
|
---|
| 122 | Name: 'Ungrouped'
|
---|
| 123 | }
|
---|
[13754] | 124 | for (; vm.data.length > 0;) {
|
---|
| 125 |
|
---|
[13782] | 126 | if (vm.data[0].ParentResourceId == null && vm.data[0].IsDisposable !== undefined) {
|
---|
[13754] | 127 | var curr = $scope.seekChildren(vm.data.splice(0, 1)[0]);
|
---|
[13782] | 128 | vm.clients.push(curr);
|
---|
| 129 | ungrouped.children.push(curr);
|
---|
| 130 | }
|
---|
| 131 | else if (vm.data[0].ParentResourceId == null) {
|
---|
| 132 | var curr = $scope.seekChildren(vm.data.splice(0, 1)[0]);
|
---|
| 133 | vm.groups.push(curr);
|
---|
[13754] | 134 | vm.tree.push(curr);
|
---|
| 135 | }
|
---|
| 136 | else {
|
---|
| 137 | var curr = $scope.seekChildren(vm.data.splice(0, 1)[0]);
|
---|
[13782] | 138 | if (curr.IsDisposable !== undefined)
|
---|
| 139 | vm.clients.push(curr);
|
---|
| 140 | else
|
---|
| 141 | vm.groups.push(curr);
|
---|
[13754] | 142 | vm.temptree.push(curr);
|
---|
| 143 | }
|
---|
| 144 | }
|
---|
[13782] | 145 | vm.tree.push(ungrouped);
|
---|
[13758] | 146 |
|
---|
[13754] | 147 | };
|
---|
| 148 |
|
---|
| 149 | $scope.seekChildren = function (current) {
|
---|
| 150 | current.calendar = [];
|
---|
| 151 | current.children = [];
|
---|
[13758] | 152 | current.todelete = [];
|
---|
[13768] | 153 | current.changes = false;
|
---|
[13754] | 154 | current.collapsed = true;
|
---|
| 155 | for (var t = 0; t < vm.temptree.length;) {
|
---|
| 156 | if (current.Id == vm.temptree[t].ParentResourceId) {
|
---|
| 157 | current.children.push(vm.temptree.splice(t, 1)[0]);
|
---|
| 158 | }
|
---|
| 159 | else {
|
---|
| 160 | t++;
|
---|
| 161 | }
|
---|
| 162 | }
|
---|
| 163 | var childc = current.children.length;//Remembers count of children received from temp tree;
|
---|
| 164 | for (var t = 0; t < vm.data.length;) {
|
---|
| 165 | if (current.Id == vm.data[t].ParentResourceId) {
|
---|
[13782] | 166 | if (vm.data[t].IsDisposable !== undefined)
|
---|
| 167 | vm.clients.push(vm.data[t]);
|
---|
| 168 | else
|
---|
| 169 | vm.groups.push(vm.data[t]);
|
---|
[13754] | 170 | current.children.push(vm.data.splice(t, 1)[0]);
|
---|
| 171 | }
|
---|
| 172 | else {
|
---|
| 173 | t++;
|
---|
| 174 | }
|
---|
| 175 | }
|
---|
| 176 | for (var t = childc; t < current.children.length; t++) {
|
---|
| 177 | current.children[t] = $scope.seekChildren(current.children[t]);
|
---|
| 178 | }
|
---|
| 179 | return current;
|
---|
| 180 | }
|
---|
[13782] | 181 |
|
---|
| 182 | $scope.toggleDisposable = function () {
|
---|
| 183 | $scope.calendarDispose = true;
|
---|
| 184 | hubber.server.toggleDisposable(vm.treeview.currentNode.Id);
|
---|
| 185 | }
|
---|
| 186 |
|
---|
[13768] | 187 | function collectInfoToSave(node, refresh, last) {
|
---|
| 188 | var arr = node.calendar.down[0];
|
---|
| 189 | var toadd = [];
|
---|
| 190 | var todel = node.todelete;
|
---|
| 191 | var toupd = [];
|
---|
| 192 | for (var i = 0; i < arr.length; i++) {
|
---|
| 193 | if (arr[i].id === '00000000-0000-0000-0000-000000000000') {
|
---|
| 194 | var t = arr[i].allDay.toString();
|
---|
| 195 | toadd.push([
|
---|
[13775] | 196 | arr[i].title,//status
|
---|
| 197 | "" + Date.parse(arr[i].start),//start
|
---|
| 198 | "" + Date.parse(arr[i].end),//end
|
---|
| 199 | t,// allday
|
---|
| 200 | node.Id, //resource id
|
---|
| 201 | arr[i].rec.recurrence.toString(),//true on recur
|
---|
| 202 | arr[i].rec.recid,//recur id
|
---|
| 203 | "" + Date.parse(arr[i].rec.start),
|
---|
| 204 | "" + Date.parse(arr[i].rec.end),
|
---|
| 205 | arr[i].rec.days.join(",")
|
---|
| 206 |
|
---|
[13782] | 207 |
|
---|
[13768] | 208 | ]);
|
---|
| 209 | }
|
---|
| 210 | else if (arr[i].changed === true) {
|
---|
| 211 | var t = arr[i].allDay.toString();
|
---|
| 212 | toupd.push([
|
---|
[13775] | 213 | arr[i].id,//id to update
|
---|
| 214 | arr[i].title,//status
|
---|
| 215 | "" + Date.parse(arr[i].start),//start
|
---|
| 216 | "" + Date.parse(arr[i].end),//end
|
---|
| 217 | t,//allday
|
---|
| 218 | arr[i].rec.recurrence.toString(),//true on recur
|
---|
| 219 | arr[i].rec.recid,//recur id
|
---|
| 220 | "" + Date.parse(arr[i].rec.start),
|
---|
| 221 | "" + Date.parse(arr[i].rec.end),
|
---|
| 222 | arr[i].rec.days.join(",")
|
---|
[13782] | 223 |
|
---|
[13768] | 224 | ]);
|
---|
| 225 | }
|
---|
[13758] | 226 | }
|
---|
[13775] | 227 | vm.sendtoserv = [todel, toadd, toupd];
|
---|
[13768] | 228 | hubber.server.saveCalendar(node.Id, todel, toadd, toupd, refresh, last);
|
---|
[13758] | 229 | }
|
---|
[13768] | 230 | $scope.saveCurrentCalendar = function () {
|
---|
[13782] | 231 | vm.calendarSaver = true;
|
---|
[13768] | 232 | collectInfoToSave(vm.treeview.currentNode, true, false);
|
---|
| 233 | //true for refresh, false for showing it's only one calendar saved.
|
---|
| 234 | }
|
---|
| 235 | $scope.saveAllCalendars = function () {
|
---|
[13782] | 236 |
|
---|
[13768] | 237 | $scope.allSave = [];
|
---|
| 238 | for (var i = 0; i < $scope.tree.length; i++)
|
---|
| 239 | createSaveRequests($scope.tree[i]);
|
---|
| 240 | ngDialog.openConfirm({
|
---|
| 241 | template:
|
---|
| 242 | '<p>Are you sure you want to save all changes made to ' + $scope.allSave.length + ' calendars?</p>' +
|
---|
| 243 | '<div>' +
|
---|
| 244 | '<button type="button" class="btn btn-primary" ng-click="confirm(1)">Yes' +
|
---|
| 245 | '<button type="button" class="btn btn-default" ng-click="closeThisDialog(0)">No </button> ' +
|
---|
| 246 | '</button></div>',
|
---|
| 247 | plain: true
|
---|
| 248 | }).then(function (success) {
|
---|
[13782] | 249 | vm.calendarSaver = true;
|
---|
[13768] | 250 | for (var i = 0; i < $scope.allSave.length; i++) {
|
---|
| 251 | if (i >= $scope.allSave.length - 1)
|
---|
| 252 | collectInfoToSave($scope.allSave[i], false, true);
|
---|
| 253 | else
|
---|
| 254 | collectInfoToSave($scope.allSave[i], false, false);
|
---|
| 255 | }
|
---|
| 256 | });
|
---|
[13775] | 257 |
|
---|
| 258 |
|
---|
[13768] | 259 | }
|
---|
| 260 | function createSaveRequests(node) {
|
---|
| 261 | if (node.changes === true)
|
---|
| 262 | $scope.allSave.push(node);
|
---|
| 263 | for (var i = 0; i < node.children.length; i++) {
|
---|
| 264 | createSaveRequests(node.children[i]);
|
---|
| 265 | }
|
---|
| 266 | }
|
---|
| 267 | $scope.clearCurrentCalendar = function () {
|
---|
[13775] | 268 |
|
---|
[13768] | 269 | $scope.selectedEventId = -1;
|
---|
| 270 | $scope.treeview.currentNode.calendar = null;
|
---|
| 271 | $scope.treeview.currentNode.todelete = [];
|
---|
| 272 | $scope.treeview.currentNode.changes = false;
|
---|
| 273 | $scope.currentcal = [];
|
---|
| 274 | hubber.server.requestDownTime(vm.treeview.currentNode.Id);
|
---|
| 275 | $(".selected.ng-binding").removeClass('changed');
|
---|
| 276 |
|
---|
| 277 |
|
---|
| 278 | }
|
---|
| 279 | $scope.clearAllCalendars = function () {
|
---|
| 280 | ngDialog.openConfirm({
|
---|
| 281 | template:
|
---|
| 282 | '<p>Are you sure you want to delete all calendar changes?</p>' +
|
---|
| 283 | '<div>' +
|
---|
| 284 | '<button type="button" class="btn btn-default" ng-click="closeThisDialog(0)">No </button> ' +
|
---|
| 285 | '<button type="button" class="btn btn-primary" ng-click="confirm(1)">Yes' +
|
---|
| 286 | '</button></div>',
|
---|
| 287 | plain: true
|
---|
| 288 | }).then(function (success) {
|
---|
| 289 | clearAllCalendarsFunc();
|
---|
| 290 | });
|
---|
| 291 |
|
---|
| 292 | }
|
---|
| 293 | function clearAllCalendarsFunc() {
|
---|
| 294 | $(".ng-binding.changed").removeClass('changed');
|
---|
| 295 | $(".ng-binding.loaded").removeClass('loaded');
|
---|
| 296 | $scope.selectedEventId = -1;
|
---|
| 297 | $scope.treeview.currentNode.calendar = null;
|
---|
| 298 | $scope.currentcal = [];
|
---|
| 299 | for (var i = 0; i < $scope.tree.length; i++)
|
---|
[13782] | 300 | clearCalendarsRecurse($scope.tree[i]);
|
---|
[13768] | 301 | hubber.server.requestDownTime(vm.treeview.currentNode.Id);
|
---|
| 302 | $(".selected.ng-binding").addClass('loaded');
|
---|
| 303 | }
|
---|
[13782] | 304 | function clearCalendarsRecurse(node) {
|
---|
[13768] | 305 |
|
---|
| 306 | node.calendar = [];
|
---|
| 307 | node.todelete = [];
|
---|
| 308 | node.changes = false;
|
---|
| 309 | for (var i = 0; i < node.children.length; i++) {
|
---|
[13782] | 310 | clearCalendarsRecurse(node.children[i]);
|
---|
[13768] | 311 | }
|
---|
| 312 | }
|
---|
[13782] | 313 | $scope.deleteAllEvents = function () {
|
---|
| 314 | vm.calendarDeleter = true;
|
---|
| 315 | vm.selectedEventId = -1;
|
---|
| 316 | var node = vm.treeview.currentNode.calendar.down[0];
|
---|
| 317 | for (var i = 0; i < node.length;) {
|
---|
| 318 | if (node[i].id != '00000000-0000-0000-0000-000000000000')
|
---|
| 319 | vm.treeview.currentNode.todelete.push(node[i].id);
|
---|
| 320 | $scope.setChanged(vm.selectedEventId);
|
---|
| 321 | node.splice(i, 1);
|
---|
| 322 | }
|
---|
| 323 | vm.calendarDeleter = false;
|
---|
| 324 | ngDialog.open({
|
---|
| 325 | template:
|
---|
| 326 | '<p>All events have been deleted. Save the changes to confirm deletion, clearing will restore all the events from the server</p>',
|
---|
| 327 | plain: true
|
---|
| 328 | });
|
---|
| 329 | }
|
---|
[13768] | 330 | $scope.deleteAllPreviousEvents = function () {
|
---|
[13782] | 331 | vm.calendarDeleter = true;
|
---|
[13768] | 332 | vm.selectedEventId = -1;
|
---|
| 333 | var node = vm.treeview.currentNode.calendar.down[0];
|
---|
| 334 | for (var i = 0; i < node.length;) {
|
---|
| 335 | if (node[i].end < Date.now()) {
|
---|
| 336 | if (node[i].id != '00000000-0000-0000-0000-000000000000')
|
---|
[13775] | 337 | vm.treeview.currentNode.todelete.push(node[i].id);
|
---|
| 338 | $scope.setChanged(vm.selectedEventId);
|
---|
[13768] | 339 | node.splice(i, 1);
|
---|
| 340 | }
|
---|
| 341 | else
|
---|
| 342 | i++;
|
---|
| 343 | }
|
---|
[13782] | 344 | vm.calendarDeleter = false;
|
---|
[13768] | 345 | ngDialog.open({
|
---|
| 346 | template:
|
---|
| 347 | '<p>All previous events have been deleted. Save the changes to confirm deletion</p>',
|
---|
| 348 | plain: true
|
---|
| 349 | });
|
---|
| 350 | }
|
---|
| 351 |
|
---|
| 352 |
|
---|
[13775] | 353 | $scope.setChanged = function (id) {
|
---|
| 354 | if (id != -1) {
|
---|
| 355 | if (vm.treeview.currentNode.calendar.down[0][id].title === "Unavailable")
|
---|
| 356 | vm.treeview.currentNode.calendar.down[0][id].color = '#0099cc';
|
---|
[13768] | 357 | else
|
---|
[13775] | 358 | vm.treeview.currentNode.calendar.down[0][id].color = '#ff5500';
|
---|
[13768] | 359 |
|
---|
[13775] | 360 | vm.treeview.currentNode.calendar.down[0][id].changed = true;
|
---|
[13768] | 361 | }
|
---|
[13758] | 362 | vm.treeview.currentNode.changes = true;
|
---|
| 363 | $(".selected.ng-binding").addClass('changed');
|
---|
| 364 | }
|
---|
| 365 | //*Add event by click
|
---|
| 366 | $scope.calendarClick = function (date, jsEvent, view) {
|
---|
[13768] | 367 |
|
---|
[13758] | 368 | var newid = 0;
|
---|
| 369 | if (vm.treeview.currentNode.calendar.down[0].length != 0)
|
---|
| 370 | newid = vm.treeview.currentNode.calendar.down[0][(vm.treeview.currentNode.calendar.down[0].length - 1)]._id + 1;
|
---|
[13768] | 371 | var dat = date.toDate();
|
---|
| 372 | var end = new Date(dat);
|
---|
| 373 | end.setHours(dat.getHours() + 2);
|
---|
[13758] | 374 | vm.treeview.currentNode.calendar.down[0].push({
|
---|
| 375 | id: '00000000-0000-0000-0000-000000000000',
|
---|
| 376 | title: 'Unavailable',
|
---|
[13768] | 377 | start: dat,
|
---|
| 378 | end: end,
|
---|
[13758] | 379 | allDay: date._ambigTime,
|
---|
[13775] | 380 | rec: {
|
---|
| 381 | recurrence: false,
|
---|
| 382 | recid: '0',
|
---|
| 383 | days: [false, false, false, false, false, false, false],
|
---|
| 384 | start: dat,
|
---|
| 385 | end: end
|
---|
| 386 |
|
---|
| 387 | },
|
---|
[13758] | 388 | _id: (newid)
|
---|
| 389 | });
|
---|
| 390 | vm.selectedEventId = vm.treeview.currentNode.calendar.down[0].length - 1;
|
---|
[13775] | 391 | vm.setChanged(vm.selectedEventId);
|
---|
[13782] | 392 | $scope.currentcal = [];
|
---|
| 393 | $scope.currentcal = vm.treeview.currentNode.calendar;
|
---|
[13758] | 394 |
|
---|
[13782] | 395 |
|
---|
[13758] | 396 | }
|
---|
[13768] | 397 | function checkId(id) {
|
---|
| 398 | for (var i = 0; i < vm.treeview.currentNode.calendar.down[0].length ; i++) {
|
---|
| 399 | if (vm.treeview.currentNode.calendar.down[0][i]._id === id)
|
---|
| 400 | return i;
|
---|
| 401 | }
|
---|
| 402 | return -1;
|
---|
| 403 | }
|
---|
[13754] | 404 | /* alert on eventClick */
|
---|
[13768] | 405 | $scope.eventClick = function (date, jsEvent, view) {
|
---|
[13758] | 406 | vm.selectedEventId = checkId(date._id);
|
---|
[13754] | 407 | };
|
---|
[13782] | 408 | $scope.eventClickBtn = function (id) {
|
---|
| 409 | vm.selectedEventId = checkId(id);
|
---|
| 410 | vm.goToDate();
|
---|
| 411 | };
|
---|
[13754] | 412 | /* alert on Drop */
|
---|
[13768] | 413 | $scope.dragandDrop = function (event, delta, revertFunc, jsEvent, ui, view) {
|
---|
[13758] | 414 | vm.selectedEventId = checkId(event._id);
|
---|
[13775] | 415 | vm.setChanged(vm.selectedEventId);
|
---|
[13768] | 416 | if (event.end == null) {
|
---|
| 417 | event.end = moment(event.start).add(2, 'hours');
|
---|
| 418 | }
|
---|
[13758] | 419 | if (vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].allDay && event.start._ambigTime == false) {
|
---|
| 420 | event.allDay = false;
|
---|
| 421 | vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].allDay = false;
|
---|
| 422 | }
|
---|
| 423 | else if (!vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].allDay && event.start._ambigTime == true) {
|
---|
| 424 | event.allDay = true;
|
---|
| 425 | vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].allDay = true;
|
---|
[13768] | 426 | //vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].end = null;
|
---|
[13758] | 427 | }
|
---|
| 428 | vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].start = new Date(event.start);
|
---|
[13768] | 429 | vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].end = new Date(event.end);
|
---|
[13754] | 430 | };
|
---|
| 431 | /* alert on Resize */
|
---|
[13768] | 432 | $scope.resizeEvent = function (event, delta, revertFunc, jsEvent, ui, view) {
|
---|
[13758] | 433 | vm.selectedEventId = checkId(event._id);
|
---|
[13775] | 434 | vm.setChanged(vm.selectedEventId);
|
---|
[13758] | 435 | vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].start = new Date(event.start);
|
---|
| 436 | vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].end = new Date(event.end);
|
---|
[13754] | 437 | };
|
---|
| 438 |
|
---|
| 439 | /* remove event */
|
---|
| 440 | $scope.remove = function (index) {
|
---|
[13758] | 441 | vm.selectedEventId = -1;
|
---|
[13775] | 442 | vm.setChanged(vm.selectedEventId);
|
---|
[13758] | 443 | if (vm.treeview.currentNode.calendar.down[0][index].id != "00000000-0000-0000-0000-000000000000") {
|
---|
[13768] | 444 | vm.treeview.currentNode.todelete.push(vm.treeview.currentNode.calendar.down[0][index].id);
|
---|
[13758] | 445 | }
|
---|
| 446 | vm.treeview.currentNode.calendar.down[0].splice(index, 1);
|
---|
| 447 |
|
---|
| 448 |
|
---|
[13754] | 449 | };
|
---|
[13782] | 450 | $scope.removeList = function (id) {
|
---|
| 451 | var index = checkId(id);
|
---|
| 452 | vm.selectedEventId = -1;
|
---|
| 453 | vm.setChanged(vm.selectedEventId);
|
---|
| 454 | if (vm.treeview.currentNode.calendar.down[0][index].id != "00000000-0000-0000-0000-000000000000") {
|
---|
| 455 | vm.treeview.currentNode.todelete.push(vm.treeview.currentNode.calendar.down[0][index].id);
|
---|
| 456 | }
|
---|
| 457 | vm.treeview.currentNode.calendar.down[0].splice(index, 1);
|
---|
[13775] | 458 |
|
---|
[13782] | 459 |
|
---|
| 460 | };
|
---|
| 461 |
|
---|
[13775] | 462 | $scope.checkDateStartEnd = function () {
|
---|
| 463 | if ($scope.currentcal.down[0][vm.selectedEventId].rec.start > $scope.currentcal.down[0][vm.selectedEventId].rec.end ||
|
---|
| 464 | $scope.currentcal.down[0][vm.selectedEventId].rec.end === undefined) {
|
---|
[13782] | 465 |
|
---|
[13775] | 466 | $scope.currentcal.down[0][vm.selectedEventId].rec.end = new Date($scope.currentcal.down[0][vm.selectedEventId].rec.start);
|
---|
[13782] | 467 |
|
---|
[13775] | 468 | }
|
---|
| 469 | if ($scope.currentcal.down[0][vm.selectedEventId].rec.start < Date.now())
|
---|
| 470 | $scope.currentcal.down[0][vm.selectedEventId].rec.start = new Date();
|
---|
[13782] | 471 | }
|
---|
[13775] | 472 | //pushes all changes to other recurs
|
---|
| 473 | $scope.pushRecurChanges = function (recid) {
|
---|
| 474 | ngDialog.openConfirm({
|
---|
| 475 | template:
|
---|
| 476 | '<p>This will change all existing recurrences and create new recurrences where needed. Are you sure?</p>' +
|
---|
| 477 | '<div>' +
|
---|
| 478 | '<button type="button" class="btn btn-default" ng-click="closeThisDialog(0)">No </button> ' +
|
---|
| 479 | '<button type="button" class="btn btn-primary" ng-click="confirm(1)">Yes' +
|
---|
| 480 | '</button></div>',
|
---|
| 481 | plain: true
|
---|
| 482 | }).then(function (success) {
|
---|
| 483 | var arr = vm.treeview.currentNode.calendar.down[0];
|
---|
| 484 | var ob = $.extend(true, {}, arr[vm.selectedEventId]);
|
---|
| 485 | for (var i = 0; i < arr.length;) {
|
---|
| 486 | if (arr[i].rec.recid === recid) {
|
---|
| 487 | if (new Date(arr[i].start) < new Date(ob.rec.start) ||
|
---|
| 488 | new Date(arr[i].end) > new Date(ob.rec.end) ||
|
---|
| 489 | !ob.rec.days[new Date(arr[i].start).getDay()]) {
|
---|
| 490 | vm.remove(i);
|
---|
| 491 | vm.selectedEventId = -1;
|
---|
| 492 |
|
---|
| 493 | }
|
---|
| 494 | else {
|
---|
[13782] | 495 |
|
---|
[13775] | 496 | arr[i].start.setHours(ob.start.getHours(), ob.start.getMinutes());
|
---|
| 497 | arr[i].end.setHours(ob.end.getHours(), ob.end.getMinutes());
|
---|
| 498 | arr[i].title = ob.title;
|
---|
| 499 | arr[i].rec = ob.rec;
|
---|
| 500 | arr[i].allDay = ob.allDay;
|
---|
| 501 | vm.setChanged(i);
|
---|
| 502 | i++;
|
---|
| 503 | }
|
---|
| 504 | }
|
---|
| 505 | else
|
---|
| 506 | i++;
|
---|
| 507 | }
|
---|
| 508 | var start = new Date(ob.rec.start);
|
---|
| 509 | start.setHours(2, 0, 0, 0);
|
---|
| 510 | var end = new Date(ob.rec.end);
|
---|
| 511 | end = new Date(end.setHours(24, 0, 0, 0) + 1000 * 3600 * 2);
|
---|
| 512 |
|
---|
| 513 | loop1:
|
---|
| 514 | for (var d = (start.getTime()) ; d < (end.getTime()) ;) {
|
---|
| 515 | var tog = ob.rec.days[new Date(d).getDay()];
|
---|
| 516 | if (tog) {
|
---|
| 517 | loop2:
|
---|
| 518 | for (var i = 0; i < arr.length; i++) {
|
---|
[13782] | 519 |
|
---|
[13775] | 520 | if (arr[i].rec.recid === recid) {
|
---|
[13782] | 521 | var dend = (d + 1000 * 3600 * 24);
|
---|
[13775] | 522 | if (arr[i].start.getTime() >= d &&
|
---|
| 523 | arr[i].end.getTime() <= dend) {
|
---|
| 524 | d += (1000 * 3600 * 24);
|
---|
| 525 | continue loop1;
|
---|
| 526 | }
|
---|
| 527 | }
|
---|
| 528 | }
|
---|
[13782] | 529 |
|
---|
[13775] | 530 | var ts = new Date(d);
|
---|
| 531 | ts.setHours(new Date(ob.start).getHours(), new Date(ob.start).getMinutes());
|
---|
| 532 | var te = new Date(d);
|
---|
| 533 | te.setHours(new Date(ob.end).getHours(), new Date(ob.end).getMinutes());
|
---|
| 534 | arr.push({
|
---|
| 535 | id: '00000000-0000-0000-0000-000000000000',
|
---|
| 536 | title: ob.title,
|
---|
| 537 | start: ts,
|
---|
| 538 | end: te,
|
---|
| 539 | allDay: ob.allDay,
|
---|
| 540 | rec: ob.rec
|
---|
| 541 | });
|
---|
| 542 | vm.setChanged(arr.length - 1);
|
---|
| 543 |
|
---|
| 544 | }
|
---|
[13782] | 545 |
|
---|
[13775] | 546 | d += (1000 * 3600 * 24);// 1 day
|
---|
[13782] | 547 |
|
---|
[13775] | 548 | }
|
---|
| 549 | });
|
---|
| 550 | }
|
---|
| 551 | $scope.deleteAllRecurrences = function (recid) {
|
---|
| 552 | ngDialog.openConfirm({
|
---|
| 553 | template:
|
---|
| 554 | '<p>This will delete every found recurrence. Are you sure?</p>' +
|
---|
| 555 | '<div>' +
|
---|
| 556 | '<button type="button" class="btn btn-default" ng-click="closeThisDialog(0)">No </button> ' +
|
---|
| 557 | '<button type="button" class="btn btn-primary" ng-click="confirm(1)">Yes' +
|
---|
| 558 | '</button></div>',
|
---|
| 559 | plain: true
|
---|
| 560 | }).then(function (success) {
|
---|
| 561 | var arr = vm.treeview.currentNode.calendar.down[0];
|
---|
| 562 | for (var i = 0; i < arr.length;) {
|
---|
| 563 | if (arr[i].rec.recid === recid)
|
---|
| 564 | vm.remove(i);
|
---|
| 565 | else
|
---|
| 566 | i++;
|
---|
| 567 | }
|
---|
| 568 | });
|
---|
| 569 | }
|
---|
| 570 |
|
---|
[13782] | 571 | $scope.goToDate = function () {
|
---|
| 572 | $("#resourcecalendar").fullCalendar('gotoDate', vm.currentcal.down[0][vm.selectedEventId].start);
|
---|
| 573 | }
|
---|
[13754] | 574 | /* Render Tooltip */
|
---|
| 575 | $scope.eventRender = function (event, element, view) {
|
---|
| 576 | element.attr({
|
---|
| 577 | 'tooltip': event.title,
|
---|
| 578 | 'tooltip-append-to-body': true
|
---|
| 579 | });
|
---|
| 580 | //$compile(element)($scope);
|
---|
| 581 | };
|
---|
| 582 | /* config object */
|
---|
| 583 | $scope.uiConfig = {
|
---|
| 584 | calendar: {
|
---|
[13758] | 585 | height: 500,
|
---|
[13754] | 586 | editable: true,
|
---|
[13758] | 587 | defaultView: 'agendaWeek',
|
---|
| 588 | firstDay: 1,
|
---|
[13754] | 589 | header: {
|
---|
| 590 | left: 'title',
|
---|
[13782] | 591 | center: 'agendaWeek, agendaDay',
|
---|
[13754] | 592 | right: 'today prev,next'
|
---|
| 593 | },
|
---|
| 594 | timezone: 'UTC',
|
---|
| 595 | timeFormat: 'HH:mm',
|
---|
[13768] | 596 | eventClick: $scope.eventClick,
|
---|
| 597 | eventDrop: $scope.dragandDrop,
|
---|
| 598 | eventResize: $scope.resizeEvent,
|
---|
[13754] | 599 | eventRender: $scope.eventRender,
|
---|
| 600 | dayClick: $scope.calendarClick
|
---|
| 601 |
|
---|
[13758] | 602 |
|
---|
[13782] | 603 |
|
---|
[13754] | 604 | }
|
---|
| 605 | };
|
---|
| 606 |
|
---|
[13775] | 607 |
|
---|
| 608 |
|
---|
[13782] | 609 | }).filter('disp', function () {
|
---|
| 610 | return function (input) {
|
---|
| 611 | return input ? 'Disposable' : 'Not disposable';
|
---|
| 612 | }
|
---|
| 613 | }).directive('animateOnChange', function ($timeout) {
|
---|
| 614 | return function (scope, element, attr) {
|
---|
| 615 | scope.$watch(attr.animateOnChange, function (nv, ov) {
|
---|
| 616 |
|
---|
| 617 | if (nv != ov) {
|
---|
| 618 | if (scope.currentcal.down[0][scope.selectedEventId].title === "Unavailable") {
|
---|
| 619 | element.addClass('changed');
|
---|
| 620 | $timeout(function () {
|
---|
| 621 | element.removeClass('changed');
|
---|
| 622 | }, 250); // Could be enhanced to take duration as a parameter
|
---|
| 623 | }
|
---|
| 624 | else {
|
---|
| 625 | element.addClass('changedshut');
|
---|
| 626 | $timeout(function () {
|
---|
| 627 | element.removeClass('changedshut');
|
---|
| 628 | }, 250); // Could be enhanced to take duration as a parameter
|
---|
| 629 | }
|
---|
| 630 | }
|
---|
| 631 | });
|
---|
| 632 | };
|
---|
[13754] | 633 | });
|
---|
| 634 |
|
---|
| 635 |
|
---|