author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Sat, 09 Oct 2010 00:05:52 +0200 | |
changeset 6427 | c8a5ac2d1eaa |
parent 5658 | 7b9553a9db65 |
child 6549 | be6d49623207 |
permissions | -rw-r--r-- |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
1 |
/** |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
2 |
* toggle visibility of an element by its id |
604
e85042d18b48
[preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
3 |
* & set current visibility status in a cookie |
e85042d18b48
[preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
4 |
* XXX whenever used outside of preferences, don't forget to |
e85042d18b48
[preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
5 |
* move me in a more appropriate place |
e85042d18b48
[preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
6 |
*/ |
1612
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
7 |
|
2133 | 8 |
var prefsValues = {}; |
9 |
||
1865
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1671
diff
changeset
|
10 |
function togglePrefVisibility(elemId) { |
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1671
diff
changeset
|
11 |
clearPreviousMessages(); |
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1671
diff
changeset
|
12 |
jQuery('#' + elemId).toggleClass('hidden'); |
1612
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
13 |
} |
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
14 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
15 |
function closeFieldset(fieldsetid) { |
1612
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
16 |
var linklabel = _('open all'); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
17 |
var linkhref = 'javascript:openFieldset("' + fieldsetid + '")'; |
1870
015dfeaf1d89
trailing space cleanup, js lint, a small indent for preference sections
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1865
diff
changeset
|
18 |
_toggleFieldset(fieldsetid, 1, linklabel, linkhref); |
1612
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
19 |
} |
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
20 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
21 |
function openFieldset(fieldsetid) { |
1612
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
22 |
var linklabel = _('close all'); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
23 |
var linkhref = 'javascript:closeFieldset("' + fieldsetid + '")'; |
1870
015dfeaf1d89
trailing space cleanup, js lint, a small indent for preference sections
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1865
diff
changeset
|
24 |
_toggleFieldset(fieldsetid, 0, linklabel, linkhref); |
1612
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
25 |
} |
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
26 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
27 |
function _toggleFieldset(fieldsetid, closeaction, linklabel, linkhref) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
28 |
jQuery('#' + fieldsetid).find('div.openlink').each(function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
29 |
var link = A({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
30 |
'href': "javascript:noop();", |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
31 |
'onclick': linkhref |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
32 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
33 |
linklabel); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
34 |
jQuery(this).empty().append(link); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
35 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
36 |
jQuery('#' + fieldsetid).find('fieldset[id]').each(function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
37 |
var fieldset = jQuery(this); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
38 |
if (closeaction) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
39 |
fieldset.addClass('hidden'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
40 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
41 |
fieldset.removeClass('hidden'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
42 |
linkLabel = (_('open all')); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
43 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
44 |
}); |
1612
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
45 |
} |
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
46 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
47 |
function validatePrefsForm(formid) { |
1865
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1671
diff
changeset
|
48 |
clearPreviousMessages(); |
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1671
diff
changeset
|
49 |
clearPreviousErrors(formid); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
50 |
return validateForm(formid, null, submitSucces, submitFailure); |
1612
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
51 |
} |
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
52 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
53 |
function submitFailure(formid) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
54 |
var form = jQuery('#' + formid); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
55 |
var dom = DIV({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
56 |
'class': 'critical' |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
57 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
58 |
_("please correct errors below")); |
1865
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1671
diff
changeset
|
59 |
jQuery(form).find('div.formsg').empty().append(dom); |
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1671
diff
changeset
|
60 |
// clearPreviousMessages() |
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1671
diff
changeset
|
61 |
jQuery(form).find('span.error').next().focus(); |
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1671
diff
changeset
|
62 |
} |
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1671
diff
changeset
|
63 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
64 |
function submitSucces(url, formid) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
65 |
var form = jQuery('#' + formid); |
1612
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
66 |
setCurrentValues(form); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
67 |
var dom = DIV({ |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
68 |
'class': 'msg' |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
69 |
}, |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
70 |
_("changes applied")); |
1612
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
71 |
jQuery(form).find('div.formsg').empty().append(dom); |
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
72 |
jQuery(form).find('input').removeClass('changed'); |
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
73 |
checkValues(form, true); |
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
74 |
return; |
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
75 |
} |
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
76 |
|
1865
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1671
diff
changeset
|
77 |
function clearPreviousMessages() { |
1612
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
78 |
jQuery('div#appMsg').addClass('hidden'); |
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
79 |
jQuery('div.formsg').empty(); |
604
e85042d18b48
[preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff
changeset
|
80 |
} |
1612
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
81 |
|
1865
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1671
diff
changeset
|
82 |
function clearPreviousErrors(formid) { |
62d3726ad8cb
restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
1671
diff
changeset
|
83 |
jQuery('#err-value:' + formid).remove(); |
1612
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
84 |
} |
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
85 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
86 |
function checkValues(form, success) { |
1612
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
87 |
var unfreezeButtons = false; |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
88 |
jQuery(form).find('select').each(function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
89 |
unfreezeButtons = _checkValue(jQuery(this), unfreezeButtons); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
90 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
91 |
jQuery(form).find('[type=text]').each(function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
92 |
unfreezeButtons = _checkValue(jQuery(this), unfreezeButtons); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
93 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
94 |
jQuery(form).find('input[type=radio]:checked').each(function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
95 |
unfreezeButtons = _checkValue(jQuery(this), unfreezeButtons); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
96 |
}); |
1870
015dfeaf1d89
trailing space cleanup, js lint, a small indent for preference sections
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1865
diff
changeset
|
97 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
98 |
if (unfreezeButtons) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
99 |
unfreezeFormButtons(form.attr('id')); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
100 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
101 |
if (!success) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
102 |
clearPreviousMessages(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
103 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
104 |
clearPreviousErrors(form.attr('id')); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
105 |
freezeFormButtons(form.attr('id')); |
1612
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
106 |
} |
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
107 |
} |
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
108 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
109 |
function _checkValue(input, unfreezeButtons) { |
2133 | 110 |
var currentValue = prefsValues[input.attr('name')]; |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
111 |
if (currentValue != input.val()) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
112 |
input.addClass('changed'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
113 |
unfreezeButtons = true; |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
114 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
115 |
input.removeClass('changed'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
116 |
jQuery("span[id=err-" + input.attr('id') + "]").remove(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
117 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
118 |
input.removeClass('error'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
119 |
return unfreezeButtons; |
1612
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
120 |
} |
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
121 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
122 |
function setCurrentValues(form) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
123 |
jQuery(form).find('[name^=value]').each(function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
124 |
var input = jQuery(this); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
125 |
var name = input.attr('name'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
126 |
if (input.attr('type') == 'radio') { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
127 |
// NOTE: there seems to be a bug with jQuery(input).attr('checked') |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
128 |
// in our case, we can't rely on its value, we use |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
129 |
// the DOM API instead. |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
130 |
if (input[0].checked) { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
131 |
prefsValues[name] = input.val(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
132 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
133 |
} else { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
134 |
prefsValues[name] = input.val(); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
135 |
} |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
136 |
jQuery(form).find('input[name=edits-' + name + ']').val(prefsValues[name]); |
2162
14088bb1a103
reindent, fix obscur perf pb w/ ff 3.0.11 by performing search on the form instead of the whole document
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2155
diff
changeset
|
137 |
}); |
1612
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
138 |
} |
2154
558079860667
[javascript][preferences] fix setCurrentValues to consider all kind of widgets (textarea, select, etc.) not just inputs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2133
diff
changeset
|
139 |
|
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
140 |
function initEvents() { |
2162
14088bb1a103
reindent, fix obscur perf pb w/ ff 3.0.11 by performing search on the form instead of the whole document
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2155
diff
changeset
|
141 |
jQuery('form').each(function() { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
142 |
var form = jQuery(this); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
143 |
//freezeFormButtons(form.attr('id')); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
144 |
form.find('.validateButton').attr('disabled', 'disabled'); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
145 |
form.find('input[type=text]').keyup(function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
146 |
checkValues(form); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
147 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
148 |
form.find('input[type=radio]').change(function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
149 |
checkValues(form); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
150 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
151 |
form.find('select').change(function() { |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
152 |
checkValues(form); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
153 |
}); |
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
154 |
setCurrentValues(form); |
1612
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
155 |
}); |
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
156 |
} |
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
157 |
|
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
158 |
$(document).ready(function() { |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
159 |
initEvents(); |
1612
0be8605c411a
validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
604
diff
changeset
|
160 |
}); |
5658
7b9553a9db65
[ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4280
diff
changeset
|
161 |