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

(-)a/Koha/SharedContent.pm (-4 / +15 lines)
Lines 76-86 sub increment_entity_value { Link Here
76
=cut
76
=cut
77
77
78
sub send_entity {
78
sub send_entity {
79
    my ($lang, $loggedinuser, $resourceid, $resourcetype, $content) = @_;
79
    my ($lang, $loggedinuser, $resourceid, $resourcetype) = @_;
80
80
81
    unless ( $content ) {
81
    my $content = prepare_entity_data($lang, $loggedinuser, $resourceid, $resourcetype);
82
        $content = prepare_entity_data($lang, $loggedinuser, $resourceid, $resourcetype);
83
    }
84
82
85
    my $result = process_request(build_request('post', $resourcetype, $content));
83
    my $result = process_request(build_request('post', $resourcetype, $content));
86
84
Lines 92-97 sub send_entity { Link Here
92
    return $result;
90
    return $result;
93
}
91
}
94
92
93
=head3 comment_entity
94
95
=cut
96
97
sub comment_entity {
98
    my ($resourceid, $resourcetype, $comment) = @_;
99
100
    my $result = process_request(build_request('post', 'resource_comment',
101
            { resource_id => $resourceid, resource_type => $resourcetype, message => $comment }));
102
103
    return $result;
104
}
105
95
=head3 prepare_entity_data
106
=head3 prepare_entity_data
96
107
97
=cut
108
=cut
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/mana/mana-comment-status.inc (-1 lines)
Lines 6-10 Link Here
6
</div>
6
</div>
7
<div id="mana_comment_failed" class="dialog alert mana_comment_status" style="display:none">
7
<div id="mana_comment_failed" class="dialog alert mana_comment_status" style="display:none">
8
    Your comment could not be submitted. Please try again later.
8
    Your comment could not be submitted. Please try again later.
9
    <div id="mana_comment_errortext"></div>
10
</div>
9
</div>
(-)a/koha-tmpl/intranet-tmpl/prog/js/mana.js (-8 / +7 lines)
Lines 29-44 function mana_comment( target_id, manamsg, resource_type ) { Link Here
29
        type: "POST",
29
        type: "POST",
30
        url: "/cgi-bin/koha/svc/mana/share",
30
        url: "/cgi-bin/koha/svc/mana/share",
31
        data: { message: manamsg, resource: resource_type, resource_id: target_id },
31
        data: { message: manamsg, resource: resource_type, resource_id: target_id },
32
        datatype: "json",
32
        dataType: "json",
33
    })
33
    })
34
        .done(function() {
34
        .done(function( data ) {
35
            $(".mana_comment_status").hide();
36
            $("#mana_comment_success").show();
37
        })
38
        .fail(function( error ) {
39
            $(".mana_comment_status").hide();
35
            $(".mana_comment_status").hide();
40
            $("#mana_comment_errortext").html( error.status + " " + error.statusText );
36
            if (data.code == "201" || data.code == "200") {
41
            $("#mana_comment_failed").show();
37
                $("#mana_comment_success").show();
38
            } else {
39
                $("#mana_comment_failed").show();
40
            }
42
        })
41
        })
43
        .always(function() {
42
        .always(function() {
44
            $("#selected_id").val("");
43
            $("#selected_id").val("");
(-)a/svc/mana/share (-27 / +5 lines)
Lines 26-32 use C4::Auth qw(check_cookie_auth); Link Here
26
use CGI;
26
use CGI;
27
use JSON;
27
use JSON;
28
28
29
30
my $input = new CGI;
29
my $input = new CGI;
31
binmode STDOUT, ":encoding(UTF-8)";
30
binmode STDOUT, ":encoding(UTF-8)";
32
print $input->header( -type => 'text/plain', -charset => 'UTF-8' );
31
print $input->header( -type => 'text/plain', -charset => 'UTF-8' );
Lines 40-69 if ( $auth_status ne "ok" ) { Link Here
40
}
39
}
41
40
42
41
43
my $content;
42
my $resource_id = $input->param("resource_id");
44
$content->{resource_id} = $input->param("resource_id");
43
my $resource_type = $input->param("resource");
45
$content->{resource_type} = $input->param("resource");
44
my $comment = $input->param("message");
46
$content->{message} = $input->param("message");
45
my $result = Koha::SharedContent::comment_entity($resource_id, $resource_type, $comment);
47
Koha::SharedContent::send_entity('', undef, undef, 'resource_comment', $content);
48
my $package = "Koha::".ucfirst($input->param('resource'));
49
my $resource;
50
my $result;
51
eval{
52
    $result = Koha::SharedContent::get_entity_by_id(
53
        scalar $input->param('resource'),
54
        scalar $input->param('id')
55
    );
56
};
57
if ( $@ or $result->{code} == 500 ){
58
    $resource->{errmsg} =  "Error: mana access got broken, please try again later\n\n ( error: $@ )";
59
}
60
else{
61
    if ( $input->param( 'saveinbase' )) {
62
        $resource = { id => $package->new_from_mana($result->{data})->id };
63
    }
64
    else{
65
        $resource = $result->{data};
66
    }
67
}
68
46
69
print(to_json($resource));
47
print(to_json($result));
(-)a/t/db_dependent/Koha/SharedContent.t (-2 / +5 lines)
Lines 23-29 use t::lib::TestBuilder; Link Here
23
use t::lib::Mocks;
23
use t::lib::Mocks;
24
use Test::MockModule;
24
use Test::MockModule;
25
use Test::MockObject;
25
use Test::MockObject;
26
use Test::More tests => 44;
26
use Test::More tests => 45;
27
use Koha::Database;
27
use Koha::Database;
28
use Koha::Patrons;
28
use Koha::Patrons;
29
use Koha::Subscriptions;
29
use Koha::Subscriptions;
Lines 165-170 is($result->{code}, 200, 'send_entity success'); Link Here
165
my $s = Koha::Subscriptions->find($subscription->{subscriptionid});
165
my $s = Koha::Subscriptions->find($subscription->{subscriptionid});
166
is($s->mana_id, 5, 'Mana id is set');
166
is($s->mana_id, 5, 'Mana id is set');
167
167
168
$content = { resource_id => $subscription->{mana_id}, resource_type => 'subscription', message => 'My comment'};
169
$result = Koha::SharedContent::comment_entity('resource_comment', $content);
170
is($result->{code}, 200, 'Comment success');
171
168
my $data = Koha::SharedContent::prepare_entity_data(
172
my $data = Koha::SharedContent::prepare_entity_data(
169
    '',
173
    '',
170
    $loggedinuser->borrowernumber,
174
    $loggedinuser->borrowernumber,
171
- 

Return to bug 22259