adding rendering template for new action

This commit is contained in:
Cayo Puigdefabregas 2022-01-05 12:13:44 +01:00
parent 483f674957
commit 7d341c7d64
4 changed files with 41 additions and 9 deletions

View File

@ -1,5 +1,5 @@
from flask_wtf import FlaskForm
from wtforms import StringField, validators
from wtforms import StringField, HiddenField, DateField, TextAreaField, SelectField, validators
from flask import g
from ereuse_devicehub.db import db
@ -78,10 +78,14 @@ class LotForm(FlaskForm):
class NewActionForm(FlaskForm):
name = StringField(u'Name')
date = StringField(u'Date')
severity = StringField(u'Severity')
description = StringField(u'Description')
name = StringField(u'Name', [validators.length(max=50)])
devices = HiddenField()
date = DateField(u'Date')
severity = SelectField(u'Severity', choices=[('Info', 'Ok'),
('Notice', 'Notice'),
('Warning', 'Warning'),
('Error', 'Error')])
description = TextAreaField(u'Description')
def save(self):
pass

View File

@ -5,7 +5,7 @@ from flask_login import login_required, current_user
from ereuse_devicehub.resources.lot.models import Lot
from ereuse_devicehub.resources.device.models import Device
from ereuse_devicehub.inventory.forms import LotDeviceForm, LotForm
from ereuse_devicehub.inventory.forms import LotDeviceForm, LotForm, NewActionForm
devices = Blueprint('inventory.devices', __name__, url_prefix='/inventory')
@ -30,6 +30,7 @@ class DeviceListView(View):
context = {'devices': devices,
'lots': lots,
'form_lot_device': LotDeviceForm(),
'form_new_action': NewActionForm(),
'lot': lot}
return flask.render_template(self.template_name, **context)

View File

@ -9,15 +9,24 @@ function deviceSelect() {
if (devices_id == "") {
$("#addingLotModal .text-danger").show();
$("#addingLotModal .btn-primary").hide();
$("#removeLotModal .text-danger").show();
$("#removeLotModal .btn-primary").hide();
$("#actionModal .text-danger").show();
$("#actionModal .btn-primary").hide();
} else {
$("#addingLotModal .text-danger").hide();
$("#addingLotModal .btn-primary").removeClass('d-none');
$("#addingLotModal .btn-primary").show();
$("#removeLotModal .text-danger").hide();
$("#removeLotModal .btn-primary").removeClass('d-none');
$("#removeLotModal .btn-primary").show();
$("#actionModal .text-danger").hide();
$("#actionModal .btn-primary").removeClass('d-none');
$("#actionModal .btn-primary").show();
}
$.map($(".devicesList"), function(x) {
$(x).val(devices_id);

View File

@ -8,15 +8,33 @@
</div>
<form action="{{ url_for('inventory.devices.lot_devices_add') }}" method="post">
{{ form_lot_device.csrf_token }}
{{ form_new_action.csrf_token }}
<div class="modal-body">
Please write a name of a lot
<input class="devicesList" type="hidden" name="devices" />
<p class="text-danger">
You need select first some device before to do one action
</p>
{% for field in form_new_action %}
{% if field != form_new_action.csrf_token %}
{% if field == form_new_action.devices %}
{{ field(class_="devicesList") }}
{% else %}
<div class="col-12">
{{ field.label(class_="form-label") }}
{{ field(class_="form-control") }}
{% if field.errors %}
<p class="text-danger">
{% for error in field.errors %}
{{ error }}<br/>
{% endfor %}
</p>
{% endif %}
</div>
{% endif %}
{% endif %}
{% endfor %}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<input type="submit" class="btn btn-primary d-none" value="Create" />