add view, lot and type in formulary new action

This commit is contained in:
Cayo Puigdefabregas 2022-01-05 16:00:13 +01:00
parent 7d341c7d64
commit fd00a3ec34
5 changed files with 32 additions and 4 deletions

View File

@ -86,6 +86,14 @@ class NewActionForm(FlaskForm):
('Warning', 'Warning'), ('Warning', 'Warning'),
('Error', 'Error')]) ('Error', 'Error')])
description = TextAreaField(u'Description') description = TextAreaField(u'Description')
lot = HiddenField()
type = HiddenField()
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.instance = None
if self.lot.data:
self.lot.data = self.lot.data.id
def save(self): def save(self):
pass pass

View File

@ -30,7 +30,7 @@ class DeviceListView(View):
context = {'devices': devices, context = {'devices': devices,
'lots': lots, 'lots': lots,
'form_lot_device': LotDeviceForm(), 'form_lot_device': LotDeviceForm(),
'form_new_action': NewActionForm(), 'form_new_action': NewActionForm(lot=lot),
'lot': lot} 'lot': lot}
return flask.render_template(self.template_name, **context) return flask.render_template(self.template_name, **context)
@ -96,7 +96,22 @@ class LotDeleteView(View):
return flask.redirect(next_url) return flask.redirect(next_url)
class NewActionView(View):
methods = ['POST']
decorators = [login_required]
def dispatch_request(self):
form = NewActionForm()
# import pdb; pdb.set_trace()
# from flask import request
if form.validate_on_submit():
form.save()
next_url = url_for('inventory.devices.devicelist')
return flask.redirect(next_url)
devices.add_url_rule('/action/add/', view_func=NewActionView.as_view('action_add'))
devices.add_url_rule('/device/', view_func=DeviceListView.as_view('devicelist')) devices.add_url_rule('/device/', view_func=DeviceListView.as_view('devicelist'))
devices.add_url_rule('/lot/<string:id>/device/', view_func=DeviceListView.as_view('lotdevicelist')) devices.add_url_rule('/lot/<string:id>/device/', view_func=DeviceListView.as_view('lotdevicelist'))
devices.add_url_rule('/lot/devices/add/', view_func=LotDeviceAddView.as_view('lot_devices_add')) devices.add_url_rule('/lot/devices/add/', view_func=LotDeviceAddView.as_view('lot_devices_add'))

View File

@ -35,4 +35,6 @@ function deviceSelect() {
function newAction(action) { function newAction(action) {
console.log(action); console.log(action);
$("#actionModal #type").val(action);
$("#activeActionModal").click();
} }

View File

@ -7,7 +7,7 @@
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div> </div>
<form action="{{ url_for('inventory.devices.lot_devices_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"> <p class="text-danger">
@ -17,6 +17,8 @@
{% 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 %}
{{ field(class_="devicesList") }} {{ field(class_="devicesList") }}
{% elif field == form_new_action.lot %}
{{ field(class_="form-control") }}
{% else %} {% else %}
<div class="col-12"> <div class="col-12">
{{ field.label(class_="form-label") }} {{ field.label(class_="form-label") }}

View File

@ -78,12 +78,13 @@
<i class="bi bi-plus"></i> <i class="bi bi-plus"></i>
New Actions New Actions
</button> </button>
<a href="javascript:void()" class="d-none" id="activeActionModal" data-bs-toggle="modal" data-bs-target="#actionModal" />
<ul class="dropdown-menu" aria-labelledby="btnActions""> <ul class="dropdown-menu" aria-labelledby="btnActions"">
<li> <li>
Status actions Status actions
</li> </li>
<li> <li>
<a href="javascript:newAction('Recycling')" class="dropdown-item" data-bs-toggle="modal" data-bs-target="#actionModal"> <a href="javascript:newAction('Recycling')" class="dropdown-item">
<i class="bi bi-recycle"></i> <i class="bi bi-recycle"></i>
Recycling Recycling
</a> </a>