/* 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');
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++;
}
function requirement_spec_tree_node_moved(event) {
- console.debug("node moved");
+ // console.debug("node moved");
var move_obj = $.jstree._reference('#tree')._get_move();
var dragged = move_obj.o;
var dropped = move_obj.r;
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);
- });
+ }, eval_json_result);
}
-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');
-}
-
-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'));
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: "RequirementSpecItem/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 find_item_id(opt.$trigger) == undefined;
+}
+
+function submit_edit_item_form(id_base) {
+ var id = $('#' + id_base + '_id').val();
+ var url = "controller.pl?" + $('#' + id_base + '_form').serialize();
+ var data = {
+ action: 'RequirementSpecItem/ajax_' + (id ? 'update' : 'create'),
+ id: id,
+ form_prefix: id_base
+ };
+ $.post(url, data, eval_json_result);
+ return true;
+}
+
+function cancel_edit_item_form(form_id_base, hidden_id_base) {
+ var id = $('#' + form_id_base + '_id').val();
+ $('#' + form_id_base + '_form').remove();
+ if (id)
+ $('#' + hidden_id_base + '-' + id).show();
+}