1 /* Functions used for the requirement specs tree view */
3 // -----------------------------------------------------------------------------
4 // ------------------------------ the tree itself ------------------------------
5 // -----------------------------------------------------------------------------
7 function requirement_spec_tree_check_move(data) {
8 var dragged_type = data.o.data('type');
9 var dropped_type = data.r.data('type');
11 // console.debug("dragged " + dragged_type + " dropped " + dropped_type + " dir " + data.p);
13 if ((dragged_type == "sections") || (dragged_type == "text-blocks-front") || (dragged_type == "text-blocks-back"))
16 if (dragged_type == "text-block") {
17 if ((dropped_type == "text-blocks-front") || (dropped_type == "text-blocks-back"))
18 return (data.p == "inside") || (data.p == "last");
19 if (dropped_type == "text-block")
20 return (data.p == "before") || (data.p == "after");
25 if (dragged_type == "section") {
26 if (dropped_type == "sections")
27 return (data.p == "inside") || (data.p == "last");
28 if (dropped_type == "section")
29 return (data.p == "before") || (data.p == "after");
34 // dragged_type == (sub) function blocks
35 if ((dropped_type == "text-block") || (dropped_type == "text-blocks-front") || (dropped_type == "text-blocks-back"))
38 var dropped_depth = dropped_type == "sections" ? 0 : dropped_type == "section" ? 1 : data.r.parent().parent().data('type') != "function-block" ? 2 : 3;
39 if ((data.p == "inside") || (data.p == "last"))
42 var dragged_depth = 1 + data.o.children('ul').size();
44 // console.debug("dropped_depth " + dropped_depth + " dragged_depth " + dragged_depth);
46 return (2 <= dropped_depth) && ((dragged_depth + dropped_depth) <= 4);
49 function requirement_spec_tree_node_moved(event) {
50 console.debug("node moved");
51 var move_obj = $.jstree._reference('#tree')._get_move();
52 var dragged = move_obj.o;
53 var dropped = move_obj.r;
54 var controller = dragged.data("type") == "text-block" ? "RequirementSpecTextBlock" : "RequirementSpecItem";
56 action: controller + "/dragged_and_dropped",
57 requirement_spec_id: $('#requirement_spec_id').val(),
58 id: dragged.data("id"),
59 dropped_id: dropped.data("id"),
60 dropped_type: dropped.data("type"),
62 current_content_type: $('#current_content_type').val(),
63 current_content_id: $('#current_content_id').val()
65 // console.debug("controller: " + controller);
66 // console.debug(data);
68 $.post("controller.pl", data, eval_json_result);
73 function requirement_spec_tree_node_clicked(event) {
74 var node = $.jstree._reference('#tree')._get_node(event.target);
75 var type = node ? node.data('type') : undefined;
80 var url = 'controller.pl?action='
81 $.get('controller.pl', {
82 action: (/^text-block/.test(type) ? 'RequirementSpecTextBlock' : 'RequirementSpecItem') + '/ajax_list.js',
83 requirement_spec_id: $('#requirement_spec_id').val(),
84 current_content_type: $('#current_content_type').val(),
85 current_content_id: $('#current_content_id').val(),
87 clicked_id: node.data('id')
91 // -------------------------------------------------------------------------
92 // ------------------------------ text blocks ------------------------------
93 // -------------------------------------------------------------------------
95 function find_text_block_id(clicked_elt) {
96 // console.log("id: " + $(clicked_elt).attr('id'));
97 var id = $(clicked_elt).attr('id');
98 if (/^text-block-\d+$/.test(id)) {
99 // console.log("find_text_block_id: case 1: " + id.substr(11));
100 return id.substr(11) * 1;
103 id = $(clicked_elt).closest("[id*=text-block-]").attr('id')
104 if (/^text-block-\d+$/.test(id)) {
105 // console.log("find_text_block_id: case 2: " + id.substr(11));
106 return id.substr(11) * 1;
109 id = $(clicked_elt).closest("[id*=tb-]").attr('id')
110 if (/^tb-\d+$/.test(id)) {
111 // console.log("find_text_block_id: case 3: " + id.substr(3));
112 return id.substr(3) * 1;
115 // console.log("find_text_block_id: case undef");
119 function find_text_block_output_position(clicked_elt) {
120 var output_position = $(clicked_elt).closest('#text-block-list-container').find('#text_block_output_position').val();
122 return output_position;
124 var type = $(clicked_elt).closest('#tb-back,#tb-front').data('type');
125 if (/^text-blocks-(front|back)/.test(type))
126 return type == "text-blocks-front" ? 0 : 1;
131 function disable_edit_text_block_commands(key, opt) {
132 return find_text_block_id(opt.$trigger) == undefined;
135 function standard_text_block_ajax_call(key, opt, other_data) {
137 action: "RequirementSpecTextBlock/ajax_" + key,
138 requirement_spec_id: $('#requirement_spec_id').val(),
139 id: find_text_block_id(opt.$trigger),
140 output_position: find_text_block_output_position(opt.$trigger),
141 current_content_type: $('#current_content_type').val(),
142 current_content_id: $('#current_content_id').val()
145 $.post("controller.pl", $.extend(data, other_data || {}), eval_json_result);
150 function submit_edit_text_block_form(id_base) {
151 var id = $('#' + id_base + '_id').val();
152 var url = "controller.pl?" + $('#' + id_base + '_form').serialize();
154 action: 'RequirementSpecTextBlock/ajax_' + (id ? 'update' : 'create'),
158 $.post(url, data, eval_json_result);
162 function cancel_edit_text_block_form(id_base) {
163 var id = $('#' + id_base + '_id').val();
164 $('#' + id_base + '_form').remove();
166 $('#text-block-' + id).show();
169 // --------------------------------------------------------------------------------
170 // ------------------------------ sections and items ------------------------------
171 // --------------------------------------------------------------------------------
173 function find_item_id(clicked_elt) {
174 console.log("clicked id: " + $(clicked_elt).attr('id'));
175 var id = $(clicked_elt).attr('id');
176 var result = /^(function-block|function-block-content|sub-function-block|sub-function-block-content|section|section-header)-(\d+)$/.exec(id);
178 console.log("find_item_id: case 1: " + result[2]);
182 id = $(clicked_elt).closest("[id*=fb-]").attr('id')
183 if (/^fb-\d+$/.test(id)) {
184 console.log("find_item_id: case 2: " + id.substr(3));
185 return id.substr(3) * 1;
188 console.log("find_item_id: case undef");
192 function standard_item_ajax_call(key, opt, other_data) {
194 action: "RequirementSpecTextBlock/ajax_" + key,
195 requirement_spec_id: $('#requirement_spec_id').val(),
196 id: find_item_id(opt.$trigger),
197 current_content_type: $('#current_content_type').val(),
198 current_content_id: $('#current_content_id').val()
201 console.log("I would normally POST the following now:");
203 // $.post("controller.pl", $.extend(data, other_data || {}), eval_json_result);
208 function disable_edit_item_commands(key, opt) {
209 return false; // find_item_id(opt.$trigger) == undefined;