use base qw(Koha::Object);
-use Koha::ERM::Packages;
-use Koha::Acquisition::Booksellers;
+use Koha::ERM::EHolding::Packages;
=head1 NAME
=head2 Class Methods
+=head3 eholding_packages
+
+Returns the eholding_packages link for this eHolding
+
+=cut
+
+sub eholding_packages {
+ my ( $self, $eholding_packages ) = @_;
+
+ if ( $eholding_packages ) {
+ my $schema = $self->_result->result_source->schema;
+ $schema->txn_do(
+ sub {
+ $self->eholding_packages->delete;
+
+ for my $eholding_package (@$eholding_packages) {
+ $self->_result->add_to_erm_eholdings_packages($eholding_package);
+ }
+ }
+ );
+ }
+ my $eholding_packages_rs = $self->_result->erm_eholdings_packages;
+ return Koha::ERM::EHolding::Packages->_new_from_dbic($eholding_packages_rs);
+}
+
=head2 Internal methods
=head3 _type
--- /dev/null
+package Koha::ERM::EHolding::Package;
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
+
+use Koha::Database;
+
+use Koha::ERM::Package;
+
+use base qw(Koha::Object);
+
+=head1 NAME
+
+Koha::ERM::EHolding::Package - Koha EHolding Package Object class
+
+=head1 API
+
+=head2 Class Methods
+
+=cut
+
+=head3 package
+
+Return the package for this link
+
+=cut
+
+sub package {
+ my ( $self ) = @_;
+ my $package_rs = $self->_result->package;
+ return Koha::ERM::Package->_new_from_dbic($package_rs);
+}
+
+=head2 Internal methods
+
+=head3 _type
+
+=cut
+
+sub _type {
+ return 'ErmEholdingsPackage';
+}
+
+1;
--- /dev/null
+package Koha::ERM::EHolding::Packages;
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
+
+
+use Koha::Database;
+
+use Koha::ERM::EHolding::Package;
+
+use base qw(Koha::Objects);
+
+=head1 NAME
+
+Koha::ERM::EHolding::Packages- Koha EHolding EHolding Object set class
+
+=head1 API
+
+=head2 Class Methods
+
+=cut
+
+=head3 type
+
+=cut
+
+sub _type {
+ return 'ErmEholdingsPackage';
+}
+
+sub object_class {
+ return 'Koha::ERM::EHolding::Package';
+}
+
+1;
my $body = $c->validation->param('body');
+ my $eholding_packages = delete $body->{eholding_packages} // [];
+
my $eholding = Koha::ERM::EHolding->new_from_api($body)->store;
+ $eholding->eholding_packages($eholding_packages);
+
$c->res->headers->location($c->req->url->to_string . '/' . $eholding->eholding_id);
return $c->render(
status => 201,
my $body = $c->validation->param('body');
+ my $eholding_packages = delete $body->{eholding_packages} // [];
+
$eholding->set_from_api($body)->store;
+ $eholding->eholding_packages($eholding_packages);
+
$c->res->headers->location($c->req->url->to_string . '/' . $eholding->eholding_id);
return $c->render(
status => 200,
type:
- string
- "null"
+ eholding_packages:
+ type: array
+ description: packages containing this title
+ items:
+ $ref: erm_eholding_package.yaml
additionalProperties: false
required:
--- /dev/null
+---
+type: object
+properties:
+ eholding_id:
+ type: integer
+ description: Internal related eHolding identifier
+ package_id:
+ type: integer
+ description: Internal package identifier
+ started_on:
+ description: Start date
+ type:
+ - string
+ - "null"
+ ended_on:
+ description: End date
+ type:
+ - string
+ - "null"
+ proxy:
+ description: Proxy
+ type:
+ - string
+ - "null"
+additionalProperties: false
+required:
+ - package_id
permissions:
erm: 1
x-koha-embed:
- - agreements
+ - eholding_packages
+ - eholding_packages.package
put:
x-mojo-to: ERM::EHoldings#update
operationId: updateErmEHoldings
permissions:
erm: 1
x-koha-embed:
- - agreements
+ - eholding_packages
+ - eholding_packages.package
delete:
x-mojo-to: ERM::EHoldings#delete
operationId: deleteErmEHoldings
--- /dev/null
+<template>
+ <fieldset class="rows" id="eholding_packages">
+ <legend>{{ $t("Packages") }}</legend>
+ <fieldset
+ class="rows"
+ v-for="(eholding_package, counter) in eholding_packages"
+ v-bind:key="counter"
+ >
+ <legend>
+ {{ $t("Package.counter", { counter: counter + 1 }) }}
+ <a href="#" @click.prevent="deletePackage(counter)"
+ ><i class="fa fa-trash"></i>
+ {{ $t("Remove from this package") }}</a
+ >
+ </legend>
+ <ol>
+ <li>
+ <label
+ :for="`eholding_package_id_${counter}`"
+ class="required"
+ >{{ $t("Package:") }}
+ </label>
+ <select
+ v-model="eholding_package.package_id"
+ :id="`eholding_package_id_${counter}`"
+ required
+ >
+ <option value=""></option>
+ <option
+ v-for="p in packages"
+ :key="p.package_id"
+ :value="p.package_id"
+ :selected="
+ p.package_id == eholding_package.package_id
+ ? true
+ : false
+ "
+ >
+ {{ p.name }}
+ </option>
+ </select>
+ <span class="required">{{ $t("Required") }}</span>
+ </li>
+ <li>
+ <label :for="`started_on_${counter}`"
+ >{{ $t("Start date:") }}
+ </label>
+ <flat-pickr
+ :id="`started_on_${counter}`"
+ v-model="eholding_package.started_on"
+ :config="fp_config"
+ :data-date_to="`ended_on_${counter}`"
+ />
+ </li>
+ <li>
+ <label :for="`ended_on_${counter}`">{{
+ $t("End date:")
+ }}</label>
+ <flat-pickr
+ :id="`ended_on_${counter}`"
+ v-model="eholding_package.ended_on"
+ :config="fp_config"
+ />
+ </li>
+ <li>
+ <label :for="`${counter}`">{{ $t("Proxy:") }}</label>
+ <input
+ :id="`proxy_${counter}`"
+ v-model="eholding_package.proxy"
+ :placeholder="$t('Proxy')"
+ />
+ </li>
+ </ol>
+ </fieldset>
+ <a v-if="packages.length" class="btn btn-default" @click="addPackage"
+ ><font-awesome-icon icon="plus" />
+ {{ $t("Add to another package") }}</a
+ >
+ <span v-else>{{ $t("There are no packages created yet") }}</span>
+ </fieldset>
+</template>
+
+<script>
+import flatPickr from 'vue-flatpickr-component'
+import { fetchPackages } from "../../fetch"
+
+export default {
+ data() {
+ return {
+ packages: [],
+ fp_config: flatpickr_defaults,
+ dates_fixed: 0,
+ }
+ },
+ beforeCreate() {
+ fetchPackages().then((packages) => this.packages = packages)
+ },
+ methods: {
+ addPackage() {
+ this.eholding_packages.push({
+ package_id: null,
+ started_on: null,
+ ended_on: null,
+ proxy: '',
+ })
+ },
+ deletePackage(counter) {
+ this.eholding_packages.splice(counter, 1)
+ },
+ },
+ props: {
+ eholding_packages: Array,
+ },
+ components: { flatPickr },
+ name: 'EHoldingPackages',
+}
+</script>
:placeholder="$t('Access type')"
/>
</li>
+
+ <EHoldingPackages
+ :eholding_packages="eholding.eholding_packages"
+ />
</ol>
</fieldset>
<fieldset class="action">
</template>
<script>
+import EHoldingPackages from "./EHoldingPackages.vue"
import { setMessage, setError } from "../../messages"
import { fetchEHolding } from '../../fetch'
parent_publication_title_id: '',
preceeding_publication_title_id: '',
access_type: '',
+ eholding_packages: [],
},
initialized: false,
}
}).catch(e => { console.log(e) })
},
},
+ components: { EHoldingPackages },
name: "EHoldingsFormAdd",
}
</script>
if (!eholding_id) return;
const apiUrl = "/api/v1/erm/eholdings/" + eholding_id;
let erm_eholding;
- await fetch(apiUrl)
+ await fetch(apiUrl, {
+ headers: {
+ "x-koha-embed": "eholding_packages,eholding_packages.package",
+ },
+ })
.then(checkError)
.then(
(result) => {