Blame view

app/partials/ContactView/ContactView.controller.js 4.73 KB
4bb02bb84   Rishav   new integration w...
1
2
3
4
  'use strict';
  
   //Load controller
    angular.module('acufuel')
1b71872b2   Kuldeep Arora   email and code be...
5
    .controller('ContactViewController', ['$scope', '$uibModal', 'ContactViewService', 'ViewCompanyService', 'ViewcontactService', 'NgTableParams', function($scope, $uibModal, ContactViewService, ViewCompanyService, ViewcontactService, NgTableParams) {
2c476c756   Anchit Jindal   added new code
6
          
e196b9b74   Anchit Jindal   new changes added
7
         /* $(document).ready(function() {
9aae3d136   Mr. Hot Foods   show loaders and ...
8
            $scope.showLoader = true;
e196b9b74   Anchit Jindal   new changes added
9
             // $('#contacts').DataTable();
9aae3d136   Mr. Hot Foods   show loaders and ...
10
              $scope.showLoader = false;
e196b9b74   Anchit Jindal   new changes added
11
          });*/
2c476c756   Anchit Jindal   added new code
12
          
e196b9b74   Anchit Jindal   new changes added
13
         /* ContactViewService.getContacts().then(function(result) {
9aae3d136   Mr. Hot Foods   show loaders and ...
14
            $scope.showLoader = true;
1b71872b2   Kuldeep Arora   email and code be...
15
            $scope.contactList = result;
9aae3d136   Mr. Hot Foods   show loaders and ...
16
            $scope.showLoader = false;
e196b9b74   Anchit Jindal   new changes added
17
          })*/
7e481a068   Rishav   implement toogle ...
18

39243c6a2   Jaideep Singh   api integraions
19
20
21
22
23
24
          $scope.search = "";
          $scope.minlength = 2;
           
  
          $scope.searchString= function(value){
           ContactViewService.getSearchResults(value).then(function(result) {
1b71872b2   Kuldeep Arora   email and code be...
25
            $scope.contactList = result;
39243c6a2   Jaideep Singh   api integraions
26
            console.log("result", result);
1b71872b2   Kuldeep Arora   email and code be...
27
              for (var i = 0; i < $scope.contactList.length; i++) {
39243c6a2   Jaideep Singh   api integraions
28
29
30
31
32
33
34
35
36
37
38
39
40
41
                  if ($scope.contactList[i].owner != null) {
                    if ($scope.contactList[i].owner.companyName != null || $scope.contactList[i].owner.companyName != undefined) {
                      $scope.contactList[i].owner = $scope.contactList[i].owner.companyName;
                    }
                  }
                }
                $scope.displayContactList = new NgTableParams({
                    page: 1,
                    count: 10,
                  }, {
                    data: $scope.contactList
                  });
          })
          }
7152ff131   Rishav   model handle
42
43
44
          $scope.reset = function(){
            $("input").val("");
          }
49676befb   Anchit Jindal   new changes applied
45
46
          
          $scope.data = {};
1b71872b2   Kuldeep Arora   email and code be...
47
          getAllContacts();
7152ff131   Rishav   model handle
48

7e481a068   Rishav   implement toogle ...
49
          $scope.changePriceEmail = function(id, index){
9aae3d136   Mr. Hot Foods   show loaders and ...
50
            
d24318592   Rishav   changes and new i...
51
            event.stopPropagation();
da24c95c8   Rishav Singla   confirmation mess...
52
53
54
55
56
57
58
59
60
61
62
63
            var contactId = id;
            var statusData = "status=" + $scope.contactList[index].priceEmail;
            ViewcontactService.changePriceEmail(contactId, statusData).then(function(result) {
                if(result.success){
                    $('#toogleMail').css('display', 'block');
                    if($scope.contactList[index].priceEmail == true){
                      $scope.messageText = 'You have enabled price distribution for this contact';
                    }else{
                      $scope.messageText = 'You have disabled price distribution for this contact';
                    }
                }
            })
9aae3d136   Mr. Hot Foods   show loaders and ...
64

da24c95c8   Rishav Singla   confirmation mess...
65
66
67
68
          }
  
          $scope.cancelToogle = function(){
            $('#toogleMail').css('display', 'none');
7e481a068   Rishav   implement toogle ...
69
          }
2c476c756   Anchit Jindal   added new code
70
          
49676befb   Anchit Jindal   new changes applied
71
72
          
          function getAllContacts(){
9aae3d136   Mr. Hot Foods   show loaders and ...
73
            $scope.showLoader = true;
da24c95c8   Rishav Singla   confirmation mess...
74
75
76
77
            ContactViewService.getContacts().then(function(result) {
              console.log('log', result);
              $scope.contactList = result;
              for (var i = 0; i < $scope.contactList.length; i++) {
1b71872b2   Kuldeep Arora   email and code be...
78
79
80
81
82
                if ($scope.contactList[i].owner != null) {
                  if ($scope.contactList[i].owner.companyName != null || $scope.contactList[i].owner.companyName != undefined) {
                    $scope.contactList[i].owner = $scope.contactList[i].owner.companyName;
                  }
                }
da24c95c8   Rishav Singla   confirmation mess...
83
84
85
86
87
88
89
90
              }
              $scope.displayContactList = new NgTableParams({
                page: 1,
                count: 10,
              }, {
                data: $scope.contactList
              });
            })
9aae3d136   Mr. Hot Foods   show loaders and ...
91
            $scope.showLoader = false;
1b71872b2   Kuldeep Arora   email and code be...
92
        }
49676befb   Anchit Jindal   new changes applied
93
94
          
          
39243c6a2   Jaideep Singh   api integraions
95
          ContactViewService.getCompanies().then(function(result) {
9aae3d136   Mr. Hot Foods   show loaders and ...
96
            $scope.showLoader = true;
1b71872b2   Kuldeep Arora   email and code be...
97
            $scope.companies = result;
e196b9b74   Anchit Jindal   new changes added
98
            $scope.showLoader = false;
2c476c756   Anchit Jindal   added new code
99
            
39243c6a2   Jaideep Singh   api integraions
100
          })
2c476c756   Anchit Jindal   added new code
101
102
103
104
          
          $scope.contactData = {};
          $scope.contactData.contactList = [];
          $scope.addContact = function(){
2c476c756   Anchit Jindal   added new code
105
106
107
108
109
110
111
112
113
114
115
116
117
118
            $scope.contactData.contactList.push($scope.data);
            ViewCompanyService.addContact($scope.contactData).then(function(result) {
              if(result.success){
                toastr.success(''+result.success+'', {
                    closeButton: true
                  })
                  $('#contact-modal-3').modal('hide');
              }else{
                toastr.error(''+result.statusText+'', {
                    closeButton: true
                  })
              }
            })
          }
52fea957f   Anchit Jindal   csv and search co...
119
          
1b71872b2   Kuldeep Arora   email and code be...
120
121
122
123
124
125
126
127
128
129
130
131
132
133
      $scope.exportContacts = function() {
        $scope.showLoader = true;
          var fileName = "contacts.csv";
          var a = document.createElement("a");
          document.body.appendChild(a);
          ContactViewService.exportContacts().then(function(result) {
                var file = new Blob([result], {type: 'application/csv'});
                var fileURL = URL.createObjectURL(file);
                a.href = fileURL;
                a.download = fileName;
                a.click();
                $scope.showLoader = false;
           })
        }
4bb02bb84   Rishav   new integration w...
134
135
  
      }]);