blob: 59ebb8278d5e03dbc5c263f1c4bf078581090741 (
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
{% extends "ishtar/forms/base_form.html" %}
{% load i18n table_form %}
{% block form_head %}
<div class="text-right">
<a class="btn btn-success mb-3" href="{% url 'file-edit-preventive-price' file.pk %}">
<i class="fa fa-pencil" aria-hidden="true"></i>
{% trans "Change price agreement" %}
</a>
</div>
{% endblock %}
{% 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" id="add-default-costs-div">
<a class="btn btn-secondary btn-sm form-planned" type="button"
id="add-default-costs"
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" id="copy-planned-costs-div">
<a class="btn btn-secondary btn-sm form-worked" type="button"
id="copy-planned-costs"
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>
<input type="hidden" id="current_tab" name="current_tab" value="{{current_tab}}"/>
{% endblock %}
{# <script type='text/javascript'> #}
{% block end_js %}
{{block.super}}
const 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();
$("#current_tab").val("worked");
} else {
$(".form-planned").closest("div.form-group").show();
$(".form-worked").closest("div.form-group").hide();
$("#current_tab").val("planned");
}
};
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(){
{% if current_tab == "worked" %}$('#planned-toggle-false').click();{% endif %}
$('input[type=radio][name=planned-toggle]').change(check_planned_value);
$(".form-cost").change(update_units);
$(":input").change(
function(){
$("#add-default-costs").addClass("disabled");
$("#copy-planned-costs").addClass("disabled");
let disabled_msg = "{% trans 'The form has changed. Submit your modifications first.' %}";
$("#add-default-costs-div").attr("title", disabled_msg);
$("#copy-planned-costs-div").attr("title", disabled_msg);
}
);
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 %}
|