Simplified javascript templating

- Load js modules in block js_load
- Write $(document).ready script in block js_ready
- Write any other js in block_js
This commit is contained in:
Oliver 2018-04-28 12:45:12 +10:00
parent 7ebb723d15
commit 095492203f
18 changed files with 68 additions and 138 deletions

View File

@ -64,14 +64,12 @@
{% endblock %}
{% block javascript %}
{% block js_load %}
<script type='text/javascript' src="{% static 'script/footable.js' %}"></script>
<script type='text/javascript' src="{% static 'script/modal_form.js' %}"></script>
{% endblock %}
<script type='text/javascript'>
$(document).ready(function () {
{% block js_ready %}
$("#build-list").footable();
$("#edit-build").click(function () {
@ -81,8 +79,4 @@ $(document).ready(function () {
reload: true
});
});
});
</script>
{% endblock %}
{% endblock %}

View File

@ -22,15 +22,10 @@
{% endblock %}
{% block javascript %}
{% block js_load %}
<script type='text/javascript' src="{% static 'script/footable.js' %}"></script>
<script type='text/javascript' src="{% static 'script/modal_form.js' %}"></script>
<script type="text/javascript">
$(document).ready(function () {
{% endblock %}
{% block js_ready %}
$('#build-list').footable();
});
</script>
{% endblock %}

View File

@ -33,11 +33,10 @@
{% endblock %}
{% block javascript %}
{% block js_load %}
<script type='text/javascript' src="{% static 'script/modal_form.js' %}"></script>
<script type='text/javascript'>
$(document).ready(function() {
{% endblock %}
{% block js_ready %}
$('#edit-company').click(function() {
launchModalForm("#modal-form",
"{% url 'company-edit' company.id %}",
@ -52,9 +51,5 @@ $(document).ready(function() {
{
redirect: "{% url 'company-index' %}"
});
})
});
</script>
});
{% endblock %}

View File

@ -39,15 +39,11 @@
{% endblock %}
{% block javascript %}
{% block js_load %}
<script type='text/javascript' src="{% static 'script/footable.js' %}"></script>
<script type='text/javascript' src="{% static 'script/modal_form.js' %}"></script>
<script type="text/javascript">
$(document).ready(function () {
{% endblock %}
{% block js_ready %}
$("#part-list").footable();
$("#part-create").click(function () {
@ -60,8 +56,4 @@ $(document).ready(function () {
reload: true,
});
});
});
</script>
{% endblock %}

View File

@ -36,13 +36,11 @@
{% endblock %}
{% block javascript %}
{% block js_load %}
<script type='text/javascript' src="{% static 'script/footable.js' %}"></script>
<script type='text/javascript' src="{% static 'script/modal_form.js' %}"></script>
<script type='text/javascript'>
$(document).ready(function() {
{% endblock %}
{% block js_ready %}
$('#company-table').footable();
$('#new-company').click(function () {
@ -52,7 +50,4 @@ $(document).ready(function() {
follow: true
});
});
});
</script>
{% endblock %}

View File

@ -38,13 +38,10 @@
{% endblock %}
{% block javascript %}
{% block js_load %}
<script type='text/javascript' src="{% static 'script/modal_form.js' %}"></script>
<script type='text/javascript'>
$(document).ready(function () {
{% endblock %}
{% block js_ready %}
$('#part-edit').click(function () {
launchModalForm("#modal-form",
"{% url 'supplier-part-edit' part.id %}",
@ -62,7 +59,4 @@ $(document).ready(function () {
}
);
});
});
</script>
{% endblock %}

View File

@ -47,13 +47,11 @@
{% endblock %}
{% block javascript %}
{% block js_load %}
<script type='text/javascript' src="{% static 'script/footable.js' %}"></script>
<script type='text/javascript' src="{% static 'script/modal_form.js' %}"></script>
<script type='text/javascript'>
$(document).ready(function(){
{% endblock %}
{% block js_ready %}
$('#bom-table').footable();
$('#bom-table').on('click', '.delete-row-button', function () {
@ -84,7 +82,4 @@ $(document).ready(function(){
}
});
});
});
</script>
{% endblock %}

View File

@ -39,12 +39,10 @@
{% endblock %}
{% block javascript %}
{% block js_load %}
<script type='text/javascript' src="{% static 'script/modal_form.js' %}"></script>
<script type='text/javascript'>
$(document).ready(function() {
{% endblock %}
{% block js_ready %}
$("#start-build").click(function() {
launchModalForm("#modal-form",
"{% url 'build-create' %}",
@ -55,7 +53,4 @@ $(document).ready(function() {
}
});
});
});
</script>
{% endblock %}

View File

@ -35,12 +35,11 @@
{% endblock %}
{% block javascript %}
{% block js_load %}
<script type='text/javascript' src="{% static 'script/footable.js' %}"></script>``
<script type='text/javascript' src="{% static 'script/modal_form.js' %}"></script>
<script type='text/javascript'>
$(document).ready(function (){
{% endblock %}
{% block js_ready %}
$('#part-list').footable();
$("#edit-category").click(function () {
@ -85,7 +84,4 @@ $(document).ready(function (){
reload: true
});
});
});
</script>
{% endblock %}

View File

@ -88,12 +88,12 @@
{% endblock %}
{% block javascript %}
{% block js_load %}
<script type='text/javascript' src="{% static 'script/modal_form.js' %}"></script>
{% endblock %}
{% block js_ready %}
<script type="text/javascript">
$(document).ready(function () {
$("#edit-part").click(function() {
launchModalForm("#modal-form", "{% url 'part-edit' part.id %}");
});
@ -104,7 +104,4 @@ $(document).ready(function () {
{redirect: "{% url 'part-index' %}"}
);
});
});
</script>
{% endblock %}

View File

@ -1,6 +1,10 @@
{% extends "base.html" %}
{% load static %}
{% block css %}
<link rel='stylesheet' href="{% static 'css/bootstrap-treeview.css' %}">
{% endblock %}
{% block content %}
{% include "part/cat_link.html" with category=category %}
@ -23,13 +27,13 @@
</div>
{% endblock %}
{% block javascript %}
{% block js_load %}
<script type='text/javascript' src="{% static 'script/footable.js' %}"></script>
<script type='text/javascript' src="{% static 'script/modal_form.js' %}"></script>
<script type="text/javascript">
$(document).ready(function () {
<script type='text/javascript' src="{% static 'script/bootstrap-treeview.js' %}"></script>
{% endblock %}
{% block js_ready %}
$('#part-list').footable();
$("#create-cat").click(function() {
@ -43,7 +47,4 @@ $(document).ready(function () {
$("#create-part").click(function() {
launchModalForm("#modal-form", "{% url 'part-create' %}");
});
});
</script>
{% endblock %}

View File

@ -49,14 +49,12 @@
{% endblock %}
{% block javascript %}
{% block js_load %}
<script type='text/javascript' src="{% static 'script/footable.js' %}"></script>
<script type='text/javascript' src="{% static 'script/modal_form.js' %}"></script>
<script type="text/javascript">
$(document).ready(function () {
{% endblock %}
{% block js_ready %}
$('#stock-table').footable();
$('#add-stock-item').click(function () {
@ -69,7 +67,4 @@ $(document).ready(function () {
}
});
});
});
</script>
{% endblock %}

View File

@ -39,14 +39,12 @@
{% endblock %}
{% block javascript %}
{% block js_load %}
<script type='text/javascript' src="{% static 'script/footable.js' %}"></script>``
<script type='text/javascript' src="{% static 'script/modal_form.js' %}"></script>
<script type='text/javascript'>
$(document).ready(function (){
{% endblock %}
{% block js_ready %}
$('#supplier-table').footable();
$('#supplier-create').click(function () {
@ -57,9 +55,4 @@ $(document).ready(function (){
data: {part: {{ part.id }} }
});
});
});
</script>
{% endblock %}

View File

@ -48,14 +48,12 @@
{% endblock %}
{% block javascript %}
{% block js_load %}
<script type='text/javascript' src="{% static 'script/footable.js' %}"></script>
<script type='text/javascript' src="{% static 'script/modal_form.js' %}"></script>
<script type="text/javascript">
$(document).ready(function () {
{% endblock %}
{% block js_ready %}
$('#stock-table').footable();
$('#location-create').click(function () {
@ -65,9 +63,4 @@ $(document).ready(function () {
follow: true
});
});
});
</script>
{% endblock %}

View File

@ -102,13 +102,12 @@
{% endblock %}
{% block javascript %}
{% block js_load %}
<script type='text/javascript' src="{% static 'script/footable.js' %}"></script>
<script type='text/javascript' src="{% static 'script/modal_form.js' %}"></script>
<script type="text/javascript">
$(document).ready(function () {
{% endblock %}
{% block js_ready %}
$("#edit-item").click(function () {
launchModalForm("#modal-form",
"{% url 'stock-item-edit' item.id %}",
@ -124,8 +123,4 @@ $(document).ready(function () {
redirect: "{% url 'part-stock' item.part.id %}"
});
});
});
</script>
{% endblock %}

View File

@ -27,14 +27,12 @@
{% endblock %}
{% block javascript %}
{% block js_load %}
<script type='text/javascript' src="{% static 'script/footable.js' %}"></script>
<script type='text/javascript' src="{% static 'script/modal_form.js' %}"></script>
<script type="text/javascript">
$(document).ready(function () {
{% endblock %}
{% block js_ready %}
$('#stock-table').footable();
$('#location-create').click(function () {
@ -74,8 +72,4 @@ $(document).ready(function () {
}
});
});
});
</script>
{% endblock %}

View File

@ -5,6 +5,6 @@
{% endblock %}
{% block javascript %}
{% block js_load %}
{% endblock %}

View File

@ -41,9 +41,20 @@ InvenTree
<script type="text/javascript" src="{% static 'script/jquery_3.3.1_jquery.min.js' %}"></script>
<script type="text/javascript" src="{% static 'script/bootstrap.min.js' %}"></script>
<script type="text/javascript" src="{% static 'script/select2/select2.js' %}"></script>
{% block js_load %}
{% endblock %}
{% block javascript %}
<script type='text/javascript'>
$(document).ready(function () {
{% block js_ready %}
{% endblock %}
});
</script>
{% block js %}
{% endblock %}
</body>