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