+};
+
+ns.cancel_edit_additional_parts_form = function() {
+ if (confirm(kivi.t8('Do you really want to cancel?'))) {
+ $('#additional_parts_list_container').show();
+ $('#additional_parts_form_container').remove();
+ }
+ return true;
+};
+
+ns.additional_parts_input_key_down = function(event) {
+ if(event.keyCode == 13) {
+ event.preventDefault();
+ ns.standard_additional_parts_ajax_call('save');
+ return false;
+ }
+};
+
+ns.add_additional_part = function() {
+ var part_id = $('#additional_parts_add_part_id').val();
+ if (!part_id || (part_id == ''))
+ return false;
+
+ var rspec_id = $('#requirement_spec_id').val();
+ var data = 'action=RequirementSpecPart/ajax_add&requirement_spec_id=' + encodeURIComponent(rspec_id) + '&part_id=' + encodeURIComponent(part_id);
+
+ $.post("controller.pl", data, kivi.eval_json_result);
+
+ return true;
+};
+
+ns.delete_additional_part = function(key, opt) {
+ opt.$trigger.remove();
+ if (!$('#edit_additional_parts_list tbody tr').size()) {
+ $('#edit_additional_parts_list_empty').show();
+ $('#edit_additional_parts_list').hide();
+ }
+
+ return true;
+};
+
+// -------------------------------------------------------------------------
+// ------------------------------- tab widget ------------------------------
+// -------------------------------------------------------------------------
+var content_div_ids_for_tab_headers = {
+ 'tab-header-function-block': 'function-blocks-tab'
+ , 'tab-header-basic-settings': 'ui-tabs-1'
+ , 'tab-header-time-cost-estimate': 'ui-tabs-2'
+ , 'tab-header-additional-parts': 'ui-tabs-3'
+ , 'tab-header-versions': 'ui-tabs-4'
+ , 'tab-header-quotations-orders': 'ui-tabs-5'
+};
+
+ns.tabs_before_activate = function(event, ui) {
+ if (!ui.oldTab)
+ return true;
+
+ var content_div_id = content_div_ids_for_tab_headers[ $(ui.oldTab).attr('id') ];
+ if (!content_div_id || (content_div_id == 'function-blocks-tab'))
+ return true;
+
+ var inputs = $('#' + content_div_id).find('input,select,textarea').filter('[type!=hidden]');
+ 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.")))
+ return true;
+
+ var new_focus = $(inputs).filter(':focusable')[0];
+ if (new_focus)
+ $(new_focus).focus();
+
+ return false;
+};
+
+// -------------------------------------------------------------------------
+// ----------------------------- context menus -----------------------------
+// -------------------------------------------------------------------------
+
+ns.create_context_menus = function(data) {
+ var general_actions;
+ if (data.is_template) {
+ general_actions = {
+ sep98: "---------"
+ , general_actions: { name: kivi.t8('Requirement spec template actions'), className: 'context-menu-heading' }
+ // , sep99: "---------"
+ , copy_reqspec: { name: kivi.t8('Copy template'), icon: "copy", callback: kivi.requirement_spec.copy_reqspec }
+ , delete_reqspec: { name: kivi.t8('Delete template'), icon: "delete", callback: kivi.requirement_spec.delete_reqspec }
+ , sep_paste_template: "---------"
+ , renumber: { name: kivi.t8('Renumber sections and function blocks'), icon: "renumber", callback: kivi.requirement_spec.renumber }
+ };
+
+ $.contextMenu({
+ selector: '.basic-settings-context-menu',
+ items: $.extend({
+ heading: { name: kivi.t8('Basic settings actions'), className: 'context-menu-heading' }
+ , edit: { name: kivi.t8('Edit'), icon: "edit", callback: kivi.requirement_spec.standard_basic_settings_ajax_call }
+ }, general_actions)
+ });
+
+ } else { // if (is_template)
+ general_actions = {
+ sep98: "---------"
+ , general_actions: { name: kivi.t8('Requirement spec actions'), className: 'context-menu-heading' }
+ , create_pdf: { name: kivi.t8('Create PDF'), icon: "pdf", callback: kivi.requirement_spec.create_reqspec_pdf }
+ , create_html: { name: kivi.t8('Create HTML'), icon: "html", callback: kivi.requirement_spec.create_reqspec_html }
+ , create_version: { name: kivi.t8('Create new version'), icon: "new", callback: kivi.requirement_spec.create_version, disabled: kivi.requirement_spec.disable_commands }
+ , copy_reqspec: { name: kivi.t8('Copy requirement spec'), icon: "copy", callback: kivi.requirement_spec.copy_reqspec }
+ , delete_reqspec: { name: kivi.t8('Delete requirement spec'), icon: "delete", callback: kivi.requirement_spec.delete_reqspec }
+ , sep_renumber: "---------"
+ , renumber: { name: kivi.t8('Renumber sections and function blocks'), icon: "renumber", callback: kivi.requirement_spec.renumber }
+ , sep_paste_template: "---------"
+ , paste_template: { name: kivi.t8('Paste template'), icon: "paste", callback: kivi.requirement_spec.paste_template }
+ };
+
+ var versioned_copy_actions = {
+ heading: { name: kivi.t8('Version actions'), className: 'context-menu-heading' }
+ , create_version_pdf: { name: kivi.t8('Create PDF'), icon: "pdf", callback: kivi.requirement_spec.create_pdf_for_versioned_copy_ajax_call }
+ , create_version_html: { name: kivi.t8('Create HTML'), icon: "html", callback: kivi.requirement_spec.create_html_for_versioned_copy_ajax_call }
+ , 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 }
+ };
+
+ if (!data.html_template_exists) {
+ delete general_actions.create_html;
+ delete versioned_copy_actions.create_version_html;
+ }
+
+ $.contextMenu({
+ selector: '.versioned-copy-context-menu',
+ items: $.extend(versioned_copy_actions, general_actions)
+ });
+
+ $.contextMenu({
+ selector: ':has(> .basic-settings-context-menu:visible)',
+ items: $.extend({
+ heading: { name: kivi.t8('Basic settings actions'), className: 'context-menu-heading' }
+ , edit: { name: kivi.t8('Edit'), icon: "edit", callback: kivi.requirement_spec.standard_basic_settings_ajax_call }
+ , edit_project_link: { name: kivi.t8('Edit project link'), callback: kivi.requirement_spec.standard_basic_settings_ajax_call }
+ }, general_actions)
+ });
+
+ $.contextMenu({
+ selector: ':has(> .edit-project-link-context-menu:visible)',
+ items: $.extend({
+ heading: { name: kivi.t8('Project link actions'), className: 'context-menu-heading' }
+ , save: { name: kivi.t8('Save'), icon: "save", callback: kivi.requirement_spec.standard_basic_settings_ajax_call }
+ , cancel: { name: kivi.t8('Cancel'), icon: "close", callback: kivi.requirement_spec.standard_basic_settings_ajax_call }
+ }, general_actions)
+ });
+
+ var paste_template_actions = {
+ };
+ } // if (is_template) ... else ...