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