Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (4.3 kB)

1
function placeTokenConfirm(){
2
         
3
        var position = $('#token-span').parents('.form-row').position();
4
        $('#token-confirm').css('top', position.top - 10);
5
}
6

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