summaryrefslogtreecommitdiff
path: root/archaeological_files/templates/ishtar/forms/preventive_detail.html
blob: 1d743c615766c6dcd9199972f8ad4d2260c94d89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
{% extends "ishtar/forms/base_form.html" %}
{% load i18n table_form %}

{% block bs_form_inlines %}
<div class="card">
  <div class="card-body">
    <div class="w-100 pb-3 text-center">
      <div class="btn-group btn-group-toggle" data-toggle="buttons">
        <label class="btn btn-lg btn-secondary active">
          <input value="true" type="radio" name="planned-toggle" id="planned-toggle-true" autocomplete="off" checked>
          {% trans "Planned" %}
        </label>
        <label class="btn btn-lg btn-secondary">
          <input value="false" type="radio" name="planned-toggle" id="planned-toggle-false" autocomplete="off">
          {% trans "Worked" %}
        </label>
      </div>
    </div>
    <div class="w-100 pb-3 text-center form-group">
      <a class="btn btn-secondary btn-sm form-planned" type="button"
         href="{% url 'file-edit-preventive-default-cost' file.pk %}">
        {% trans "Add default costs" %}
      </a>
    </div>
    <div class="w-100 pb-3 text-center form-group">
      <a class="btn btn-secondary btn-sm form-worked" type="button"
         href="{% url 'file-edit-preventive-copy-planned' file.pk %}">
        {% trans "Copy planned costs" %}
      </a>
    </div>
    {% for inline in inline_forms %}
    <h4>{{inline.form_label}}</h4>
    {% bs_formset inline 0 True %}
    {% endfor %}
  </div>
</div>
{% endblock %}

{# <script type='text/javascript'> #}
{% block end_js %}
  {{block.super}}
  var check_planned_value = function() {
    if ($('#planned-toggle-true').is(":checked") === false){
      $(".form-planned").closest("div.form-group").hide()
      $(".form-worked").closest("div.form-group").show()
    } else {
      $(".form-planned").closest("div.form-group").show()
      $(".form-worked").closest("div.form-group").hide()
    }
  };

  const cost_units = {{% for unit_pk, value in form_unities %}{% if forloop.counter0 %},{% endif %}
    {{unit_pk}}: "{{value}}"{% endfor %}
  };
  const flat_rates = [{% for pk in form_flat_rates %}{% if forloop.counter0 %},{% endif %}
    "{{pk}}"{% endfor %}
  ];
  var update_units = function() {
    $(".form-cost").each(function(){
      var unit = cost_units[$(this).val()];
      if (!unit){
        unit = "...";
      }
      $(this).parent().parent().find(".unit-label").html(unit);
      if (flat_rates.indexOf($(this).val()) != -1){
        $(this).parent().parent().find(".unit-form").prop("disabled", true);
      } else {
        $(this).parent().parent().find(".unit-form").prop("disabled", false);
      }
      check_planned_value();
    });
  };
  $(document).ready(function(){
    $('input[type=radio][name=planned-toggle]').change(check_planned_value);
    $(".form-cost").change(update_units);
    check_planned_value();
    update_units();
  });
{% endblock %}
{# </script> #}
{% block extra_validation_button %}
<div class="col-sm">
  <a href="{% url 'display-item' 'file' file.pk %}" class="btn btn-secondary" role="button" aria-pressed="true">
    {% trans "Back to the file" %}
  </a>
</div>
{% endblock %}