Subversion Repositories SmartDukaan

Rev

Rev 15747 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
15747 anikendra 1
angular.module('starter.controllers', [])
2
 
3
.controller('AppCtrl', function($scope, $ionicModal, $timeout) {
4
 
5
  // With the new view caching in Ionic, Controllers are only called
6
  // when they are recreated or on app start, instead of every page change.
7
  // To listen for when this page is active (for example, to refresh data),
8
  // listen for the $ionicView.enter event:
9
  //$scope.$on('$ionicView.enter', function(e) {
10
  //});
11
 
12
  // Form data for the login modal
13
  $scope.loginData = {};
14
 
15
  // Create the login modal that we will use later
16
  $ionicModal.fromTemplateUrl('templates/login.html', {
17
    scope: $scope
18
  }).then(function(modal) {
19
    $scope.modal = modal;
20
  });
21
 
22
  // Triggered in the login modal to close it
23
  $scope.closeLogin = function() {
24
    $scope.modal.hide();
25
  };
26
 
27
  // Open the login modal
28
  $scope.login = function() {
29
    $scope.modal.show();
30
  };
31
 
32
  // Perform the login action when the user submits the login form
33
  $scope.doLogin = function() {
34
    console.log('Doing login', $scope.loginData);
35
 
36
    // Simulate a login delay. Remove this and replace with your login
37
    // code if using a login system
38
    $timeout(function() {
39
      $scope.closeLogin();
40
    }, 1000);
41
  };
42
})
43
 
44
.controller('EventsCtrl', function($scope,$ionicLoading,$http,apihost,$window) {
45
  $scope.me = 1;
46
  $scope.getEvents = function () {
47
    console.log("Fetch events");
48
    $ionicLoading.show({
49
      template: 'Loading...'
50
    }); 
51
    if($scope.me) {     
52
      $http.get(apihost+"/list_events").
53
        success(function(data, status, headers, config) {
54
          $ionicLoading.hide();
55
          console.log(data);
56
          $scope.events = data;
57
        }).
58
        error(function(data, status, headers, config) {
59
          $ionicLoading.hide();
60
          console.log(data);                      
61
        });
62
    }
63
  };   
64
  $scope.getEvents();
65
  $scope.toTimestamp = function(date) {
66
    return $window.jQuery.timeago(date);
67
  };
68
})
69
.controller('UsersCtrl', function($scope,$ionicLoading,$http,apihost) {
70
  $scope.me = 1;
71
  $scope.getUsers = function () {
72
    console.log("Fetch all users");
73
    $ionicLoading.show({
74
      template: 'Loading...'
75
    }); 
76
    if($scope.me) {     
77
      $http.get(apihost+"/list_users").
78
        success(function(data, status, headers, config) {
79
          $ionicLoading.hide();
80
          console.log(data);
81
          $scope.users = data;
82
        }).
83
        error(function(data, status, headers, config) {
84
          $ionicLoading.hide();
85
          console.log(data);                      
86
        });
87
    }
88
  }; 
89
  $scope.getUsers();
90
})
91
 
92
.controller('UserCtrl', function($scope, $stateParams, $ionicLoading,$http,apihost,$window) {
93
  $scope.me = 1;
94
  $scope.getEvents = function (userId) {
95
    console.log("Fetch events for "+userId);    
96
    if($scope.me) {     
97
      $http.get(apihost+"/list_events/?user_id="+$stateParams.userId).
98
        success(function(data, status, headers, config) {
99
          $ionicLoading.hide();
100
          console.log(data);
101
          $scope.events = data;
102
        }).
103
        error(function(data, status, headers, config) {
104
          $ionicLoading.hide();
105
          console.log(data);                      
106
        });
107
    }
108
  }; 
109
  $scope.getUser = function () {
110
    console.log("Fetch user "+$stateParams.userId);
111
    $ionicLoading.show({
112
      template: 'Loading...'
113
    }); 
114
    if($scope.me) {     
115
      $http.get(apihost+"/list_users/?id="+$stateParams.userId).
116
        success(function(data, status, headers, config) {
117
          $ionicLoading.hide();
118
          console.log(data);
119
          $scope.user = data[0];
120
          $scope.events = $scope.getEvents($scope.user.id);
121
        }).
122
        error(function(data, status, headers, config) {
123
          // $ionicLoading.hide();
124
          console.log(data);                      
125
        });
126
    }
127
  };   
128
  $scope.getUser();
129
  $scope.toTimestamp = function(date) {
130
    // var dateSplitted = date.split('-'); // date must be in DD-MM-YYYY format
131
    // var formattedDate = dateSplitted[1]+'/'+dateSplitted[0]+'/'+dateSplitted[2];
132
    // return new Date(formattedDate).getTime();
133
    return $window.jQuery.timeago(date);
134
  };
15765 anikendra 135
  $scope.keyisnot = function(key){
136
    if(key!='profile_pic')return true;
137
    return false;
138
  }
15747 anikendra 139
});