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