web/data/cubicweb.preferences.js
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 19 Oct 2010 14:06:26 +0200
changeset 6551 50ec97e4f9cc
parent 6549 be6d49623207
child 6554 d60250252fc6
permissions -rw-r--r--
breadcrumbs/edid_box are now contextual component (closes #1334196)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
c3beb65d884d simplify js
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1992
diff changeset
     8
var prefsValues = {};
c3beb65d884d simplify js
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1992
diff changeset
     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) {
6549
be6d49623207 js cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5658
diff changeset
    54
    var $form = jQuery('#' + formid);
be6d49623207 js cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5658
diff changeset
    55
    var dom = DIV({'class': 'critical'}, _("please correct errors below"));
be6d49623207 js cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5658
diff changeset
    56
    $form.find('div.formsg').empty().append(dom);
1865
62d3726ad8cb restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1671
diff changeset
    57
    // clearPreviousMessages()
6549
be6d49623207 js cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5658
diff changeset
    58
    $form.find('span.error').next().focus();
1865
62d3726ad8cb restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1671
diff changeset
    59
}
62d3726ad8cb restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1671
diff changeset
    60
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    61
function submitSucces(url, formid) {
6549
be6d49623207 js cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5658
diff changeset
    62
    var $form = jQuery('#' + formid);
be6d49623207 js cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5658
diff changeset
    63
    setCurrentValues($form);
be6d49623207 js cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5658
diff changeset
    64
    var dom = DIV({'class': 'msg'}, _("changes applied"));
be6d49623207 js cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5658
diff changeset
    65
    $form.find('div.formsg').empty().append(dom);
be6d49623207 js cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5658
diff changeset
    66
    $form.find('input').removeClass('changed');
1612
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    67
    checkValues(form, true);
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    68
    return;
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    69
}
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    70
1865
62d3726ad8cb restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1671
diff changeset
    71
function clearPreviousMessages() {
1612
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    72
    jQuery('div#appMsg').addClass('hidden');
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    73
    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
    74
}
1612
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    75
1865
62d3726ad8cb restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1671
diff changeset
    76
function clearPreviousErrors(formid) {
62d3726ad8cb restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1671
diff changeset
    77
    jQuery('#err-value:' + formid).remove();
1612
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    78
}
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    79
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    80
function checkValues(form, success) {
1612
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    81
    var unfreezeButtons = false;
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    82
    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
    83
        unfreezeButtons = _checkValue(jQuery(this), unfreezeButtons);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    84
    });
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    85
    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
    86
        unfreezeButtons = _checkValue(jQuery(this), unfreezeButtons);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    87
    });
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    88
    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
    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
    });
1870
015dfeaf1d89 trailing space cleanup, js lint, a small indent for preference sections
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1865
diff changeset
    91
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    92
    if (unfreezeButtons) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    93
        unfreezeFormButtons(form.attr('id'));
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    94
    } else {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    95
        if (!success) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    96
            clearPreviousMessages();
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    97
        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    98
        clearPreviousErrors(form.attr('id'));
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    99
        freezeFormButtons(form.attr('id'));
1612
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   100
    }
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   101
}
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   102
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   103
function _checkValue(input, unfreezeButtons) {
2133
c3beb65d884d simplify js
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1992
diff changeset
   104
    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
   105
    if (currentValue != input.val()) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   106
        input.addClass('changed');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   107
        unfreezeButtons = true;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   108
    } else {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   109
        input.removeClass('changed');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   110
        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
   111
    }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   112
    input.removeClass('error');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   113
    return unfreezeButtons;
1612
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   114
}
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   115
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   116
function setCurrentValues(form) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   117
    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
   118
        var input = jQuery(this);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   119
        var name = input.attr('name');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   120
        if (input.attr('type') == 'radio') {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   121
            // 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
   122
            //       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
   123
            //       the DOM API instead.
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   124
            if (input[0].checked) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   125
                prefsValues[name] = input.val();
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   126
            }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   127
        } else {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   128
            prefsValues[name] = input.val();
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   129
        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   130
        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
   131
    });
1612
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   132
}
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
   133
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   134
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
   135
    jQuery('form').each(function() {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   136
        var form = jQuery(this);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   137
        //freezeFormButtons(form.attr('id'));
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   138
        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
   139
        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
   140
            checkValues(form);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   141
        });
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   142
        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
   143
            checkValues(form);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   144
        });
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   145
        form.find('select').change(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
        setCurrentValues(form);
1612
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   149
    });
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   150
}
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   151
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   152
$(document).ready(function() {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   153
    initEvents();
1612
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   154
});
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   155