Commit f8969f64 authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_mrp_quality_assurance: support fast quality control post

using gadget
parent dec83150
div.dialog_in_listbox input[type='submit']{
margin-top: 0pt;
margin-right:0pt;
}
.document_table tbody tr td form div.dialog_in_listbox{
width: max-content;
position: relative;
}
.ui-visibility-hidden {
visibility: hidden;
}
div.dialog_in_listbox .ui-icon-spinner{
position: absolute;
top:50%;
left:18%;
transform: translate(-50%, -50%);
}
input[type='submit'].error {
cursor: default;
pointer-events: none;
}
input[type='submit'].success {
background-color: #37A419;
border-color: #37A419;
cursor: default;
pointer-events: none;
}
input[type='submit'].success:hover,
input[type='submit'].success:focus {
background-color: #37A419;
}
form.dialog_form_center_in_listbox {
display: flex;
justify-content: center;
align-items: center;
}
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1" />
<title>Post Ok for quality control gadget</title>
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<script src="jio.js" type="text/javascript"></script>
<link rel="stylesheet" href="gadget_post_ok_for_quality_control.css">
<script src="gadget_post_ok_for_quality_control.js" type="text/javascript"></script>
</head>
<body>
<form class="dialog_form_center_in_listbox">
<div class="dialog_button_container dialog_in_listbox">
<input name="action_confirm" class="dialogconfirm" type="submit" value="Mark OK">
<span class="ui-icon-spinner ui-btn-icon-notext ui-visibility-hidden"></span>
</div>
</form>
</body>
</html>
\ No newline at end of file
/*global window, rJS, RSVP, jIO */
/*jslint nomen: true, maxlen:180, indent:2*/
(function (rJS, jIO, RSVP, window) {
"use strict";
rJS(window)
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("getSetting", "getSetting")
.declareMethod('render', function (options) {
var gadget = this;
return gadget.getSetting("hateoas_url")
.push(function (hateoas_url) {
options.hateoas_url = hateoas_url;
options.submit_state = 'initial';
options.input_value = 'Mark OK';
return gadget.changeState(options);
});
})
.onStateChange(function (modification_dict) {
var gadget = this,
button_container =
gadget.element.querySelector('.dialog_button_container'),
submit_input = button_container.querySelector('input'),
spinner = button_container.querySelector('.ui-icon-spinner');
if (modification_dict.hasOwnProperty('input_value')) {
submit_input.value = modification_dict.input_value;
}
if (modification_dict.hasOwnProperty('submit_state')) {
switch (gadget.state.submit_state) {
case 'initial':
submit_input.disabled = false;
spinner.classList.add('ui-visibility-hidden');
submit_input.classList.remove('success');
submit_input.classList.remove('error');
break;
case 'sending':
submit_input.disabled = true;
spinner.classList.remove('ui-visibility-hidden');
submit_input.classList.remove('success');
submit_input.classList.remove('error');
break;
case 'success':
submit_input.disabled = true;
spinner.classList.add('ui-visibility-hidden');
submit_input.classList.add('success');
submit_input.classList.remove('error');
break;
case 'error':
submit_input.disabled = true;
spinner.classList.add('ui-visibility-hidden');
submit_input.classList.remove('success');
submit_input.classList.add('error');
break;
}
}
})
.onEvent('submit', function submit() {
var gadget = this;
return new RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.changeState({
'submit_state': 'sending',
'input_value': 'Posting'
}),
gadget.jio_putAttachment(
gadget.state.quality_control,
// it's ugly, we should generate url in server side,
// but it doesn't work well to get hateoas_url in server side
// romain will check it in generic code
gadget.state.hateoas_url + gadget.state.post_url,
{
'result': gadget.state.value,
'fast_post': true
}
)
]);
})
.push(function (result_list) {
return jIO.util.readBlobAsText(result_list[1].target.response);
})
.push(function (response) {
var result = JSON.parse(response.target.result);
return gadget.changeState({
'submit_state': result.status,
'input_value': result.value
});
});
});
}(rJS, jIO, RSVP, window));
\ No newline at end of file
from DateTime import DateTime from DateTime import DateTime
import json
now = DateTime() now = DateTime()
user_value = context.portal_membership.getAuthenticatedMember().getUserValue() user_value = context.portal_membership.getAuthenticatedMember().getUserValue()
if result == 'ok': if result == 'ok':
context.edit( context.edit(
destination_decision_value = user_value, destination_decision_value = user_value,
...@@ -12,6 +12,11 @@ if result == 'ok': ...@@ -12,6 +12,11 @@ if result == 'ok':
effective_date = now effective_date = now
) )
elif result == 'nok': elif result == 'nok':
if fast_post:
return json.dumps({
'status': 'error',
'value': 'Only OK is allow'
})
if not context.getCausalityRelatedValue(portal_type='Defect Item') and redirect_to_defect_dialog: if not context.getCausalityRelatedValue(portal_type='Defect Item') and redirect_to_defect_dialog:
return context.Base_redirect(form_id = 'declare_defect', keep_items={ return context.Base_redirect(form_id = 'declare_defect', keep_items={
'post_quality_control': True, 'post_quality_control': True,
...@@ -37,6 +42,11 @@ elif result == 'nok': ...@@ -37,6 +42,11 @@ elif result == 'nok':
effective_date = now effective_date = now
) )
else: else:
if fast_post:
return json.dumps({
'status': 'error',
'value': 'Only OK is allow'
})
raise ValueError('unknown result: %s' % result) raise ValueError('unknown result: %s' % result)
me_line = context.getAggregateRelatedValue(portal_type='Manufacturing Execution Line') me_line = context.getAggregateRelatedValue(portal_type='Manufacturing Execution Line')
...@@ -48,7 +58,15 @@ if me_line: ...@@ -48,7 +58,15 @@ if me_line:
context.post() context.post()
if batch: if batch:
return context return context
if fast_post:
return json.dumps({
'status': 'success',
'value': 'OK'
})
ME = context.getCausalityValue(portal_type='Manufacturing Execution') ME = context.getCausalityValue(portal_type='Manufacturing Execution')
return ME.Base_redirect( return ME.Base_redirect(
'view', 'view',
keep_items={ keep_items={
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>result, redirect_to_defect_dialog = True, batch=False, **kw</string> </value> <value> <string>result, redirect_to_defect_dialog = True, batch=False, fast_post = False, **kw</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
web_page_module/gadget_post_ok_for_quality_control**
\ No newline at end of file
portal_alarms/psa_quality_assurance_builder_alarm portal_alarms/psa_quality_assurance_builder_alarm
\ No newline at end of file web_page_module/gadget_post_ok_for_quality_control**
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment