fixing js form for trade
This commit is contained in:
parent
cd16baaadb
commit
f3ffcd89ca
|
@ -622,11 +622,29 @@ class DataWipeForm(NewActionForm):
|
||||||
|
|
||||||
|
|
||||||
class TradeForm(NewActionForm):
|
class TradeForm(NewActionForm):
|
||||||
supplier = StringField(u'Supplier', [validators.DataRequired()],
|
supplier = StringField(u'Supplier', [validators.Optional()],
|
||||||
description="Please enter the supplier's email address")
|
description="Please enter the supplier's email address",
|
||||||
receiver = StringField(u'Receiver', [validators.DataRequired()],
|
render_kw={'data-email': ""})
|
||||||
description="Please enter the receiver's email address")
|
receiver = StringField(u'Receiver', [validators.Optional()],
|
||||||
|
description="Please enter the receiver's email address",
|
||||||
|
render_kw={'data-email': ""})
|
||||||
confirm = BooleanField(u'Confirm', [validators.Optional()],
|
confirm = BooleanField(u'Confirm', [validators.Optional()],
|
||||||
|
default=True,
|
||||||
description="I need confirmation from the other user for every device and document.")
|
description="I need confirmation from the other user for every device and document.")
|
||||||
code = StringField(u'Code', [validators.Optional()],
|
code = StringField(u'Code', [validators.Optional()],
|
||||||
description="If you don't need confirm, you need put a code for trace the user in the statistics.")
|
description="If you don't need confirm, you need put a code for trace the user in the statistics.")
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.supplier.render_kw['data-email'] = g.user.email
|
||||||
|
self.receiver.render_kw['data-email'] = g.user.email
|
||||||
|
|
||||||
|
def validate(self, extra_validators=None):
|
||||||
|
is_valid = super().validate(extra_validators)
|
||||||
|
|
||||||
|
if not self.confirm and not self.code:
|
||||||
|
self.code.errors = ["If you don't want confirm, you need a code"]
|
||||||
|
is_valid = False
|
||||||
|
|
||||||
|
return is_valid
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import flask
|
import flask
|
||||||
|
from flask import g
|
||||||
from flask import Blueprint, request, url_for
|
from flask import Blueprint, request, url_for
|
||||||
from flask.views import View
|
from flask.views import View
|
||||||
from flask_login import current_user, login_required
|
from flask_login import current_user, login_required
|
||||||
|
@ -38,7 +39,12 @@ class DeviceListMix(View):
|
||||||
form_new_action = NewActionForm(lot=lot.id)
|
form_new_action = NewActionForm(lot=lot.id)
|
||||||
form_new_allocate = AllocateForm(lot=lot.id)
|
form_new_allocate = AllocateForm(lot=lot.id)
|
||||||
form_new_datawipe = DataWipeForm(lot=lot.id)
|
form_new_datawipe = DataWipeForm(lot=lot.id)
|
||||||
form_new_trade = TradeForm(lot=lot.id)
|
form_new_trade = TradeForm(
|
||||||
|
lot=lot.id,
|
||||||
|
receiver=g.user.email,
|
||||||
|
supplier=g.user.email,
|
||||||
|
type='Trade'
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
devices = Device.query.filter(
|
devices = Device.query.filter(
|
||||||
Device.owner_id == current_user.id).filter(
|
Device.owner_id == current_user.id).filter(
|
||||||
|
@ -47,7 +53,11 @@ class DeviceListMix(View):
|
||||||
form_new_action = NewActionForm()
|
form_new_action = NewActionForm()
|
||||||
form_new_allocate = AllocateForm()
|
form_new_allocate = AllocateForm()
|
||||||
form_new_datawipe = DataWipeForm()
|
form_new_datawipe = DataWipeForm()
|
||||||
form_new_trade = TradeForm()
|
form_new_trade = TradeForm(
|
||||||
|
receiver=g.user.email,
|
||||||
|
supplier=g.user.email,
|
||||||
|
type='Trade'
|
||||||
|
)
|
||||||
|
|
||||||
action_devices = form_new_action.devices.data
|
action_devices = form_new_action.devices.data
|
||||||
list_devices = []
|
list_devices = []
|
||||||
|
@ -301,6 +311,7 @@ class NewActionView(View):
|
||||||
|
|
||||||
def dispatch_request(self):
|
def dispatch_request(self):
|
||||||
self.form = self.form_class()
|
self.form = self.form_class()
|
||||||
|
# import pdb; pdb.set_trace()
|
||||||
|
|
||||||
if self.form.validate_on_submit():
|
if self.form.validate_on_submit():
|
||||||
instance = self.form.save()
|
instance = self.form.save()
|
||||||
|
|
|
@ -63,6 +63,27 @@ function removeTag() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function newTrade(action) {
|
||||||
|
var title = "Trade "
|
||||||
|
var receiver = $("#receiver").data("email");
|
||||||
|
var supplier = $("#supplier").data("email");
|
||||||
|
if (action == 'supplier') {
|
||||||
|
title = 'Trade Incoming';
|
||||||
|
$("#receiver").attr('disabled', 'disabled');
|
||||||
|
$("#supplier").prop('disabled', false);
|
||||||
|
$("#supplier").val('');
|
||||||
|
$("#receiver").val(receiver);
|
||||||
|
} else if (action == 'receiver') {
|
||||||
|
title = 'Trade Outgoing';
|
||||||
|
$("#supplier").attr('disabled', 'disabled');
|
||||||
|
$("#receiver").prop('disabled', false);
|
||||||
|
$("#receiver").val('');
|
||||||
|
$("#supplier").val(supplier);
|
||||||
|
}
|
||||||
|
$("#tradeLotModalModal #title-action").html(title);
|
||||||
|
$("#activeTradeModal").click();
|
||||||
|
}
|
||||||
|
|
||||||
function newAction(action) {
|
function newAction(action) {
|
||||||
$("#actionModal #type").val(action);
|
$("#actionModal #type").val(action);
|
||||||
$("#actionModal #title-action").html(action);
|
$("#actionModal #title-action").html(action);
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
Lots
|
Lots
|
||||||
<span class="caret"></span>
|
<span class="caret"></span>
|
||||||
</button>
|
</button>
|
||||||
|
<span class="d-none" id="activeTradeModal" data-bs-toggle="modal" data-bs-target="#tradeLotModal"></span>
|
||||||
<ul class="dropdown-menu" aria-labelledby="btnLots">
|
<ul class="dropdown-menu" aria-labelledby="btnLots">
|
||||||
{% if lot and lot.is_temporary and not lot.devices %}
|
{% if lot and lot.is_temporary and not lot.devices %}
|
||||||
<li>
|
<li>
|
||||||
|
@ -74,15 +75,13 @@
|
||||||
</li>
|
</li>
|
||||||
{% if lot.is_temporary %}
|
{% if lot.is_temporary %}
|
||||||
<li>
|
<li>
|
||||||
<a href="javascript:void()" class="dropdown-item"
|
<a href="javascript:newTrade('supplier')" class="dropdown-item">
|
||||||
data-bs-toggle="modal" data-bs-target="#tradeLotModal">
|
|
||||||
<i class="bi bi-plus"></i>
|
<i class="bi bi-plus"></i>
|
||||||
Add supplier
|
Add supplier
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a href="javascript:void()" class="dropdown-item"
|
<a href="javascript:newTrade('receiver')" class="dropdown-item">
|
||||||
data-bs-toggle="modal" data-bs-target="#tradeLotModal">
|
|
||||||
<i class="bi bi-plus"></i>
|
<i class="bi bi-plus"></i>
|
||||||
Add receiver
|
Add receiver
|
||||||
</a>
|
</a>
|
||||||
|
|
Reference in a new issue