Bug 32030: Max document file size - client-side validation
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
b563544200
commit
ebeb7e6161
4 changed files with 49 additions and 1 deletions
|
@ -35,8 +35,11 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
|
|||
}
|
||||
);
|
||||
|
||||
my $max_allowed_packet = C4::Context->dbh->selectrow_array(q{SELECT @@max_allowed_packet});
|
||||
|
||||
$template->param(
|
||||
vendors => Koha::Acquisition::Booksellers->search,
|
||||
max_allowed_packet => $max_allowed_packet,
|
||||
);
|
||||
|
||||
output_html_with_http_headers $input, $cookie, $template->output;
|
||||
|
|
|
@ -54,6 +54,8 @@
|
|||
const ERMProviders = "[% Koha.Preference('ERMProviders') | html %]";
|
||||
const erm_providers = ERMProviders.split(',');
|
||||
|
||||
const max_allowed_packet = [% To.json(max_allowed_packet) | $raw %];
|
||||
|
||||
const ERMModule = [% IF Koha.Preference('ERMModule') %]true[% ELSE %]false[% END %];
|
||||
|
||||
const logged_in_user_lists = [% To.json(logged_in_user.virtualshelves.unblessed) | $raw %];
|
||||
|
|
|
@ -217,6 +217,7 @@ export default {
|
|||
av_agreement_license_statuses,
|
||||
av_agreement_license_location,
|
||||
av_agreement_relationships,
|
||||
max_allowed_packet,
|
||||
}
|
||||
},
|
||||
data() {
|
||||
|
@ -300,6 +301,20 @@ export default {
|
|||
errors.push(this.$__("Only one controlling license is allowed"))
|
||||
}
|
||||
|
||||
let documents_with_uploaded_files = agreement.documents.filter(
|
||||
doc => typeof doc.file_content !== "undefined"
|
||||
)
|
||||
if (
|
||||
documents_with_uploaded_files.filter(
|
||||
doc => atob(doc.file_content).length >= max_allowed_packet
|
||||
).length >= 1
|
||||
) {
|
||||
errors.push(
|
||||
this.$__("File size exceeds maximum allowed: %s MB").format(
|
||||
(max_allowed_packet / (1024 * 1024)).toFixed(2)
|
||||
)
|
||||
)
|
||||
}
|
||||
errors.forEach(function (e) {
|
||||
setWarning(e)
|
||||
})
|
||||
|
|
|
@ -143,7 +143,7 @@
|
|||
import { inject } from "vue"
|
||||
import flatPickr from "vue-flatpickr-component"
|
||||
import Documents from "./Documents.vue"
|
||||
import { setMessage, setError } from "../../messages"
|
||||
import { setMessage, setError, setWarning } from "../../messages"
|
||||
import { fetchLicense } from "../../fetch"
|
||||
import { storeToRefs } from "pinia"
|
||||
|
||||
|
@ -159,6 +159,7 @@ export default {
|
|||
vendors,
|
||||
av_license_types,
|
||||
av_license_statuses,
|
||||
max_allowed_packet,
|
||||
}
|
||||
},
|
||||
data() {
|
||||
|
@ -193,10 +194,37 @@ export default {
|
|||
this.license = license
|
||||
this.initialized = true
|
||||
},
|
||||
checkForm(license) {
|
||||
let errors = []
|
||||
|
||||
let documents_with_uploaded_files = license.documents.filter(
|
||||
doc => typeof doc.file_content !== "undefined"
|
||||
)
|
||||
if (
|
||||
documents_with_uploaded_files.filter(
|
||||
doc => atob(doc.file_content).length >= max_allowed_packet
|
||||
).length >= 1
|
||||
) {
|
||||
errors.push(
|
||||
this.$__("File size exceeds maximum allowed: %s MB").format(
|
||||
(max_allowed_packet / (1024 * 1024)).toFixed(2)
|
||||
)
|
||||
)
|
||||
}
|
||||
errors.forEach(function (e) {
|
||||
setWarning(e)
|
||||
})
|
||||
return !errors.length
|
||||
},
|
||||
onSubmit(e) {
|
||||
e.preventDefault()
|
||||
|
||||
let license = JSON.parse(JSON.stringify(this.license)) // copy
|
||||
|
||||
if (!this.checkForm(license)) {
|
||||
return false
|
||||
}
|
||||
|
||||
let apiUrl = "/api/v1/erm/licenses"
|
||||
|
||||
let method = "POST"
|
||||
|
|
Loading…
Reference in a new issue