diff --git a/rhodecode/public/js/src/rhodecode/pullrequests.js b/rhodecode/public/js/src/rhodecode/pullrequests.js --- a/rhodecode/public/js/src/rhodecode/pullrequests.js +++ b/rhodecode/public/js/src/rhodecode/pullrequests.js @@ -217,3 +217,126 @@ var ReviewerAutoComplete = function(inpu } }); }; + + +VersionController = function () { + var self = this; + this.$verSource = $('input[name=ver_source]'); + this.$verTarget = $('input[name=ver_target]'); + this.$showVersionDiff = $('#show-version-diff'); + + this.adjustRadioSelectors = function (curNode) { + var getVal = function (item) { + if (item == 'latest') { + return Number.MAX_SAFE_INTEGER + } + else { + return parseInt(item) + } + }; + + var curVal = getVal($(curNode).val()); + var cleared = false; + + $.each(self.$verSource, function (index, value) { + var elVal = getVal($(value).val()); + + if (elVal > curVal) { + if ($(value).is(':checked')) { + cleared = true; + } + $(value).attr('disabled', 'disabled'); + $(value).removeAttr('checked'); + $(value).css({'opacity': 0.1}); + } + else { + $(value).css({'opacity': 1}); + $(value).removeAttr('disabled'); + } + }); + + if (cleared) { + // if we unchecked an active, set the next one to same loc. + $(this.$verSource).filter('[value={0}]'.format( + curVal)).attr('checked', 'checked'); + } + + self.setLockAction(false, + $(curNode).data('verPos'), + $(this.$verSource).filter(':checked').data('verPos') + ); + }; + + + this.attachVersionListener = function () { + self.$verTarget.change(function (e) { + self.adjustRadioSelectors(this) + }); + self.$verSource.change(function (e) { + self.adjustRadioSelectors(self.$verTarget.filter(':checked')) + }); + }; + + this.init = function () { + + var curNode = self.$verTarget.filter(':checked'); + self.adjustRadioSelectors(curNode); + self.setLockAction(true); + self.attachVersionListener(); + + }; + + this.setLockAction = function (state, selectedVersion, otherVersion) { + var $showVersionDiff = this.$showVersionDiff; + + if (state) { + $showVersionDiff.attr('disabled', 'disabled'); + $showVersionDiff.addClass('disabled'); + $showVersionDiff.html($showVersionDiff.data('labelTextLocked')); + } + else { + $showVersionDiff.removeAttr('disabled'); + $showVersionDiff.removeClass('disabled'); + + if (selectedVersion == otherVersion) { + $showVersionDiff.html($showVersionDiff.data('labelTextShow')); + } else { + $showVersionDiff.html($showVersionDiff.data('labelTextDiff')); + } + } + + }; + + this.showVersionDiff = function () { + var target = self.$verTarget.filter(':checked'); + var source = self.$verSource.filter(':checked'); + + if (target.val() && source.val()) { + var params = { + 'pull_request_id': templateContext.pull_request_data.pull_request_id, + 'repo_name': templateContext.repo_name, + 'version': target.val(), + 'from_version': source.val() + }; + window.location = pyroutes.url('pullrequest_show', params) + } + + return false; + }; + + this.toggleVersionView = function (elem) { + + if (this.$showVersionDiff.is(':visible')) { + $('.version-pr').hide(); + this.$showVersionDiff.hide(); + $(elem).html($(elem).data('toggleOn')) + } else { + $('.version-pr').show(); + this.$showVersionDiff.show(); + $(elem).html($(elem).data('toggleOff')) + } + + return false + } + +}; \ No newline at end of file diff --git a/rhodecode/templates/pullrequests/pullrequest_show.mako b/rhodecode/templates/pullrequests/pullrequest_show.mako --- a/rhodecode/templates/pullrequests/pullrequest_show.mako +++ b/rhodecode/templates/pullrequests/pullrequest_show.mako @@ -607,125 +607,6 @@ } } - VersionController = function() { - var self = this; - this.$verSource = $('input[name=ver_source]'); - this.$verTarget = $('input[name=ver_target]'); - - this.adjustRadioSelectors = function (curNode) { - var getVal = function(item) { - if (item == 'latest'){ - return Number.MAX_SAFE_INTEGER - } - else { - return parseInt(item) - } - }; - - var curVal = getVal($(curNode).val()); - var cleared = false; - - $.each(self.$verSource, function(index, value){ - var elVal = getVal($(value).val()); - - if(elVal > curVal){ - if ($(value).is(':checked')) { - cleared = true; - } - $(value).attr('disabled', 'disabled'); - $(value).removeAttr('checked'); - $(value).css({'opacity': 0.1}); - } - else{ - $(value).css({'opacity': 1}); - $(value).removeAttr('disabled'); - } - }); - - if (cleared) { - // if we unchecked an active, set the next one to same loc. - $(this.$verSource).filter('[value={0}]'.format( - curVal)).attr('checked', 'checked'); - } - - self.setLockAction(false, - $(curNode).data('verPos'), - $(this.$verSource).filter(':checked').data('verPos') - ); - }; - - - this.attachVersionListener = function () { - self.$verTarget.change(function(e){ - self.adjustRadioSelectors(this) - }); - self.$verSource.change(function(e){ - self.adjustRadioSelectors(self.$verTarget.filter(':checked')) - }); - }; - - this.init = function () { - - var curNode = self.$verTarget.filter(':checked'); - self.adjustRadioSelectors(curNode); - self.setLockAction(true); - self.attachVersionListener(); - - }; - - this.setLockAction = function (state, selectedVersion, otherVersion) { - if (state) { - $('#show-version-diff').attr('disabled', 'disabled'); - $('#show-version-diff').addClass('disabled'); - $('#show-version-diff').html($('#show-version-diff').data('labelTextLocked')); - } - else { - $('#show-version-diff').removeAttr('disabled'); - $('#show-version-diff').removeClass('disabled'); - - if (selectedVersion == otherVersion) { - $('#show-version-diff').html($('#show-version-diff').data('labelTextShow')); - } else { - $('#show-version-diff').html($('#show-version-diff').data('labelTextDiff')); - } - } - - }; - - this.showVersionDiff = function(){ - var target = self.$verTarget.filter(':checked'); - var source = self.$verSource.filter(':checked'); - - if (target.val() && source.val()) { - var params = { - 'pull_request_id': ${c.pull_request.pull_request_id}, - 'repo_name': templateContext.repo_name, - 'version': target.val(), - 'from_version': source.val() - }; - window.location = pyroutes.url('pullrequest_show', params) - } - - return false; - }; - - this.toggleVersionView = function (elem) { - - if ($('#show-version-diff').is(':visible')) { - $('.version-pr').hide(); - $('#show-version-diff').hide(); - $(elem).html($(elem).data('toggleOn')) - } else { - $('.version-pr').show(); - $('#show-version-diff').show(); - $(elem).html($(elem).data('toggleOff')) - } - - return false - } - - }; - versionController = new VersionController(); versionController.init();