mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-01 04:10:06 -05:00
100 lines
3.6 KiB
HTML
100 lines
3.6 KiB
HTML
{% extends "base.html" %}
|
|
{% load crispy_forms_tags %}
|
|
{% load i18n %}
|
|
{% load custom_tags %}
|
|
|
|
{% block title %}{% trans 'Edit Recipe' %}{% endblock %}
|
|
|
|
{% block extra_head %}
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/tabulator/4.4.3/js/tabulator.min.js"
|
|
integrity="sha256-u2YCVBkzzkIuLh6bMHUmqv6uuuHLxGgc6XF+rCJUV5k=" crossorigin="anonymous"></script>
|
|
<link rel="stylesheet"
|
|
href="https://cdnjs.cloudflare.com/ajax/libs/tabulator/4.4.3/css/bootstrap/tabulator_bootstrap4.min.css"
|
|
integrity="sha256-+AmauyGZPl0HNTBQ5AMZBxfzP+rzXJjraezMKpWwWSE=" crossorigin="anonymous"/>
|
|
{% endblock %}
|
|
|
|
{% block content %}
|
|
|
|
<h3>{% trans 'Edit Recipe' %}</h3>
|
|
|
|
<form action="." method="post">
|
|
{% csrf_token %}
|
|
{{ form|crispy }}
|
|
<div id="ingredients-table"></div>
|
|
<br>
|
|
<div class="table-controls">
|
|
<button class="btn" id="new_empty" type="button"><i class="far fa-plus"></i></button>
|
|
</div>
|
|
|
|
<input type="hidden" id="ingredients_data_input" name="ingredients">
|
|
<hr>
|
|
<input type="submit" value="Submit" class="btn btn-success">
|
|
<a href="{% url 'redirect_delete' form.instance|get_class|lower form.instance.pk %}"
|
|
class="btn btn-danger">{% trans 'Delete' %}</a>
|
|
{% if view_url %}
|
|
<a href="{{ view_url }}" class="btn btn-info">{% trans 'View' %} <i class="far fa-eye"></i></a>
|
|
{% endif %}
|
|
</form>
|
|
|
|
<script>
|
|
//converts multiselct in recipe edit to searchable multiselect
|
|
//shitty solution that needs to be redone at some point
|
|
$(document).ready(function () {
|
|
$('#id_keywords').select2();
|
|
|
|
var ingredients = {{ ingredients|safe }}
|
|
|
|
ingredients.forEach(function (cur, i) {
|
|
cur.delete = false
|
|
})
|
|
|
|
var data = ingredients
|
|
|
|
var table = new Tabulator("#ingredients-table", {
|
|
index: "id",
|
|
layout: "fitColumns",
|
|
reactiveData: true,
|
|
data: data,
|
|
columns: [
|
|
{
|
|
title: "{% trans 'ingredient' %}",
|
|
field: "ingredient",
|
|
validator: "required",
|
|
editor: "input"
|
|
},
|
|
{title: "{% trans 'amount' %}", field: "amount", validator: "required", editor: "input"},
|
|
{title: "{% trans 'unit' %}", field: "unit", validator: "required", editor: "input"},
|
|
{
|
|
title: "{% trans 'delete' %}",
|
|
field: "delete",
|
|
align: "center",
|
|
editor: true,
|
|
formatter: "tickCross"
|
|
},
|
|
{title: "id", field: "id", visible: false}
|
|
],
|
|
dataEdited: function (data) {
|
|
$('#ingredients_data_input').val(JSON.stringify(data))
|
|
|
|
data.forEach(function (cur, i) {
|
|
if (cur.delete) {
|
|
table.deleteRow(cur.id);
|
|
}
|
|
})
|
|
}
|
|
});
|
|
|
|
|
|
document.getElementById("new_empty").addEventListener("click", function () {
|
|
data.push({
|
|
ingredient: "{% trans 'ingredient' %}",
|
|
amount: "100",
|
|
unit: "g",
|
|
id: Math.floor(Math.random() * 10000000),
|
|
delete: false,
|
|
});
|
|
});
|
|
});
|
|
|
|
</script>
|
|
{% endblock %} |