2 * ================================================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ================================================================================
\r
23 class ContactUsManageController {
\r
24 constructor($scope,$log, message, $q, $http, conf,contactUsService,confirmBoxService) {
\r
25 $scope.contactUsList=[];
\r
26 $scope.contactUsAllAppList=[];
\r
28 $scope.newContactUs ={
\r
35 /*Get the existing contact us first, then based on the existing, filter from all apps*/
\r
36 $scope.getContactUsList = function(){
\r
37 contactUsService.getContactUs().then(res=> {
\r
38 // $log.info('getting getContactUs',res.response);
\r
39 if(res!=null && res.response!=null){
\r
40 for(var i=0; i<res.response.length;i++){
\r
41 if(res.response[i].appId!=1)
\r
42 $scope.contactUsList.push(res.response[i]);
\r
45 /*get all the apps*/
\r
46 contactUsService.getListOfApp().then(res=> {
\r
48 $scope.contactUsAllAppListTemp=[];
\r
49 // $log.info('contactUsService::getListOfApp: getting res');
\r
50 var result = (typeof(res.data) != "undefined" && res.data!=null)?res.data:null;
\r
51 // $log.info('contactUsService::getListOfApp: result',result);
\r
53 var realAppIndex = 0;
\r
54 $scope.contactUsAllAppList.length=0;
\r
55 for (var i = 1; i <= res1.length; i++) {
\r
56 if (!res1[i - 1].restrictedApp) {
\r
58 for(var j =0; j<$scope.contactUsList.length;j++){
\r
59 if(res1[i - 1].title==$scope.contactUsList[j].appName)
\r
62 // not allowed to add(duplicate) another entry if the app is already available in the table
\r
64 if(res1[i - 1].title){
\r
65 $scope.contactUsAllAppList.push({
\r
66 index: realAppIndex,
\r
67 title: res1[i - 1].title,
\r
68 value: res1[i - 1].index
\r
71 realAppIndex = realAppIndex + 1;
\r
74 // $log.debug('contactUsService:getAvailableApps:: Restricted/URL only App will not be used = ' + res1[i - 1].title);
\r
78 $log.error('contactUsService:error:: ', err);
\r
82 //this.isLoadingTable = false;
\r
87 $scope.getContactUsList();
\r
89 $scope.closeDialog = function(){
\r
90 $scope.closeThisDialog( $scope.widgetData);
\r
93 /*Add new Contact Us*/
\r
94 $scope.newContactUsFun = function(){
\r
95 if($scope.newContactUs.app.title==null || $scope.newContactUs.app.title=='' ){
\r
96 confirmBoxService.showInformation('Please select an App to add').then(isConfirmed => {
\r
101 if($scope.newContactUs.url !=null && $scope.newContactUs.url != '' && !validateUrl($scope.newContactUs.url)){
\r
102 var warningMsg = "Please enter a valid URL";
\r
103 confirmBoxService.showInformation(warningMsg).then(isConfirmed => {return;});
\r
107 contactUsService.addContactUs($scope.newContactUs).then(res=> {
\r
108 // $log.info('contactUsService: add ContactUs successfully');
\r
109 $scope.contactUsList.length=0;
\r
110 // $log.info('contactUsService: refreshing the Contact US table');
\r
111 $scope.getContactUsList();
\r
113 /* confirmBoxService.showInformation('You have added a new Contact Us item').then(isConfirmed => { });*/
\r
119 $scope.newContactUs ={
\r
128 $log.error('contactUsService: addContactUs error:: ', err);
\r
129 // $scope.errMsg=err;
\r
130 confirmBoxService.showInformation('Add Contact Us list failed: ' + err);
\r
133 //this.isLoadingTable = false;
\r
136 /* Edit Contact Us*/
\r
137 $scope.editContactUsFun = function(contactObj){
\r
138 // $log.info('contactUsService: edit ContactUs save successfully', contactObj);
\r
140 appId:contactObj.appId,
\r
141 appName:contactObj.appName,
\r
142 description:contactObj.description,
\r
143 contactName:contactObj.contactName,
\r
144 contactEmail:contactObj.contactEmail,
\r
145 url:contactObj.url,
\r
148 contactUsService.modifyContactUs(contactUsObj).then(res=> {
\r
149 // $log.info('contactUsService: edit ContactUs successfully');
\r
150 // confirmBoxService.showInformation('You have saved the changes').then(isConfirmed => {});
\r
154 $log.error('contactUsService: editContactUs error:: ', err);
\r
155 confirmBoxService.showInformation('Edit Contact Us list failed: ' + err);
\r
156 // $scope.errMsg=err;
\r
158 //this.isLoadingTable = false;
\r
163 $scope.$watch('newContactUs.app.value', (newVal, oldVal) => {
\r
164 for(var i=0;i<$scope.contactUsAllAppList.length;i++){
\r
165 if($scope.contactUsAllAppList[i].value==newVal){
\r
166 $scope.newContactUs.app=angular.copy($scope.contactUsAllAppList[i]);;
\r
171 $scope.delContactUsFun = function(appObj){
\r
172 var confirmMsg = 'Are you sure you want to delete '+appObj.appName +' from the list?' + ' Press OK to delete.';
\r
173 confirmBoxService.confirm(confirmMsg).then(function (confirmed) {
\r
174 if (confirmed == true) {
\r
175 contactUsService.removeContactUs(appObj.appId).then(res=> {
\r
176 // $log.info('delContactUsFun: delete ContactUs successfully',res);
\r
178 $scope.contactUsList.length=0;
\r
179 $scope.getContactUsList();
\r
180 confirmBoxService.showInformation('Item has been deleted').then(isConfirmed => {});
\r
182 $log.error('contactUsService: addContactUs error:: ', err);
\r
183 confirmBoxService.showInformation('Deletion failed: ' + err);
\r
184 // $scope.errMsg=err;
\r
186 //this.isLoadingTable = false;
\r
195 ContactUsManageController.$inject = ['$scope','$log', 'message', '$q', '$http', 'conf','contactUsService','confirmBoxService'];
\r
196 angular.module('ecompApp').controller('ContactUsManageController', ContactUsManageController);
\r
200 function validateUrl(value){
\r
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-\uF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