-
Notifications
You must be signed in to change notification settings - Fork 16
/
suggestions_and_journals.js
415 lines (351 loc) · 14.8 KB
/
suggestions_and_journals.js
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
jQuery(document).ready(function($) {
////// functions for handling edit locks ///////////////////////
function setLockTimeout() {
var ts = $("#lock_expires").attr("data-timestamp");
var d = new Date(ts);
var hours = d.getHours();
var minutes = d.getMinutes();
if (String(minutes).length == 1) { minutes = "0" + minutes }
var formatted = hours + ":" + minutes;
$("#lock_expires").html(formatted)
}
setLockTimeout();
function unlock(params) {
var type = params.type;
var id = params.id;
function success_callback(data) {
var newWindow = window.open('', '_self', ''); //open the current window
window.close();
}
function error_callback(jqXHR, textStatus, errorThrown) {
alert("error releasing lock: " + textStatus + " " + errorThrown)
}
$.ajax({
type: "POST",
url: "/service/unlock/" + type + "/" + id,
contentType: "application/json",
dataType: "json",
success : success_callback,
error: error_callback
})
}
$("#unlock").click(function(event) {
event.preventDefault();
var id = $(this).attr("data-id");
var type = $(this).attr("data-type");
unlock({type : type, id : id})
});
// NOTE: this does not play well with page reloads, so not using it
//$(window).unload(function() {
// var id = $("#unlock").attr("data-id")
// var type = $("#unlock").attr("data-type")
// unlock({type : type, id : id})
//});
////////////////////////////////////////////////////
////////////////////////////////////////////////////
// functions for diff table
$(".show_hide_diff_table").click(function(event) {
event.preventDefault();
var state = $(this).attr("data-state");
if (state == "hidden") {
$(".form_diff").slideDown();
$(this).html("hide").attr("data-state", "shown");
} else if (state === "shown") {
$(".form_diff").slideUp();
$(this).html("show").attr("data-state", "hidden");
}
});
///////////////////////////////////////////////////
///////////////////////////////////////////////////
// quick reject
function showCustomRejectNote() {
$("#custom_reject_reason").show();
}
function hideCustomRejectNote() {
$("#custom_reject_reason").hide();
}
$("#submit_quick_reject").on("click", function(event) {
if ($("#reject_reason").val() == "" && $("#additional_reject_information").val() == "") {
alert("When selecting 'Other' as a reason for rejection, you must provide additional information");
event.preventDefault();
}
});
///////////////////////////////////////////////////
// define a new highlight function, letting us highlight any element
// on a page
// adapted from http://stackoverflow.com/a/11589350
jQuery.fn.highlight = function(color, fade_time) {
// some defaults
var color = color || "#F68B1F"; // the DOAJ color
var fade_time = fade_time || 1500; // milliseconds
$(this).each(function() {
var el = $(this);
el.before("<div/>");
el.prev()
.width(el.width())
.height(el.height())
.css({
"position": "absolute",
"background-color": color,
"opacity": ".9"
})
.fadeOut(fade_time);
});
};
// animated scrolling to an anchor
jQuery.fn.anchorAnimate = function(settings) {
settings = jQuery.extend({
speed : 700
}, settings);
return this.each(function(){
var caller = this;
$(caller).click(function (event) {
event.preventDefault();
var locationHref = window.location.href;
var elementClick = $(caller).attr("href");
var destination = $(elementClick).offset().top;
$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
window.location.hash = elementClick; // ... but it also needs to be getting set here for the animation itself to work
});
setTimeout(function(){
highlight_target();
}, settings.speed + 50);
return false;
})
})
};
toggle_optional_field('waiver_policy', ['#waiver_policy_url']);
toggle_optional_field('download_statistics', ['#download_statistics_url']);
toggle_optional_field('plagiarism_screening', ['#plagiarism_screening_url']);
toggle_optional_field('publishing_rights', ['#publishing_rights_url'], ["True"]);
toggle_optional_field('copyright', ['#copyright_url'], ["True"]);
toggle_optional_field('license_embedded', ['#license_embedded_url']);
toggle_optional_field('processing_charges', ['#processing_charges_amount', '#processing_charges_currency']);
toggle_optional_field('submission_charges', ['#submission_charges_amount', '#submission_charges_currency']);
toggle_optional_field('license', ['#license_checkbox'], ["Other"]);
$('#country').select2({allowClear: true});
$('#processing_charges_currency').select2({allowClear: true});
$('#submission_charges_currency').select2({allowClear: true});
$("#keywords").select2({
minimumInputLength: 1,
tags: [],
tokenSeparators: [","],
maximumSelectionSize: 6
});
$("#languages").select2({allowClear: true});
autocomplete('#publisher', 'bibjson.publisher.name');
autocomplete('#society_institution', 'bibjson.institution.name');
autocomplete('#owner', 'id', 'account');
autocomplete('#editor_group', 'name', 'editor_group', 1, false);
exclusive_checkbox('digital_archiving_policy', 'No policy in place');
exclusive_checkbox('article_identifiers', 'None');
exclusive_checkbox('deposit_policy', 'None');
if ("onhashchange" in window) {
window.onhashchange = highlight_target();
$('a.animated').anchorAnimate();
}
setup_subject_tree();
if (typeof(notes_editable) !== 'undefined' && notes_editable === false) { // set by template
$('#add_note_btn').hide()
} else {
setup_remove_buttons();
setup_add_buttons();
}
$("#editor_group").change(function(event) {
event.preventDefault();
$("#editor").html("<option val='' selected='selected'></option>")
});
$(".application_journal_form").on("submit", function(event) {
$(".save-record").attr("disabled", "disabled");
});
});
function setup_subject_tree() {
$(function () {
$('#subject_tree').jstree({
'plugins':["checkbox","sort","search"],
'core' : {
'data' : lcc_jstree
},
"checkbox" : {
"three_state" : false
},
"search" : {
"fuzzy" : false,
"show_only_matches" : true
}
});
});
$('#subject_tree')
.on('ready.jstree', function (e, data) {
var subjects = $('#subject').val() || [];
for (var i = 0; i < subjects.length; i++) {
$('#subject_tree').jstree('select_node', subjects[i]);
}
});
$('#subject_tree')
.on('changed.jstree', function (e, data) {
var subjects = $('#subject').val(data.selected);
});
$('#subject_tree_container').prepend('<div class="form-group" id="subject_tree_search-container">\
<label class="control-label col-xs-3" for="subject_tree_search">Search through the subjects</label>\
<div class="col-xs-9">\
<input class="input-large" id="subject_tree_search" type="text" placeholder="start typing...">\
<p class="help-block">Selecting a subject will <strong>not automatically select its sub-categories</strong>.</p>\
</div>\
</div>');
var to = false;
$('#subject_tree_search').keyup(function () {
if(to) { clearTimeout(to); }
to = setTimeout(function () {
var v = $('#subject_tree_search').val();
$('#subject_tree').jstree(true).search(v);
}, 750);
});
// Previously the superseded container was completely hidden, but we want to show its errors, so hide its children.
//$('#subject-container').hide();
$('#subject-container').find("label").hide();
$('#subject-container').find("#subject").hide();
$('#subject-container').css('margin-bottom', 0);
}
function exclusive_checkbox(field_name, exclusive_val) {
var doit = function() {
if (this.checked) {
$('#' + field_name + ' :checkbox:not([value="' + exclusive_val + '"])').prop('disabled', true);
$('#' + field_name + ' .extra_input_field').prop('disabled', true);
} else {
$('#' + field_name + ' :checkbox:not([value="' + exclusive_val + '"])').prop('disabled', false);
$('#' + field_name + ' .extra_input_field').prop('disabled', false);
}
};
$('#' + field_name + ' :checkbox[value="' + exclusive_val + '"]').each(doit); // on page load too
$('#' + field_name + ' :checkbox[value="' + exclusive_val + '"]').change(doit); // when exclusive checkbox ticked
}
function highlight_target() {
$(window.location.hash).highlight()
}
function setup_add_buttons() {
var customisations = {
// by container element id - container of the add more button and the fields being added
'notes-outer-container': {'value': 'Add new note', 'id': 'add_note_btn'}
};
$('.addable-field-container').each(function() {
var e = $(this);
var id = e.attr('id');
var value = customisations[id]['value'] || 'Add';
var thebtn = '<button class="btn btn-info add_button"';
thebtn += ' value="' + value + '"';
if (customisations[id]['id']) {
thebtn += ' id="' + customisations[id]['id'] + '"';
}
thebtn += ' style="margin-bottom: 20px;">' + value + '</button>';
e.prepend(thebtn);
});
setup_add_button_handlers();
}
function setup_add_button_handlers() {
// this isn't as generic as the other functions - each button has to
// have its own click handler defined here for it to work
var add_note_btn = function (event) {
event.preventDefault();
if (typeof cur_number_of_notes == 'undefined') {
cur_number_of_notes = 0; // yes, global
$('[id^=notes-][id$="-container"]').each(function(){
cur_number_of_notes += 1; // it doesn't have to be sequential or exact or anything like that,
// it just needs to be DIFFERENT for every note
// so count the number of notes already on the page
});
}
// FIXME: this is a duplicate of what the jinja template does, meaning we have 2 places
// where we need to update it if it changes. Should clone a similar element instead.
var delclass = "";
if (notes_deletable) { // global variable set by template
delclass = " deletable "
}
var thefield = '<div class="form-group ' + delclass + '" id="notes-' + cur_number_of_notes + '-container">\
<div class="col-xs-8 nested-field-container">\
<div class="col-xs-12 ">\
<textarea class=" col-xs-12" id="notes-' + cur_number_of_notes + '-note" name="notes-' + cur_number_of_notes + '-note"></textarea>\
</div>\
</div>\
<div class="col-xs-3 nested-field-container">\
<div class="col-xs-12 ">\
<input class=" col-xs-12" disabled="" id="notes-' + cur_number_of_notes + '-date" name="notes-' + cur_number_of_notes + '-date" type="text" value="">\
</div>\
</div>\
<div class="col-xs-1">\
<button id="remove_notes-' + cur_number_of_notes + '-container" target="notes-' + cur_number_of_notes + '-container" class="btn btn-danger remove_button">\
<i class="glyphicon glyphicon-remove"></i>\
</button>\
</div>\
</div>';
cur_number_of_notes += 1; // this doesn't get decremented in the remove button because there's no point, WTForms will understand it
// even if the ID-s go 0, 2, 7, 13 etc.
$(this).after(thefield);
if (notes_deletable) {
setup_remove_buttons();
}
};
var button_handlers = {
// by button element id
'add_note_btn': add_note_btn
};
for (var button_id in button_handlers) {
$('#' + button_id).unbind('click');
$('#' + button_id).click(button_handlers[button_id]);
}
}
function setup_remove_buttons() {
$('.deletable').each(function() {
var e = $(this);
var id = e.attr('id');
if(e.find('button[id="remove_'+id+'"]').length == 0) {
e.append('<div class="col-xs-1"><button id="remove_'+id+'" target="'+id+'" class="btn btn-danger remove_button"><i class="glyphicon glyphicon-remove"></i></button></div>');
}
setup_remove_button_handler();
});
}
function setup_remove_button_handler() {
$(".remove_button").unbind("click");
$(".remove_button").click( function(event) {
event.preventDefault();
var toremove = $(this).attr('target');
$('#' + toremove).remove();
});
}
/*
Permits Managing Editors to assign editors on the Application and Journal edit forms.
*/
function load_eds_in_group(ed_query_url) {
var ed_group_name = $("#s2id_editor_group").find('span').text();
$.ajax({
type : "GET",
data : {egn : ed_group_name},
dataType: "json",
url: ed_query_url,
success: function(resp)
{
// Get the options for the drop-down from our ajax request
var assoc_options = [];
if (resp != null)
{
assoc_options = [["", "Choose an editor"]];
for (var i=0; i<resp.length; i++)
{
assoc_options = assoc_options.concat([[resp[i], resp[i]]]);
}
}
else
{
assoc_options = [["", ""]];
}
// Set the editor drop-down options to be the chosen group's associates
var ed_field = $("#editor");
ed_field.empty();
for (var j=0; j < assoc_options.length; j++) {
ed_field.append(
$("<option></option>").attr("value", assoc_options[j][0]).text(assoc_options[j][1])
);
}
}
})
}