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