web/data/cubicweb.preferences.js
author Katia Saurfelt <katia.saurfelt@logilab.fr>
Thu, 30 Apr 2009 16:16:20 +0200
changeset 1617 ac8a4ce6a830
parent 1612 0be8605c411a
child 1641 2c80b09d8d86
permissions -rw-r--r--
remove logs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
604
e85042d18b48 [preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     1
/* toggle visibility of an element by its id
e85042d18b48 [preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     2
 * & 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
     3
 * 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
     4
 *     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
     5
 */
1612
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
     6
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
     7
function toggleVisibility(elemId) {
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
     8
    _clearPreviousMessages();
604
e85042d18b48 [preferences] preferences sections will now remember their collapsed/open status
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     9
    jqNode(elemId).toggleClass('hidden');
1612
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    10
}
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
function closeFieldset(fieldsetid){
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    13
    var linklabel = _('open all');
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    14
    var linkhref = 'javascript:openFieldset("' +fieldsetid + '")'
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    15
    _toggleFieldset(fieldsetid, 1, linklabel, linkhref)
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    16
}
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
function openFieldset(fieldsetid){
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    19
    var linklabel = _('close all');
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    20
    var linkhref = 'javascript:closeFieldset("'+ fieldsetid + '")'
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    21
    _toggleFieldset(fieldsetid, 0, linklabel, linkhref)
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    22
}
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
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    25
function _toggleFieldset(fieldsetid, closeaction, linklabel, linkhref){
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    26
    jQuery('#'+fieldsetid).find('div.openlink').each(function(){
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    27
	    var link = A({'href' : "javascript:noop();",
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    28
			  'onclick' : linkhref},
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    29
			  linklabel)
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    30
	    jQuery(this).empty().append(link);
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    31
	});
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    32
    jQuery('#'+fieldsetid).find('fieldset[id]').each(function(){
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    33
	    var fieldset = jQuery(this);
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    34
	    if(closeaction){
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    35
		fieldset.addClass('hidden')
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    36
	    }else{
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    37
		fieldset.removeClass('hidden');
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    38
		linkLabel = (_('open all'));
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    39
	    }
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    40
	});
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    41
 
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    42
}
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
function validatePrefsForm(formid){
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    45
    var form = getNode(formid);
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    46
    freezeFormButtons(formid);
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    47
    try {
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    48
	var d = _sendForm(formid, null);
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    49
    } catch (ex) {
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    50
	log('got exception', ex);
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    51
	return false;
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    52
    }
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    53
    function _callback(result, req) {
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    54
	_clearPreviousMessages();
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    55
	_clearPreviousErrors(formid);
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    56
	// success
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    57
	if(result[0]){
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    58
	    return submitSucces(formid)
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    59
	}
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    60
 	// Failures
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    61
	unfreezeFormButtons(formid);
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    62
	var descr = result[1];
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    63
        if (!isArrayLike(descr) || descr.length != 2) {
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    64
	   log('got strange error :', descr);
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    65
	   updateMessage(descr);
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    66
	   return ;
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    67
	}
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    68
        _displayValidationerrors(formid, descr[0], descr[1]);
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    69
	var dom = DIV({'class':'critical'},
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    70
		      _("please correct errors below"));
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
	updateMessage(_(""));
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    73
	return false;
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    74
    }
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    75
    d.addCallback(_callback);
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    76
    return false;
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    77
}
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
function submitSucces(formid){
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    80
    var form = jQuery('#'+formid);
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    81
    setCurrentValues(form);
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    82
    var dom = DIV({'class':'message'},
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    83
		  _("changes applied"));
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    84
    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
    85
    jQuery(form).find('input').removeClass('changed');
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    86
    checkValues(form, true);
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    87
    return;
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    88
}
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    89
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    90
function _clearPreviousMessages() {
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    91
    jQuery('div#appMsg').addClass('hidden');
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    92
    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
    93
}
1612
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    94
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    95
function _clearPreviousErrors(formid) {
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
    96
    jQuery('#' + formid + ' span.error').remove();
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
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   100
function checkValues(form, success){
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   101
    var unfreezeButtons = false;
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   102
    jQuery(form).find('select').each(function () { 
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   103
	    unfreezeButtons = _checkValue(jQuery(this), unfreezeButtons);
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   104
	});
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   105
    jQuery(form).find('[type=text]').each(function () {
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   106
	    unfreezeButtons = _checkValue(jQuery(this), unfreezeButtons);
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
    jQuery(form).find('input[type=radio]').each(function () { 
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   109
	    if (jQuery(this).attr('checked')){
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   110
		unfreezeButtons = _checkValue(jQuery(this), unfreezeButtons);
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
     }); 
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   113
   
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   114
    if (unfreezeButtons){
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   115
	unfreezeFormButtons(form.attr('id'));
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   116
    }else{
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   117
	if (!success){
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   118
	    _clearPreviousMessages();
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   119
	}
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   120
	_clearPreviousErrors(form.attr('id'));
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   121
	freezeFormButtons(form.attr('id'));
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   122
    }
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   123
}
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   124
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   125
function _checkValue(input, unfreezeButtons){
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   126
     var currentValueInput = jQuery("input[id=current-" + input.attr('name') + "]");
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   127
     if (currentValueInput.attr('value') != input.attr('value')){
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   128
	 input.addClass('changed');
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   129
	 unfreezeButtons = true;
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   130
     }else{
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   131
	 input.removeClass('changed');
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   132
	 jQuery("span[id=err-" + input.attr('id') + "]").remove();
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   133
     }	
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   134
     input.removeClass('error');
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   135
     return unfreezeButtons
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   136
}
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   137
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   138
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   139
function setCurrentValues(form){
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   140
    jQuery(form).find('input[id^=current-value]').each(function () { 
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   141
	    var currentValueInput = jQuery(this);
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   142
	    var name = currentValueInput.attr('id').split('-')[1];
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   143
	    jQuery(form).find("[name=" + name + "]").each(function (){
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   144
		    var input = jQuery(this);
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   145
		    if(input.attr('type')=='radio'){
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   146
			if(input.attr('checked')){
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   147
			    log(input.attr('value'));
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   148
			    currentValueInput.attr('value', input.attr('value'));
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
		    }else{
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   151
			currentValueInput.attr('value', input.attr('value'));
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   152
		    }
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   153
		});
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   154
    });
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
function initEvents(){
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   159
  jQuery('form').each(function() { 
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   160
	  var form = jQuery(this);
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   161
	  freezeFormButtons(form.attr('id'));
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   162
	  form.find('input[type=text]').keyup(function(){  
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   163
		  checkValues(form);	   
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   164
          });
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   165
	  form.find('input[type=radio]').change(function(){  
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   166
		  checkValues(form);	   
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   167
          });
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   168
	  form.find('select').change(function(){  
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   169
		  checkValues(form);	 
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   170
          });
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   171
    });
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   172
}
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   173
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   174
$(document).ready(function() {
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   175
	initEvents();
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   176
});
0be8605c411a validation of preferencies done by ajax
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents: 604
diff changeset
   177