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

(-)a/Koha/ArticleRequest.pm (+4 lines)
Lines 268-273 sub store { Link Here
268
    if ( !$self->in_storage ) {
268
    if ( !$self->in_storage ) {
269
        $self->created_on( dt_from_string() );
269
        $self->created_on( dt_from_string() );
270
    }
270
    }
271
    my $format = $self->format;
272
    if ( C4::Context->preference('ArticleRequestsSupportedFormats') !~ /\b$format\b/ ) {
273
        Koha::Exceptions::ArticleRequest::WrongFormat->throw;
274
    }
271
275
272
    return $self->SUPER::store;
276
    return $self->SUPER::store;
273
}
277
}
(-)a/Koha/Exceptions/ArticleRequest.pm (+4 lines)
Lines 27-32 use Exception::Class ( Link Here
27
        isa         => 'Koha::Exceptions::ArticleRequest',
27
        isa         => 'Koha::Exceptions::ArticleRequest',
28
        description => 'Article request limit was reached'
28
        description => 'Article request limit was reached'
29
    },
29
    },
30
    'Koha::Exceptions::ArticleRequest::WrongFormat' => {
31
        isa         => 'Koha::Exceptions::ArticleRequest',
32
        description => 'Passed format is not locally supported'
33
    },
30
);
34
);
31
35
32
=head1 NAME
36
=head1 NAME
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-request-article.tt (-2 / +31 lines)
Lines 300-305 Link Here
300
                var first_format = supported_formats.split('|')[0].replace(/^\s*|\s*$/g, '');
300
                var first_format = supported_formats.split('|')[0].replace(/^\s*|\s*$/g, '');
301
                $('#format option[value="'+first_format+'"]').attr('selected', true);
301
                $('#format option[value="'+first_format+'"]').attr('selected', true);
302
            }
302
            }
303
        });
303
304
    </script>
304
            if ( f.length ) {
305
                alert( _("The following fields are required and not filled in: ") + f.join(", ") );
306
                return 0;
307
            }
308
309
            // Check if all fields are blank
310
            if( m.length == 0 && $('#title').val()=='' && $('#author').val()=='' && $('#volume').val()=='' && $('#issue').val()=='' && $('#date').val()=='' && $('#pages').val()=='' && $('#chapters').val()=='' && $('#patron_notes').val()=='' && !$('input[name="toc_request"]').prop('checked') ) {
311
                alert( _("Please fill in at least one field.") );
312
                return 0;
313
            }
314
315
            allow_submit = true;
316
            $('#place-article-request').submit();
317
        }
318
    });
319
320
    // Initialize format(s)
321
    var supported_formats = "[% Koha.Preference('ArticleRequestsSupportedFormats') | html %]";
322
    if( !supported_formats.match(/PHOTOCOPY/) )
323
        $('#format option[value="PHOTOCOPY"]').remove();
324
    if( !supported_formats.match(/SCAN/) )
325
        $('#format option[value="SCAN"]').remove();
326
327
    if( $('#format option').length > 1 ) {
328
        // Select first listed format
329
        var first_format = supported_formats.split('|')[0].replace(/^\s*|\s*$/g, '');
330
        $('#format option[value="'+first_format+'"]').attr('selected', true);
331
    }
332
});
333
</script>
305
[% END %]
334
[% END %]
(-)a/t/db_dependent/Koha/ArticleRequest.t (-2 / +17 lines)
Lines 17-29 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 5;
20
use Test::More tests => 6;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Exception;
22
23
23
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
24
use t::lib::Mocks;
25
use t::lib::Mocks;
25
26
26
use Koha::ArticleRequests;
27
use Koha::ArticleRequests;
28
use Koha::Exceptions::ArticleRequest;
27
29
28
my $schema  = Koha::Database->new->schema;
30
my $schema  = Koha::Database->new->schema;
29
my $builder = t::lib::TestBuilder->new;
31
my $builder = t::lib::TestBuilder->new;
Lines 211-213 subtest 'cancel() tests' => sub { Link Here
211
213
212
    $schema->storage->txn_rollback;
214
    $schema->storage->txn_rollback;
213
};
215
};
214
- 
216
217
subtest 'store' => sub {
218
    plan tests => 2;
219
    $schema->storage->txn_begin;
220
221
    t::lib::Mocks::mock_preference( 'ArticleRequestsSupportedFormats', 'SCAN' );
222
    my $ar = $builder->build_object( { class => 'Koha::ArticleRequests', value => { format => 'PHOTOCOPY' } } );
223
    throws_ok { $ar->format('test')->store } 'Koha::Exceptions::ArticleRequest::WrongFormat',
224
        'Format not supported';
225
    t::lib::Mocks::mock_preference( 'ArticleRequestsSupportedFormats', 'SCAN|PHOTOCOPY|ELSE' );
226
    lives_ok { $ar->format('PHOTOCOPY')->store } 'Now we do support it';
227
228
    $schema->storage->txn_rollback;
229
};

Return to bug 36081