counter_click.jinja 6.92 KB
Newer Older
Skia's avatar
Skia committed
1
{% extends "core/base.jinja" %}
2
{% from "core/macros.jinja" import user_mini_profile, user_subscription %}
3

Skia's avatar
Skia committed
4

Skia's avatar
Skia committed
5
6
{% macro add_product(id, content, class="") %}
<form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}" class="{{ class }}">
Skia's avatar
Skia committed
7
    {% csrf_token %}
8
    <input type="hidden" name="action" value="add_product">
Skia's avatar
Skia committed
9
    <button type="submit" name="product_id" value="{{ id }}"> {{ content|safe }} </button>
10
11
12
</form>
{% endmacro %}

Skia's avatar
Skia committed
13
14
{% macro del_product(id, content, class="") %}
<form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}" class="{{ class }}">
15
16
17
    {% csrf_token %}
    <input type="hidden" name="action" value="del_product">
    <button type="submit" name="product_id" value="{{ id }}"> {{ content }} </button>
Skia's avatar
Skia committed
18
19
20
</form>
{% endmacro %}

21
22
23
24
{% block title %}
{{ counter }}
{% endblock %}

Skia's avatar
Skia committed
25
{% block content %}
Skia's avatar
Skia committed
26
<h4>{{ counter }}</h4>
Skia's avatar
Skia committed
27

28
<div id="user_info">
Skia's avatar
Skia committed
29
    <h5>{% trans %}Customer{% endtrans %}</h5>
30
    {{ user_mini_profile(customer.user) }}
31
    {{ user_subscription(customer.user) }}
32
    <p>{% trans %}Amount: {% endtrans %}{{ customer.amount }}</p>
Skia's avatar
Skia committed
33
</div>
Skia's avatar
Skia committed
34
<div id="bar_ui">
Skia's avatar
Skia committed
35
    <h5>{% trans %}Selling{% endtrans %}</h5>
Skia's avatar
Skia committed
36
    <div>
Skia's avatar
Skia committed
37
38
39
40
41
42
43
44
45
46
47
48
49
50
        <div class="important">
            {% if request.session['too_young'] %}
            <p><strong>{% trans %}Too young for that product{% endtrans %}</strong></p>
            {% endif %}
            {% if request.session['not_allowed'] %}
            <p><strong>{% trans %}Not allowed for that product{% endtrans %}</strong></p>
            {% endif %}
            {% if request.session['no_age'] %}
            <p><strong>{% trans %}No date of birth provided{% endtrans %}</strong></p>
            {% endif %}
            {% if request.session['not_enough'] %}
            <p><strong>{% trans %}Not enough money{% endtrans %}</strong></p>
            {% endif %}
        </div>
Skia's avatar
Skia committed
51
52
53
        <form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}">
            {% csrf_token %}
            <input type="hidden" name="action" value="code">
54
            <input type="input" name="code" value="" autofocus class="focus" id="code_field"/>
Skia's avatar
Skia committed
55
56
57
58
59
60
61
            <input type="submit" value="{% trans %}Go{% endtrans %}" />
        </form>
        <p>{% trans %}Basket: {% endtrans %}</p>
        <ul>
            {% for id,infos in request.session['basket']|dictsort %}
            {% set product = counter.products.filter(id=id).first() %}
            {% set s = infos['qty'] * infos['price'] / 100 %}
Skia's avatar
Skia committed
62
            <li>{{ del_product(id, '-', "inline") }} {{ infos['qty'] + infos['bonus_qty'] }} {{ add_product(id, '+', "inline") }}
Skia's avatar
Skia committed
63
64
65
66
67
68
69
70
            {{ product.name }}: {{ "%0.2f"|format(s) }}
            {% if infos['bonus_qty'] %}
                P
            {% endif %}
            </li>
            {% endfor %}
        </ul>
        <p><strong>{% trans %}Total: {% endtrans %}{{ "%0.2f"|format(basket_total) }}</strong></p>
Skia's avatar
Skia committed
71
72
73
74
75
76
77
78
79
80
81
82
83
84
        <div class="important">
            {% if request.session['too_young'] %}
            <p><strong>{% trans %}Too young for that product{% endtrans %}</strong></p>
            {% endif %}
            {% if request.session['not_allowed'] %}
            <p><strong>{% trans %}Not allowed for that product{% endtrans %}</strong></p>
            {% endif %}
            {% if request.session['no_age'] %}
            <p><strong>{% trans %}No date of birth provided{% endtrans %}</strong></p>
            {% endif %}
            {% if request.session['not_enough'] %}
            <p><strong>{% trans %}Not enough money{% endtrans %}</strong></p>
            {% endif %}
        </div>
Skia's avatar
Skia committed
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
        <form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}">
            {% csrf_token %}
            <input type="hidden" name="action" value="finish">
            <input type="submit" value="{% trans %}Finish{% endtrans %}" />
        </form>
        <form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}">
            {% csrf_token %}
            <input type="hidden" name="action" value="cancel">
            <input type="submit" value="{% trans %}Cancel{% endtrans %}" />
        </form>
    </div>
    {% if counter.type == 'BAR' %}
    <h5>{% trans %}Refilling{% endtrans %}</h5>
    <div>
        <form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}">
            {% csrf_token %}
            {{ refill_form.as_p() }}
            <input type="hidden" name="action" value="refill">
            <input type="submit" value="{% trans %}Go{% endtrans %}" />
        </form>
    </div>
106
    {% endif %}
Skia's avatar
Skia committed
107
108
</div>
<div id="products">
109
110
111
112
113
114
115
    <ul>
        {% for t in categories -%}
        {%- if counter.products.filter(product_type=t).exists() -%}
        <li><a href="#cat_{{ t|slugify }}">{{ t }}</a></li>
        {%- endif -%}
        {%- endfor %}
    </ul>
Skia's avatar
Skia committed
116
117
    {% for t in categories -%}
    {%- if counter.products.filter(product_type=t).exists() -%}
118
119
    <div id="cat_{{ t|slugify }}">
        <h5>{{ t }}</h5>
Skia's avatar
Skia committed
120
        {% for p in counter.products.filter(product_type=t).all() -%}
Skia's avatar
Skia committed
121
122
123
124
125
126
127
            {% set file = None %}
            {% if p.icon %}
                {% set file = p.icon.url %}
            {% else %}
                {% set file = static('core/img/na.gif') %}
            {% endif %}
            {% set prod = '<strong>%s</strong><hr><img src="%s" /><span>%s €<br>%s</span>' % (p.name, file, p.selling_price, p.code) %}
Skia's avatar
Skia committed
128
                {{ add_product(p.id, prod, "form_button") }}
Skia's avatar
Skia committed
129
        {%- endfor %}
130
    </div>
Skia's avatar
Skia committed
131
132
    {%- endif -%}
    {%- endfor %}
Skia's avatar
Skia committed
133
</div>
134

Skia's avatar
Skia committed
135
136
{% endblock %}

137
138
139
140
141
{% block script %}
{{ super() }}
<script>
$( function() {
    var products = [
Skia's avatar
Skia committed
142
    {% for p in counter.products.all() -%}
143
144
145
146
147
        {
            value: "{{ p.code }}",
            label: "{{ p.name }}",
            tags: "{{ p.code }} {{ p.name }}",
        },
Skia's avatar
Skia committed
148
    {%- endfor %}
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
    ];
    var quantity = "";
    var search = "";
    var pattern = /^(\d+x)?(.*)/i;
    $( "#code_field" ).autocomplete({
        select: function (event, ui) {
            event.preventDefault();
            $("#code_field").val(quantity + ui.item.value);
        },
        focus: function (event, ui) {
            event.preventDefault();
            $("#code_field").val(quantity + ui.item.value);
        },
        source: function( request, response ) {
            var res = pattern.exec(request.term);
            quantity = res[1] || "";
            search = res[2];
            var matcher = new RegExp( $.ui.autocomplete.escapeRegex( search ), "i" );
            response($.grep( products, function( value ) {
                value = value.tags;
                return matcher.test( value );
            }));
        },
    });
});
Skia's avatar
Skia committed
174
175
176
$( function() {
    $("#bar_ui").accordion({
        heightStyle: "content",
177
178
179
        activate: function(event, ui){
            $(".focus").focus();
        }
Skia's avatar
Skia committed
180
        });
181
    $("#products").tabs();
Skia's avatar
Skia committed
182
});
183
184
185
</script>
{% endblock %}

Skia's avatar
Skia committed
186
187