##// END OF EJS Templates
pr-versioning: move version controller to dedicated PR file
marcink -
r1371:6a4c8be4 default
parent child Browse files
Show More
@@ -217,3 +217,126 b' var ReviewerAutoComplete = function(inpu'
217 }
217 }
218 });
218 });
219 };
219 };
220
221
222 VersionController = function () {
223 var self = this;
224 this.$verSource = $('input[name=ver_source]');
225 this.$verTarget = $('input[name=ver_target]');
226 this.$showVersionDiff = $('#show-version-diff');
227
228 this.adjustRadioSelectors = function (curNode) {
229 var getVal = function (item) {
230 if (item == 'latest') {
231 return Number.MAX_SAFE_INTEGER
232 }
233 else {
234 return parseInt(item)
235 }
236 };
237
238 var curVal = getVal($(curNode).val());
239 var cleared = false;
240
241 $.each(self.$verSource, function (index, value) {
242 var elVal = getVal($(value).val());
243
244 if (elVal > curVal) {
245 if ($(value).is(':checked')) {
246 cleared = true;
247 }
248 $(value).attr('disabled', 'disabled');
249 $(value).removeAttr('checked');
250 $(value).css({'opacity': 0.1});
251 }
252 else {
253 $(value).css({'opacity': 1});
254 $(value).removeAttr('disabled');
255 }
256 });
257
258 if (cleared) {
259 // if we unchecked an active, set the next one to same loc.
260 $(this.$verSource).filter('[value={0}]'.format(
261 curVal)).attr('checked', 'checked');
262 }
263
264 self.setLockAction(false,
265 $(curNode).data('verPos'),
266 $(this.$verSource).filter(':checked').data('verPos')
267 );
268 };
269
270
271 this.attachVersionListener = function () {
272 self.$verTarget.change(function (e) {
273 self.adjustRadioSelectors(this)
274 });
275 self.$verSource.change(function (e) {
276 self.adjustRadioSelectors(self.$verTarget.filter(':checked'))
277 });
278 };
279
280 this.init = function () {
281
282 var curNode = self.$verTarget.filter(':checked');
283 self.adjustRadioSelectors(curNode);
284 self.setLockAction(true);
285 self.attachVersionListener();
286
287 };
288
289 this.setLockAction = function (state, selectedVersion, otherVersion) {
290 var $showVersionDiff = this.$showVersionDiff;
291
292 if (state) {
293 $showVersionDiff.attr('disabled', 'disabled');
294 $showVersionDiff.addClass('disabled');
295 $showVersionDiff.html($showVersionDiff.data('labelTextLocked'));
296 }
297 else {
298 $showVersionDiff.removeAttr('disabled');
299 $showVersionDiff.removeClass('disabled');
300
301 if (selectedVersion == otherVersion) {
302 $showVersionDiff.html($showVersionDiff.data('labelTextShow'));
303 } else {
304 $showVersionDiff.html($showVersionDiff.data('labelTextDiff'));
305 }
306 }
307
308 };
309
310 this.showVersionDiff = function () {
311 var target = self.$verTarget.filter(':checked');
312 var source = self.$verSource.filter(':checked');
313
314 if (target.val() && source.val()) {
315 var params = {
316 'pull_request_id': templateContext.pull_request_data.pull_request_id,
317 'repo_name': templateContext.repo_name,
318 'version': target.val(),
319 'from_version': source.val()
320 };
321 window.location = pyroutes.url('pullrequest_show', params)
322 }
323
324 return false;
325 };
326
327 this.toggleVersionView = function (elem) {
328
329 if (this.$showVersionDiff.is(':visible')) {
330 $('.version-pr').hide();
331 this.$showVersionDiff.hide();
332 $(elem).html($(elem).data('toggleOn'))
333 } else {
334 $('.version-pr').show();
335 this.$showVersionDiff.show();
336 $(elem).html($(elem).data('toggleOff'))
337 }
338
339 return false
340 }
341
342 }; No newline at end of file
@@ -607,125 +607,6 b''
607 }
607 }
608 }
608 }
609
609
610 VersionController = function() {
611 var self = this;
612 this.$verSource = $('input[name=ver_source]');
613 this.$verTarget = $('input[name=ver_target]');
614
615 this.adjustRadioSelectors = function (curNode) {
616 var getVal = function(item) {
617 if (item == 'latest'){
618 return Number.MAX_SAFE_INTEGER
619 }
620 else {
621 return parseInt(item)
622 }
623 };
624
625 var curVal = getVal($(curNode).val());
626 var cleared = false;
627
628 $.each(self.$verSource, function(index, value){
629 var elVal = getVal($(value).val());
630
631 if(elVal > curVal){
632 if ($(value).is(':checked')) {
633 cleared = true;
634 }
635 $(value).attr('disabled', 'disabled');
636 $(value).removeAttr('checked');
637 $(value).css({'opacity': 0.1});
638 }
639 else{
640 $(value).css({'opacity': 1});
641 $(value).removeAttr('disabled');
642 }
643 });
644
645 if (cleared) {
646 // if we unchecked an active, set the next one to same loc.
647 $(this.$verSource).filter('[value={0}]'.format(
648 curVal)).attr('checked', 'checked');
649 }
650
651 self.setLockAction(false,
652 $(curNode).data('verPos'),
653 $(this.$verSource).filter(':checked').data('verPos')
654 );
655 };
656
657
658 this.attachVersionListener = function () {
659 self.$verTarget.change(function(e){
660 self.adjustRadioSelectors(this)
661 });
662 self.$verSource.change(function(e){
663 self.adjustRadioSelectors(self.$verTarget.filter(':checked'))
664 });
665 };
666
667 this.init = function () {
668
669 var curNode = self.$verTarget.filter(':checked');
670 self.adjustRadioSelectors(curNode);
671 self.setLockAction(true);
672 self.attachVersionListener();
673
674 };
675
676 this.setLockAction = function (state, selectedVersion, otherVersion) {
677 if (state) {
678 $('#show-version-diff').attr('disabled', 'disabled');
679 $('#show-version-diff').addClass('disabled');
680 $('#show-version-diff').html($('#show-version-diff').data('labelTextLocked'));
681 }
682 else {
683 $('#show-version-diff').removeAttr('disabled');
684 $('#show-version-diff').removeClass('disabled');
685
686 if (selectedVersion == otherVersion) {
687 $('#show-version-diff').html($('#show-version-diff').data('labelTextShow'));
688 } else {
689 $('#show-version-diff').html($('#show-version-diff').data('labelTextDiff'));
690 }
691 }
692
693 };
694
695 this.showVersionDiff = function(){
696 var target = self.$verTarget.filter(':checked');
697 var source = self.$verSource.filter(':checked');
698
699 if (target.val() && source.val()) {
700 var params = {
701 'pull_request_id': ${c.pull_request.pull_request_id},
702 'repo_name': templateContext.repo_name,
703 'version': target.val(),
704 'from_version': source.val()
705 };
706 window.location = pyroutes.url('pullrequest_show', params)
707 }
708
709 return false;
710 };
711
712 this.toggleVersionView = function (elem) {
713
714 if ($('#show-version-diff').is(':visible')) {
715 $('.version-pr').hide();
716 $('#show-version-diff').hide();
717 $(elem).html($(elem).data('toggleOn'))
718 } else {
719 $('.version-pr').show();
720 $('#show-version-diff').show();
721 $(elem).html($(elem).data('toggleOff'))
722 }
723
724 return false
725 }
726
727 };
728
729 versionController = new VersionController();
610 versionController = new VersionController();
730 versionController.init();
611 versionController.init();
731
612
General Comments 0
You need to be logged in to leave comments. Login now