caisse-bliss/assets/js/parts/main.js

106 lines
3.7 KiB
JavaScript
Raw Normal View History

2018-04-04 16:25:25 +02:00
console.log('hello console for main.js');
2018-04-05 14:21:32 +02:00
var stuff = ['initialstuff'];
angular
.module('caisse', [])
.controller('CaisseCtrl', ['$scope', '$http', function ($scope, $http, stuff) {
$scope.productsFromDB = []; // loaded products
$scope.categories = []; // product categories
$scope.commentaire = []; // comment about the client or the current selling
$scope.initLoadDone = false; // becames true after first init of product loading
2018-04-05 16:40:40 +02:00
$scope.recentSellings = [];
2018-04-05 14:21:32 +02:00
$scope.pausedSelling = [];
$scope.activeSelling = []; // list of products to sell
$scope.activeFestival = { // an event where selling take place
2018-04-05 16:40:40 +02:00
name : "le festival",
dateCreation: new Date(),
commentaire : ""
};
2018-04-05 17:01:36 +02:00
/**
* 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);
};
2018-04-05 14:21:32 +02:00
$scope.stuff = stuff;
$scope.setActiveSelling = function (selling) {
$scope.activeSelling = selling;
};
$scope.pauseSelling = function (selling) {
$scope.pausedSelling.push(selling);
};
2018-04-05 16:40:40 +02:00
$scope.addProduct = function (product) {
$scope.activeSelling.push(product);
2018-04-05 14:21:32 +02:00
};
$scope.fetchProductsFromDB = function () {
console.log('fetch products...');
2018-04-05 16:40:40 +02:00
$http.get('get-my-products').then((rep) => {
2018-04-05 14:21:32 +02:00
2018-04-05 16:40:40 +02:00
console.log('ok', rep);
$scope.categories = rep.data.categories;
$scope.recentSellings = rep.data.history;
2018-04-06 15:43:14 +02:00
$scope.initLoadDone = true;
2018-04-05 14:21:32 +02:00
}, (err) => {
console.log(err);
2018-04-06 15:43:14 +02:00
$scope.initLoadDone = true;
2018-04-05 14:21:32 +02:00
});
};
2018-04-05 17:01:36 +02:00
$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);
2018-04-05 14:21:32 +02:00
};
$scope.clearCurrentSelling = function () {
$scope.commentaire = "";
$scope.activeSelling = [];
};
2018-04-05 14:21:32 +02:00
$scope.sendForm = function () {
2018-04-05 16:40:40 +02:00
let lesParams = {
sellingComment: $scope.commentaire,
2018-04-05 16:40:40 +02:00
activeSelling : $scope.activeSelling,
activeFestival: $scope.activeFestival
};
2018-04-05 14:21:32 +02:00
$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);
})
;
};
2018-04-05 17:01:36 +02:00
$scope.init = (function () {
$scope.fetchProductsFromDB();
})();
2018-04-05 14:21:32 +02:00
}]);
2018-04-04 16:25:25 +02:00