Skip to content

Commit

Permalink
Issue #1: Add a stub plugin structure for YAML configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Cohen Arazi <[email protected]>
  • Loading branch information
tomascohen committed Oct 17, 2019
1 parent 5c051fd commit 74d01f1
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
87 changes: 87 additions & 0 deletions Koha/Plugin/Org/KC/ILL/Koha.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package Koha::Plugin::Org::KC::ILL::Koha;

# This program 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.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program comes with ABSOLUTELY NO WARRANTY;

use Modern::Perl;

use base qw(Koha::Plugins::Base);

use Mojo::JSON qw(decode_json);
use YAML;

our $VERSION = "{VERSION}";

our $metadata = {
name => 'ILL plugin Koha <->Koha',
author => 'Koha Community',
date_authored => '2018-09-10',
date_updated => "2019-10-02",
minimum_version => '18.05',
maximum_version => undef,
version => $VERSION,
description => 'ILL plugin Koha <->Koha'
};

sub new {
my ( $class, $args ) = @_;

$args->{'metadata'} = $metadata;
$args->{'metadata'}->{'class'} = $class;

my $self = $class->SUPER::new($args);

return $self;
}

sub configure {
my ( $self, $args ) = @_;
my $cgi = $self->{'cgi'};

my $template = $self->get_template({ file => 'configure.tt' });

unless ( scalar $cgi->param('save') ) {

## Grab the values we already have for our settings, if any exist
$template->param(
configuration => $self->retrieve_data('configuration'),
);

$self->output_html( $template->output() );
}
else {
$self->store_data(
{
configuration => scalar $cgi->param('configuration'),
}
);
$template->param(
configuration => $self->retrieve_data('configuration'),
);
$self->output_html( $template->output() );
}
}

sub configuration {
my ($self) = @_;

my $configuration;
eval { $configuration = YAML::Load( $self->retrieve_data('configuration') . "\n\n" ); };
die($@) if $@;

return $configuration;
}

1;
40 changes: 40 additions & 0 deletions Koha/Plugin/Org/KC/ILL/Koha/configure.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[% INCLUDE 'doc-head-open.inc' %]
<title>Koha &rsaquo; ILL plugin Koha &lt;-&gt; Koha &rsaquo; Configuration</title>
[% INCLUDE 'doc-head-close.inc' %]
</head>
<body>
[% INCLUDE 'header.inc' %]
[% INCLUDE 'cat-search.inc' %]

<div id="breadcrumbs">
<a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo;
<a href="?class=[% CLASS %]&method=configure">ILL plugin Koha &lt;-&gt; Koha</a> &rsaquo;
Configuration
</div>

<div id="doc3" class="yui-t2">
<div id="yui-main">
<h2>ILL plugin Koha &lt;-&gt; Koha</h2>
<br/>
<form method="post">
<input type="hidden" name="class" value="[% CLASS %]"/>
<input type="hidden" name="method" value="configure"/>
<input type="hidden" name="step" value="configure"/>
<input type="hidden" name="save" value="1"/>
<div class="input-group">
<span class="input-group-addon" id="configuration_label">Configuration</span>
<textarea rows="30"
columns="100"
class="form-control"
aria-describedby="configuration_label"
name="configuration" id="configuration">[%- configuration -%]</textarea>
</div>
<br/>
<button type="submit" value="Save" class="btn btn-default" type="button">Save</button>
</form>
</div>
<div class="yui-b">
<div id="navmenu">&nbsp;</div>
</div>

[% INCLUDE 'intranet-bottom.inc' %]

0 comments on commit 74d01f1

Please sign in to comment.