Revision 5aec18fe
Von Sven Schöling vor fast 8 Jahren hinzugefügt
SL/Controller/PriceRule.pm | ||
---|---|---|
236 | 236 |
} |
237 | 237 |
|
238 | 238 |
sub add_javascripts { |
239 |
$::request->{layout}->add_javascripts(qw(kivi.PriceRule.js autocomplete_customer.js autocomplete_vendor.js autocomplete_part.js));
|
|
239 |
$::request->{layout}->add_javascripts(qw(kivi.PriceRule.js autocomplete_customer.js autocomplete_vendor.js kivi.Part.js));
|
|
240 | 240 |
} |
241 | 241 |
|
242 | 242 |
sub init_price_rule { |
SL/Controller/RequirementSpec.pm | ||
---|---|---|
322 | 322 |
|
323 | 323 |
$::auth->assert('requirement_spec_edit'); |
324 | 324 |
$::request->{layout}->use_stylesheet("${_}.css") for qw(jquery.contextMenu requirement_spec); |
325 |
$::request->{layout}->use_javascript("${_}.js") for qw(jquery.jstree jquery/jquery.contextMenu jquery/jquery.hotkeys requirement_spec ckeditor/ckeditor ckeditor/adapters/jquery autocomplete_part autocomplete_customer);
|
|
325 |
$::request->{layout}->use_javascript("${_}.js") for qw(jquery.jstree jquery/jquery.contextMenu jquery/jquery.hotkeys requirement_spec ckeditor/ckeditor ckeditor/adapters/jquery kivi.Part.js autocomplete_customer);
|
|
326 | 326 |
$self->init_visible_section; |
327 | 327 |
|
328 | 328 |
return 1; |
SL/Presenter/Chart.pm | ||
---|---|---|
159 | 159 |
rendering. If you write a standard controller that only calls C<render> once, it |
160 | 160 |
will just work. In case the header is generated in a different render call |
161 | 161 |
(multiple blocks, ajax, old C<bin/mozilla> style controllers) you need to |
162 |
include C<js/autocomplete_part.js> yourself.
|
|
162 |
include C<js/autocomplete_chart.js> yourself.
|
|
163 | 163 |
|
164 | 164 |
=back |
165 | 165 |
|
SL/Presenter/Part.pm | ||
---|---|---|
42 | 42 |
join('', map { $params{$_} ? $self->input_tag("", delete $params{$_}, id => "${id}_${_}", type => 'hidden') : '' } qw(part_type classification_id unit convertible_unit)) . |
43 | 43 |
$self->input_tag("", ref $value ? $value->displayable_name : '', id => "${id}_name", %params); |
44 | 44 |
|
45 |
$::request->layout->add_javascripts('autocomplete_part.js');
|
|
45 |
$::request->layout->add_javascripts('kivi.Part.js');
|
|
46 | 46 |
$::request->presenter->need_reinit_widgets($id); |
47 | 47 |
|
48 | 48 |
$self->html_tag('span', $ret, class => 'part_picker'); |
... | ... | |
224 | 224 |
rendering. If you write a standard controller that only call C<render> once, it |
225 | 225 |
will just work. In case the header is generated in a different render call |
226 | 226 |
(multiple blocks, ajax, old C<bin/mozilla> style controllers) you need to |
227 |
include C<js/autocomplete_part.js> yourself.
|
|
227 |
include C<kivi.Part.js> yourself.
|
|
228 | 228 |
|
229 | 229 |
=back |
230 | 230 |
|
bin/mozilla/do.pl | ||
---|---|---|
302 | 302 |
|
303 | 303 |
$form->{follow_up_trans_info} = $form->{donumber} .'('. $form->{VC_OBJ}->name .')'; |
304 | 304 |
|
305 |
$::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.File kivi.MassDeliveryOrderPrint kivi.SalesPurchase ckeditor/ckeditor ckeditor/adapters/jquery kivi.io autocomplete_customer autocomplete_part));
|
|
305 |
$::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.File kivi.MassDeliveryOrderPrint kivi.SalesPurchase kivi.Part ckeditor/ckeditor ckeditor/adapters/jquery kivi.io autocomplete_customer));
|
|
306 | 306 |
|
307 | 307 |
my @custom_hidden; |
308 | 308 |
push @custom_hidden, map { "shiptocvar_" . $_->name } @{ SL::DB::Manager::CustomVariableConfig->get_all(where => [ module => 'ShipTo' ]) }; |
bin/mozilla/ir.pl | ||
---|---|---|
296 | 296 |
$TMPL_VAR{payment_terms_obj} = get_payment_terms_for_invoice(); |
297 | 297 |
$form->{duedate} = $TMPL_VAR{payment_terms_obj}->calc_date(reference_date => $form->{invdate}, due_date => $form->{due_due})->to_kivitendo if $TMPL_VAR{payment_terms_obj}; |
298 | 298 |
|
299 |
$::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.Draft kivi.File kivi.SalesPurchase ckeditor/ckeditor ckeditor/adapters/jquery kivi.io autocomplete_customer autocomplete_part autocomplete_project client_js));
|
|
299 |
$::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.Draft kivi.File kivi.SalesPurchase kivi.Part ckeditor/ckeditor ckeditor/adapters/jquery kivi.io autocomplete_customer autocomplete_project client_js));
|
|
300 | 300 |
|
301 | 301 |
$form->header(); |
302 | 302 |
|
bin/mozilla/is.pl | ||
---|---|---|
354 | 354 |
), @custom_hiddens, |
355 | 355 |
map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts}]; |
356 | 356 |
|
357 |
$::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.Draft kivi.File kivi.SalesPurchase ckeditor/ckeditor ckeditor/adapters/jquery kivi.io autocomplete_customer autocomplete_part client_js));
|
|
357 |
$::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.Draft kivi.File kivi.SalesPurchase kivi.Part ckeditor/ckeditor ckeditor/adapters/jquery kivi.io autocomplete_customer client_js));
|
|
358 | 358 |
|
359 | 359 |
$TMPL_VAR{payment_terms_obj} = get_payment_terms_for_invoice(); |
360 | 360 |
$form->{duedate} = $TMPL_VAR{payment_terms_obj}->calc_date(reference_date => $form->{invdate}, due_date => $form->{duedate})->to_kivitendo if $TMPL_VAR{payment_terms_obj}; |
bin/mozilla/oe.pl | ||
---|---|---|
435 | 435 |
} |
436 | 436 |
} |
437 | 437 |
|
438 |
$::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.SalesPurchase kivi.File show_form_details show_history show_vc_details ckeditor/ckeditor ckeditor/adapters/jquery kivi.io autocomplete_customer autocomplete_part));
|
|
438 |
$::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.SalesPurchase kivi.File kivi.Part show_form_details show_history show_vc_details ckeditor/ckeditor ckeditor/adapters/jquery kivi.io autocomplete_customer));
|
|
439 | 439 |
|
440 | 440 |
$form->header; |
441 | 441 |
if ($form->{CFDD_shipto} && $form->{CFDD_shipto_id} ) { |
js/autocomplete_part.js | ||
---|---|---|
1 |
namespace('kivi', function(k){ |
|
2 |
"use strict"; |
|
3 |
|
|
4 |
k.PartPicker = function($real, options) { |
|
5 |
// short circuit in case someone double inits us |
|
6 |
if ($real.data("part_picker")) |
|
7 |
return $real.data("part_picker"); |
|
8 |
|
|
9 |
var KEY = { |
|
10 |
ESCAPE: 27, |
|
11 |
ENTER: 13, |
|
12 |
TAB: 9, |
|
13 |
LEFT: 37, |
|
14 |
RIGHT: 39, |
|
15 |
PAGE_UP: 33, |
|
16 |
PAGE_DOWN: 34, |
|
17 |
SHIFT: 16, |
|
18 |
CTRL: 17, |
|
19 |
ALT: 18, |
|
20 |
}; |
|
21 |
var CLASSES = { |
|
22 |
PICKED: 'partpicker-picked', |
|
23 |
UNDEFINED: 'partpicker-undefined', |
|
24 |
FAT_SET_ITEM: 'partpicker_fat_set_item', |
|
25 |
} |
|
26 |
var o = $.extend({ |
|
27 |
limit: 20, |
|
28 |
delay: 50, |
|
29 |
fat_set_item: $real.hasClass(CLASSES.FAT_SET_ITEM), |
|
30 |
}, options); |
|
31 |
var STATES = { |
|
32 |
PICKED: CLASSES.PICKED, |
|
33 |
UNDEFINED: CLASSES.UNDEFINED |
|
34 |
} |
|
35 |
var real_id = $real.attr('id'); |
|
36 |
var $dummy = $('#' + real_id + '_name'); |
|
37 |
var $part_type = $('#' + real_id + '_part_type'); |
|
38 |
var $classification_id = $('#' + real_id + '_classification_id'); |
|
39 |
var $unit = $('#' + real_id + '_unit'); |
|
40 |
var $convertible_unit = $('#' + real_id + '_convertible_unit'); |
|
41 |
var state = STATES.PICKED; |
|
42 |
var last_real = $real.val(); |
|
43 |
var last_dummy = $dummy.val(); |
|
44 |
var timer; |
|
45 |
|
|
46 |
function open_dialog () { |
|
47 |
k.popup_dialog({ |
|
48 |
url: 'controller.pl?action=Part/part_picker_search', |
|
49 |
data: $.extend({ |
|
50 |
real_id: real_id, |
|
51 |
}, ajax_data($dummy.val())), |
|
52 |
id: 'part_selection', |
|
53 |
dialog: { |
|
54 |
title: k.t8('Part picker'), |
|
55 |
width: 800, |
|
56 |
height: 800, |
|
57 |
} |
|
58 |
}); |
|
59 |
window.clearTimeout(timer); |
|
60 |
return true; |
|
61 |
} |
|
62 |
|
|
63 |
function ajax_data(term) { |
|
64 |
var data = { |
|
65 |
'filter.all:substr:multi::ilike': term, |
|
66 |
'filter.obsolete': 0, |
|
67 |
'filter.unit_obj.convertible_to': $convertible_unit && $convertible_unit.val() ? $convertible_unit.val() : '', |
|
68 |
no_paginate: $('#no_paginate').prop('checked') ? 1 : 0, |
|
69 |
current: $real.val(), |
|
70 |
}; |
|
71 |
|
|
72 |
if ($part_type && $part_type.val()) |
|
73 |
data['filter.part_type'] = $part_type.val().split(','); |
|
74 |
|
|
75 |
if ($classification_id && $classification_id.val()) |
|
76 |
data['filter.classification_id'] = $classification_id.val().split(','); |
|
77 |
|
|
78 |
if ($unit && $unit.val()) |
|
79 |
data['filter.unit'] = $unit.val().split(','); |
|
80 |
|
|
81 |
return data; |
|
82 |
} |
|
83 |
|
|
84 |
function set_item (item) { |
|
85 |
if (item.id) { |
|
86 |
$real.val(item.id); |
|
87 |
// autocomplete ui has name, use the value for ajax items, which contains displayable_name |
|
88 |
$dummy.val(item.name ? item.name : item.value); |
|
89 |
} else { |
|
90 |
$real.val(''); |
|
91 |
$dummy.val(''); |
|
92 |
} |
|
93 |
state = STATES.PICKED; |
|
94 |
last_real = $real.val(); |
|
95 |
last_dummy = $dummy.val(); |
|
96 |
$real.trigger('change'); |
|
97 |
|
|
98 |
if (o.fat_set_item && item.id) { |
|
99 |
$.ajax({ |
|
100 |
url: 'controller.pl?action=Part/show.json', |
|
101 |
data: { 'part.id': item.id }, |
|
102 |
success: function(rsp) { |
|
103 |
$real.trigger('set_item:PartPicker', rsp); |
|
104 |
}, |
|
105 |
}); |
|
106 |
} else { |
|
107 |
$real.trigger('set_item:PartPicker', item); |
|
108 |
} |
|
109 |
annotate_state(); |
|
110 |
} |
|
111 |
|
|
112 |
function make_defined_state () { |
|
113 |
if (state == STATES.PICKED) { |
|
114 |
annotate_state(); |
|
115 |
return true |
|
116 |
} else if (state == STATES.UNDEFINED && $dummy.val() === '') |
|
117 |
set_item({}) |
|
118 |
else { |
|
119 |
set_item({ id: last_real, name: last_dummy }) |
|
120 |
} |
|
121 |
annotate_state(); |
|
122 |
} |
|
123 |
|
|
124 |
function annotate_state () { |
|
125 |
if (state == STATES.PICKED) |
|
126 |
$dummy.removeClass(STATES.UNDEFINED).addClass(STATES.PICKED); |
|
127 |
else if (state == STATES.UNDEFINED && $dummy.val() === '') |
|
128 |
$dummy.removeClass(STATES.UNDEFINED).addClass(STATES.PICKED); |
|
129 |
else { |
|
130 |
$dummy.addClass(STATES.UNDEFINED).removeClass(STATES.PICKED); |
|
131 |
} |
|
132 |
} |
|
133 |
|
|
134 |
function update_results () { |
|
135 |
$.ajax({ |
|
136 |
url: 'controller.pl?action=Part/part_picker_result', |
|
137 |
data: $.extend({ |
|
138 |
'real_id': $real.val(), |
|
139 |
}, ajax_data(function(){ var val = $('#part_picker_filter').val(); return val === undefined ? '' : val })), |
|
140 |
success: function(data){ $('#part_picker_result').html(data) } |
|
141 |
}); |
|
142 |
} |
|
143 |
|
|
144 |
function result_timer (event) { |
|
145 |
if (!$('no_paginate').prop('checked')) { |
|
146 |
if (event.keyCode == KEY.PAGE_UP) { |
|
147 |
$('#part_picker_result a.paginate-prev').click(); |
|
148 |
return; |
|
149 |
} |
|
150 |
if (event.keyCode == KEY.PAGE_DOWN) { |
|
151 |
$('#part_picker_result a.paginate-next').click(); |
|
152 |
return; |
|
153 |
} |
|
154 |
} |
|
155 |
window.clearTimeout(timer); |
|
156 |
timer = window.setTimeout(update_results, 100); |
|
157 |
} |
|
158 |
|
|
159 |
function close_popup() { |
|
160 |
$('#part_selection').dialog('close'); |
|
161 |
} |
|
162 |
|
|
163 |
function handle_changed_text(callbacks) { |
|
164 |
$.ajax({ |
|
165 |
url: 'controller.pl?action=Part/ajax_autocomplete', |
|
166 |
dataType: "json", |
|
167 |
data: $.extend( ajax_data($dummy.val()), { prefer_exact: 1 } ), |
|
168 |
success: function (data) { |
|
169 |
if (data.length == 1) { |
|
170 |
set_item(data[0]); |
|
171 |
if (callbacks && callbacks.match_one) callbacks.match_one(data[0]); |
|
172 |
} else if (data.length > 1) { |
|
173 |
state = STATES.UNDEFINED; |
|
174 |
if (callbacks && callbacks.match_many) callbacks.match_many(data); |
|
175 |
} else { |
|
176 |
state = STATES.UNDEFINED; |
|
177 |
if (callbacks &&callbacks.match_none) callbacks.match_none(); |
|
178 |
} |
|
179 |
annotate_state(); |
|
180 |
} |
|
181 |
}); |
|
182 |
} |
|
183 |
|
|
184 |
$dummy.autocomplete({ |
|
185 |
source: function(req, rsp) { |
|
186 |
$.ajax($.extend(o, { |
|
187 |
url: 'controller.pl?action=Part/ajax_autocomplete', |
|
188 |
dataType: "json", |
|
189 |
data: ajax_data(req.term), |
|
190 |
success: function (data){ rsp(data) } |
|
191 |
})); |
|
192 |
}, |
|
193 |
select: function(event, ui) { |
|
194 |
set_item(ui.item); |
|
195 |
}, |
|
196 |
search: function(event, ui) { |
|
197 |
if ((event.which == KEY.SHIFT) || (event.which == KEY.CTRL) || (event.which == KEY.ALT)) |
|
198 |
event.preventDefault(); |
|
199 |
} |
|
200 |
}); |
|
201 |
/* In case users are impatient and want to skip ahead: |
|
202 |
* Capture <enter> key events and check if it's a unique hit. |
|
203 |
* If it is, go ahead and assume it was selected. If it wasn't don't do |
|
204 |
* anything so that autocompletion kicks in. For <tab> don't prevent |
|
205 |
* propagation. It would be nice to catch it, but javascript is too stupid |
|
206 |
* to fire a tab event later on, so we'd have to reimplement the "find |
|
207 |
* next active element in tabindex order and focus it". |
|
208 |
*/ |
|
209 |
/* note: |
|
210 |
* event.which does not contain tab events in keypressed in firefox but will report 0 |
|
211 |
* chrome does not fire keypressed at all on tab or escape |
|
212 |
*/ |
|
213 |
$dummy.keydown(function(event){ |
|
214 |
if (event.which == KEY.ENTER || event.which == KEY.TAB) { |
|
215 |
// if string is empty assume they want to delete |
|
216 |
if ($dummy.val() === '') { |
|
217 |
set_item({}); |
|
218 |
return true; |
|
219 |
} else if (state == STATES.PICKED) { |
|
220 |
return true; |
|
221 |
} |
|
222 |
if (event.which == KEY.TAB) { |
|
223 |
event.preventDefault(); |
|
224 |
handle_changed_text(); |
|
225 |
} |
|
226 |
if (event.which == KEY.ENTER) { |
|
227 |
handle_changed_text({ |
|
228 |
match_one: function(){$('#update_button').click();}, |
|
229 |
match_many: function(){open_dialog();} |
|
230 |
}); |
|
231 |
return false; |
|
232 |
} |
|
233 |
} else if ((event.which != KEY.SHIFT) && (event.which != KEY.CTRL) && (event.which != KEY.ALT)) { |
|
234 |
state = STATES.UNDEFINED; |
|
235 |
} |
|
236 |
}); |
|
237 |
|
|
238 |
$dummy.on('paste', function(){ |
|
239 |
setTimeout(function() { |
|
240 |
handle_changed_text(); |
|
241 |
}, 1); |
|
242 |
}); |
|
243 |
|
|
244 |
$dummy.blur(function(){ |
|
245 |
window.clearTimeout(timer); |
|
246 |
timer = window.setTimeout(annotate_state, 100); |
|
247 |
}); |
|
248 |
|
|
249 |
// now add a picker div after the original input |
|
250 |
var popup_button = $('<span>').addClass('ppp_popup_button'); |
|
251 |
$dummy.after(popup_button); |
|
252 |
popup_button.click(open_dialog); |
|
253 |
|
|
254 |
var pp = { |
|
255 |
real: function() { return $real }, |
|
256 |
dummy: function() { return $dummy }, |
|
257 |
part_type: function() { return $part_type }, |
|
258 |
classification_id: function() { return $classification_id }, |
|
259 |
unit: function() { return $unit }, |
|
260 |
convertible_unit: function() { return $convertible_unit }, |
|
261 |
update_results: update_results, |
|
262 |
result_timer: result_timer, |
|
263 |
set_item: set_item, |
|
264 |
reset: make_defined_state, |
|
265 |
is_defined_state: function() { return state == STATES.PICKED }, |
|
266 |
init_results: function () { |
|
267 |
$('div.part_picker_part').each(function(){ |
|
268 |
$(this).click(function(){ |
|
269 |
set_item({ |
|
270 |
id: $(this).children('input.part_picker_id').val(), |
|
271 |
name: $(this).children('input.part_picker_description').val(), |
|
272 |
classification_id: $(this).children('input.part_picker_classification_id').val(), |
|
273 |
unit: $(this).children('input.part_picker_unit').val(), |
|
274 |
partnumber: $(this).children('input.part_picker_partnumber').val(), |
|
275 |
description: $(this).children('input.part_picker_description').val(), |
|
276 |
}); |
|
277 |
close_popup(); |
|
278 |
$dummy.focus(); |
|
279 |
return true; |
|
280 |
}); |
|
281 |
}); |
|
282 |
$('#part_selection').keydown(function(e){ |
|
283 |
if (e.which == KEY.ESCAPE) { |
|
284 |
close_popup(); |
|
285 |
$dummy.focus(); |
|
286 |
} |
|
287 |
}); |
|
288 |
} |
|
289 |
} |
|
290 |
$real.data('part_picker', pp); |
|
291 |
return pp; |
|
292 |
} |
|
293 |
}); |
|
294 |
|
|
295 |
$(function(){ |
|
296 |
$('input.part_autocomplete').each(function(i,real){ |
|
297 |
kivi.PartPicker($(real)); |
|
298 |
}) |
|
299 |
}); |
js/kivi.CustomerVendor.js | ||
---|---|---|
48 | 48 |
kivi.CustomerVendorPicker($ctrl).set_item({ id: cvar.id, name: cvar.value }); |
49 | 49 |
|
50 | 50 |
else if (cvar.type == 'part') |
51 |
kivi.PartPicker($ctrl).set_item({ id: cvar.id, name: cvar.value }); |
|
51 |
kivi.Part.Picker($ctrl).set_item({ id: cvar.id, name: cvar.value });
|
|
52 | 52 |
|
53 | 53 |
else |
54 | 54 |
$ctrl.val(cvar.value); |
js/kivi.Part.js | ||
---|---|---|
263 | 263 |
$.post("controller.pl", { action: 'Part/warehouse_changed', warehouse_id: function(){ return $('#part_warehouse_id').val() } }, kivi.eval_json_result); |
264 | 264 |
} |
265 | 265 |
|
266 |
ns.Picker = function($real, options) { |
|
267 |
// short circuit in case someone double inits us |
|
268 |
if ($real.data("part_picker")) |
|
269 |
return $real.data("part_picker"); |
|
270 |
|
|
271 |
var KEY = { |
|
272 |
ESCAPE: 27, |
|
273 |
ENTER: 13, |
|
274 |
TAB: 9, |
|
275 |
LEFT: 37, |
|
276 |
RIGHT: 39, |
|
277 |
PAGE_UP: 33, |
|
278 |
PAGE_DOWN: 34, |
|
279 |
SHIFT: 16, |
|
280 |
CTRL: 17, |
|
281 |
ALT: 18, |
|
282 |
}; |
|
283 |
var CLASSES = { |
|
284 |
PICKED: 'partpicker-picked', |
|
285 |
UNDEFINED: 'partpicker-undefined', |
|
286 |
FAT_SET_ITEM: 'partpicker_fat_set_item', |
|
287 |
} |
|
288 |
var o = $.extend({ |
|
289 |
limit: 20, |
|
290 |
delay: 50, |
|
291 |
fat_set_item: $real.hasClass(CLASSES.FAT_SET_ITEM), |
|
292 |
}, options); |
|
293 |
var STATES = { |
|
294 |
PICKED: CLASSES.PICKED, |
|
295 |
UNDEFINED: CLASSES.UNDEFINED |
|
296 |
} |
|
297 |
var real_id = $real.attr('id'); |
|
298 |
var $dummy = $('#' + real_id + '_name'); |
|
299 |
var $part_type = $('#' + real_id + '_part_type'); |
|
300 |
var $classification_id = $('#' + real_id + '_classification_id'); |
|
301 |
var $unit = $('#' + real_id + '_unit'); |
|
302 |
var $convertible_unit = $('#' + real_id + '_convertible_unit'); |
|
303 |
var state = STATES.PICKED; |
|
304 |
var last_real = $real.val(); |
|
305 |
var last_dummy = $dummy.val(); |
|
306 |
var timer; |
|
307 |
|
|
308 |
function open_dialog () { |
|
309 |
kivi.popup_dialog({ |
|
310 |
url: 'controller.pl?action=Part/part_picker_search', |
|
311 |
data: $.extend({ |
|
312 |
real_id: real_id, |
|
313 |
}, ajax_data($dummy.val())), |
|
314 |
id: 'part_selection', |
|
315 |
dialog: { |
|
316 |
title: kivi.t8('Part picker'), |
|
317 |
width: 800, |
|
318 |
height: 800, |
|
319 |
} |
|
320 |
}); |
|
321 |
window.clearTimeout(timer); |
|
322 |
return true; |
|
323 |
} |
|
324 |
|
|
325 |
function ajax_data(term) { |
|
326 |
var data = { |
|
327 |
'filter.all:substr:multi::ilike': term, |
|
328 |
'filter.obsolete': 0, |
|
329 |
'filter.unit_obj.convertible_to': $convertible_unit && $convertible_unit.val() ? $convertible_unit.val() : '', |
|
330 |
no_paginate: $('#no_paginate').prop('checked') ? 1 : 0, |
|
331 |
current: $real.val(), |
|
332 |
}; |
|
333 |
|
|
334 |
if ($part_type && $part_type.val()) |
|
335 |
data['filter.part_type'] = $part_type.val().split(','); |
|
336 |
|
|
337 |
if ($classification_id && $classification_id.val()) |
|
338 |
data['filter.classification_id'] = $classification_id.val().split(','); |
|
339 |
|
|
340 |
if ($unit && $unit.val()) |
|
341 |
data['filter.unit'] = $unit.val().split(','); |
|
342 |
|
|
343 |
return data; |
|
344 |
} |
|
345 |
|
|
346 |
function set_item (item) { |
|
347 |
if (item.id) { |
|
348 |
$real.val(item.id); |
|
349 |
// autocomplete ui has name, use the value for ajax items, which contains displayable_name |
|
350 |
$dummy.val(item.name ? item.name : item.value); |
|
351 |
} else { |
|
352 |
$real.val(''); |
|
353 |
$dummy.val(''); |
|
354 |
} |
|
355 |
state = STATES.PICKED; |
|
356 |
last_real = $real.val(); |
|
357 |
last_dummy = $dummy.val(); |
|
358 |
$real.trigger('change'); |
|
359 |
|
|
360 |
if (o.fat_set_item && item.id) { |
|
361 |
$.ajax({ |
|
362 |
url: 'controller.pl?action=Part/show.json', |
|
363 |
data: { id: item.id }, |
|
364 |
success: function(rsp) { |
|
365 |
$real.trigger('set_item:PartPicker', rsp); |
|
366 |
}, |
|
367 |
}); |
|
368 |
} else { |
|
369 |
$real.trigger('set_item:PartPicker', item); |
|
370 |
} |
|
371 |
annotate_state(); |
|
372 |
} |
|
373 |
|
|
374 |
function make_defined_state () { |
|
375 |
if (state == STATES.PICKED) { |
|
376 |
annotate_state(); |
|
377 |
return true |
|
378 |
} else if (state == STATES.UNDEFINED && $dummy.val() === '') |
|
379 |
set_item({}) |
|
380 |
else { |
|
381 |
set_item({ id: last_real, name: last_dummy }) |
|
382 |
} |
|
383 |
annotate_state(); |
|
384 |
} |
|
385 |
|
|
386 |
function annotate_state () { |
|
387 |
if (state == STATES.PICKED) |
|
388 |
$dummy.removeClass(STATES.UNDEFINED).addClass(STATES.PICKED); |
|
389 |
else if (state == STATES.UNDEFINED && $dummy.val() === '') |
|
390 |
$dummy.removeClass(STATES.UNDEFINED).addClass(STATES.PICKED); |
|
391 |
else { |
|
392 |
$dummy.addClass(STATES.UNDEFINED).removeClass(STATES.PICKED); |
|
393 |
} |
|
394 |
} |
|
395 |
|
|
396 |
function update_results () { |
|
397 |
$.ajax({ |
|
398 |
url: 'controller.pl?action=Part/part_picker_result', |
|
399 |
data: $.extend({ |
|
400 |
'real_id': $real.val(), |
|
401 |
}, ajax_data(function(){ var val = $('#part_picker_filter').val(); return val === undefined ? '' : val })), |
|
402 |
success: function(data){ $('#part_picker_result').html(data) } |
|
403 |
}); |
|
404 |
} |
|
405 |
|
|
406 |
function result_timer (event) { |
|
407 |
if (!$('no_paginate').prop('checked')) { |
|
408 |
if (event.keyCode == KEY.PAGE_UP) { |
|
409 |
$('#part_picker_result a.paginate-prev').click(); |
|
410 |
return; |
|
411 |
} |
|
412 |
if (event.keyCode == KEY.PAGE_DOWN) { |
|
413 |
$('#part_picker_result a.paginate-next').click(); |
|
414 |
return; |
|
415 |
} |
|
416 |
} |
|
417 |
window.clearTimeout(timer); |
|
418 |
timer = window.setTimeout(update_results, 100); |
|
419 |
} |
|
420 |
|
|
421 |
function close_popup() { |
|
422 |
$('#part_selection').dialog('close'); |
|
423 |
} |
|
424 |
|
|
425 |
function handle_changed_text(callbacks) { |
|
426 |
$.ajax({ |
|
427 |
url: 'controller.pl?action=Part/ajax_autocomplete', |
|
428 |
dataType: "json", |
|
429 |
data: $.extend( ajax_data($dummy.val()), { prefer_exact: 1 } ), |
|
430 |
success: function (data) { |
|
431 |
if (data.length == 1) { |
|
432 |
set_item(data[0]); |
|
433 |
if (callbacks && callbacks.match_one) callbacks.match_one(data[0]); |
|
434 |
} else if (data.length > 1) { |
|
435 |
state = STATES.UNDEFINED; |
|
436 |
if (callbacks && callbacks.match_many) callbacks.match_many(data); |
|
437 |
} else { |
|
438 |
state = STATES.UNDEFINED; |
|
439 |
if (callbacks &&callbacks.match_none) callbacks.match_none(); |
|
440 |
} |
|
441 |
annotate_state(); |
|
442 |
} |
|
443 |
}); |
|
444 |
} |
|
445 |
|
|
446 |
$dummy.autocomplete({ |
|
447 |
source: function(req, rsp) { |
|
448 |
$.ajax($.extend(o, { |
|
449 |
url: 'controller.pl?action=Part/ajax_autocomplete', |
|
450 |
dataType: "json", |
|
451 |
data: ajax_data(req.term), |
|
452 |
success: function (data){ rsp(data) } |
|
453 |
})); |
|
454 |
}, |
|
455 |
select: function(event, ui) { |
|
456 |
set_item(ui.item); |
|
457 |
}, |
|
458 |
search: function(event, ui) { |
|
459 |
if ((event.which == KEY.SHIFT) || (event.which == KEY.CTRL) || (event.which == KEY.ALT)) |
|
460 |
event.preventDefault(); |
|
461 |
} |
|
462 |
}); |
|
463 |
/* In case users are impatient and want to skip ahead: |
|
464 |
* Capture <enter> key events and check if it's a unique hit. |
|
465 |
* If it is, go ahead and assume it was selected. If it wasn't don't do |
|
466 |
* anything so that autocompletion kicks in. For <tab> don't prevent |
|
467 |
* propagation. It would be nice to catch it, but javascript is too stupid |
|
468 |
* to fire a tab event later on, so we'd have to reimplement the "find |
|
469 |
* next active element in tabindex order and focus it". |
|
470 |
*/ |
|
471 |
/* note: |
|
472 |
* event.which does not contain tab events in keypressed in firefox but will report 0 |
|
473 |
* chrome does not fire keypressed at all on tab or escape |
|
474 |
*/ |
|
475 |
$dummy.keydown(function(event){ |
|
476 |
if (event.which == KEY.ENTER || event.which == KEY.TAB) { |
|
477 |
// if string is empty assume they want to delete |
|
478 |
if ($dummy.val() === '') { |
|
479 |
set_item({}); |
|
480 |
return true; |
|
481 |
} else if (state == STATES.PICKED) { |
|
482 |
return true; |
|
483 |
} |
|
484 |
if (event.which == KEY.TAB) { |
|
485 |
event.preventDefault(); |
|
486 |
handle_changed_text(); |
|
487 |
} |
|
488 |
if (event.which == KEY.ENTER) { |
|
489 |
handle_changed_text({ |
|
490 |
match_one: function(){$('#update_button').click();}, |
|
491 |
match_many: function(){open_dialog();} |
|
492 |
}); |
|
493 |
return false; |
|
494 |
} |
|
495 |
} else if ((event.which != KEY.SHIFT) && (event.which != KEY.CTRL) && (event.which != KEY.ALT)) { |
|
496 |
state = STATES.UNDEFINED; |
|
497 |
} |
|
498 |
}); |
|
499 |
|
|
500 |
$dummy.on('paste', function(){ |
|
501 |
setTimeout(function() { |
|
502 |
handle_changed_text(); |
|
503 |
}, 1); |
|
504 |
}); |
|
505 |
|
|
506 |
$dummy.blur(function(){ |
|
507 |
window.clearTimeout(timer); |
|
508 |
timer = window.setTimeout(annotate_state, 100); |
|
509 |
}); |
|
510 |
|
|
511 |
// now add a picker div after the original input |
|
512 |
var popup_button = $('<span>').addClass('ppp_popup_button'); |
|
513 |
$dummy.after(popup_button); |
|
514 |
popup_button.click(open_dialog); |
|
515 |
|
|
516 |
var pp = { |
|
517 |
real: function() { return $real }, |
|
518 |
dummy: function() { return $dummy }, |
|
519 |
part_type: function() { return $part_type }, |
|
520 |
classification_id: function() { return $classification_id }, |
|
521 |
unit: function() { return $unit }, |
|
522 |
convertible_unit: function() { return $convertible_unit }, |
|
523 |
update_results: update_results, |
|
524 |
result_timer: result_timer, |
|
525 |
set_item: set_item, |
|
526 |
reset: make_defined_state, |
|
527 |
is_defined_state: function() { return state == STATES.PICKED }, |
|
528 |
init_results: function () { |
|
529 |
$('div.part_picker_part').each(function(){ |
|
530 |
$(this).click(function(){ |
|
531 |
set_item({ |
|
532 |
id: $(this).children('input.part_picker_id').val(), |
|
533 |
name: $(this).children('input.part_picker_description').val(), |
|
534 |
classification_id: $(this).children('input.part_picker_classification_id').val(), |
|
535 |
unit: $(this).children('input.part_picker_unit').val(), |
|
536 |
partnumber: $(this).children('input.part_picker_partnumber').val(), |
|
537 |
description: $(this).children('input.part_picker_description').val(), |
|
538 |
}); |
|
539 |
close_popup(); |
|
540 |
$dummy.focus(); |
|
541 |
return true; |
|
542 |
}); |
|
543 |
}); |
|
544 |
$('#part_selection').keydown(function(e){ |
|
545 |
if (e.which == KEY.ESCAPE) { |
|
546 |
close_popup(); |
|
547 |
$dummy.focus(); |
|
548 |
} |
|
549 |
}); |
|
550 |
} |
|
551 |
} |
|
552 |
$real.data('part_picker', pp); |
|
553 |
return pp; |
|
554 |
}; |
|
555 |
|
|
266 | 556 |
$(function(){ |
267 | 557 |
|
268 | 558 |
// assortment |
... | ... | |
305 | 595 |
|
306 | 596 |
$('#part_warehouse_id').change(kivi.Part.reload_bin_selection); |
307 | 597 |
|
598 |
$('input.part_autocomplete').each(function(i,real){ |
|
599 |
kivi.Part.Picker($(real)); |
|
600 |
}); |
|
308 | 601 |
}); |
309 |
}) |
|
602 |
}); |
js/kivi.js | ||
---|---|---|
243 | 243 |
$(elt).datepicker(); |
244 | 244 |
}); |
245 | 245 |
|
246 |
if (ns.PartPicker)
|
|
246 |
if (ns.Part) |
|
247 | 247 |
ns.run_once_for('input.part_autocomplete', 'part_picker', function(elt) { |
248 |
kivi.PartPicker($(elt)); |
|
248 |
kivi.Part.Picker($(elt));
|
|
249 | 249 |
}); |
250 | 250 |
|
251 | 251 |
if (ns.ProjectPicker) |
templates/webpages/part/_part_picker_result.html | ||
---|---|---|
30 | 30 |
[% L.paginate_controls(target='#part_picker_result', selector='#part_picker_result', models=SELF.models) %] |
31 | 31 |
|
32 | 32 |
<script type='text/javascript'> |
33 |
kivi.PartPicker($('#'+$('#part_picker_real_id').val())).init_results() |
|
33 |
kivi.Part.Picker($('#'+$('#part_picker_real_id').val())).init_results()
|
|
34 | 34 |
</script> |
templates/webpages/part/part_picker_search.html | ||
---|---|---|
17 | 17 |
</div> |
18 | 18 |
|
19 | 19 |
<script type='text/javascript'> |
20 |
var pp = kivi.PartPicker($('#[% FORM.real_id %]')); |
|
20 |
var pp = kivi.Part.Picker($('#[% FORM.real_id %]'));
|
|
21 | 21 |
$(function(){ |
22 | 22 |
$('#part_picker_filter').focus(); |
23 | 23 |
pp.update_results(); |
Auch abrufbar als: Unified diff
PartPicker von autocomplete_part.js nach kivi.Part.js verschoben