changeset 3512:ff3f10a6a203 beta

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.
author Mads Kiilerich <madski@unity3d.com>
date Thu, 07 Mar 2013 19:00:28 +0100
parents e1568c0bac1f
children a2a61978752f
files rhodecode/public/js/rhodecode.js rhodecode/templates/pullrequests/pullrequest.html
diffstat 2 files changed, 12 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/public/js/rhodecode.js	Sat Mar 09 15:10:05 2013 +0100
+++ b/rhodecode/public/js/rhodecode.js	Thu Mar 07 19:00:28 2013 +0100
@@ -86,19 +86,6 @@
     }
 }
 
-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
  *
--- a/rhodecode/templates/pullrequests/pullrequest.html	Sat Mar 09 15:10:05 2013 +0100
+++ b/rhodecode/templates/pullrequests/pullrequest.html	Thu Mar 07 19:00:28 2013 +0100
@@ -161,12 +161,19 @@
       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,
@@ -182,8 +189,6 @@
 
   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();
   });