Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
third-party
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alexis AOUN
third-party
Commits
9d2a5ee7
Commit
9d2a5ee7
authored
May 21, 2021
by
Damien Moulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove a supplier
parent
a2b6085b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
99 additions
and
1 deletions
+99
-1
oders_helper_style.css
orders/static/css/oders_helper_style.css
+28
-0
orders_helper.js
orders/static/js/orders_helper.js
+58
-1
helper.html
templates/orders/helper.html
+13
-0
No files found.
orders/static/css/oders_helper_style.css
View file @
9d2a5ee7
...
@@ -10,4 +10,31 @@
...
@@ -10,4 +10,31 @@
.product_qty_input
{
.product_qty_input
{
width
:
100px
;
width
:
100px
;
}
#suppliers_container
{
display
:
flex
;
justify-content
:
center
;
align-items
:
center
;
margin
:
20px
0
20px
0
;
}
.supplier_pill
{
background-color
:
#e7e9ed
;
border-radius
:
50px
;
width
:
200px
;
min-height
:
35px
;
display
:
flex
;
flex-direction
:
column
;
justify-content
:
center
;
align-items
:
center
;
padding
:
8px
;
margin-right
:
5px
;
}
.remove_supplier_icon
{
color
:
red
;
margin-left
:
5px
;
cursor
:
pointer
;
}
}
\ No newline at end of file
orders/static/js/orders_helper.js
View file @
9d2a5ee7
...
@@ -40,7 +40,7 @@ function add_supplier() {
...
@@ -40,7 +40,7 @@ function add_supplier() {
contentType
:
"application/json; charset=utf-8"
,
contentType
:
"application/json; charset=utf-8"
,
success
:
function
(
data
)
{
success
:
function
(
data
)
{
save_supplier_products
(
supplier
,
data
.
res
.
products
);
save_supplier_products
(
supplier
,
data
.
res
.
products
);
display_products
();
update_display
();
$
(
"#supplier_input"
).
val
(
""
)
$
(
"#supplier_input"
).
val
(
""
)
closeModal
();
closeModal
();
},
},
...
@@ -58,6 +58,25 @@ function add_supplier() {
...
@@ -58,6 +58,25 @@ function add_supplier() {
}
}
/**
/**
* Remove a supplier from the selected list & its associated products
* @param {int} supplier_id
*/
function
remove_supplier
(
supplier_id
)
{
// Remove from suppliers list
selected_suppliers
=
selected_suppliers
.
filter
(
supplier
=>
supplier
.
id
!=
supplier_id
)
// Remove the supplier from the products suppliers list
for
(
const
i
in
products
)
{
products
[
i
].
suppliers
=
products
[
i
].
suppliers
.
filter
(
supplier
=>
supplier
.
id
!=
supplier_id
)
}
// Remove products only associated to this product
products
=
products
.
filter
(
product
=>
product
.
suppliers
.
length
>
0
)
update_display
();
}
/**
* When products are fetched, save them and the relation with the supplier.
* When products are fetched, save them and the relation with the supplier.
* If product already saved, add the supplier to its suppliers list.
* If product already saved, add the supplier to its suppliers list.
* Else, add product with supplier.
* Else, add product with supplier.
...
@@ -101,6 +120,28 @@ function supplier_column_name(supplier) {
...
@@ -101,6 +120,28 @@ function supplier_column_name(supplier) {
return
`supplier_
${
parsed_name
}
`
;
return
`supplier_
${
parsed_name
}
`
;
}
}
/**
* Display the selected suppliers
*/
function
display_suppliers
()
{
let
supplier_container
=
$
(
"#suppliers_container"
);
$
(
"#suppliers_container"
).
empty
();
for
(
supplier
of
selected_suppliers
)
{
let
template
=
$
(
"#templates #supplier_pill"
)
template
.
find
(
".supplier_name"
).
text
(
supplier
.
display_name
);
template
.
find
(
".remove_supplier_icon"
).
attr
(
'id'
,
`remove_supplier_
${
supplier
.
id
}
`
)
supplier_container
.
append
(
template
.
html
());
}
$
(
".remove_supplier_icon"
).
on
(
"click"
,
function
(
e
)
{
const
el_id
=
$
(
this
).
attr
(
'id'
).
split
(
'_'
);
const
supplier_id
=
el_id
[
el_id
.
length
-
1
]
remove_supplier
(
supplier_id
);
})
}
/* DATATABLE */
/* DATATABLE */
/**
/**
...
@@ -160,6 +201,11 @@ function prepare_datatable_columns() {
...
@@ -160,6 +201,11 @@ function prepare_datatable_columns() {
*/
*/
function
display_products
()
{
function
display_products
()
{
// Empty datatable if already exists
// Empty datatable if already exists
if
(
products
.
length
==
0
)
{
$
(
'.main'
).
hide
();
return
-
1
;
}
if
(
products_table
)
{
if
(
products_table
)
{
products_table
.
clear
().
destroy
();
products_table
.
clear
().
destroy
();
$
(
'#products_table'
).
empty
();
$
(
'#products_table'
).
empty
();
...
@@ -185,6 +231,14 @@ function display_products() {
...
@@ -185,6 +231,14 @@ function display_products() {
$
(
'.main'
).
show
();
$
(
'.main'
).
show
();
}
}
/**
* Update DOM display
*/
function
update_display
()
{
display_suppliers
();
display_products
();
}
$
(
document
).
ready
(
function
()
{
$
(
document
).
ready
(
function
()
{
$
.
ajaxSetup
({
headers
:
{
"X-CSRFToken"
:
getCookie
(
'csrftoken'
)
}
});
$
.
ajaxSetup
({
headers
:
{
"X-CSRFToken"
:
getCookie
(
'csrftoken'
)
}
});
...
@@ -223,4 +277,7 @@ $(document).ready(function() {
...
@@ -223,4 +277,7 @@ $(document).ready(function() {
e
.
preventDefault
();
e
.
preventDefault
();
add_supplier
();
add_supplier
();
})
})
// todo on input change : update value in array of products
// todo on click on 'X' change to i
});
});
templates/orders/helper.html
View file @
9d2a5ee7
...
@@ -25,6 +25,8 @@
...
@@ -25,6 +25,8 @@
</form>
</form>
</div>
</div>
<div
class=
"txtcenter"
id=
"suppliers_container"
></div>
<div
class=
"main"
style=
"display:none;"
>
<div
class=
"main"
style=
"display:none;"
>
<div
class=
"table_area"
>
<div
class=
"table_area"
>
<table
id=
"products_table"
class=
"display"
cellspacing=
"0"
width=
"100%"
></table>
<table
id=
"products_table"
class=
"display"
cellspacing=
"0"
width=
"100%"
></table>
...
@@ -32,6 +34,17 @@
...
@@ -32,6 +34,17 @@
</div>
</div>
</div>
</div>
<div
id=
"templates"
style=
"display:none;"
>
<div
id=
"supplier_pill"
>
<div
class=
"supplier_pill"
>
<div
class=
"supplier_name_container"
>
<span
class=
"supplier_name"
></span>
<i
class=
"fas fa-times remove_supplier_icon"
></i>
</div>
</div>
</div>
</div>
<script
src=
"{% static "
js
/
all_common
.
js
"
%}?
v=
"></script>
<script
src=
"{% static "
js
/
all_common
.
js
"
%}?
v=
"></script>
<script type="
text
/
javascript
"
src=
"{% static 'js/orders_helper.js' %}?v="
></script>
<script type="
text
/
javascript
"
src=
"{% static 'js/orders_helper.js' %}?v="
></script>
{% endblock %}
{% endblock %}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment