!function(o){var a=function(a){o(a.submitBtn).on("click",function(o){n(a,t)}),o(a.modalID).on("hidden.bs.modal",function(n){o(a.modalForm).remove()})},n=function(n,t){o.ajax({type:o(n.modalForm).attr("method"),url:o(n.modalForm).attr("action"),data:o(n.modalForm).serialize(),beforeSend:function(){o(n.submitBtn).prop("disabled",!0)},success:function(s){o(s).find(n.errorClass).length>0?(o(n.modalID).find(n.modalContent).html(s),o(n.modalForm).attr("action",n.formURL),a(n)):t(n)}})},t=function(n){if(n.asyncUpdate){var t=s(n.asyncSettings),d=n.asyncSettings;t&&o.ajax({type:o(n.modalForm).attr("method"),url:o(n.modalForm).attr("action"),data:o(n.modalForm).serialize()+"&asyncUpdate=True",success:function(t){var s=o("body");0===s.length&&console.error("django-bootstrap-modal-forms: <body> element missing in your html."),s.prepend(d.successMessage),o.ajax({type:"GET",url:d.dataUrl,dataType:"json",success:function(t){o(d.dataElementId).html(t[d.dataKey]),d.addModalFormFunction&&d.addModalFormFunction(),d.closeOnSubmit?o(n.modalID).modal("hide"):o(n.modalID).find(n.modalContent).load(n.formURL,function(){o(n.modalForm).attr("action",n.formURL),a(n)})}})}})}else o(n.modalForm).submit()},s=function(o){var a=[];return o.successMessage||(a.push("successMessage"),console.error("django-bootstrap-modal-forms: 'successMessage' in asyncSettings is missing.")),o.dataUrl||(a.push("dataUrl"),console.error("django-bootstrap-modal-forms: 'dataUrl' in asyncSettings is missing.")),o.dataElementId||(a.push("dataElementId"),console.error("django-bootstrap-modal-forms: 'dataElementId' in asyncSettings is missing.")),o.dataKey||(a.push("dataKey"),console.error("django-bootstrap-modal-forms: 'dataKey' in asyncSettings is missing.")),o.addModalFormFunction||(a.push("addModalFormFunction"),console.error("django-bootstrap-modal-forms: 'addModalFormFunction' in asyncSettings is missing.")),!(a.length>0)};o.fn.modalForm=function(n){var t=o.extend({modalID:"#modal",modalContent:".modal-content",modalForm:".modal-content form",formURL:null,errorClass:".invalid",submitBtn:".submit-btn",asyncUpdate:!1,asyncSettings:{closeOnSubmit:!1,successMessage:null,dataUrl:null,dataElementId:null,dataKey:null,addModalFormFunction:null}},n);return this.each(function(){o(this).click(function(n){!function(n){o(n.modalID).find(n.modalContent).load(n.formURL,function(){o(n.modalID).modal("show"),o(n.modalForm).attr("action",n.formURL),a(n)})}(t)})}),this}}(jQuery);