Pflichtenhefte: Auflisten von Abschnitten
[kivitendo-erp.git] / js / requirement_spec.js
index de3e8d5..6e9aaf4 100644 (file)
@@ -1,5 +1,9 @@
 /* Functions used for the requirement specs tree view */
 
+// -----------------------------------------------------------------------------
+// ------------------------------ the tree itself ------------------------------
+// -----------------------------------------------------------------------------
+
 function requirement_spec_tree_check_move(data) {
   var dragged_type = data.o.data('type');
   var dropped_type = data.r.data('type');
@@ -31,7 +35,7 @@ function requirement_spec_tree_check_move(data) {
   if ((dropped_type == "text-block") || (dropped_type == "text-blocks-front") || (dropped_type == "text-blocks-back"))
     return false;
 
-  var dropped_depth = dropped_type == "sections" ? 0 : dropped_type == "section" ? 1 : data.r.parent().parent().data('type') != "functionblock" ? 2 : 3;
+  var dropped_depth = dropped_type == "sections" ? 0 : dropped_type == "section" ? 1 : data.r.parent().parent().data('type') != "function-block" ? 2 : 3;
   if ((data.p == "inside") || (data.p == "last"))
     dropped_depth++;
 
@@ -73,68 +77,20 @@ function requirement_spec_tree_node_clicked(event) {
   if (!type)
     return;
 
-  if ('sections' ==  type) {
-    $('#current_content_type').val('sections');
-    $('#current_content_id').val('');
-    return;
-  }
-
   var url = 'controller.pl?action='
   $.get('controller.pl', {
-    action:               (/^text-block/ ? 'RequirementSpecTextBlock' : 'RequirementSpecItem') + '/ajax_list.js',
+    action:               (/^text-block/.test(type) ? 'RequirementSpecTextBlock' : 'RequirementSpecItem') + '/ajax_list.js',
     requirement_spec_id:  $('#requirement_spec_id').val(),
     current_content_type: $('#current_content_type').val(),
     current_content_id:   $('#current_content_id').val(),
     clicked_type:         type,
     clicked_id:           node.data('id')
-  }, function(new_data) {
-    $('#current_content_type').val(type);
-    $('#current_content_id').val(node.data('id'));
-    eval_json_result(new_data);
-  });
-}
-
-function section_form_requested(data) {
-  $('#new-section-button').removeAttr('disabled');
-  if (data.status == "ok")
-    $('#content-column').html(data.html);
-  else
-    alert('oh yeah response: ' + data.status + "\n" + data.error);
-}
-
-function section_form_submitted(data) {
-  alert('oh yeah response: ' + data.status);
-}
-
-function server_side_error(things_to_enable) {
-  alert('Server-side error.');
-  if (things_to_enable)
-    $(things_to_enable).removeAttr('disabled');
+  }, eval_json_result);
 }
 
-function new_section_form() {
-  $('#new-section-button').attr('disabled', 'disabled');
-  $.ajax({
-    type: 'POST',
-    url: 'controller.pl',
-    data: 'action=RequirementSpecItem/new.json&requirement_spec_id=' + $('#requirement_spec_id').val() + '&item_type=section',
-    success: section_form_requested,
-    error: function() { server_side_error('#new-section-button'); }
-  });
-}
-
-function submit_section_form(id) {
-  $.ajax({
-    type: 'POST',
-    url: 'controller.pl',
-    data: 'action=RequirementSpecItem/create.json&' + $('section-form-' + id).serialize(),
-    success: section_form_submitted
-  });
-}
-
-function cancel_section_form(id) {
-  $('#content-column').html('intentionally empty');
-}
+// -------------------------------------------------------------------------
+// ------------------------------ text blocks ------------------------------
+// -------------------------------------------------------------------------
 
 function find_text_block_id(clicked_elt) {
   // console.log("id: " + $(clicked_elt).attr('id'));
@@ -209,3 +165,46 @@ function cancel_edit_text_block_form(id_base) {
   if (id)
     $('#text-block-' + id).show();
 }
+
+// --------------------------------------------------------------------------------
+// ------------------------------ sections and items ------------------------------
+// --------------------------------------------------------------------------------
+
+function find_item_id(clicked_elt) {
+  console.log("clicked id: " + $(clicked_elt).attr('id'));
+  var id     = $(clicked_elt).attr('id');
+  var result = /^(function-block|function-block-content|sub-function-block|sub-function-block-content|section|section-header)-(\d+)$/.exec(id);
+  if (result) {
+    console.log("find_item_id: case 1: " + result[2]);
+    return result[2];
+  }
+
+  id = $(clicked_elt).closest("[id*=fb-]").attr('id')
+  if (/^fb-\d+$/.test(id)) {
+    console.log("find_item_id: case 2: " + id.substr(3));
+    return id.substr(3) * 1;
+  }
+
+  console.log("find_item_id: case undef");
+  return undefined;
+}
+
+function standard_item_ajax_call(key, opt, other_data) {
+  var data = {
+    action:               "RequirementSpecTextBlock/ajax_" + key,
+    requirement_spec_id:  $('#requirement_spec_id').val(),
+    id:                   find_item_id(opt.$trigger),
+    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", $.extend(data, other_data || {}), eval_json_result);
+
+  return true;
+}
+
+function disable_edit_item_commands(key, opt) {
+  return false; // find_item_id(opt.$trigger) == undefined;
+}