2 * ================================================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ================================================================================
23 class ContactUsManageController {
24 constructor($scope,$log, message, $q, $http, conf,contactUsService,confirmBoxService) {
25 $scope.contactUsList=[];
26 $scope.contactUsAllAppList=[];
28 $scope.newContactUs ={
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]);
46 contactUsService.getListOfApp().then(res=> {
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);
54 $scope.contactUsAllAppList.length=0;
55 for (var i = 1; i <= res1.length; i++) {
56 if (!res1[i - 1].restrictedApp) {
58 for(var j =0; j<$scope.contactUsList.length;j++){
59 if(res1[i - 1].title==$scope.contactUsList[j].appName)
62 // not allowed to add(duplicate) another entry if the app is already available in the table
64 if(res1[i - 1].title){
65 $scope.contactUsAllAppList.push({
67 title: res1[i - 1].title,
68 value: res1[i - 1].index
71 realAppIndex = realAppIndex + 1;
74 // $log.debug('contactUsService:getAvailableApps:: Restricted/URL only App will not be used = ' + res1[i - 1].title);
78 $log.error('contactUsService:error:: ', err);
82 //this.isLoadingTable = false;
87 $scope.getContactUsList();
89 $scope.closeDialog = function(){
90 $scope.closeThisDialog( $scope.widgetData);
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 => {
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;});
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();
113 /* confirmBoxService.showInformation('You have added a new Contact Us item').then(isConfirmed => { });*/
119 $scope.newContactUs ={
128 $log.error('contactUsService: addContactUs error:: ', err);
129 // $scope.errMsg=err;
130 confirmBoxService.showInformation('Add Contact Us list failed: ' + err);
133 //this.isLoadingTable = false;
137 $scope.editContactUsFun = function(contactObj){
138 // $log.info('contactUsService: edit ContactUs save successfully', contactObj);
140 appId:contactObj.appId,
141 appName:contactObj.appName,
142 description:contactObj.description,
143 contactName:contactObj.contactName,
144 contactEmail:contactObj.contactEmail,
148 contactUsService.modifyContactUs(contactUsObj).then(res=> {
149 // $log.info('contactUsService: edit ContactUs successfully');
150 // confirmBoxService.showInformation('You have saved the changes').then(isConfirmed => {});
154 $log.error('contactUsService: editContactUs error:: ', err);
155 confirmBoxService.showInformation('Edit Contact Us list failed: ' + err);
156 // $scope.errMsg=err;
158 //this.isLoadingTable = false;
163 $scope.$watch('newContactUs.app.value', (newVal, oldVal) => {
164 for(var i=0;i<$scope.contactUsAllAppList.length;i++){
165 if($scope.contactUsAllAppList[i].value==newVal){
166 $scope.newContactUs.app=angular.copy($scope.contactUsAllAppList[i]);;
171 $scope.delContactUsFun = function(appObj){
172 var confirmMsg = 'Are you sure you want to delete '+appObj.appName +' from the list?' + ' Press OK to delete.';
173 confirmBoxService.confirm(confirmMsg).then(function (confirmed) {
174 if (confirmed == true) {
175 contactUsService.removeContactUs(appObj.appId).then(res=> {
176 // $log.info('delContactUsFun: delete ContactUs successfully',res);
178 $scope.contactUsList.length=0;
179 $scope.getContactUsList();
180 confirmBoxService.showInformation('Item has been deleted').then(isConfirmed => {});
182 $log.error('contactUsService: addContactUs error:: ', err);
183 confirmBoxService.showInformation('Deletion failed: ' + err);
184 // $scope.errMsg=err;
186 //this.isLoadingTable = false;
195 ContactUsManageController.$inject = ['$scope','$log', 'message', '$q', '$http', 'conf','contactUsService','confirmBoxService'];
196 angular.module('ecompApp').controller('ContactUsManageController', ContactUsManageController);
200 function validateUrl(value){
201 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|-|\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