Bug 19630: Added Status column to Patron Holds table
[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() {
35             $(".mana_comment_status").hide();
36             $("#mana_comment_success").show();
37         })
38         .fail(function( error ) {
39             $(".mana_comment_status").hide();
40             $("#mana_comment_errortext").html( error.status + " " + error.statusText );
41             $("#mana_comment_failed").show();
42         })
43         .always(function() {
44             $("#selected_id").val("");
45             $("#mana-resource-id").val("");
46             $("#mana-comment").val("");
47             mana_comment_close();
48         });
49 }
50
51 $(document).ready(function() {
52
53     $("body").on("submit", "#mana_comment_form", function( e ) {
54         e.preventDefault();
55         var resource_type = $('#mana-resource').val();
56         var resource_id = $('#mana-resource-id').val();
57         var comment = $("#mana-comment").val();
58         mana_comment(resource_id, comment, resource_type);
59     });
60
61     $("body").on("click", '#mana-comment-close', function( e ) {
62         e.preventDefault();
63         mana_comment_close();
64     });
65
66     $("body").on("click", ".mana-actions a", function( e ) {
67         e.preventDefault();
68         $(".mana_comment_status").hide();
69         var commentid = $(this).data("commentid");
70         var resourceid = $(this).data("resourceid");
71         $("#mana-resource-id").val( resourceid );
72         if ( commentid == "other") {
73             if( $("#new_mana_comment").length ){
74                 $("#selected_id").val( commentid );
75                 $("#mana_results, #new_mana_comment").toggle();
76             } else {
77                 $("#mana-comment-box").modal("show");
78             }
79         } else {
80             mana_increment( commentid, "resource_comment", "nb");
81         }
82     });
83 });