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

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/modals/quick_add_patron.inc (+70 lines)
Line 0 Link Here
1
<div class="modal" id="addQuickAddUserModal" tabindex="-1" role="dialog"
2
        aria-labelledby="addQuickAddUserModalLabel" aria-hidden="true">
3
        <form id="quick_add_user_form">
4
        <div class="modal-dialog modal-md" role="document">
5
            <div class="modal-content modal-md">
6
                <div class="modal-header">
7
                    <button type="button" class="closebtn" data-dismiss="modal"
8
                        aria-label="Close">
9
                        <span aria-hidden="true">&times;</span>
10
                    </button>
11
                    <h4 class="modal-title" id="addQuickAddUserModalLabel">Add patron
12
                    </h4>
13
                </div>
14
                <div class="modal-body">
15
                    <fieldset class="rows" id="quick_add_user_fieldset">
16
                        <ol>
17
                            <li>
18
                                <label for="surname" class="required">
19
                                    Surname: </label>
20
                                <input type="text" id="surname_quick_add" name="surname" size="20"
21
                                    value="" required="" class="noEnterSubmit">
22
                                <span class="required">Required</span>
23
                            </li>
24
                            <li>
25
                                <label for="cardnumber" class="required">
26
                                    Card number:
27
                                </label>
28
                                <!-- NOTE: div.hint closing tag isn't on the same line -->
29
                                <input type="text" id="cardnumber_quick_add" name="cardnumber" size="20"
30
                                    value="" minlength="1" maxlength="32" required=""
31
                                    class="noEnterSubmit">
32
                                <span class="required">Required</span>
33
                                <span id="cn_max" class="required" style="display: none;">Card number
34
                                    must not be more than 32 characters.</span>
35
                                <div class="hint">Card number must be between 1 and 32 characters.
36
                                </div>
37
                                <!--/div.hint -->
38
                            </li>
39
                            <li>
40
                                <label for="libraries" class="required">Library:</label>
41
                                <select name="branchcode" id="libraries_quick_add"
42
                                    class="noEnterSubmit">
43
                                    
44
                                </select>
45
                                <span class="required">Required</span>
46
                            </li>
47
                            <li>
48
                                <label for="categorycode_entry" class="required">Category: </label>
49
                                <select id="categorycode_entry_quick_add" name="categorycode"
50
                                    class="noEnterSubmit">
51
                                </select>
52
                                <span class="required">Required</span>
53
                            </li>
54
                        </ol>
55
                    </fieldset>
56
                </div> <!-- /.modal-body -->
57
                <div class="modal-footer">
58
                    <input type="hidden" id="quick_add_user_biblio" name="biblio_id"
59
                        value="test">
60
                    <button type="submit" class="btn btn-primary"
61
                        id="addConfirm">Submit <i id="user-submit-spinner"
62
                            class="fa fa-spinner fa-pulse fa-fw"
63
                            style="display:none"></i></button>
64
                    <button type="button" class="btn btn-default"
65
                        data-dismiss="modal">Cancel</button>
66
                </div> <!-- /.modal-footer -->
67
            </div> <!-- /.modal-content -->
68
        </div> <!-- /.modal-dialog -->
69
        </form>
70
    </div> <!-- /#addQuickAddUserModal -->
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt (+3 lines)
Lines 235-240 legend:hover { Link Here
235
                                [% END %]
235
                                [% END %]
236
                                    <i class="fa fa-times"></i> Cancel
236
                                    <i class="fa fa-times"></i> Cancel
237
                                </a>
237
                                </a>
238
                                <a id="quick_add_user_button"  href="#">+ Add new user</a>
238
                            </div>
239
                            </div>
239
                        [% END %]
240
                        [% END %]
240
241
Lines 1680-1686 legend:hover { Link Here
1680
    [% Asset.js("lib/hc-sticky.js") | $raw %]
1681
    [% Asset.js("lib/hc-sticky.js") | $raw %]
1681
    [% INCLUDE 'calendar.inc' %]
1682
    [% INCLUDE 'calendar.inc' %]
1682
    [% INCLUDE 'str/members-menu.inc' %]
1683
    [% INCLUDE 'str/members-menu.inc' %]
1684
    [% INCLUDE modals/quick_add_patron.inc %]
1683
    [% Asset.js("js/members-menu.js") | $raw %]
1685
    [% Asset.js("js/members-menu.js") | $raw %]
1686
    [% Asset.js("js/modals/quick_add_patron.js") | $raw %]
1684
    <script>
1687
    <script>
1685
        function update_cardnumber_warning(size){
1688
        function update_cardnumber_warning(size){
1686
            var max_len = [% maxlength_cardnumber | html %];
1689
            var max_len = [% maxlength_cardnumber | html %];
(-)a/koha-tmpl/intranet-tmpl/prog/js/modals/quick_add_patron.js (-1 / +149 lines)
Line 0 Link Here
0
- 
1
$(document).ready(function() {
2
 $("#quick_add_user_button").on("click", function () {
3
     if (!$("#libraries_quick_add").children("option").length) {
4
         _GETLibraries();
5
     }
6
     if (!$("#categorycode_entry_quick_add").children("optgroup").length) {
7
         _GETPatronCategories();
8
     }
9
     $("#addQuickAddUserModal").modal("show");
10
     $(".dialog.alert").remove();
11
 });
12
13
 $("#addQuickAddUserModal").on("click", "#addConfirm", function (e) {
14
     e.preventDefault();
15
     if (!$("#quick_add_user_form").get(0).checkValidity()) {
16
         $("#quick_add_user_form").get(0).reportValidity();
17
     } else {
18
         $("#user-submit-spinner").show();
19
         _POSTPatron({
20
             surname: $("#surname_quick_add").val(),
21
             cardnumber: $("#cardnumber_quick_add").val(),
22
             library_id: $("#libraries_quick_add").val(),
23
             category_id: $("#categorycode_entry_quick_add").val(),
24
         });
25
     }
26
 });
27
28
 /**
29
  * Sends a GET request to the /api/v1/patron_categories endpoint to fetch patron categories
30
  *
31
  * Upon success, adds the categories to the category dropdown
32
  */
33
 function _GETPatronCategories() {
34
     $.ajax({
35
         url: "/api/v1/patron_categories",
36
         type: "GET",
37
         success: function (data) {
38
             let groupedCategories = Object.groupBy(
39
                 data,
40
                 ({ category_type }) => category_type
41
             );
42
43
             // Add <optgroup>
44
             $.each(groupedCategories, function (category_code, categories) {
45
                 $("#categorycode_entry_quick_add").append(
46
                     $(
47
                         '<optgroup id="' +
48
                             category_code +
49
                             '"label="' +
50
                             _getCategoryTypeName(category_code) +
51
                             '"></optgroup>'
52
                     )
53
                 );
54
55
                 // Add <option>
56
                 $.each(categories, function (i, category) {
57
                     $(
58
                         "#categorycode_entry_quick_add #" + category_code
59
                     ).append(
60
                         $("<option></option>")
61
                             .val(category.patron_category_id)
62
                             .html(category.name)
63
                     );
64
                 });
65
             });
66
         },
67
         error: function (data) {
68
             console.log(data);
69
         },
70
     });
71
 }
72
73
 /**
74
  * Sends a GET request to the /api/v1/libraries endpoint to fetch libraries
75
  *
76
  * Upon success, adds the libraries to the library dropdown
77
  */
78
 function _GETLibraries() {
79
     $.ajax({
80
         url: "/api/v1/libraries",
81
         type: "GET",
82
         success: function (data) {
83
             $.each(data, function (val, text) {
84
                 $("#libraries_quick_add").append(
85
                     $("<option></option>").val(text.library_id).html(text.name)
86
                 );
87
             });
88
         },
89
         error: function (data) {
90
             console.log(data);
91
         },
92
     });
93
 }
94
95
 /**
96
  * Sends a POST request to the /api/v1/patrons endpoint to add a new patron
97
  *
98
  * Upon completion, show a dialog with appropriate message
99
  * Upon success, add new patron's cardnumber to the cardnumber input
100
  *
101
  * @param {Object}   params           Patron's data to be posted.
102
  */
103
 function _POSTPatron(params) {
104
     $.ajax({
105
         url: "/api/v1/patrons",
106
         type: "POST",
107
         headers: { "Content-Type": "application/json;charset=utf-8" },
108
         data: JSON.stringify(params),
109
         success: function (data) {
110
             $("#user-submit-spinner").hide();
111
             $("#addQuickAddUserModal").modal("hide");
112
             $("#surname_quick_add").val("");
113
             $("#cardnumber_quick_add").val("");
114
             $("#toolbar").before(
115
                 '<div class="dialog message">' +
116
                     __(
117
                         'Patron sucessfully created: </br> <strong><a target="_blank" href="/cgi-bin/koha/members/moremember.pl?borrowernumber=' +
118
                             data.patron_id +
119
                             '">' +
120
                             data.surname +
121
                             "(" +
122
                             data.cardnumber +
123
                             ")"
124
                     ) +
125
                     "</div>"
126
             );
127
            //  create_form_cardnumber_input.val(data.cardnumber);
128
         },
129
         error: function (data) {
130
             console.log(data);
131
             $("#user-submit-spinner").hide();
132
             $("#addQuickAddUserModal").modal("hide");
133
             $("#interlibraryloans").before(
134
                 '<div class="dialog alert">' +
135
                     __(
136
                         "There was an error creating the patron: </br> <strong>" +
137
                             (data.responseJSON.error
138
                                 ? data.responseJSON.error
139
                                 : data.responseJSON.errors
140
                                       .map((e) => e.path + " " + e.message)
141
                                       .join("</br>")) +
142
                             "</strong>"
143
                     ) +
144
                     "</div>"
145
             );
146
         },
147
     });
148
 }
149
});

Return to bug 36179