console.log('hello console for main.js'); var stuff = ['initialstuff']; angular .module('caisse', []) .controller('CaisseCtrl', ['$scope', '$http', function ($scope, $http, stuff) { $scope.productsFromDB = [ {id: 1, name: "truc 1", price: 8, category: 1}, {id: 2, name: "truc 2", price: 2, category: 1}, {id: 3, name: "truc 3", price: 4, category: 2}, {id: 4, name: "truc 4", price: 1, category: 2}, ]; $scope.categories = []; $scope.recentSellings = []; $scope.pausedSelling = []; $scope.activeSelling = []; $scope.activeFestival = { name : "le festival", dateCreation: new Date(), commentaire : "" }; /** * get the sum of products prices * @param list * @returns {number} */ $scope.sumOfList = function (list) { let counter = 0; for (let i = 0; i < list.length; i++) { counter += list[i].price; } return counter; }; /** * sum of current selling list prices * @returns {number} * @constructor */ $scope.CurrentSellingTotal = function () { return $scope.sumOfList($scope.activeSelling); }; $scope.stuff = stuff; $scope.setActiveSelling = function (selling) { $scope.activeSelling = selling; }; $scope.pauseSelling = function (selling) { $scope.pausedSelling.push(selling); }; $scope.addProduct = function (product) { $scope.activeSelling.push(product); }; $scope.fetchProductsFromDB = function () { console.log('fetch products...'); $http.get('get-my-products').then((rep) => { console.log('ok', rep); $scope.categories = rep.data.categories; $scope.recentSellings = rep.data.history; }, (err) => { console.log(err); }); }; $scope.pauseSelling = function () { $scope.pausedSelling.push(angular.copy($scope.activeSelling)); $scope.activeSelling = []; }; $scope.setBackPausedSelling = function (sellingList, index) { $scope.activeSelling = angular.copy(sellingList); $scope.pausedSelling.splice(index, 1); }; $scope.sendForm = function () { let lesParams = { activeSelling : $scope.activeSelling, activeFestival: $scope.activeFestival }; $http({ method: 'POST', url : '/add-selling', data : lesParams // pass in data as strings }).then(function (rep) { console.log(rep); if (!rep.success) { // if not successful, bind errors to error variables $scope.errors = rep.errors; } else { // if successful, bind success message to message $scope.successMessage = rep.data.message; // changer le type de bout de phrase demandé $scope.formData["tykayn_portfoliobundle_cadexqphrasepart[type]"]["$viewValue"] = 'nouveauType'; } }, function (rep) { console.log('nope! ', rep.data); }) ; }; $scope.init = (function () { $scope.fetchProductsFromDB(); })(); }]);