Subversion Repositories SmartDukaan

Rev

Rev 13542 | Rev 13557 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
13542 anikendra 1
angular.module('starter.controllers', [])
2
 
13551 anikendra 3
.controller('DashCtrl', function($scope, $stateParams, Categories, CategoryProducts, localStorageService, apihost) {  
13542 anikendra 4
  $scope.me = localStorageService.get('me');
13551 anikendra 5
  $scope.apihost = apihost;
6
  $scope.curpage = 1;
7
  $scope.maxpages = 10;
8
  $scope.products = [];
13542 anikendra 9
  $scope.categories = Categories.all({'me':$scope.me});
13551 anikendra 10
  $scope.getCategoryName = function(id,cats){
11
    for(var i in cats){
12
      if(cats[i].Category.id == id){
13
        return cats[i].Category.name;
14
      }
15
    }  
16
  }
17
  /*
18
  $scope.loadmore = function () {    
19
    console.log('Fetch category products page '+$scope.curpage);
20
    CategoryProducts.all({'me':$scope.me, page: $scope.curpage++},  
21
      function( result ) {          
22
        // console.log(result);
23
        // $scope.category = result.categories;
24
        $scope.maxpages = result.maxresults;
25
        $scope.$broadcast('scroll.infiniteScrollComplete');
26
        for(var i in result.products){
27
          $scope.products[i] = result.products;
28
          // var catproducts = result.products[i];
29
          // console.log(catproducts.products);
30
          // $scope.products[i] = catproducts.products;
31
        }
32
        // $scope.chunkedData = $scope.chunk($scope.products, 2);
33
      },
34
      function( error ) {
35
        console.log( "Something went wrong!" );
36
      }
37
    );
38
  },
39
  */  
40
  $scope.moreDataCanBeLoaded = function() {
41
    if($scope.curpage <= $scope.maxpages)
42
      return true;
43
    return false;
44
  },
45
  $scope.$on('$stateChangeSuccess', function() {
46
    // $scope.loadmore();
47
  });
48
  // var catproducts = CategoryProducts.all({'me':$scope.me, page: $scope.curpage++});    
49
  // $scope.products = catproducts.products;
50
  CategoryProducts.all({'me':$scope.me, page: $scope.curpage++},  
51
      function( result ) {          
52
        console.log(result);
53
        $scope.products = result.products;
54
        $scope.maxpages = result.maxresults;
55
        $scope.$broadcast('scroll.infiniteScrollComplete');
56
        /*for(var i in result.products){
57
          console.log(result.products[i].products);
58
          $scope.products[i] = result.products[i];
59
          console.log($scope.products);
60
        }*/
61
      },
62
      function( error ) {
63
        console.log( "Something went wrong!" );
64
      }
65
    );
13542 anikendra 66
  $scope.hasProducts = function(categoryId,products) {
67
    for(index in products) {
68
      // console.log(products[index].Product.category_id);
69
      // console.log(objects[index].Product.category_id)
70
      if(products[index].Product.category_id == categoryId) // filter by name only
71
        return true;
72
    }
73
  }
74
})
75
 
13551 anikendra 76
.controller('ChatsCtrl', function($scope, Products, localStorageService, apihost) {
13542 anikendra 77
  $scope.me = localStorageService.get('me');
13551 anikendra 78
  $scope.apihost = apihost;
79
  $scope.curpage = 1;
80
  $scope.maxpages = 10;
81
  $scope.products = [];
82
  $scope.loadmore = function () {    
83
    console.log('Fetch deal products page '+$scope.curpage);
84
    Products.all({'me':$scope.me, page: $scope.curpage++},  
85
      function( result ) {          
86
        $scope.category = result.category;
87
        $scope.maxpages = result.maxresults;
88
        $scope.$broadcast('scroll.infiniteScrollComplete');                               
89
        for(var i in result.products){
90
          $scope.products.push(result.products[i]);          
91
        }
92
        $scope.chunkedData = $scope.chunk($scope.products, 2);
93
      },
94
      function( error ) {
95
        console.log( "Something went wrong!" );
96
      }
97
    );
98
  },  
99
  $scope.moreDataCanBeLoaded = function() {
100
    if($scope.curpage <= $scope.maxpages)
101
      return true;
102
    return false;
103
  },
104
  $scope.$on('$stateChangeSuccess', function() {
105
    $scope.loadmore();
106
  });   
13542 anikendra 107
})
108
 
13551 anikendra 109
.controller('CategoryCtrl', function($scope, $stateParams, Chats) {
13542 anikendra 110
  $scope.chat = Chats.get($stateParams.chatId);
111
})
112
 
113
.controller('FriendsCtrl', function($scope, Friends) {
114
  $scope.friends = Friends.all();
115
})
116
 
117
.controller('FriendDetailCtrl', function($scope, $stateParams, Friends) {
118
  $scope.friend = Friends.get($stateParams.friendId);
119
})
120
 
121
.controller('AccountCtrl', function($scope) {
122
  $scope.settings = {
123
    enableFriends: true
124
  };
125
})
126
.controller('LoginCtrl', function($scope,$location,localStorageService) {
127
  $scope.me = $location.search().user_id;
128
  if($scope.me){
129
    console.log($scope.me);
130
    localStorageService.set('me',$scope.me); 
131
    $location.path("/tab/chats");    
132
  }  
133
});