Revision 926099a8
Von Sven Schöling vor fast 8 Jahren hinzugefügt
js/kivi.Part.js | ||
---|---|---|
177 | 177 |
$.post("controller.pl", data, kivi.eval_json_result); |
178 | 178 |
}; |
179 | 179 |
|
180 |
ns.set_multi_assembly_items = function(data) { |
|
181 |
data.push({ name: 'part.id', value: $('#part_id').val() }); |
|
182 |
data.push({ name: 'part.part_type', value: $('#part_part_type').val() }); |
|
183 |
$.post("controller.pl?action=Part/add_multi_assembly_items", data, kivi.eval_json_result); |
|
184 |
} |
|
185 |
|
|
186 |
ns.set_multi_assortment_items = function(data) { |
|
187 |
data.push({ name: 'part.id', value: $('#part_id').val() }); |
|
188 |
data.push({ name: 'part.part_type', value: $('#part_part_type').val() }); |
|
189 |
$.post("controller.pl?action=Part/add_multi_assortment_items", data, kivi.eval_json_result); |
|
190 |
} |
|
191 |
|
|
192 |
ns.close_picker_dialogs = function() { |
|
193 |
$('.part_autocomplete').each(function(_, e) { |
|
194 |
var picker = $(e).data('part_picker'); |
|
195 |
if (picker) picker.close_dialog(); |
|
196 |
}); |
|
197 |
} |
|
198 |
|
|
180 | 199 |
ns.redisplay_items = function(data) { |
181 | 200 |
var old_rows; |
182 | 201 |
var part_type = $("#part_part_type").val(); |
... | ... | |
205 | 224 |
$("#assembly_rows tr:last").find('input[type=text]').filter(':visible:first').focus(); |
206 | 225 |
}; |
207 | 226 |
|
208 |
ns.show_multi_items_dialog = function(part_type,part_id) { |
|
209 |
|
|
210 |
$('#row_table_id thead a img').remove(); |
|
211 |
|
|
212 |
kivi.popup_dialog({ |
|
213 |
url: 'controller.pl?action=Part/show_multi_items_dialog', |
|
214 |
data: { callback: 'Part/add_multi_' + part_type + '_items', |
|
215 |
callback_data_id: 'ic', |
|
216 |
'part.part_type': part_type, |
|
217 |
'part.id' : part_id, |
|
218 |
}, |
|
219 |
id: 'jq_multi_items_dialog', |
|
220 |
dialog: { |
|
221 |
title: kivi.t8('Add multiple items'), |
|
222 |
width: 800, |
|
223 |
height: 800 |
|
224 |
} |
|
225 |
}); |
|
226 |
return true; |
|
227 |
}; |
|
228 |
|
|
229 |
ns.close_multi_items_dialog = function() { |
|
230 |
$('#jq_multi_items_dialog').dialog('close'); |
|
231 |
}; |
|
232 |
|
|
233 |
|
|
234 | 227 |
// makemodel |
235 | 228 |
ns.makemodel_renumber_positions = function() { |
236 | 229 |
$('.makemodel_row [name="position"]').each(function(idx, elt) { |
... | ... | |
296 | 289 |
this.state = this.STATES.PICKED; |
297 | 290 |
this.last_dummy = this.$dummy.val(); |
298 | 291 |
this.timer = undefined; |
292 |
this.dialog = undefined; |
|
299 | 293 |
|
300 | 294 |
this.init(); |
301 | 295 |
}; |
... | ... | |
354 | 348 |
} |
355 | 349 |
this.annotate_state(); |
356 | 350 |
}, |
351 |
set_multi_items: function(data) { |
|
352 |
this.run_action(this.o.action.set_multi_items, [ data ]); |
|
353 |
}, |
|
357 | 354 |
make_defined_state: function() { |
358 | 355 |
if (this.state == this.STATES.PICKED) { |
359 | 356 |
this.annotate_state(); |
... | ... | |
438 | 435 |
} |
439 | 436 |
}, |
440 | 437 |
open_dialog: function() { |
441 |
new ns.PickerPopup(this); |
|
438 |
if (this.o.multiple) { |
|
439 |
this.dialog = new ns.PickerMultiPopup(this); |
|
440 |
} else { |
|
441 |
this.dialog = new ns.PickerPopup(this); |
|
442 |
} |
|
443 |
}, |
|
444 |
close_dialog: function() { |
|
445 |
this.dialog.close_dialog(); |
|
446 |
this.dialog = undefined; |
|
442 | 447 |
}, |
443 | 448 |
init: function() { |
444 | 449 |
var self = this; |
... | ... | |
549 | 554 |
partnumber: $(this).children('input.part_picker_partnumber').val(), |
550 | 555 |
description: $(this).children('input.part_picker_description').val(), |
551 | 556 |
}); |
552 |
self.close_popup();
|
|
557 |
self.close_dialog();
|
|
553 | 558 |
self.pp.$dummy.focus(); |
554 | 559 |
return true; |
555 | 560 |
}); |
556 | 561 |
}); |
557 | 562 |
$('#part_selection').keydown(function(e){ |
558 | 563 |
if (e.which == KEY.ESCAPE) { |
559 |
self.close_popup();
|
|
564 |
self.close_dialog();
|
|
560 | 565 |
self.pp.$dummy.focus(); |
561 | 566 |
} |
562 | 567 |
}); |
... | ... | |
580 | 585 |
this.timer = window.setTimeout(function() { self.update_results() }, 100); |
581 | 586 |
} |
582 | 587 |
}, |
583 |
close_popup: function() {
|
|
588 |
close_dialog: function() {
|
|
584 | 589 |
$('#part_selection').dialog('close'); |
585 | 590 |
} |
586 | 591 |
}; |
587 | 592 |
|
593 |
ns.PickerMultiPopup = function(pp) { |
|
594 |
this.pp = pp; |
|
595 |
this.callback = 'Part/add_multi_' + this.pp.o.part_type + '_items'; |
|
596 |
this.open_dialog(); |
|
597 |
}; |
|
598 |
|
|
599 |
ns.PickerMultiPopup.prototype = { |
|
600 |
open_dialog: function() { |
|
601 |
var self = this; |
|
602 |
$('#row_table_id thead a img').remove(); |
|
603 |
|
|
604 |
kivi.popup_dialog({ |
|
605 |
url: 'controller.pl?action=Part/show_multi_items_dialog', |
|
606 |
data: $.extend({ |
|
607 |
real_id: self.pp.real_id, |
|
608 |
}, self.pp.ajax_data(this.pp.$dummy.val())), |
|
609 |
id: 'jq_multi_items_dialog', |
|
610 |
dialog: { |
|
611 |
title: kivi.t8('Add multiple items'), |
|
612 |
width: 800, |
|
613 |
height: 800 |
|
614 |
}, |
|
615 |
load: function() { |
|
616 |
self.init_search(); |
|
617 |
} |
|
618 |
}); |
|
619 |
return true; |
|
620 |
}, |
|
621 |
init_search: function() { |
|
622 |
var self = this; |
|
623 |
$('#multi_items_filter_table input, #multi_items_filter_table select').keydown(function(event) { |
|
624 |
if(event.which == KEY.ENTER) { |
|
625 |
event.preventDefault(); |
|
626 |
self.update_results(); |
|
627 |
return false; |
|
628 |
} |
|
629 |
}); |
|
630 |
|
|
631 |
$('#multi_items_filter_all_substr_multi_ilike').focus(); |
|
632 |
$('#multi_items_filter_button').click(function(){ self.update_results() }); |
|
633 |
$('#multi_items_filter_reset').click(function(){ $("#multi_items_form").resetForm() }); |
|
634 |
$('#continue_button').click(function(){ self.add_multi_items() }); |
|
635 |
}, |
|
636 |
update_results: function() { |
|
637 |
var self = this; |
|
638 |
var data = $('#multi_items_form').serializeArray(); |
|
639 |
data.push({ name: 'type', value: self.pp.type }); |
|
640 |
$.ajax({ |
|
641 |
url: 'controller.pl?action=Part/multi_items_update_result', |
|
642 |
data: data, |
|
643 |
method: 'post', |
|
644 |
success: function(data){ |
|
645 |
$('#multi_items_result').html(data); |
|
646 |
self.init_results(); |
|
647 |
self.enable_continue(); |
|
648 |
} |
|
649 |
}); |
|
650 |
}, |
|
651 |
set_qty_to_one: function(clicked) { |
|
652 |
if ($(clicked).val() === '') { |
|
653 |
$(clicked).val(kivi.format_amount(1.00, -2)); |
|
654 |
} |
|
655 |
$(clicked).select(); |
|
656 |
}, |
|
657 |
init_results: function() { |
|
658 |
var self = this; |
|
659 |
$('#multi_items_all_qty').change(function(event){ |
|
660 |
$('.multi_items_qty').val($(event.target).val()); |
|
661 |
}); |
|
662 |
$('.multi_items_qty').click(function(){ self.set_qty_to_one(this) }); |
|
663 |
}, |
|
664 |
result_timer: function(event) { |
|
665 |
}, |
|
666 |
close_dialog: function() { |
|
667 |
$('#jq_multi_items_dialog').dialog('close'); |
|
668 |
}, |
|
669 |
disable_continue: function() { |
|
670 |
$('#multi_items_result input').off("keydown"); |
|
671 |
$('#continue_button').prop('disabled', true); |
|
672 |
}, |
|
673 |
enable_continue: function() { |
|
674 |
var self = this; |
|
675 |
$('#multi_items_result input').keydown(function(event) { |
|
676 |
if(event.keyCode == KEY.ENTER) { |
|
677 |
event.preventDefault(); |
|
678 |
self.add_multi_items(); |
|
679 |
return false; |
|
680 |
} |
|
681 |
}); |
|
682 |
$('#continue_button').prop('disabled', false); |
|
683 |
}, |
|
684 |
add_multi_items: function() { |
|
685 |
// rows at all |
|
686 |
var n_rows = $('.multi_items_qty').length; |
|
687 |
if ( n_rows === 0) { return; } |
|
688 |
|
|
689 |
// filled rows |
|
690 |
n_rows = $('.multi_items_qty').filter(function() { |
|
691 |
return $(this).val().length > 0; |
|
692 |
}).length; |
|
693 |
if (n_rows === 0) { return; } |
|
694 |
|
|
695 |
this.disable_continue(); |
|
696 |
|
|
697 |
var data = $('#multi_items_form').serializeArray(); |
|
698 |
this.pp.set_multi_items(data); |
|
699 |
} |
|
700 |
}; |
|
701 |
|
|
588 | 702 |
ns.reinit_widgets = function() { |
589 | 703 |
kivi.run_once_for('input.part_autocomplete', 'part_picker', function(elt) { |
590 | 704 |
if (!$(elt).data('part_picker')) |
... | ... | |
597 | 711 |
} |
598 | 712 |
|
599 | 713 |
$(function(){ |
600 |
|
|
601 |
// assortment |
|
602 |
// TODO: allow units for assortment items |
|
603 |
$('#add_assortment_item_id').on('set_item:PartPicker', function(e,o) { $('#add_item_unit').val(o.unit) }); |
|
604 |
|
|
605 | 714 |
$('#ic').on('focusout', '.reformat_number', function(event) { |
606 | 715 |
ns.reformat_number(event); |
607 |
}) |
|
608 |
|
|
609 |
$('.add_assortment_item_input').keydown(function(event) { |
|
610 |
if(event.keyCode == 13) { |
|
611 |
event.preventDefault(); |
|
612 |
if ($("input[name='add_items[+].parts_id']").val() !== '' ) { |
|
613 |
kivi.Part.show_multi_items_dialog("assortment"); |
|
614 |
// ns.add_assortment_item(); |
|
615 |
} |
|
616 |
return false; |
|
617 |
} |
|
618 |
}); |
|
619 |
|
|
620 |
$('.add_assembly_item_input').keydown(function(event) { |
|
621 |
if(event.keyCode == 13) { |
|
622 |
event.preventDefault(); |
|
623 |
if ($("input[name='add_items[+].parts_id']").val() !== '' ) { |
|
624 |
kivi.Part.show_multi_items_dialog("assortment"); |
|
625 |
// ns.add_assembly_item(); |
|
626 |
} |
|
627 |
return false; |
|
628 |
} |
|
629 | 716 |
}); |
630 | 717 |
|
631 | 718 |
$('.add_makemodel_input').keydown(function(event) { |
templates/webpages/part/_multi_items_dialog.html | ||
---|---|---|
2 | 2 |
|
3 | 3 |
<form method="post" id="multi_items_form" method="POST"> |
4 | 4 |
|
5 |
[% L.hidden_tag('part.part_type', FORM.part.part_type) %] |
|
6 |
|
|
7 | 5 |
<table id='multi_items_filter_table'> |
8 | 6 |
<tr> |
9 | 7 |
<th>[%- LxERP.t8("Description") %]/[%- LxERP.t8("Partnumber") %]:</th> |
10 |
<td>[%- L.input_tag('multi_items.filter.all:substr:multi::ilike', partfilter) %]</td>
|
|
8 |
<td>[%- L.input_tag('multi_items.filter.all:substr:multi::ilike', SELF.multi_items_models.filtered.laundered.all_substr_multi__ilike) %]</td>
|
|
11 | 9 |
<th>[%- LxERP.t8("Partsgroup") %]</th> |
12 | 10 |
<td>[%- L.select_tag('multi_items.filter.partsgroup_id', all_partsgroups, title_key='partsgroup', value_key='id', with_empty=1) %]</td> |
13 | 11 |
<tr> |
14 | 12 |
</table> |
15 | 13 |
|
16 |
[% L.button_tag('update_result()', LxERP.t8('Filter')) %]
|
|
17 |
[% L.button_tag('$("#multi_items_form").resetForm()', LxERP.t8('Reset')) %]
|
|
14 |
[% L.button_tag('', LxERP.t8('Filter'), id='multi_items_filter_button') %]
|
|
15 |
[% L.button_tag('', LxERP.t8('Reset'), id='multi_items_filter_reset') %]
|
|
18 | 16 |
|
19 | 17 |
<hr> |
20 | 18 |
<div id='multi_items_result'></div> |
21 | 19 |
<hr> |
22 | 20 |
|
23 |
[% L.button_tag('add_multi_items()', LxERP.t8('Continue'), id='continue_button') %] |
|
24 |
<a href="#" onclick="kivi.Part.close_multi_items_dialog();">[%- LxERP.t8("Cancel") %]</a> |
|
25 |
|
|
26 |
<script type='text/javascript'> |
|
27 |
function update_result() { |
|
28 |
var data = $('#multi_items_form').serializeArray(); |
|
29 |
data.push({ name: 'type', value: '[%- FORM.type %]' }); |
|
30 |
$.ajax({ |
|
31 |
url: 'controller.pl?action=Part/multi_items_update_result', |
|
32 |
data: data, |
|
33 |
method: 'post', |
|
34 |
success: function(data){ |
|
35 |
$('#multi_items_result').html(data); |
|
36 |
enable_continue(); |
|
37 |
} |
|
38 |
}); |
|
39 |
} |
|
40 |
|
|
41 |
function disable_continue() { |
|
42 |
// disable keydown-event and continue button to prevent |
|
43 |
// impatient users to add parts multiple times |
|
44 |
$('#multi_items_result input').off("keydown"); |
|
45 |
$('#continue_button').prop('disabled', true); |
|
46 |
} |
|
47 |
|
|
48 |
function enable_continue() { |
|
49 |
$('#multi_items_result input').keydown(function(event) { |
|
50 |
if(event.keyCode == 13) { |
|
51 |
event.preventDefault(); |
|
52 |
add_multi_items(); |
|
53 |
return false; |
|
54 |
} |
|
55 |
}); |
|
56 |
$('#continue_button').prop('disabled', false); |
|
57 |
} |
|
58 |
|
|
59 |
function add_multi_items() { |
|
60 |
// rows at all |
|
61 |
var n_rows = $('.multi_items_qty').length; |
|
62 |
if ( n_rows == 0) { return; } |
|
63 |
|
|
64 |
// filled rows |
|
65 |
n_rows = $('.multi_items_qty').filter(function() { |
|
66 |
return $(this).val().length > 0; |
|
67 |
}).length; |
|
68 |
if ( n_rows == 0) { return; } |
|
69 |
|
|
70 |
disable_continue(); |
|
71 |
|
|
72 |
// var data = $('#[%- FORM.callback_data_id %]').serializeArray(); /* do i need to serialize this as well? */ |
|
73 |
// var data = data.concat($('#multi_items_form').serializeArray()); |
|
74 |
var data = $('#multi_items_form').serializeArray(); |
|
75 |
data.push({ name: 'action', value: '[%- FORM.callback %]' }); |
|
76 |
data.push({ name: 'part_type', value: '[%- FORM.part.part_type %]' }); |
|
77 |
data.push({ name: 'part.id' , value: '[%- FORM.part.id %]' }); |
|
78 |
$.post("controller.pl", data, kivi.eval_json_result); |
|
79 |
} |
|
80 |
|
|
81 |
$('#multi_items_filter_table input, #multi_items_filter_table select').keydown(function(event) { |
|
82 |
if(event.keyCode == 13) { |
|
83 |
event.preventDefault(); |
|
84 |
update_result(); |
|
85 |
return false; |
|
86 |
} |
|
87 |
}); |
|
88 |
|
|
89 |
$('#multi_items_filter_all_substr_multi_ilike').focus(); |
|
90 |
</script> |
|
21 |
[% L.button_tag('', LxERP.t8('Continue'), id='continue_button') %] |
|
91 | 22 |
|
92 | 23 |
</form> |
templates/webpages/part/_multi_items_result.html | ||
---|---|---|
22 | 22 |
<td> |
23 | 23 |
[% L.hidden_tag("add_items[+].parts_id", item.id) %] |
24 | 24 |
[% L.input_tag("add_items[].qty_as_number", '', size = 5, |
25 |
class = 'multi_items_qty numeric', onclick = 'set_qty_to_one(this)') %]
|
|
25 |
class = 'multi_items_qty numeric') %] |
|
26 | 26 |
</td> |
27 | 27 |
<td>[% HTML.escape(item.unit) %]</td> |
28 | 28 |
<td>[% P.part(item) %]</td> |
... | ... | |
31 | 31 |
</tr> |
32 | 32 |
[%- END %] |
33 | 33 |
</table> |
34 |
|
|
35 |
<script type='text/javascript'> |
|
36 |
function set_qty_to_one(clicked) { |
|
37 |
if ($(clicked).val() == '') { |
|
38 |
$(clicked).val('[%- LxERP.format_amount(1.00, -2) %]'); |
|
39 |
} |
|
40 |
$(clicked).select(); |
|
41 |
} |
|
42 |
|
|
43 |
$('#multi_items_all_qty').change(function(event){ |
|
44 |
$('.multi_items_qty').val($(event.target).val()); |
|
45 |
}); |
|
46 |
</script> |
templates/webpages/part/test_page.html | ||
---|---|---|
28 | 28 |
Convertible unit 'Std': (only select parts with unit Tag/Std/Min)<br> |
29 | 29 |
[% L.part_picker('part_id7', undef, convertible_unit='Std') %]<br> |
30 | 30 |
|
31 |
With multi select popup<br> |
|
32 |
[% L.part_picker('part_id8', undef, multiple=1) %]<br> |
|
33 |
|
|
31 | 34 |
<h2>Styling</h2> |
32 | 35 |
|
33 | 36 |
In a span: |
Auch abrufbar als: Unified diff
PartPicker: Multipicker als separate popupklasse