1 /* Functions used for the requirement specs tree view */
3 function check_move(data) {
4 var dragged_type = data.o.data('type');
5 var dropped_type = data.r.data('type');
7 // console.debug("dragged " + dragged_type + " dropped " + dropped_type + " dir " + data.p);
9 if ((dragged_type == "sections") || (dragged_type == "textblocks-front") || (dragged_type == "textblocks-back"))
12 if (dragged_type == "textblock") {
13 if ((dropped_type == "textblocks-front") || (dropped_type == "textblocks-back"))
14 return (data.p == "inside") || (data.p == "last");
15 if (dropped_type == "textblock")
16 return (data.p == "before") || (data.p == "after");
21 if (dragged_type == "section") {
22 if (dropped_type == "sections")
23 return (data.p == "inside") || (data.p == "last");
24 if (dropped_type == "section")
25 return (data.p == "before") || (data.p == "after");
30 // dragged_type == (sub) function blocks
31 if ((dropped_type == "textblock") || (dropped_type == "textblocks-front") || (dropped_type == "textblocks-back"))
34 var dropped_depth = dropped_type == "sections" ? 0 : dropped_type == "section" ? 1 : data.r.parent().parent().data('type') != "functionblock" ? 2 : 3;
35 if ((data.p == "inside") || (data.p == "last"))
38 var dragged_depth = 1 + data.o.children('ul').size();
40 // console.debug("dropped_depth " + dropped_depth + " dragged_depth " + dragged_depth);
42 return (2 <= dropped_depth) && ((dragged_depth + dropped_depth) <= 4);
45 function node_moved(event) {
46 console.debug("node moved");
47 var move_obj = $.jstree._reference('#tree')._get_move();
48 var dragged = move_obj.o;
49 var dropped = move_obj.r;
50 var controller = dragged.data("type") == "textblock" ? "RequirementSpecTextBlock" : "RequirementSpecItem";
52 action: controller + "/dragged_and_dropped",
53 requirement_spec_id: $('#requirement_spec_id').val(),
54 id: dragged.data("id"),
55 dropped_id: dropped.data("id"),
56 dropped_type: dropped.data("type"),
58 current_content_type: $('#current_content_type').val(),
59 current_content_id: $('#current_content_id').val()
61 // console.debug("controller: " + controller);
62 // console.debug(data);
64 $.post("controller.pl", data, eval_json_result);
69 function node_clicked(event) {
70 var node = $.jstree._reference('#tree')._get_node(event.target);
71 var type = node ? node.data('type') : undefined;
76 if ('sections' == type) {
77 $('#current_content_type').val('sections');
78 $('#current_content_id').val('');
82 var url = 'controller.pl?action='
83 $.get('controller.pl', {
84 action: (/^textblock/ ? 'RequirementSpecTextBlock' : 'RequirementSpecItem') + '/ajax_list.js',
85 current_content_type: $('#current_content_type').val(),
86 current_content_id: $('#current_content_id').val(),
88 clicked_id: node.data('id')
89 }, function(new_data) {
90 $('#current_content_type').val(type);
91 $('#current_content_id').val(node.data('id'));
92 eval_json_result(new_data);
96 function section_form_requested(data) {
97 $('#new-section-button').removeAttr('disabled');
98 if (data.status == "ok")
99 $('#content-column').html(data.html);
101 alert('oh yeah response: ' + data.status + "\n" + data.error);
104 function section_form_submitted(data) {
105 alert('oh yeah response: ' + data.status);
108 function server_side_error(things_to_enable) {
109 alert('Server-side error.');
110 if (things_to_enable)
111 $(things_to_enable).removeAttr('disabled');
114 function new_section_form() {
115 $('#new-section-button').attr('disabled', 'disabled');
118 url: 'controller.pl',
119 data: 'action=RequirementSpecItem/new.json&requirement_spec_id=' + $('#requirement_spec_id').val() + '&item_type=section',
120 success: section_form_requested,
121 error: function() { server_side_error('#new-section-button'); }
125 function submit_section_form(id) {
128 url: 'controller.pl',
129 data: 'action=RequirementSpecItem/create.json&' + $('section-form-' + id).serialize(),
130 success: section_form_submitted
134 function cancel_section_form(id) {
135 $('#content-column').html('intentionally empty');