summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-widget-ms/common-widgets/portal-common-scheduler-widget/js/controller.js
blob: 934095c3c19e97409a32cca2b24d79ae41fa6ad2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
function SchedulerCtrl($rootScope , $scope,$state,widgetsCatalogService,$log,schedulerService,$filter,confirmBoxService,userProfileService,conf,$interval,$compile) {
			/****define fields****/
			var pollpromise;
			/*Assign the data that's passed to scheduler UI*/
			$scope.hasParentData = true;
			$rootScope.schedulerID = '';
			$scope.orgUserId="";
			$scope.policys = [];
			$scope.selectedPolicy={policyName:"",policyConfig:""};
			$scope.scheduler = {};
			$scope.schedulingInfo = {};
			$scope.timeSlots = [];
			$scope.changeManagement = {};
            $rootScope.schedulerForm = {
            	checkboxSelection : 'false',
        		fromDate:'',
        		toDate:'',
        		duration:'',
        		fallbackDuration:'',
        		concurrencyLimit:''
            };
            
            $scope.vnfNames = [];
            $scope.vnfTypes = [];
            $scope.schedulerObj = {};
			
			var tomorrow = new Date();
			tomorrow.setDate(tomorrow.getDate() + 1);
            $scope.minDate = tomorrow.toISOString().substring(0, 10);

    		
			/*form validation*/
			$scope.durationEmpty=false;
			$scope.concurrencyLimitEmpty = false;
			$scope.fallBackDurationEmpty=false;
			$scope.fromDateEmpty = false;
			$scope.toDateEmpty=false;

			/*interval values for getting time slots*/
			var hasvaluereturnd = true; 
			var hasthresholdreached = false; 
			var thresholdvalue =10; // interval threshold value				
			
			$scope.timeUnit= [
				{text: 'HOURS'},
				{text: 'MINUTES'},
				{text: 'SECONDS'}
			];
		

			/***** Functions for modal popup ******/ 
			$scope.radioSelections=function (){
				if( $rootScope.schedulerForm.checkboxSelection=="true"){
					$rootScope.schedulerForm.fromDate='';
					$rootScope.schedulerForm.toDate=''
				}
			}
			
			/*Dropdown update: everytime values in dropdown chagnes, update the selected value*/
			$scope.$watch('selectedPolicy.policyName', (newVal, oldVal) => {
	            for (var i = 0; i < $scope.policys.length; i++) 
	                if ($scope.policys[i].policyName == newVal) 
	                    $scope.selectedPolicy = angular.copy($scope.policys[i]);;            
	        });
			
			$scope.$watch('selectedTimeUint.text', (newVal, oldVal) => {
	            for (var i = 0; i < $scope.timeUnit.length; i++) 
	                if ($scope.timeUnit[i].text == newVal) 
	                	$scope.selectedTimeUint = angular.copy($scope.timeUnit[i]);;
	        });
			
			/**
			 * This function is to validate and check if the input is a valid date. 
			 * There are two checkers in this function:
			 * Check 1: the input is a valid date object,return true, return false otherwise.
			 * Check 2: check if the input has the format of MM/DD/YYYY or M/D/YYYY and is a valid date value. 
			 * @param  dateInput
			 * @return true/false
			 */	
			$scope.isDateValid = function(dateInput) {
				/*Check 1: see if the input is able to convert into date object*/
				if ( Object.prototype.toString.call(dateInput) === "[object Date]" ) 
					return true;
				/*Check 2: see if the input is the date format MM/DD/YYYY */
				var isDateStrFormat = false;
				try{
					/*check the format of MM/DD/YYYY or M/D/YYYY */
					var startDateformat = dateInput.split('/');
					if (startDateformat.length != 3) 
						return false; 
					var day = startDateformat[1];
					var month = parseInt(startDateformat[0])-1;
					var year = startDateformat[2];
					if (year.length != 4) 
						return false;
					/*check the input value and see if it's a valid date*/
					var composedDate = new Date(year, month, day);
					if(composedDate.getDate() == day && composedDate.getMonth() == month && composedDate.getFullYear() == year)
						isDateStrFormat = true
					else
						isDateStrFormat =false;
				}catch(err){
					return false;
				}
				return isDateStrFormat;
			};

			/**
			 * This function is to check whether the input date is greater than current date or not.  
			 * @param  date
			 * @return true/false
			 */			
			$scope.isStartDateValidFromToday = function (date) {
				if(!$scope.isDateValid(date))
					return false;
				var startDate = new Date(date);
                var currentDate = new Date();
                if(startDate<=currentDate)
					return false;
				return true;
            };
			
			/**
			 * This function is to check whether the input to date is greater than input from date.  
			 * @param  fromDate , toDate
			 * @return true/false
			 */	
			$scope.isToDateGreaterFromDate = function (fromDate,toDate) {
				if(!$scope.isDateValid(fromDate) || !$scope.isDateValid(toDate))
					return false; 	
                var fromDateObj = new Date(fromDate);
                var toDateObj = new Date(toDate);
                if(toDateObj<=fromDateObj)
                	return false;        
                return true;
            };
			
			/**
			 * This function is to get error message from the input json response object.  
			 * @param  response , method
			 * @return errorMsg
			 */				
			$scope.parseErrorMsg = function(response, method){
				var errorMsg = '';
				if(response.entity){
					try{
						var entityJson = JSON.parse(response.entity);
						if(entityJson){
							errorMsg = entityJson.requestError.text;
						}	
					}catch(err){
						$log.error('SchedulerCtrl::' + method +'  error: ' + err);
					}
				}
				return errorMsg;
			}
			/***** Scheduler UI functions *****/

			/* This function is to send scheduler task approval to scheduler microservice.  */	
			$scope.submit = function () {
				$rootScope.showSpinner =true;
				
				var approvalDateTime = new Date($scope.timeSlots[0].startTime);
				$scope.schedulingInfo={
					scheduleId: $rootScope.schedulerID,
					approvalDateTime:approvalDateTime.toISOString(),
					approvalUserId:$scope.orgUserId,
					approvalStatus:$scope.schedulerObjConst.approvalSubmitStatus,
					approvalType: $scope.schedulerObjConst.approvalType
				}
				var approvalObj= JSON.stringify($scope.schedulingInfo)
				schedulerService.postSubmitForApprovedTimeslots(approvalObj).then(response => {
					if(response.status>=200 && response.status<=204){
						confirmBoxService.showInformation("Successfully Sent for Approval").then(isConfirmed => {});
					}else{
						var errorMsg = $scope.parseErrorMsg(response, 'postSubmitForApprovedTimeslots');		
						confirmBoxService.showInformation("Failed to Send for Approval "+ errorMsg).then(isConfirmed => {
							$scope.closeModal();
						});
					}
				}).catch(err => {
					$log.error('SchedulerCtrl::postSubmitForApprovedTimeslots error: ' + err);
					var errorMsg = '';
					if(err.data)
						errorMsg = $scope.parseErrorMsg(err.data, 'postSubmitForApprovedTimeslots');	
					else
						errorMsg = err;
					confirmBoxService.showInformation("There was a problem sending Schedule request. " + errorMsg).then(isConfirmed => {
						$scope.closeModal();
					});
				}).finally(() => {
					$rootScope.showSpinner = false;
				});
			};

			/* This function is to send scheduler task rejection to scheduler microservice.  */	
			$scope.reject = function () {
				$rootScope.showSpinner =true;
				var approvalDateTime = new Date($scope.timeSlots[0].startTime);
				$scope.schedulingInfo={
					scheduleId: $rootScope.schedulerID,
					approvalDateTime:approvalDateTime.toISOString(),
					approvalUserId:$scope.orgUserId,
					approvalStatus: $scope.schedulerObjConst.approvalRejectStatus,
					approvalType: $scope.schedulerObjConst.approvalType
				}
				var approvalObj= JSON.stringify($scope.schedulingInfo)
				schedulerService.postSubmitForApprovedTimeslots(approvalObj).then(response => {
					if(response.status>=200 && response.status<=299){
						confirmBoxService.showInformation("Successfully Sent for Reject").then(isConfirmed => {});
					}else{
						var errorMsg = $scope.parseErrorMsg(response, 'postSubmitForApprovedTimeslots');		
						confirmBoxService.showInformation("Failed to Send for Reject "+ errorMsg).then(isConfirmed => {});
					}
				}).catch(err => {
					$log.error('SchedulerCtrl::postSubmitForApprovedTimeslots error: ' + err);
					var errorMsg = '';
					if(err.data)
						errorMsg = $scope.parseErrorMsg(err.data, 'postSubmitForApprovedTimeslots');	
					else
						errorMsg = err;
					confirmBoxService.showInformation("There was a problem rejecting Schedule request. " + errorMsg).then(isConfirmed => {
						$scope.closeModal();
					});
				}).finally(() => {
					$rootScope.showSpinner = false;
				});
			};

			/* This function is to send policy config and receive scheduler Id.  */	
			function sendSchedulerReq(){
				$scope.timeSlots=[];
				$scope.timeSlots.length=0;
				$scope.schedulerObj.userId=$scope.orgUserId;   
				$scope.schedulerObj.domainData[0].WorkflowName=$scope.vnfObject.workflow;
				$scope.schedulerObj.schedulingInfo.normalDurationInSeconds=convertToSecs($rootScope.schedulerForm.duration)
				$scope.schedulerObj.schedulingInfo.additionalDurationInSeconds=convertToSecs($rootScope.schedulerForm.fallbackDuration)
				$scope.schedulerObj.schedulingInfo.concurrencyLimit=parseInt($rootScope.schedulerForm.concurrencyLimit)
				
				$scope.schedulerObj.schedulingInfo['vnfDetails'][0].groupId=$scope.schedulerObjConst.groupId;				
				$scope.schedulerObj.schedulingInfo['vnfDetails'][0].node=getVnfData($scope.vnfObject.vnfNames);	
				for(var i=0;i<$scope.policys.length;i++){
					if($scope.policys[i].policyName == $scope.selectedPolicy.policyName){
						try{						
							var config = $scope.policys[i].config;
							var configJson = JSON.parse(config);
							$scope.selectedPolicy.policyConfig = configJson.policyName;
						}catch(err){
							confirmBoxService.showInformation("There was a problem setting Policy config. Please try again later. " + err).then(isConfirmed => {
								$scope.closeModal();
							});
							return;
						}								
					}							
				}
				$scope.schedulerObj.schedulingInfo.policyId=$scope.selectedPolicy.policyConfig; 								
				var changeWindow=[{
					startTime:$filter('date')(new Date($rootScope.schedulerForm.fromDate), "yyyy-MM-ddTHH:mmZ", "UTC"),
					endTime:$filter('date')(new Date($rootScope.schedulerForm.toDate), "yyyy-MM-ddTHH:mmZ", "UTC")
				}];
				$scope.schedulerObj.schedulingInfo['vnfDetails'][0].changeWindow=changeWindow;
				
				if($rootScope.schedulerForm.checkboxSelection=="true"){               //When Scheduled now we remove the changeWindow
					delete $scope.schedulerObj.schedulingInfo['vnfDetails'][0].changeWindow;
				}
				var requestScheduler=  JSON.stringify($scope.schedulerObj)
				$rootScope.showSpinner = true;
				schedulerService.getStatusSchedulerId(requestScheduler).then(response => {
					
					var errorMsg = '';
					if(response && response.entity!=null){
						var errorMsg = $scope.parseErrorMsg(response, 'getStatusSchedulerId');		
						confirmBoxService.showInformation("There was a problem retrieving scheduler ID. Please try again later. " + errorMsg).then(isConfirmed => {
							$scope.closeModal();
						});

					}else{
						if(response && response.uuid){
							$rootScope.schedulerID = response.uuid;
							var scheduledID= JSON.stringify({scheduleId:$rootScope.schedulerID});              	 
							$scope.seviceCallToGetTimeSlots();
						}else{
							confirmBoxService.showInformation("There was a problem retrieving scheduler ID. Please try again later. " + response).then(isConfirmed => {

							});
						}
						
						
					}
				}).catch(err => {
					$rootScope.showSpinner = false; 
                    $log.error('SchedulerCtrl::getStatusSchedulerId error: ' + err);
					var errorMsg = '';
					if(err.data)
						errorMsg = $scope.parseErrorMsg(err.data, 'getStatusSchedulerId');	
					else
						errorMsg = err;
					confirmBoxService.showInformation("There was a problem retrieving scheduler ID. Please try again later." + errorMsg).then(isConfirmed => {
						$scope.closeModal();
					});
                }).finally(() => {
					$rootScope.showSpinner = false;
				});
			}

			/* This function is to get time slots from SNIRO  */	
			$scope.seviceCallToGetTimeSlots = function(){
				$rootScope.showTimeslotSpinner = true;
				schedulerService.getTimeslotsForScheduler($rootScope.schedulerID).then(response => {	
					if($rootScope.schedulerForm.checkboxSelection=="false"){
						if(response.entity && JSON.parse(response.entity).schedule){ //received the timeslots
							var entityJson = JSON.parse(response.entity);
							var scheduleColl=JSON.parse(entityJson.schedule);
							if(scheduleColl.length>0){
								$scope.timeSlots =scheduleColl;
								hasvaluereturnd = false;
								$rootScope.showTimeslotSpinner = false; 
								$scope.stopPoll();
								confirmBoxService.showInformation(entityJson.scheduleId +" Successfully Returned TimeSlots.").then(isConfirmed => {});
							}else
								confirmBoxService.showInformation("No time slot available").then(isConfirmed => {
									$scope.closeModal();
								});
						}else{ // do polling 
							if($scope.timeSlots.length==0 && hasthresholdreached==false){
								var polltime=$scope.schedulerObjConst.getTimeslotRate*1000;
								pollpromise= poll(polltime, function () {
									if($scope.timeSlots.length==0){
										hasvaluereturnd = true;                          
										$scope.seviceCallToGetTimeSlots()
									}else
										hasvaluereturnd = false;		
								});
							} else {
								if($rootScope.showTimeslotSpinner === true){
									$rootScope.showTimeslotSpinner = false;
									hasthresholdreached = false;
									confirmBoxService.showInformation("Failed to get time slot - Timeout error. Please try again later").then(isConfirmed => { 
										$scope.closeModal();
									});
								}
							}
						}
					}else{
						if(response.entity){
							$rootScope.showTimeslotSpinner = false; 
							if($rootScope.schedulerForm.checkboxSelection=="false")
								confirmBoxService.showInformation("Schedule ID :" + response.entity.scheduleId +" is ready to schedule.").then(isConfirmed => {});	
							else{
								var entityObj = JSON.parse(response.entity);
								confirmBoxService.showInformation("ID :" + entityObj.scheduleId +" is successfully sent for Approval").then(isConfirmed => {
									$scope.closeModal();
								});	
							}		
						}
					}
				}).catch(err => {
					$log.error('SchedulerCtrl::seviceCallToGetTimeSlots error: ' + err);
					$rootScope.showTimeslotSpinner = false; 
					confirmBoxService.showInformation("There was a problem retrieving time slows. Please try again later.").then(isConfirmed => {
						$scope.closeModal();
					});
				})
			}
			
			
			$scope.closeModal = function(){		
				setTimeout(function(){ $rootScope.closeModal(); }, 500);
			}
			
			/* This function is to get policy list from policy microservice */	
			$scope.getPolicy = function(){
			     schedulerService.getPolicyInfo().then(res =>{
			    	 if(res==null || res=='' || res.status==null || !(res.status>=200 && res.status<=299)){
	                    $log.error('SchedulerWidgetCtrl::getPolicyInfo caught error', res);
						var errorMsg = $scope.parseErrorMsg(res, 'getPolicy');		
						confirmBoxService.showInformation('There was a problem retrieving ploicy. Please try again later. ' + errorMsg).then(isConfirmed => {
							$scope.closeModal();
						});
			    	 }else
			    		$scope.policys = res.entity;
			     });
			}
			
			$scope.removeXMLExtension = function(str){
				return str.replace(".xml","");
			};
			/* Find Button */
			$scope.schedule = function () {		
				if($scope.formValidation())
					sendSchedulerReq();
			};
			
			/*************utility functions**************/
			
			function convertToSecs(number){
				var totalSecs;
				if($scope.selectedTimeUint.text === 'HOURS'){
					totalSecs=number * 3600;
				} else if($scope.selectedOption === 'MINUTES') {
					totalSecs=number * 60;
				} else {
					totalSecs=number;
				}
				return totalSecs;
			}

			function poll(interval, callback) {
				return $interval(function () {
					if (hasvaluereturnd)   //check flag before start new call
						callback(hasvaluereturnd);				
					thresholdvalue = thresholdvalue - 1;  //Decrease threshold value 
					if (thresholdvalue == 0) 
						$scope.stopPoll(); // Stop $interval if it reaches to threshold				
				}, interval)
			}

			// stop interval.
			$scope.stopPoll = function () {
				$interval.cancel(pollpromise);
				thresholdvalue = 0;     //reset all flags. 
				hasvaluereturnd = false;
				hasthresholdreached=true;
				$rootScope.showSpinner = false;
			}

			function getVnfData(arrColl){
				var vnfcolletion=[];
				for(var i=0;i<arrColl.length;i++)
					vnfcolletion.push(arrColl[i].name);				
				return vnfcolletion
			}

			function extractChangeManagementCallbackDataStr(changeManagement) {
				var result = {};
				result.requestType = changeManagement.workflow;
				result.requestDetails = [];
				_.forEach(changeManagement.vnfNames, function (vnfName) {
					if (vnfName && vnfName.version) {
						if (vnfName.selectedFile) {
							vnfName.version.requestParameters.userParams = vnfName.selectedFile;
						}
						result.requestDetails.push(vnfName.version)
					}
				});
				return JSON.stringify(result);
			}

			
			$scope.constructScheduleInfo = function(){
	            var callbackData = extractChangeManagementCallbackDataStr($scope.vnfObject);
				$scope.schedulerObj = {
	            		domain: $scope.schedulerObjConst.domain,
	            		scheduleId: '',
	            		scheduleName: $scope.schedulerObjConst.scheduleName,
	            		userId: '',
	            		domainData: [{
	            			'WorkflowName':  $scope.schedulerObjConst.WorkflowName,
	            			'CallbackUrl': $scope.schedulerObjConst.CallbackUrl,
	            			'CallbackData': callbackData
	            		}],
	            		schedulingInfo: {
	            			normalDurationInSeconds: '',
	            			additionalDurationInSeconds: '',
	            			concurrencyLimit: '',
	            			policyId: '',
	            			vnfDetails: [
	            				{
	            					groupId: "",
	            					node: [],
	            					changeWindow: [{
	            						startTime: '',
	            						endTime: ''
	            					}]
	            				}
	            			]
	            		},
		            }
			}
			
			$scope.formValidation = function(){
				$scope.durationEmpty=false;
				$scope.concurrencyLimitEmpty = false;
				$scope.fallBackDurationEmpty=false;
				$scope.fromDateGreater=false;
				$scope.fromDateEmpty=false;
				$scope.toDateEmpty=false;
				if($rootScope.schedulerForm.duration=='')
					$scope.durationEmpty=true;
				if($rootScope.schedulerForm.fallbackDuration=='')
					$scope.fallBackDurationEmpty=true;	
				if($rootScope.schedulerForm.concurrencyLimit=='')
					$scope.concurrencyLimitEmpty = true;
				if(!($rootScope.schedulerForm.fromDate instanceof Date))
					$scope.fromDateEmpty=true;
				if(!($rootScope.schedulerForm.toDate  instanceof Date ))
					$scope.toDateEmpty=true;
				var fromDateObj = new Date($rootScope.schedulerForm.fromDate);
				var toDateObj = new Date($rootScope.schedulerForm.toDate);				
				if(fromDateObj>toDateObj)
					$scope.fromDateGreater = true;					
				if($scope.durationEmpty||$scope.fallBackDurationEmpty ||$scope.concurrencyLimitEmpty || (($scope.fromDateEmpty || $scope.toDateEmpty) &&  $rootScope.schedulerForm.checkboxSelection=='false' ) ||$scope.fromDateGreater)
					return false;
				if($rootScope.schedulerForm.checkboxSelection == false && (!isDateValid($rootScope.schedulerForm.toDate) || !isDateValid($rootScope.schedulerForm.fromDate)))
					return false;
				if($scope.selectedPolicy.policyName=='' || $scope.selectedPolicy.policyName=='Select Policy'){
					confirmBoxService.showInformation("Policy is required").then(isConfirmed => {});
					return false;
				}
				return true;		
			}
			
			$scope.getScheduleConstant =function(){
				schedulerService.getSchedulerConstants().then(res =>{
					if(res==null || res=='' || res.status==null || res.status!="OK"){
						$log.error('SchedulerWidgetCtrl::getSchedulerConstants caught error', res);		
						confirmBoxService.showInformation('There is a problem about the Scheduler UI. Please try again later.').then(isConfirmed => {
							$scope.closeModal();
						});
					}else{
						var response = res.response;
						$scope.schedulerObjConst= {
							domain: response.domainName,
							scheduleName : response.scheduleName,
							WorkflowName : response.workflowName,
							CallbackUrl : response.callbackUrl,
							approvalType : response.approvalType,
							approvalSubmitStatus : response.approvalSubmitStatus,
							approvalRejectStatus : response.approvalRejectStatus,
							getTimeslotRate : response.intervalRate,
							policyName : response.policyName,
							groupId : response.groupId
						}
						$scope.constructScheduleInfo();
						$scope.getPolicy() // get policy items for the dropdown in the scheduler UI	
					}
				});	
			}
			
			/*This function is to get the current logged in user id*/
			$scope.getUserId = function(){
				$rootScope.showSpinner = true;
				userProfileService.getUserProfile()
				.then(profile=> {
					$scope.orgUserId = profile.orgUserId;
				}).finally(() => {
					$rootScope.showSpinner = false;
				});
			}
			
			$scope.activateThis = function(ele){
   			 	$compile(ele.contents())($scope);
   			 	$scope.$apply();
            };
			
			/** listening calls from parents **/
			$scope.$on("submit", function(events,data){
				$scope.submit();
			});

			$scope.$on("reject", function(events,data){
				$scope.reject();
			});
			
			$scope.$on("schedule", function(events,data){
				$scope.schedule();
			});

			/** init **/
            
            var init = function () {				
				$rootScope.showSpinner = false;
				$scope.selectedTimeUint=$scope.timeUnit[0];

				if($scope.$parent.parentData){	
					$scope.hasParentData = true;
					$scope.message = $scope.$parent.parentData;				
					$scope.vnfObject = $scope.message.data;
					$scope.schedulerObj = $scope.message.data;
					$scope.getUserId();
					$scope.getScheduleConstant(); //get Scheduler constants from properties file     		
				}else{
					//second approach to get data
					var isModal = $( "#scheduler-body" ).hasClass( "b2b-modal-body" );
					if(isModal){
						$scope.message = schedulerService.getWidgetData();
						if($scope.message){
							$scope.hasParentData = true;
							$scope.vnfObject = $scope.message.data;
							$scope.schedulerObj = $scope.message.data;
							$scope.getUserId();
							$scope.getScheduleConstant(); //get Scheduler constants from properties file
						}								
					}else{
						$scope.hasParentData = false;
					}
				}
			};
			
			init();
			
			
}