Bug 19918: Close span tag in opac-registration-confirmation.tt
[koha.git] / koha-tmpl / intranet-tmpl / prog / js / automatic_item_modification_by_age.js
1 function clear_inputs(node, new_node) {
2     var selects = $(node).find("select");
3     $(selects).each(function(i) {
4         var select = this;
5         $(new_node).find("select").eq(i).val($(select).val());
6     });
7     var inputs = $(node).find("input");
8     $(inputs).each(function(i) {
9         var input = this;
10         $(new_node).find("input").eq(i).val($(input).val());
11     });
12 }
13
14 function remove_block_action( link ) {
15     var blocks = $(link).parent().parent();
16     if( $(blocks).find(".block").length > 2 ) {
17         $(blocks).find("a.remove_block").show();
18     } else {
19         $(blocks).find("a.remove_block").hide();
20     }
21     $(link).parent().remove();
22 }
23
24 function remove_rule_action( link ) {
25     if( $("#rules").find(".rule").length < 2 ) {
26             $("#rules").hide();
27             $("#norules").show();
28     }
29     $(link).parent().parent().remove();
30     update_rule_count();
31 }
32
33 function clone_block(block) {
34     var new_block = $(block).clone(1);
35     clear_inputs(block, new_block);
36     $(new_block).find('a.remove_block').show();
37     var blocks = $(block).parent();
38     $(blocks).append(new_block);
39     $(blocks).find('a.remove_block').click(function(e){
40         e.preventDefault();
41         remove_block_action($(this));
42     }).show();
43 }
44
45 function update_rule_count(){
46     rules = $(".rulecount");
47     rules.each( function( i ){
48         $(this).text( i + 1 );
49     });
50 }
51
52 $(document).ready(function() {
53     $("#new_rule .remove_rule").hide();
54     $("#new_rule a.remove_block").hide();
55     $("#rules a.remove_block").click(function(e){
56         e.preventDefault();
57         remove_block_action($(this));
58     });
59     $("#rules .remove_rule").click(function(e){
60         e.preventDefault();
61         remove_rule_action($(this));
62     });
63
64     var unique_id = $(".rule").length + 1;
65     $(".add_rule").click(function(e){
66         e.preventDefault();
67         var rule = $("#new_rule");
68         var rules = $("#rules");
69         var new_rule = rule.clone(1);
70         new_rule.removeAttr('id');
71         new_rule.attr('class', 'rule');
72         clear_inputs(rule, new_rule);
73         new_rule.find("select[name='condition_field']").attr('name', 'condition_field_' + unique_id);
74         new_rule.find("select[name='substitution_field']").attr('name', 'substitution_field_' + unique_id);
75         new_rule.find("input[name='condition_value']").attr('name', 'condition_value_' + unique_id);
76         new_rule.find("input[name='substitution_value']").attr('name', 'substitution_value_' + unique_id);
77         new_rule.find("input[name='age']").attr('name', 'age_' + unique_id);
78         new_rule.find("input[name='unique_id']").val(unique_id);
79
80         $("#rules").append(new_rule);
81         update_rule_count();
82         var scrollToPoint = new_rule.position();
83         window.scroll(0, scrollToPoint.top - $("#toolbar").height() );
84
85         if( $("#rules").find(".rule").length > 0 ) {
86                 $("#rules").show();
87                 $("#norules").hide();
88         }
89         if( $("#rules").find(".conditions > .condition").length > 1 ) {
90
91         }
92         if( $("#rules").find(".conditions > .condition").length > 1 ) {
93
94         }
95         new_rule.find('.remove_rule').click(function(e){
96             e.preventDefault();
97             remove_rule_action( $(this) );
98         }).show();
99         new_rule.find('.add_rule').remove();
100         unique_id++;
101     });
102
103     $("a.add_block").click(function(e){
104         e.preventDefault();
105         clone_block( $(this).parent() );
106     });
107
108     if( $("#rules").find(".rule").length < 1 ) {
109             $("#rules").hide();
110             $("#norules").show();
111     }
112
113     $("#rules .rule .blocks").each(function(){
114         if ( $(this).find(".block").length == 1 ) {
115             $(this).find("a.remove_block").hide();
116         }
117     });
118
119     jQuery.validator.addClassRules("age", {
120         digits: true
121     });
122
123     $("#rules_form").validate();
124 });