View | Details | Raw Unified | Return to bug 10855
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/add_fields.tt (+178 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Serials &rsaquo; Manage new fields for subscriptions
3
  [% IF op == "list" %] &rsaquo; List of fields
4
  [% ELSIF op == "add_form" %]
5
    [% IF field %] &rsaquo; Modify field
6
    [% ELSE %] &rsaquo; Add field
7
    [% END %]
8
  [% END %]
9
</title>
10
[% INCLUDE 'doc-head-close.inc' %]
11
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
12
<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.dataTables.min.js"></script>
13
[% INCLUDE 'datatables-strings.inc' %]
14
<script type="text/javascript" src="[% themelang %]/js/datatables.js"></script>
15
<script type="text/javascript">
16
//<![CDATA[
17
  $(document).ready(function(){
18
19
    $("#fieldst").dataTable($.extend(true, {}, dataTablesDefaults, {
20
        'bAutoWidth': false,
21
        'sDom': 't<"bottom pager"ilpf>',
22
        'sPaginationType': 'four_button',
23
        'aLengthMenu': [[10, 20, 50, 100, -1], [10, 20, 50, 100, "All"]],
24
        'iDisplayLength': 20,
25
        'aaSorting': [[ 0, "asc" ]],
26
    }));
27
28
    $(".confirmdelete").click(function(){
29
      return confirm(_("Are you sure you want to delete this field?"));
30
    });
31
32
    $("#add_field").on('submit', function(){
33
        if ( $("#marcfield").val().length > 0
34
            && $("select[name='authorised_value_category']" ).val().length > 0 ) {
35
            alert("You cannot select an authorised value category and a marcfield");
36
            return false;
37
        }
38
        return true;
39
    });
40
  });
41
//]]>
42
</script>
43
</head>
44
45
<body id="ser_add_fields" class="ser">
46
  [% INCLUDE 'header.inc' %]
47
  [% INCLUDE 'serials-search.inc' %]
48
49
  <div id="breadcrumbs">
50
    <a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/serials/serials-home.pl">Serials</a> &rsaquo; Manage new fields for subscriptions
51
  </div>
52
53
  <div id="doc3" class="yui-t2">
54
  <div id="bd">
55
  <div id="yui-main">
56
  <div class="yui-b">
57
  [% IF op == 'list' %]
58
    <div id="toolbar" class="btn-toolbar">
59
      <a class="btn btn-small" id="newfields" href="/cgi-bin/koha/serials/add_fields.pl?op=add_form"><i class="icon-plus"></i> New fields</a>
60
    </div>
61
  [% END %]
62
63
  [% IF messages %]
64
    [% FOR message IN messages %]
65
      [% IF message.code == 'insert' %]
66
        [% IF message.number > 0 %]
67
          <div class="dialog message">The field has been inserted</div>
68
        [% ELSE %]
69
          <div class="dialog alert">The field has not been inserted (name still exist?)</div>
70
        [% END %]
71
      [% ELSIF message.code == 'update' %]
72
        [% IF message.number > 0 %]
73
          <div class="dialog message">The field has been updated</div>
74
        [% ELSE %]
75
          <div class="dialog alert">The field has not been updated (name still exist?)</div>
76
        [% END %]
77
      [% ELSIF message.code == 'delete' %]
78
        [% IF message.number > 0 %]
79
          <div class="dialog message">The field has been deleted</div>
80
        [% ELSE %]
81
          <div class="dialog alert">The field has not been deleted</div>
82
        [% END %]
83
      [% END %]
84
    [% END %]
85
  [% END %]
86
87
  [% IF op == 'list' %]
88
    <h3>Additional fields for subscriptions</h3>
89
    [% IF fields %]
90
      <table id="fieldst">
91
        <thead>
92
          <tr>
93
            <th>Name</th>
94
            <th>Authorised value category</th>
95
            <th>Marc field</th>
96
            <th>Searchable</th>
97
            <th>Actions</th>
98
          </tr>
99
        </thead>
100
        <tbody>
101
          [% FOR field IN fields %]
102
            <tr>
103
              <td>[% field.name %]</td>
104
              <td>[% field.authorised_value_category %]</td>
105
              <td>[% field.marcfield %]</td>
106
              <td>
107
                [% IF field.searchable %]Yes[% ELSE %]No[% END %]
108
              </td>
109
              <td>
110
                <a href="/cgi-bin/koha/serials/add_fields.pl?op=add_form&amp;field_id=[% field.id %]" title="Edit this field">Edit</a>
111
                <a class="confirmdelete" href="/cgi-bin/koha/serials/add_fields.pl?op=delete&amp;field_id=[% field.id %]" title="Delete this field">Delete</a>
112
              </td>
113
            </tr>
114
          [% END %]
115
        </tbody>
116
      </table>
117
    [% ELSE %]
118
      There is no field defined.
119
    [% END %]
120
  [% ELSIF op == 'add_form' %]
121
    [% IF field %]
122
      <h3>Modify field</h3>
123
    [% ELSE %]
124
      <h3>Add field</h3>
125
    [% END %]
126
    <form action="/cgi-bin/koha/serials/add_fields.pl" name="add_form" id="add_field" method="post">
127
      <fieldset class="rows">
128
        <ol>
129
          <li>
130
            <label for="name" class="required">Name: </label>
131
            <input type="text" name="name" id="name" value="[% field.name | html %]" />
132
          </li>
133
          <li>
134
            <label for="av">Authorised value category: </label>
135
            <select name="authorised_value_category">
136
              <option value="">None</option>
137
              [% FOR category IN categories %]
138
                [% IF field.authorised_value_category == category %]
139
                  <option value="[% category %]" selected="selected">[% category %]</option>
140
                [% ELSE %]
141
                  <option value="[% category %]">[% category %]</option>
142
                [% END %]
143
              [% END %]
144
            </select>
145
          </li>
146
          <li>
147
            <label for="marcfield">Marc field: </label>
148
            <input type="text" name="marcfield" id="marcfield" value="[% field.marcfield| html %]" />
149
          </li>
150
          <li>
151
            <label for="searchable">Searchable: </label>
152
            [% IF field.searchable %]
153
              <input type="checkbox" name="searchable" id="searchable" checked="checked" />
154
            [% ELSE %]
155
              <input type="checkbox" name="searchable" id="searchable" />
156
            [% END %]
157
          </li>
158
        </ol>
159
      </fieldset>
160
      <fieldset class="action">
161
        [% IF field %]
162
          <input type="hidden" name="field_id" value="[% field.id %]" />
163
        [% END %]
164
        <input type="hidden" name="op" value="add" />
165
        <input type="submit" value="Save" />
166
        <a href="/cgi-bin/koha/serials/add_fields.pl" class="cancel">Cancel</a>
167
      </fieldset>
168
    </form>
169
  [% END %]
170
171
  </div>
172
  </div>
173
174
<div class="yui-b">
175
[% INCLUDE 'serials-menu.inc' %]
176
</div>
177
</div>
178
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/serials/add_fields.pl (-1 / +126 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Copyright 2013 BibLibre
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, see <http://www.gnu.org/licenses>.
18
19
use Modern::Perl;
20
use CGI;
21
use C4::Auth;
22
use C4::Koha;
23
use C4::Output;
24
use Koha::AdditionalField;
25
26
my $input = new CGI;
27
28
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
29
    {
30
        template_name   => "serials/add_fields.tt",
31
        query           => $input,
32
        type            => "intranet",
33
        authnotrequired => 0,
34
        flagsrequired   => { serials => '*' },
35
        debug           => 1,
36
    }
37
);
38
39
my $op = $input->param('op') // 'list';
40
my $field_id = $input->param('field_id');
41
my @messages;
42
43
if ( $op eq 'add' ) {
44
    my $name = $input->param('name') // q{};
45
    my $authorised_value_category = $input->param('authorised_value_category') // q{};
46
    my $marcfield = $input->param('marcfield') // q{};
47
    my $searchable = $input->param('searchable') ? 1 : 0;
48
    if ( $field_id and $name ) {
49
        my $updated = 0;
50
        eval {
51
            my $af = Koha::AdditionalField->new({
52
                id => $field_id,
53
                name => $name,
54
                authorised_value_category => $authorised_value_category,
55
                marcfield => $marcfield,
56
                searchable => $searchable,
57
            });
58
            $updated = $af->update;
59
        };
60
        push @messages, {
61
            code => 'update',
62
            number => $updated,
63
        };
64
    } elsif ( $name ) {
65
        my $inserted = 0;
66
        eval {
67
            my $af = Koha::AdditionalField->new({
68
                tablename => 'subscription',
69
                name => $name,
70
                authorised_value_category => $authorised_value_category,
71
                marcfield => $marcfield,
72
                searchable => $searchable,
73
            });
74
            $inserted = $af->insert;
75
        };
76
        push @messages, {
77
            code => 'insert',
78
            number => $inserted,
79
        };
80
    } else {
81
        push @messages, {
82
            code => 'insert',
83
            number => 0,
84
        };
85
    }
86
    $op = 'list';
87
}
88
89
if ( $op eq 'delete' ) {
90
    my $deleted = 0;
91
    eval {
92
        my $af = Koha::AdditionalField->new( { id => $field_id } );
93
        $deleted = $af->delete;
94
        $deleted = 0 if $deleted eq '0E0';
95
    };
96
    push @messages, {
97
        code => 'delete',
98
        number => $deleted,
99
    };
100
    $op = 'list';
101
}
102
103
if ( $op eq 'add_form' ) {
104
    my $categories = C4::Koha::GetAuthorisedValueCategories();
105
    my $field;
106
    if ( $field_id ) {
107
        $field = Koha::AdditionalField->new( { id => $field_id } )->fetch;
108
    }
109
110
    $template->param(
111
        field => $field,
112
        categories => $categories,
113
    );
114
}
115
116
if ( $op eq 'list' ) {
117
    my $fields = Koha::AdditionalField->all( { tablename => 'subscription' } );
118
    $template->param( fields => $fields );
119
}
120
121
$template->param(
122
    op => $op,
123
    messages => \@messages,
124
);
125
126
output_html_with_http_headers $input, $cookie, $template->output;

Return to bug 10855