[PORTAL-7] Rebase
[portal.git] / ecomp-portal-FE-common / client / app / views / support / contact-us / contact-us-manage / contact-us-manage.controller.js
diff --git a/ecomp-portal-FE-common/client/app/views/support/contact-us/contact-us-manage/contact-us-manage.controller.js b/ecomp-portal-FE-common/client/app/views/support/contact-us/contact-us-manage/contact-us-manage.controller.js
new file mode 100644 (file)
index 0000000..8413382
--- /dev/null
@@ -0,0 +1,202 @@
+/*-\r
+ * ================================================================================\r
+ * ECOMP Portal\r
+ * ================================================================================\r
+ * Copyright (C) 2017 AT&T Intellectual Property\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ================================================================================\r
+ */\r
+'use strict';\r
+\r
+(function () {\r
+    class ContactUsManageController {\r
+        constructor($scope,$log, message, $q, $http, conf,contactUsService,confirmBoxService) {\r
+               $scope.contactUsList=[];\r
+               $scope.contactUsAllAppList=[];\r
+               $scope.errMsg='';\r
+               $scope.newContactUs ={\r
+                               app:'',\r
+                               name:'',\r
+                               email:'',\r
+                               url:'',\r
+                               desc:''                         \r
+               };\r
+               /*Get the existing contact us first, then based on the existing, filter from all apps*/\r
+               $scope.getContactUsList = function(){\r
+                       contactUsService.getContactUs().then(res=> {\r
+                       // $log.info('getting getContactUs',res.response);\r
+                       if(res!=null && res.response!=null){\r
+                               for(var i=0; i<res.response.length;i++){\r
+                                       if(res.response[i].appId!=1)\r
+                                               $scope.contactUsList.push(res.response[i]);\r
+                               }\r
+                       }\r
+                       /*get all the apps*/\r
+                       contactUsService.getListOfApp().then(res=> {\r
+                       var tableData=[];\r
+                       $scope.contactUsAllAppListTemp=[];\r
+                       // $log.info('contactUsService::getListOfApp: getting res');\r
+                       var result = (typeof(res.data) != "undefined" && res.data!=null)?res.data:null;\r
+                       // $log.info('contactUsService::getListOfApp: result',result);          \r
+                       var res1 = result;\r
+                        var realAppIndex = 0;\r
+                        $scope.contactUsAllAppList.length=0;\r
+                        for (var i = 1; i <= res1.length; i++) {\r
+                            if (!res1[i - 1].restrictedApp) {\r
+                               var okToAdd = true;\r
+                               for(var j =0; j<$scope.contactUsList.length;j++){\r
+                                       if(res1[i - 1].title==$scope.contactUsList[j].appName)\r
+                                               okToAdd=false;\r
+                               }\r
+                               // not allowed to add(duplicate) another entry if the app is already available in the table\r
+                               if(okToAdd){\r
+                                       if(res1[i - 1].title){\r
+                                               $scope.contactUsAllAppList.push({\r
+                                            index: realAppIndex,\r
+                                            title: res1[i - 1].title,\r
+                                            value: res1[i - 1].index\r
+                                        });\r
+                                       }       \r
+                                       realAppIndex = realAppIndex + 1;\r
+                               }         \r
+                            } else {\r
+                                // $log.debug('contactUsService:getAvailableApps:: Restricted/URL only App will not be used = ' + res1[i - 1].title);\r
+                            }\r
+                        }       \r
+                    }).catch(err=> {\r
+                        $log.error('contactUsService:error:: ', err);\r
+                        \r
+                       \r
+                    }).finally(() => {\r
+                        //this.isLoadingTable = false;\r
+                    });\r
+               });\r
+               }\r
+               \r
+               $scope.getContactUsList();\r
+               \r
+               $scope.closeDialog = function(){\r
+                       $scope.closeThisDialog( $scope.widgetData);\r
+               }\r
+               \r
+               /*Add new Contact Us*/\r
+               $scope.newContactUsFun = function(){ \r
+                       if($scope.newContactUs.app.title==null || $scope.newContactUs.app.title=='' ){\r
+                               confirmBoxService.showInformation('Please select an App to add').then(isConfirmed => {\r
+                                       return;\r
+                               });     \r
+                       }\r
+                                               \r
+                       if($scope.newContactUs.url !=null && $scope.newContactUs.url != '' && !validateUrl($scope.newContactUs.url)){\r
+                               var warningMsg = "Please enter a valid URL";\r
+                               confirmBoxService.showInformation(warningMsg).then(isConfirmed => {return;});\r
+                               return;\r
+                       }\r
+                       \r
+                       contactUsService.addContactUs($scope.newContactUs).then(res=> {\r
+                               // $log.info('contactUsService: add ContactUs successfully');\r
+                               $scope.contactUsList.length=0;\r
+                               // $log.info('contactUsService: refreshing the Contact US table');\r
+                               $scope.getContactUsList();\r
+                               $scope.errMsg='';\r
+                               /*      confirmBoxService.showInformation('You have added a new Contact Us item').then(isConfirmed => { });*/\r
+                               var defaultSel={\r
+                                               index: 0,\r
+                            title: '',\r
+                            value: ''\r
+                               }\r
+                               $scope.newContactUs ={\r
+                                       app:defaultSel,                         \r
+                                       name:'',\r
+                                       email:'',\r
+                                       url:'',\r
+                                       desc:''                         \r
+                       };\r
+\r
+                }).catch(err=> {\r
+                    $log.error('contactUsService: addContactUs error:: ', err);\r
+                   // $scope.errMsg=err;\r
+                    confirmBoxService.showInformation('Add Contact Us list failed: ' + err);\r
+                   \r
+                }).finally(() => {\r
+                    //this.isLoadingTable = false;\r
+                });\r
+               }\r
+               /* Edit Contact Us*/\r
+               $scope.editContactUsFun = function(contactObj){\r
+                       // $log.info('contactUsService: edit ContactUs save successfully', contactObj);                         \r
+                       var contactUsObj={\r
+                               appId:contactObj.appId,\r
+                               appName:contactObj.appName,\r
+                               description:contactObj.description,\r
+                               contactName:contactObj.contactName,\r
+                               contactEmail:contactObj.contactEmail,\r
+                               url:contactObj.url,                     \r
+                };\r
+                       \r
+                       contactUsService.modifyContactUs(contactUsObj).then(res=> {\r
+                               // $log.info('contactUsService: edit ContactUs successfully');\r
+                               //      confirmBoxService.showInformation('You have saved the changes').then(isConfirmed => {});\r
+                               $scope.errMsg='';\r
+                               \r
+                }).catch(err=> {\r
+                    $log.error('contactUsService: editContactUs error:: ', err);\r
+                    confirmBoxService.showInformation('Edit Contact Us list failed: ' + err);\r
+                   // $scope.errMsg=err;\r
+                }).finally(() => {\r
+                    //this.isLoadingTable = false;\r
+                });\r
+                       \r
+               }\r
+               \r
+               $scope.$watch('newContactUs.app.value', (newVal, oldVal) => {\r
+                       for(var i=0;i<$scope.contactUsAllAppList.length;i++){\r
+                       if($scope.contactUsAllAppList[i].value==newVal){\r
+                       $scope.newContactUs.app=angular.copy($scope.contactUsAllAppList[i]);;\r
+                       }\r
+                       }\r
+                       });\r
+               /*del Contact Us*/\r
+               $scope.delContactUsFun = function(appObj){\r
+                       var confirmMsg = 'Are you sure you want to delete '+appObj.appName +' from the list?' + ' Press OK to delete.';\r
+                       confirmBoxService.confirm(confirmMsg).then(function (confirmed) {\r
+                    if (confirmed == true) {                           \r
+                       contactUsService.removeContactUs(appObj.appId).then(res=> {   \r
+                               // $log.info('delContactUsFun: delete ContactUs successfully',res);\r
+                                       $scope.errMsg='';\r
+                                       $scope.contactUsList.length=0;\r
+                                       $scope.getContactUsList();\r
+                                       confirmBoxService.showInformation('Item has been deleted').then(isConfirmed => {});\r
+                        }).catch(err=> {\r
+                            $log.error('contactUsService: addContactUs error:: ', err);\r
+                            confirmBoxService.showInformation('Deletion failed: ' + err);\r
+                           // $scope.errMsg=err;\r
+                        }).finally(() => {\r
+                            //this.isLoadingTable = false;\r
+                        });\r
+                    }\r
+                });\r
+                       \r
+               }       \r
+               \r
+        }        \r
+    }\r
+    ContactUsManageController.$inject = ['$scope','$log',  'message', '$q', '$http', 'conf','contactUsService','confirmBoxService'];\r
+    angular.module('ecompApp').controller('ContactUsManageController', ContactUsManageController);\r
+\r
\r
+})();\r
+function validateUrl(value){\r
+    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\u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