@ -103,18 +103,10 @@
<select name="profile" id="profile">
<option value="">Do not use profile</option>
</select>
</li>
<li>
<label for="profile_name">Profile name</label>
<input type="text" id="profile_name" name="profile_name" />
<div class="hint">When you select a profile it pre-fills your form with profile values.</div>
<div class="hint">Later you can modify your form and that's what matters on import.</div>
</li>
</ol>
<fieldset class="action">
<button id="add_profile" disabled>Add profile</button>
<button id="mod_profile" disabled>Update profile</button>
<button id="del_profile" disabled>Remove profile</button>
</fieldset>
</fieldset>
<form method="post" id="processfile" action="[% SCRIPT_NAME | html %]" enctype="multipart/form-data">
@ -216,7 +208,12 @@
</li>
</ol>
</fieldset>
<fieldset class="action"><input type="button" id="mainformsubmit" value="Stage for import" /></fieldset>
<fieldset class="action">
<input type="button" id="mainformsubmit" value="Stage for import" />
<button id="add_profile" disabled>Save profile</button>
<input type="text" id="profile_name" name="profile_name" placeholder="Profile name"/>
<button id="del_profile" disabled>Remove profile</button>
</fieldset>
<div id="jobpanel"><div id="jobstatus" class="progress_panel">Job progress: <div id="jobprogress"></div> <span id="jobprogresspercent">0</span>%</div>
<div id="jobfailed"></div></div>
@ -241,6 +238,8 @@
[% Asset.js("js/file-upload.js") | $raw %]
<script>
var xhr;
var PROFILE_SAVE_MSG = _("Profile saved");
var PROFILE_DEL_MSG = _("Profile deleted");
$(document).ready(function(){
$("#processfile").hide();
$('#profile_fieldset').hide();
@ -298,10 +297,10 @@
$("#profile_name").keyup(function(){
$("#add_profile").prop("disabled", this.value.trim()=='');
$("#mod_profile").prop("disabled", this.value.trim()=='' || !$("#profile").val())
});
$("#add_profile").click(function() {
$("#add_profile").click(function(event) {
event.preventDefault();
var name = $("#profile_name").val().trim();
if(!name) {
alert(_("Profile must have a name"));
@ -317,7 +316,7 @@
});
if(profile.length) {
if(!confirm(_("There is another profile with this name.")+"\n\n"+_("Do you want to replace it ?"))) {
if(!confirm(_("There is another profile with this name.")+"\n\n"+_("Do you want to update it with new values ?"))) {
return;
}
}
@ -340,7 +339,7 @@
if(profile.length) {
$.ajax({
url: "/api/v1/import-batch- profiles/"+profile[0].profile_id,
url: "/api/v1/import_batch_ profiles/"+profile[0].profile_id,
method: "PUT",
data: JSON.stringify(params),
contentType: 'application/json'
@ -349,7 +348,7 @@
.fail(reject);
} else {
$.ajax({
url: "/api/v1/import-batch- profiles/",
url: "/api/v1/import_batch_ profiles/",
method: "POST",
data: JSON.stringify(params),
contentType: 'application/json'
@ -359,6 +358,7 @@
}
})
.then(function(profile) {
humanMsg.displayAlert(PROFILE_SAVE_MSG);
return getProfiles(profile.profile_id);
})
.catch(function(error) {
@ -366,70 +366,8 @@
})
});
$("#mod_profile").click(function() {
var name = $("#profile_name").val().trim();
var id = $("#profile").val();
if(!id) return;
if(!name) {
alert(_("Profile must have a name"));
return;
}
var profile = $("#profile option[value!='']")
.map(function() {
return $(this).data('profile');
})
.filter(function() {
return this.name == name && this.profile_id != id;
});
if(profile.length) {
if(!confirm(_("There is another profile with this name.")+"\n\n"+_("Do you want to replace it?"))) {
return;
}
}
new Promise(function(resolve, reject) {
if(!profile.length) return resolve();
$.ajax({
url: "/api/v1/import-batch-profiles/"+profile[0].profile_id,
method: "DELETE"
})
.done(resolve)
.fail(reject);
})
.then(function(){
const params = {
comments: $("#comments").val() || null,
record_type: $("#record_type").val() || null,
encoding: $("#encoding").val() || null,
format: $("#format").val() || null,
template_id: $("#marc_modification_template_id").val() || null,
matcher_id: $("#matcher").val() || null,
overlay_action: $("#overlay_action").val() || null,
nomatch_action: $("#nomatch_action").val() || null,
parse_items: !!parseInt($("input[name='parse_items']:checked").val()) || null,
item_action: $("#item_action").val() || null,
name: name
};
return new Promise(function(resolve, reject) {
$.ajax({
url: "/api/v1/import-batch-profiles/"+id,
method: "PUT",
data: JSON.stringify(params),
contentType: 'application/json'
})
.done(resolve)
.fail(reject);
});
})
.then(function() {
return getProfiles(id);
})
.catch(function(error) {
alert(_("An error occurred")+"\n\n"+error.message);
})
});
$("#del_profile").click(function() {
$("#del_profile").click(function(event) {
event.preventDefault();
var id = $("#profile").val();
if(!id) return;
if(!confirm(_("Are you sure you want to delete this profile?"))) {
@ -437,21 +375,22 @@
}
new Promise(function(resolve, reject) {
$.ajax({
url: "/api/v1/import-batch- profiles/"+id,
url: "/api/v1/import_batch_ profiles/"+id,
method: "DELETE"
})
.done(resolve)
.fail(reject);
})
.then(function() {
humanMsg.displayAlert(PROFILE_DEL_MSG);
return getProfiles();
})
.catch(function(error) {
alert(_("An error occurred")+"\n\n"+error);
})
});
});
function CheckForm(f) {
if ($("#fileToUpload").value == '') {
alert(_("Please upload a file first."));
@ -510,7 +449,7 @@
const select = $("#profile");
$("option[value!='']", select).remove();
return new Promise(function(resolve, reject) {
$.ajax("/api/v1/import-batch- profiles")
$.ajax("/api/v1/import_batch_ profiles")
.then(resolve, reject);
})
.then(function(profiles) {