Pflichtenheftitems: Shift+Return = nächster neuer Block auf anderer Ebene
[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 // -------------------------------------------------------------------------
106 // ------------------------------ text blocks ------------------------------
107 // -------------------------------------------------------------------------
108
109 ns.find_text_block_id = function(clicked_elt) {
110   var id = $(clicked_elt).attr('id');
111
112   if (/^text-block-picture-\d+$/.test(id))
113     id = $(clicked_elt).closest('.text-block-context-menu').attr('id');
114
115   // console.log("id: " + id);
116   if (/^text-block-\d+$/.test(id)) {
117     // console.log("find_text_block_id: case 1: " + id.substr(11));
118     return id.substr(11) * 1;
119   }
120
121   id = $(clicked_elt).closest("[id*=text-block-]").attr('id')
122   if (/^text-block-\d+$/.test(id)) {
123     // console.log("find_text_block_id: case 2: " + id.substr(11));
124     return id.substr(11) * 1;
125   }
126
127   id = $(clicked_elt).closest("[id*=tb-]").attr('id')
128   if (/^tb-\d+$/.test(id)) {
129     // console.log("find_text_block_id: case 3: " + id.substr(3));
130     return id.substr(3) * 1;
131   }
132
133   // console.log("find_text_block_id: case undef, id: " + id);
134   return undefined;
135 };
136
137 ns.find_text_block_output_position = function(clicked_elt) {
138   var output_position = $(clicked_elt).closest('#text-block-list-container').find('#text_block_output_position').val();
139   if (output_position)
140     return output_position;
141
142   var type = $(clicked_elt).closest('#tb-back,#tb-front').data('type') || $('#current_content_type').val();
143   if (/^text-blocks-(front|back)/.test(type))
144     return type == "text-blocks-front" ? 0 : 1;
145
146   return undefined;
147 };
148
149 ns.disable_edit_text_block_commands = function(key, opt) {
150   return ns.find_text_block_id(opt.$trigger) == undefined;
151 };
152
153 ns.standard_text_block_ajax_call = function(key, opt, other_data) {
154   var data = {
155     action:               "RequirementSpecTextBlock/ajax_" + key,
156     requirement_spec_id:  $('#requirement_spec_id').val(),
157     id:                   ns.find_text_block_id(opt.$trigger),
158     output_position:      ns.find_text_block_output_position(opt.$trigger),
159     current_content_type: $('#current_content_type').val(),
160     current_content_id:   $('#current_content_id').val()
161   };
162
163   $.post("controller.pl", $.extend(data, other_data || {}), kivi.eval_json_result);
164
165   return true;
166 };
167
168 ns.cancel_edit_text_block_form = function(id_base) {
169   var id = $('#' + id_base + '_id').val();
170   $('#' + id_base + '_form').remove();
171   if (id)
172     $('#text-block-' + id).show();
173 };
174
175 ns.ask_delete_text_block = function(key, opt) {
176   if (confirm(kivi.t8("Are you sure?")))
177     ns.standard_text_block_ajax_call(key, opt);
178   return true;
179 };
180
181 ns.find_text_block_picture_id = function(clicked_elt) {
182   var id    = $(clicked_elt).attr('id');
183   var match = id.match(/^text-block-picture-(\d+)$/);
184   if (match)
185     return match[1] * 1;
186
187   return undefined;
188 };
189
190 ns.add_edit_text_block_picture_ajax_call = function(key, opt) {
191   var title = key == 'add_picture' ? kivi.t8('Add picture to text block') : kivi.t8('Edit picture');
192
193   kivi.popup_dialog({ url:    'controller.pl',
194                       data:   { action:     'RequirementSpecTextBlock/ajax_' + key,
195                                 id:         ns.find_text_block_id(opt.$trigger),
196                                 picture_id: ns.find_text_block_picture_id(opt.$trigger) },
197                       dialog: { title:      title }});
198
199   return true;
200 };
201
202 ns.standard_text_block_picture_ajax_call = function(key, opt) {
203   var data = {
204       action: "RequirementSpecTextBlock/ajax_" + key
205     , id:     ns.find_text_block_picture_id(opt.$trigger)
206   };
207
208   if (key == 'download_picture')
209     $.download("controller.pl", data);
210   else
211     $.post("controller.pl", data, kivi.eval_json_result);
212
213   return true;
214 };
215
216 ns.ask_delete_text_block_picture = function(key, opt) {
217   if (confirm(kivi.t8("Are you sure?")))
218     ns.standard_text_block_picture_ajax_call(key, opt);
219   return true;
220 };
221
222 ns.handle_text_block_picture_popup_menu_markings = function(opt, add) {
223   var id = ns.find_text_block_picture_id(opt.$trigger);
224   if (id)
225     $('#text-block-picture-' + id ).toggleClass('selected', add);
226   return true;
227 };
228
229 ns.text_block_picture_popup_menu_shown = function(opt) {
230   return ns.handle_text_block_picture_popup_menu_markings(opt, true);
231 };
232
233 ns.text_block_picture_popup_menu_hidden = function(opt) {
234   return ns.handle_text_block_picture_popup_menu_markings(opt, false);
235 };
236
237 ns.make_text_block_picture_lists_sortable = function() {
238   kivi.run_once_for(".requirement-spec-text-block-picture-list", 'make-text-block-picture-list-sortable', function($elt) {
239     $elt.sortable({
240       stop: function(event, ui) {
241         $.post('controller.pl?action=RequirementSpecTextBlock/reorder_pictures', {
242           'picture_id[]': $($elt.sortable('toArray')).map(function(idx, str) { return str.replace('text-block-picture-', ''); }).toArray()
243         });
244         return ui;
245       }
246       , distance: 5
247     });
248   });
249 };
250
251 // --------------------------------------------------------------------------------
252 // ------------------------------ sections and items ------------------------------
253 // --------------------------------------------------------------------------------
254
255 ns.find_item_id = function(clicked_elt) {
256   // console.log("clicked id: " + $(clicked_elt).attr('id'));
257   var id     = $(clicked_elt).attr('id');
258   var result = /^(function-block|function-block-content|sub-function-block|sub-function-block-content|section|section-header)-(\d+)$/.exec(id);
259   if (result) {
260     // console.log("find_item_id: case 1: " + result[2]);
261     return result[2];
262   }
263
264   id = $(clicked_elt).closest("[id*=fb-]").attr('id')
265   if (/^fb-\d+$/.test(id)) {
266     // console.log("find_item_id: case 2: " + id.substr(3));
267     return id.substr(3) * 1;
268   }
269
270   // console.log("find_item_id: case undef");
271   return undefined;
272 };
273
274 ns.standard_item_ajax_call = function(key, opt, other_data) {
275   var data = {
276     action:               "RequirementSpecItem/ajax_" + key,
277     requirement_spec_id:  $('#requirement_spec_id').val(),
278     id:                   ns.find_item_id(opt.$trigger),
279     current_content_type: $('#current_content_type').val(),
280     current_content_id:   $('#current_content_id').val()
281   };
282
283   // console.log("I would normally POST the following now:");
284   // console.log(data);
285   $.post("controller.pl", $.extend(data, other_data || {}), kivi.eval_json_result);
286
287   return true;
288 };
289
290 ns.disable_edit_item_commands = function(key, opt) {
291   return ns.find_item_id(opt.$trigger) == undefined;
292 };
293
294 ns.disable_add_function_block_command = function(key, opt) {
295   return opt.$trigger.attr('id') == "sections";
296 };
297
298 ns.cancel_edit_item_form = function(form_id_base, options) {
299   $('#' + form_id_base + '_form').remove();
300   if (!options)
301     return;
302   if (options.to_show)
303     $(options.to_show).show();
304   if (options.to_hide_if_empty && (1 == $(options.to_hide_if_empty).children().size()))
305     $(options.to_hide_if_empty).hide();
306 };
307
308 ns.ask_delete_item = function(key, opt) {
309   if (confirm(kivi.t8("Are you sure?")))
310     ns.standard_item_ajax_call(key, opt);
311   return true;
312 };
313
314 ns.handle_text_block_popup_menu_markings = function(opt, add) {
315   var id = ns.find_text_block_id(opt.$trigger);
316   if (id)
317     $('#text-block-' + id).toggleClass('selected', add);
318   return true;
319 };
320
321 ns.text_block_popup_menu_shown = function(opt) {
322   return ns.handle_text_block_popup_menu_markings(opt, true);
323 };
324
325 ns.text_block_popup_menu_hidden = function(opt) {
326   return ns.handle_text_block_popup_menu_markings(opt, false);
327 };
328
329 ns.handle_item_popup_menu_markings = function(opt, add) {
330   var id = ns.find_item_id(opt.$trigger);
331   if (id)
332     $('#section-' + id + ',#function-block-' + id + ',#sub-function-block-' + id).toggleClass('selected', add);
333   return true;
334 };
335
336 ns.item_popup_menu_shown = function(opt) {
337   return ns.handle_item_popup_menu_markings(opt, true);
338 };
339
340 ns.item_popup_menu_hidden = function(opt) {
341   return ns.handle_item_popup_menu_markings(opt, false);
342 };
343
344 ns.submit_function_block = function(event, shift_in_out) {
345   event.preventDefault();
346
347   var prefix = $(this).attr('id').match("^(?:edit|new)_function_block_[\\d_]+\\d")[0];
348   var action = $('#' + prefix + '_id').val() ? 'update' : 'create';
349   kivi.submit_ajax_form('controller.pl?action=RequirementSpecItem/ajax_' + action, '#' + prefix + '_form', { shift_in_out: !!shift_in_out });
350
351   return false;
352 };
353
354 ns.init_function_block_keypress_events = function(form_id) {
355   $("#" + form_id + " INPUT[type=text]").bind("keypress", "return", ns.submit_function_block);
356
357   $('#' + form_id + ' INPUT[type=text],#' + form_id + ' TEXTAREA,#' + form_id + ' INPUT[type=button]')
358     .bind('keypress', 'shift+return', function(event) { return ns.submit_function_block.apply(this, [ event, true ]); });
359 };
360
361 // -------------------------------------------------------------------------
362 // ------------------------------- templates -------------------------------
363 // -------------------------------------------------------------------------
364
365 ns.paste_template = function(key, opt, other_data) {
366   kivi.popup_dialog({ url: 'controller.pl?action=RequirementSpec/select_template_to_paste', dialog: { title: kivi.t8("Select template to paste") } });
367 };
368
369 ns.paste_selected_template = function(template_id) {
370   $('#jqueryui_popup_dialog').dialog("close");
371
372   var data = {
373     action:               "RequirementSpec/paste_template",
374     id:                   $('#requirement_spec_id').val(),
375     template_id:          template_id,
376     current_content_type: $('#current_content_type').val(),
377     current_content_id:   $('#current_content_id').val()
378   };
379
380   // console.log("I would normally POST the following now:");
381   // console.log(data);
382   $.post("controller.pl", data, kivi.eval_json_result);
383
384   return true;
385 };
386
387 // -------------------------------------------------------------------------
388 // ---------------------------- basic settings -----------------------------
389 // -------------------------------------------------------------------------
390 ns.standard_basic_settings_ajax_call = function(key, opt) {
391   if (key == 'cancel') {
392     if (confirm(kivi.t8('Do you really want to cancel?'))) {
393       $('#basic_settings').show();
394       $('#basic_settings_form').remove();
395     }
396     return true;
397   }
398
399   var data = 'action=RequirementSpec/ajax_' + key + '&id=' + encodeURIComponent($('#requirement_spec_id').val());
400
401   $.post("controller.pl", data, kivi.eval_json_result);
402
403   return true;
404 };
405
406 // -------------------------------------------------------------------------
407 // -------------------------- time/cost estimate ---------------------------
408 // -------------------------------------------------------------------------
409
410 ns.standard_time_cost_estimate_ajax_call = function(key, opt) {
411   if (key == 'cancel') {
412     if (confirm(kivi.t8('Do you really want to cancel?'))) {
413       $('#time_cost_estimate').show();
414       $('#time_cost_estimate_form_container').remove();
415     }
416     return true;
417   }
418
419   var data = "action=RequirementSpec/ajax_" + key + "_time_and_cost_estimate&";
420
421   if (key == 'save')
422     data += $('#edit_time_cost_estimate_form').serialize()
423          +  '&' + $('#current_content_type').serialize()
424          +  '&' + $('#current_content_id').serialize();
425   else
426     data += 'id=' + encodeURIComponent($('#requirement_spec_id').val());
427
428   $.post("controller.pl", data, kivi.eval_json_result);
429
430   return true;
431 };
432
433 ns.time_cost_estimate_input_key_down = function(event) {
434   if(event.keyCode == 13) {
435     event.preventDefault();
436     ns.standard_time_cost_estimate_ajax_call('save');
437     return false;
438   }
439 };
440
441 // -------------------------------------------------------------------------
442 // --------------------------- quotations/orders ---------------------------
443 // -------------------------------------------------------------------------
444
445 ns.find_quotation_order_id = function(clicked_elt) {
446   return $(clicked_elt).find('>[name=order_id]').val();
447 };
448
449 ns.standard_quotation_order_ajax_call = function(key, opt) {
450   if (key == 'cancel') {
451     if (confirm(kivi.t8('Do you really want to cancel?'))) {
452       $('#quotations_and_orders').show();
453       $('#quotations_and_orders_article_assignment,#quotations_and_orders_new,#quotations_and_orders_update').remove();
454     }
455     return true;
456   }
457
458   else if ((key == 'create') && $('#quotations_and_orders_form INPUT[name="sections[].order_part_id"]').filter(function(idx, elt) { return ($(elt).val() || '') == '' }).size()) {
459     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.'));
460     return false;
461   }
462
463   var data = 'action=RequirementSpecOrder/' + key
464            + '&' + $('#requirement_spec_id').serialize();
465
466   if ((key == 'save_assignment') || (key == 'create') || (key == 'do_update'))
467     data += '&' + $('#quotations_and_orders_form').serialize();
468   else if ((key == 'update') || (key == 'delete'))
469     data += '&rs_order_id=' + encodeURIComponent(ns.find_quotation_order_id(opt.$trigger));
470
471   // console.log("I would normally POST the following now:");
472   // console.log(data);
473   $.post("controller.pl", data, kivi.eval_json_result);
474
475   return true;
476 };
477
478 ns.ask_delete_quotation_order = function(key, opt) {
479   if (confirm(kivi.t8("Are you sure?")))
480     ns.standard_quotation_order_ajax_call(key, opt);
481   return true;
482 };
483
484 ns.disable_edit_quotation_order_commands = function(key, opt) {
485   return ns.find_quotation_order_id(opt.$trigger) == undefined;
486 };
487
488 ns.disable_create_quotation_order_commands = function(key, opt) {
489   return !$('#quotations_and_orders_sections');
490 };
491
492 ns.assign_order_part_id_to_all = function() {
493   var order_part_id   = $('#quotations_and_orders_order_id').val();
494   var order_part_name = $('#quotations_and_orders_order_id_name').val();
495
496   $('#quotations_and_orders_form INPUT[name="sections[].order_part_id"]').each(function(idx, elt) {
497     $(elt).val(order_part_id);
498   });
499
500   $('#quotations_and_orders_form [id^=quotations_and_orders_sections_order_pard_id_]').filter(function() {
501     return $(this).attr('id') && $(this).attr('id').match("^quotations_and_orders_sections_order_pard_id_[0-9]+_name$");
502   }).each(function(idx, elt) {
503     $(elt).val(order_part_name);
504   });
505 };
506
507 // -------------------------------------------------------------------------
508 // ---------------------------- general actions ----------------------------
509 // -------------------------------------------------------------------------
510
511 ns.create_reqspec_pdf = function(key, opt) {
512   var data = {
513     action: "RequirementSpec/create_pdf",
514     id:     $('#requirement_spec_id').val()
515   };
516   $.download("controller.pl", data);
517 };
518
519 ns.copy_reqspec = function(key, opt) {
520   window.location.href = "controller.pl?action=RequirementSpec/new&copy_source_id=" + encodeURIComponent($('#requirement_spec_id').val());
521   return true;
522 };
523
524 ns.delete_reqspec = function(key, opt) {
525   if (confirm(kivi.t8("Are you sure?")))
526     window.location.href = "controller.pl?action=RequirementSpec/destroy&id=" + encodeURIComponent($('#requirement_spec_id').val());
527   return true;
528 };
529
530 ns.disable_commands = function(key, opt) {
531   if (key === "create_version")
532     return ($('#current_version_id').val() || '') == '' ? false : true;
533   return false;
534 };
535
536 // -------------------------------------------------------------------------
537 // -------------------------------- versions -------------------------------
538 // -------------------------------------------------------------------------
539
540 ns.find_versioned_copy_id = function(clicked_elt) {
541   var id = $(clicked_elt).find("[name=versioned_copy_id]");
542   return id ? id.val() : undefined;
543 };
544
545 ns.disable_versioned_copy_item_commands = function(key, opt) {
546   if (key === "revert_to_version")
547     return !ns.find_versioned_copy_id(opt.$trigger);
548   return false;
549 };
550
551 ns.create_version = function() {
552   kivi.popup_dialog({ url:    'controller.pl',
553                       data:   { action:              'RequirementSpecVersion/new',
554                                 requirement_spec_id: $('#requirement_spec_id').val() },
555                       dialog: { title: kivi.t8('Create a new version') }});
556   return true;
557 };
558
559 ns.create_pdf_for_versioned_copy_ajax_call = function(key, opt) {
560   var data = {
561     action: "RequirementSpec/create_pdf",
562     id:     ns.find_versioned_copy_id(opt.$trigger)
563   };
564   $.download("controller.pl", data);
565
566   return true;
567 };
568
569 ns.revert_to_versioned_copy_ajax_call = function(key, opt) {
570   if (!confirm(kivi.t8('Do you really want to revert to this version?')))
571     return true;
572
573   var data = {
574     action:            'RequirementSpec/revert_to',
575     versioned_copy_id: ns.find_versioned_copy_id(opt.$trigger),
576     id:                $('#requirement_spec_id').val()
577   };
578
579   $.post("controller.pl", data, kivi.eval_json_result);
580
581   return true;
582 };
583
584 // -------------------------------------------------------------------------
585 // ------------------------------- tab widget ------------------------------
586 // -------------------------------------------------------------------------
587 var content_div_ids_for_tab_headers = {
588     'tab-header-function-block':     'function-blocks-tab'
589   , 'tab-header-basic-settings':     'ui-tabs-1'
590   , 'tab-header-time-cost-estimate': 'ui-tabs-2'
591   , 'tab-header-versions':           'ui-tabs-3'
592   , 'tab-header-quotations-orders':  'ui-tabs-4'
593 };
594
595 ns.tabs_before_activate = function(event, ui) {
596   if (!ui.oldTab)
597     return true;
598
599   var content_div_id = content_div_ids_for_tab_headers[ $(ui.oldTab).attr('id') ];
600   if (!content_div_id || (content_div_id == 'function-blocks-tab'))
601     return true;
602
603   var inputs = $('#' + content_div_id).find('input,select,textarea').filter('[type!=hidden]');
604   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.")))
605     return true;
606
607   var new_focus = $(inputs).filter(':focusable')[0];
608   if (new_focus)
609     $(new_focus).focus();
610
611   return false;
612 };
613
614 // -------------------------------------------------------------------------
615 // ----------------------------- context menus -----------------------------
616 // -------------------------------------------------------------------------
617
618 ns.create_context_menus = function(is_template) {
619   if (is_template) {
620     var general_actions = {
621         sep98:           "---------"
622       , general_actions: { name: kivi.t8('Requirement spec template actions'), className: 'context-menu-heading' }
623       // , sep99:           "---------"
624       , copy_reqspec:    { name: kivi.t8('Copy template'),   icon: "copy",   callback: kivi.requirement_spec.copy_reqspec   }
625       , delete_reqspec:  { name: kivi.t8('Delete template'), icon: "delete", callback: kivi.requirement_spec.delete_reqspec }
626     };
627
628   } else {                      // if (is_template)
629     var general_actions = {
630         sep98:              "---------"
631       , general_actions:    { name: kivi.t8('Requirement spec actions'), className: 'context-menu-heading' }
632       , create_pdf:         { name: kivi.t8('Create PDF'),              icon: "pdf",    callback: kivi.requirement_spec.create_reqspec_pdf }
633       , create_version:     { name: kivi.t8('Create new version'),      icon: "new",    callback: kivi.requirement_spec.create_version, disabled: kivi.requirement_spec.disable_commands }
634       , copy_reqspec:       { name: kivi.t8('Copy requirement spec'),   icon: "copy",   callback: kivi.requirement_spec.copy_reqspec   }
635       , delete_reqspec:     { name: kivi.t8('Delete requirement spec'), icon: "delete", callback: kivi.requirement_spec.delete_reqspec }
636       , sep_paste_template: "---------"
637       , paste_template:     { name: kivi.t8('Paste template'),     icon: "paste",  callback: kivi.requirement_spec.paste_template }
638     };
639
640     $.contextMenu({
641       selector: '.versioned-copy-context-menu',
642       items:    $.extend({
643           heading:            { name: kivi.t8('Version actions'), className: 'context-menu-heading' }
644         , create_version_pdf: { name: kivi.t8('Create PDF'),        icon: "pdf",    callback: kivi.requirement_spec.create_pdf_for_versioned_copy_ajax_call                                                                      }
645         , 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 }
646       }, general_actions)
647     });
648
649     var paste_template_actions = {
650     };
651   }                             // if (is_template) ... else ...
652
653   $.contextMenu({
654     selector: '.text-block-context-menu',
655     events:   {
656         show: kivi.requirement_spec.text_block_popup_menu_shown
657       , hide: kivi.requirement_spec.text_block_popup_menu_hidden
658     },
659     items:    $.extend({
660         heading: { name: kivi.t8('Text block actions'),    className: 'context-menu-heading' }
661       , add:     { name: kivi.t8('Add text block'),        icon: "add",    callback: kivi.requirement_spec.standard_text_block_ajax_call }
662       , 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 }
663       , 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 }
664       , 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 }
665       , sep1:    "---------"
666       , 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 }
667       , sep2:    "---------"
668       , 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 }
669       , paste:   { name: kivi.t8('Paste'),                 icon: "paste",  callback: kivi.requirement_spec.standard_text_block_ajax_call  }
670     }, general_actions)
671   });
672
673   $.contextMenu({
674     selector: '.text-block-picture-context-menu',
675     events:   {
676         show: kivi.requirement_spec.text_block_picture_popup_menu_shown
677       , hide: kivi.requirement_spec.text_block_picture_popup_menu_hidden
678     },
679     items:    $.extend({
680         heading:          { name: kivi.t8('Text block picture actions'), className: 'context-menu-heading'                                                 }
681       , add_picture:      { name: kivi.t8('Add picture'),      icon: "add-picture", callback: kivi.requirement_spec.add_edit_text_block_picture_ajax_call  }
682       , edit_picture:     { name: kivi.t8('Edit picture'),     icon: "edit",        callback: kivi.requirement_spec.add_edit_text_block_picture_ajax_call  }
683       , delete_picture:   { name: kivi.t8('Delete picture'),   icon: "delete",      callback: kivi.requirement_spec.ask_delete_text_block_picture          }
684       , download_picture: { name: kivi.t8('Download picture'), icon: "download",    callback: kivi.requirement_spec.standard_text_block_picture_ajax_call  }
685       , sep2:             "---------"
686       , copy_picture:     { name: kivi.t8('Copy'),             icon: "copy",        callback: kivi.requirement_spec.standard_text_block_picture_ajax_call  }
687       , paste_picture:    { name: kivi.t8('Paste'),            icon: "paste",       callback: kivi.requirement_spec.standard_text_block_picture_ajax_call  }
688     }, general_actions)
689   });
690
691   $.contextMenu({
692     selector: '.basic-settings-context-menu',
693     items:    $.extend({
694         heading: { name: kivi.t8('Basic settings actions'), className: 'context-menu-heading' }
695       , edit:    { name: kivi.t8('Edit'), icon: "edit", callback: kivi.requirement_spec.standard_basic_settings_ajax_call }
696     }, general_actions)
697   });
698
699   $.contextMenu({
700     selector: '.edit-basic-settings-context-menu',
701     items:    $.extend({
702         heading: { name: kivi.t8('Basic settings actions'), className: 'context-menu-heading' }
703       , save:    { name: kivi.t8('Save'),   icon: "save",  callback: kivi.requirement_spec.standard_basic_settings_ajax_call }
704       , cancel:  { name: kivi.t8('Cancel'), icon: "close", callback: kivi.requirement_spec.standard_basic_settings_ajax_call }
705     }, general_actions)
706   });
707
708   $.contextMenu({
709     selector: '.time-cost-estimate-context-menu',
710     items:    $.extend({
711         heading: { name: kivi.t8('Time/cost estimate actions'), className: 'context-menu-heading' }
712       , edit:    { name: kivi.t8('Edit'), icon: "edit", callback: kivi.requirement_spec.standard_time_cost_estimate_ajax_call }
713     }, general_actions)
714   });
715
716   $.contextMenu({
717     selector: '.edit-time-cost-estimate-context-menu',
718     items:    $.extend({
719         heading: { name: kivi.t8('Time/cost estimate actions'), className: 'context-menu-heading' }
720       , save:    { name: kivi.t8('Save'),   icon: "save",  callback: kivi.requirement_spec.standard_time_cost_estimate_ajax_call }
721       , cancel:  { name: kivi.t8('Cancel'), icon: "close", callback: kivi.requirement_spec.standard_time_cost_estimate_ajax_call }
722     }, general_actions)
723   });
724
725   $.contextMenu({
726     selector: '.quotations-and-orders-context-menu,.quotations-and-orders-order-context-menu',
727     items:    $.extend({
728         heading:            { name: kivi.t8('Quotations/Orders actions'), className: 'context-menu-heading'                                                                                            }
729       , edit_assignment:    { name: kivi.t8('Edit article/section assignments'), icon: "edit",   callback: ns.standard_quotation_order_ajax_call                                                       }
730       , sep1:               "---------"
731       , new:                { name: kivi.t8('Create new qutoation/order'),       icon: "add",    callback: ns.standard_quotation_order_ajax_call, disabled: ns.disable_create_quotation_order_commands }
732       , update:             { name: kivi.t8('Update quotation/order'),           icon: "update", callback: ns.standard_quotation_order_ajax_call, disabled: ns.disable_edit_quotation_order_commands   }
733       , sep2:               "---------"
734       , delete:             { name: kivi.t8('Delete quotation/order'),           icon: "delete", callback: ns.ask_delete_quotation_order,         disabled: ns.disable_edit_quotation_order_commands   }
735     }, general_actions)
736   });
737
738   $.contextMenu({
739     selector: '.quotations-and-orders-edit-assignment-context-menu',
740     items:    $.extend({
741         heading:         { name: kivi.t8('Edit article/section assignments'), className: 'context-menu-heading'    }
742       , save_assignment: { name: kivi.t8('Save'),   icon: "edit",  callback: ns.standard_quotation_order_ajax_call }
743       , cancel:          { name: kivi.t8('Cancel'), icon: "close", callback: ns.standard_quotation_order_ajax_call }
744     }, general_actions)
745   });
746
747   $.contextMenu({
748     selector: '.quotations-and-orders-new-context-menu',
749     items:    $.extend({
750         heading: { name: kivi.t8('Create new quotation/order'), className: 'context-menu-heading'          }
751       , create:  { name: kivi.t8('Create'), icon: "edit",  callback: ns.standard_quotation_order_ajax_call }
752       , cancel:  { name: kivi.t8('Cancel'), icon: "close", callback: ns.standard_quotation_order_ajax_call }
753     }, general_actions)
754   });
755
756   $.contextMenu({
757     selector: '.quotations-and-orders-update-context-menu',
758     items:    $.extend({
759         heading:   { name: kivi.t8('Update quotation/order'), className: 'context-menu-heading'               }
760       , do_update: { name: kivi.t8('Update'), icon: "update", callback: ns.standard_quotation_order_ajax_call }
761       , cancel:    { name: kivi.t8('Cancel'), icon: "close",  callback: ns.standard_quotation_order_ajax_call }
762     }, general_actions)
763   });
764
765   $.contextMenu({
766     selector: '#content',
767     items:    general_actions
768   });
769
770   var events = {
771       show: kivi.requirement_spec.item_popup_menu_shown
772     , hide: kivi.requirement_spec.item_popup_menu_hidden
773   };
774
775   $.contextMenu({
776     selector: '.section-context-menu',
777     events:   events,
778     items:    $.extend({
779         heading:            { name: kivi.t8('Section/Function block actions'), className: 'context-menu-heading' }
780       , add_section:        { name: kivi.t8('Add section'),        icon: "add",    callback: kivi.requirement_spec.standard_item_ajax_call }
781       , 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 }
782       , sep1:               "---------"
783       , edit:               { name: kivi.t8('Edit'),               icon: "edit",   callback: kivi.requirement_spec.standard_item_ajax_call, disabled: kivi.requirement_spec.disable_edit_item_commands }
784       , delete:             { name: kivi.t8('Delete'),             icon: "delete", callback: kivi.requirement_spec.ask_delete_item,         disabled: kivi.requirement_spec.disable_edit_item_commands }
785       , sep2:               "---------"
786       , flag:               { name: kivi.t8('Toggle marker'),      icon: "flag",   callback: kivi.requirement_spec.standard_item_ajax_call, disabled: kivi.requirement_spec.disable_edit_item_commands }
787       , sep3:               "---------"
788       , copy:               { name: kivi.t8('Copy'),               icon: "copy",   callback: kivi.requirement_spec.standard_item_ajax_call, disabled: kivi.requirement_spec.disable_edit_item_commands }
789       , paste:              { name: kivi.t8('Paste'),              icon: "paste",  callback: kivi.requirement_spec.standard_item_ajax_call }
790     }, general_actions)
791   });
792
793   $.contextMenu({
794     selector: '.function-block-context-menu,.sub-function-block-context-menu',
795     events:   events,
796     items:    $.extend({
797         heading:                { name: kivi.t8('Function block actions'), className: 'context-menu-heading' }
798       , add_function_block:     { name: kivi.t8('Add function block'),     icon: "add",    callback: kivi.requirement_spec.standard_item_ajax_call }
799       , add_sub_function_block: { name: kivi.t8('Add sub function block'), icon: "add",    callback: kivi.requirement_spec.standard_item_ajax_call }
800       , sep1:                   "---------"
801       , edit:                   { name: kivi.t8('Edit'),                   icon: "edit",   callback: kivi.requirement_spec.standard_item_ajax_call, disabled: kivi.requirement_spec.disable_edit_item_commands }
802       , delete:                 { name: kivi.t8('Delete'),                 icon: "delete", callback: kivi.requirement_spec.ask_delete_item,         disabled: kivi.requirement_spec.disable_edit_item_commands }
803       , sep2:                   "---------"
804       , flag:                   { name: kivi.t8('Toggle marker'),          icon: "flag",   callback: kivi.requirement_spec.standard_item_ajax_call, disabled: kivi.requirement_spec.disable_edit_item_commands }
805       , sep3:                   "---------"
806       , copy:                   { name: kivi.t8('Copy'),                   icon: "copy",   callback: kivi.requirement_spec.standard_item_ajax_call, disabled: kivi.requirement_spec.disable_edit_item_commands }
807       , paste:                  { name: kivi.t8('Paste'),                  icon: "paste",  callback: kivi.requirement_spec.standard_item_ajax_call }
808     }, general_actions)
809   });
810 };
811
812 });                             // end of namespace(...., function() {...