-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.js
98 lines (80 loc) · 2.64 KB
/
admin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
var app = angular.module("app", ["orderapp", "goodapp"]);
app.directive("getUrl", function() { // get image-url from hidden iframe
return function(scope, element, attr) {
element.on("load", function(e) {
var path = e.target.contentDocument.body.innerHTML;
scope.$apply(function() {
scope.newgood.img = path;
});
});
};
});
app.controller("mainCtrl", function($scope, $rootScope, $http) {
// $broadcast-listening: to goodCtrl add-good
// $broadcast-listening: to goodCtrl new-category
// $on-listening: from goodCtrl create-category
$scope.$on("create-category", function(event, data) {
$scope.category = data;
});
// view properties
$scope.current = {
view: "view/goodlist.html",
button: "Замовлення",
buttons: true
};
$scope.showOrder = function() {
$scope.current = {
view: "view/orderlist.html",
button: "Товари",
buttons: false
};
$scope.showPage = $scope.showProducts;
};
$scope.showProducts = function() {
$scope.current = {
view: "view/goodlist.html",
button: "Замовлення",
buttons: true
};
$scope.showPage = $scope.showOrder;
};
$scope.showPage = $scope.showOrder;
// modal new good settings
$scope.file_field = "Вибрати файл";
window.onload = function() {
var input_file = document.getElementById("upl"); // input for downloading image-file
input_file.onchange = function() {
if(input_file.files[0].name) {
$scope.file_field = input_file.files[0].name;
$scope.$apply();
}
};
};
$scope.newgood = {};
$scope.newProduct = function() { // save new good to database
var obj = $scope.newgood;
$http.post("/addgoods", obj).then(function(data) {
if(DB_error(data.data)) return;
alert(data.data);
$scope.newgood = {};
$rootScope.$broadcast("add-good", true);
});
};
// save new category to database
$scope.newCategory = function(newcategory) {
var obj = {
title: newcategory
};
$http.post("/addcategory", obj).then(function(data) {
if(DB_error(data.data)) return;
alert(data.data);
$rootScope.$broadcast("new-category", true);
});
};
// logout function
$scope.logoutadmin = function() {
$.get("/logout", function(data) {
location.reload();
});
};
});