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