-
Notifications
You must be signed in to change notification settings - Fork 1
/
template.html
221 lines (209 loc) · 9.77 KB
/
template.html
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<div class="row">
<!-- Success and Error Messages for the user -->
<div class="span6 offset2" style="height:50px">
<div id="success" class="alert alert-success" style="display:none;">
<a class="close">×</a>
<strong>Well done!</strong> Your answer has been saved
</div>
<div id="loading" class="alert alert-info" style="display:none;">
<a class="close">×</a>
Loading next task...
</div>
<div id="taskcompleted" class="alert alert-info" style="display:none;">
<strong>The task has been completed!</strong> Thanks a lot!
</div>
<div id="finish" class="alert alert-success" style="display:none;">
<strong>Congratulations!</strong> You have participated in all available tasks!
<br/>
<div class="alert-actions">
<a class="btn small" href="/">Go back</a>
<a class="btn small" href="/app">or, Check other applications</a>
</div>
</div>
<div id="error" class="alert alert-error" style="display:none;">
<a class="close">×</a>
<strong>Error!</strong> Something went wrong, please contact the site administrators
</div>
</div> <!-- End Success and Error Messages for the user -->
</div> <!-- End of Row -->
<!--
Task DOM for loading the message that needs to be translated
It uses the class="skeleton" to identify the elements that belong to the
task.
-->
<div class="row skeleton"> <!-- Start Skeleton Row-->
<div class="span12 "><!-- Start of Question and Submission DIV (column) -->
<h1 id="question">Question</h1> <!-- The question will be loaded here -->
<div class="row-fluid">
<div class="span6">
<div id="msg" class="well" dir="rtl"></div>
<!-- Feedback items for the user -->
<p>You have translated: <span id="done" class="label label-info"></span> messages from
<!-- Progress bar for the user -->
<span id="total" class="label label-inverse"></span></p>
<div class="progress progress-striped">
<div id="progress" rel="tooltip" title="#" class="bar" style="width: 0%;"></div>
</div>
</div>
<div class="span6">
<div id="step1">
<textarea id="EngTranslation" class="input-block-level" style="height:100px;" placeholder="Type here the English translation"></textarea>
<div id="answer"> <!-- Start DIV for the submission buttons -->
<form id="types">
<label class="checkbox">
<input type="checkbox" value="more_than_one_sentence"></input>
<i class="icon-plus"></i> Has more than one sentence?
</label>
<label>
<input type="checkbox" value="privacy"></input>
<i class="icon-eye-open"></i> Contains personal identifying information?
</label>
<label>
<input type="checkbox" value="location_info"></input>
<i class="icon-globe"></i> Contains location information?
</label>
</form>
<br/>
<!-- If the user clicks this button, the saved answer will be value="yes"-->
<button class="btn btn-success btn-answer" value="translated"><i class="icon icon-white icon-thumbs-up"></i> Message Translated, go to next step</button>
<!-- If the user clicks this button, the saved answer will be value="no"-->
<button class="btn btn-danger btn-answer" value="spam"><i class="icon icon-white icon-thumbs-down"></i> Spam or irrelevant</button>
</div><!-- End of DIV for the submission buttons -->
</div>
<div id="step2" style="display:none;">
<input id="arabicLocation" type="text" placeholder="Type the location in Arabic"/>
<input id="englishLocation" type="text" placeholder="Type the location in English"/>
<div id="answer"> <!-- Start DIV for the submission buttons -->
<!-- If the user clicks this button, the saved answer will be value="yes"-->
<button class="btn btn-success btn-answer" value="submit"><i class="icon icon-white icon-thumbs-up"></i> Save Translation and Location</button>
</div><!-- End of DIV for the submission buttons -->
</div>
</div>
</div>
</div>
</div>
<script>
function loadUserProgress() {
pybossa.userProgress('translate').done(function(data){
var pct = Math.round((data.done*100)/data.total);
$("#progress").css("width", pct.toString() +"%");
$("#progress").attr("title", pct.toString() + "% completed!");
$("#progress").tooltip({'placement': 'left'});
$("#total").text(data.total);
$("#done").text(data.done);
});
}
pybossa.taskLoaded(function(task, deferred) {
if ( !$.isEmptyObject(task) ) {
// Create the candidate answer
task.info.answer = {'task_id': task.id,
'arabic': 'None',
'english': 'spam',
'arabicLocation': 'None',
'englishLocation': 'None',
'more_than_one_sentence': 0,
'privacy_issues': 0,
'location_info': 0};
// load message from task
var msg = $('<p/>');
var header = "<h2>Date: " + task.info.msg_date + "<br/>Subject: " + task.info.msg_subject + "</h2><hr>";
var all_html = '';
var all_text = '';
msg.attr("dir", "rtl");
// continue as soon as the message is loaded
if (task.info.msgs_html) {
for (var i=0;i<task.info.msgs_html.length;i++) {
all_html += task.info.msgs_html[i];
}
//msg.text(task.info.all_html);
task.info.answer.arabic = all_html;
}
if (task.info.msgs_text) {
for (var i=0;i<task.info.msgs_text.length;i++) {
all_text += task.info.msgs_text[i];
}
//msg.text(all_text);
task.info.answer.arabic = all_text;
if ((all_html != '') && (all_text != '')) {
msg.html(header + "<h2>HTML version</h2><hr>" + all_html + "<br/><h2>Plain Text Version</h2><hr>" + all_text);
}
if ((all_html != '') && (all_text == '')) {
msg.html(header + "<h2>HTML version</h2><hr>" + all_html);
}
if ((all_html == '') && (all_text != '')) {
msg.html(header + "<h2>Plain Text Version</h2><hr>" + all_text);
}
}
deferred.resolve(task);
//msg.addClass('lead');
task.info.msg = msg;
}
else {
deferred.resolve(task);
}
});
pybossa.presentTask(function(task, deferred) {
if ( !$.isEmptyObject(task) ) {
loadUserProgress();
$('#msg').html('').append(task.info.msg);
$("#step1").show();
$("#step2").hide();
$('#EngTranslation').val("");
$('#arabicLocation').val("");
$('#englishLocation').val("");
$("input:checkbox").removeAttr("checked");
$("#question").html(task.info.question);
$('.btn-answer').off('click').on('click', function(evt) {
var answer = $(evt.target).attr("value");
if (typeof answer != 'undefined') {
//console.log(answer);
if (answer == 'translated') {
$("#types :checked").each(
function() {
if ($(this).val() == 'more_than_one_sentence') {
task.info.answer.more_than_one_sentence = 1;
}
if ($(this).val() == 'privacy') {
task.info.answer.privacy_issues = 1;
}
if ($(this).val() == 'location_info') {
task.info.answer.location_info = 1;
}
});
if ($("#EngTranslation").val()) {
task.info.answer.english = $("#EngTranslation").val();
$("#step1").hide();
$("#step2").show();
$("#question").html("Please, Copy and Paste the location, if any, in Arabic and English");
}
else {
alert("Please, translate the message or click in the Spam button if the message is spam");
return;
}
}
if ((answer == 'submit') || (answer == 'spam')){
task.info.answer.arabicLocation = $("#arabicLocation").val();
task.info.answer.englishLocation = $("#englishLocation").val();
pybossa.saveTask(task.id, task.info.answer).done(function() {
deferred.resolve();
});
$("#loading").fadeIn(500);
}
}
else {
$("#error").show();
}
});
$("#loading").hide();
}
else {
$(".skeleton").hide();
$("#loading").hide();
$("#finish").fadeIn(500);
}
btn_one_sentence = 0;
btn_personal_info = 0;
btn_loc_info = 0;
});
pybossa.run('translate');
</script>