From 981a636b63101fd5b1f953d245bf15eaa2c017df Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Wed, 15 Apr 2015 16:04:28 +0200 Subject: [PATCH] SONAR-5851 scroll to selected section (changelog/comparison) --- .../main/js/quality-profiles/controller.js | 5 +++- .../quality-profiles/create-profile-view.js | 2 -- .../quality-profiles/profile-details-view.js | 28 +++++++++++++++++++ .../quality-profiles/rename-profile-view.js | 2 -- .../src/main/js/quality-profiles/router.js | 4 ++- 5 files changed, 35 insertions(+), 6 deletions(-) diff --git a/server/sonar-web/src/main/js/quality-profiles/controller.js b/server/sonar-web/src/main/js/quality-profiles/controller.js index c3e3f0c27cf..f81ff6a0af9 100644 --- a/server/sonar-web/src/main/js/quality-profiles/controller.js +++ b/server/sonar-web/src/main/js/quality-profiles/controller.js @@ -48,6 +48,7 @@ define([ changelog: function (key, since, to) { var that = this; + this.anchor = 'changelog'; this.fetchProfiles().done(function () { var profile = that.options.app.profiles.findWhere({ key: key }); if (profile != null) { @@ -59,6 +60,7 @@ define([ compare: function (key, withKey) { var that = this; + this.anchor = 'comparison'; this.fetchProfiles().done(function () { var profile = that.options.app.profiles.findWhere({ key: key }); if (profile != null) { @@ -86,7 +88,8 @@ define([ var profileDetailsView = new ProfileDetailsView({ model: profile, - canWrite: that.options.app.canWrite + canWrite: that.options.app.canWrite, + anchor: that.anchor }); that.options.app.layout.detailsRegion.show(profileDetailsView); }); diff --git a/server/sonar-web/src/main/js/quality-profiles/create-profile-view.js b/server/sonar-web/src/main/js/quality-profiles/create-profile-view.js index 00d54e2b38d..e6045f31716 100644 --- a/server/sonar-web/src/main/js/quality-profiles/create-profile-view.js +++ b/server/sonar-web/src/main/js/quality-profiles/create-profile-view.js @@ -37,7 +37,6 @@ define([ onFormSubmit: function (e) { ModalFormView.prototype.onFormSubmit.apply(this, arguments); - this.disableForm(); this.sendRequest(e); }, @@ -73,7 +72,6 @@ define([ uploader({ form: $(e.currentTarget) }).done(function (r) { if (_.isArray(r.errors) || _.isArray(r.warnings)) { that.showErrors(r.errors, r.warnings); - that.enableForm(); } else { that.addProfile(r.profile); that.close(); diff --git a/server/sonar-web/src/main/js/quality-profiles/profile-details-view.js b/server/sonar-web/src/main/js/quality-profiles/profile-details-view.js index 5d5d0977d57..41455007911 100644 --- a/server/sonar-web/src/main/js/quality-profiles/profile-details-view.js +++ b/server/sonar-web/src/main/js/quality-profiles/profile-details-view.js @@ -51,6 +51,12 @@ define([ } this.changelogRegion.show(new ProfileChangelogView({ model: this.model })); this.comparisonRegion.show(new ProfileComparisonView({ model: this.model })); + if (this.options.anchor === 'changelog') { + this.scrollToChangelog(); + } + if (this.options.anchor === 'comparison') { + this.scrollToComparison(); + } }, initProjectsSelect: function () { @@ -104,6 +110,28 @@ define([ }).render(); }, + scrollTo: function (selector) { + var el = this.$(selector), + parent = el.scrollParent(); + var elOffset = el.offset(), + parentOffset = parent.offset(); + if (parent.is(document)) { + parentOffset = { top: 0 }; + } + if (elOffset != null && parentOffset != null) { + var scrollTop = elOffset.top - parentOffset.top - 53; + parent.scrollTop(scrollTop); + } + }, + + scrollToChangelog: function () { + this.scrollTo('#quality-profile-changelog'); + }, + + scrollToComparison: function () { + this.scrollTo('#quality-profile-comparison'); + }, + serializeData: function () { var key = this.model.get('key'), rulesSearchUrl = '/coding_rules#qprofile=' + encodeURIComponent(key) + '|activation=true'; diff --git a/server/sonar-web/src/main/js/quality-profiles/rename-profile-view.js b/server/sonar-web/src/main/js/quality-profiles/rename-profile-view.js index 7ca92f76d24..023f3a94f78 100644 --- a/server/sonar-web/src/main/js/quality-profiles/rename-profile-view.js +++ b/server/sonar-web/src/main/js/quality-profiles/rename-profile-view.js @@ -29,7 +29,6 @@ define([ onFormSubmit: function () { ModalFormView.prototype.onFormSubmit.apply(this, arguments); - this.disableForm(); this.sendRequest(); }, @@ -54,7 +53,6 @@ define([ that.close(); }).fail(function (jqXHR) { that.showErrors(jqXHR.responseJSON.errors, jqXHR.responseJSON.warnings); - that.enableForm(); }); } }); diff --git a/server/sonar-web/src/main/js/quality-profiles/router.js b/server/sonar-web/src/main/js/quality-profiles/router.js index cd82dacfc92..7970d6d2ea6 100644 --- a/server/sonar-web/src/main/js/quality-profiles/router.js +++ b/server/sonar-web/src/main/js/quality-profiles/router.js @@ -47,7 +47,9 @@ define(function () { compare: function () { var params = window.getQueryParams(); - this.app.controller.compare(params.key, params.withKey); + if (params.key && params.withKey) { + this.app.controller.compare(params.key, params.withKey); + } } }); -- 2.39.5