diff --git a/config.local.py b/config.local.py
index 8c13253..1003e8a 100644
--- a/config.local.py
+++ b/config.local.py
@@ -1,2 +1,2 @@
SQLALCHEMY_TRACK_MODIFICATIONS = True
-SQLALCHEMY_DATABASE_URI = "postgresql://tetalab_user:tetalab@localhost/tetalab_stock"
+SQLALCHEMY_DATABASE_URI = "postgresql://tetastock:tetastock@localhost/tetastock"
diff --git a/static/images/login.png b/static/images/login.png
new file mode 100644
index 0000000..b0b3ae7
Binary files /dev/null and b/static/images/login.png differ
diff --git a/static/images/logout.png b/static/images/logout.png
new file mode 100644
index 0000000..b3806f4
Binary files /dev/null and b/static/images/logout.png differ
diff --git a/static/scripts/tetalab.js b/static/scripts/tetalab.js
index bb69729..2f1a42d 100644
--- a/static/scripts/tetalab.js
+++ b/static/scripts/tetalab.js
@@ -46,6 +46,36 @@ function valid_input(obj) {
, 2000);
}
+/* **************************************************************************************
+ * LOGIN
+ * **************************************************************************************/
+
+function login() {
+ err = false;
+ username = document.getElementById('login');
+ password = document.getElementById('password');
+ if (username.value.length < 1) {
+ err = true;
+ invalid_input(username);
+ }
+ if (password.value.length < 1){
+ err = true;
+ invalid_input(password);
+ }
+ if (err)
+ return;
+
+ setcookie('login', username.value, 30);
+ setcookie('password', password.value, 30);
+ document.location='/';
+}
+
+function logout() {
+ setcookie('token', '', 30);
+ document.location='/';
+}
+
+
/* **************************************************************************************
* COMPONTANTS
* **************************************************************************************/
@@ -143,7 +173,7 @@ function search_componants_by_provider(obj) {
function confirm_componant_delete() {
var msg="La suppression est définitive \net n'est pas autorisée si le \ncomposant fait partie d'un Kit.\n\nConfirmer ?";
- return confirm(msg)
+ return confirm(msg);
}
// New componant
@@ -383,7 +413,7 @@ function create_provider() {
function confirm_provider_delete() {
var msg="La suppression est définitive \net n'est pas autorisée si le \nfournisseur est référencé \npar un composant.\n\nConfirmer ?";
- return confirm(msg)
+ return confirm(msg);
}
// Update provider
@@ -410,3 +440,162 @@ function update_provider(obj, provider_id, type) {
xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhttp.send('field='+obj.id+'&value='+obj.value);
}
+
+
+/* **************************************************************************************
+ * KITS
+ * **************************************************************************************/
+
+// Update result
+function update_kits() {
+ obj = document.getElementById('result_container');
+ var xhttp = new XMLHttpRequest();
+ xhttp.onerror = function(){
+ obj.innerHTML = "Erreur lors de la mise à jour de la liste (1)"
+ };
+
+ xhttp.onload = function(){
+ if (xhttp.status != 200) {
+ obj.innerHTML = "Erreur lors de la mise à jour de la liste (2)"
+ }
+ };
+
+ xhttp.onreadystatechange = function() {
+ if (xhttp.readyState == 4 && xhttp.status == 200) {
+ var response = xhttp.responseText;
+ obj.innerHTML = response;
+ return true;
+ }
+ };
+ xhttp.open('POST', '/kits/update', true);
+ xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
+ xhttp.send();
+}
+
+// Result ordering
+
+function update_kits_by_name(order) {
+ setcookie('k_order', order, 30);
+ setcookie('k_sort', 'name', 30);
+ setcookie('k_order_refresh', '1', 30);
+ update_kits();
+}
+
+function update_kits_by_name(order) {
+ setcookie('k_order', order, 30);
+ setcookie('k_sort', 'name', 30);
+ setcookie('k_order_refresh', '1', 30);
+ update_kits();
+}
+
+function update_kits_by_designation(order) {
+ setcookie('k_order', order, 30);
+ setcookie('k_sort', 'designation', 30);
+ setcookie('k_order_refresh', '1', 30);
+ update_kits();
+}
+
+function k_krevious_kage(prevhop) {
+ setcookie('k_offset', prevhop, 30);
+ update_kits();
+}
+
+function k_next_kage(nexthop) {
+ setcookie('k_offset', nexthop, 30);
+ update_kits();
+}
+
+// Search kits
+
+function search_kits_by_name(obj) {
+ setcookie('k_name', obj.value, 30);
+ update_kits();
+}
+
+function search_kits_by_designation(obj) {
+ setcookie('k_designation', obj.value, 30);
+ update_kits();
+}
+
+// New kit
+
+function new_kit() {
+ var err = false;
+ var obj = {};
+ if (getcookie('k_count') > 0){
+ var err = true;
+ obj[0] = document.getElementById('name');
+ }
+ if (getcookie('k_name').length < 1){
+ var err = true;
+ obj[0] = document.getElementById('name');
+ }
+ if (getcookie('k_designation').length < 1){
+ var err = true;
+ obj[1] = document.getElementById('designation');
+ }
+ if (err == true) {
+ for (i in obj){
+ invalid_input(obj[i]);
+ }
+ return;
+ }
+ create_kit();
+ update_kits();
+}
+
+function create_kit() {
+ var MSG='Erreur lors de la creation du kit.';
+ var xhttp = new XMLHttpRequest();
+ xhttp.onerror = function(){
+ alert(MSG);
+ return false;
+ };
+
+ xhttp.onload = function(){
+ if (xhttp.readyState == 4 && xhttp.status == 200) {
+ var response = xhttp.responseText;
+ if (response == 'OK'){
+ return true;
+ }
+ alert(MSG);
+ return false;
+ }
+ };
+
+ xhttp.open('POST', '/kits/new', true);
+ xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
+ xhttp.send();
+}
+
+// Delete kit
+
+function confirm_kit_delete() {
+ var msg="La suppression d'un kit est définitive.\n\nConfirmer ?";
+ return confirm(msg);
+}
+
+// Update kit
+
+function update_kit(obj, kit_id, type) {
+ var xhttp = new XMLHttpRequest();
+ xhttp.onerror = function(){
+ invalid_input(obj);
+ };
+
+ xhttp.onload = function(){
+ if (xhttp.readyState == 4 && xhttp.status == 200) {
+ var response = xhttp.responseText;
+ if (response == 'OK'){
+ valid_input(obj);
+ return;
+ }
+ obj.style.borderColor = red;
+ invalid_input(obj);
+ }
+ };
+
+ xhttp.open('POST', '/kits/update/'+kit_id, true);
+ xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
+ xhttp.send('field='+obj.id+'&value='+obj.value);
+}
diff --git a/static/style/style.css b/static/style/style.css
index d21e2cb..f82c79f 100644
--- a/static/style/style.css
+++ b/static/style/style.css
@@ -44,6 +44,19 @@ div.top_menu {
border-width: 1px 0 0 0;
}
+div.top_menu input {
+ position: relative;
+ top: 4px;
+ width: 16px;
+ height: 16px;
+ border-radius: 2px;
+ margin-right: 4px;
+}
+
+div.top_menu input:hover {
+ background-color: #FF5D00;
+}
+
span.top_menu_item {
margin: 5px 2px 0 0;
font-size: 12px;
diff --git a/stock.sql b/stock.sql
index 3c642f3..133acf0 100644
--- a/stock.sql
+++ b/stock.sql
@@ -1,9 +1,13 @@
\c postgres;
-drop database tetalab_stock;
-create database tetalab_stock;
+drop database tetastock;
+drop role tetastock;
-\c tetalab_stock;
+create role tetastock with LOGIN ENCRYPTED PASSWORD 'tetastock';
+
+create database tetastock;
+
+\c tetastock;
CREATE TABLE stock_users (
id serial primary key,
@@ -14,8 +18,8 @@ CREATE TABLE stock_users (
CREATE TABLE stock_kits (
id serial primary key,
- name text not NULL,
- description text not NULL
+ name text not NULL unique,
+ designation text not NULL
);
CREATE TABLE stock_providers (
@@ -46,12 +50,26 @@ CREATE TABLE stock_kit_compositions (
quantity integer not NULL
);
-alter table stock_users owner to tetalab_user;
-alter table stock_kits owner to tetalab_user;
-alter table stock_providers owner to tetalab_user;
-alter table stock_componants owner to tetalab_user;
-alter table stock_kit_compositions owner to tetalab_user;
-alter database tetalab_stock owner to tetalab_user;
+CREATE TABLE stock_orders (
+ id serial primary key,
+ componant_id integer REFERENCES stock_componants(id),
+ quantity integer not NULL,
+ price NUMERIC not NULL default 0,
+ date timestamp not NULL
+);
+
+alter table stock_users owner to tetastock;
+alter table stock_kits owner to tetastock;
+alter table stock_providers owner to tetastock;
+alter table stock_componants owner to tetastock;
+alter table stock_kit_compositions owner to tetastock;
+alter table stock_orders owner to tetastock;
+alter database tetastock owner to tetastock;
+
+insert into stock_users (mail, password, name) values
+('doug.letough@free.fr', '$2a$08$578910202124252729313uTyggq4ANEjMljcClFriOqcsttB2fnAW', 'Doug Le Tough');
+insert into stock_users (mail, password, name) values
+('doug@redatomik.org', '$2a$08$578910202124252729313uTyggq4ANEjMljcClFriOqcsttB2fnAW', 'Doug Le Tough');
insert into stock_providers (name, address, mail, url, comment)
values ('Tous', 'N/A', 'N/A', 'N/A', 'N/A');
diff --git a/templates/componant.html b/templates/componant.html
index 8a40813..3dc5da9 100644
--- a/templates/componant.html
+++ b/templates/componant.html
@@ -6,7 +6,7 @@
{% endblock %}
-
+
{% block left_menu %}