arrowcounter/counter/static/js/count_edit.js

34 lines
725 B
JavaScript
Raw Normal View History

'use strict';
2018-08-09 16:06:25 +00:00
var acForm = $('#edit-arrowcount-form'),
input = acForm.find('#id_count');
function arrowCountUpdateAjax() {
$.ajax({
url: acForm.attr('data-update-ajax'),
data: acForm.serialize(),
method: 'POST',
success: function(e) {
if(!e.success) {
M.toast({html: gettext('Error while updating') + ': ' + e.error})
}
}
});
}
2018-08-09 16:06:25 +00:00
$('.count-up').click(function() {
var count = parseInt(input.val(), 10);
if(!isNaN(count) && count >= 0) {
2018-08-09 16:06:25 +00:00
input.val(count + 1);
arrowCountUpdateAjax();
}
2018-08-09 16:06:25 +00:00
});
$('.count-down').click(function() {
var count = parseInt(input.val(), 10);
if(!isNaN(count) && count > 0) {
2018-08-09 16:06:25 +00:00
input.val(count - 1);
arrowCountUpdateAjax();
}
2018-08-09 16:06:25 +00:00
});