+ $.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);
+
+ return true;
+};
+
+ns.ask_delete_quotation_order = function(key, opt) {
+ if (confirm(kivi.t8("Are you sure?")))
+ ns.standard_quotation_order_ajax_call(key, opt);
+ return true;
+};
+
+ns.disable_edit_quotation_order_commands = function(key, opt) {
+ return ns.find_quotation_order_id(opt.$trigger) == undefined;
+};
+
+ns.disable_create_quotation_order_commands = function(key, opt) {
+ return !$('#quotations_and_orders_sections');
+};
+
+ns.assign_order_part_id_to_all = function() {
+ var order_part_id = $('#quotations_and_orders_order_id').val();
+ var order_part_name = $('#quotations_and_orders_order_id_name').val();
+
+ $('#quotations_and_orders_form INPUT[name="sections[].order_part_id"]').each(function(idx, elt) {
+ $(elt).val(order_part_id);
+ });
+
+ $('#quotations_and_orders_form [id^=quotations_and_orders_sections_order_pard_id_]').filter(function() {
+ return $(this).attr('id') && $(this).attr('id').match("^quotations_and_orders_sections_order_pard_id_[0-9]+_name$");
+ }).each(function(idx, elt) {
+ $(elt).val(order_part_name);
+ });
+};
+
+// -------------------------------------------------------------------------
+// ---------------------------- general actions ----------------------------
+// -------------------------------------------------------------------------
+
+ns.create_reqspec_pdf = function(key, opt) {
+ var data = {
+ action: "RequirementSpec/create_pdf",
+ id: $('#requirement_spec_id').val()
+ };
+ $.download("controller.pl", data);
+};
+
+ns.copy_reqspec = function(key, opt) {
+ window.location.href = "controller.pl?action=RequirementSpec/new©_source_id=" + encodeURIComponent($('#requirement_spec_id').val());
+ return true;
+};
+
+ns.delete_reqspec = function(key, opt) {
+ if (confirm(kivi.t8("Are you sure?")))
+ window.location.href = "controller.pl?action=RequirementSpec/destroy&id=" + encodeURIComponent($('#requirement_spec_id').val());
+ return true;
+};
+
+ns.disable_commands = function(key, opt) {
+ if (key === "create_version")
+ return ($('#current_version_id').val() || '') == '' ? false : true;
+ return false;
+};
+
+// -------------------------------------------------------------------------
+// -------------------------------- versions -------------------------------
+// -------------------------------------------------------------------------
+
+ns.find_versioned_copy_id = function(clicked_elt) {
+ var id = $(clicked_elt).find("[name=versioned_copy_id]");
+ return id ? id.val() : undefined;
+};
+
+ns.disable_versioned_copy_item_commands = function(key, opt) {
+ if (key === "revert_to_version")
+ return !ns.find_versioned_copy_id(opt.$trigger);
+ return false;
+};
+
+ns.create_version = function() {
+ kivi.popup_dialog({ url: 'controller.pl',
+ data: { action: 'RequirementSpecVersion/new',
+ requirement_spec_id: $('#requirement_spec_id').val() },
+ dialog: { title: kivi.t8('Create a new version') }});
+ return true;
+};
+
+ns.create_pdf_for_versioned_copy_ajax_call = function(key, opt) {
+ var data = {
+ action: "RequirementSpec/create_pdf",
+ id: ns.find_versioned_copy_id(opt.$trigger)
+ };
+ $.download("controller.pl", data);
+
+ return true;
+};
+
+ns.revert_to_versioned_copy_ajax_call = function(key, opt) {
+ if (!confirm(kivi.t8('Do you really want to revert to this version?')))
+ return true;
+
+ var data = {
+ action: 'RequirementSpec/revert_to',
+ versioned_copy_id: ns.find_versioned_copy_id(opt.$trigger),
+ id: $('#requirement_spec_id').val()
+ };
+
+ $.post("controller.pl", data, kivi.eval_json_result);