Create a new supplier part directly from the order form

This commit is contained in:
Oliver Walters 2019-06-13 20:35:15 +10:00
parent 4be82a31ce
commit 915395e676
2 changed files with 31 additions and 2 deletions

View File

@ -37,7 +37,7 @@
</td> </td>
<td> <td>
<button class='btn btn-default btn-create' id='new_supplier_part_{{ part.id }}' title='Create new supplier part for {{ part }}' type='button'> <button class='btn btn-default btn-create' id='new_supplier_part_{{ part.id }}' title='Create new supplier part for {{ part }}' type='button'>
<span onClick='newSupplierPartFromWizard()' class='glyphicon glyphicon-small glyphicon-plus'></span> <span part-id='{{ part.id }}' onClick='newSupplierPartFromOrderWizard()' class='glyphicon glyphicon-small glyphicon-plus'></span>
</button> </button>
</td> </td>
<td> <td>

View File

@ -9,3 +9,32 @@ function removeOrderRowFromOrderWizard(e) {
$('#' + row).remove(); $('#' + row).remove();
} }
function newSupplierPartFromOrderWizard(e) {
/* Create a new supplier part directly from an order form.
* Launches a secondary modal and (if successful),
* back-populates the selected row.
*/
e = e || window.event;
var src = e.target || e.srcElement;
var part = $(src).attr('part-id');
launchModalForm("/supplier-part/new/", {
modal: '#modal-form-secondary',
data: {
part: part,
},
success: function(response) {
/* A new supplier part has been created! */
var dropdown = '#id_supplier_part_' + part;
var option = new Option(response.text, response.pk, true, true);
$('#modal-form').find(dropdown).append(option).trigger('change');
},
});
}