Bug 19878: Move template JavaScript to the footer: UNIMARC editor plugins, part 7
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / onboarding.js
blob93cb010b0c8b80162ce8ee9bcfcd7458e7cf06d9
1 function _(s) { return s; } // dummy function for gettext
3 // http://stackoverflow.com/questions/1038746/equivalent-of-string-format-in-jquery/5341855#5341855
4 String.prototype.format = function() { return formatstr(this, arguments); };
5 function formatstr(str, col) {
6     col = typeof col === 'object' ? col : Array.prototype.slice.call(arguments, 1);
7     var idx = 0;
8     return str.replace(/%%|%s|%(\d+)\$s/g, function (m, n) {
9         if (m == "%%") { return "%"; }
10         if (m == "%s") { return col[idx++]; }
11         return col[n];
12     });
15 jQuery.validator.addMethod( "category_code_check", function(value,element){
16     var patt = /^[A-Za-z0-9]{0,10}$/g;
17     if (patt.test(element.value)) {
18         return true;
19     } else {
20         return false;
21     }
22     }, MSG_LETTERS_NUMBERS_ONLY
25 jQuery.validator.addMethod( "enrollment_period", function(){
26       enrolmentperiod = $("#enrolmentperiod").val();
27       enrolmentperioddate = $("#enrolmentperioddate").val();
28       if (( $("#enrolmentperiod").val() === "" && $("#enrolmentperioddate").val() === "") || ($("#enrolmentperiod").val() !== "" && $("#enrolmentperioddate").val() !== "")) {
29              return false;
30       } else {
31              return true;
32       }
33     }, MSG_ONLY_ONE_ENROLLMENTPERIOD
36 jQuery.validator.addMethod( "password_match", function(value,element){
37         var MSG_PASSWORD_MISMATCH = ( MSG_PASSWORD_MISMATCH );
38         var password = document.getElementById('password').value;
39         var confirmpassword = document.getElementById('password2').value;
41         if ( password != confirmpassword ){
42                return false;
43           }
44           else{
45                return true;
46           }
47     },  MSG_PASSWORD_MISMATCH
50 function toUC(f) {
51     var x=f.value.toUpperCase();
52     f.value=x;
53     return true;
56 $(document).ready(function() {
57     if ($("#branches option:selected").length < 1) {
58         $("#branches option:first").attr("selected", "selected");
59     }
60     $("#categorycode").on("blur",function(){
61          toUC(this);
62     });
64     $("#enrolmentperioddate").datepicker({
65         minDate: 1
66     }); // Require that "until date" be in the future
68     $("#category_form").validate({
69         rules: {
70             categorycode: {
71                 required: true,
72                 category_code_check: true
73             },
74             description: {
75                     required:true
76             },
77             enrolmentperiod: {
78                required: function(element){
79                      return $("#enrolmentperioddate").val() === "";
80                },
81                digits: true,
82                enrollment_period: true,
83             },
84             enrolmentperioddate: {
85                 required: function(element){
86                     return $("#enrolmentperiod").val() === "";
87                 },
88                 enrollment_period: true,
89                 // is_valid_date ($(#"enrolementperioddate").val());
90             },
91             dateofbirthrequired: {
92                 digits: true
93             },
94             upperagelimit: {
95                 digits: true
96             },
97             enrolmentfee: {
98                 number: true
99             },
100             reservefee: {
101                 number: true
102             },
103             category_type: {
104                 required: true
105             }
106         },
107         messages: {
108             enrolmentperiod: {
109                 required: MSG_ONE_ENROLLMENTPERIOD
110             },
111             enrolmentperioddate: {
112                 required: MSG_ONE_ENROLLMENTPERIOD
113             }
114         }
115     });
117     $("#createpatron").validate({
118         rules: {
119             surname: {
120                 required: true
121             },
122             firstname: {
123                 required: true
124             },
125             cardnumber: {
126                 required: true
127             },
128             password: {
129                 required: true,
130                 password_strong: true,
131                 password_no_spaces: true
132             },
133             password2: {
134                 required: true,
135                 password_match: true
136             }
137         },
138         messages: {
139             password: {
140                 required: MSG_PASSWORD_MISMATCH
141             },
142         }
144     });
146     $("#createitemform").validate();
147     $("#createcirculationrule").validate();