Creazione organizza
[YouAndWeb_TwoToc] / client / app / come_funziona / come_funziona.controller.js
diff --git a/client/app/come_funziona/come_funziona.controller.js b/client/app/come_funziona/come_funziona.controller.js
new file mode 100755 (executable)
index 0000000..93f06b2
--- /dev/null
@@ -0,0 +1,82 @@
+'use strict';
+
+angular.module('dashboardApp')
+  .controller('Come_FunzionaCtrl', function($scope, $http, datepickerPopupConfig, $stateParams) {
+
+  var baseLimit = 7;
+  $scope.limit = baseLimit;
+  var d = new Date();
+  d.setHours(0,0,0,0);
+  $scope.dataInizio = new Date(d);
+
+  $scope.posters = [];
+  var route;
+  $scope.loadCount = 0;
+  $scope.loadShows = function() {
+    route = '/api/shows?limit=' + $scope.limit;
+    if ($scope.dataInizio) {
+      route += '&date=' + $scope.dataInizio;
+    }
+    if ($scope.category) {
+      route += '&category=' + $scope.category;
+    }
+    if ($stateParams.lat && $stateParams.lng) {
+      route += '&lat=' + $stateParams.lat + '&lng=' + $stateParams.lng;
+    }
+    if ($scope.fulltext) {
+      route += '&fulltext=' + $scope.fulltext;
+    }
+       $http.get(route).then(function(response) {
+         $scope.posters = response.data;
+         $scope.limit += $scope.limit;
+      if ($scope.loadCount % 2 === 0) {
+        $scope.limit++;
+      }
+      $scope.loadCount++;
+       });
+  };
+  $scope.loadShows();
+
+
+  var posterCount = 0;
+  $scope.pCount = function(index) {
+    posterCount = index % 10 === 0 ? 0 : posterCount + 1;
+    return posterCount === 0 || posterCount === 6;
+  };
+
+  $scope.datepickers = {
+    dataInizio: false,
+    dataFine: false
+  };
+
+  $scope.open = function($event, which, whichnot) {
+    $event.preventDefault();
+    $event.stopPropagation();
+
+    $scope.datepickers[which]= true;
+    $scope.datepickers[whichnot]= false;
+  };
+
+  $scope.dateOptions = {
+    'year-format': 'yy',
+    'starting-day': 1,
+    'show-weeks': false
+  };
+
+  datepickerPopupConfig.showButtonBar = false;
+  datepickerPopupConfig.appendToBody = false;
+
+  $scope.minDate = new Date();
+  $scope.minDateFine = new Date();
+
+  $scope.searchShows = function() {
+    $scope.limit = baseLimit;
+    $scope.loadCount = 0;
+       $scope.loadShows();
+  };
+
+  // load categories
+  $http.get('/api/categories?active=true').then(function(response) {
+    $scope.categories = response.data;
+  });
+});