Statistics
| Branch: | Tag: | Revision:

root / snf-astakos-app / astakos / im / static / im / js / auth_methods.js @ 7b5bca4a

History | View | Annotate | Download (3.6 kB)

1
$(document).ready(function() {
2
                 
3
                 
4
         $('.auth_methods .canremove').click( function(e) {
5
            e.preventDefault(e);
6
            $(this).parent('li').addClass('remove');
7
            $(this).siblings('.dialog-wrap').slideDown('slow');
8
    })  
9
    
10
    $('.auth_methods .no').click( function(e) {
11
            e.preventDefault(e);
12
            $(this).parents('li').removeClass('remove');
13
            $(this).parents('.dialog-wrap').slideUp('slow');
14
    })  
15
    $('.auth_methods .canremove').hover(
16
      function () {
17
              $(this).siblings('span.details').hide();
18
      },
19
      function () {
20
              $(this).siblings('span.details').show();
21
      });
22
                 
23
        /* complex form js */
24
        
25
        // Intresting divs
26
        
27
        emailDiv = $('#id_email').parents('.form-row');
28
        newEmailDiv = $('#id_new_email_address').parents('.form-row');
29
        oldPasswordDiv = $('#id_old_password').parents('.form-row');
30
        newPassword1Div = $('#id_new_password1').parents('.form-row');
31
        newPassword2Div = $('#id_new_password2').parents('.form-row');
32
        emailCheck = $('#id_change_email').parents('.form-row');
33
        passwordCheck = $('#id_change_password').parents('.form-row');
34
        authTokenDiv = $('#id_auth_token').parents('.form-row');
35
        
36
        if ( newEmailDiv.length>0  ){ 
37
                emailDiv.addClass('form-following');
38
        }
39
        
40
        oldPasswordDiv.addClass('form-following');
41
        
42
        
43
        // Intresting img spans
44
        
45
        emailDiv.find('span.extra-img').attr('id','email-span');
46
        oldPasswordDiv.find('span.extra-img').attr('id','password-span');
47
        authTokenDiv.find('span.extra-img').attr('id','token-span');
48
        // Default hidden fields
49
        
50
        newEmailDiv.hide();
51
        newPassword1Div.hide();
52
        newPassword2Div.hide();
53
        emailCheck.hide();
54
        passwordCheck.hide();
55
        
56
        
57
        
58
        newEmailDiv.addClass('email-span');
59
        newPassword1Div.addClass('password-span');
60
        newPassword2Div.addClass('password-span');
61
        
62
        // If errors show fields
63
        
64
        
65
        if ($('input#id_change_password:checkbox').attr('checked')) {
66
                oldPasswordDiv.find('input').focus();
67
                newPassword1Div.show();
68
                newPassword2Div.show();
69
                $('.form-following #password-span').parents('.form-row').addClass('open');
70
        }; 
71
        
72
        
73
        
74
        if ($('input#id_change_password:checkbox').attr('checked')) {
75
                newEmailDiv.show();
76
                
77
                $('.form-following #email-span').parents('.form-row').addClass('open');
78
        }; 
79
        
80
        // Email, Password forms
81
        
82
        $('.form-following .extra-img').click(function(e){
83
                
84
                $(this).parents('.form-row').toggleClass('open');
85
                id = $(this).attr('id');
86
                $('.form-row').each(function() {
87
                        if( $(this).hasClass(id) ) {
88
                                $(this).toggle();
89
                        }
90
                }); 
91
         
92
                 
93
                 if ( !($(this).parents('.form-row').hasClass('open')) ){
94
                         $('.form-row').each(function() {
95
                                if( $(this).hasClass(id) ) {
96
                                        console.info($(this).find('input[type="text"]'));
97
                                        $(this).find('input').val('');
98
                                        $(this).removeClass('with-errors');
99
                                        $(this).find('.form-error').hide();
100
                                }
101
                        }); 
102
                 }         else {
103
                         // focus on first input
104
                         if ( id == 'email-span') { newEmailDiv.find('input').focus(); } 
105
                         if ( id == 'password-span') { oldPasswordDiv.find('input').focus(); }
106
                 }
107
        });
108
        
109
        //  check uncheck checkbox
110
        $('#email-span').click(function(){ 
111
       var $checkbox = $('input#id_change_email:checkbox');
112
       $checkbox.attr('checked', !$checkbox.attr('checked'));
113
         });
114
        
115
        //  check uncheck checkbox
116
        $('#password-span').click(function(){ 
117
       var $checkbox = $('input#id_change_password:checkbox');
118
       $checkbox.attr('checked', !$checkbox.attr('checked'));
119
         });
120
        
121
        // refresh token
122
        authTokenDiv.addClass('refresh');
123
        $('#token-span').click(function(e){
124
                renewToken();
125
        })
126
        
127
        
128
        
129
        /* end of complex form js */
130
        
131
         
132
            
133
});
134