caisse-bliss/assets/js/parts/main.js
2018-04-05 14:21:32 +02:00

71 lines
2.4 KiB
JavaScript

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.pausedSelling = [];
$scope.activeSelling = [];
$scope.CurrentSellingTotal = $scope.activeSelling.reduce(function (a, b) {
return a + b.price;
}, 0);
$scope.stuff = stuff;
$scope.setActiveSelling = function (selling) {
$scope.activeSelling = selling;
};
$scope.pauseSelling = function (selling) {
$scope.pausedSelling.push(selling);
};
$scope.addProduct = function (id) {
let found = $scope.productsFromDB.find({id: id});
if (found) {
$scope.productsToRecord.push(found);
}
};
$scope.fetchProductsFromDB = function () {
console.log('fetch products...');
$http.get('get-my-products').then((data) => {
console.log('ok');
$scope.productsFromDB = data;
}, (err) => {
console.log(err);
});
};
$scope.init = (function () {
$scope.fetchProductsFromDB();
})();
$scope.logtest = function () {
console.log('log test ok');
};
$scope.sendForm = function () {
let lesParams = {};
$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);
})
;
};
}]);