CSS: Unix-style newlines für kivitendo DHTML-Menü
[kivitendo-erp.git] / js / requirement_spec.js
1 /* Functions used for the requirement specs */
2
3 namespace("kivi.requirement_spec", function(ns) {
4
5 // -----------------------------------------------------------------------------
6 // ------------------------------ basic settings -------------------------------
7 // -----------------------------------------------------------------------------
8
9 ns.basic_settings_customer_changed = function(customer_ctrl, value_ctrl) {
10   $.get(
11     'controller.pl?action=Customer/get_hourly_rate',
12     { id: $(customer_ctrl).val() },
13     function(data) { if (data.hourly_rate_formatted) $(value_ctrl).val(data.hourly_rate_formatted); }
14   );
15 };
16
17 // -----------------------------------------------------------------------------
18 // ------------------------------ the tree itself ------------------------------
19 // -----------------------------------------------------------------------------
20
21 ns.tree_check_move = function(data) {
22   var dragged_type = data.o.data('type');
23   var dropped_type = data.r.data('type');
24
25   // console.debug("dragged " + dragged_type + " dropped " + dropped_type + " dir " + data.p);
26
27   if ((dragged_type == "sections") || (dragged_type == "text-blocks-front") || (dragged_type == "text-blocks-back"))
28     return false;
29
30   if (dragged_type == "text-block") {
31     if ((dropped_type == "text-blocks-front") || (dropped_type == "text-blocks-back"))
32       return (data.p == "inside") || (data.p == "last");
33     if (dropped_type == "text-block")
34       return (data.p == "before") || (data.p == "after");
35
36     return false;
37   }
38
39   if (dragged_type == "section") {
40     if (dropped_type == "sections")
41       return (data.p == "inside") || (data.p == "last");
42     if (dropped_type == "section")
43       return (data.p == "before") || (data.p == "after");
44
45     return false;
46   }
47
48   // dragged_type == (sub) function blocks
49   if ((dropped_type == "text-block") || (dropped_type == "text-blocks-front") || (dropped_type == "text-blocks-back"))
50     return false;
51
52   var dropped_depth = dropped_type == "sections" ? 0 : dropped_type == "section" ? 1 : data.r.parent().parent().data('type') != "function-block" ? 2 : 3;
53   if ((data.p == "inside") || (data.p == "last"))
54     dropped_depth++;
55
56   var dragged_depth = 1 + data.o.children('ul').size();
57
58   // console.debug("dropped_depth " + dropped_depth + " dragged_depth " + dragged_depth);
59
60   return (2 <= dropped_depth) && ((dragged_depth + dropped_depth) <= 4);
61 };
62
63 ns.tree_node_moved = function(event) {
64   // console.debug("node moved");
65   var move_obj   = $.jstree._reference('#tree')._get_move();
66   var dragged    = move_obj.o;
67   var dropped    = move_obj.r;
68   var controller = dragged.data("type") == "text-block" ? "RequirementSpecTextBlock" : "RequirementSpecItem";
69   var data       = {
70     action:               controller + "/dragged_and_dropped",
71     requirement_spec_id:  $('#requirement_spec_id').val(),
72     id:                   dragged.data("id"),
73     dropped_id:           dropped.data("id"),
74     dropped_type:         dropped.data("type"),
75     position:             move_obj.p,
76     current_content_type: $('#current_content_type').val(),
77     current_content_id:   $('#current_content_id').val()
78   };
79   // console.debug("controller: " + controller);
80   // console.debug(data);
81
82   $.post("controller.pl", data, kivi.eval_json_result);
83
84   return true;
85 };
86
87 ns.tree_node_clicked = function(event) {
88   var node = $.jstree._reference('#tree')._get_node(event.target);
89   var type = node ? node.data('type') : undefined;
90
91   if (!type)
92     return;
93
94   var url = 'controller.pl?action='
95   $.get('controller.pl', {
96     action:               (/^text-block/.test(type) ? 'RequirementSpecTextBlock' : 'RequirementSpecItem') + '/ajax_list.js',
97     requirement_spec_id:  $('#requirement_spec_id').val(),
98     current_content_type: $('#current_content_type').val(),
99     current_content_id:   $('#current_content_id').val(),
100     clicked_type:         type,
101     clicked_id:           node.data('id')
102   }, kivi.eval_json_result);
103 };
104
105 ns.setup_tooltip_for_tree_node = function(li) {
106   $(li).find('a').prop('title', $(li).prop('title')).tooltip();
107   $(li).prop('title', '');
108 };
109
110 ns.tree_loaded = function(event) {
111   var id = $('#tree').data('initially_selected_node');
112   if (id)
113     $.jstree._reference("#tree").select_node(id, true);
114
115   $('#tree li[title!=""]').each(function(idx, elt) {
116     ns.setup_tooltip_for_tree_node(elt);
117   });
118 };
119
120 ns.tree_node_created = function(event, data) {
121   console.info("created ", data);
122   if (data && data.rslt && data.rslt.obj)
123     ns.setup_tooltip_for_tree_node(data.rslt.obj);
124 };
125
126 ns.initialize_requirement_spec = function(data) {
127   $('#tree').data('initially_selected_node', data.initially_selected_node);
128
129   $('#tree')
130     .bind('create_node.jstree', ns.tree_node_created)
131     .bind('move_node.jstree',   ns.tree_node_moved)
132     .bind('click.jstree',       ns.tree_node_clicked)
133     .bind('loaded.jstree',      ns.tree_loaded)
134     .jstree({
135       core: {
136         animation: 0,
137         initially_open: data.initially_open,
138       },
139       json_data: {
140         data: data.tree_data
141       },
142       crrm: {
143         move: {
144           check_move: ns.tree_check_move,
145           open_move:  true
146         }
147       },
148       themes: {
149         theme: "requirement-spec"
150       },
151       plugins: [ "themes", "json_data", "ui", "crrm", "dnd" ]
152     });
153
154   ns.create_context_menus(data);
155   $('#requirement_spec_tabs').on("tabsbeforeactivate", ns.tabs_before_activate);
156
157   ns.time_based_units = data.time_based_units;
158 };
159
160 // -------------------------------------------------------------------------
161 // ------------------------------ text blocks ------------------------------
162 // -------------------------------------------------------------------------
163
164 ns.find_text_block_id = function(clicked_elt) {
165   var id = $(clicked_elt).attr('id');
166
167   if (/^text-block-picture-\d+$/.test(id))
168     id = $(clicked_elt).closest('.text-block-context-menu').attr('id');
169
170   // console.log("id: " + id);
171   if (/^text-block-\d+$/.test(id)) {
172     // console.log("find_text_block_id: case 1: " + id.substr(11));
173     return id.substr(11) * 1;
174   }
175
176   id = $(clicked_elt).closest("[id*=text-block-]").attr('id')
177   if (/^text-block-\d+$/.test(id)) {
178     // console.log("find_text_block_id: case 2: " + id.substr(11));
179     return id.substr(11) * 1;
180   }
181
182   id = $(clicked_elt).closest("[id*=tb-]").attr('id')
183   if (/^tb-\d+$/.test(id)) {
184     // console.log("find_text_block_id: case 3: " + id.substr(3));
185     return id.substr(3) * 1;
186   }
187
188   // console.log("find_text_block_id: case undef, id: " + id);
189   return undefined;
190 };
191
192 ns.find_text_block_output_position = function(clicked_elt) {
193   var output_position = $(clicked_elt).closest('#text-block-list-container').find('#text_block_output_position').val();
194   if (output_position)
195     return output_position;
196
197   var type = $(clicked_elt).closest('#tb-back,#tb-front').data('type') || $('#current_content_type').val();
198   if (/^text-blocks-(front|back)/.test(type))
199     return type == "text-blocks-front" ? 0 : 1;
200
201   return undefined;
202 };
203
204 ns.disable_edit_text_block_commands = function(key, opt) {
205   return ns.find_text_block_id(opt.$trigger) == undefined;
206 };
207
208 ns.standard_text_block_ajax_call = function(key, opt, other_data) {
209   var data = {
210     action:               "RequirementSpecTextBlock/ajax_" + key,
211     requirement_spec_id:  $('#requirement_spec_id').val(),
212     id:                   ns.find_text_block_id(opt.$trigger),
213     output_position:      ns.find_text_block_output_position(opt.$trigger),
214     current_content_type: $('#current_content_type').val(),
215     current_content_id:   $('#current_content_id').val()
216   };
217
218   $.post("controller.pl", $.extend(data, other_data || {}), kivi.eval_json_result);
219
220   return true;
221 };
222
223 ns.cancel_edit_text_block_form = function(id_base) {
224   var id = $('#' + id_base + '_id').val();
225   $('#' + id_base + '_form').remove();
226   if (id)
227     $('#text-block-' + id).show();
228 };
229
230 ns.ask_delete_text_block = function(key, opt) {
231   if (confirm(kivi.t8("Are you sure?")))
232     ns.standard_text_block_ajax_call(key, opt);
233   return true;
234 };
235
236 ns.find_text_block_picture_id = function(clicked_elt) {
237   var id    = $(clicked_elt).attr('id');
238   var match = id.match(/^text-block-picture-(\d+)$/);
239   if (match)
240     return match[1] * 1;
241
242   return undefined;
243 };
244
245 ns.add_edit_text_block_picture_ajax_call = function(key, opt) {
246   var title = key == 'add_picture' ? kivi.t8('Add picture to text block') : kivi.t8('Edit picture');
247
248   kivi.popup_dialog({ url:    'controller.pl',
249                       data:   { action:     'RequirementSpecTextBlock/ajax_' + key,
250                                 id:         ns.find_text_block_id(opt.$trigger),
251                                 picture_id: ns.find_text_block_picture_id(opt.$trigger) },
252                       dialog: { title:      title }});
253
254   return true;
255 };
256
257 ns.standard_text_block_picture_ajax_call = function(key, opt) {
258   var data = {
259       action: "RequirementSpecTextBlock/ajax_" + key
260     , id:     ns.find_text_block_picture_id(opt.$trigger)
261   };
262
263   if (key == 'download_picture')
264     $.download("controller.pl", data);
265   else
266     $.post("controller.pl", data, kivi.eval_json_result);
267
268   return true;
269 };
270
271 ns.ask_delete_text_block_picture = function(key, opt) {
272   if (confirm(kivi.t8("Are you sure?")))
273     ns.standard_text_block_picture_ajax_call(key, opt);
274   return true;
275 };
276
277 ns.handle_text_block_picture_popup_menu_markings = function(opt, add) {
278   var id = ns.find_text_block_picture_id(opt.$trigger);
279   if (id)
280     $('#text-block-picture-' + id ).toggleClass('selected', add);
281   return true;
282 };
283
284 ns.text_block_picture_popup_menu_shown = function(opt) {
285   return ns.handle_text_block_picture_popup_menu_markings(opt, true);
286 };
287
288 ns.text_block_picture_popup_menu_hidden = function(opt) {
289   return ns.handle_text_block_picture_popup_menu_markings(opt, false);
290 };
291
292 ns.make_text_block_picture_lists_sortable = function() {
293   kivi.run_once_for(".requirement-spec-text-block-picture-list", 'make-text-block-picture-list-sortable', function($elt) {
294     $elt.sortable({
295       stop: function(event, ui) {
296         $.post('controller.pl?action=RequirementSpecTextBlock/reorder_pictures', {
297           'picture_id[]': $($elt.sortable('toArray')).map(function(idx, str) { return str.replace('text-block-picture-', ''); }).toArray()
298         });
299         return ui;
300       }
301       , distance: 5
302     });
303   });
304 };
305
306 // --------------------------------------------------------------------------------
307 // ------------------------------ sections and items ------------------------------
308 // --------------------------------------------------------------------------------
309
310 ns.find_item_id = function(clicked_elt) {
311   // console.log("clicked id: " + $(clicked_elt).attr('id'));
312   var id     = $(clicked_elt).attr('id');
313   var result = /^(function-block|function-block-content|sub-function-block|sub-function-block-content|section|section-header)-(\d+)$/.exec(id);
314   if (result) {
315     // console.log("find_item_id: case 1: " + result[2]);
316     return result[2];
317   }
318
319   id = $(clicked_elt).closest("[id*=fb-]").attr('id')
320   if (/^fb-\d+$/.test(id)) {
321     // console.log("find_item_id: case 2: " + id.substr(3));
322     return id.substr(3) * 1;
323   }
324
325   // console.log("find_item_id: case undef");
326   return undefined;
327 };
328
329 ns.standard_item_ajax_call = function(key, opt, other_data) {
330   var data = {
331     action:               "RequirementSpecItem/ajax_" + key,
332     requirement_spec_id:  $('#requirement_spec_id').val(),
333     id:                   ns.find_item_id(opt.$trigger),
334     current_content_type: $('#current_content_type').val(),
335     current_content_id:   $('#current_content_id').val()
336   };
337
338   // console.log("I would normally POST the following now:");
339   // console.log(data);
340   $.post("controller.pl", $.extend(data, other_data || {}), kivi.eval_json_result);
341
342   return true;
343 };
344
345 ns.disable_edit_item_commands = function(key, opt) {
346   return ns.find_item_id(opt.$trigger) == undefined;
347 };
348
349 ns.disable_add_function_block_command = function(key, opt) {
350   return opt.$trigger.attr('id') == "sections";
351 };
352
353 ns.cancel_edit_item_form = function(form_id_base, options) {
354   $('#' + form_id_base + '_form').remove();
355   if (!options)
356     return;
357   if (options.to_show)
358     $(options.to_show).show();
359   if (options.to_hide_if_empty && (1 == $(options.to_hide_if_empty).children().size()))
360     $(options.to_hide_if_empty).hide();
361 };
362
363 ns.ask_delete_item = function(key, opt) {
364   if (confirm(kivi.t8("Are you sure?")))
365     ns.standard_item_ajax_call(key, opt);
366   return true;
367 };
368
369 ns.handle_text_block_popup_menu_markings = function(opt, add) {
370   var id = ns.find_text_block_id(opt.$trigger);
371   if (id)
372     $('#text-block-' + id).toggleClass('selected', add);
373   return true;
374 };
375
376 ns.text_block_popup_menu_shown = function(opt) {
377   return ns.handle_text_block_popup_menu_markings(opt, true);
378 };
379
380 ns.text_block_popup_menu_hidden = function(opt) {
381   return ns.handle_text_block_popup_menu_markings(opt, false);
382 };
383
384 ns.handle_item_popup_menu_markings = function(opt, add) {
385   var id = ns.find_item_id(opt.$trigger);
386   if (id)
387     $('#section-' + id + ',#function-block-' + id + ',#sub-function-block-' + id).toggleClass('selected', add);
388   return true;
389 };
390
391 ns.item_popup_menu_shown = function(opt) {
392   return ns.handle_item_popup_menu_markings(opt, true);
393 };
394
395 ns.item_popup_menu_hidden = function(opt) {
396   return ns.handle_item_popup_menu_markings(opt, false);
397 };
398
399 ns.submit_function_block = function(event, shift_in_out) {
400   event.preventDefault();
401
402   var prefix = $(this).attr('id').match("^(?:edit|new)_function_block_[\\d_]+\\d")[0];
403   var action = $('#' + prefix + '_id').val() ? 'update' : 'create';
404   kivi.submit_ajax_form('controller.pl?action=RequirementSpecItem/ajax_' + action, '#' + prefix + '_form', { shift_in_out: !!shift_in_out });
405
406   return false;
407 };
408
409 ns.init_function_block_keypress_events = function(form_id) {
410   $("#" + form_id + " INPUT[type=text]").bind("keypress", "return", ns.submit_function_block);
411
412   $('#' + form_id + ' INPUT[type=text],#' + form_id + ' TEXTAREA,#' + form_id + ' INPUT[type=button]')
413     .bind('keypress', 'shift+return', function(event) { return ns.submit_function_block.apply(this, [ event, true ]); });
414 };
415
416 ns.renumber_callback = function(accepted) {
417   console.log(accepted ? "yay :)" : "oh no :(");
418   if (!accepted)
419     return;
420
421   $.ajax({
422     url:     'controller.pl?action=RequirementSpec/renumber_sections',
423     type:    'post',
424     data:    { id: $('#requirement_spec_id').val() },
425     success: kivi.eval_json_result
426   });
427 };
428
429 ns.renumber = function(opt) {
430   $('#rs-dialog-confirm').remove();
431
432   var text1   = kivi.t8('Re-numbering all sections and function blocks in the order they are currently shown cannot be undone.');
433   var text2   = kivi.t8('Do you really want do continue?');
434   var $dialog = $('<div id="rs-dialog-confirm"><p>' + text1 + '</p><p>' + text2 + '</p></div>').hide().appendTo('body');
435   var buttons = {};
436
437   buttons[kivi.t8('Yes')] = function() {
438     $(this).dialog('close');
439     ns.renumber_callback(true);
440   };
441
442   buttons[kivi.t8('No')] = function() {
443     $(this).dialog('close');
444     ns.renumber_callback(false);
445   };
446
447   $dialog.dialog({
448       resizable: false
449     , modal:     true
450     , title:     kivi.t8('Are you sure?')
451     , height:    250
452     , width:     400
453     , buttons:   buttons
454   });
455 };
456
457 // -------------------------------------------------------------------------
458 // ------------------------------- templates -------------------------------
459 // -------------------------------------------------------------------------
460
461 ns.paste_template = function(key, opt, other_data) {
462   kivi.popup_dialog({ url: 'controller.pl?action=RequirementSpec/select_template_to_paste', dialog: { title: kivi.t8("Select template to paste") } });
463 };
464
465 ns.paste_selected_template = function(template_id) {
466   $('#jqueryui_popup_dialog').dialog("close");
467
468   var data = {
469     action:               "RequirementSpec/paste_template",
470     id:                   $('#requirement_spec_id').val(),
471     template_id:          template_id,
472     current_content_type: $('#current_content_type').val(),
473     current_content_id:   $('#current_content_id').val()
474   };
475
476   // console.log("I would normally POST the following now:");
477   // console.log(data);
478   $.post("controller.pl", data, kivi.eval_json_result);
479
480   return true;
481 };
482
483 // -------------------------------------------------------------------------
484 // ---------------------------- basic settings -----------------------------
485 // -------------------------------------------------------------------------
486 ns.standard_basic_settings_ajax_call = function(key, opt) {
487   if (key == 'cancel') {
488     if (confirm(kivi.t8('Do you really want to cancel?'))) {
489       $('#basic_settings').show();
490       $('#basic_settings_form,#project_link_form').remove();
491     }
492     return true;
493
494   } else if (key == 'save') {
495     $('#basic_settings_form_submit').click();
496     return true;
497   }
498
499   var data = 'action=RequirementSpec/ajax_' + key + '&id=' + encodeURIComponent($('#requirement_spec_id').val());
500
501   $.post("controller.pl", data, kivi.eval_json_result);
502
503   return true;
504 };
505
506 // -------------------------------------------------------------------------
507 // -------------------------- time/cost estimate ---------------------------
508 // -------------------------------------------------------------------------
509
510 ns.standard_time_cost_estimate_ajax_call = function(key, opt) {
511   if (key == 'cancel') {
512     if (confirm(kivi.t8('Do you really want to cancel?'))) {
513       $('#time_cost_estimate').show();
514       $('#time_cost_estimate_form_container').remove();
515     }
516     return true;
517   }
518
519   var add_data = '';
520   if (key == 'save_keep_open') {
521     key      = 'save';
522     add_data = 'keep_open=1&';
523   }
524
525   var data = "action=RequirementSpec/ajax_" + key + "_time_and_cost_estimate&" + add_data;
526
527   if (key == 'save')
528     data += $('#edit_time_cost_estimate_form').serialize()
529          +  '&' + $('#current_content_type').serialize()
530          +  '&' + $('#current_content_id').serialize();
531   else
532     data += 'id=' + encodeURIComponent($('#requirement_spec_id').val());
533
534   $.post("controller.pl", data, kivi.eval_json_result);
535
536   return true;
537 };
538
539 ns.time_cost_estimate_input_key_down = function(event) {
540   if(event.keyCode == 13) {
541     event.preventDefault();
542     ns.standard_time_cost_estimate_ajax_call('save');
543     return false;
544   }
545 };
546
547 // -------------------------------------------------------------------------
548 // --------------------------- quotations/orders ---------------------------
549 // -------------------------------------------------------------------------
550
551 ns.find_quotation_order_id = function(clicked_elt) {
552   return $(clicked_elt).find('>[name=order_id]').val();
553 };
554
555 ns.standard_quotation_order_ajax_call = function(key, opt) {
556   if (key == 'cancel') {
557     if (confirm(kivi.t8('Do you really want to cancel?'))) {
558       $('#quotations_and_orders').show();
559       $('#quotations_and_orders_article_assignment,#quotations_and_orders_new,#quotations_and_orders_update').remove();
560     }
561     return true;
562   }
563
564   else if ((key == 'create') && $('#quotations_and_orders_form INPUT[name="sections[].order_part_id"]').filter(function(idx, elt) { return ($(elt).val() || '') == '' }).size()) {
565     alert(kivi.t8('There is one or more sections for which no part has been assigned yet; therefore creating the new record is not possible yet.'));
566     return false;
567   }
568
569   var data = 'action=RequirementSpecOrder/' + key
570            + '&' + $('#requirement_spec_id').serialize();
571
572   if ((key == 'save_assignment') || (key == 'create') || (key == 'do_update'))
573     data += '&' + $('#quotations_and_orders_form').serialize();
574   else if ((key == 'update') || (key == 'delete'))
575     data += '&rs_order_id=' + encodeURIComponent(ns.find_quotation_order_id(opt.$trigger));
576
577   // console.log("I would normally POST the following now:");
578   // console.log(data);
579   $.post("controller.pl", data, kivi.eval_json_result);
580
581   return true;
582 };
583
584 ns.ask_delete_quotation_order = function(key, opt) {
585   if (confirm(kivi.t8("Are you sure?")))
586     ns.standard_quotation_order_ajax_call(key, opt);
587   return true;
588 };
589
590 ns.disable_edit_quotation_order_commands = function(key, opt) {
591   return ns.find_quotation_order_id(opt.$trigger) == undefined;
592 };
593
594 ns.disable_create_quotation_order_commands = function(key, opt) {
595   return !$('#quotations_and_orders_sections');
596 };
597
598 ns.assign_order_part_id_to_all = function() {
599   var order_part_id   = $('#quotations_and_orders_order_id').val();
600   var order_part_name = $('#quotations_and_orders_order_id_name').val();
601
602   $('#quotations_and_orders_form INPUT[name="sections[].order_part_id"]').each(function(idx, elt) {
603     $(elt).val(order_part_id);
604   });
605
606   $('#quotations_and_orders_form [id^=quotations_and_orders_sections_order_pard_id_]').filter(function() {
607     return $(this).attr('id') && $(this).attr('id').match("^quotations_and_orders_sections_order_pard_id_[0-9]+_name$");
608   }).each(function(idx, elt) {
609     $(elt).val(order_part_name);
610   });
611
612   var unit = $('#quotations_and_orders_order_id').closest('td').data('unit');
613   var text = ns.time_based_units[unit] ? kivi.t8("time and effort based position") : kivi.t8("flat-rate position");
614
615   $('#quotations_and_orders_form [data-unit-column=1]').html(unit);
616   $('#quotations_and_orders_form [data-position-type-column=1]').html(text);
617 };
618
619 ns.assign_order_part_on_part_picked = function(event, item) {
620   if (!item || !item.unit)
621     return;
622
623   var $elt = $(this),
624       id   = $elt.prop('id');
625
626   if (id == 'quotations_and_orders_order_id')
627     $elt.closest('td').data('unit', item.unit);
628
629   else {
630     var $tr  = $elt.closest('tr');
631     var text = ns.time_based_units[item.unit] ? kivi.t8("time and effort based position") : kivi.t8("flat-rate position");
632
633     $tr.find('[data-unit-column=1]').html(item.unit);
634     $tr.find('[data-position-type-column=1]').html(text);
635   }
636 };
637
638 // -------------------------------------------------------------------------
639 // ---------------------------- general actions ----------------------------
640 // -------------------------------------------------------------------------
641
642 ns.create_reqspec_pdf = function(key, opt) {
643   var data = {
644     action: "RequirementSpec/create_pdf",
645     id:     $('#requirement_spec_id').val()
646   };
647   $.download("controller.pl", data);
648 };
649
650 ns.create_reqspec_html = function(key, opt) {
651   window.open("controller.pl?action=RequirementSpec/create_html&id=" + encodeURIComponent($('#requirement_spec_id').val()), '_blank');
652   return true;
653 };
654
655 ns.copy_reqspec = function(key, opt) {
656   window.location.href = "controller.pl?action=RequirementSpec/new&copy_source_id=" + encodeURIComponent($('#requirement_spec_id').val());
657   return true;
658 };
659
660 ns.delete_reqspec = function(key, opt) {
661   if (confirm(kivi.t8("Are you sure?")))
662     window.location.href = "controller.pl?action=RequirementSpec/destroy&id=" + encodeURIComponent($('#requirement_spec_id').val());
663   return true;
664 };
665
666 ns.disable_commands = function(key, opt) {
667   if (key === "create_version")
668     return ($('#current_version_id').val() || '') == '' ? false : true;
669   return false;
670 };
671
672 // -------------------------------------------------------------------------
673 // -------------------------------- versions -------------------------------
674 // -------------------------------------------------------------------------
675
676 ns.find_versioned_copy_id = function(clicked_elt) {
677   var id = $(clicked_elt).find("[name=versioned_copy_id]");
678   return id.size() ? id.val() : undefined;
679 };
680
681 ns.disable_versioned_copy_item_commands = function(key, opt) {
682   if (key === "revert_to_version")
683     return !ns.find_versioned_copy_id(opt.$trigger);
684   return false;
685 };
686
687 ns.create_version = function() {
688   kivi.popup_dialog({ url:    'controller.pl',
689                       data:   { action:              'RequirementSpecVersion/new',
690                                 requirement_spec_id: $('#requirement_spec_id').val() },
691                       dialog: { title: kivi.t8('Create a new version') }});
692   return true;
693 };
694
695 ns.create_pdf_for_versioned_copy_ajax_call = function(key, opt) {
696   var data = {
697     action: "RequirementSpec/create_pdf",
698     id:     ns.find_versioned_copy_id(opt.$trigger) || $('#requirement_spec_id').val()
699   };
700   $.download("controller.pl", data);
701
702   return true;
703 };
704
705 ns.create_html_for_versioned_copy_ajax_call = function(key, opt) {
706   window.open("controller.pl?action=RequirementSpec/create_html&id=" + encodeURIComponent(ns.find_versioned_copy_id(opt.$trigger) || $('#requirement_spec_id').val()), '_blank');
707   return true;
708 };
709
710 ns.revert_to_versioned_copy_ajax_call = function(key, opt) {
711   if (!confirm(kivi.t8('Do you really want to revert to this version?')))
712     return true;
713
714   var data = {
715     action:            'RequirementSpec/revert_to',
716     versioned_copy_id: ns.find_versioned_copy_id(opt.$trigger),
717     id:                $('#requirement_spec_id').val()
718   };
719
720   $.post("controller.pl", data, kivi.eval_json_result);
721
722   return true;
723 };
724
725 // -------------------------------------------------------------------------
726 // -------------------------- time/cost estimate ---------------------------
727 // -------------------------------------------------------------------------
728
729 ns.standard_time_cost_estimate_ajax_call = function(key, opt) {
730   if (key == 'cancel') {
731     if (confirm(kivi.t8('Do you really want to cancel?'))) {
732       $('#time_cost_estimate').show();
733       $('#time_cost_estimate_form_container').remove();
734     }
735     return true;
736   }
737
738   var add_data = '';
739   if (key == 'save_keep_open') {
740     key      = 'save';
741     add_data = 'keep_open=1&';
742   }
743
744   var data = "action=RequirementSpec/ajax_" + key + "_time_and_cost_estimate&" + add_data;
745
746   if (key == 'save')
747     data += $('#edit_time_cost_estimate_form').serialize()
748          +  '&' + $('#current_content_type').serialize()
749          +  '&' + $('#current_content_id').serialize();
750   else
751     data += 'id=' + encodeURIComponent($('#requirement_spec_id').val());
752
753   $.post("controller.pl", data, kivi.eval_json_result);
754
755   return true;
756 };
757
758 ns.time_cost_estimate_input_key_down = function(event) {
759   if(event.keyCode == 13) {
760     event.preventDefault();
761     ns.standard_time_cost_estimate_ajax_call('save');
762     return false;
763   }
764 };
765
766 // -------------------------------------------------------------------------
767 // -------------------------- additional parts -----------------------------
768 // -------------------------------------------------------------------------
769
770 ns.standard_additional_parts_ajax_call = function(key, opt) {
771   var add_data = '';
772   if (key == 'save_keep_open') {
773     key      = 'save';
774     add_data = 'keep_open=1&';
775   }
776
777   var data = "action=RequirementSpecPart/ajax_" + key + "&" + add_data + 'requirement_spec_id=' + encodeURIComponent($('#requirement_spec_id').val()) + '&';
778
779   if (key == 'save')
780     data += $('#edit_additional_parts_form').serialize();
781
782   $.post("controller.pl", data, kivi.eval_json_result);
783
784   return true;
785 };
786
787 ns.prepare_edit_additional_parts_form = function() {
788   $("#edit_additional_parts_list tbody").sortable({
789     distance: 5,
790     handle:   '.dragdrop',
791     helper:   function(event, ui) {
792       ui.children().each(function() {
793         $(this).width($(this).width());
794       });
795       return ui;
796     }
797
798   });
799 };
800
801 ns.cancel_edit_additional_parts_form = function() {
802   if (confirm(kivi.t8('Do you really want to cancel?'))) {
803     $('#additional_parts_list_container').show();
804     $('#additional_parts_form_container').remove();
805   }
806   return true;
807 };
808
809 ns.additional_parts_input_key_down = function(event) {
810   if(event.keyCode == 13) {
811     event.preventDefault();
812     ns.standard_additional_parts_ajax_call('save');
813     return false;
814   }
815 };
816
817 ns.add_additional_part = function() {
818   var part_id = $('#additional_parts_add_part_id').val();
819   if (!part_id || (part_id == ''))
820     return false;
821
822   var rspec_id = $('#requirement_spec_id').val();
823   var data     = 'action=RequirementSpecPart/ajax_add&requirement_spec_id=' + encodeURIComponent(rspec_id) + '&part_id=' + encodeURIComponent(part_id);
824
825   $.post("controller.pl", data, kivi.eval_json_result);
826
827   return true;
828 };
829
830 ns.delete_additional_part = function(key, opt) {
831   opt.$trigger.remove();
832   if (!$('#edit_additional_parts_list tbody tr').size()) {
833    $('#edit_additional_parts_list_empty').show();
834    $('#edit_additional_parts_list').hide();
835   }
836
837   return true;
838 };
839
840 // -------------------------------------------------------------------------
841 // ------------------------------- tab widget ------------------------------
842 // -------------------------------------------------------------------------
843 var content_div_ids_for_tab_headers = {
844     'tab-header-function-block':     'function-blocks-tab'
845   , 'tab-header-basic-settings':     'ui-tabs-1'
846   , 'tab-header-time-cost-estimate': 'ui-tabs-2'
847   , 'tab-header-additional-parts':   'ui-tabs-3'
848   , 'tab-header-versions':           'ui-tabs-4'
849   , 'tab-header-quotations-orders':  'ui-tabs-5'
850 };
851
852 ns.tabs_before_activate = function(event, ui) {
853   if (!ui.oldTab)
854     return true;
855
856   var content_div_id = content_div_ids_for_tab_headers[ $(ui.oldTab).attr('id') ];
857   if (!content_div_id || (content_div_id == 'function-blocks-tab'))
858     return true;
859
860   var inputs = $('#' + content_div_id).find('input,select,textarea').filter('[type!=hidden]');
861   if (!inputs.size() || confirm(kivi.t8("If you switch to a different tab without saving you will lose the data you've entered in the current tab.")))
862     return true;
863
864   var new_focus = $(inputs).filter(':focusable')[0];
865   if (new_focus)
866     $(new_focus).focus();
867
868   return false;
869 };
870
871 // -------------------------------------------------------------------------
872 // ----------------------------- context menus -----------------------------
873 // -------------------------------------------------------------------------
874
875 ns.create_context_menus = function(data) {
876   var general_actions;
877   if (data.is_template) {
878     general_actions = {
879         sep98:           "---------"
880       , general_actions: { name: kivi.t8('Requirement spec template actions'), className: 'context-menu-heading' }
881       // , sep99:           "---------"
882       , copy_reqspec:    { name: kivi.t8('Copy template'),   icon: "copy",   callback: kivi.requirement_spec.copy_reqspec   }
883       , delete_reqspec:  { name: kivi.t8('Delete template'), icon: "delete", callback: kivi.requirement_spec.delete_reqspec }
884       , sep_paste_template: "---------"
885       , renumber:        { name: kivi.t8('Renumber sections and function blocks'), icon: "renumber", callback: kivi.requirement_spec.renumber }
886     };
887
888     $.contextMenu({
889       selector: '.basic-settings-context-menu',
890       items:    $.extend({
891           heading: { name: kivi.t8('Basic settings actions'), className: 'context-menu-heading' }
892         , edit:    { name: kivi.t8('Edit'), icon: "edit", callback: kivi.requirement_spec.standard_basic_settings_ajax_call }
893       }, general_actions)
894     });
895
896   } else {                      // if (is_template)
897     general_actions = {
898         sep98:              "---------"
899       , general_actions:    { name: kivi.t8('Requirement spec actions'), className: 'context-menu-heading' }
900       , create_pdf:         { name: kivi.t8('Create PDF'),              icon: "pdf",    callback: kivi.requirement_spec.create_reqspec_pdf }
901       , create_html:        { name: kivi.t8('Create HTML'),             icon: "html",   callback: kivi.requirement_spec.create_reqspec_html }
902       , create_version:     { name: kivi.t8('Create new version'),      icon: "new",    callback: kivi.requirement_spec.create_version, disabled: kivi.requirement_spec.disable_commands }
903       , copy_reqspec:       { name: kivi.t8('Copy requirement spec'),   icon: "copy",   callback: kivi.requirement_spec.copy_reqspec   }
904       , delete_reqspec:     { name: kivi.t8('Delete requirement spec'), icon: "delete", callback: kivi.requirement_spec.delete_reqspec }
905       , sep_renumber:       "---------"
906       , renumber:           { name: kivi.t8('Renumber sections and function blocks'), icon: "renumber", callback: kivi.requirement_spec.renumber }
907       , sep_paste_template: "---------"
908       , paste_template:     { name: kivi.t8('Paste template'),     icon: "paste",  callback: kivi.requirement_spec.paste_template }
909     };
910
911     var versioned_copy_actions = {
912         heading:             { name: kivi.t8('Version actions'), className: 'context-menu-heading' }
913       , create_version_pdf:  { name: kivi.t8('Create PDF'),        icon: "pdf",    callback: kivi.requirement_spec.create_pdf_for_versioned_copy_ajax_call                                                                      }
914       , create_version_html: { name: kivi.t8('Create HTML'),       icon: "html",   callback: kivi.requirement_spec.create_html_for_versioned_copy_ajax_call                                                                     }
915       , revert_to_version:   { name: kivi.t8('Revert to version'), icon: "revert", callback: kivi.requirement_spec.revert_to_versioned_copy_ajax_call,     disabled: kivi.requirement_spec.disable_versioned_copy_item_commands }
916     };
917
918     if (!data.html_template_exists) {
919       delete general_actions.create_html;
920       delete versioned_copy_actions.create_version_html;
921     }
922
923     $.contextMenu({
924       selector: '.versioned-copy-context-menu',
925       items:    $.extend(versioned_copy_actions, general_actions)
926     });
927
928     $.contextMenu({
929       selector: ':has(> .basic-settings-context-menu:visible)',
930       items:    $.extend({
931           heading:           { name: kivi.t8('Basic settings actions'), className: 'context-menu-heading' }
932         , edit:              { name: kivi.t8('Edit'),              icon: "edit", callback: kivi.requirement_spec.standard_basic_settings_ajax_call }
933         , edit_project_link: { name: kivi.t8('Edit project link'),               callback: kivi.requirement_spec.standard_basic_settings_ajax_call }
934       }, general_actions)
935     });
936
937     $.contextMenu({
938       selector: ':has(> .edit-project-link-context-menu:visible)',
939       items:    $.extend({
940           heading: { name: kivi.t8('Project link actions'), className: 'context-menu-heading' }
941         , save:    { name: kivi.t8('Save'),   icon: "save",  callback: kivi.requirement_spec.standard_basic_settings_ajax_call }
942         , cancel:  { name: kivi.t8('Cancel'), icon: "close", callback: kivi.requirement_spec.standard_basic_settings_ajax_call }
943       }, general_actions)
944     });
945
946     var paste_template_actions = {
947     };
948   }                             // if (is_template) ... else ...
949
950   $.contextMenu({
951     selector: '.text-block-context-menu',
952     events:   {
953         show: kivi.requirement_spec.text_block_popup_menu_shown
954       , hide: kivi.requirement_spec.text_block_popup_menu_hidden
955     },
956     items:    $.extend({
957         heading: { name: kivi.t8('Text block actions'),    className: 'context-menu-heading' }
958       , add:     { name: kivi.t8('Add text block'),        icon: "add",    callback: kivi.requirement_spec.standard_text_block_ajax_call }
959       , edit:    { name: kivi.t8('Edit text block'),       icon: "edit",   callback: kivi.requirement_spec.standard_text_block_ajax_call, disabled: kivi.requirement_spec.disable_edit_text_block_commands }
960       , delete:  { name: kivi.t8('Delete text block'),     icon: "delete", callback: kivi.requirement_spec.ask_delete_text_block,         disabled: kivi.requirement_spec.disable_edit_text_block_commands }
961       , add_picture: { name: kivi.t8('Add picture to text block'), icon: "add-picture", callback: kivi.requirement_spec.add_edit_text_block_picture_ajax_call, disabled: kivi.requirement_spec.disable_edit_text_block_commands }
962       , sep1:    "---------"
963       , flag:    { name: kivi.t8('Toggle marker'),         icon: "flag",   callback: kivi.requirement_spec.standard_text_block_ajax_call, disabled: kivi.requirement_spec.disable_edit_text_block_commands }
964       , sep2:    "---------"
965       , copy:    { name: kivi.t8('Copy'),                  icon: "copy",   callback: kivi.requirement_spec.standard_text_block_ajax_call, disabled: kivi.requirement_spec.disable_edit_text_block_commands }
966       , paste:   { name: kivi.t8('Paste'),                 icon: "paste",  callback: kivi.requirement_spec.standard_text_block_ajax_call  }
967     }, general_actions)
968   });
969
970   $.contextMenu({
971     selector: '.text-block-picture-context-menu',
972     events:   {
973         show: kivi.requirement_spec.text_block_picture_popup_menu_shown
974       , hide: kivi.requirement_spec.text_block_picture_popup_menu_hidden
975     },
976     items:    $.extend({
977         heading:          { name: kivi.t8('Text block picture actions'), className: 'context-menu-heading'                                                 }
978       , add_picture:      { name: kivi.t8('Add picture'),      icon: "add-picture", callback: kivi.requirement_spec.add_edit_text_block_picture_ajax_call  }
979       , edit_picture:     { name: kivi.t8('Edit picture'),     icon: "edit",        callback: kivi.requirement_spec.add_edit_text_block_picture_ajax_call  }
980       , delete_picture:   { name: kivi.t8('Delete picture'),   icon: "delete",      callback: kivi.requirement_spec.ask_delete_text_block_picture          }
981       , download_picture: { name: kivi.t8('Download picture'), icon: "download",    callback: kivi.requirement_spec.standard_text_block_picture_ajax_call  }
982       , sep2:             "---------"
983       , copy_picture:     { name: kivi.t8('Copy'),             icon: "copy",        callback: kivi.requirement_spec.standard_text_block_picture_ajax_call  }
984       , paste_picture:    { name: kivi.t8('Paste'),            icon: "paste",       callback: kivi.requirement_spec.standard_text_block_picture_ajax_call  }
985     }, general_actions)
986   });
987
988   $.contextMenu({
989     selector: ':has(> .edit-basic-settings-context-menu:visible)',
990     items:    $.extend({
991         heading: { name: kivi.t8('Basic settings actions'), className: 'context-menu-heading' }
992       , save:    { name: kivi.t8('Save'),   icon: "save",  callback: kivi.requirement_spec.standard_basic_settings_ajax_call }
993       , cancel:  { name: kivi.t8('Cancel'), icon: "close", callback: kivi.requirement_spec.standard_basic_settings_ajax_call }
994     }, general_actions)
995   });
996
997   $.contextMenu({
998     selector: ':has(> div > .time-cost-estimate-context-menu:visible)',
999     items:    $.extend({
1000         heading: { name: kivi.t8('Time/cost estimate actions'), className: 'context-menu-heading' }
1001       , edit:    { name: kivi.t8('Edit'), icon: "edit", callback: kivi.requirement_spec.standard_time_cost_estimate_ajax_call }
1002     }, general_actions)
1003   });
1004
1005   $.contextMenu({
1006     selector: ':has(> .edit-time-cost-estimate-context-menu:visible)',
1007     items:    $.extend({
1008         heading: { name: kivi.t8('Time/cost estimate actions'), className: 'context-menu-heading' }
1009       , save:    { name: kivi.t8('Save'),   icon: "save",  callback: kivi.requirement_spec.standard_time_cost_estimate_ajax_call }
1010       , save_keep_open: { name: kivi.t8('Save and keep open'), icon: "save", callback: kivi.requirement_spec.standard_time_cost_estimate_ajax_call }
1011       , cancel:  { name: kivi.t8('Cancel'), icon: "close", callback: kivi.requirement_spec.standard_time_cost_estimate_ajax_call }
1012     }, general_actions)
1013   });
1014
1015   $.contextMenu({
1016     selector: ':has(> .additional-parts-context-menu:visible)',
1017     items:    $.extend({
1018         heading: { name: kivi.t8('Additional articles actions'), className: 'context-menu-heading' }
1019       , edit:    { name: kivi.t8('Edit'), icon: "edit", callback: kivi.requirement_spec.standard_additional_parts_ajax_call }
1020     }, general_actions)
1021   });
1022
1023   var additional_parts_actions = {
1024       save:           { name: kivi.t8('Save'),               icon: "save",  callback: kivi.requirement_spec.standard_additional_parts_ajax_call }
1025     , save_keep_open: { name: kivi.t8('Save and keep open'), icon: "save",  callback: kivi.requirement_spec.standard_additional_parts_ajax_call }
1026     , cancel:         { name: kivi.t8('Cancel'),             icon: "close",  callback: kivi.requirement_spec.cancel_edit_additional_parts_form }
1027   };
1028
1029   $.contextMenu({
1030     selector: ':has(> .edit-additional-parts-context-menu:visible)',
1031     items:    $.extend({
1032         heading:        { name: kivi.t8('Additional articles actions'), className: 'context-menu-heading' }
1033     }, additional_parts_actions, general_actions)
1034   });
1035
1036   $.contextMenu({
1037     selector: '.edit-additional-parts-row-context-menu',
1038     items:    $.extend({
1039         heading:        { name: kivi.t8('Additional articles actions'), className: 'context-menu-heading' }
1040       , delete:         { name: kivi.t8('Remove article'),     icon: "delete", callback: kivi.requirement_spec.delete_additional_part }
1041     }, additional_parts_actions, general_actions)
1042   });
1043
1044   $.contextMenu({
1045     selector: ':has(> .quotations-and-orders-context-menu:visible),.quotations-and-orders-order-context-menu',
1046     items:    $.extend({
1047         heading:            { name: kivi.t8('Quotations/Orders actions'), className: 'context-menu-heading'                                                                                            }
1048       , edit_assignment:    { name: kivi.t8('Edit article/section assignments'), icon: "edit",   callback: ns.standard_quotation_order_ajax_call                                                       }
1049       , sep1:               "---------"
1050       , new:                { name: kivi.t8('Create new qutoation/order'),       icon: "add",    callback: ns.standard_quotation_order_ajax_call, disabled: ns.disable_create_quotation_order_commands }
1051       , update:             { name: kivi.t8('Update quotation/order'),           icon: "update", callback: ns.standard_quotation_order_ajax_call, disabled: ns.disable_edit_quotation_order_commands   }
1052       , sep2:               "---------"
1053       , delete:             { name: kivi.t8('Delete quotation/order'),           icon: "delete", callback: ns.ask_delete_quotation_order,         disabled: ns.disable_edit_quotation_order_commands   }
1054     }, general_actions)
1055   });
1056
1057   $.contextMenu({
1058     selector: ':has(> .quotations-and-orders-edit-assignment-context-menu:visible)',
1059     items:    $.extend({
1060         heading:         { name: kivi.t8('Edit article/section assignments'), className: 'context-menu-heading'    }
1061       , save_assignment: { name: kivi.t8('Save'),   icon: "edit",  callback: ns.standard_quotation_order_ajax_call }
1062       , cancel:          { name: kivi.t8('Cancel'), icon: "close", callback: ns.standard_quotation_order_ajax_call }
1063     }, general_actions)
1064   });
1065
1066   $.contextMenu({
1067     selector: ':has(> .quotations-and-orders-new-context-menu:visible)',
1068     items:    $.extend({
1069         heading: { name: kivi.t8('Create new quotation/order'), className: 'context-menu-heading'          }
1070       , create:  { name: kivi.t8('Create'), icon: "edit",  callback: ns.standard_quotation_order_ajax_call }
1071       , cancel:  { name: kivi.t8('Cancel'), icon: "close", callback: ns.standard_quotation_order_ajax_call }
1072     }, general_actions)
1073   });
1074
1075   $.contextMenu({
1076     selector: ':has(> .quotations-and-orders-update-context-menu:visible)',
1077     items:    $.extend({
1078         heading:   { name: kivi.t8('Update quotation/order'), className: 'context-menu-heading'               }
1079       , do_update: { name: kivi.t8('Update'), icon: "update", callback: ns.standard_quotation_order_ajax_call }
1080       , cancel:    { name: kivi.t8('Cancel'), icon: "close",  callback: ns.standard_quotation_order_ajax_call }
1081     }, general_actions)
1082   });
1083
1084   $.contextMenu({
1085     selector: '#content',
1086     items:    general_actions
1087   });
1088
1089   var events = {
1090       show: kivi.requirement_spec.item_popup_menu_shown
1091     , hide: kivi.requirement_spec.item_popup_menu_hidden
1092   };
1093
1094   $.contextMenu({
1095     selector: '.section-context-menu',
1096     events:   events,
1097     items:    $.extend({
1098         heading:            { name: kivi.t8('Section/Function block actions'), className: 'context-menu-heading' }
1099       , add_section:        { name: kivi.t8('Add section'),        icon: "add",    callback: kivi.requirement_spec.standard_item_ajax_call }
1100       , add_function_block: { name: kivi.t8('Add function block'), icon: "add",    callback: kivi.requirement_spec.standard_item_ajax_call, disabled: kivi.requirement_spec.disable_add_function_block_command }
1101       , sep1:               "---------"
1102       , edit:               { name: kivi.t8('Edit'),               icon: "edit",   callback: kivi.requirement_spec.standard_item_ajax_call, disabled: kivi.requirement_spec.disable_edit_item_commands }
1103       , delete:             { name: kivi.t8('Delete'),             icon: "delete", callback: kivi.requirement_spec.ask_delete_item,         disabled: kivi.requirement_spec.disable_edit_item_commands }
1104       , sep2:               "---------"
1105       , flag:               { name: kivi.t8('Toggle marker'),      icon: "flag",   callback: kivi.requirement_spec.standard_item_ajax_call, disabled: kivi.requirement_spec.disable_edit_item_commands }
1106       , sep3:               "---------"
1107       , copy:               { name: kivi.t8('Copy'),               icon: "copy",   callback: kivi.requirement_spec.standard_item_ajax_call, disabled: kivi.requirement_spec.disable_edit_item_commands }
1108       , paste:              { name: kivi.t8('Paste'),              icon: "paste",  callback: kivi.requirement_spec.standard_item_ajax_call }
1109     }, general_actions)
1110   });
1111
1112   $.contextMenu({
1113     selector: '.function-block-context-menu,.sub-function-block-context-menu',
1114     events:   events,
1115     items:    $.extend({
1116         heading:                { name: kivi.t8('Function block actions'), className: 'context-menu-heading' }
1117       , add_function_block:     { name: kivi.t8('Add function block'),     icon: "add",    callback: kivi.requirement_spec.standard_item_ajax_call }
1118       , add_sub_function_block: { name: kivi.t8('Add sub function block'), icon: "add",    callback: kivi.requirement_spec.standard_item_ajax_call }
1119       , sep1:                   "---------"
1120       , edit:                   { name: kivi.t8('Edit'),                   icon: "edit",   callback: kivi.requirement_spec.standard_item_ajax_call, disabled: kivi.requirement_spec.disable_edit_item_commands }
1121       , delete:                 { name: kivi.t8('Delete'),                 icon: "delete", callback: kivi.requirement_spec.ask_delete_item,         disabled: kivi.requirement_spec.disable_edit_item_commands }
1122       , sep2:                   "---------"
1123       , flag:                   { name: kivi.t8('Toggle marker'),          icon: "flag",   callback: kivi.requirement_spec.standard_item_ajax_call, disabled: kivi.requirement_spec.disable_edit_item_commands }
1124       , sep3:                   "---------"
1125       , copy:                   { name: kivi.t8('Copy'),                   icon: "copy",   callback: kivi.requirement_spec.standard_item_ajax_call, disabled: kivi.requirement_spec.disable_edit_item_commands }
1126       , paste:                  { name: kivi.t8('Paste'),                  icon: "paste",  callback: kivi.requirement_spec.standard_item_ajax_call }
1127     }, general_actions)
1128   });
1129 };
1130
1131 });                             // end of namespace(...., function() {...
1132
1133 function local_reinit_widgets() {
1134   kivi.run_once_for('#quotations_and_orders_order_id,[name="sections[].order_part_id"]', "assign_order_part_on_part_picked", function(elt) {
1135     $(elt).on('set_item:PartPicker', kivi.requirement_spec.assign_order_part_on_part_picked);
1136   });
1137 }