X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/ca7c2f910a3eecaa971a0d9943b94928cafa5530..e2f753a4cb6c299fc6440ae94e20891a5a0c77cb:/js/requirement_spec.js?ds=sidebyside diff --git a/js/requirement_spec.js b/js/requirement_spec.js index fdd949e8e..de3e8d531 100644 --- a/js/requirement_spec.js +++ b/js/requirement_spec.js @@ -1,18 +1,18 @@ /* Functions used for the requirement specs tree view */ -function check_move(data) { +function requirement_spec_tree_check_move(data) { var dragged_type = data.o.data('type'); var dropped_type = data.r.data('type'); // console.debug("dragged " + dragged_type + " dropped " + dropped_type + " dir " + data.p); - if ((dragged_type == "sections") || (dragged_type == "textblocks-front") || (dragged_type == "textblocks-back")) + if ((dragged_type == "sections") || (dragged_type == "text-blocks-front") || (dragged_type == "text-blocks-back")) return false; - if (dragged_type == "textblock") { - if ((dropped_type == "textblocks-front") || (dropped_type == "textblocks-back")) + if (dragged_type == "text-block") { + if ((dropped_type == "text-blocks-front") || (dropped_type == "text-blocks-back")) return (data.p == "inside") || (data.p == "last"); - if (dropped_type == "textblock") + if (dropped_type == "text-block") return (data.p == "before") || (data.p == "after"); return false; @@ -28,7 +28,7 @@ function check_move(data) { } // dragged_type == (sub) function blocks - if ((dropped_type == "textblock") || (dropped_type == "textblocks-front") || (dropped_type == "textblocks-back")) + 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; @@ -42,12 +42,12 @@ function check_move(data) { return (2 <= dropped_depth) && ((dragged_depth + dropped_depth) <= 4); } -function node_moved(event) { +function requirement_spec_tree_node_moved(event) { console.debug("node moved"); var move_obj = $.jstree._reference('#tree')._get_move(); var dragged = move_obj.o; var dropped = move_obj.r; - var controller = dragged.data("type") == "textblock" ? "RequirementSpecTextBlock" : "RequirementSpecItem"; + var controller = dragged.data("type") == "text-block" ? "RequirementSpecTextBlock" : "RequirementSpecItem"; var data = { action: controller + "/dragged_and_dropped", requirement_spec_id: $('#requirement_spec_id').val(), @@ -66,7 +66,7 @@ function node_moved(event) { return true; } -function node_clicked(event) { +function requirement_spec_tree_node_clicked(event) { var node = $.jstree._reference('#tree')._get_node(event.target); var type = node ? node.data('type') : undefined; @@ -81,7 +81,8 @@ function node_clicked(event) { var url = 'controller.pl?action=' $.get('controller.pl', { - action: (/^textblock/ ? 'RequirementSpecTextBlock' : 'RequirementSpecItem') + '/ajax_list.js', + action: (/^text-block/ ? '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, @@ -134,3 +135,77 @@ function submit_section_form(id) { function cancel_section_form(id) { $('#content-column').html('intentionally empty'); } + +function find_text_block_id(clicked_elt) { + // console.log("id: " + $(clicked_elt).attr('id')); + var id = $(clicked_elt).attr('id'); + if (/^text-block-\d+$/.test(id)) { + // console.log("find_text_block_id: case 1: " + id.substr(11)); + return id.substr(11) * 1; + } + + id = $(clicked_elt).closest("[id*=text-block-]").attr('id') + if (/^text-block-\d+$/.test(id)) { + // console.log("find_text_block_id: case 2: " + id.substr(11)); + return id.substr(11) * 1; + } + + id = $(clicked_elt).closest("[id*=tb-]").attr('id') + if (/^tb-\d+$/.test(id)) { + // console.log("find_text_block_id: case 3: " + id.substr(3)); + return id.substr(3) * 1; + } + + // console.log("find_text_block_id: case undef"); + return undefined; +} + +function find_text_block_output_position(clicked_elt) { + var output_position = $(clicked_elt).closest('#text-block-list-container').find('#text_block_output_position').val(); + if (output_position) + return output_position; + + var type = $(clicked_elt).closest('#tb-back,#tb-front').data('type'); + if (/^text-blocks-(front|back)/.test(type)) + return type == "text-blocks-front" ? 0 : 1; + + return undefined; +} + +function disable_edit_text_block_commands(key, opt) { + return find_text_block_id(opt.$trigger) == undefined; +} + +function standard_text_block_ajax_call(key, opt, other_data) { + var data = { + action: "RequirementSpecTextBlock/ajax_" + key, + requirement_spec_id: $('#requirement_spec_id').val(), + id: find_text_block_id(opt.$trigger), + output_position: find_text_block_output_position(opt.$trigger), + current_content_type: $('#current_content_type').val(), + current_content_id: $('#current_content_id').val() + }; + + $.post("controller.pl", $.extend(data, other_data || {}), eval_json_result); + + return true; +} + +function submit_edit_text_block_form(id_base) { + var id = $('#' + id_base + '_id').val(); + var url = "controller.pl?" + $('#' + id_base + '_form').serialize(); + var data = { + action: 'RequirementSpecTextBlock/ajax_' + (id ? 'update' : 'create'), + id: id, + form_prefix: id_base + }; + $.post(url, data, eval_json_result); + return true; +} + +function cancel_edit_text_block_form(id_base) { + var id = $('#' + id_base + '_id').val(); + $('#' + id_base + '_form').remove(); + if (id) + $('#text-block-' + id).show(); +}