nexus site path corrected
[portal.git] / ecomp-portal-FE / client / app / views / support / contact-us / contact-us-manage / contact-us-manage.controller.js
1 /*-
2  * ================================================================================
3  * eCOMP Portal
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ================================================================================
19  */
20 'use strict';
21
22 (function () {
23     class ContactUsManageController {
24         constructor($scope,$log, message, $q, $http, conf,contactUsService,confirmBoxService) {
25                 $scope.contactUsList=[];
26                 $scope.contactUsAllAppList=[];
27                 $scope.errMsg='';
28                 $scope.newContactUs ={
29                                 app:'',
30                                 name:'',
31                                 email:'',
32                                 url:'',
33                                 desc:''                         
34                 };
35                 /*Get the existing contact us first, then based on the existing, filter from all apps*/
36                 $scope.getContactUsList = function(){
37                         contactUsService.getContactUs().then(res=> {
38                         // $log.info('getting getContactUs',res.response);
39                         if(res!=null && res.response!=null){
40                                 for(var i=0; i<res.response.length;i++){
41                                         if(res.response[i].appId!=1)
42                                                 $scope.contactUsList.push(res.response[i]);
43                                 }
44                         }
45                         /*get all the apps*/
46                         contactUsService.getListOfApp().then(res=> {
47                         var tableData=[];
48                         $scope.contactUsAllAppListTemp=[];
49                         // $log.info('contactUsService::getListOfApp: getting res');
50                         var result = (typeof(res.data) != "undefined" && res.data!=null)?res.data:null;
51                         // $log.info('contactUsService::getListOfApp: result',result);          
52                         var res1 = result;
53                         var realAppIndex = 0;
54                         $scope.contactUsAllAppList.length=0;
55                         for (var i = 1; i <= res1.length; i++) {
56                             if (!res1[i - 1].restrictedApp) {
57                                 var okToAdd = true;
58                                 for(var j =0; j<$scope.contactUsList.length;j++){
59                                         if(res1[i - 1].title==$scope.contactUsList[j].appName)
60                                                 okToAdd=false;
61                                 }
62                                 // not allowed to add(duplicate) another entry if the app is already available in the table
63                                 if(okToAdd){
64                                         if(res1[i - 1].title){
65                                                 $scope.contactUsAllAppList.push({
66                                             index: realAppIndex,
67                                             title: res1[i - 1].title,
68                                             value: res1[i - 1].index
69                                         });
70                                         }       
71                                         realAppIndex = realAppIndex + 1;
72                                 }         
73                             } else {
74                                 // $log.debug('contactUsService:getAvailableApps:: Restricted/URL only App will not be used = ' + res1[i - 1].title);
75                             }
76                         }       
77                     }).catch(err=> {
78                         $log.error('contactUsService:error:: ', err);
79                         
80                        
81                     }).finally(() => {
82                         //this.isLoadingTable = false;
83                     });
84                 });
85                 }
86                 
87                 $scope.getContactUsList();
88                 
89                 $scope.closeDialog = function(){
90                         $scope.closeThisDialog( $scope.widgetData);
91                 }
92                 
93                 /*Add new Contact Us*/
94                 $scope.newContactUsFun = function(){ 
95                         if($scope.newContactUs.app.title==null || $scope.newContactUs.app.title=='' ){
96                                 confirmBoxService.showInformation('Please select an App to add').then(isConfirmed => {
97                                         return;
98                                 });     
99                         }
100                                                 
101                         if($scope.newContactUs.url !=null && $scope.newContactUs.url != '' && !validateUrl($scope.newContactUs.url)){
102                                 var warningMsg = "Please enter a valid URL";
103                                 confirmBoxService.showInformation(warningMsg).then(isConfirmed => {return;});
104                                 return;
105                         }
106                         
107                         contactUsService.addContactUs($scope.newContactUs).then(res=> {
108                                 // $log.info('contactUsService: add ContactUs successfully');
109                                 $scope.contactUsList.length=0;
110                                 // $log.info('contactUsService: refreshing the Contact US table');
111                                 $scope.getContactUsList();
112                                 $scope.errMsg='';
113                                 /*      confirmBoxService.showInformation('You have added a new Contact Us item').then(isConfirmed => { });*/
114                                 var defaultSel={
115                                                 index: 0,
116                             title: '',
117                             value: ''
118                                 }
119                                 $scope.newContactUs ={
120                                         app:defaultSel,                         
121                                         name:'',
122                                         email:'',
123                                         url:'',
124                                         desc:''                         
125                         };
126
127                 }).catch(err=> {
128                     $log.error('contactUsService: addContactUs error:: ', err);
129                    // $scope.errMsg=err;
130                     confirmBoxService.showInformation('Add Contact Us list failed: ' + err);
131                    
132                 }).finally(() => {
133                     //this.isLoadingTable = false;
134                 });
135                 }
136                 /* Edit Contact Us*/
137                 $scope.editContactUsFun = function(contactObj){
138                         // $log.info('contactUsService: edit ContactUs save successfully', contactObj);                         
139                         var contactUsObj={
140                                 appId:contactObj.appId,
141                                 appName:contactObj.appName,
142                                 description:contactObj.description,
143                                 contactName:contactObj.contactName,
144                                 contactEmail:contactObj.contactEmail,
145                                 url:contactObj.url,                     
146                 };
147                         
148                         contactUsService.modifyContactUs(contactUsObj).then(res=> {
149                                 // $log.info('contactUsService: edit ContactUs successfully');
150                                 //      confirmBoxService.showInformation('You have saved the changes').then(isConfirmed => {});
151                                 $scope.errMsg='';
152                                 
153                 }).catch(err=> {
154                     $log.error('contactUsService: editContactUs error:: ', err);
155                     confirmBoxService.showInformation('Edit Contact Us list failed: ' + err);
156                    // $scope.errMsg=err;
157                 }).finally(() => {
158                     //this.isLoadingTable = false;
159                 });
160                         
161                 }
162                 /*del Contact Us*/
163                 $scope.delContactUsFun = function(appObj){
164                         var confirmMsg = 'Are you sure you want to delete '+appObj.appName +' from the list?' + ' Press OK to delete.';
165                         confirmBoxService.confirm(confirmMsg).then(function (confirmed) {
166                     if (confirmed == true) {                            
167                         contactUsService.removeContactUs(appObj.appId).then(res=> {   
168                                 // $log.info('delContactUsFun: delete ContactUs successfully',res);
169                                         $scope.errMsg='';
170                                         $scope.contactUsList.length=0;
171                                         $scope.getContactUsList();
172                                         confirmBoxService.showInformation('Item has been deleted').then(isConfirmed => {});
173                         }).catch(err=> {
174                             $log.error('contactUsService: addContactUs error:: ', err);
175                             confirmBoxService.showInformation('Deletion failed: ' + err);
176                            // $scope.errMsg=err;
177                         }).finally(() => {
178                             //this.isLoadingTable = false;
179                         });
180                     }
181                 });
182                         
183                 }       
184                 
185         }        
186     }
187     ContactUsManageController.$inject = ['$scope','$log',  'message', '$q', '$http', 'conf','contactUsService','confirmBoxService'];
188     angular.module('ecompApp').controller('ContactUsManageController', ContactUsManageController);
189
190  
191 })();
192 function validateUrl(value){
193     return /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value);
194   }