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

(-)a/catalogue/itemsearch.pl (-4 / +29 lines)
Lines 40-47 my $format = $cgi->param('format'); Link Here
40
my $template_name = 'catalogue/itemsearch.tt';
40
my $template_name = 'catalogue/itemsearch.tt';
41
41
42
if (defined $format and $format eq 'json') {
42
if (defined $format and $format eq 'json') {
43
    $template_name = 'catalogue/itemsearch_json.tt';
44
45
    # Map DataTables parameters with 'regular' parameters
43
    # Map DataTables parameters with 'regular' parameters
46
    $cgi->param('rows', scalar $cgi->param('iDisplayLength'));
44
    $cgi->param('rows', scalar $cgi->param('iDisplayLength'));
47
    $cgi->param('page', (scalar $cgi->param('iDisplayStart') / scalar $cgi->param('iDisplayLength')) + 1);
45
    $cgi->param('page', (scalar $cgi->param('iDisplayStart') / scalar $cgi->param('iDisplayLength')) + 1);
Lines 260-267 if (scalar keys %params > 0) { Link Here
260
            print "$line\n" unless $line =~ m|^\s*$|;
258
            print "$line\n" unless $line =~ m|^\s*$|;
261
        }
259
        }
262
    } elsif ($format eq 'json') {
260
    } elsif ($format eq 'json') {
263
        $template->param(sEcho => scalar $cgi->param('sEcho'));
261
        my $response = {
264
        output_with_http_headers $cgi, $cookie, $template->output, 'json';
262
            sEcho => scalar $cgi->param('sEcho'),
263
            iTotalRecords => $total_rows,
264
            iTotalDisplayRecords => $total_rows,
265
            aaData => [ map {
266
                my $av = Koha::AuthorisedValues->search({ category => 'CCODE', authorised_value => $_->{ccode} });
267
                my $ccode = $av->count ? $av->next->lib : $_->{ccode};
268
                my $homebranch = Koha::Libraries->find($_->{homebranch});
269
                my $holdingbranch = Koha::Libraries->find($_->{holdingbranch});
270
                {
271
                    biblionumber  => $_->{biblionumber},
272
                    itemnumber  => $_->{itemnumber},
273
                    author => $_->{biblio}->author,
274
                    title => $_->{biblio}->title,
275
                    publicationyear => $_->{biblioitem}->{publicationyear} || $_->{biblio}->copyrightdate,
276
                    publishercode => $_->{biblioitem}->{publishercode},
277
                    ccode => $ccode,
278
                    barcode => $_->{barcode},
279
                    itemcallnumber => $_->{itemcallnumber},
280
                    homebranch => $homebranch ? $homebranch->branchname : '',
281
                    holdingbranch => $holdingbranch ? $holdingbranch->branchname : '',
282
                    location => $_->{location},
283
                    stocknumber => $_->{stocknumber},
284
                    notforloan => $_->{status},
285
                    issues => $_->{issues} || 0,
286
                };
287
            } @$results ],
288
        };
289
        output_with_http_headers $cgi, $cookie, encode_json($response), 'json';
265
    }
290
    }
266
291
267
    exit;
292
    exit;
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.json.inc (-26 lines)
Lines 1-26 Link Here
1
[%- USE Branches -%]
2
[%- USE Koha -%]
3
[% USE AuthorisedValues %]
4
[%- biblio = item.biblio -%]
5
[%- biblioitem = item.biblioitem -%]
6
[
7
  "[% FILTER escape_quotes = replace('"', '\"') ~%]
8
    <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% biblio.biblionumber | uri %]" title="Go to record detail page">[% biblio.title | html %]</a>[% IF ( Koha.Preference( 'marcflavour' ) == 'UNIMARC' && biblio.author ) %] by[% END %] [% biblio.author | html %]
9
  [%~ END %]",
10
  "[% (biblioitem.publicationyear || biblio.copyrightdate) | html %]",
11
  "[% biblioitem.publishercode | html %]",
12
  "[% AuthorisedValues.GetByCode( 'CCODE', item.ccode ) | html %]",
13
  "[% FILTER escape_quotes ~%]
14
    <a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=[% biblio.biblionumber | uri %]#item[% item.itemnumber | uri %]" title="Go to item details">[% item.barcode | html %]</a>
15
  [%~ END %]",
16
  "[% item.itemcallnumber | html %]",
17
  "[% Branches.GetName(item.homebranch) | html %]",
18
  "[% Branches.GetName(item.holdingbranch) | html %]",
19
  "[% item.location | html %]",
20
  "[% item.stocknumber | html %]",
21
  "[% item.status | html %]",
22
  "[% (item.issues || 0) | html %]",
23
  "[% FILTER escape_quotes ~%]
24
    <div class="btn-group dropup"><button type="button" class="btn btn-xs btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <i class="fa fa-pencil"></i> Edit <span class="caret"></span> </button> <ul class="dropdown-menu"> <li><a href="/cgi-bin/koha/cataloguing/additem.pl?op=edititem&biblionumber=[% item.biblionumber | uri %]&itemnumber=[% item.itemnumber | uri %]">Edit item</a></li> <li><a href="/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=[% item.biblionumber | html %]">Edit record</a></li> </ul> </div>
25
  [%~ END %]"
26
]
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/i18n.inc (-18 / +18 lines)
Lines 1-38 Link Here
1
[% USE I18N %]
1
[% USE I18N %]
2
[% USE raw %]
2
[% USE raw %]
3
3
4
[% MACRO t(msgid) BLOCK %]
4
[% MACRO t(msgid) BLOCK ~%]
5
    [% I18N.t(msgid) | $raw %]
5
    [% I18N.t(msgid) | $raw %]
6
[% END %]
6
[%~ END %]
7
7
8
[% MACRO tx(msgid, vars) BLOCK %]
8
[% MACRO tx(msgid, vars) BLOCK ~%]
9
    [% I18N.tx(msgid, vars) | $raw %]
9
    [% I18N.tx(msgid, vars) | $raw %]
10
[% END %]
10
[%~ END %]
11
11
12
[% MACRO tn(msgid, msgid_plural, count) BLOCK %]
12
[% MACRO tn(msgid, msgid_plural, count) BLOCK ~%]
13
    [% I18N.tn(msgid, msgid_plural, count) | $raw %]
13
    [% I18N.tn(msgid, msgid_plural, count) | $raw %]
14
[% END %]
14
[%~ END %]
15
15
16
[% MACRO tnx(msgid, msgid_plural, count, vars) BLOCK %]
16
[% MACRO tnx(msgid, msgid_plural, count, vars) BLOCK ~%]
17
    [% I18N.tnx(msgid, msgid_plural, count, vars) | $raw %]
17
    [% I18N.tnx(msgid, msgid_plural, count, vars) | $raw %]
18
[% END %]
18
[%~ END %]
19
19
20
[% MACRO txn(msgid, msgid_plural, count, vars) BLOCK %]
20
[% MACRO txn(msgid, msgid_plural, count, vars) BLOCK ~%]
21
    [% I18N.txn(msgid, msgid_plural, count, vars) | $raw %]
21
    [% I18N.txn(msgid, msgid_plural, count, vars) | $raw %]
22
[% END %]
22
[%~ END %]
23
23
24
[% MACRO tp(msgctxt, msgid) BLOCK %]
24
[% MACRO tp(msgctxt, msgid) BLOCK ~%]
25
    [% I18N.tp(msgctxt, msgid) | $raw %]
25
    [% I18N.tp(msgctxt, msgid) | $raw %]
26
[% END %]
26
[%~ END %]
27
27
28
[% MACRO tpx(msgctxt, msgid, vars) BLOCK %]
28
[% MACRO tpx(msgctxt, msgid, vars) BLOCK ~%]
29
    [% I18N.tpx(msgctxt, msgid, vars) | $raw %]
29
    [% I18N.tpx(msgctxt, msgid, vars) | $raw %]
30
[% END %]
30
[%~ END %]
31
31
32
[% MACRO tnp(msgctxt, msgid, msgid_plural, count) BLOCK %]
32
[% MACRO tnp(msgctxt, msgid, msgid_plural, count) BLOCK ~%]
33
    [% I18N.tnp(msgctxt, msgid, msgid_plural, count) | $raw %]
33
    [% I18N.tnp(msgctxt, msgid, msgid_plural, count) | $raw %]
34
[% END %]
34
[%~ END %]
35
35
36
[% MACRO tnpx(msgctxt, msgid, msgid_plural, count, vars) BLOCK %]
36
[% MACRO tnpx(msgctxt, msgid, msgid_plural, count, vars) BLOCK ~%]
37
    [% I18N.tnpx(msgctxt, msgid, msgid_plural, count, vars) | $raw %]
37
    [% I18N.tnpx(msgctxt, msgid, msgid_plural, count, vars) | $raw %]
38
[% END %]
38
[%~ END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt (-13 / +151 lines)
Lines 1-6 Link Here
1
[% USE raw %]
1
[% USE raw %]
2
[% USE To %]
2
[% USE To %]
3
[% USE Asset %]
3
[% USE Asset %]
4
[% USE Koha %]
5
[% USE JSON.Escape %]
6
[% PROCESS 'i18n.inc' %]
4
7
5
[% BLOCK form_label %]
8
[% BLOCK form_label %]
6
  [% SWITCH label %]
9
  [% SWITCH label %]
Lines 364-382 Link Here
364
                },
367
                },
365
                'sDom': '<"top pager"ilp>t<"bottom pager"ip>r',
368
                'sDom': '<"top pager"ilp>t<"bottom pager"ip>r',
366
                'aoColumns': [
369
                'aoColumns': [
367
                    { 'sName': 'title' },
370
                    {
368
                    { 'sName': 'publicationyear' },
371
                        'sName': 'title',
369
                    { 'sName': 'publishercode' },
372
                        'mData': 'title',
370
          { 'sName': 'ccode' },
373
                        'mRender': function (sData, sType, oRow) {
371
                    { 'sName': 'barcode' },
374
                            const a = document.createElement('a');
372
                    { 'sName': 'itemcallnumber' },
375
                            a.appendChild(document.createTextNode(oRow.title));
373
                    { 'sName': 'homebranch' },
376
                            a.href = '/cgi-bin/koha/catalogue/detail.pl?biblionumber=' + oRow.biblionumber;
374
                    { 'sName': 'holdingbranch' },
377
                            a.setAttribute('title', [% t('Go to record detail page').json %]);
375
                    { 'sName': 'location' },
378
376
                    { 'sName': 'stocknumber' },
379
                            let output = a.outerHTML;
377
                    { 'sName': 'notforloan' },
380
                            if (oRow.author) {
378
                    { 'sName': 'issues' },
381
                                const marcflavour = [% Koha.Preference('marcflavour').json %];
379
                    { 'sName': 'checkbox', 'bSortable': false }
382
                                if (marcflavour === 'UNIMARC') {
383
                                    output += ' ' + [% t('by').json %];
384
                                }
385
                                output += ' ' + oRow.author;
386
                            }
387
388
                            return output;
389
                        }
390
                    },
391
                    {
392
                        'sName': 'publicationyear',
393
                        'mData': 'publicationyear',
394
                        'mRender': function (sData) {
395
                            return sData ? sData.escapeHtml() : '';
396
                        }
397
                    },
398
                    {
399
                        'sName': 'publishercode',
400
                        'mData': 'publishercode',
401
                        'mRender': function (sData) {
402
                            return sData ? sData.escapeHtml() : '';
403
                        }
404
                    },
405
                    {
406
                        'sName': 'ccode',
407
                        'mData': 'ccode',
408
                        'mRender': function (sData) {
409
                            return sData ? sData.escapeHtml() : '';
410
                        }
411
                    },
412
                    {
413
                        'sName': 'barcode',
414
                        'mData': 'barcode',
415
                        'mRender': function (sData, sType, oRow) {
416
                            let output = '';
417
                            if (oRow.barcode) {
418
                                const a = document.createElement('a');
419
                                a.href = '/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=' + oRow.biblionumber + '#item' + oRow.itemnumber;
420
                                a.setAttribute('title', [% t('Go to item details').json %]);
421
                                a.appendChild(document.createTextNode(oRow.barcode));
422
                                output = a.outerHTML;
423
                            }
424
425
                            return output;
426
                        }
427
                    },
428
                    {
429
                        'sName': 'itemcallnumber',
430
                        'mData': 'itemcallnumber',
431
                        'mRender': function (sData) {
432
                            return sData ? sData.escapeHtml() : '';
433
                        }
434
                    },
435
                    {
436
                        'sName': 'homebranch',
437
                        'mData': 'homebranch',
438
                        'mRender': function (sData) {
439
                            return sData ? sData.escapeHtml() : '';
440
                        }
441
                    },
442
                    {
443
                        'sName': 'holdingbranch',
444
                        'mData': 'holdingbranch',
445
                        'mRender': function (sData) {
446
                            return sData ? sData.escapeHtml() : '';
447
                        }
448
                    },
449
                    {
450
                        'sName': 'location',
451
                        'mData': 'location',
452
                        'mRender': function (sData) {
453
                            return sData ? sData.escapeHtml() : '';
454
                        }
455
                    },
456
                    {
457
                        'sName': 'stocknumber',
458
                        'mData': 'stocknumber',
459
                        'mRender': function (sData) {
460
                            return sData ? sData.escapeHtml() : '';
461
                        }
462
                    },
463
                    {
464
                        'sName': 'notforloan',
465
                        'mData': 'notforloan',
466
                        'mRender': function (sData) {
467
                            return sData ? sData.escapeHtml() : '';
468
                        }
469
                    },
470
                    {
471
                        'sName': 'issues',
472
                        'mData': 'issues',
473
                    },
474
                    {
475
                        'sName': 'checkbox',
476
                        'bSortable': false,
477
                        'mData': null,
478
                        'mRender': function (sData, sType, oRow) {
479
                            const pencil = document.createElement('i');
480
                            pencil.classList.add('fa', 'fa-pencil');
481
482
                            const edit = document.createTextNode(' ' + [% t('Edit').json %] + ' ');
483
484
                            const caret = document.createElement('span');
485
                            caret.classList.add('caret')
486
487
                            const button = document.createElement('button');
488
                            button.type = 'button';
489
                            button.classList.add('btn', 'btn-xs', 'btn-default', 'dropdown-toggle');
490
                            button.setAttribute('data-toggle', 'dropdown');
491
                            button.setAttribute('aria-haspopup', 'true');
492
                            button.setAttribute('aria-expanded', 'false');
493
                            button.appendChild(pencil);
494
                            button.appendChild(edit);
495
                            button.appendChild(caret);
496
497
                            const edit_item = document.createElement('a');
498
                            edit_item.href = '/cgi-bin/koha/cataloguing/additem.pl?op=edititem&biblionumber=' + oRow.biblionumber + '&itemnumber=' + oRow.itemnumber;
499
                            edit_item.appendChild(document.createTextNode([% t('Edit item').json %]));
500
501
                            const edit_record = document.createElement('a');
502
                            edit_record.href = '/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=' + oRow.biblionumber;
503
                            edit_record.appendChild(document.createTextNode([% t('Edit record').json %]));
504
505
                            const ul = document.createElement('ul');
506
                            ul.classList.add('dropdown-menu');
507
                            ul.appendChild(document.createElement('li').appendChild(edit_item).parentNode);
508
                            ul.appendChild(document.createElement('li').appendChild(edit_record).parentNode);
509
510
                            const div = document.createElement('div');
511
                            div.classList.add('btn-group', 'dropup');
512
                            div.appendChild(button);
513
                            div.appendChild(ul);
514
515
                            return div.outerHTML;
516
                        }
517
                    }
380
                ],
518
                ],
381
                "sPaginationType": "full_numbers"
519
                "sPaginationType": "full_numbers"
382
            })).columnFilter({
520
            })).columnFilter({
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch_json.tt (-12 lines)
Lines 1-11 Link Here
1
{
2
  "sEcho": [% sEcho | html %],
3
  "iTotalRecords": [% total_rows | html %],
4
  "iTotalDisplayRecords": [% total_rows | html %],
5
  "aaData": [
6
  [%- FOREACH item IN results -%]
7
    [%- INCLUDE 'catalogue/itemsearch_item.json.inc' item = item -%]
8
    [%- UNLESS loop.last %],[% END -%]
9
  [%- END -%]
10
  ]
11
}
12
- 

Return to bug 21716