Lines 95-105
Link Here
|
95 |
</div> |
95 |
</div> |
96 |
</form> |
96 |
</form> |
97 |
|
97 |
|
|
|
98 |
<fieldset class="rows" id="profile_fieldset"> |
99 |
<legend>Profile settings</legend> |
100 |
<ol> |
101 |
<li> |
102 |
<label for="profile">Pre fill values with profile</label> |
103 |
<select name="profile" id="profile"> |
104 |
<option value="">Do not use profile</option> |
105 |
</select> |
106 |
</li> |
107 |
<li> |
108 |
<label for="profile_name">Profile name</label> |
109 |
<input type="text" id="profile_name" name="profile_name" /> |
110 |
|
111 |
</li> |
112 |
</ol> |
113 |
<fieldset class="action"> |
114 |
<button id="add_profile" disabled>Add profile</button> |
115 |
<button id="mod_profile" disabled>Update profile</button> |
116 |
<button id="del_profile" disabled>Remove profile</button> |
117 |
</fieldset> |
118 |
</fieldset> |
119 |
|
98 |
<form method="post" id="processfile" action="[% SCRIPT_NAME | html %]" enctype="multipart/form-data"> |
120 |
<form method="post" id="processfile" action="[% SCRIPT_NAME | html %]" enctype="multipart/form-data"> |
99 |
[% IF basketno && booksellerid %] |
121 |
[% IF basketno && booksellerid %] |
100 |
<input type="hidden" name="basketno" id="basketno" value="[% basketno | html %]" /> |
122 |
<input type="hidden" name="basketno" id="basketno" value="[% basketno | html %]" /> |
101 |
<input type="hidden" name="booksellerid" id="booksellerid" value="[% booksellerid | html %]" /> |
123 |
<input type="hidden" name="booksellerid" id="booksellerid" value="[% booksellerid | html %]" /> |
102 |
[% END %] |
124 |
[% END %] |
|
|
125 |
<input type="hidden" name="profile_id" id="profile_id"/> |
103 |
<fieldset class="rows"> |
126 |
<fieldset class="rows"> |
104 |
<input type="hidden" name="uploadedfileid" id="uploadedfileid" value="" /> |
127 |
<input type="hidden" name="uploadedfileid" id="uploadedfileid" value="" /> |
105 |
<input type="hidden" name="runinbackground" id="runinbackground" value="" /> |
128 |
<input type="hidden" name="runinbackground" id="runinbackground" value="" /> |
Lines 220-225
Link Here
|
220 |
var xhr; |
243 |
var xhr; |
221 |
$(document).ready(function(){ |
244 |
$(document).ready(function(){ |
222 |
$("#processfile").hide(); |
245 |
$("#processfile").hide(); |
|
|
246 |
$('#profile_fieldset').hide(); |
223 |
$("#record_type").change(function() { |
247 |
$("#record_type").change(function() { |
224 |
if ($(this).val() == 'auth') { |
248 |
if ($(this).val() == 'auth') { |
225 |
$('#items').hide(); |
249 |
$('#items').hide(); |
Lines 238-243
Link Here
|
238 |
$("#mainformsubmit").on("click",function(){ |
262 |
$("#mainformsubmit").on("click",function(){ |
239 |
return CheckForm( document.getElementById("processfile")); |
263 |
return CheckForm( document.getElementById("processfile")); |
240 |
}); |
264 |
}); |
|
|
265 |
getProfiles(); |
266 |
$('#profile').change(function(){ |
267 |
if(this.value=='') { |
268 |
$("#mod_profile, #del_profile").prop("disabled",true); |
269 |
$("#comments").val(""); |
270 |
$("#record_type").val('biblio').change(); |
271 |
$("#encoding").val('UTF-8').change(); |
272 |
$("#format").val('ISO2709').change(); |
273 |
$("#marc_modification_template_id").val("").change(); |
274 |
$("#matcher").val("").change(); |
275 |
$("#overlay_action").val('replace').change(); |
276 |
$("#nomatch_action").val('create_new').change(); |
277 |
$("#parse_itemsyes").prop("checked", true).change(); |
278 |
$("#item_action").val('always_add').change(); |
279 |
$("#profile_name").val('').keyup(); |
280 |
} else { |
281 |
const profile = $('option:selected', this).data('profile'); |
282 |
$("#profile_id").val(profile.id); |
283 |
$("#mod_profile, #del_profile").prop("disabled", null); |
284 |
$("#comments").val(profile.comments); |
285 |
$("#record_type").val(profile.record_type).change(); |
286 |
$("#encoding").val(profile.encoding).change(); |
287 |
$("#format").val(profile.format).change(); |
288 |
$("#marc_modification_template_id").val(profile.template_id).change(); |
289 |
$("#matcher").val(profile.matcher_id).change(); |
290 |
$("#overlay_action").val(profile.overlay_action).change(); |
291 |
$("#nomatch_action").val(profile.nomatch_action).change(); |
292 |
$("input[name='parse_items'][value='"+(profile.parse_items?'1':'0')+"']").prop("checked", true).change(); |
293 |
$("#item_action").val(profile.item_action).change(); |
294 |
$("#profile_name").val(profile.name).keyup(); |
295 |
} |
296 |
}); |
297 |
|
298 |
$("#profile_name").keyup(function(){ |
299 |
$("#add_profile").prop("disabled", this.value.trim()==''); |
300 |
$("#mod_profile").prop("disabled", this.value.trim()=='' || !$("#profile").val()) |
301 |
}); |
302 |
|
303 |
$("#add_profile").click(function() { |
304 |
var name = $("#profile_name").val().trim(); |
305 |
if(!name) { |
306 |
alert(_("Profile must have a name")); |
307 |
return; |
308 |
} |
309 |
|
310 |
var profile = $("#profile option[value!='']") |
311 |
.map(function() { |
312 |
return $(this).data('profile'); |
313 |
}) |
314 |
.filter(function() { |
315 |
return this.name == name; |
316 |
}); |
317 |
|
318 |
if(profile.length) { |
319 |
if(!confirm(_("There is another profile with this name.")+"\n\n"+_("Do you want to replace it?"))) { |
320 |
return; |
321 |
} |
322 |
} |
323 |
|
324 |
new Promise(function(resolve, reject) { |
325 |
|
326 |
const params = { |
327 |
comments: $("#comments").val() || null, |
328 |
record_type: $("#record_type").val() || null, |
329 |
encoding: $("#encoding").val() || null, |
330 |
format: $("#format").val() || null, |
331 |
template_id: $("#marc_modification_template_id").val() || null, |
332 |
matcher_id: $("#matcher").val() || null, |
333 |
overlay_action: $("#overlay_action").val() || null, |
334 |
nomatch_action: $("#nomatch_action").val() || null, |
335 |
parse_items: !!$("input[name='parse_items']:checked").val() || null, |
336 |
item_action: $("#item_action").val() || null, |
337 |
name: name |
338 |
}; |
339 |
|
340 |
if(profile.length) { |
341 |
$.ajax({ |
342 |
url: "/api/v1/import-batch-profiles/"+profile[0].id, |
343 |
method: "PUT", |
344 |
data: JSON.stringify(params), |
345 |
contentType: 'application/json' |
346 |
}) |
347 |
.done(resolve) |
348 |
.fail(reject); |
349 |
} else { |
350 |
$.ajax({ |
351 |
url: "/api/v1/import-batch-profiles/", |
352 |
method: "POST", |
353 |
data: JSON.stringify(params), |
354 |
contentType: 'application/json' |
355 |
}) |
356 |
.done(resolve) |
357 |
.fail(reject); |
358 |
} |
359 |
}) |
360 |
.then(function(profile) { |
361 |
return getProfiles(profile.id); |
362 |
}) |
363 |
.catch(function(error) { |
364 |
alert(_("An error occurred")+"\n\n"+error); |
365 |
}) |
366 |
}); |
367 |
|
368 |
$("#mod_profile").click(function() { |
369 |
var name = $("#profile_name").val().trim(); |
370 |
var id = $("#profile").val(); |
371 |
if(!id) return; |
372 |
if(!name) { |
373 |
alert(_("Profile must have a name")); |
374 |
return; |
375 |
} |
376 |
var profile = $("#profile option[value!='']") |
377 |
.map(function() { |
378 |
return $(this).data('profile'); |
379 |
}) |
380 |
.filter(function() { |
381 |
return this.name == name && this.id != id; |
382 |
}); |
383 |
|
384 |
if(profile.length) { |
385 |
if(!confirm(_("There is another profile with this name.")+"\n\n"+_("Do you want to replace it?"))) { |
386 |
return; |
387 |
} |
388 |
} |
389 |
new Promise(function(resolve, reject) { |
390 |
if(!profile.length) return resolve(); |
391 |
$.ajax({ |
392 |
url: "/api/v1/import-batch-profiles/"+profile[0].id, |
393 |
method: "DELETE" |
394 |
}) |
395 |
.done(resolve) |
396 |
.fail(reject); |
397 |
}) |
398 |
.then(function(){ |
399 |
const params = { |
400 |
comments: $("#comments").val() || null, |
401 |
record_type: $("#record_type").val() || null, |
402 |
encoding: $("#encoding").val() || null, |
403 |
format: $("#format").val() || null, |
404 |
template_id: $("#marc_modification_template_id").val() || null, |
405 |
matcher_id: $("#matcher").val() || null, |
406 |
overlay_action: $("#overlay_action").val() || null, |
407 |
nomatch_action: $("#nomatch_action").val() || null, |
408 |
parse_items: !!$("input[name='parse_items']:checked").val() || null, |
409 |
item_action: $("#item_action").val() || null, |
410 |
name: name |
411 |
}; |
412 |
return new Promise(function(resolve, reject) { |
413 |
$.ajax({ |
414 |
url: "/api/v1/import-batch-profiles/"+id, |
415 |
method: "PUT", |
416 |
data: JSON.stringify(params), |
417 |
contentType: 'application/json' |
418 |
}) |
419 |
.done(resolve) |
420 |
.fail(reject); |
421 |
}); |
422 |
}) |
423 |
.then(function() { |
424 |
return getProfiles(id); |
425 |
}) |
426 |
.catch(function(error) { |
427 |
alert(_("An error occurred")+"\n\n"+error.message); |
428 |
}) |
429 |
}); |
430 |
|
431 |
$("#del_profile").click(function() { |
432 |
var id = $("#profile").val(); |
433 |
if(!id) return; |
434 |
if(!confirm(_("Are you sure you want to delete this profile?"))) { |
435 |
return; |
436 |
} |
437 |
new Promise(function(resolve, reject) { |
438 |
$.ajax({ |
439 |
url: "/api/v1/import-batch-profiles/"+id, |
440 |
method: "DELETE" |
441 |
}) |
442 |
.done(resolve) |
443 |
.fail(reject); |
444 |
}) |
445 |
.then(function() { |
446 |
return getProfiles(); |
447 |
}) |
448 |
.catch(function(error) { |
449 |
alert(_("An error occurred")+"\n\n"+error); |
450 |
}) |
451 |
}); |
452 |
|
241 |
}); |
453 |
}); |
242 |
function CheckForm(f) { |
454 |
function CheckForm(f) { |
243 |
if ($("#fileToUpload").value == '') { |
455 |
if ($("#fileToUpload").value == '') { |
Lines 252-257
Link Here
|
252 |
$('#fileuploadbutton').hide(); |
464 |
$('#fileuploadbutton').hide(); |
253 |
$("#fileuploadfailed").hide(); |
465 |
$("#fileuploadfailed").hide(); |
254 |
$("#processfile").hide(); |
466 |
$("#processfile").hide(); |
|
|
467 |
$('#profile_fieldset').hide(); |
255 |
$("#fileuploadstatus").show(); |
468 |
$("#fileuploadstatus").show(); |
256 |
$("#uploadedfileid").val(''); |
469 |
$("#uploadedfileid").val(''); |
257 |
xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), 'temp=1', cbUpload ); |
470 |
xhr= AjaxUpload( $('#fileToUpload'), $('#fileuploadprogress'), 'temp=1', cbUpload ); |
Lines 277-282
Link Here
|
277 |
$('#format').val('MARCXML'); |
490 |
$('#format').val('MARCXML'); |
278 |
} |
491 |
} |
279 |
$("#processfile").show(); |
492 |
$("#processfile").show(); |
|
|
493 |
$('#profile_fieldset').show(); |
280 |
} else { |
494 |
} else { |
281 |
var errMsgs = [ _("Error code 0 not used"), _("File already exists"), _("Directory is not writeable"), _("Root directory for uploads not defined"), _("Temporary directory for uploads not defined") ]; |
495 |
var errMsgs = [ _("Error code 0 not used"), _("File already exists"), _("Directory is not writeable"), _("Root directory for uploads not defined"), _("Temporary directory for uploads not defined") ]; |
282 |
var errCode = errors[$('#fileToUpload').prop('files')[0].name].code; |
496 |
var errCode = errors[$('#fileToUpload').prop('files')[0].name].code; |
Lines 290-295
Link Here
|
290 |
); |
504 |
); |
291 |
} |
505 |
} |
292 |
} |
506 |
} |
|
|
507 |
|
508 |
function getProfiles(id) { |
509 |
const select = $("#profile"); |
510 |
$("option[value!='']", select).remove(); |
511 |
return new Promise(function(resolve, reject) { |
512 |
$.ajax("/api/v1/import-batch-profiles") |
513 |
.then(resolve, reject); |
514 |
}) |
515 |
.then(function(profiles) { |
516 |
profiles.forEach(function(profile) { |
517 |
const opt = $("<option/>"); |
518 |
select.append(opt); |
519 |
if(id && profile.id == id) { |
520 |
opt.prop('selected', true); |
521 |
} |
522 |
opt.attr("value", profile.id); |
523 |
opt.html(profile.name); |
524 |
opt.data("profile", profile); |
525 |
}); |
526 |
}) |
527 |
.then(function(){ |
528 |
select.change(); |
529 |
}); |
530 |
} |
531 |
|
532 |
|
293 |
</script> |
533 |
</script> |
294 |
[% END %] |
534 |
[% END %] |
295 |
|
535 |
|