7 function save_responses (root) {
12 for (var i in responses) {
14 for (var j in responses[i]) {
20 r.answer(responses[i][j]);
21 r.answer_date( findNodeByName(root,'effective_date').value );
28 var meth = 'open-ils.circ.survey.submit.anon';
29 if (survey_user) meth = 'open-ils.circ.survey.submit.user_id';
31 var req = new RemoteRequest( 'open-ils.circ', meth, res );
33 var ok = req.getResultObject();
36 alert('Survey response successfully saved!');
46 function init_survey (root, s_id, usr_id) {
48 var x = findNodeByName(root,'editor');
53 var adv = cgi.param('adv');
56 alert('No survey id passed in!');
60 if (findNodeByName(root,'save_response')) {
61 findNodeByName(root,'save_response')
64 "save_responses(document.getElementById('" + root.id + "')); return false;"
68 var today = new Date()
69 var month = today.getMonth() + 1
70 var day = today.getDate()
71 var year = today.getFullYear()
73 if (findNodeByName(root,'effective_date')) {
74 findNodeByName(root,'effective_date').value = '%04d%s%02d%s%02d'.sprintf(year,s,month,s,day);
75 findNodeByName(root,'effective_date').id = 'e_date_' + s_id;
80 findNodeByName(root,'effective_date').parentNode.parentNode.setAttribute('adv','false');
83 var req = new RemoteRequest( 'open-ils.circ', 'open-ils.circ.survey.fleshed.retrieve', s_id );
85 sur = req.getResultObject();
89 if (findNodeByName(x,'sur.name'))
90 findNodeByName(x,'sur.name').appendChild( text( sur.name() ) );
92 if (findNodeByName(x,'sur.description'))
93 findNodeByName(x,'sur.description').appendChild( text( sur.description() ) );
95 if (findNodeByName(x,'sur.start_date'))
96 findNodeByName(x,'sur.start_date').appendChild( text( sur.start_date() ) );
98 if (findNodeByName(x,'sur.end_date'))
99 findNodeByName(x,'sur.end_date').appendChild( text( sur.end_date() ) );
101 q_tmpl = findNodeByName(root,'question-tmpl').getElementsByTagName('table')[0];
103 x = findNodeByName(x,'questions');
104 for (var i in sur.questions()) {
105 var q = sur.questions()[i];
106 var new_q = q_tmpl.cloneNode(true);
107 x.appendChild(new_q);
109 findNodeByName(new_q,'q.question').appendChild( text( q.question() ) );
111 var sel = findNodeByName(new_q,'answers-sel');
112 sel.options[0] = new Option('-- Select one --');
114 var rad = findNodeByName(new_q,'answers-rad');
118 for (var j in q.answers()) {
119 var a = q.answers()[j];
120 var opt = new Option(a.answer());
122 opt.setAttribute('answer', a.id());
123 opt.setAttribute('question', q.id());
124 opt.setAttribute('survey', sur.id());
126 sel.options[sel.options.length] = opt;
129 rad.parentNode.className = 'rad-value';
130 for (var j in q.answers()) {
131 var a = q.answers()[j];
133 var opt = rad.cloneNode(true);
136 opt.firstChild.setAttribute('name','res_' + i );
137 opt.firstChild.setAttribute('answer', a.id());
138 opt.firstChild.setAttribute('question', q.id());
139 opt.firstChild.setAttribute('survey', sur.id());
141 opt.appendChild(text(a.answer()));
142 rad.parentNode.appendChild(opt);
150 function update_response (sel) {
151 var opt = sel.options[sel.selectedIndex];
152 if (!responses[opt.getAttribute('survey')])
153 responses[opt.getAttribute('survey')] = {};
155 responses[opt.getAttribute('survey')][opt.getAttribute('question')] = opt.getAttribute('answer');
157 function update_response_rad (opt) {
158 if (!responses[opt.getAttribute('survey')])
159 responses[opt.getAttribute('survey')] = {};
161 responses[opt.getAttribute('survey')][opt.getAttribute('question')] = opt.getAttribute('answer');