Changeset 13775
- Timestamp:
- 04/19/16 17:11:50 (9 years ago)
- Location:
- branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Hubs/CalendarHub.cs
r13768 r13775 77 77 obj.AllDayEvent = false; 78 78 obj.ResourceId = Guid.Parse(s[4]); 79 adminClient.Store(obj, CancellationToken.None); 79 if (s[5] == "true") 80 { 81 obj.Recurring = true; 82 if (s[6] == "0") 83 { 84 var dayarr = s[9].Split(','); 85 var start = (new DateTime(1970, 1, 1)).AddMilliseconds(double.Parse(s[7])); 86 var end = (new DateTime(1970, 1, 1)).AddMilliseconds(double.Parse(s[8])); 87 loopAddDowns(start, end, dayarr, obj); 88 } 89 else 90 { 91 obj.RecurringId = Guid.Parse(s[6]); 92 adminClient.Store(obj, CancellationToken.None); 93 } 94 } 95 else { 96 obj.Recurring = false; 97 adminClient.Store(obj, CancellationToken.None); 98 } 99 100 80 101 } 81 102 foreach(var s in upd) … … 92 113 else 93 114 obj.AllDayEvent = false; 94 //adminClient.Store(obj, CancellationToken.None); Throws error 115 if (s[5] == "true" && !obj.Recurring) 116 { 117 obj.Recurring = true; 118 if (s[6] == "00000000-0000-0000-0000-000000000000") 119 { 120 var dayarr = s[9].Split(','); 121 var start = (new DateTime(1970, 1, 1)).AddMilliseconds(double.Parse(s[7])); 122 var end = (new DateTime(1970, 1, 1)).AddMilliseconds(double.Parse(s[8])); 123 //loopAddDowns(start, end, dayarr, obj); 124 } 125 else 126 { 127 obj.RecurringId = Guid.Parse(s[6]); 128 //adminClient.Store(obj, CancellationToken.None); //Throws error 129 } 130 } 131 else 132 { 133 //adminClient.Store(obj, CancellationToken.None); //Throws error 134 } 135 136 95 137 } 96 138 if( last) … … 103 145 } 104 146 } 147 private void loopAddDowns(DateTime start, DateTime end, string[] dayarr, Downtime obj) 148 { 149 var rid = Guid.NewGuid(); 150 for (; start < end;) 151 { 152 if (dayarr[(int)(start.DayOfWeek)] == "true") 153 { 154 var temp = new Downtime(); 155 temp.StartDate = start.AddHours(obj.StartDate.Hour - start.Hour).AddMinutes(obj.StartDate.Minute - start.Minute); 156 temp.EndDate = start.AddHours(obj.EndDate.Hour - start.Hour).AddMinutes(obj.EndDate.Minute - start.Minute); 157 temp.Id = obj.Id; 158 temp.DowntimeType = obj.DowntimeType; 159 temp.AllDayEvent = obj.AllDayEvent; 160 temp.ResourceId = obj.ResourceId; 161 temp.Recurring = obj.Recurring; 162 temp.RecurringId = rid; 163 adminClient.Store(temp, CancellationToken.None); 164 } 165 start = start.AddDays(1); 166 } 167 } 105 168 } 106 169 } -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Scripts/Hubs/CalendarHubber.js
r13768 r13775 11 11 var y = date.getFullYear(); 12 12 var hubber = $.connection.calendarHub; 13 13 14 vm.alertMessage = "No alerts"; 14 15 vm.currentcal = []; … … 43 44 var arrdown = []; 44 45 var str = ""; 45 var col = "";46 46 for (var i = 0; i < json.length; i++) { 47 47 if (json[i].DowntimeType === 0) { … … 60 60 allDay: json[i].AllDayEvent, 61 61 color: col, 62 rec: { 63 recurrence: json[i].Recurring, 64 recid: json[i].RecurringId, 65 days: [false, false, false, false, false, false, false], 66 start: new Date(json[i].StartDate), 67 end: new Date(json[i].EndDate) 68 69 }, 62 70 changed: false 63 71 }); … … 67 75 68 76 $scope.currentcal = $scope.treeview.currentNode.calendar; 77 $("#resourcecalendar").fullCalendar('refresh'); 69 78 $scope.$apply(); 70 79 } … … 145 154 var t = arr[i].allDay.toString(); 146 155 toadd.push([ 147 arr[i].title, 148 "" + Date.parse(arr[i].start), 149 "" + Date.parse(arr[i].end), 150 t, 151 node.Id 156 arr[i].title,//status 157 "" + Date.parse(arr[i].start),//start 158 "" + Date.parse(arr[i].end),//end 159 t,// allday 160 node.Id, //resource id 161 arr[i].rec.recurrence.toString(),//true on recur 162 arr[i].rec.recid,//recur id 163 "" + Date.parse(arr[i].rec.start), 164 "" + Date.parse(arr[i].rec.end), 165 arr[i].rec.days.join(",") 166 167 152 168 ]); 153 169 } … … 155 171 var t = arr[i].allDay.toString(); 156 172 toupd.push([ 157 arr[i].id, 158 arr[i].title, 159 "" + Date.parse(arr[i].start), 160 "" + Date.parse(arr[i].end), 161 t 173 arr[i].id,//id to update 174 arr[i].title,//status 175 "" + Date.parse(arr[i].start),//start 176 "" + Date.parse(arr[i].end),//end 177 t,//allday 178 arr[i].rec.recurrence.toString(),//true on recur 179 arr[i].rec.recid,//recur id 180 "" + Date.parse(arr[i].rec.start), 181 "" + Date.parse(arr[i].rec.end), 182 arr[i].rec.days.join(",") 183 162 184 ]); 163 185 } 164 186 } 165 vm.sendtoserv = [to add, toupd, todel];187 vm.sendtoserv = [todel, toadd, toupd]; 166 188 hubber.server.saveCalendar(node.Id, todel, toadd, toupd, refresh, last); 167 189 } … … 190 212 } 191 213 }); 192 193 214 215 194 216 } 195 217 function createSaveRequests(node) { … … 201 223 } 202 224 $scope.clearCurrentCalendar = function () { 203 225 204 226 $scope.selectedEventId = -1; 205 227 $scope.treeview.currentNode.calendar = null; … … 253 275 if (node[i].end < Date.now()) { 254 276 if (node[i].id != '00000000-0000-0000-0000-000000000000') 255 vm.treeview.currentNode.todelete.push(node[i].id);256 $scope.setChanged( );277 vm.treeview.currentNode.todelete.push(node[i].id); 278 $scope.setChanged(vm.selectedEventId); 257 279 node.splice(i, 1); 258 280 } … … 268 290 269 291 270 $scope.setChanged = function ( ) {271 if ( vm.selectedEventId != -1) {272 if (vm.treeview.currentNode.calendar.down[0][ vm.selectedEventId].title === "Unavailable")273 vm.treeview.currentNode.calendar.down[0][ vm.selectedEventId].color = '#0099cc';292 $scope.setChanged = function (id) { 293 if (id != -1) { 294 if (vm.treeview.currentNode.calendar.down[0][id].title === "Unavailable") 295 vm.treeview.currentNode.calendar.down[0][id].color = '#0099cc'; 274 296 else 275 vm.treeview.currentNode.calendar.down[0][ vm.selectedEventId].color = '#ff5500';276 277 vm.treeview.currentNode.calendar.down[0][ vm.selectedEventId].changed = true;297 vm.treeview.currentNode.calendar.down[0][id].color = '#ff5500'; 298 299 vm.treeview.currentNode.calendar.down[0][id].changed = true; 278 300 } 279 301 vm.treeview.currentNode.changes = true; … … 289 311 var end = new Date(dat); 290 312 end.setHours(dat.getHours() + 2); 291 console.log(end);292 313 vm.treeview.currentNode.calendar.down[0].push({ 293 314 id: '00000000-0000-0000-0000-000000000000', … … 296 317 end: end, 297 318 allDay: date._ambigTime, 319 rec: { 320 recurrence: false, 321 recid: '0', 322 days: [false, false, false, false, false, false, false], 323 start: dat, 324 end: end 325 326 }, 298 327 _id: (newid) 299 328 }); 300 329 vm.selectedEventId = vm.treeview.currentNode.calendar.down[0].length - 1; 301 vm.setChanged( );330 vm.setChanged(vm.selectedEventId); 302 331 // $("#resourcecalendar").fullCalendar('refetchEvents'); 303 332 … … 317 346 $scope.dragandDrop = function (event, delta, revertFunc, jsEvent, ui, view) { 318 347 vm.selectedEventId = checkId(event._id); 319 vm.setChanged( );348 vm.setChanged(vm.selectedEventId); 320 349 if (event.end == null) { 321 350 event.end = moment(event.start).add(2, 'hours'); … … 336 365 $scope.resizeEvent = function (event, delta, revertFunc, jsEvent, ui, view) { 337 366 vm.selectedEventId = checkId(event._id); 338 vm.setChanged( );367 vm.setChanged(vm.selectedEventId); 339 368 vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].start = new Date(event.start); 340 369 vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].end = new Date(event.end); … … 344 373 $scope.remove = function (index) { 345 374 vm.selectedEventId = -1; 346 vm.setChanged( );375 vm.setChanged(vm.selectedEventId); 347 376 if (vm.treeview.currentNode.calendar.down[0][index].id != "00000000-0000-0000-0000-000000000000") { 348 377 vm.treeview.currentNode.todelete.push(vm.treeview.currentNode.calendar.down[0][index].id); … … 352 381 353 382 }; 383 384 $scope.checkDateStartEnd = function () { 385 if ($scope.currentcal.down[0][vm.selectedEventId].rec.start > $scope.currentcal.down[0][vm.selectedEventId].rec.end || 386 $scope.currentcal.down[0][vm.selectedEventId].rec.end === undefined) { 387 388 $scope.currentcal.down[0][vm.selectedEventId].rec.end = new Date($scope.currentcal.down[0][vm.selectedEventId].rec.start); 389 390 } 391 if ($scope.currentcal.down[0][vm.selectedEventId].rec.start < Date.now()) 392 $scope.currentcal.down[0][vm.selectedEventId].rec.start = new Date(); 393 } 394 //pushes all changes to other recurs 395 $scope.pushRecurChanges = function (recid) { 396 ngDialog.openConfirm({ 397 template: 398 '<p>This will change all existing recurrences and create new recurrences where needed. Are you sure?</p>' + 399 '<div>' + 400 '<button type="button" class="btn btn-default" ng-click="closeThisDialog(0)">No </button> ' + 401 '<button type="button" class="btn btn-primary" ng-click="confirm(1)">Yes' + 402 '</button></div>', 403 plain: true 404 }).then(function (success) { 405 var arr = vm.treeview.currentNode.calendar.down[0]; 406 var ob = $.extend(true, {}, arr[vm.selectedEventId]); 407 for (var i = 0; i < arr.length;) { 408 if (arr[i].rec.recid === recid) { 409 if (new Date(arr[i].start) < new Date(ob.rec.start) || 410 new Date(arr[i].end) > new Date(ob.rec.end) || 411 !ob.rec.days[new Date(arr[i].start).getDay()]) { 412 vm.remove(i); 413 vm.selectedEventId = -1; 414 415 } 416 else { 417 418 arr[i].start.setHours(ob.start.getHours(), ob.start.getMinutes()); 419 arr[i].end.setHours(ob.end.getHours(), ob.end.getMinutes()); 420 arr[i].title = ob.title; 421 arr[i].rec = ob.rec; 422 arr[i].allDay = ob.allDay; 423 vm.setChanged(i); 424 i++; 425 } 426 } 427 else 428 i++; 429 } 430 var start = new Date(ob.rec.start); 431 start.setHours(2, 0, 0, 0); 432 var end = new Date(ob.rec.end); 433 end = new Date(end.setHours(24, 0, 0, 0) + 1000 * 3600 * 2); 434 435 loop1: 436 for (var d = (start.getTime()) ; d < (end.getTime()) ;) { 437 var tog = ob.rec.days[new Date(d).getDay()]; 438 if (tog) { 439 loop2: 440 for (var i = 0; i < arr.length; i++) { 441 442 if (arr[i].rec.recid === recid) { 443 var dend = (d+1000 * 3600 * 24); 444 if (arr[i].start.getTime() >= d && 445 arr[i].end.getTime() <= dend) { 446 d += (1000 * 3600 * 24); 447 continue loop1; 448 } 449 } 450 } 451 452 var ts = new Date(d); 453 ts.setHours(new Date(ob.start).getHours(), new Date(ob.start).getMinutes()); 454 var te = new Date(d); 455 te.setHours(new Date(ob.end).getHours(), new Date(ob.end).getMinutes()); 456 arr.push({ 457 id: '00000000-0000-0000-0000-000000000000', 458 title: ob.title, 459 start: ts, 460 end: te, 461 allDay: ob.allDay, 462 rec: ob.rec 463 }); 464 vm.setChanged(arr.length - 1); 465 466 } 467 468 d += (1000 * 3600 * 24);// 1 day 469 470 } 471 }); 472 } 473 $scope.deleteAllRecurrences = function (recid) { 474 ngDialog.openConfirm({ 475 template: 476 '<p>This will delete every found recurrence. 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 for (var i = 0; i < arr.length;) { 485 if (arr[i].rec.recid === recid) 486 vm.remove(i); 487 else 488 i++; 489 } 490 }); 491 } 492 354 493 /* Render Tooltip */ 355 494 $scope.eventRender = function (event, element, view) { … … 383 522 } 384 523 }; 385 $rootScope.$on('$locationChangeStart', function (event, newUrl, oldUrl) { 386 console.log($(".changed").length); 387 if ($(".changed").length != 0) { 388 ngDialog.openConfirm({ 389 template: 390 '<p>You have unsaved changes. Are you sure you want to leave this page? All changes will be lost. </p>' + 391 '<div>' + 392 '<button type="button" class="btn btn-primary" ng-click="confirm(1)">Yes' + 393 '<button type="button" class="btn btn-default" ng-click="closeThisDialog(0)">No </button> ' + 394 '</button></div>', 395 plain: true 396 }).then(function (success) { 397 $rootScope.allowNavigation(); 398 }); 399 } 400 401 event.preventDefault(); // This prevents the navigation from happening 402 } 403 ); 524 525 404 526 405 527 }); -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Views/Resource/Index.cshtml
r13768 r13775 99 99 <td>Status</td> 100 100 <td> 101 <select class="content-select" ng-model="currentcal.down[0][selectedEventId].title" ng-change="setChanged( )">101 <select class="content-select" ng-model="currentcal.down[0][selectedEventId].title" ng-change="setChanged(selectedEventId)"> 102 102 <option value="Unavailable">Unavailable</option> 103 103 <option value="Shutdown">Shutdown command</option> … … 106 106 </tr> 107 107 <tr> 108 <td>Recurrence</td> 109 <td> 110 <input type="checkbox" class="checkbox" ng-model="currentcal.down[0][selectedEventId].rec.recurrence" ng-change="setChanged(selectedEventId)" /> 111 <p ng-if="currentcal.down[0][selectedEventId].changed && currentcal.down[0][selectedEventId].rec.recurrence" style="color:darkred;font-weight:bold"> 112 The recurrence itself will be made during saving, settings can be changed here. 113 </p> 114 </td> 115 </tr> 116 <tr ng-if="currentcal.down[0][selectedEventId].rec.recurrence"> 117 <td> 118 Start 119 </td> 120 <td> 121 <input type="date" 122 ng-model="currentcal.down[0][selectedEventId].rec.start" 123 ng-change="checkDateStartEnd()" /> 124 </td> 125 </tr> 126 <tr ng-if="currentcal.down[0][selectedEventId].rec.recurrence" > 127 <td> 128 End 129 </td> 130 <td> 131 <input type="date" 132 ng-model="currentcal.down[0][selectedEventId].rec.end" 133 ng-change="checkDateStartEnd()" 134 min="{{currentcal.down[0][selectedEventId].rec.start | date:'yyyy-MM-dd'}}"/> 135 </td> 136 </tr> 137 138 <tr ng-if="currentcal.down[0][selectedEventId].rec.recurrence"> 139 <td colspan="2"> 140 <label class="checkbox-inline"><input type="checkbox" ng-model="currentcal.down[0][selectedEventId].rec.days[1]">Monday</label> 141 <label class="checkbox-inline"><input type="checkbox" ng-model="currentcal.down[0][selectedEventId].rec.days[2]">Tuesday</label> 142 <label class="checkbox-inline"><input type="checkbox" ng-model="currentcal.down[0][selectedEventId].rec.days[3]">Wednesday</label> 143 <label class="checkbox-inline"><input type="checkbox" ng-model="currentcal.down[0][selectedEventId].rec.days[4]">Thursday</label> 144 <label class="checkbox-inline"><input type="checkbox" ng-model="currentcal.down[0][selectedEventId].rec.days[5]">Friday</label> 145 <label class="checkbox-inline"><input type="checkbox" ng-model="currentcal.down[0][selectedEventId].rec.days[6]">Saturday</label> 146 <label class="checkbox-inline"><input type="checkbox" ng-model="currentcal.down[0][selectedEventId].rec.days[0]">Sunday</label> 147 </td> 148 149 </tr> 150 <tr> 108 151 <td></td> 109 152 <td> 153 <button class="btn btn-info" 154 ng-click="pushRecurChanges(currentcal.down[0][selectedEventId].rec.recid)" 155 ng-if="currentcal.down[0][selectedEventId].rec.recid != '0' && 156 currentcal.down[0][selectedEventId].rec.recid != '00000000-0000-0000-0000-000000000000' && 157 currentcal.down[0][selectedEventId].changed"> 158 Push all changes to other recurrencies 159 </button> 110 160 <button class="btn btn-danger" 111 161 ng-click="remove(selectedEventId)"> 112 162 <i class="fa fa-trash-o"></i> 113 163 Delete 164 </button> 165 <button class="btn btn-danger" 166 ng-click="deleteAllRecurrences(currentcal.down[0][selectedEventId].rec.recid)" 167 ng-if="currentcal.down[0][selectedEventId].rec.recid != '0' 168 && currentcal.down[0][selectedEventId].rec.recid != '00000000-0000-0000-0000-000000000000'"> 169 Delete all recurrencies 114 170 </button> 115 171 </td> -
branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/wwwroot/js/hubs/calendarhubber.js
r13768 r13775 11 11 var y = date.getFullYear(); 12 12 var hubber = $.connection.calendarHub; 13 13 14 vm.alertMessage = "No alerts"; 14 15 vm.currentcal = []; … … 43 44 var arrdown = []; 44 45 var str = ""; 45 var col = "";46 46 for (var i = 0; i < json.length; i++) { 47 47 if (json[i].DowntimeType === 0) { … … 60 60 allDay: json[i].AllDayEvent, 61 61 color: col, 62 rec: { 63 recurrence: json[i].Recurring, 64 recid: json[i].RecurringId, 65 days: [false, false, false, false, false, false, false], 66 start: new Date(json[i].StartDate), 67 end: new Date(json[i].EndDate) 68 69 }, 62 70 changed: false 63 71 }); … … 67 75 68 76 $scope.currentcal = $scope.treeview.currentNode.calendar; 77 $("#resourcecalendar").fullCalendar('refresh'); 69 78 $scope.$apply(); 70 79 } … … 145 154 var t = arr[i].allDay.toString(); 146 155 toadd.push([ 147 arr[i].title, 148 "" + Date.parse(arr[i].start), 149 "" + Date.parse(arr[i].end), 150 t, 151 node.Id 156 arr[i].title,//status 157 "" + Date.parse(arr[i].start),//start 158 "" + Date.parse(arr[i].end),//end 159 t,// allday 160 node.Id, //resource id 161 arr[i].rec.recurrence.toString(),//true on recur 162 arr[i].rec.recid,//recur id 163 "" + Date.parse(arr[i].rec.start), 164 "" + Date.parse(arr[i].rec.end), 165 arr[i].rec.days.join(",") 166 167 152 168 ]); 153 169 } … … 155 171 var t = arr[i].allDay.toString(); 156 172 toupd.push([ 157 arr[i].id, 158 arr[i].title, 159 "" + Date.parse(arr[i].start), 160 "" + Date.parse(arr[i].end), 161 t 173 arr[i].id,//id to update 174 arr[i].title,//status 175 "" + Date.parse(arr[i].start),//start 176 "" + Date.parse(arr[i].end),//end 177 t,//allday 178 arr[i].rec.recurrence.toString(),//true on recur 179 arr[i].rec.recid,//recur id 180 "" + Date.parse(arr[i].rec.start), 181 "" + Date.parse(arr[i].rec.end), 182 arr[i].rec.days.join(",") 183 162 184 ]); 163 185 } 164 186 } 165 vm.sendtoserv = [to add, toupd, todel];187 vm.sendtoserv = [todel, toadd, toupd]; 166 188 hubber.server.saveCalendar(node.Id, todel, toadd, toupd, refresh, last); 167 189 } … … 190 212 } 191 213 }); 192 193 214 215 194 216 } 195 217 function createSaveRequests(node) { … … 201 223 } 202 224 $scope.clearCurrentCalendar = function () { 203 225 204 226 $scope.selectedEventId = -1; 205 227 $scope.treeview.currentNode.calendar = null; … … 253 275 if (node[i].end < Date.now()) { 254 276 if (node[i].id != '00000000-0000-0000-0000-000000000000') 255 vm.treeview.currentNode.todelete.push(node[i].id);256 $scope.setChanged( );277 vm.treeview.currentNode.todelete.push(node[i].id); 278 $scope.setChanged(vm.selectedEventId); 257 279 node.splice(i, 1); 258 280 } … … 268 290 269 291 270 $scope.setChanged = function ( ) {271 if ( vm.selectedEventId != -1) {272 if (vm.treeview.currentNode.calendar.down[0][ vm.selectedEventId].title === "Unavailable")273 vm.treeview.currentNode.calendar.down[0][ vm.selectedEventId].color = '#0099cc';292 $scope.setChanged = function (id) { 293 if (id != -1) { 294 if (vm.treeview.currentNode.calendar.down[0][id].title === "Unavailable") 295 vm.treeview.currentNode.calendar.down[0][id].color = '#0099cc'; 274 296 else 275 vm.treeview.currentNode.calendar.down[0][ vm.selectedEventId].color = '#ff5500';276 277 vm.treeview.currentNode.calendar.down[0][ vm.selectedEventId].changed = true;297 vm.treeview.currentNode.calendar.down[0][id].color = '#ff5500'; 298 299 vm.treeview.currentNode.calendar.down[0][id].changed = true; 278 300 } 279 301 vm.treeview.currentNode.changes = true; … … 289 311 var end = new Date(dat); 290 312 end.setHours(dat.getHours() + 2); 291 console.log(end);292 313 vm.treeview.currentNode.calendar.down[0].push({ 293 314 id: '00000000-0000-0000-0000-000000000000', … … 296 317 end: end, 297 318 allDay: date._ambigTime, 319 rec: { 320 recurrence: false, 321 recid: '0', 322 days: [false, false, false, false, false, false, false], 323 start: dat, 324 end: end 325 326 }, 298 327 _id: (newid) 299 328 }); 300 329 vm.selectedEventId = vm.treeview.currentNode.calendar.down[0].length - 1; 301 vm.setChanged( );330 vm.setChanged(vm.selectedEventId); 302 331 // $("#resourcecalendar").fullCalendar('refetchEvents'); 303 332 … … 317 346 $scope.dragandDrop = function (event, delta, revertFunc, jsEvent, ui, view) { 318 347 vm.selectedEventId = checkId(event._id); 319 vm.setChanged( );348 vm.setChanged(vm.selectedEventId); 320 349 if (event.end == null) { 321 350 event.end = moment(event.start).add(2, 'hours'); … … 336 365 $scope.resizeEvent = function (event, delta, revertFunc, jsEvent, ui, view) { 337 366 vm.selectedEventId = checkId(event._id); 338 vm.setChanged( );367 vm.setChanged(vm.selectedEventId); 339 368 vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].start = new Date(event.start); 340 369 vm.treeview.currentNode.calendar.down[0][vm.selectedEventId].end = new Date(event.end); … … 344 373 $scope.remove = function (index) { 345 374 vm.selectedEventId = -1; 346 vm.setChanged( );375 vm.setChanged(vm.selectedEventId); 347 376 if (vm.treeview.currentNode.calendar.down[0][index].id != "00000000-0000-0000-0000-000000000000") { 348 377 vm.treeview.currentNode.todelete.push(vm.treeview.currentNode.calendar.down[0][index].id); … … 352 381 353 382 }; 383 384 $scope.checkDateStartEnd = function () { 385 if ($scope.currentcal.down[0][vm.selectedEventId].rec.start > $scope.currentcal.down[0][vm.selectedEventId].rec.end || 386 $scope.currentcal.down[0][vm.selectedEventId].rec.end === undefined) { 387 388 $scope.currentcal.down[0][vm.selectedEventId].rec.end = new Date($scope.currentcal.down[0][vm.selectedEventId].rec.start); 389 390 } 391 if ($scope.currentcal.down[0][vm.selectedEventId].rec.start < Date.now()) 392 $scope.currentcal.down[0][vm.selectedEventId].rec.start = new Date(); 393 } 394 //pushes all changes to other recurs 395 $scope.pushRecurChanges = function (recid) { 396 ngDialog.openConfirm({ 397 template: 398 '<p>This will change all existing recurrences and create new recurrences where needed. Are you sure?</p>' + 399 '<div>' + 400 '<button type="button" class="btn btn-default" ng-click="closeThisDialog(0)">No </button> ' + 401 '<button type="button" class="btn btn-primary" ng-click="confirm(1)">Yes' + 402 '</button></div>', 403 plain: true 404 }).then(function (success) { 405 var arr = vm.treeview.currentNode.calendar.down[0]; 406 var ob = $.extend(true, {}, arr[vm.selectedEventId]); 407 for (var i = 0; i < arr.length;) { 408 if (arr[i].rec.recid === recid) { 409 if (new Date(arr[i].start) < new Date(ob.rec.start) || 410 new Date(arr[i].end) > new Date(ob.rec.end) || 411 !ob.rec.days[new Date(arr[i].start).getDay()]) { 412 vm.remove(i); 413 vm.selectedEventId = -1; 414 415 } 416 else { 417 418 arr[i].start.setHours(ob.start.getHours(), ob.start.getMinutes()); 419 arr[i].end.setHours(ob.end.getHours(), ob.end.getMinutes()); 420 arr[i].title = ob.title; 421 arr[i].rec = ob.rec; 422 arr[i].allDay = ob.allDay; 423 vm.setChanged(i); 424 i++; 425 } 426 } 427 else 428 i++; 429 } 430 var start = new Date(ob.rec.start); 431 start.setHours(2, 0, 0, 0); 432 var end = new Date(ob.rec.end); 433 end = new Date(end.setHours(24, 0, 0, 0) + 1000 * 3600 * 2); 434 435 loop1: 436 for (var d = (start.getTime()) ; d < (end.getTime()) ;) { 437 var tog = ob.rec.days[new Date(d).getDay()]; 438 if (tog) { 439 loop2: 440 for (var i = 0; i < arr.length; i++) { 441 442 if (arr[i].rec.recid === recid) { 443 var dend = (d+1000 * 3600 * 24); 444 if (arr[i].start.getTime() >= d && 445 arr[i].end.getTime() <= dend) { 446 d += (1000 * 3600 * 24); 447 continue loop1; 448 } 449 } 450 } 451 452 var ts = new Date(d); 453 ts.setHours(new Date(ob.start).getHours(), new Date(ob.start).getMinutes()); 454 var te = new Date(d); 455 te.setHours(new Date(ob.end).getHours(), new Date(ob.end).getMinutes()); 456 arr.push({ 457 id: '00000000-0000-0000-0000-000000000000', 458 title: ob.title, 459 start: ts, 460 end: te, 461 allDay: ob.allDay, 462 rec: ob.rec 463 }); 464 vm.setChanged(arr.length - 1); 465 466 } 467 468 d += (1000 * 3600 * 24);// 1 day 469 470 } 471 }); 472 } 473 $scope.deleteAllRecurrences = function (recid) { 474 ngDialog.openConfirm({ 475 template: 476 '<p>This will delete every found recurrence. 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 for (var i = 0; i < arr.length;) { 485 if (arr[i].rec.recid === recid) 486 vm.remove(i); 487 else 488 i++; 489 } 490 }); 491 } 492 354 493 /* Render Tooltip */ 355 494 $scope.eventRender = function (event, element, view) { … … 383 522 } 384 523 }; 385 $rootScope.$on('$locationChangeStart', function (event, newUrl, oldUrl) { 386 console.log($(".changed").length); 387 if ($(".changed").length != 0) { 388 ngDialog.openConfirm({ 389 template: 390 '<p>You have unsaved changes. Are you sure you want to leave this page? All changes will be lost. </p>' + 391 '<div>' + 392 '<button type="button" class="btn btn-primary" ng-click="confirm(1)">Yes' + 393 '<button type="button" class="btn btn-default" ng-click="closeThisDialog(0)">No </button> ' + 394 '</button></div>', 395 plain: true 396 }).then(function (success) { 397 $rootScope.allowNavigation(); 398 }); 399 } 400 401 event.preventDefault(); // This prevents the navigation from happening 402 } 403 ); 524 525 404 526 405 527 });
Note: See TracChangeset
for help on using the changeset viewer.