web/data/cubicweb.preferences.js
author Julien Cristau <julien.cristau@logilab.fr>
Fri, 10 Jan 2014 15:02:07 +0100
changeset 9392 dd88d86d780a
parent 8185 864fc1f147a4
child 10027 292c81246347
permissions -rw-r--r--
[server] remove old backwards compat for PropagateSubjectRelation*Hook Those classes were removed from server/hook.py.
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
/**
6880
4be32427b2b9 [book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6554
diff changeset
     2
 * toggle visibility of an element by its id & set current visibility status in a cookie
4be32427b2b9 [book] fixes some references and other doc construction pbs
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6554
diff changeset
     3
 *
604
e85042d18b48 [preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     4
 */
1612
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
     5
2133
c3beb65d884d simplify js
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1992
diff changeset
     6
var prefsValues = {};
c3beb65d884d simplify js
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1992
diff changeset
     7
1865
62d3726ad8cb restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1671
diff changeset
     8
function togglePrefVisibility(elemId) {
62d3726ad8cb restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1671
diff changeset
     9
    clearPreviousMessages();
62d3726ad8cb restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1671
diff changeset
    10
    jQuery('#' + elemId).toggleClass('hidden');
1612
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    11
}
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    12
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    13
function closeFieldset(fieldsetid) {
8185
864fc1f147a4 [js, i18n] translated strings should use " not ' else they are discarded by xgettext. Closes #1892489
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7667
diff changeset
    14
    var linklabel = _("open all");
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    15
    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
    16
    _toggleFieldset(fieldsetid, 1, linklabel, linkhref);
1612
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    17
}
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    18
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    19
function openFieldset(fieldsetid) {
8185
864fc1f147a4 [js, i18n] translated strings should use " not ' else they are discarded by xgettext. Closes #1892489
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7667
diff changeset
    20
    var linklabel = _("close all");
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    21
    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
    22
    _toggleFieldset(fieldsetid, 0, linklabel, linkhref);
1612
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    23
}
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    24
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    25
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
    26
    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
    27
        var link = A({
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    28
            'href': "javascript:noop();",
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    29
            'onclick': linkhref
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    30
        },
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    31
        linklabel);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    32
        jQuery(this).empty().append(link);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    33
    });
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    34
    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
    35
        var fieldset = jQuery(this);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    36
        if (closeaction) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    37
            fieldset.addClass('hidden');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    38
        } else {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    39
            fieldset.removeClass('hidden');
8185
864fc1f147a4 [js, i18n] translated strings should use " not ' else they are discarded by xgettext. Closes #1892489
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7667
diff changeset
    40
            linkLabel = (_("open all"));
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    41
        }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    42
    });
1612
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    43
}
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    44
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    45
function validatePrefsForm(formid) {
1865
62d3726ad8cb restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1671
diff changeset
    46
    clearPreviousMessages();
6554
d60250252fc6 [js preferences] fix various pb with js for preferences form: buggy clearPreviousError, bad prototype of callbacks given to validate form, dunno how error display was expecting to work...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6549
diff changeset
    47
    _clearPreviousErrors(formid);
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    48
    return validateForm(formid, null, submitSucces, submitFailure);
1612
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    49
}
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    50
6554
d60250252fc6 [js preferences] fix various pb with js for preferences form: buggy clearPreviousError, bad prototype of callbacks given to validate form, dunno how error display was expecting to work...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6549
diff changeset
    51
function submitFailure(result, formid, cbargs) {
6549
be6d49623207 js cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5658
diff changeset
    52
    var $form = jQuery('#' + formid);
be6d49623207 js cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5658
diff changeset
    53
    var dom = DIV({'class': 'critical'}, _("please correct errors below"));
be6d49623207 js cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5658
diff changeset
    54
    $form.find('div.formsg').empty().append(dom);
6554
d60250252fc6 [js preferences] fix various pb with js for preferences form: buggy clearPreviousError, bad prototype of callbacks given to validate form, dunno how error display was expecting to work...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6549
diff changeset
    55
    unfreezeFormButtons(formid);
d60250252fc6 [js preferences] fix various pb with js for preferences form: buggy clearPreviousError, bad prototype of callbacks given to validate form, dunno how error display was expecting to work...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6549
diff changeset
    56
    var descr = result[1];
d60250252fc6 [js preferences] fix various pb with js for preferences form: buggy clearPreviousError, bad prototype of callbacks given to validate form, dunno how error display was expecting to work...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6549
diff changeset
    57
    _displayValidationerrors(formid, descr[0], descr[1]);
6549
be6d49623207 js cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5658
diff changeset
    58
    $form.find('span.error').next().focus();
6554
d60250252fc6 [js preferences] fix various pb with js for preferences form: buggy clearPreviousError, bad prototype of callbacks given to validate form, dunno how error display was expecting to work...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6549
diff changeset
    59
    return false; // so handleFormValidationResponse doesn't try to display error
1865
62d3726ad8cb restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1671
diff changeset
    60
}
62d3726ad8cb restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1671
diff changeset
    61
6554
d60250252fc6 [js preferences] fix various pb with js for preferences form: buggy clearPreviousError, bad prototype of callbacks given to validate form, dunno how error display was expecting to work...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6549
diff changeset
    62
function submitSucces(result, formid, cbargs) {
6549
be6d49623207 js cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5658
diff changeset
    63
    var $form = jQuery('#' + formid);
be6d49623207 js cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5658
diff changeset
    64
    setCurrentValues($form);
be6d49623207 js cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5658
diff changeset
    65
    var dom = DIV({'class': 'msg'}, _("changes applied"));
be6d49623207 js cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5658
diff changeset
    66
    $form.find('div.formsg').empty().append(dom);
be6d49623207 js cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5658
diff changeset
    67
    $form.find('input').removeClass('changed');
1612
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    68
    checkValues(form, true);
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    69
    return;
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    70
}
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    71
1865
62d3726ad8cb restore ajax validation cwpreferencies
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1671
diff changeset
    72
function clearPreviousMessages() {
1612
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    73
    jQuery('div#appMsg').addClass('hidden');
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    74
    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
    75
}
1612
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    76
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    77
function checkValues(form, success) {
1612
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    78
    var unfreezeButtons = false;
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    79
    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
    80
        unfreezeButtons = _checkValue(jQuery(this), unfreezeButtons);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    81
    });
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    82
    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
    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('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
    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
    });
1870
015dfeaf1d89 trailing space cleanup, js lint, a small indent for preference sections
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1865
diff changeset
    88
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    89
    if (unfreezeButtons) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    90
        unfreezeFormButtons(form.attr('id'));
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    91
    } else {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    92
        if (!success) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    93
            clearPreviousMessages();
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    94
        }
6554
d60250252fc6 [js preferences] fix various pb with js for preferences form: buggy clearPreviousError, bad prototype of callbacks given to validate form, dunno how error display was expecting to work...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6549
diff changeset
    95
        _clearPreviousErrors(form.attr('id'));
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
    96
        freezeFormButtons(form.attr('id'));
1612
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    97
    }
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    98
}
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    99
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   100
function _checkValue(input, unfreezeButtons) {
2133
c3beb65d884d simplify js
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 1992
diff changeset
   101
    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
   102
    if (currentValue != input.val()) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   103
        input.addClass('changed');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   104
        unfreezeButtons = true;
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   105
    } else {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   106
        input.removeClass('changed');
7667
600b407ae5c0 [preferences js] jquery 1.6 needs quote when querying attribute value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6880
diff changeset
   107
        jQuery('span[id="err-' + input.attr('id') + '"]').remove();
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   108
    }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   109
    input.removeClass('error');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   110
    return unfreezeButtons;
1612
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   111
}
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   112
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   113
function setCurrentValues(form) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   114
    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
   115
        var input = jQuery(this);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   116
        var name = input.attr('name');
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   117
        if (input.attr('type') == 'radio') {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   118
            // 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
   119
            //       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
   120
            //       the DOM API instead.
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   121
            if (input[0].checked) {
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   122
                prefsValues[name] = input.val();
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   123
            }
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   124
        } else {
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
        }
7667
600b407ae5c0 [preferences js] jquery 1.6 needs quote when querying attribute value
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6880
diff changeset
   127
        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
   128
    });
1612
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   129
}
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
   130
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   131
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
   132
    jQuery('form').each(function() {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   133
        var form = jQuery(this);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   134
        //freezeFormButtons(form.attr('id'));
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   135
        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
   136
        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
   137
            checkValues(form);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   138
        });
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   139
        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
   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('select').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
        setCurrentValues(form);
1612
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   146
    });
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   147
}
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   148
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   149
$(document).ready(function() {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   150
    initEvents();
1612
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   151
});
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 4280
diff changeset
   152