+ if(typeof time == 'object'){
+ return true;
+ }
+ var startDateformat =time.split('/');
+ if (startDateformat.length != 3) return false;
+ var day = startDateformat[1];
+ var month = startDateformat[0];
+ month= parseInt(month)-1;
+ var year = startDateformat[2];
+ if(year.length!=4) return false;
+ var composedDate = new Date(year, month, day);
+ return composedDate.getDate() == day &&
+ composedDate.getMonth() == month &&
+ composedDate.getFullYear() == year;
+
+ };
+
+
+ $scope.addUserNotification = function () {
+ $scope.notificationRoleIds = [];
+ // pre-processing
+
+ for(var fi=0;fi<$scope.treedata.length;fi++){
+ var fLevel = $scope.treedata[fi];
+ if(fLevel){
+ var fLevelChild = fLevel.child;
+ for(var si=0;si<fLevelChild.length;si++){
+ var sLevel = fLevelChild[si];
+ if(sLevel){
+ var sLevelChild = sLevel.child;
+ if(sLevelChild){
+ for(var ti=0;ti< sLevelChild.length;ti++){
+ var tLevel = sLevelChild[ti];
+ if(tLevel.isSelected && tLevel.roleId){
+ $scope.newNotifModel.anyTreeItemSelected=true;
+ for(var i in tLevel.roleId)
+ $scope.notificationRoleIds.push(tLevel.roleId[i]);
+ }
+ }
+ }
+ }
+ if(sLevel.isSelected && sLevel.roleId){
+ for(var i in sLevel.roleId)
+ $scope.notificationRoleIds.push(sLevel.roleId[i]);
+ }
+ }
+ }
+ }
+
+ $scope.notificationRoleIds.sort();
+ if (($scope.newNotifModel.isOnlineUsersOnly) && ($scope.newNotifModel.isForAllRoles) && ($scope.newNotifModel.selectedPriority) && ($scope.newNotifModel.isActive)
+ && ($scope.newNotifModel.startTime) && ($scope.newNotifModel.endTime) && ($scope.newNotifModel.msgHeader != '') && ($scope.newNotifModel.msgDescription != '')) {
+ this.newUserNotification =
+ {
+ 'notificationId':$scope.notificationId,
+ 'isForOnlineUsers': $scope.newNotifModel.isOnlineUsersOnly.value,
+ 'isForAllRoles': $scope.newNotifModel.isForAllRoles,
+ 'priority': $scope.newNotifModel.selectedPriority,
+ 'activeYn': $scope.newNotifModel.isActive.value,
+ 'startTime': $scope.newNotifModel.startTime,
+ 'endTime': $scope.newNotifModel.endTime,
+ 'msgHeader': $scope.newNotifModel.msgHeader,
+ 'msgDescription': $scope.newNotifModel.msgDescription,
+ 'roleIds': $scope.notificationRoleIds,
+ 'createdDate': new Date()
+ };
+
+ // POST ajax call here;
+ if ($scope.isEditMode) {
+ notificationService.updateAdminNotification(this.newUserNotification)
+ .then(() => {
+ if(this.debug)
+ $log.debug('NotificationService:updateAdminNotification:: Admin notification update succeeded!');
+ $scope.closeThisDialog(true);
+ }).catch(err => {
+ $log.error('notificationService.updateAdminNotfication failed: ' + JSON.stringify(err));
+ switch (err.status) {
+ case '409': // Conflict
+ // handleConflictErrors(err);
+ break;
+ case '500': // Internal Server Error
+ confirmBoxService.showInformation('There was a problem updating the notification. ' +
+ 'Please try again later. Error: ' + err.status).then(isConfirmed => { });
+ break;
+ case '403': // Forbidden... possible
+ // webjunction error to
+ // try again
+ confirmBoxService.showInformation('There was a problem updating the notification. ' +
+ 'Please try again. If the problem persists, then try again later. Error: ' + err.status).then(isConfirmed => { });
+ break;
+ default:
+ confirmBoxService.showInformation('There was a problem updating the notification. ' +
+ 'Please try again. If the problem persists, then try again later. Error: ' + err.status).then(isConfirmed => { });
+ }
+ }).finally(() => {
+ // for bug in IE 11
+ var objOffsetVersion = objAgent.indexOf("MSIE");
+ if (objOffsetVersion != -1) {
+ if(this.debug)
+ $log.debug('AppDetailsModalCtrl:updateOnboardingApp:: Browser is IE, forcing Refresh');
+ $window.location.reload();
+ }
+ // for bug in IE 11
+ });
+
+ } else {
+ notificationService.addAdminNotification(this.newUserNotification)
+ .then((res) => {
+ if(this.debug)
+ $log.debug('notificationService:addAdminNotification:: Admin notification creation succeeded!,',res);
+ if(res.status=='ERROR'){
+ confirmBoxService.showInformation('There was a problem adding the notification. ' +
+ ' Error: ' + res.response).then(isConfirmed => { });
+
+
+ }
+ else{
+ //$scope.closeThisDialog(true);
+ $scope.$dismiss('cancel');
+ }
+
+ // emptyCookies();
+ }).catch(err => {
+ switch (err.status) {
+ case '409': // Conflict
+ // handleConflictErrors(err);
+ break;
+ case '500': // Internal Server Error
+ confirmBoxService.showInformation('There was a problem adding the notification. ' +
+ 'Please try again later. Error: ' + err.status).then(isConfirmed => { });
+ break;
+ default:
+ confirmBoxService.showInformation('There was a problem adding the notification. ' +
+ 'Please try again. If the problem persists, then try again later. Error: ' +
+ err.status).then(isConfirmed => { });
+ }
+ $log.error('notificationService:addAdminNotification error:: ' + JSON.stringify(err));
+ })
+ }
+
+
+ } else {
+ $log.warn('please fill in all required fields');
+ confirmBoxService.showInformation('Please fill in all required fields').then(isConfirmed => { });
+ }