Simplified modal calls

- Default modal target supplied (can be overridden in options)
This commit is contained in:
Oliver 2018-05-08 19:55:39 +10:00
parent c5155d5ac7
commit 3f1c6e2059
16 changed files with 55 additions and 43 deletions

View File

@ -83,16 +83,14 @@
{% block js_ready %}
{{ block.super }}
$("#edit-build").click(function () {
launchModalForm("#modal-form",
"{% url 'build-edit' build.id %}",
launchModalForm("{% url 'build-edit' build.id %}",
{
reload: true
});
});
$("#cancel-build").click(function() {
launchModalForm("#modal-form",
"{% url 'build-cancel' build.id %}",
launchModalForm("{% url 'build-cancel' build.id %}",
{
reload: true
});

View File

@ -31,7 +31,7 @@
{% block js_ready %}
{{ block.super }}
$("#new-build").click(function() {
launchModalForm("#modal-form",
launchModalForm(
"{% url 'build-create' %}",
{
follow: true

View File

@ -69,7 +69,7 @@
{% block js_ready %}
$("#company-thumb").click(function() {
launchModalForm("#modal-form",
launchModalForm(
"{% url 'company-image' company.id %}",
{
reload: true

View File

@ -46,7 +46,7 @@
{% block js_ready %}
{{ block.super }}
$('#edit-company').click(function() {
launchModalForm("#modal-form",
launchModalForm(
"{% url 'company-edit' company.id %}",
{
reload: true
@ -54,7 +54,7 @@
});
$('#delete-company').click(function() {
launchDeleteForm("#modal-delete",
launchDeleteForm(
"{% url 'company-delete' company.id %}",
{
redirect: "{% url 'company-index' %}"

View File

@ -18,7 +18,7 @@
{{ block.super }}
$("#part-create").click(function () {
launchModalForm("#modal-form",
launchModalForm(
"{% url 'supplier-part-create' %}",
{
data: {

View File

@ -41,7 +41,7 @@
{% block js_ready %}
{{ block.super }}
$('#part-edit').click(function () {
launchModalForm("#modal-form",
launchModalForm(
"{% url 'supplier-part-edit' part.id %}",
{
reload: true
@ -50,7 +50,7 @@
});
$('#part-delete').click(function() {
launchDeleteForm("#modal-delete",
launchDeleteForm(
"{% url 'supplier-part-delete' part.id %}",
{
redirect: "{% url 'company-index' %}"

View File

@ -28,7 +28,7 @@
$('#bom-table').on('click', '.delete-button', function () {
var button = $(this);
launchDeleteForm("#modal-delete",
launchDeleteForm(
button.attr('url'),
{
success: reloadBom
@ -38,7 +38,7 @@
$("#bom-table").on('click', '.edit-button', function () {
var button = $(this);
launchModalForm("#modal-form",
launchModalForm(
button.attr('url'),
{
success: reloadBom
@ -47,7 +47,7 @@
});
$("#new-bom-item").click(function () {
launchModalForm("#modal-form",
launchModalForm(
"{% url 'bom-item-create' %}",
{
reload: true,

View File

@ -40,7 +40,7 @@
{% block js_ready %}
{{ block.super }}
$("#start-build").click(function() {
launchModalForm("#modal-form",
launchModalForm(
"{% url 'build-create' %}",
{
follow: true,

View File

@ -53,7 +53,7 @@
{{ block.super }}
$("#cat-create").click(function() {
launchModalForm("#modal-form",
launchModalForm(
"{% url 'category-create' %}",
{
follow: true,
@ -66,7 +66,7 @@
})
$("#part-create").click(function() {
launchModalForm("#modal-form",
launchModalForm(
"{% url 'part-create' %}",
{
follow: true,
@ -80,7 +80,7 @@
{% if category %}
$("#cat-edit").click(function () {
launchModalForm("#modal-form",
launchModalForm(
"{% url 'category-edit' category.id %}",
{
reload: true
@ -96,8 +96,7 @@
{% endif %}
$('#cat-delete').click(function() {
launchDeleteForm('#modal-delete',
"{% url 'category-delete' category.id %}",
launchDeleteForm("{% url 'category-delete' category.id %}",
{
redirect: redirect
});

View File

@ -102,7 +102,7 @@
{% block js_ready %}
{{ block.super }}
$("#edit-part").click(function() {
launchModalForm("#modal-form",
launchModalForm(
"{% url 'part-edit' part.id %}",
{
reload: true,
@ -110,7 +110,7 @@
});
$('#delete-part').click(function() {
launchDeleteForm("#modal-delete",
launchDeleteForm(
"{% url 'part-delete' part.id %}",
{
redirect: {% if part.category %}"{% url 'category-detail' part.category.id %}"{% else %}"{% url 'part-index' %}"{% endif %}

View File

@ -81,7 +81,7 @@
{% block js_ready %}
{{ block.super }}
$("#part-thumb").click(function() {
launchModalForm("#modal-form",
launchModalForm(
"{% url 'part-image' part.id %}",
{
reload: true

View File

@ -42,7 +42,7 @@
{{ block.super }}
$('#add-stock-item').click(function () {
launchModalForm("#modal-form",
launchModalForm(
"{% url 'stock-item-create' %}",
{
reload: true,

View File

@ -29,7 +29,7 @@
{{ block.super }}
$('#supplier-create').click(function () {
launchModalForm("#modal-form",
launchModalForm(
"{% url 'supplier-part-create' %}",
{
reload: true,

View File

@ -94,12 +94,22 @@ function openModal(modal, title='', content='') {
}
function launchDeleteForm(modal, url, options = {}) {
function launchDeleteForm(url, options = {}) {
var modal = '#modal-delete';
if (options.modal) {
modal = options.modal;
}
$(modal).on('shown.bs.modal', function() {
$(modal + ' .modal-form-content').scrollTop(0);
});
// Un-bind any attached click listeners
$(modal).off('click', '#modal-form-delete');
// Request delete form data
$.ajax({
url: url,
type: 'get',
@ -125,9 +135,6 @@ function launchDeleteForm(modal, url, options = {}) {
}
});
// Un-bind any attached click listeners
$(modal).off('click', '#modal-form-delete');
$(modal).on('click', '#modal-form-delete', function() {
var form = $(modal).find('#delete-form');
@ -155,7 +162,13 @@ function injectModalForm(modal, form_html) {
attachSelect(modal);
}
function handleModalForm(modal, url, options) {
function handleModalForm(url, options) {
var modal = '#modal-form';
if (options.modal) {
modal = options.modal;
}
var form = $(modal).find('.js-modal-form');
@ -217,7 +230,13 @@ function handleModalForm(modal, url, options) {
* Opens a model window and fills it with a requested form
* If the form is loaded successfully, calls handleModalForm
*/
function launchModalForm(modal, url, options = {}) {
function launchModalForm(url, options = {}) {
var modal = '#modal-form';
if (options.modal) {
modal = options.modal;
}
// Form the ajax request to retrieve the django form data
ajax_data = {

View File

@ -132,7 +132,7 @@
{% block js_ready %}
{{ block.super }}
$("#stock-edit").click(function () {
launchModalForm("#modal-form",
launchModalForm(
"{% url 'stock-item-edit' item.id %}",
{
reload: true
@ -141,7 +141,7 @@
{% if item.in_stock %}
$("#stock-move").click(function() {
launchModalForm("#modal-form",
launchModalForm(
"{% url 'stock-item-move' item.id %}",
{
reload: true,
@ -149,7 +149,7 @@
});
$("#stock-stocktake").click(function() {
launchModalForm("#modal-form",
launchModalForm(
"{% url 'stock-item-stocktake' item.id %}",
{
reload: true
@ -159,7 +159,7 @@
{% endif %}
$("#stock-delete").click(function () {
launchDeleteForm("#modal-delete",
launchDeleteForm(
"{% url 'stock-item-delete' item.id %}",
{
redirect: "{% url 'part-stock' item.part.id %}"

View File

@ -65,8 +65,7 @@
{% block js_ready %}
{{ block.super }}
$('#location-create').click(function () {
launchModalForm("#modal-form",
"{% url 'stock-location-create' %}",
launchModalForm("{% url 'stock-location-create' %}",
{
data: {
{% if location %}
@ -80,8 +79,7 @@
{% if location %}
$('#location-edit').click(function() {
launchModalForm("#modal-form",
"{% url 'stock-location-edit' location.id %}",
launchModalForm("{% url 'stock-location-edit' location.id %}",
{
reload: true
});
@ -89,8 +87,7 @@
});
$('#location-delete').click(function() {
launchDeleteForm("#modal-delete",
"{% url 'stock-location-delete' location.id %}",
launchDeleteForm("{% url 'stock-location-delete' location.id %}",
{
redirect: "{% url 'stock-index' %}"
});
@ -100,8 +97,7 @@
{% endif %}
$('#item-create').click(function () {
launchModalForm("#modal-form",
"{% url 'stock-item-create' %}",
launchModalForm("{% url 'stock-item-create' %}",
{
success: function() {
$("#stock-table").bootstrapTable('refresh');