Bug 16795 - Patron categories: Accept integers only for enrolment period and age...
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / js / categories.js
1 jQuery.validator.addMethod( "letters_numbers", function(value,element){
2     var patt = /^[a-zA-Z0-9\-_]+$/g;
3     if (patt.test(element.value)) {
4         return true;
5     } else {
6         return false;
7     }
8     }, MSG_CATEGORYCODE_CHARS
9 );
10
11 jQuery.validator.addMethod( "enrollment_period", function(){
12         enrolmentperiod = $("#enrolmentperiod").val();
13         enrolmentperioddate = $("#enrolmentperioddate").val();
14         if ( $("#enrolmentperiod").val() !== "" && $("#enrolmentperioddate").val() !== "" ) {
15             return false;
16         } else {
17             return true;
18         }
19     }, MSG_ONE_ENROLLMENTPERIOD
20 );
21
22
23 $(document).ready(function() {
24     $("#table_categorie").dataTable($.extend(true, {}, dataTablesDefaults, {
25         "aoColumnDefs": [{
26             "aTargets": [-1],
27             "bSortable": false,
28             "bSearchable": false
29         }, {
30             "aTargets": [3, 4, 5],
31             "sType": "natural"
32         }, ],
33         "aaSorting": [
34             [1, "asc"]
35         ],
36         "sPaginationType": "four_button"
37     }));
38
39     $("#enrolmentperioddate").datepicker({
40         minDate: 1
41     }); // Require that "until date" be in the future
42
43     if ($("#branches option:selected").length < 1) {
44         $("#branches option:first").attr("selected", "selected");
45     }
46
47     $("#categorycode").on("blur",function(){
48         toUC(this);
49     });
50
51     $("#category_form").validate({
52         rules: {
53             categorycode: {
54                 required: true,
55                 letters_numbers: true
56             },
57             description: "required",
58             enrolmentperiod: {
59                 required: function(element){
60                     return $("#enrolmentperioddate").val() === "";
61                 },
62                 digits: true,
63                 enrollment_period: true
64             },
65             enrolmentperioddate: {
66                 required: function(element){
67                     return $("#enrolmentperiod").val() === "";
68                 },
69                 enrollment_period: true
70             },
71             dateofbirthrequired: {
72                 digits: true
73             },
74             upperagelimit: {
75                 digits: true
76             },
77             enrolmentfee: {
78                 number: true
79             },
80             reservefee: {
81                 number: true
82             },
83             category_type: {
84                 required: true
85             }
86         },
87         messages: {
88             enrolmentperiod: {
89                 required: MSG_ONE_ENROLLMENTPERIOD
90             },
91             enrolmentperioddate: {
92                 required: MSG_ONE_ENROLLMENTPERIOD
93             }
94         }
95
96     });
97 });