Parent: [831432] (diff)

Download this file

osseval.js    95 lines (88 with data), 3.7 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
# This Source Code Form of OSSEval is subject to the terms of the GNU AFFERO
# GENERAL PUBLIC LICENSE, v. 3.0. If a copy of the AGPL was not
# distributed with this file, You can obtain one at http://www.gnu.org/licenses/agpl.txt
#
# OSSeval is powered by the SOS Open Source AGPL edition.
# The AGPL requires that you do not remove the SOS Open Source attribution and copyright
# notices from the user interface (see section 5.d below).
# OSSEval Copyright 2014 Bitergium SLL
# SOS Open Source Copyright 2012 Roberto Galoppini
# Author: Davide Galletti
*/
var id_selected_instance=0;
$(document).ready(function () {
$('legend').click(function () {
var $this = $(this);
var parent = $this.parent();
var contents = parent.contents().not(this);
if (contents.length > 0) {
$this.data("contents", contents.remove());
} else {
$this.data("contents").appendTo(parent);
}
});
$('legend').css( 'cursor', 'pointer' );
});
var update_answers_error = function(data, textStatus, jqXHR) {
console.log("update_answers_error: " + data.response);
}
var update_answers_success = function(data, textStatus, jqXHR) {
answers=eval(data);
for (i=0;i<answers.length;i++) {
$('input#choice' + data[i].choice_id).prop('checked', true);
$('input#notes' + data[i].question_id).prop('value', data[i].notes);
}
}
function updateAnswers(id_selected_instance) {
// First I clear them all
$('input.radioquestion').prop('checked', false);
$('input.questionnotes').prop('value', '');
$.ajax({
type: 'GET',
url: 'get_answers',
dataType: 'json',
success: update_answers_success,
error: update_answers_error,
data: {id_instance: id_selected_instance }
});
}
var update_metadata_error = function(data, textStatus, jqXHR) {
console.log("update_metadata_error: " + data.response);
}
var update_metadata_success = function(data, textStatus, jqXHR) {
m=eval(data);
for (i=0;i<m.length;i++) {
if (m[i].choice_id > 0) { //there is an automatic answer
already_checked = false
rq = $('[name="radioquestion'+m[i].question_id+'"]')
// Is there one radio already selected?
for (j=0;j<rq.length;j++) {
already_checked = already_checked || $('input#'+rq[j].id).prop('checked')
}
if (already_checked) { //at least one was already selected
if ($('input#choice'+m[i].choice_id).prop('checked')) //it's the one I would automatically suggest
m[i].description += " <b>(Value automatically selected)</b>"
else //I write in the description that I have an automatic suggestion
m[i].description += ' <b><font color=red>(Value automatically suggested: "'+$('input#choice'+m[i].choice_id).parent().text()+'")</font></b>'
} else { //if no value has been set yet
$('input#choice'+m[i].choice_id).prop('checked', true); //I set it according to the suggested value
$('input#choice'+m[i].choice_id).trigger("click");//I force a click to save the data
m[i].description += " <b><font color=red>(Value automatically selected)</font></b>"
}
}
$('div#MetadataInfo' + data[i].question_id).html(m[i].description);
}
}
function updateMetadata(id_selected_instance) {
//<div id="MetadataInfo{{ q.id }}">
$("div[id*='MetadataInfo']").html("<img src='/static/images/wait1.gif'/>")
$.ajax({
type: 'GET',
url: 'get_metadata',
dataType: 'json',
success: update_metadata_success,
error: update_metadata_error,
data: {id_instance: id_selected_instance }
});
}