web/data/cubicweb.preferences.js
branchstable
changeset 1870 015dfeaf1d89
parent 1865 62d3726ad8cb
child 1992 b073057c2756
equal deleted inserted replaced
1868:af1ae863606d 1870:015dfeaf1d89
     9     jQuery('#' + elemId).toggleClass('hidden');
     9     jQuery('#' + elemId).toggleClass('hidden');
    10 }
    10 }
    11 
    11 
    12 function closeFieldset(fieldsetid){
    12 function closeFieldset(fieldsetid){
    13     var linklabel = _('open all');
    13     var linklabel = _('open all');
    14     var linkhref = 'javascript:openFieldset("' +fieldsetid + '")'
    14     var linkhref = 'javascript:openFieldset("' +fieldsetid + '")';
    15     _toggleFieldset(fieldsetid, 1, linklabel, linkhref)
    15     _toggleFieldset(fieldsetid, 1, linklabel, linkhref);
    16 }
    16 }
    17 
    17 
    18 function openFieldset(fieldsetid){
    18 function openFieldset(fieldsetid){
    19     var linklabel = _('close all');
    19     var linklabel = _('close all');
    20     var linkhref = 'javascript:closeFieldset("'+ fieldsetid + '")'
    20     var linkhref = 'javascript:closeFieldset("'+ fieldsetid + '")';
    21     _toggleFieldset(fieldsetid, 0, linklabel, linkhref)
    21     _toggleFieldset(fieldsetid, 0, linklabel, linkhref);
    22 }
    22 }
    23 
    23 
    24 
    24 
    25 function _toggleFieldset(fieldsetid, closeaction, linklabel, linkhref){
    25 function _toggleFieldset(fieldsetid, closeaction, linklabel, linkhref){
    26     jQuery('#'+fieldsetid).find('div.openlink').each(function(){
    26     jQuery('#'+fieldsetid).find('div.openlink').each(function(){
    27 	    var link = A({'href' : "javascript:noop();",
    27 	    var link = A({'href' : "javascript:noop();",
    28 			  'onclick' : linkhref},
    28 			  'onclick' : linkhref},
    29 			  linklabel)
    29 			  linklabel);
    30 	    jQuery(this).empty().append(link);
    30 	    jQuery(this).empty().append(link);
    31 	});
    31 	});
    32     jQuery('#'+fieldsetid).find('fieldset[id]').each(function(){
    32     jQuery('#'+fieldsetid).find('fieldset[id]').each(function(){
    33 	    var fieldset = jQuery(this);
    33 	    var fieldset = jQuery(this);
    34 	    if(closeaction){
    34 	    if(closeaction){
    35 		fieldset.addClass('hidden')
    35 		fieldset.addClass('hidden');
    36 	    }else{
    36 	    }else{
    37 		fieldset.removeClass('hidden');
    37 		fieldset.removeClass('hidden');
    38 		linkLabel = (_('open all'));
    38 		linkLabel = (_('open all'));
    39 	    }
    39 	    }
    40 	});
    40 	});
    41 }
    41 }
    42 
    42 
    43 function validatePrefsForm(formid){
    43 function validatePrefsForm(formid){
    44     freezeFormButtons(formid);
       
    45     clearPreviousMessages();
    44     clearPreviousMessages();
    46     clearPreviousErrors(formid);
    45     clearPreviousErrors(formid);
    47     return validateForm(formid, null,  submitSucces, submitFailure);
    46     return validateForm(formid, null,  submitSucces, submitFailure);
    48 }
    47 }
    49 
    48 
    77 }
    76 }
    78 
    77 
    79 
    78 
    80 function checkValues(form, success){
    79 function checkValues(form, success){
    81     var unfreezeButtons = false;
    80     var unfreezeButtons = false;
    82     jQuery(form).find('select').each(function () { 
    81     jQuery(form).find('select').each(function () {
    83 	    unfreezeButtons = _checkValue(jQuery(this), unfreezeButtons);
    82 	    unfreezeButtons = _checkValue(jQuery(this), unfreezeButtons);
    84 	});
    83 	});
    85     jQuery(form).find('[type=text]').each(function () {
    84     jQuery(form).find('[type=text]').each(function () {
    86 	    unfreezeButtons = _checkValue(jQuery(this), unfreezeButtons);
    85 	    unfreezeButtons = _checkValue(jQuery(this), unfreezeButtons);
    87 	});
    86 	});
    88     jQuery(form).find('input[type=radio]').each(function () { 
    87     jQuery(form).find('input[type=radio]').each(function () {
    89 	    if (jQuery(this).attr('checked')){
    88 	    if (jQuery(this).attr('checked')){
    90 		unfreezeButtons = _checkValue(jQuery(this), unfreezeButtons);
    89 		unfreezeButtons = _checkValue(jQuery(this), unfreezeButtons);
    91 	    }
    90 	    }
    92      }); 
    91      });
    93     
    92 
    94     if (unfreezeButtons){
    93     if (unfreezeButtons){
    95 	unfreezeFormButtons(form.attr('id'));
    94 	unfreezeFormButtons(form.attr('id'));
    96     }else{
    95     }else{
    97 	if (!success){
    96 	if (!success){
    98 	    clearPreviousMessages();
    97 	    clearPreviousMessages();
   108 	 input.addClass('changed');
   107 	 input.addClass('changed');
   109 	 unfreezeButtons = true;
   108 	 unfreezeButtons = true;
   110      }else{
   109      }else{
   111 	 input.removeClass('changed');
   110 	 input.removeClass('changed');
   112 	 jQuery("span[id=err-" + input.attr('id') + "]").remove();
   111 	 jQuery("span[id=err-" + input.attr('id') + "]").remove();
   113      }	
   112      }
   114      input.removeClass('error');
   113      input.removeClass('error');
   115      return unfreezeButtons
   114      return unfreezeButtons;
   116 }
   115 }
   117 
   116 
   118 
   117 
   119 function setCurrentValues(form){
   118 function setCurrentValues(form){
   120     jQuery(form).find('input[name^=current-value]').each(function () { 
   119     jQuery(form).find('input[name^=current-value]').each(function () {
   121 	    var currentValueInput = jQuery(this);
   120 	    var currentValueInput = jQuery(this);
   122 	    var name = currentValueInput.attr('name').split('-')[1];
   121 	    var name = currentValueInput.attr('name').split('-')[1];
   123 	    jQuery(form).find("[name=" + name + "]").each(function (){
   122 	    jQuery(form).find("[name=" + name + "]").each(function (){
   124 		    var input = jQuery(this);
   123 		    var input = jQuery(this);
   125 		    if(input.attr('type')=='radio'){
   124 		    if(input.attr('type')=='radio'){
   132 		});
   131 		});
   133     });
   132     });
   134 }
   133 }
   135 
   134 
   136 function initEvents(){
   135 function initEvents(){
   137   jQuery('form').each(function() { 
   136   jQuery('form').each(function() {
   138 	  var form = jQuery(this);
   137 	  var form = jQuery(this);
   139 	  freezeFormButtons(form.attr('id'));
   138 	  freezeFormButtons(form.attr('id'));
   140 	  form.find('input[type=text]').keyup(function(){  
   139 	  form.find('input[type=text]').keyup(function(){
   141 		  checkValues(form);	   
   140 		  checkValues(form);
   142           });
   141           });
   143 	  form.find('input[type=radio]').change(function(){  
   142 	  form.find('input[type=radio]').change(function(){
   144 		  checkValues(form);	   
   143 		  checkValues(form);
   145           });
   144           });
   146 	  form.find('select').change(function(){  
   145 	  form.find('select').change(function(){
   147 		  checkValues(form);	 
   146 		  checkValues(form);
   148           });
   147           });
   149 	  setCurrentValues(form);
   148 	  setCurrentValues(form);
   150     });
   149     });
   151 }
   150 }
   152 
   151