Bug 11529: Clean up subtitle usage
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / mana.js
1 /* global mana_comment_close */
2
3 function mana_increment(mana_id, resource, fieldvalue, stepvalue ) {
4     $("#mana_comment_progress").show();
5     if( !stepvalue ){ stepvalue = 1; }
6     $.ajax({
7         type: "POST",
8         url: "/cgi-bin/koha/svc/mana/increment",
9         data: {id: mana_id, resource: resource, field: fieldvalue, step: stepvalue},
10         datatype: "json",
11     })
12         .done(function() {
13             $(".mana_comment_status").hide();
14             $("#mana_comment_success").show();
15         })
16         .fail(function( error ) {
17             $(".mana_comment_status").hide();
18             $("#mana_comment_errortext").html( error.status + " " + error.statusText );
19             $("#mana_comment_failed").show();
20         })
21         .always(function() {
22             mana_comment_close();
23         });
24 }
25
26 function mana_comment( target_id, manamsg, resource_type ) {
27     $("#mana_comment_progress").show();
28     $.ajax( {
29         type: "POST",
30         url: "/cgi-bin/koha/svc/mana/share",
31         data: { message: manamsg, resource: resource_type, resource_id: target_id },
32         dataType: "json",
33     })
34         .done(function( data ) {
35             $(".mana_comment_status").hide();
36             if (data.code == "201" || data.code == "200") {
37                 $("#mana_comment_success").show();
38             } else {
39                 $("#mana_comment_failed").show();
40             }
41         })
42         .always(function() {
43             $("#selected_id").val("");
44             $("#mana-resource-id").val("");
45             $("#mana-comment").val("");
46             mana_comment_close();
47         });
48 }
49
50 $(document).ready(function() {
51
52     $("body").on("submit", "#mana_comment_form", function( e ) {
53         e.preventDefault();
54         var resource_type = $('#mana-resource').val();
55         var resource_id = $('#mana-resource-id').val();
56         var comment = $("#mana-comment").val();
57         mana_comment(resource_id, comment, resource_type);
58     });
59
60     $("body").on("click", '#mana-comment-close', function( e ) {
61         e.preventDefault();
62         mana_comment_close();
63     });
64
65     $("body").on("click", ".mana-actions a", function( e ) {
66         e.preventDefault();
67         $(".mana_comment_status").hide();
68         var commentid = $(this).data("commentid");
69         var resourceid = $(this).data("resourceid");
70         $("#mana-resource-id").val( resourceid );
71         if ( commentid == "other") {
72             if( $("#new_mana_comment").length ){
73                 $("#selected_id").val( commentid );
74                 $("#mana_results, #new_mana_comment").toggle();
75             } else {
76                 $("#mana-comment-box").modal("show");
77             }
78         } else {
79             mana_increment( commentid, "resource_comment", "nb");
80         }
81     });
82 });