allow to edit GroupOrderArticle result from orders screen
Conflicts: app/assets/javascripts/application.js
This commit is contained in:
parent
f9d2c20aaa
commit
60826ceedc
34 changed files with 393 additions and 220 deletions
|
|
@ -7,7 +7,6 @@
|
|||
//= require bootstrap-datepicker/locales/bootstrap-datepicker.de
|
||||
//= require bootstrap-datepicker/locales/bootstrap-datepicker.nl
|
||||
//= require bootstrap-datepicker/locales/bootstrap-datepicker.fr
|
||||
//= require jquery.observe_field
|
||||
//= require list
|
||||
//= require list.unlist
|
||||
//= require list.delay
|
||||
|
|
@ -20,6 +19,7 @@
|
|||
//= require ordering
|
||||
//= require stupidtable
|
||||
//= require touchclick
|
||||
//= require delta_input
|
||||
|
||||
// Load following statements, when DOM is ready
|
||||
$(function() {
|
||||
|
|
@ -69,17 +69,32 @@ $(function() {
|
|||
return false;
|
||||
});
|
||||
|
||||
// Submit form when changing text of an input field
|
||||
// Use jquery observe_field plugin
|
||||
$('form[data-submit-onchange] input[type=text]').each(function() {
|
||||
$(this).observe_field(1, function() {
|
||||
$(this).parents('form').submit();
|
||||
});
|
||||
// Submit form when clicking on checkbox
|
||||
$(document).on('click', 'form[data-submit-onchange] input[type=checkbox]:not(input[data-ignore-onchange])', function() {
|
||||
$(this).parents('form').submit();
|
||||
});
|
||||
|
||||
// Submit form when clicking on checkbox
|
||||
$('form[data-submit-onchange] input[type=checkbox]:not(input[data-ignore-onchange])').click(function() {
|
||||
$(this).parents('form').submit();
|
||||
// Submit form when changing text of an input field.
|
||||
// Wubmission will be done after 500ms of not typed, unless data-submit-onchange=changed,
|
||||
// in which case it happens when the input box loses its focus ('changed' event).
|
||||
$(document).on('changed keyup focusin', 'form[data-submit-onchange] input[type=text]', function(e) {
|
||||
var input = $(this);
|
||||
// when form has data-submit-onchange=changed, don't do updates while typing
|
||||
if (e.type!='changed' && input.parents('form[data-submit-onchange=changed]')) {
|
||||
return true;
|
||||
}
|
||||
// remember old value when it's getting the focus
|
||||
if (e.type=='focusin') {
|
||||
input.data('old-value', input.val());
|
||||
return true;
|
||||
}
|
||||
// trigger timeout to submit form when value was changed
|
||||
clearTimeout(input.data('submit-timeout-id'));
|
||||
input.data('submit-timeout-id', setTimeout(function() {
|
||||
if (input.val() != input.data('old-value')) input.parents('form').submit();
|
||||
input.removeData('submit-timeout-id');
|
||||
input.removeData('old-value');
|
||||
}, 500));
|
||||
});
|
||||
|
||||
$('[data-redirect-to]').bind('change', function() {
|
||||
|
|
|
|||
49
app/assets/javascripts/delta_input.js
Normal file
49
app/assets/javascripts/delta_input.js
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
|
||||
$(function() {
|
||||
$(document).on('click', 'button[data-increment]', function() {
|
||||
data_delta_update($('#'+$(this).data('increment')), +1);
|
||||
});
|
||||
$(document).on('click', 'button[data-decrement]', function() {
|
||||
data_delta_update($('#'+$(this).data('decrement')), -1);
|
||||
});
|
||||
$(document).on('change keyup', 'input[type="text"][data-delta]', function() {
|
||||
data_delta_update(this, 0);
|
||||
});
|
||||
});
|
||||
|
||||
function data_delta_update(el, direction) {
|
||||
var id = $(el).attr('id');
|
||||
|
||||
var min = $(el).data('min');
|
||||
var max = $(el).data('max');
|
||||
var delta = $(el).data('delta');
|
||||
var granularity = $(el).data('granularity');
|
||||
|
||||
var val = $(el).val();
|
||||
var oldval = $.isNumeric(val) ? Number(val) : 0;
|
||||
var newval = oldval + delta*direction;
|
||||
|
||||
if (newval < min) newval = min;
|
||||
if (newval > max) newval = max;
|
||||
|
||||
// disable buttons when min/max reached
|
||||
$('button[data-decrement='+id+']').attr('disabled', newval<=min ? 'disabled' : null);
|
||||
$('button[data-increment='+id+']').attr('disabled', newval>=max ? 'disabled' : null);
|
||||
|
||||
// warn when what was entered is not a number
|
||||
$(el).toggleClass('error', val!='' && val!='.' && (!$.isNumeric(val) || val < 0));
|
||||
|
||||
// update field, unless the user is typing
|
||||
if (!$(el).is(':focus')) {
|
||||
$(el).val(round_float(newval, granularity));
|
||||
$(el).trigger('changed');
|
||||
}
|
||||
}
|
||||
|
||||
// truncate numbers because of tiny floating point deviations
|
||||
// if we don't do this, 1.0 might be shown as 0.99999999
|
||||
function round_float(s, granularity) {
|
||||
var e = granularity ? 1/granularity : 1000;
|
||||
return Math.round(Number(s)*e) / e;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue