forked from PrestaShop/PrestaShop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin_carrier_wizard.js
758 lines (668 loc) · 24 KB
/
admin_carrier_wizard.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
/*
* 2007-2014 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <[email protected]>
* @copyright 2007-2014 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
var fees_is_hide = false;
$(document).ready(function() {
bind_inputs();
initCarrierWizard();
if (parseInt($('input[name="is_free"]:checked').val()))
is_freeClick($('input[name="is_free"]:checked'));
displayRangeType();
$('#attachement_fileselectbutton').click(function(e) {
$('#carrier_logo_input').trigger('click');
});
$('#attachement_filename').click(function(e) {
$('#carrier_logo_input').trigger('click');
});
$('#carrier_logo_input').change(function(e) {
if ($(this)[0].files !== undefined)
{
var files = $(this)[0].files;
var name = '';
$.each(files, function(index, value) {
name += value.name+', ';
});
$('#attachement_filename').val(name.slice(0, -2));
}
else // Internet Explorer 9 Compatibility
{
var name = $(this).val().split(/[\\/]/);
$('#attachement_filename').val(name[name.length-1]);
}
});
$('#carrier_logo_remove').click(function(e) {
$('#attachement_filename').val('');
});
});
function initCarrierWizard()
{
$("#carrier_wizard").smartWizard({
'labelNext' : labelNext,
'labelPrevious' : labelPrevious,
'labelFinish' : labelFinish,
'fixHeight' : 1,
'onShowStep' : onShowStepCallback,
'onLeaveStep' : onLeaveStepCallback,
'onFinish' : onFinishCallback,
'transitionEffect' : 'slideleft',
'enableAllSteps' : enableAllSteps,
'keyNavigation' : false
});
displayRangeType();
}
function displayRangeType()
{
if ($('input[name="shipping_method"]:checked').val() == 1)
{
string = string_weight;
$('.weight_unit').show();
$('.price_unit').hide();
}
else
{
string = string_price;
$('.price_unit').show();
$('.weight_unit').hide();
}
is_freeClick($('input[name="is_free"]:checked'));
$('.range_type').html(string);
}
function onShowStepCallback()
{
$('.anchor li a').each(function () {
$(this).closest('li').addClass($(this).attr('class'));
});
$('#carrier_logo_block').prependTo($('div.content').filter(function() { return $(this).css('display') != 'none' }).find('.defaultForm').find('fieldset'));
resizeWizard();
}
function onFinishCallback(obj, context)
{
$('.wizard_error').remove();
$.ajax({
type:"POST",
url : validate_url,
async: false,
dataType: 'json',
data : $('#carrier_wizard .stepContainer .content form').serialize() + '&action=finish_step&ajax=1&step_number='+context.fromStep,
success : function(data) {
if (data.has_error)
{
displayError(data.errors, context.fromStep);
resizeWizard();
}
else
window.location.href = carrierlist_url;
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
jAlert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);
}
});
}
function onLeaveStepCallback(obj, context)
{
if (context.toStep == nbr_steps)
displaySummary();
return validateSteps(context.fromStep, context.toStep); // return false to stay on step and true to continue navigation
}
function displaySummary()
{
// used as buffer - you must not replace directly in the translation vars
var tmp;
// Carrier name
$('#summary_name').html($('#name').val());
// Delay and pricing
tmp = summary_translation_meta_informations.replace('@s2', '<strong>' + $('#delay_1').val() + '</strong>');
if ($('#is_free_on').attr('checked'))
tmp = tmp.replace('@s1', summary_translation_free);
else
tmp = tmp.replace('@s1', summary_translation_paid);
$('#summary_meta_informations').html(tmp);
// Tax and calculation mode for the shipping cost
tmp = summary_translation_shipping_cost.replace('@s2', '<strong>' + $('#id_tax_rules_group option:selected').text() + '</strong>');
if ($('#billing_price').attr('checked'))
tmp = tmp.replace('@s1', summary_translation_price);
else if ($('#billing_weight').attr('checked'))
tmp = tmp.replace('@s1', summary_translation_weight);
else
tmp = tmp.replace('@s1', '<strong>' + summary_translation_undefined + '</strong>');
$('#summary_shipping_cost').html(tmp);
// Weight or price ranges
$('#summary_range').html(summary_translation_range+' '+summary_translation_range_limit);
if ($('input[name="shipping_method"]:checked').val() == 1)
unit = PS_WEIGHT_UNIT;
else
unit = currency_sign;
var range_inf = summary_translation_undefined;
var range_sup = summary_translation_undefined;
$('tr.range_inf td input').each(function()
{
if (!isNaN(parseFloat($(this).val())) && (range_inf == summary_translation_undefined || parseFloat(range_inf) > parseFloat($(this).val())))
range_inf = $(this).val();
});
$('tr.range_sup td input').each(function(){
if (!isNaN(parseFloat($(this).val())) && (range_sup == summary_translation_undefined || parseFloat(range_sup) < parseFloat($(this).val())))
range_sup = $(this).val();
});
$('#summary_range').html(
$('#summary_range').html()
.replace('@s1', '<strong>' + range_inf +' '+ unit + '</strong>')
.replace('@s2', '<strong>' + range_sup +' '+ unit + '</strong>')
.replace('@s3', '<strong>' + $('#range_behavior option:selected').text().toLowerCase() + '</strong>')
);
if ($('#is_free_on').attr('checked'))
$('span.is_free').hide();
// Delivery zones
$('#summary_zones').html('');
$('.input_zone').each(function(){
if ($(this).attr('checked'))
$('#summary_zones').html($('#summary_zones').html() + '<li><strong>' + $(this).closest('tr').find('label').text() + '</strong></li>');
});
// Group restrictions
$('#summary_groups').html('');
$('input[name$="groupBox[]"]').each(function(){
if ($(this).attr('checked'))
$('#summary_groups').html($('#summary_groups').html() + '<li><strong>' + $(this).closest('tr').find('td:eq(2)').text() + '</strong></li>');
});
// shop restrictions
$('#summary_shops').html('');
$('.input_shop').each(function(){
if ($(this).attr('checked'))
$('#summary_shops').html($('#summary_shops').html() + '<li><strong>' + $(this).closest().text() + '</strong></li>');
});
}
function validateSteps(fromStep, toStep)
{
var is_ok = true;
if ((multistore_enable && fromStep == 3) || (!multistore_enable && fromStep == 2))
{
if (toStep > fromStep && !$('#is_free_on').attr('checked'))
{
is_ok = false;
$('.input_zone').each(function () {
if ($(this).prop('checked'))
is_ok = true;
});
if (!is_ok)
{
displayError([select_at_least_one_zone], fromStep);
return;
}
}
if (toStep > fromStep && !$('#is_free_on').attr('checked') && !validateRange(2))
is_ok = false;
}
$('.wizard_error').remove();
if (is_ok && isOverlapping())
is_ok = false;
if (is_ok)
{
form = $('#carrier_wizard #step-'+fromStep+' form');
$.ajax({
type:"POST",
url : validate_url,
async: false,
dataType: 'json',
data : form.serialize()+'&step_number='+fromStep+'&action=validate_step&ajax=1',
success : function(datas)
{
if (datas.has_error)
{
is_ok = false;
$('div.input-group input').focus(function () {
$(this).closest('div.input-group').removeClass('has-error');
});
displayError(datas.errors, fromStep);
resizeWizard();
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
jAlert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);
}
});
}
return is_ok;
}
function displayError(errors, step_number)
{
$('#carrier_wizard .actionBar a.btn').removeClass('disabled');
$('.wizard_error').remove();
str_error = '<div class="error wizard_error" style="display:none"><ul>';
for (var error in errors)
{
$('#carrier_wizard .actionBar a.btn').addClass('disabled');
$('input[name="'+error+'"]').closest('div.input-group').addClass('has-error');
str_error += '<li>'+errors[error]+'</li>';
}
$('#step-'+step_number).prepend(str_error+'</ul></div>');
$('.wizard_error').fadeIn('fast');
bind_inputs();
}
function resizeWizard()
{
resizeInterval = setInterval(function (){$("#carrier_wizard").smartWizard('fixHeight'); clearInterval(resizeInterval)}, 100);
}
function bind_inputs()
{
$('input').focus(function () {
$(this).closest('div.input-group').removeClass('has-error');
$('#carrier_wizard .actionBar a.btn').not('.buttonFinish').removeClass('disabled');
$('.wizard_error').fadeOut('fast', function () { $(this).remove()});
});
$('tr.delete_range td button').off('click').on('click', function () {
if (confirm(delete_range_confirm))
{
index = $(this).closest('td').index();
$('tr.range_sup td:eq('+index+'), tr.range_inf td:eq('+index+'), tr.fees_all td:eq('+index+'), tr.delete_range td:eq('+index+')').remove();
$('tr.fees').each(function () {
$(this).find('td:eq('+index+')').remove();
});
rebuildTabindex();
}
return false;
});
$('tr.fees td input:checkbox').off('change').on('change', function ()
{
if($(this).is(':checked'))
{
$(this).closest('tr').find('td').each(function () {
index = $(this).index();
if ($('tr.fees_all td:eq('+index+')').hasClass('validated'))
{
enableGlobalFees(index);
$(this).find('div.input-group input:text').removeAttr('disabled');
}
else
disabledGlobalFees(index);
});
}
else
$(this).closest('tr').find('td').find('div.input-group input:text').attr('disabled', 'disabled').val('');
return false;
});
$('tr.range_sup td input:text, tr.range_inf td input:text').focus(function () {
$(this).closest('div.input-group').removeClass('has-error');
});
$('tr.range_sup td input:text, tr.range_inf td input:text').keypress(function (evn) {
index = $(this).closest('td').index();
if (evn.keyCode == 13)
{
if (validateRange(index))
enableRange(index);
else
disableRange(index);
return false;
}
});
$('tr.fees_all td input:text').keypress(function (evn) {
index = $(this).parent('td').index();
if (evn.keyCode == 13)
return false;
});
$('tr.range_sup td input:text, tr.range_inf td input:text').typeWatch({
captureLength: 0,
highlight: false,
wait: 1000,
callback: function() {
index = $(this.el).closest('td').index();
range_sup = $('tr.range_sup td:eq('+index+')').find('div.input-group input:text').val().trim();
range_inf = $('tr.range_inf td:eq('+index+')').find('div.input-group input:text').val().trim();
if (range_sup != '' && range_inf != '')
{
if (validateRange(index))
enableRange(index);
else
disableRange(index);
}
}
});
$(document.body).off('change', 'tr.fees_all td input').on('change', 'tr.fees_all td input', function() {
index = $(this).closest('td').index();
val = $(this).val();
$(this).val('');
$('tr.fees').each(function () {
$(this).find('td:eq('+index+') input:text:enabled').val(val);
});
return false;
});
$('input[name="is_free"]').off('click').on('click', function() {
is_freeClick(this);
});
$('input[name="shipping_method"]').off('click').on('click', function() {
$.ajax({
type:"POST",
url : validate_url,
async: false,
dataType: 'html',
data : 'id_carrier='+parseInt($('#id_carrier').val())+'&shipping_method='+parseInt($(this).val())+'&action=changeRanges&ajax=1',
success : function(data) {
$('#zone_ranges').replaceWith(data);
displayRangeType();
bind_inputs();
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
jAlert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);
}
});
});
$('#zones_table td input[type=text]').off('change').on('change', function () {
checkAllFieldIsNumeric();
});
}
function is_freeClick(elt)
{
var is_free = $(elt);
if (parseInt(is_free.val()))
hideFees();
else if (fees_is_hide)
showFees();
}
function hideFees()
{
$('tr.range_inf td, tr.range_sup td, tr.fees_all td, tr.fees td').each(function () {
if ($(this).index() >= 2)
{
$(this).find('input:text, button').val('').attr('disabled', 'disabled').css('background-color', '#999999').css('border-color', '#999999');
$(this).css('background-color', '#999999');
}
});
fees_is_hide = true;
}
function showFees()
{
$('tr.range_inf td, tr.range_sup td, tr.fees_all td, tr.fees td').each(function () {
if ($(this).index() >= 2)
{
//enable only if zone is active
tr = $(this).closest('tr');
validate = $('tr.fees_all td:eq('+$(this).index()+')').hasClass('validated');
if ($(tr).index() > 2 && $(tr).find('td:eq(1) input').attr('checked') && validate || !$(tr).hasClass('range_sup') || !$(tr).hasClass('range_inf'))
$(this).find('div.input-group input:text').removeAttr('disabled');
$(this).find('input:text, button').css('background-color', '').css('border-color', '');
$(this).find('button').css('background-color', '').css('border-color', '').removeAttr('disabled');
$(this).css('background-color', '');
}
});
}
function validateRange(index)
{
$('#carrier_wizard .actionBar a.btn').removeClass('disabled');
$('.wizard_error').remove();
//reset error css
$('tr.range_sup td input:text').closest('div.input-group').removeClass('has-error');
$('tr.range_inf td input:text').closest('div.input-group').removeClass('has-error');
var is_valid = true;
range_sup = parseFloat($('tr.range_sup td:eq('+index+')').find('div.input-group input:text').val().trim());
range_inf = parseFloat($('tr.range_inf td:eq('+index+')').find('div.input-group input:text').val().trim());
if (isNaN(range_sup) || range_sup.length === 0)
{
$('tr.range_sup td:eq('+index+')').find('div.input-group input:text').closest('div.input-group').addClass('has-error');
is_valid = false;
displayError([invalid_range], $("#carrier_wizard").smartWizard('currentStep'));
}
else if (is_valid && (isNaN(range_inf) || range_inf.length === 0))
{
$('tr.range_inf td:eq('+index+')').closest('div.input-group input:text').closest('div.input-group').addClass('has-error');
is_valid = false;
displayError([invalid_range], $("#carrier_wizard").smartWizard('currentStep'));
}
else if (is_valid && range_inf >= range_sup)
{
$('tr.range_sup td:eq('+index+')').find('div.input-group input:text').closest('div.input-group').addClass('has-error');
$('tr.range_inf td:eq('+index+')').find('div.input-group input:text').closest('div.input-group').addClass('has-error');
is_valid = false;
displayError([invalid_range], $("#carrier_wizard").smartWizard('currentStep'));
}
else if (is_valid && index > 2) //check range only if it's not the first range
{
$('tr.range_sup td').not('.range_type, .range_sign, tr.range_sup td:last').each(function ()
{
if ($('tr.fees_all td:eq('+index+')').hasClass('validated'))
{
is_valid = false;
curent_index = $(this).index();
current_sup = $(this).find('div.input-group input').val();
current_inf = $('tr.range_inf td:eq('+curent_index+') input').val();
if ($('tr.range_inf td:eq('+curent_index+1+') input').length)
next_inf = $('tr.range_inf td:eq('+curent_index+1+') input').val();
else
next_inf = false;
//check if range already exist
//check if ranges is overlapping
if ((range_sup != current_sup && range_inf != current_inf) && ((range_sup > current_sup || range_sup <= current_inf) && (range_inf < current_inf || range_inf >= current_sup)))
is_valid = true;
}
});
if (!is_valid)
{
$('tr.range_sup td:eq('+index+')').find('div.input-group input:text').closest('div.input-group').addClass('has-error');
$('tr.range_inf td:eq('+index+')').find('div.input-group input:text').closest('div.input-group').addClass('has-error');
displayError([range_is_overlapping], $("#carrier_wizard").smartWizard('currentStep'));
}
else
isOverlapping();
}
return is_valid;
}
function enableZone(index)
{
$('tr.fees').each(function () {
if ($(this).find('td:eq(1)').find('input[type=checkbox]:checked').length)
$(this).find('td:eq('+index+')').find('div.input-group input').removeAttr('disabled');
});
}
function disableZone(index)
{
$('tr.fees').each(function () {
$(this).find('td:eq('+index+')').find('div.input-group input').attr('disabled', 'disabled');
});
}
function enableRange(index)
{
$('tr.fees').each(function () {
//only enable fees for enabled zones
if ($(this).find('td').find('input:checkbox').attr('checked') == 'checked')
enableZone(index);
});
$('tr.fees_all td:eq('+index+')').addClass('validated').removeClass('not_validated');
//if ($('.zone input[type=checkbox]:checked').length)
enableGlobalFees(index);
bind_inputs();
}
function enableGlobalFees(index)
{
$('span.fees_all').show();
$('tr.fees_all td:eq('+index+')').find('div.input-group input').show().removeAttr('disabled');
$('tr.fees_all td:eq('+index+')').find('div.input-group .currency_sign').show();
}
function disabledGlobalFees(index)
{
$('span.fees_all').hide();
$('tr.fees_all td:eq('+index+')').find('div.input-group input').hide().attr('disabled', 'disabled');
$('tr.fees_all td:eq('+index+')').find('div.input-group .currency_sign').hide();
}
function disableRange(index)
{
$('tr.fees').each(function () {
//only enable fees for enabled zones
if ($(this).find('td').find('input:checkbox').attr('checked') == 'checked')
disableZone(index);
});
$('tr.fees_all td:eq('+index+')').find('div.input-group input').attr('disabled', 'disabled');
$('tr.fees_all td:eq('+index+')').removeClass('validated').addClass('not_validated');
}
function add_new_range()
{
if (!$('tr.fees_all td:last').hasClass('validated'))
{
alert(need_to_validate);
return false;
}
last_sup_val = $('tr.range_sup td:last input').val();
//add new rand sup input
$('tr.range_sup td:last').after('<td class="range_data"><div class="input-group fixed-width-md"><span class="input-group-addon weight_unit" style="display: none;">'+PS_WEIGHT_UNIT+'</span><span class="input-group-addon price_unit" style="display: none;">'+currency_sign+'</span><input class="form-control" name="range_sup[]" type="text" /></div></td>');
//add new rand inf input
$('tr.range_inf td:last').after('<td class="border_bottom"><div class="input-group fixed-width-md"><span class="input-group-addon weight_unit" style="display: none;">'+PS_WEIGHT_UNIT+'</span><span class="input-group-addon price_unit" style="display: none;">'+currency_sign+'</span><input class="form-control" name="range_inf[]" type="text" value="'+last_sup_val+'" /></div></td>');
$('tr.fees_all td:last').after('<td class="border_top border_bottom"><div class="input-group fixed-width-md"><span class="input-group-addon currency_sign" style="display:none" >'+currency_sign+'</span><input class="form-control" style="display:none" type="text" /></div></td>');
$('tr.fees').each(function () {
$(this).find('td:last').after('<td><div class="input-group fixed-width-md"><span class="input-group-addon currency_sign">'+currency_sign+'</span><input class="form-control" disabled="disabled" name="fees['+$(this).data('zoneid')+'][]" type="text" /></div></td>');
});
$('tr.delete_range td:last').after('<td><button class="btn btn-default">'+labelDelete+'</button</td>');
bind_inputs();
rebuildTabindex();
displayRangeType();
resizeWizard();
return false;
}
function delete_new_range()
{
if ($('#new_range_form_placeholder').find('td').length = 1)
return false;
}
function checkAllFieldIsNumeric()
{
$('#carrier_wizard .actionBar a.btn').removeClass('disabled');
$('#zones_table td input[type=text]').each(function () {
if (!$.isNumeric($(this).val()) && $(this).val() != '')
$(this).closest('div.input-group').addClass('has-error');
});
}
function rebuildTabindex()
{
i = 1;
$('#zones_table tr').each(function ()
{
j = i;
$(this).find('td').each(function ()
{
j = zones_nbr + j;
if ($(this).index() >= 2 && $(this).find('div.input-group input'))
$(this).find('div.input-group input').attr('tabindex', j);
});
i++;
});
}
function repositionRange(current_index, new_index)
{
$('tr.range_sup, tr.range_inf, tr.fees_all, tr.fees, tr.delete_range ').each(function () {
$(this).find('td:eq('+current_index+')').each(function () {
$(this).closest('tr').find('td:eq('+new_index+')').after(this.outerHTML);
$(this).remove();
});
});
}
function checkRangeContinuity(reordering)
{
reordering = typeof reordering !== 'undefined' ? reordering : false;
res = true;
$('tr.range_sup td').not('.range_type, .range_sign').each(function ()
{
index = $(this).index();
if (index > 2)
{
range_sup = parseFloat($('tr.range_sup td:eq('+index+')').find('div.input-group input:text').val().trim());
range_inf = parseFloat($('tr.range_inf td:eq('+index+')').find('div.input-group input:text').val().trim());
prev_index = index-1;
prev_range_sup = parseFloat($('tr.range_sup td:eq('+prev_index+')').find('div.input-group input:text').val().trim());
prev_range_inf = parseFloat($('tr.range_inf td:eq('+prev_index+')').find('div.input-group input:text').val().trim());
if (range_inf < prev_range_inf || range_sup < prev_range_sup)
{
res = false;
if (reordering)
{
new_position = getCorrectRangePosistion(range_inf, range_sup);
if (new_position)
repositionRange(index, new_position);
}
}
}
});
if (res)
$('.ranges_not_follow').fadeOut();
else
$('.ranges_not_follow').fadeIn();
resizeWizard();
}
function getCorrectRangePosistion(current_inf, current_sup)
{
new_position = false;
$('tr.range_sup td').not('.range_type, .range_sign').each(function ()
{
index = $(this).index();
range_sup = parseFloat($('tr.range_sup td:eq('+index+')').find('div.input-group input:text').val().trim());
next_range_inf = 0
if ($('tr.range_inf td:eq('+index+1+')').length)
next_range_inf = parseFloat($('tr.range_inf td:eq('+index+1+')').find('div.input-group input:text').val().trim());
if (current_inf >= range_sup && current_sup < next_range_inf)
new_position = index;
});
return new_position;
}
function isOverlapping()
{
var is_valid = false;
$('#carrier_wizard .actionBar a.btn').removeClass('disabled');
$('tr.range_sup td').not('.range_type, .range_sign').each( function ()
{
index = $(this).index();
current_inf = parseFloat($('.range_inf td:eq('+index+') input').val());
current_sup = parseFloat($('.range_sup td:eq('+index+') input').val());
$('tr.range_sup td').not('.range_type, .range_sign').each( function ()
{
testing_index = $(this).index();
if (testing_index != index) //do not test himself
{
testing_inf = parseFloat($('.range_inf td:eq('+testing_index+') input').val());
testing_sup = parseFloat($('.range_sup td:eq('+testing_index+') input').val());
if ((current_inf >= testing_inf && current_inf < testing_sup) || (current_sup > testing_inf && current_sup < testing_sup))
{
$('tr.range_sup td:eq('+testing_index+') div.input-group, tr.range_inf td:eq('+testing_index+') div.input-group').addClass('has-error');
displayError([overlapping_range], $("#carrier_wizard").smartWizard('currentStep'));
is_valid = true;
}
}
});
});
return is_valid;
}
function checkAllZones(elt)
{
if($(elt).is(':checked'))
{
$('.input_zone').attr('checked', 'checked');
$('.fees div.input-group input:text').each(function () {
index = $(this).closest('td').index();
enableGlobalFees(index);
if ($('tr.fees_all td:eq('+index+')').hasClass('validated'))
{
$(this).removeAttr('disabled');
$('.fees_all td:eq('+index+') div.input-group input:text').removeAttr('disabled');
}
});
}
else
{
$('.input_zone').removeAttr('checked');
$('.fees div.input-group input:text, .fees_all div.input-group input:text').attr('disabled', 'disabled');
}
}