add count of devices in action form

This commit is contained in:
Cayo Puigdefabregas 2022-02-03 13:58:54 +01:00
parent aeef04b92c
commit 7f9a6784e9
2 changed files with 21 additions and 4 deletions

View File

@ -11,15 +11,23 @@ $(document).ready(function() {
function deviceSelect() { function deviceSelect() {
var devices = $(".deviceSelect").filter(':checked'); var devices = $(".deviceSelect").filter(':checked');
var devices_count = devices.length;
var devices_id = $.map(devices, function(x) { return $(x).attr('data')}).join(","); var devices_id = $.map(devices, function(x) { return $(x).attr('data')}).join(",");
if (devices_id == "") { if (devices_count == 0) {
$("#addingLotModal .text-danger").show(); $("#addingLotModal .text-danger").show();
$("#addingLotModal .btn-primary").hide(); $("#addingLotModal .btn-primary").hide();
$("#removeLotModal .text-danger").show(); $("#removeLotModal .text-danger").show();
$("#removeLotModal .btn-primary").hide(); $("#removeLotModal .btn-primary").hide();
$("#addingTagModal .text-danger").show(); $("#addingTagModal .text-danger").show();
$("#addingTagModal .btn-primary").hide(); $("#addingTagModal .btn-primary").hide();
$("#actionModal .text-danger").show();
$("#actionModal .btn-primary").hide();
$("#allocateModal .text-danger").show();
$("#allocateModal .btn-primary").hide();
} else { } else {
$("#addingLotModal .text-danger").hide(); $("#addingLotModal .text-danger").hide();
$("#addingLotModal .btn-primary").show(); $("#addingLotModal .btn-primary").show();
@ -53,11 +61,15 @@ function removeTag() {
function newAction(action) { function newAction(action) {
$("#actionModal #type").val(action); $("#actionModal #type").val(action);
$("#actionModal #title-action").html(action); $("#actionModal #title-action").html(action);
devices_count = $(".deviceSelect").filter(':checked').length;
$("#actionModal .devices-count").html(devices_count);
$("#activeActionModal").click(); $("#activeActionModal").click();
} }
function newAllocate(action) { function newAllocate(action) {
$("#allocateModal #type").val(action); $("#allocateModal #type").val(action);
$("#allocateModal #title-action").html(action); $("#allocateModal #title-action").html(action);
devices_count = $(".deviceSelect").filter(':checked').length;
$("#actionModal .devices-count").html(devices_count);
$("#activeAllocateModal").click(); $("#activeAllocateModal").click();
} }

View File

@ -10,12 +10,17 @@
<form action="{{ url_for('inventory.devices.action_add') }}" method="post"> <form action="{{ url_for('inventory.devices.action_add') }}" method="post">
{{ form_new_action.csrf_token }} {{ form_new_action.csrf_token }}
<div class="modal-body"> <div class="modal-body">
<p class="text-danger">
You need select first some device before to do one action
</p>
{% for field in form_new_action %} {% for field in form_new_action %}
{% if field != form_new_action.csrf_token %} {% if field != form_new_action.csrf_token %}
{% if field == form_new_action.devices %} {% if field == form_new_action.devices %}
<div class="col-12">
{{ field.label(class_="form-label") }}: <span class="devices-count"></span>
{{ field(class_="form-control") }}
<p class="text-danger">
You need select first some device before to do one action
</p>
<p class="enumeration-devices"></p>
</div>
{{ field(class_="devicesList") }} {{ field(class_="devicesList") }}
{% elif field == form_new_action.type %} {% elif field == form_new_action.type %}
{{ field(class_="form-control") }} {{ field(class_="form-control") }}