[PORTAL-7] Rebase
[portal.git] / ecomp-portal-FE-common / client / app / views / support / contact-us / contact-us.controller.js
1 /*-\r
2  * ================================================================================\r
3  * ECOMP Portal\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
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \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
19  */\r
20 'use strict';\r
21 \r
22 (function () {  \r
23                 \r
24     class ContactUsCtrl {\r
25         constructor($log, contactUsService, applicationsService, $modal, ngDialog, $state,$anchorScroll,$location) {  \r
26                 \r
27                 contactUsService.getContactUSPortalDetails().then(res => {\r
28                         // $log.info('ContactUsCtrl:: contactUsService getContactUSPortalDetails res',res);\r
29                 // $log.info('getting res',res);\r
30                 var result = (typeof(res.response) != "undefined" && res.response!=null)?res.response:null;\r
31                 //      $log.info('result',result);\r
32                 //      $log.info('done');\r
33                 var source = JSON.parse(result);\r
34                 //      $log.info(source); \r
35                 this.ush_TicketInfoUrl = source.ush_ticket_url; \r
36                 this.portalInfo_Address = source.feedback_email_address; \r
37                 this.feedback_Url = source.portal_info_url;                     \r
38                 }).catch(err=> {\r
39                         $log.error('ContactUsCtrl:error:: ', err);\r
40             }).finally(() => {\r
41            });\r
42                 \r
43                 let init = () => {\r
44                 // $log.info('ecomp app::contact-us-controller::initializing...');\r
45                 this.appTable=[];\r
46                 this.functionalTableData=[];\r
47             };\r
48             init();     \r
49             \r
50             let updateContactUsTable = () => {\r
51                 contactUsService.getAppsAndContacts().then(res=> {\r
52                                 // $log.info('ContactUsCtrl:: contactUsService getAppsAndContacts res',res);\r
53                         var tableData=[];\r
54                         // $log.info('getting res',res);\r
55                         var result = (typeof(res.response) != "undefined" && res.response!=null)?res.response:null;\r
56                         // $log.info('result',result);\r
57                         // $log.info('done');\r
58                         var source = result;\r
59                         // $log.info(source);\r
60                         // Drop Portal app, empty name entries\r
61                         for(var i=0;i<source.length; i++) {\r
62                                 var dataArr = source[i];\r
63                                 if ( !dataArr.appName  || dataArr.appId == 1) {\r
64                                         continue;\r
65                                 }\r
66                         var dataTemp={\r
67                                 app_name: dataArr.appName,\r
68                                 contact_name: dataArr.contactName,\r
69                                 contact_email: dataArr.contactEmail,\r
70                                 desc: dataArr.description,\r
71                                 url_Info: dataArr.url,\r
72                                 app_Id: dataArr.appId,\r
73                         }\r
74                         tableData.push(dataTemp);\r
75                         }               \r
76                         this.appTable=tableData;\r
77                  }).catch(err=> {\r
78                                  $log.error('ContactUsCtrl.updateContactUsTable:error:: ', err);\r
79                          })\r
80             };\r
81             \r
82             contactUsService.getAppCategoryFunctions().then(res=> {\r
83                         // $log.info('ContactUsCtrl:: contactUsService getAppCategoryFunctionsthen res',res);\r
84                 var tablefunctionalData=[];\r
85                 // $log.info('getting res',res);\r
86                 var result = (typeof(res.response) != "undefined" && res.response!=null)?res.response:null;\r
87                 // $log.info('result',result);\r
88                 // $log.info('done');\r
89                 var source = result;\r
90                 // $log.info(source);                   \r
91                 for(var i=0;i<source.length; i++) {\r
92                         var datafunctionalArr = source[i];\r
93                         var datafuntionalTemp={\r
94                                 category: datafunctionalArr.category,\r
95                                 app_Name: datafunctionalArr.application,\r
96                                 functions: datafunctionalArr.functions,\r
97                                 app_Id: datafunctionalArr.appId,\r
98                         }\r
99                         tablefunctionalData.push(datafuntionalTemp);\r
100                 }               \r
101                 this.functionalTableData=tablefunctionalData;\r
102              }).catch(err=> {\r
103                          $log.error('ContactUsCtrl:error:: ', err);\r
104                  })\r
105             \r
106             updateContactUsTable();\r
107             this.editContactUsModalPopup = () => {\r
108                  // $log.debug('ContactUsCtrl::editContactUsModalPopup updating table data...');               \r
109                  var modalInstance = ngDialog.open({\r
110                      templateUrl: 'app/views/support/contact-us/contact-us-manage/contact-us-manage.html',\r
111                      controller: 'ContactUsManageController',\r
112                      resolve: {\r
113                          message: function message() {\r
114                              var message = {\r
115                                  type: 'Contact',\r
116                              };\r
117                              return message;\r
118                          }\r
119                      }\r
120                  }).closePromise.then(needUpdate => {                    \r
121                          updateContactUsTable();\r
122                      });       \r
123              };\r
124              \r
125              this.goToSection = (id) => {\r
126                 \r
127                  var targetDiv = document.getElementById(id);  \r
128                  \r
129                  var offSetHeight = 0;\r
130                  for(var i=0;i<this.appTable.length;i++){  \r
131                          if(this.appTable[i].app_Id==id)\r
132                                  break;\r
133                          if(this.appTable[i].showFlag==true){\r
134                                  offSetHeight+=document.getElementById('collapse'+i).clientHeight;                              \r
135                          }\r
136                  }\r
137                  console.log(offSetHeight);\r
138                  this.appTable.forEach(d => d.showFlag = false);\r
139                 // let index = this.appTable.findIndex(a => a.app_Id == id);\r
140                  var index =-1;\r
141                  for(var i=0; i<this.appTable.length;i++){\r
142                          if(this.appTable[i].app_Id==id){\r
143                                  index = i;\r
144                                  break;\r
145                          }\r
146                  }\r
147                  console.log(index);\r
148                  if (index > -1) {\r
149                          // setting the showFlag to true based on index comparing with the app_Id \r
150                          this.appTable[index].showFlag = true;\r
151                          $location.hash('appId'+index);\r
152                       $anchorScroll();\r
153                 /*       $('#contentId').animate({\r
154                             scrollTop: targetDiv.offsetTop-offSetHeight\r
155                         }, 'fast');*/\r
156                  }                               \r
157                  \r
158              };\r
159              \r
160              // Take the user to the application on the get access page.\r
161              this.goGetAccess = (appName) => {\r
162                  // $log.debug('ContactUsCtrl::goGetAccess received name ' + appName);\r
163                  applicationsService.goGetAccessAppName = appName;\r
164                  $state.go('root.getAccess');\r
165              };\r
166              \r
167         }\r
168     }\r
169     ContactUsCtrl.$inject = ['$log','contactUsService', 'applicationsService', '$modal', 'ngDialog', '$state','$anchorScroll','$location'];\r
170     angular.module('ecompApp').controller('ContactUsCtrl', ContactUsCtrl);\r
171 })();\r