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

(-)a/Koha/Schema/Result/ItemMessage.pm (+111 lines)
Line 0 Link Here
1
use utf8;
2
package Koha::Schema::Result::ItemMessage;
3
4
# Created by DBIx::Class::Schema::Loader
5
# DO NOT MODIFY THE FIRST PART OF THIS FILE
6
7
=head1 NAME
8
9
Koha::Schema::Result::ItemMessage
10
11
=cut
12
13
use strict;
14
use warnings;
15
16
use base 'DBIx::Class::Core';
17
18
=head1 TABLE: C<item_messages>
19
20
=cut
21
22
__PACKAGE__->table("item_messages");
23
24
=head1 ACCESSORS
25
26
=head2 item_message_id
27
28
  data_type: 'integer'
29
  is_auto_increment: 1
30
  is_nullable: 0
31
32
=head2 itemnumber
33
34
  data_type: 'integer'
35
  is_foreign_key: 1
36
  is_nullable: 0
37
38
=head2 type
39
40
  data_type: 'varchar'
41
  is_nullable: 1
42
  size: 80
43
44
=head2 message
45
46
  data_type: 'text'
47
  is_nullable: 0
48
49
=head2 created_on
50
51
  data_type: 'timestamp'
52
  datetime_undef_if_invalid: 1
53
  default_value: current_timestamp
54
  is_nullable: 0
55
56
=cut
57
58
__PACKAGE__->add_columns(
59
  "item_message_id",
60
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
61
  "itemnumber",
62
  { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
63
  "type",
64
  { data_type => "varchar", is_nullable => 1, size => 80 },
65
  "message",
66
  { data_type => "text", is_nullable => 0 },
67
  "created_on",
68
  {
69
    data_type => "timestamp",
70
    datetime_undef_if_invalid => 1,
71
    default_value => \"current_timestamp",
72
    is_nullable => 0,
73
  },
74
);
75
76
=head1 PRIMARY KEY
77
78
=over 4
79
80
=item * L</item_message_id>
81
82
=back
83
84
=cut
85
86
__PACKAGE__->set_primary_key("item_message_id");
87
88
=head1 RELATIONS
89
90
=head2 itemnumber
91
92
Type: belongs_to
93
94
Related object: L<Koha::Schema::Result::Item>
95
96
=cut
97
98
__PACKAGE__->belongs_to(
99
  "itemnumber",
100
  "Koha::Schema::Result::Item",
101
  { itemnumber => "itemnumber" },
102
  { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
103
);
104
105
106
# Created by DBIx::Class::Schema::Loader v0.07040 @ 2015-02-09 07:59:08
107
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:6shNRfWMQ+v1d5GwgX01rw
108
109
110
# You can replace this text with custom code or comments, and it will be preserved on regeneration
111
1;
(-)a/Koha/Service/AuthorisedValues.pm (+63 lines)
Line 0 Link Here
1
package Koha::Service::AuthorisedValues;
2
3
# This file is part of Koha.
4
#
5
# Copyright (C) 2015 ByWater Solutions
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use JSON;
23
24
use C4::Koha;
25
26
use base 'Koha::Service';
27
28
sub new {
29
    my ($class) = @_;
30
31
    # Authentication is handled manually below
32
    return $class->SUPER::new(
33
        {
34
            authnotrequired => 0,
35
            routes          => [
36
                [ qr'GET /(.+)', 'get_authorised_values' ],
37
            ],
38
        }
39
    );
40
}
41
42
sub run {
43
    my ($self) = @_;
44
45
    $self->authenticate;
46
47
    unless ( $self->auth_status eq "ok" ) {
48
        $self->output(
49
            XMLout( { auth_status => $self->auth_status }, NoAttr => 1, RootName => 'response', XMLDecl => 1 ),
50
            { type => 'xml', status => '403 Forbidden' } );
51
        exit;
52
    }
53
54
    $self->dispatch;
55
}
56
57
sub get_authorised_values {
58
    my ( $self, $category ) = @_;
59
60
    $self->output( GetAuthorisedValues($category) );
61
}
62
63
1;
(-)a/Koha/Service/Item/Message.pm (+162 lines)
Line 0 Link Here
1
package Koha::Service::Item::Message;
2
3
# This file is part of Koha.
4
#
5
# Copyright (C) 2015 ByWater Solutions
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use JSON;
23
24
use Koha::Database;
25
use C4::Koha;
26
27
use base 'Koha::Service';
28
29
sub new {
30
    my ($class) = @_;
31
32
    # Authentication is handled manually below
33
    return $class->SUPER::new(
34
        {
35
            authnotrequired => 0,
36
            needed_flags    => { editcatalogue => 'edit_catalogue' },
37
            routes          => [
38
                [ qr'GET /(\d+)',    'get_messages' ],
39
                [ qr'POST /(\d+)',   'add_message' ],
40
                [ qr'PUT /(\d+)',    'update_message' ],
41
                [ qr'DELETE /(\d+)', 'delete_message' ],
42
            ]
43
        }
44
    );
45
}
46
47
sub run {
48
    my ($self) = @_;
49
50
    $self->authenticate;
51
52
    unless ( $self->auth_status eq "ok" ) {
53
        $self->output(
54
            XMLout( { auth_status => $self->auth_status }, NoAttr => 1, RootName => 'response', XMLDecl => 1 ),
55
            { type => 'xml', status => '403 Forbidden' } );
56
        exit;
57
    }
58
59
    $self->dispatch;
60
}
61
62
sub get_messages {
63
    my ( $self, $itemnumber ) = @_;
64
65
    my $rs = Koha::Database->new->schema()->resultset('ItemMessage')
66
      ->search( { itemnumber => $itemnumber }, { result_class => 'DBIx::Class::ResultClass::HashRefInflator' } );
67
68
    my @messages = map { $_ } $rs->all();
69
    map { $_->{authorised_value} = GetAuthorisedValueByCode( 'ITEM_MESSAGE', $_->{type} ) } @messages;
70
71
    warn Data::Dumper::Dumper( \@messages );
72
73
    $self->output( \@messages );
74
}
75
76
sub add_message {
77
    my ( $self, $itemnumber ) = @_;
78
79
    my $query = $self->query;
80
81
    my $json = $query->param('POSTDATA');
82
    my $data = from_json( $json, { utf8 => 1 } );
83
84
    my $type    = $data->{type};
85
    my $message = $data->{message};
86
87
    my $msg = Koha::Database->new->schema()->resultset('ItemMessage')->create(
88
        {
89
            itemnumber => $itemnumber,
90
            type       => $type,
91
            message    => $message,
92
        }
93
    );
94
    $msg->discard_changes();
95
96
    $self->output(
97
        {
98
            item_message_id  => $msg->id(),
99
            itemnumber       => $itemnumber,
100
            type             => $type,
101
            message          => $message,
102
            created_on       => $msg->created_on(),
103
            authorised_value => GetAuthorisedValueByCode( 'ITEM_MESSAGE', $type ),
104
        }
105
    );
106
}
107
108
sub update_message {
109
    my ( $self, $id ) = @_;
110
111
    my $query = $self->query;
112
113
    my $json = $query->param('PUTDATA');
114
    my $data = from_json( $json, { utf8 => 1 } );
115
116
    my $type    = $data->{type};
117
    my $message = $data->{message};
118
119
    my $msg = Koha::Database->new->schema()->resultset('ItemMessage')->find($id);
120
121
    croak("no item message") unless $msg;
122
123
    $msg->update(
124
        {
125
            type    => $type,
126
            message => $message,
127
        }
128
    );
129
130
    $self->output(
131
        {
132
            item_message_id  => $msg->id(),
133
            itemnumber       => $msg->get_column('itemnumber'),
134
            type             => $type,
135
            message          => $message,
136
            created_on       => $msg->created_on(),
137
            authorised_value => GetAuthorisedValueByCode( 'ITEM_MESSAGE', $type ),
138
        }
139
    );
140
}
141
142
sub delete_message {
143
    my ( $self, $id ) = @_;
144
145
    my $msg = Koha::Database->new->schema()->resultset('ItemMessage')->find($id);
146
147
    craok("no item message") unless $msg;
148
149
    $msg->delete();
150
151
    $self->output(
152
        {
153
            item_message_id => $msg->id(),
154
            itemnumber      => $msg->get_column('itemnumber'),
155
            type            => $msg->type(),
156
            message         => $msg->message(),
157
            created_on      => $msg->created_on(),
158
        }
159
    );
160
}
161
162
1;
(-)a/installer/data/mysql/kohastructure.sql (+9 lines)
Lines 1261-1266 CREATE TABLE `items` ( -- holdings/item information Link Here
1261
  CONSTRAINT `items_ibfk_3` FOREIGN KEY (`holdingbranch`) REFERENCES `branches` (`branchcode`) ON UPDATE CASCADE
1261
  CONSTRAINT `items_ibfk_3` FOREIGN KEY (`holdingbranch`) REFERENCES `branches` (`branchcode`) ON UPDATE CASCADE
1262
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
1262
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
1263
1263
1264
CREATE TABLE `item_messages` (
1265
    `item_message_id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY,
1266
    `itemnumber` INT( 11 ) NOT NULL,
1267
    `type` VARCHAR( 80 ) NULL, -- ITEM_MESSAGE authorised value
1268
    `message` TEXT NOT NULL,
1269
    `created_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
1270
    INDEX (  `itemnumber` )
1271
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
1272
1264
--
1273
--
1265
-- Table structure for table `itemtypes`
1274
-- Table structure for table `itemtypes`
1266
--
1275
--
(-)a/installer/data/mysql/updatedatabase.pl (+17 lines)
Lines 9732-9737 if ( CheckVersion($DBversion) ) { Link Here
9732
    SetVersion($DBversion);
9732
    SetVersion($DBversion);
9733
}
9733
}
9734
9734
9735
$DBversion = "3.19.00.006";
9736
if ( CheckVersion($DBversion) ) {
9737
    $dbh->do(q{
9738
        CREATE TABLE `item_messages` (
9739
            `item_message_id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY,
9740
            `itemnumber` INT( 11 ) NOT NULL,
9741
            `type` VARCHAR( 80 ) NULL, -- ITEM_MESSAGE authorised value
9742
            `message` TEXT NOT NULL,
9743
            `created_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
9744
            INDEX (  `itemnumber` )
9745
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
9746
    });
9747
9748
    print "Upgrade to $DBversion done (Bug 13733 - Give librarians the ability to add messages to an item)\n";
9749
    SetVersion ($DBversion);
9750
}
9751
9735
=head1 FUNCTIONS
9752
=head1 FUNCTIONS
9736
9753
9737
=head2 TableExists($table)
9754
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/partials/widgets/item-messages.html (+34 lines)
Line 0 Link Here
1
<h4>
2
    Messages
3
    <a href="" ng-click="showNewMessageEditor()">
4
        <i class="icon-plus-sign"></i>
5
    </a>
6
</h4>
7
<ol class="bibliodetails">
8
    <li ng-repeat="m in messages">
9
        <span class="label">
10
            {{m.authorised_value}}
11
            &nbsp;
12
        </span>
13
14
        {{m.message}}
15
16
        <a href="" ng-click="remove(m)">
17
            <i class="icon-remove-sign"></i>
18
        </a>
19
    </li>
20
21
    <li ng-show="showAddNewMessage">
22
        <span class="label">
23
            <select ng-model="itemMessage.type">
24
                <option value="{{t.authorised_value}}" ng-repeat="t in types">{{t.lib}}</option>
25
            </select>
26
        </span>
27
28
        <textarea ng-model="itemMessage.message"/>
29
30
        <input type="submit" class="submit" value="Save" ng-click="create()">
31
32
        <a href="" ng-click="hideNewMessageEditor()">Cancel</a>
33
    </li>
34
</ol>
(-)a/koha-tmpl/intranet-tmpl/prog/en/js/item-messages.js (+89 lines)
Line 0 Link Here
1
var koha = angular.module('Koha', []);
2
3
koha.factory('AuthorisedValueService', [ '$http', function( $http ) {
4
    var authorised_values = {};
5
6
    return {
7
        list: function( params ) {
8
            var category = params.category;
9
            var callback = params.callback;
10
11
            if ( authorised_values[category] ) {
12
                if ( callback ) {
13
                    return callback(authorised_values[category]);
14
                } else {
15
                    return authorised_values[category];
16
                }
17
            } else {
18
                $http.get('/cgi-bin/koha/svc/authorised_values/' + category).then(function(response) {
19
                    authorised_values[category] = response.data;
20
21
                    if ( callback ) {
22
                        return callback(response.data);
23
                    } else {
24
                        return response.data;
25
                    }
26
                }, function(errResponse) {
27
                    console.error('Error while fetching authorised values');
28
                });
29
            }
30
        },
31
    };
32
}]);
33
34
koha.directive('itemMessages', [ '$http', 'AuthorisedValueService', function( $http, AuthorisedValueService ) {
35
    return {
36
        scope: {
37
            itemnumber: '@'
38
        },
39
        templateUrl: '/intranet-tmpl/prog/en/includes/partials/widgets/item-messages.html',
40
        link: function($scope, $element, $attrs) {
41
            $scope.showAddNewMessage = false;
42
            $scope.messages = [];
43
44
            AuthorisedValueService.list( {
45
                category: 'ITEM_MESSAGE',
46
                callback: function( types ) {
47
                  $scope.types = types;
48
                },
49
            } );
50
51
            $http.get('/cgi-bin/koha/svc/item/message/' + $scope.itemnumber).then(function(response) {
52
                $scope.messages = response.data;
53
            }, function(errResponse) {
54
                console.error('Error while fetching notes');
55
            });
56
57
            $scope.create = function() {
58
                $scope.showAddNewMessage = false;
59
60
                $http.post('/cgi-bin/koha/svc/item/message/' + $scope.itemnumber, $scope.itemMessage).then(function(response) {
61
                    $scope.hideNewMessageEditor();
62
                    $scope.messages.push( response.data );
63
                }, function(errResponse) {
64
                    console.error('Error while posting note');
65
                });
66
            }
67
68
            $scope.remove = function(im) {
69
                $http.delete('/cgi-bin/koha/svc/item/message/' + im.item_message_id).then(function(response) {
70
                    var index = $scope.messages.indexOf(im);
71
                    $scope.messages.splice( index, 1 );
72
                }, function(errResponse) {
73
                    console.error('Error while deleting note');
74
                });
75
            }
76
77
            $scope.showNewMessageEditor = function() {
78
                $scope.showAddNewMessage = true;
79
            };
80
81
            $scope.hideNewMessageEditor = function() {
82
                $scope.showAddNewMessage = false;
83
                $scope.itemMessage.type = "";
84
                $scope.itemMessage.message = "";
85
            };
86
        }
87
    };
88
}]);
89
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt (-1 / +8 lines)
Lines 13-20 Link Here
13
    browser.show();
13
    browser.show();
14
//]]>
14
//]]>
15
</script>
15
</script>
16
[% INCLUDE 'doc-head-angular.inc' %]
17
<script type="text/javascript" src="/intranet-tmpl/prog/en/js/item-messages.js"></script>
16
</head>
18
</head>
17
<body id="catalog_moredetail" class="catalog">
19
<body id="catalog_moredetail" class="catalog" ng-app="Koha">
18
[% USE KohaDates %]
20
[% USE KohaDates %]
19
[% INCLUDE 'header.inc' %]
21
[% INCLUDE 'header.inc' %]
20
[% INCLUDE 'cat-search.inc' %]
22
[% INCLUDE 'cat-search.inc' %]
Lines 181-186 Link Here
181
            </li>
183
            </li>
182
            [% IF ITEM_DAT.withdrawn_on %]<li><span class="label">Withdrawn on:</span>[% ITEM_DAT.withdrawn_on | $KohaDates %] &nbsp;</li>[% END %]
184
            [% IF ITEM_DAT.withdrawn_on %]<li><span class="label">Withdrawn on:</span>[% ITEM_DAT.withdrawn_on | $KohaDates %] &nbsp;</li>[% END %]
183
            </ol></div>
185
            </ol></div>
186
187
            <div class="listgroup">
188
                <item-messages itemnumber="[% ITEM_DAT.itemnumber %]"></item-messages>
189
            </div>
190
184
            <div class="listgroup"><h4>History</h4>
191
            <div class="listgroup"><h4>History</h4>
185
            <ol class="bibliodetails">
192
            <ol class="bibliodetails">
186
193
(-)a/svc/authorised_values (+24 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright (C) 2015 ByWater Solutions
4
#
5
# This file is part of Koha.
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 2 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, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
#
20
21
use Modern::Perl;
22
23
use Koha::Service::AuthorisedValues;
24
Koha::Service::AuthorisedValues->new->run;
(-)a/svc/item/message (-1 / +24 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright (C) 2015 ByWater Solutions
4
#
5
# This file is part of Koha.
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 2 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, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
#
20
21
use Modern::Perl;
22
23
use Koha::Service::Item::Message;
24
Koha::Service::Item::Message->new->run;

Return to bug 13733