Bug 30708: Rebase - Use name instead of url for router-links
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / restrictiontypes.js
1 jQuery.validator.addMethod( "restrictionCode", function(value){
2     var ex = Object.keys(existing);
3     return (value.length > 0 && ex.indexOf(value.toUpperCase()) > -1) ?
4         false :
5         true;
6 }, MSG_DUPLICATE_CODE);
7
8 jQuery.validator.addMethod( "restrictionDisplayText", function(value){
9     var ex = Object.values(existing).map(function(el) {
10         return el.toLowerCase();
11     });
12     var code = $('input[name="code"]').val();
13     return (value.length > 0 && ex.indexOf(value.toLowerCase()) > -1) && existing[code] != value ?
14         false :
15         true;
16 }, MSG_DUPLICATE_DISPLAY_TEXT);
17
18 $(document).ready(function() {
19     KohaTable("restriction_types", {
20         "aoColumnDefs": [{
21             "aTargets": [-1],
22             "bSortable": false,
23             "bSearchable": false
24         }, {
25             "aTargets": [0, 1],
26             "sType": "natural"
27         }, ],
28         "aaSorting": [
29             [1, "asc"]
30         ],
31         "sPaginationType": "full",
32         "exportColumns": [0,1],
33     });
34
35     $("#restriction_form").validate({
36         rules: {
37             code: {
38                 required: true,
39                 restrictionCode: true
40             },
41             display_text: {
42                 required: true,
43                 restrictionDisplayText: true
44             }
45         },
46         messages: {
47             code: {
48                 restrictionCode: MSG_DUPLICATE_CODE
49             },
50             display_text: {
51                 restrictionDisplayText: MSG_DUPLICATE_DISPLAY_TEXT
52             }
53         }
54     });
55 });