2  * ============LICENSE_START==========================================
 
   4  * ===================================================================
 
   5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 
   6  * ===================================================================
 
   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
 
  13  *             http://www.apache.org/licenses/LICENSE-2.0
 
  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.
 
  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
 
  26  *             https://creativecommons.org/licenses/by/4.0/
 
  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.
 
  34  * ============LICENSE_END============================================
 
  36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
 
  41     class ContactUsManageController {
 
  42         constructor($scope,$log, message, $q, $http, conf,contactUsService,confirmBoxService) {
 
  43                 $scope.contactUsList=[];
 
  44                 $scope.contactUsAllAppList=[];
 
  46                 $scope.newContactUs ={
 
  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]);
 
  64                         contactUsService.getListOfApp().then(res=> {
 
  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);          
 
  72                         $scope.contactUsAllAppList.length=0;
 
  73                         for (var i = 1; i <= res1.length; i++) {
 
  74                             if (!res1[i - 1].restrictedApp) {
 
  76                                 for(var j =0; j<$scope.contactUsList.length;j++){
 
  77                                         if(res1[i - 1].title==$scope.contactUsList[j].appName)
 
  80                                 // not allowed to add(duplicate) another entry if the app is already available in the table
 
  82                                         if(res1[i - 1].title){
 
  83                                                 $scope.contactUsAllAppList.push({
 
  85                                             title: res1[i - 1].title,
 
  86                                             value: res1[i - 1].index
 
  89                                         realAppIndex = realAppIndex + 1;
 
  92                                 // $log.debug('contactUsService:getAvailableApps:: Restricted/URL only App will not be used = ' + res1[i - 1].title);
 
  96                         $log.error('contactUsService:error:: ', err);
 
 100                         //this.isLoadingTable = false;
 
 105                 $scope.getContactUsList();
 
 107                 $scope.closeDialog = function(){
 
 108                         $scope.closeThisDialog( $scope.widgetData);
 
 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 => {
 
 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;});
 
 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();
 
 131                                 /*      confirmBoxService.showInformation('You have added a new Contact Us item').then(isConfirmed => { });*/
 
 137                                 $scope.newContactUs ={
 
 146                     $log.error('contactUsService: addContactUs error:: ', err);
 
 147                    // $scope.errMsg=err;
 
 148                     confirmBoxService.showInformation('Add Contact Us list failed: ' + err);
 
 151                     //this.isLoadingTable = false;
 
 155                 $scope.editContactUsFun = function(contactObj){
 
 156                         // $log.info('contactUsService: edit ContactUs save successfully', contactObj);                         
 
 158                                 appId:contactObj.appId,
 
 159                                 appName:contactObj.appName,
 
 160                                 description:contactObj.description,
 
 161                                 contactName:contactObj.contactName,
 
 162                                 contactEmail:contactObj.contactEmail,
 
 166                         contactUsService.modifyContactUs(contactUsObj).then(res=> {
 
 167                                 // $log.info('contactUsService: edit ContactUs successfully');
 
 168                                 //      confirmBoxService.showInformation('You have saved the changes').then(isConfirmed => {});
 
 172                     $log.error('contactUsService: editContactUs error:: ', err);
 
 173                     confirmBoxService.showInformation('Edit Contact Us list failed: ' + err);
 
 174                    // $scope.errMsg=err;
 
 176                     //this.isLoadingTable = false;
 
 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]);;
 
 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);
 
 196                                         $scope.contactUsList.length=0;
 
 197                                         $scope.getContactUsList();
 
 198                                         confirmBoxService.showInformation('Item has been deleted').then(isConfirmed => {});
 
 200                             $log.error('contactUsService: addContactUs error:: ', err);
 
 201                             confirmBoxService.showInformation('Deletion failed: ' + err);
 
 202                            // $scope.errMsg=err;
 
 204                             //this.isLoadingTable = false;
 
 213     ContactUsManageController.$inject = ['$scope','$log',  'message', '$q', '$http', 'conf','contactUsService','confirmBoxService'];
 
 214     angular.module('ecompApp').controller('ContactUsManageController', ContactUsManageController);
 
 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\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);