+};
+
+ns.ask_delete_item = function(key, opt) {
+ if (confirm(kivi.t8("Are you sure?")))
+ ns.standard_item_ajax_call(key, opt);
+ return true;
+};
+
+ns.handle_text_block_popup_menu_markings = function(opt, add) {
+ var id = ns.find_text_block_id(opt.$trigger);
+ if (id)
+ $('#text-block-' + id).toggleClass('selected', add);
+ return true;
+};
+
+ns.text_block_popup_menu_shown = function(opt) {
+ return ns.handle_text_block_popup_menu_markings(opt, true);
+};
+
+ns.text_block_popup_menu_hidden = function(opt) {
+ return ns.handle_text_block_popup_menu_markings(opt, false);
+};
+
+ns.handle_item_popup_menu_markings = function(opt, add) {
+ var id = ns.find_item_id(opt.$trigger);
+ if (id)
+ $('#section-' + id + ',#function-block-' + id + ',#sub-function-block-' + id).toggleClass('selected', add);
+ return true;
+};
+
+ns.item_popup_menu_shown = function(opt) {
+ return ns.handle_item_popup_menu_markings(opt, true);
+};
+
+ns.item_popup_menu_hidden = function(opt) {
+ return ns.handle_item_popup_menu_markings(opt, false);
+};
+
+ns.submit_function_block = function(event, shift_in_out) {
+ event.preventDefault();
+
+ var prefix = $(this).attr('id').match("^(?:edit|new)_function_block_[\\d_]+\\d")[0];
+ var action = $('#' + prefix + '_id').val() ? 'update' : 'create';
+ kivi.submit_ajax_form('controller.pl?action=RequirementSpecItem/ajax_' + action, '#' + prefix + '_form', { shift_in_out: !!shift_in_out });
+
+ return false;
+};
+
+ns.init_function_block_keypress_events = function(form_id) {
+ $("#" + form_id + " INPUT[type=text]").bind("keypress", "return", ns.submit_function_block);
+
+ $('#' + form_id + ' INPUT[type=text],#' + form_id + ' TEXTAREA,#' + form_id + ' INPUT[type=button]')
+ .bind('keypress', 'shift+return', function(event) { return ns.submit_function_block.apply(this, [ event, true ]); });
+};
+
+// -------------------------------------------------------------------------
+// ------------------------------- templates -------------------------------
+// -------------------------------------------------------------------------
+
+ns.paste_template = function(key, opt, other_data) {
+ kivi.popup_dialog({ url: 'controller.pl?action=RequirementSpec/select_template_to_paste', dialog: { title: kivi.t8("Select template to paste") } });
+};
+
+ns.paste_selected_template = function(template_id) {
+ $('#jqueryui_popup_dialog').dialog("close");
+
+ var data = {
+ action: "RequirementSpec/paste_template",
+ id: $('#requirement_spec_id').val(),
+ template_id: template_id,
+ current_content_type: $('#current_content_type').val(),
+ current_content_id: $('#current_content_id').val()
+ };
+
+ // console.log("I would normally POST the following now:");
+ // console.log(data);
+ $.post("controller.pl", data, kivi.eval_json_result);
+
+ return true;
+};
+
+// -------------------------------------------------------------------------
+// ---------------------------- basic settings -----------------------------
+// -------------------------------------------------------------------------
+ns.standard_basic_settings_ajax_call = function(key, opt) {
+ if (key == 'cancel') {
+ if (confirm(kivi.t8('Do you really want to cancel?'))) {
+ $('#basic_settings').show();
+ $('#basic_settings_form,#project_link_form').remove();
+ }
+ return true;
+
+ } else if (key == 'save') {
+ $('#basic_settings_form_submit').click();
+ return true;
+ }
+
+ var data = 'action=RequirementSpec/ajax_' + key + '&id=' + encodeURIComponent($('#requirement_spec_id').val());
+
+ $.post("controller.pl", data, kivi.eval_json_result);
+
+ return true;
+};
+
+// -------------------------------------------------------------------------
+// -------------------------- time/cost estimate ---------------------------
+// -------------------------------------------------------------------------
+
+ns.standard_time_cost_estimate_ajax_call = function(key, opt) {
+ if (key == 'cancel') {
+ if (confirm(kivi.t8('Do you really want to cancel?'))) {
+ $('#time_cost_estimate').show();
+ $('#time_cost_estimate_form_container').remove();
+ }
+ return true;
+ }
+
+ var add_data = '';
+ if (key == 'save_keep_open') {
+ key = 'save';
+ add_data = 'keep_open=1&';
+ }
+
+ var data = "action=RequirementSpec/ajax_" + key + "_time_and_cost_estimate&" + add_data;
+
+ if (key == 'save')
+ data += $('#edit_time_cost_estimate_form').serialize()
+ + '&' + $('#current_content_type').serialize()
+ + '&' + $('#current_content_id').serialize();
+ else
+ data += 'id=' + encodeURIComponent($('#requirement_spec_id').val());
+
+ $.post("controller.pl", data, kivi.eval_json_result);
+
+ return true;
+};
+
+ns.time_cost_estimate_input_key_down = function(event) {
+ if(event.keyCode == 13) {
+ event.preventDefault();
+ ns.standard_time_cost_estimate_ajax_call('save');
+ return false;
+ }
+};
+
+// -------------------------------------------------------------------------
+// --------------------------- quotations/orders ---------------------------
+// -------------------------------------------------------------------------
+
+ns.find_quotation_order_id = function(clicked_elt) {
+ return $(clicked_elt).find('>[name=order_id]').val();
+};
+
+ns.standard_quotation_order_ajax_call = function(key, opt) {
+ if (key == 'cancel') {
+ if (confirm(kivi.t8('Do you really want to cancel?'))) {
+ $('#quotations_and_orders').show();
+ $('#quotations_and_orders_article_assignment,#quotations_and_orders_new,#quotations_and_orders_update').remove();
+ }
+ return true;
+ }
+
+ else if ((key == 'create') && $('#quotations_and_orders_form INPUT[name="sections[].order_part_id"]').filter(function(idx, elt) { return ($(elt).val() || '') == '' }).size()) {
+ 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.'));
+ return false;
+ }
+
+ var data = 'action=RequirementSpecOrder/' + key
+ + '&' + $('#requirement_spec_id').serialize();
+
+ if ((key == 'save_assignment') || (key == 'create') || (key == 'do_update'))
+ data += '&' + $('#quotations_and_orders_form').serialize();
+ else if ((key == 'update') || (key == 'delete'))
+ data += '&rs_order_id=' + encodeURIComponent(ns.find_quotation_order_id(opt.$trigger));
+
+ // console.log("I would normally POST the following now:");
+ // console.log(data);
+ $.post("controller.pl", data, kivi.eval_json_result);