counter_click.jinja 6.07 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
37
38
39
40
41
    <div>
        {% 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>
Skia's avatar
Skia committed
42
        {% endif %}
Skia's avatar
Skia committed
43
44
45
        {% if request.session['no_age'] %}
        <p><strong>{% trans %}No date of birth provided{% endtrans %}</strong></p>
        {% endif %}
Skia's avatar
Skia committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
        {% if request.session['not_enough'] %}
        <p><strong>{% trans %}Not enough money{% endtrans %}</strong></p>
        {% endif %}
        <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">
            <input type="input" name="code" value="" autofocus id="code_field"/>
            <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
60
            <li>{{ del_product(id, '-', "inline") }} {{ infos['qty'] + infos['bonus_qty'] }} {{ add_product(id, '+', "inline") }}
Skia's avatar
Skia committed
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
            {{ 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>
        <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>
90
    {% endif %}
Skia's avatar
Skia committed
91
92
</div>
<div id="products">
93
94
95
96
97
98
99
    <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
100
101
    {% for t in categories -%}
    {%- if counter.products.filter(product_type=t).exists() -%}
102
103
    <div id="cat_{{ t|slugify }}">
        <h5>{{ t }}</h5>
Skia's avatar
Skia committed
104
        {% for p in counter.products.filter(product_type=t).all() -%}
Skia's avatar
Skia committed
105
106
107
108
109
110
111
            {% 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
112
                {{ add_product(p.id, prod, "form_button") }}
Skia's avatar
Skia committed
113
        {%- endfor %}
114
    </div>
Skia's avatar
Skia committed
115
116
    {%- endif -%}
    {%- endfor %}
Skia's avatar
Skia committed
117
</div>
118

Skia's avatar
Skia committed
119
120
{% endblock %}

121
122
123
124
125
{% block script %}
{{ super() }}
<script>
$( function() {
    var products = [
Skia's avatar
Skia committed
126
    {% for p in counter.products.all() -%}
127
128
129
130
131
        {
            value: "{{ p.code }}",
            label: "{{ p.name }}",
            tags: "{{ p.code }} {{ p.name }}",
        },
Skia's avatar
Skia committed
132
    {%- endfor %}
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
    ];
    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
158
159
160
161
$( function() {
    $("#bar_ui").accordion({
        heightStyle: "content",
        });
162
    $("#products").tabs();
Skia's avatar
Skia committed
163
});
164
165
166
</script>
{% endblock %}

Skia's avatar
Skia committed
167
168