|
a |
|
b/qiita_pet/templates/edit_study.html |
|
|
1 |
{% extends sitebase.html %} |
|
|
2 |
{% block head %} |
|
|
3 |
<script type = "text/javascript" |
|
|
4 |
src = "{% raw qiita_config.portal_dir %}/static/vendor/js/jquery.validate.min.js"> |
|
|
5 |
</script> |
|
|
6 |
<style> |
|
|
7 |
.custom-combobox { |
|
|
8 |
position: relative; |
|
|
9 |
display: inline-block; |
|
|
10 |
} |
|
|
11 |
.custom-combobox-toggle { |
|
|
12 |
position: absolute; |
|
|
13 |
top: 0; |
|
|
14 |
bottom: 0; |
|
|
15 |
margin-left: -1px; |
|
|
16 |
padding: 0; |
|
|
17 |
} |
|
|
18 |
.custom-combobox-input { |
|
|
19 |
margin: 0; |
|
|
20 |
padding: 5px 10px; |
|
|
21 |
} |
|
|
22 |
</style> |
|
|
23 |
|
|
|
24 |
<script> |
|
|
25 |
$(document).ready(function() { |
|
|
26 |
$("#new_person_div").hide(); |
|
|
27 |
$( "#{{creation_form.principal_investigator.id}}" ).chosen({ |
|
|
28 |
allow_single_deselect: true |
|
|
29 |
}); |
|
|
30 |
$( "#{{creation_form.lab_person.id}}" ).chosen({ |
|
|
31 |
allow_single_deselect: true |
|
|
32 |
}); |
|
|
33 |
|
|
|
34 |
$("#study_title").on("keyup", function() { |
|
|
35 |
var title = $(this).val(); |
|
|
36 |
// removing any duplicated whitespaces |
|
|
37 |
title = title.replace(/ +(?= )/g, ''); |
|
|
38 |
//remove all utf-8 encoded characters that are not also printable ASCII characters. |
|
|
39 |
title = title.replace(/[^\x20-\x7E]+/g, ""); |
|
|
40 |
// removing white spaces from the front of the text |
|
|
41 |
$(this).val(title.trimLeft()); |
|
|
42 |
}); |
|
|
43 |
|
|
|
44 |
$("#new_person_name").on("keyup", function() { |
|
|
45 |
var npn = $(this).val(); |
|
|
46 |
// removing any duplicated whitespaces |
|
|
47 |
npn = npn.replace(/ +(?= )/g, ''); |
|
|
48 |
//remove all utf-8 encoded characters that are not also printable ASCII characters. |
|
|
49 |
npn = npn.replace(/[^\x20-\x7E]+/g, ""); |
|
|
50 |
// removing white spaces from the front of the text |
|
|
51 |
$(this).val(npn.trimLeft()); |
|
|
52 |
}); |
|
|
53 |
|
|
|
54 |
$("#create_study").validate({ |
|
|
55 |
ignore: "", |
|
|
56 |
submitHandler: function (form) { |
|
|
57 |
//from http://stackoverflow.com/a/18265708 |
|
|
58 |
// let's disable the inputs for the duration of the ajax request |
|
|
59 |
$("#create_study_submit").prop('disabled', true); |
|
|
60 |
|
|
|
61 |
// fire off ajax the request |
|
|
62 |
request = $.ajax({ |
|
|
63 |
type: "GET", |
|
|
64 |
url: '{% raw qiita_config.portal_dir %}/check_study/', |
|
|
65 |
data: {study_title: $("#study_title")[0].value.trim() {% if study %}, old_study_title: "{% raw study.title.replace('"', '\\"') %}"{% end %} } |
|
|
66 |
}); |
|
|
67 |
|
|
|
68 |
// callback handler that will be called on success |
|
|
69 |
request.done(function (response, textStatus, jqXHR) { |
|
|
70 |
if (response == 'True') { |
|
|
71 |
form.submit(); |
|
|
72 |
} |
|
|
73 |
else { |
|
|
74 |
var title = $("#study_title")[0].value.trim(); |
|
|
75 |
$("#create_study_submit").prop('disabled', false); |
|
|
76 |
$("#messagespan").text("Study '" + title + "' already exists! Please choose a different name."); |
|
|
77 |
alert($("#messagespan").text()); |
|
|
78 |
$("#study_title").val(title) |
|
|
79 |
} |
|
|
80 |
}); |
|
|
81 |
|
|
|
82 |
// callback handler that will be called on failure |
|
|
83 |
request.fail(function (jqXHR, textStatus, errorThrown) { |
|
|
84 |
// log the error to the console |
|
|
85 |
console.error( |
|
|
86 |
"The following error occured: " + textStatus, errorThrown); |
|
|
87 |
$("#create_study_submit").prop('disabled', false); |
|
|
88 |
}); |
|
|
89 |
}, |
|
|
90 |
rules:{ |
|
|
91 |
{% for idx, form_item in enumerate(creation_form, start=1) %} |
|
|
92 |
{% if form_item.flags.required %} |
|
|
93 |
{{form_item.name}}: {required:true}, |
|
|
94 |
{% end %} |
|
|
95 |
{% end %} |
|
|
96 |
}, |
|
|
97 |
messages: { |
|
|
98 |
{% for idx, form_item in enumerate(creation_form, start=1) %} |
|
|
99 |
{% if form_item.flags.required %} |
|
|
100 |
{{form_item.name}}: '{{form_item.label.text}} is required', |
|
|
101 |
{% end %} |
|
|
102 |
{% end %} |
|
|
103 |
}, |
|
|
104 |
errorLabelContainer: "#errorspan", |
|
|
105 |
wrapper: "li", |
|
|
106 |
}); |
|
|
107 |
|
|
|
108 |
$('#{{creation_form.principal_investigator.id}}').on('change', function(e) { |
|
|
109 |
$("#create_study").validate().element("#{{creation_form.principal_investigator.id}}"); |
|
|
110 |
}); |
|
|
111 |
}); |
|
|
112 |
|
|
|
113 |
counter = -1; |
|
|
114 |
|
|
|
115 |
function add_new_person(name, affiliation, email, phone, address) { |
|
|
116 |
if (name.value == '') { |
|
|
117 |
$("#new_person_name").focus(); |
|
|
118 |
return false; |
|
|
119 |
}; |
|
|
120 |
if (affiliation.value == '') { |
|
|
121 |
$("#new_person_affiliation").focus(); |
|
|
122 |
return false; |
|
|
123 |
}; |
|
|
124 |
if (email.value == '') { |
|
|
125 |
$("#new_person_email").focus(); |
|
|
126 |
return false; |
|
|
127 |
}; |
|
|
128 |
|
|
|
129 |
var new_element = '<option value="'+counter+'" "selected">' + name.value + ', ' + affiliation.value + '</option>'; |
|
|
130 |
|
|
|
131 |
$("#{{creation_form.principal_investigator.id}}").append(new_element); |
|
|
132 |
$("#{{creation_form.lab_person.id}}" ).append(new_element); |
|
|
133 |
$("#{{creation_form.principal_investigator.id}}").trigger("chosen:updated"); |
|
|
134 |
$("#{{creation_form.lab_person.id}}" ).trigger("chosen:updated"); |
|
|
135 |
$("#new_person_div").hide(400); |
|
|
136 |
|
|
|
137 |
$("#create_study").append('<input type="hidden" name="new_people_names" value="' + name.value + '">'); |
|
|
138 |
$("#create_study").append('<input type="hidden" name="new_people_affiliations" value="' + affiliation.value + '">'); |
|
|
139 |
$("#create_study").append('<input type="hidden" name="new_people_emails" value="' + email.value + '">'); |
|
|
140 |
$("#create_study").append('<input type="hidden" name="new_people_phones" value="' + phone.value + '">'); |
|
|
141 |
$("#create_study").append('<input type="hidden" name="new_people_addresses" value="' + address.value + '">'); |
|
|
142 |
|
|
|
143 |
counter -= 1; |
|
|
144 |
}; |
|
|
145 |
|
|
|
146 |
{% if study %} |
|
|
147 |
function cancel_edition(){ |
|
|
148 |
if (confirm("Are you sure you want to go to the study description page? None of the changes will be stored")){ |
|
|
149 |
window.location.href = "{% raw qiita_config.portal_dir %}/study/description/{{study.id}}"; |
|
|
150 |
} |
|
|
151 |
} |
|
|
152 |
{% end %} |
|
|
153 |
|
|
|
154 |
</script> |
|
|
155 |
|
|
|
156 |
{% end %} |
|
|
157 |
|
|
|
158 |
{% block content %} |
|
|
159 |
<h1>{% if study %}Edit study (ID: {{study.id}}) {% else %}Create a new Study{%end%}</h1> |
|
|
160 |
<hr/> |
|
|
161 |
<h3>If you are planning to load a study with data already present in NCBI SRA or EBI ENA, please complete <a target="_blank" href="https://docs.google.com/forms/d/1SIq_JNWai7cZ2wwjD8xZpTab7qBifLKu3TZm2B363CE/edit?ts=5fbe8c0b&gxids=7628">this form</a> as we may be able to assist. |
|
|
162 |
<hr/> |
|
|
163 |
<h3> |
|
|
164 |
<font color="red">*</font> = Required Field |
|
|
165 |
</h3> |
|
|
166 |
<span id="errorspan" name="errorspan" style="color: red"></span> |
|
|
167 |
<span id="messagespan" name="messagespan" style="color: red"></span> |
|
|
168 |
<br /> |
|
|
169 |
<form id="create_study" name="create_study" action={%if study%}'{% raw qiita_config.portal_dir %}/study/edit/{{study.id}}'{%else%}'{% raw qiita_config.portal_dir %}/study/create/'{%end%} method="POST"> |
|
|
170 |
<table> |
|
|
171 |
{% for idx, form_item in enumerate(creation_form, start=1) %} |
|
|
172 |
{% set kwargs = {'tabindex': idx, 'class_': 'form-control'} %} |
|
|
173 |
{% set additional_info = form_item.description %} |
|
|
174 |
{# form-item-specific rendering #} |
|
|
175 |
{% if form_item.label.text == 'Environmental Packages' %} |
|
|
176 |
{% set kwargs['size'] = len(form_item.choices) %} |
|
|
177 |
{% set additional_info = 'You can select multiple entries by control-clicking (mac: command-clicking)' %} |
|
|
178 |
{% elif form_item.label.text == 'Principal Investigator'%} |
|
|
179 |
{% set kwargs['class_'] = kwargs['class_'] + ' chzn-select' %} |
|
|
180 |
<tr> |
|
|
181 |
<td></td> |
|
|
182 |
<td><b>Can't find the person you're looking for? <a href="#bot" onclick='$("#new_person_div").show(400); return false;'>Add a person</a></b></td> |
|
|
183 |
</tr> |
|
|
184 |
<tr> |
|
|
185 |
<td></td> |
|
|
186 |
<td> |
|
|
187 |
<div name="new_person_div" id="new_person_div"> |
|
|
188 |
<table> |
|
|
189 |
<tr> |
|
|
190 |
<td><b>Name:</b><br><font size=1>Names may only contain ASCII characters </font></td> |
|
|
191 |
<td><input type="text" id="new_person_name" name="new_person_name" class="form-control"></td> |
|
|
192 |
<td><h4> <font color="red">*</font></h4></td> |
|
|
193 |
</tr> |
|
|
194 |
<td><b>Affiliation:</b></td> |
|
|
195 |
<td><input type="text" id="new_person_affiliation" name="new_person_affiliation" class="form-control"></td> |
|
|
196 |
<td><h4> <font color="red">*</font></h4></td> |
|
|
197 |
</tr> |
|
|
198 |
<tr> |
|
|
199 |
<td><b>E-mail Address:</b></td> |
|
|
200 |
<td><input type="text" id="new_person_email" name="new_person_email" class="form-control"></td> |
|
|
201 |
<td><h4> <font color="red">*</font></h4></td> |
|
|
202 |
</tr> |
|
|
203 |
<tr> |
|
|
204 |
<td><b>Phone:</b></td> |
|
|
205 |
<td><input type="text" id="new_person_phone" name="new_person_phone" class="form-control"></td> |
|
|
206 |
</tr> |
|
|
207 |
<tr> |
|
|
208 |
<td><b>Address:</b></td> |
|
|
209 |
<td><input type="text" id="new_person_address" name="new_person_address" class="form-control"></td> |
|
|
210 |
</tr> |
|
|
211 |
<tr> |
|
|
212 |
<td> |
|
|
213 |
<table> |
|
|
214 |
<tr> |
|
|
215 |
<td><input value="Add Person" type="button" class="btn btn-link" onclick='add_new_person(create_study.new_person_name, create_study.new_person_affiliation, create_study.new_person_email, create_study.new_person_phone, create_study.new_person_address);'></td> |
|
|
216 |
<td><input value="Cancel" type="button" class="btn btn-link" onclick='$("#new_person_div").hide(400); return true;'></td> |
|
|
217 |
</tr> |
|
|
218 |
</table> |
|
|
219 |
</td> |
|
|
220 |
</tr> |
|
|
221 |
</table> |
|
|
222 |
</div> |
|
|
223 |
</td> |
|
|
224 |
{% elif form_item.label.text == 'Study Title'%} |
|
|
225 |
{% set additional_info = 'Study titles may only contain ASCII characters' %} |
|
|
226 |
{% end %} |
|
|
227 |
<tr> |
|
|
228 |
<td width="20%">{% raw form_item.label %} <br /> <small>{{additional_info}}</small></td> |
|
|
229 |
<td width="30%">{% raw form_item(**kwargs) %}</td> |
|
|
230 |
<td width="50%">{% if form_item.flags.required %}<font color="red"><h4> *</h4></font>{% end %}</td> |
|
|
231 |
</tr> |
|
|
232 |
{% end %} |
|
|
233 |
</tr> |
|
|
234 |
<tr> |
|
|
235 |
<td> |
|
|
236 |
<a name="bot"><input type='submit' id="create_study_submit" class='btn btn-success' value="{%if study%}Update{%else%}Create{%end%} Study"> |
|
|
237 |
{%if study%} <input type='button' id="cancel_form" class='btn btn-default' value="Cancel" onclick="cancel_edition()">{%end%} |
|
|
238 |
</td> |
|
|
239 |
</tr> |
|
|
240 |
</table> |
|
|
241 |
</form> |
|
|
242 |
{% end %} |