Changeset - ff3f10a6a203
[Not reviewed]
beta
0 2 0
Mads Kiilerich - 13 years ago 2013-03-07 19:00:28
madski@unity3d.com
Transplanted from: 6b0c23e9b32f
pullrequest: just replace children of other_ref when other_repo changes

We were inserting a full select statement as innerHTML of a select and would
thus get nested select statements. IE did not render that correctly ... and
other browsers did strange things.

Instead we now create a in memory DOM object and move the optgroups. After
appending children to the selector we have to set selectedIndex on all
browsers.
2 files changed with 12 insertions and 20 deletions:
0 comments (0 inline, 0 general)
rhodecode/public/js/rhodecode.js
Show inline comments
 
@@ -65,61 +65,48 @@ String.prototype.rstrip = function(char)
 

	
 

	
 
if(!Array.prototype.indexOf) {
 
    Array.prototype.indexOf = function(needle) {
 
        for(var i = 0; i < this.length; i++) {
 
            if(this[i] === needle) {
 
                return i;
 
            }
 
        }
 
        return -1;
 
    };
 
}
 

	
 
// IE(CRAP) doesn't support previousElementSibling
 
var prevElementSibling = function( el ) {
 
    if( el.previousElementSibling ) {
 
        return el.previousElementSibling;
 
    } else {
 
        while( el = el.previousSibling ) {
 
            if( el.nodeType === 1 ) return el;
 
        }
 
    }
 
}
 

	
 
var setSelectValue = function(select, val){
 
	var selection =  YUD.get(select);
 
	
 
    // select element
 
    for(var i=0;i<selection.options.length;i++){
 
        if (selection.options[i].innerHTML == val) {
 
            selection.selectedIndex = i;
 
            break;
 
        }
 
    }	
 
}
 

	
 

	
 
/**
 
 * SmartColorGenerator
 
 *
 
 *usage::
 
 *	var CG = new ColorGenerator();
 
 *  var col = CG.getColor(key); //returns array of RGB
 
 *  'rgb({0})'.format(col.join(',')
 
 * 
 
 * @returns {ColorGenerator}
 
 */
 
var ColorGenerator = function(){
 
	this.GOLDEN_RATIO = 0.618033988749895;
 
	this.CURRENT_RATIO = 0.22717784590367374 // this can be random
 
	this.HSV_1 = 0.75;//saturation
 
	this.HSV_2 = 0.95;
 
	this.color;
 
	this.cacheColorMap = {};
 
};
 

	
 
ColorGenerator.prototype = {
 
    getColor:function(key){
 
    	if(this.cacheColorMap[key] !== undefined){
 
    		return this.cacheColorMap[key];
 
    	}
rhodecode/templates/pullrequests/pullrequest.html
Show inline comments
 
@@ -140,60 +140,65 @@
 

	
 
      var other_repo = YUQ('#pull_request_form #other_repo')[0].value;
 
      var other_ref = YUQ('#pull_request_form #other_ref')[0].value.split(':');
 

	
 
      var select_refs = YUQ('#pull_request_form select.refs')
 
      var rev_data = {
 
          'org_repo': org_repo,
 
          'org_ref': org_ref[2],
 
          'org_ref_type': 'rev',
 
          'other_repo': other_repo,
 
          'other_ref': other_ref[2],
 
          'other_ref_type': 'rev',
 
      }; // gather the org/other ref and repo here
 

	
 
      for (k in rev_data){
 
          url = url.replace('__'+k+'__',rev_data[k]);
 
      }
 

	
 
      YUD.get('pull_request_overview').innerHTML = "${_('Loading ...')}";
 
      YUD.get('pull_request_overview_url').href = url; // shouldn't have as_form ... but ...
 
      YUD.setStyle(YUD.get('pull_request_overview_url').parentElement,'display','');
 
      ypjax(url,'pull_request_overview', function(data){
 
          var sel_box = YUQ('#pull_request_form #other_repo')[0];
 
          var repo_name = sel_box.options[sel_box.selectedIndex].value;
 
          YUD.get('other_repo_desc').innerHTML = other_repos_info[repo_name]['description'];
 
          // replace options of other_ref with the ones for the current other_repo
 
          var other_ref_selector = YUD.get('other_ref');
 
          var new_select = YUD.createElementFromMarkup(other_repos_info[repo_name]['revs']);
 
          var new_selectedIndex = new_select.selectedIndex;
 
          other_ref_selector.innerHTML = ""; // clear old options
 
          while (new_select.length > 0){ // children will be popped when appened to other_ref_selector
 
              other_ref_selector.appendChild(new_select.children[0]);
 
          }
 
          // browsers lost track of selected when appendChild was used
 
          other_ref_selector.selectedIndex = new_selectedIndex;
 
          // reset && add the reviewer based on selected repo
 
          var _data = other_repos_info[repo_name];
 
          YUD.get('other_repo_desc').innerHTML = other_repos_info[repo_name]['description'];
 
          YUD.get('other_ref').innerHTML = other_repos_info[repo_name]['revs'];
 
          // select back the revision that was just compared
 
          setSelectValue(YUD.get('other_ref'), rev_data['other_ref']);
 
          // reset && add the reviewer based on selected repo
 
          YUD.get('review_members').innerHTML = '';
 
          addReviewMember(_data.user.user_id, _data.user.firstname,
 
                          _data.user.lastname, _data.user.username,
 
                          _data.user.gravatar_link);
 
      })
 
  }
 

	
 
  ## refresh automatically when something changes (org_repo can't change)
 

	
 
  YUE.on('org_ref', 'change', function(e){
 
     loadPreview();
 
  });
 

	
 
  YUE.on('other_repo', 'change', function(e){
 
      var repo_name = e.currentTarget.value;
 
      // replace the <select> of changed repo
 
      YUD.get('other_ref').innerHTML = other_repos_info[repo_name]['revs'];
 
      loadPreview();
 
  });
 

	
 
  YUE.on('other_ref', 'change', function(e){
 
     loadPreview();
 
  });
 

	
 
  //lazy load overview after 0.5s
 
  setTimeout(loadPreview, 500)
 

	
 
</script>
 

	
 
</%def>
0 comments (0 inline, 0 general)