Subversion Repositories SmartDukaan

Rev

Rev 13542 | Rev 13557 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 13542 Rev 13551
Line 1... Line 1...
1
angular.module('starter.controllers', [])
1
angular.module('starter.controllers', [])
2
 
2
 
3
.controller('DashCtrl', function($scope, $stateParams, Categories, CategoryProducts, localStorageService) {  
3
.controller('DashCtrl', function($scope, $stateParams, Categories, CategoryProducts, localStorageService, apihost) {  
4
  $scope.me = localStorageService.get('me');
4
  $scope.me = localStorageService.get('me');
-
 
5
  $scope.apihost = apihost;
-
 
6
  $scope.curpage = 1;
-
 
7
  $scope.maxpages = 10;
-
 
8
  $scope.products = [];
5
  $scope.categories = Categories.all({'me':$scope.me});
9
  $scope.categories = Categories.all({'me':$scope.me});
-
 
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 () {    
6
  $scope.products = CategoryProducts.all({'me':$scope.me});    
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
  },
7
  // $scope.$on('$stateChangeSuccess', function() {
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];
8
  //   console.log("state changed");
59
          console.log($scope.products);
-
 
60
        }*/
-
 
61
      },
-
 
62
      function( error ) {
-
 
63
        console.log( "Something went wrong!" );
-
 
64
      }
9
  // });  
65
    );
10
  $scope.hasProducts = function(categoryId,products) {
66
  $scope.hasProducts = function(categoryId,products) {
11
    for(index in products) {
67
    for(index in products) {
12
      // console.log(products[index].Product.category_id);
68
      // console.log(products[index].Product.category_id);
13
      // console.log(objects[index].Product.category_id)
69
      // console.log(objects[index].Product.category_id)
14
      if(products[index].Product.category_id == categoryId) // filter by name only
70
      if(products[index].Product.category_id == categoryId) // filter by name only
15
        return true;
71
        return true;
16
    }
72
    }
17
  }
73
  }
18
})
74
})
19
 
75
 
20
.controller('ChatsCtrl', function($scope, Products, localStorageService) {
76
.controller('ChatsCtrl', function($scope, Products, localStorageService, apihost) {
21
  $scope.me = localStorageService.get('me');
77
  $scope.me = localStorageService.get('me');
22
  console.log($scope.me);
78
  $scope.apihost = apihost;
-
 
79
  $scope.curpage = 1;
-
 
80
  $scope.maxpages = 10;
23
  $scope.products = Products.all({'me':$scope.me});  
81
  $scope.products = [];
24
  $scope.loadmore = function(){
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 ) {
25
    console,log('load more');
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;
26
  }
103
  },
-
 
104
  $scope.$on('$stateChangeSuccess', function() {
-
 
105
    $scope.loadmore();
-
 
106
  });   
27
})
107
})
28
 
108
 
29
.controller('ChatDetailCtrl', function($scope, $stateParams, Chats) {
109
.controller('CategoryCtrl', function($scope, $stateParams, Chats) {
30
  $scope.chat = Chats.get($stateParams.chatId);
110
  $scope.chat = Chats.get($stateParams.chatId);
31
})
111
})
32
 
112
 
33
.controller('FriendsCtrl', function($scope, Friends) {
113
.controller('FriendsCtrl', function($scope, Friends) {
34
  $scope.friends = Friends.all();
114
  $scope.friends = Friends.all();