2018-08-09 17:31:50 +00:00
|
|
|
'use strict';
|
2019-08-01 11:48:35 +00:00
|
|
|
// vim: set ts=2 sw=2 et tw=80:
|
2018-08-09 16:06:25 +00:00
|
|
|
|
2018-08-09 17:31:50 +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
|
|
|
|
2019-08-01 11:48:35 +00:00
|
|
|
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() {
|
2018-08-09 16:06:25 +00:00
|
|
|
var count = parseInt(input.val(), 10);
|
2018-08-09 17:31:50 +00:00
|
|
|
if(!isNaN(count) && count >= 0) {
|
|
|
|
arrowCountUpdateAjax();
|
|
|
|
}
|
2018-08-09 16:06:25 +00:00
|
|
|
});
|
|
|
|
|
2019-08-01 11:48:35 +00:00
|
|
|
$('.count-up').click(function(e) {
|
|
|
|
var increment = parseInt(e.currentTarget.getAttribute("data-increment"));
|
|
|
|
arrowCountFetchAjax(function (count) {
|
|
|
|
input.val(count + increment);
|
|
|
|
arrowCountUpdateAjax();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-08-09 16:06:25 +00:00
|
|
|
$('.count-down').click(function() {
|
|
|
|
var count = parseInt(input.val(), 10);
|
2018-08-09 17:31:50 +00:00
|
|
|
if(!isNaN(count) && count > 0) {
|
2018-08-09 16:06:25 +00:00
|
|
|
input.val(count - 1);
|
2018-08-09 17:31:50 +00:00
|
|
|
arrowCountUpdateAjax();
|
|
|
|
}
|
2018-08-09 16:06:25 +00:00
|
|
|
});
|