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

(-)a/cataloguing/additem.pl (-25 / +102 lines)
Lines 22-60 Link Here
22
use Modern::Perl;
22
use Modern::Perl;
23
23
24
use CGI qw ( -utf8 );
24
use CGI qw ( -utf8 );
25
25
use C4::Auth qw( get_template_and_user haspermission );
26
use C4::Auth qw( get_template_and_user haspermission );
26
use C4::Output qw( output_and_exit_if_error output_and_exit output_html_with_http_headers );
27
use C4::Biblio qw(
28
    GetFrameworkCode
29
    GetMarcFromKohaField
30
    GetMarcStructure
31
    IsMarcStructureInternal
32
    ModBiblio
33
);
34
use C4::Context;
35
use C4::Circulation qw( barcodedecode LostItem );
36
use C4::Barcodes;
37
use C4::Barcodes::ValueBuilder;
27
use C4::Barcodes::ValueBuilder;
28
use C4::Barcodes;
29
use C4::Biblio qw( GetFrameworkCode GetMarcFromKohaField GetMarcStructure IsMarcStructureInternal ModBiblio );
30
use C4::Circulation qw( barcodedecode LostItem );
31
use C4::Context;
32
use C4::Members;
33
use C4::Output qw( output_and_exit_if_error output_and_exit output_html_with_http_headers );
34
use C4::Search qw( enabled_staff_search_views );
38
use Koha::Biblios;
35
use Koha::Biblios;
39
use Koha::Items;
36
use Koha::Item::Templates;
40
use Koha::ItemTypes;
37
use Koha::ItemTypes;
41
use Koha::Items;
38
use Koha::Items;
39
use Koha::Items;
42
use Koha::Libraries;
40
use Koha::Libraries;
43
use Koha::Patrons;
41
use Koha::Patrons;
44
use Koha::SearchEngine::Indexer;
42
use Koha::SearchEngine::Indexer;
45
use C4::Search qw( enabled_staff_search_views );
46
use Storable qw( freeze thaw );
47
use URI::Escape qw( uri_escape_utf8 );
48
use C4::Members;
49
use Koha::UI::Form::Builder::Item;
43
use Koha::UI::Form::Builder::Item;
50
use Koha::Result::Boolean;
44
use Koha::Result::Boolean;
51
45
52
use MARC::File::XML;
53
use URI::Escape qw( uri_escape_utf8 );
54
use Encode qw( encode_utf8 );
46
use Encode qw( encode_utf8 );
55
use MIME::Base64 qw( decode_base64url encode_base64url );
56
use List::Util qw( first );
57
use List::MoreUtils qw( any uniq );
47
use List::MoreUtils qw( any uniq );
48
use List::Util qw( first );
49
use MARC::File::XML;
50
use MIME::Base64 qw( decode_base64url encode_base64url );
51
use Storable qw( freeze thaw );
52
use URI::Escape qw( uri_escape_utf8 );
53
use URI::Escape qw( uri_escape_utf8 );
58
54
59
our $dbh = C4::Context->dbh;
55
our $dbh = C4::Context->dbh;
60
56
Lines 86-91 sub add_item_to_item_group { Link Here
86
    )->store();
82
    )->store();
87
}
83
}
88
84
85
sub get_item_from_template {
86
    my ( $template_id ) = @_;
87
88
    my $template = Koha::Item::Templates->find($template_id);
89
90
    return $template->decoded_contents if $template;
91
}
92
89
sub get_item_from_cookie {
93
sub get_item_from_cookie {
90
    my ( $input ) = @_;
94
    my ( $input ) = @_;
91
95
Lines 175-186 my @errors; # store errors found while checking data BEFORE saving item. Link Here
175
# Getting last created item cookie
179
# Getting last created item cookie
176
my $prefillitem = C4::Context->preference('PrefillItem');
180
my $prefillitem = C4::Context->preference('PrefillItem');
177
181
182
my $load_template_submit = $input->param('load_template_submit');
183
my $delete_template_submit = $input->param('delete_template_submit');
184
my $unload_template_submit = $input->param('unload_template_submit');
185
my $use_template_for_session = $input->param('use_template_for_session') || $input->cookie('ItemEditorSessionTemplateId');
186
my $template_id = $input->param('template_id') || $input->cookie('ItemEditorSessionTemplateId');
187
if ( $delete_template_submit ) {
188
    my $t = Koha::Item::Templates->find($template_id);
189
    $t->delete if $t && $t->borrowernumber eq $loggedinuser;
190
    $template_id = undef;
191
    $use_template_for_session = undef;
192
}
193
if ($load_template_submit || $unload_template_submit) {
194
    $op = q{} if $template_id;
195
196
    $template_id = undef if !$input->param('template_id');
197
    $template_id = undef if $unload_template_submit;
198
199
    # Unset the cookie if either no template id as submitted, or "use for session" checkbox as unchecked
200
    my $cookie_value = $input->param('use_template_for_session') && $template_id ? $template_id : q{};
201
    $use_template_for_session = $cookie_value;
202
203
    # Update the cookie
204
    my $template_cookie = $input->cookie(
205
        -name     => 'ItemEditorSessionTemplateId',
206
        -value    => $cookie_value,
207
        -HttpOnly => 1,
208
        -expires  => '',
209
        -sameSite => 'Lax'
210
    );
211
212
    $cookie = [ $cookie, $template_cookie ];
213
}
214
$template->param(
215
    template_id    => $template_id,
216
    item_templates => Koha::Item::Templates->get_available($loggedinuser),
217
    use_template_for_session => $use_template_for_session,
218
);
219
178
#-------------------------------------------------------------------------------
220
#-------------------------------------------------------------------------------
179
if ($op eq "additem") {
221
if ($op eq "additem") {
180
222
181
    my $add_submit                 = $input->param('add_submit');
223
    my $add_submit                 = $input->param('add_submit');
182
    my $add_duplicate_submit       = $input->param('add_duplicate_submit');
224
    my $add_duplicate_submit       = $input->param('add_duplicate_submit');
183
    my $add_multiple_copies_submit = $input->param('add_multiple_copies_submit');
225
    my $add_multiple_copies_submit = $input->param('add_multiple_copies_submit');
226
    my $save_as_template_submit    = $input->param('save_as_template_submit');
184
    my $number_of_copies           = $input->param('number_of_copies');
227
    my $number_of_copies           = $input->param('number_of_copies');
185
228
186
    my @columns = Koha::Items->columns;
229
    my @columns = Koha::Items->columns;
Lines 226-233 if ($op eq "additem") { Link Here
226
269
227
    $item->barcode(barcodedecode($item->barcode));
270
    $item->barcode(barcodedecode($item->barcode));
228
271
272
    if ($save_as_template_submit) {
273
        my $template_name       = $input->param('template_name');
274
        my $template_is_shared  = $input->param('template_is_shared');
275
        my $replace_template_id = $input->param('replace_template_id');
276
277
        if ($replace_template_id) {
278
            my $template = Koha::Item::Templates->find($replace_template_id);
279
            if ($template) {
280
                $template->update(
281
                    {
282
                        id             => $replace_template_id,
283
                        is_shared      => $template_is_shared ? 1 : 0,
284
                        contents       => $item->unblessed,
285
                    }
286
                );
287
            }
288
        }
289
        else {
290
            my $template = Koha::Item::Template->new(
291
                {
292
                    name           => $template_name,
293
                    borrowernumber => $loggedinuser,
294
                    is_shared      => $template_is_shared ? 1 : 0,
295
                    contents       => $item->unblessed,
296
                }
297
            )->store();
298
        }
299
    }
229
    # If we have to add or add & duplicate, we add the item
300
    # If we have to add or add & duplicate, we add the item
230
    if ( $add_submit || $add_duplicate_submit || $prefillitem) {
301
    elsif ( $add_submit || $add_duplicate_submit || $prefillitem) {
231
302
232
        # check for item barcode # being unique
303
        # check for item barcode # being unique
233
        if ( defined $item->barcode
304
        if ( defined $item->barcode
Lines 591-603 my @header_value_loop = map { Link Here
591
} sort keys %$subfieldcode_attribute_mappings;
662
} sort keys %$subfieldcode_attribute_mappings;
592
663
593
# Using last created item if it exists
664
# Using last created item if it exists
594
if (   $prefillitem
665
if (
595
    && $op ne "additem"
666
    $op ne "additem"
596
    && $op ne "edititem"
667
    && $op ne "edititem"
597
    && $op ne "dupeitem" )
668
    && $op ne "dupeitem" )
598
{
669
{
599
    my $item_from_cookie = get_item_from_cookie($input);
670
    if ( $template_id ) {
600
    $current_item = $item_from_cookie if $item_from_cookie;
671
        my $item_from_template = get_item_from_template($template_id);
672
        $current_item = $item_from_template if $item_from_template;
673
    }
674
    elsif ( $prefillitem ) {
675
        my $item_from_cookie = get_item_from_cookie($input);
676
        $current_item = $item_from_cookie if $item_from_cookie;
677
    }
601
}
678
}
602
679
603
if ( $current_item->{more_subfields_xml} ) {
680
if ( $current_item->{more_subfields_xml} ) {
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/str/cataloging_additem.inc (+1 lines)
Lines 20-25 Link Here
20
    var MSG_CONFIRM_DELETE_ITEM = _("Are you sure you want to delete this item?");
20
    var MSG_CONFIRM_DELETE_ITEM = _("Are you sure you want to delete this item?");
21
    var MSG_CONFIRM_ADD_ITEM = _("Are you sure you want to add a new item? Any changes made on this page will be lost.");
21
    var MSG_CONFIRM_ADD_ITEM = _("Are you sure you want to add a new item? Any changes made on this page will be lost.");
22
    var MSG_CONFIRM_SAVE = _("Are you sure you want to save?");
22
    var MSG_CONFIRM_SAVE = _("Are you sure you want to save?");
23
    var MSG_TEMPLATE_NAME_REQUIRED = _("Template name is required.");
23
    var table_settings = [% TablesSettings.GetTableSettings( 'cataloguing', 'additem', 'itemst', 'json' ) | $raw %];
24
    var table_settings = [% TablesSettings.GetTableSettings( 'cataloguing', 'additem', 'itemst', 'json' ) | $raw %];
24
</script>
25
</script>
25
<!-- / str/cataloging_additem.inc -->
26
<!-- / str/cataloging_additem.inc -->
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt (+67 lines)
Lines 162-167 Link Here
162
    [% ELSE %]
162
    [% ELSE %]
163
        <h2 id="edititem">Edit item #[% itemnumber | html %][% IF ( barcode ) %] / Barcode [% barcode | html %][% END %]</h2>
163
        <h2 id="edititem">Edit item #[% itemnumber | html %][% IF ( barcode ) %] / Barcode [% barcode | html %][% END %]</h2>
164
    [% END %]
164
    [% END %]
165
166
    <div id="item-template-toolbar" class="btn-toolbar">
167
        <select name="template_id" id="template_id" class="select2" style="width: 20em">
168
            <option value="0" selected="selected">Do not use template</option>
169
            <optgroup label="My templates">
170
                [% FOREACH t IN item_templates.owned %]
171
                    [% IF t.id == template_id %]
172
                        <option data-owner="1" value="[% t.id | html %]" selected="selected">[% t.name | html %][% IF t.is_shared %] (shared)[% END %]</option>
173
                    [% ELSE %]
174
                        <option data-owner="1" value="[% t.id | html %]">[% t.name | html %][% IF t.is_shared %] (shared)[% END %]</option>
175
                    [% END %]
176
                [% END %]
177
            </optgroup>
178
            <optgroup label="Shared templates">
179
                [% FOREACH t IN item_templates.shared %]
180
                    [% IF t.id == template_id %]
181
                        <option data-owner="0" value="[% t.id | html %]" selected="selected">[% t.name | html %]</option>
182
                    [% ELSE %]
183
                        <option data-owner="0" value="[% t.id | html %]">[% t.name | html %]</option>
184
                    [% END %]
185
                [% END %]
186
            </optgroup>
187
        </select>
188
        <button type="submit" id="load_template_submit" name="load_template_submit" value="1"><i class="fa fa-wpforms"></i> Apply template</button>
189
        <label for="use_template_for_session">
190
            [% IF use_template_for_session %]
191
                <input type="checkbox" id="use_template_for_session" name="use_template_for_session" checked="checked">
192
            [% ELSE %]
193
                <input type="checkbox" id="use_template_for_session" name="use_template_for_session">
194
            [% END %]
195
        For session</label>
196
197
        <button type="submit" id="unload_template_submit" name="unload_template_submit" value="1"><i class="fa fa-eraser"></i> Clear template</button>
198
199
        <button type="submit" id="delete_template_submit" name="delete_template_submit" value="1" disabled><i class="fa fa-trash"></i> Delete template</button>
200
201
    </div>
202
165
	<fieldset class="rows">
203
	<fieldset class="rows">
166
        [% PROCESS subfields_for_item subfields => subfields %]
204
        [% PROCESS subfields_for_item subfields => subfields %]
167
    </fieldset>
205
    </fieldset>
Lines 218-223 Link Here
218
        <div class="hint"><p>The barcode you enter will be incremented for each additional item.</p></div>
256
        <div class="hint"><p>The barcode you enter will be incremented for each additional item.</p></div>
219
    </fieldset>
257
    </fieldset>
220
258
259
    <span id="savetemplate">
260
        <input type="button" name="save_as_template" id="save_as_template" value="Save as template" />
261
    </span>
262
    <fieldset id="save_as_template_span">
263
        <legend>Save template</legend>
264
        <select name="replace_template_id" id="replace_template_id" class="select2" style="width: 20em">
265
            <option value="0" selected="selected">Save as new</option>
266
            <optgroup label="Update existing">
267
                [% FOREACH t IN item_templates.owned %]
268
                    <option data-owner="1" value="[% t.id | html %]">[% t.name | html %][% IF t.is_shared %] (shared)[% END %]</option>
269
                [% END %]
270
            </optgroup>
271
        </select>
272
273
        <span id="template_name_block">
274
            <label for="template_name" class="required">Template name: </label>
275
            <input type="text" id="template_name" name="template_name" class="required"/>
276
            <span class="required">Required</span>
277
        </span>
278
279
        <label for="template_is_shared">
280
            <input type="checkbox" id="template_is_shared" name="template_is_shared"/>
281
            Share template
282
        </label>
283
284
        <input type="submit" id="save_as_template_submit" name="save_as_template_submit" value="Save" onclick="javascript:return CheckTemplateForm(this.form);" />
285
        <a href="#" id="cancel_save_as_template" class="cancel">Cancel</a>
286
    </fieldset>
287
221
    [% ELSE %]
288
    [% ELSE %]
222
    [% IF op != 'add_item' %]
289
    [% IF op != 'add_item' %]
223
        <input type="hidden" name="itemnumber" value="[% itemnumber | html %]" />
290
        <input type="hidden" name="itemnumber" value="[% itemnumber | html %]" />
(-)a/koha-tmpl/intranet-tmpl/prog/js/cataloging_additem.js (-1 / +40 lines)
Lines 69-74 $(document).ready(function(){ Link Here
69
        multiCopyControl.toggle();
69
        multiCopyControl.toggle();
70
    });
70
    });
71
71
72
    var saveAsTemplateControl = $("#save_as_template_span");
73
    var saveTemplateBlock = $("#savetemplate");
74
    saveAsTemplateControl.hide();
75
    $("#save_as_template").on("click",function(e){
76
        e.preventDefault;
77
        saveTemplateBlock.toggle();
78
        saveAsTemplateControl.toggle();
79
        $('#template_name').focus();
80
    });
81
    $("#cancel_save_as_template").on("click",function(e){
82
        e.preventDefault();
83
        saveTemplateBlock.toggle();
84
        saveAsTemplateControl.toggle();
85
    });
86
87
    $("#template_id").on("change", function() {
88
        if ( $(this).find(":selected").data("owner") ) {
89
            $("#delete_template_submit").removeAttr("disabled");
90
        } else {
91
            $("#delete_template_submit").attr("disabled", "disabled");
92
        }
93
    });
94
    $("#template_id").change(); // Trigger to enable delete button if patron's template is in use
95
    $("#replace_template_id").on("change", function() {
96
        if ( $(this).find(":selected").val() > 0 ) {
97
            $("#template_name_block").hide();
98
        } else {
99
            $("#template_name_block").show();
100
        }
101
    });
102
72
    // Add new item to an item group
103
    // Add new item to an item group
73
    if ( has_item_groups ) {
104
    if ( has_item_groups ) {
74
        $('#item-group-add-or-create-form-description-block').hide();
105
        $('#item-group-add-or-create-form-description-block').hide();
Lines 98-103 $(document).ready(function(){ Link Here
98
    });
129
    });
99
});
130
});
100
131
132
function CheckTemplateForm(f) {
133
    if ( $('#replace_template_id').val() == "0" &&  $('#template_name').val() == "" ) {
134
        alert(MSG_TEMPLATE_NAME_REQUIRED);
135
        return false;
136
    } else {
137
        return true;
138
    }
139
}
140
101
function Check(f) {
141
function Check(f) {
102
    var total_mandatory = CheckMandatorySubfields(f);
142
    var total_mandatory = CheckMandatorySubfields(f);
103
    var total_important = CheckImportantSubfields(f);
143
    var total_important = CheckImportantSubfields(f);
104
- 

Return to bug 24606