diff --git a/counter/static/css/main.css b/counter/static/css/main.css index 0bc9c4b..4ce5cd1 100644 --- a/counter/static/css/main.css +++ b/counter/static/css/main.css @@ -69,37 +69,72 @@ form .card-action button { margin-right: auto; } +.edit-arrowcount.title { + font-size: 3rem; +} + +.edit-arrowcount.ends { + text-align: center; + margin: .5rem; + margin-bottom: calc(20px - .5rem); +} + +.edit-arrowcount.ends button { + font-size: 1.5rem; + font-weight: bold; + width: 5.5rem; + height: 4rem; + display: inline-block; + margin: .4rem; +} + #edit-arrowcount-form input, #edit-target-form input { - text-align: center + text-align: center; } #edit-arrowcount-form #id_count, #edit-target-form #id_target { - font-size: 3em; + font-size: 2.5em; padding: .25em 0; } -.count-up, .count-down { +.edit-arrowcount.onebyone { + display: inline-block; width: 100%; + text-align: center; +} + +.count-up, .count-down { + height: 7rem; + font-size: 5rem; + text-align: center; + padding: 0; + font-family: 'Verdana', sans-serif; } .count-up { - height: 8rem; + width: calc(70% - .45rem - 2px); + margin-right: .4rem; } .count-down { - height: 5rem; + width: calc(30% - .45rem - 1px); + margin-left: .4rem; } -.count-up .material-icons { - font-size: 7rem; - line-height: 8rem; -} +@media screen and (max-width: 359px) { + .count-up, .count-down { + width: 100%; + margin-left: 0; + margin-right: 0; + } -.count-down .material-icons { - font-size: 4.5rem; - line-height: 5rem; + .count-down { + height: 4rem; + font-size: 3rem; + margin-top: 1rem; + } } .inline-block { diff --git a/counter/static/js/count_edit.js b/counter/static/js/count_edit.js index 8bb6cd0..ab94ab6 100644 --- a/counter/static/js/count_edit.js +++ b/counter/static/js/count_edit.js @@ -1,4 +1,5 @@ 'use strict'; +// vim: set ts=2 sw=2 et tw=80: var acForm = $('#edit-arrowcount-form'), input = acForm.find('#id_count'); @@ -16,14 +17,35 @@ function arrowCountUpdateAjax() { }); } -$('.count-up').click(function() { +function arrowCountFetchAjax(next) { + $.ajax({ + url: acForm.attr('data-fetch-ajax'), + method: 'GET', + success: function(e) { + if(!e.success) { + M.toast({html: gettext('Error while updating') + ': ' + e.error}) + } else { + next(e.count); + } + } + }); +} + +$('#id_count').keypress(function() { var count = parseInt(input.val(), 10); if(!isNaN(count) && count >= 0) { - input.val(count + 1); arrowCountUpdateAjax(); } }); +$('.count-up').click(function(e) { + var increment = parseInt(e.currentTarget.getAttribute("data-increment")); + arrowCountFetchAjax(function (count) { + input.val(count + increment); + arrowCountUpdateAjax(); + }); +}); + $('.count-down').click(function() { var count = parseInt(input.val(), 10); if(!isNaN(count) && count > 0) { diff --git a/counter/templates/counter/edit.html b/counter/templates/counter/edit.html index 1c1fe1f..6649754 100644 --- a/counter/templates/counter/edit.html +++ b/counter/templates/counter/edit.html @@ -11,8 +11,9 @@ {% endblock %} {% block content %} -

{% trans "Update count" %}

+

{% trans "Update count" %}

@@ -20,17 +21,25 @@
{{ form.as_p }}
-
- +
-
- + {% endfor %} + {% endwith %}
diff --git a/counter/urls.py b/counter/urls.py index acc576e..55b600b 100644 --- a/counter/urls.py +++ b/counter/urls.py @@ -19,4 +19,6 @@ urlpatterns = [ name='count_delete'), path('count/edit//ajax', login_required(views \ .arrow_count_update_ajax), name='count_edit_ajax'), + path('count/get//ajax', login_required(views \ + .arrow_count_fetch_ajax), name='count_fetch_ajax'), ] diff --git a/counter/views.py b/counter/views.py index d0cd8c5..8f2553b 100644 --- a/counter/views.py +++ b/counter/views.py @@ -193,6 +193,29 @@ def target_delete(request): pass return redirect('index') +@login_required +def arrow_count_fetch_ajax(request, ac_id): + count = get_arrowcount(ac_id, request) + if not count[0]: + return count[1] + else: + return JsonResponse({ + 'success': True, + 'count': count[1] + }) + +def get_arrowcount(ac_id, request): + arrow_count = ArrowCount.objects.filter( + id=ac_id, user=request.user)[0] + + if arrow_count == None: + return (False, JsonResponse({ + 'success': False, + 'error': _('ArrowCount instance not found or from different user') + })) + else: + return (True, arrow_count) + @login_required def arrow_count_update_ajax(request, ac_id): try: @@ -209,18 +232,19 @@ def arrow_count_update_ajax(request, ac_id): 'error': _('count is negative or 0') }) - arrow_count = ArrowCount.objects.filter( - id=ac_id, user=request.user)[0] + count = get_arrowcount(ac_id, request) + if not count[0]: + return count[1] + arrow_count.count = count[1] - if arrow_count == None: + try: + arrow_count.save() + except psycopg2.errors.NumericValueOutOfRange: return JsonResponse({ 'success': False, - 'error': _('ArrowCount instance not found or from different user') + 'error': _('count too big') }) - arrow_count.count = count - arrow_count.save() - return JsonResponse({ 'success': True, 'count': arrow_count.count diff --git a/locale/it/LC_MESSAGES/django.po b/locale/it/LC_MESSAGES/django.po index f687464..e8fedc5 100644 --- a/locale/it/LC_MESSAGES/django.po +++ b/locale/it/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Arrowcounter\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-07-27 13:51+0200\n" +"POT-Creation-Date: 2019-08-01 13:47+0200\n" "PO-Revision-Date: 2019-07-27 13:00+0200\n" "Last-Translator: Claudio Maggioni \n" "Language-Team: Claudio Maggioni \n" @@ -76,15 +76,19 @@ msgstr "" "\">Torna alla homepage.\n" #: counter/templates/base.html:9 counter/templates/base.html:25 -#: counter/templates/index.html:8 +#: counter/templates/base.html:65 counter/templates/index.html:8 msgid "Arrow counter" msgstr "Contafrecce" +#: counter/templates/base.html:67 counter/templates/index.html:9 +msgid "A simple online arrow counter" +msgstr "Un semplice contafrecce online" + #: counter/templates/counter/edit.html:7 counter/templates/counter/edit.html:14 msgid "Update count" msgstr "Aggiorna conteggio" -#: counter/templates/counter/edit.html:37 counter/templates/counter/new.html:17 +#: counter/templates/counter/edit.html:46 counter/templates/counter/new.html:17 #: counter/templates/target/edit.html:20 msgid "Save" msgstr "Salva" @@ -122,10 +126,6 @@ msgstr "Nuovo conteggio" msgid "Home" msgstr "Home" -#: counter/templates/index.html:9 -msgid "A simple online arrow counter" -msgstr "Un semplice contafrecce online" - #: counter/templates/index.html:17 msgid "Arrows shot this year:" msgstr "Frecce tirate quest'anno:" @@ -181,14 +181,18 @@ msgstr "Rimuovi" msgid "page is negative or 0" msgstr "pagina negativa o uguale a 0" -#: counter/views.py:203 +#: counter/views.py:214 +msgid "ArrowCount instance not found or from different user" +msgstr "istanza ArrowCount non trovata o appartenente ad altro utente" + +#: counter/views.py:226 msgid "count is not a number" msgstr "count non è un numero" -#: counter/views.py:209 +#: counter/views.py:232 msgid "count is negative or 0" msgstr "count è negativo o uguale a 0" -#: counter/views.py:218 -msgid "ArrowCount instance not found or from different user" -msgstr "istanza ArrowCount non trovata o appartenente ad altro utente" +#: counter/views.py:245 +msgid "count too big" +msgstr "conteggio troppo alto"