@@ -, +, @@ --- C4/Serials.pm | 8 +++--- Koha/SharedContent.pm | 30 ++++++++++++++++++++++ koha-tmpl/intranet-tmpl/prog/en/includes/mana.inc | 18 ++++++++++--- .../prog/en/includes/serials-toolbar.inc | 4 +-- svc/mana/{share => comment} | 25 +++--------------- svc/mana/increment | 10 +++++++- 6 files changed, 63 insertions(+), 32 deletions(-) rename svc/mana/{share => comment} (65%) --- a/C4/Serials.pm +++ a/C4/Serials.pm @@ -281,10 +281,10 @@ sub GetSubscription { }); $subscription->{additional_fields} = $additional_field_values->{$subscriptionid}; - if ( my $mana_id = $subscription->{mana_id} ) { - my $mana_subscription = Koha::SharedContent::get_entity_by_id( - 'subscription', $mana_id, {usecomments => 1}); - $subscription->{comments} = $mana_subscription->{data}->{comments}; + if ( C4::Context->preference('Mana') == 1 ) { + $subscription->{comments} = Koha::SharedContent::get_entity_comments( + 'subscription', $subscription->{mana_id} + ); } return $subscription; --- a/Koha/SharedContent.pm +++ a/Koha/SharedContent.pm @@ -134,6 +134,36 @@ sub get_entity_by_id { return process_request(build_request('getwithid', @_)); } +=head3 get_entity_comments + +=cut + +sub get_entity_comments { + my ($resource, $id) = @_; + + unless ($id) { + return []; + } + + my $entity = get_entity_by_id( + $resource, $id, { usecomments => 1 } + ); + + return $entity->{data}->{comments}; +} + +=head3 send_entity_comment + +=cut + +sub send_entity_comment { + my ($content) = @_; + + my $result = process_request(build_request('post', 'resource_comment', $content)); + + return $result; +} + =head3 search_entities =cut --- a/koha-tmpl/intranet-tmpl/prog/en/includes/mana.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/mana.inc @@ -7,16 +7,28 @@ $(document).ready(function() { url: "/cgi-bin/koha/svc/mana/increment", data: {id: mana_id, resource: resource, field: fieldvalue, step: stepvalue}, datatype: "json", - }) + }).done(function(result) { + data = JSON.parse(result); + + html = data.message + ' (' + data.new_count + ')'; + comment = $('li.mana-comment[data-id="' + data.id + '"] a').html(html); + }); } function mana_comment( target_id, manamsg, resource_type ) { $.ajax( { type: "POST", - url: "/cgi-bin/koha/svc/mana/share", + url: "/cgi-bin/koha/svc/mana/comment", data: {message: manamsg, resource: resource_type , resource_id: target_id}, datatype: "json", - }) + }).done(function(result) { + data = JSON.parse(result); + comment = $('
').addClass('mana-comment') + .attr('data-id', data.id) + .append('' + manamsg + ' (1)'); + + $('.mana-comment-divider').before(comment); + }); } $(document).on('click', 'ul li.mana-comment', function() { --- a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-toolbar.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-toolbar.inc @@ -70,8 +70,8 @@ [% c.message | html %] ([% c.nb | html %]) [% END %] - -