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