From: Stas Vilchik Date: Mon, 25 May 2015 12:24:45 +0000 (+0200) Subject: SONAR-6565 add select list for groups X-Git-Tag: 5.2-RC1~1854 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=850622c8e811b7465946165352a17f95f90897df;p=sonarqube.git SONAR-6565 add select list for groups --- diff --git a/server/sonar-web/src/main/js/apps/users/groups-view.js b/server/sonar-web/src/main/js/apps/users/groups-view.js new file mode 100644 index 00000000000..8b49948d143 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/users/groups-view.js @@ -0,0 +1,37 @@ +define([ + 'components/common/modals', + 'components/common/select-list', + './templates' +], function (Modal) { + + return Modal.extend({ + template: Templates['users-groups'], + itemTemplate: Templates['users-group'], + + onRender: function () { + Modal.prototype.onRender.apply(this, arguments); + new window.SelectList({ + el: this.$('#users-groups'), + width: '100%', + readOnly: false, + focusSearch: false, + format: function (item) { + return item.name + '
' + item.description + ''; + }, + searchUrl: baseUrl + '/api/users/groups?ps=100&login=' + this.model.id, + selectUrl: baseUrl + '/api/qualityprofiles/add_project', + deselectUrl: baseUrl + '/api/qualityprofiles/remove_project', + extra: { + profileKey: key + }, + selectParameter: 'projectUuid', + selectParameterValue: 'uuid', + parse: function (r) { + this.more = false; + return r.groups; + } + }); + } + }); + +}); diff --git a/server/sonar-web/src/main/js/apps/users/list-item-view.js b/server/sonar-web/src/main/js/apps/users/list-item-view.js index 0a3e62ace44..d36925e2d0d 100644 --- a/server/sonar-web/src/main/js/apps/users/list-item-view.js +++ b/server/sonar-web/src/main/js/apps/users/list-item-view.js @@ -2,8 +2,9 @@ define([ './update-view', './change-password-view', './deactivate-view', + './groups-view', './templates' -], function (UpdateView, ChangePasswordView, DeactivateView) { +], function (UpdateView, ChangePasswordView, DeactivateView, GroupsView) { return Marionette.ItemView.extend({ tagName: 'li', @@ -14,7 +15,8 @@ define([ 'click .js-user-more-scm': 'onMoreScmClick', 'click .js-user-update': 'onUpdateClick', 'click .js-user-change-password': 'onChangePasswordClick', - 'click .js-user-deactivate': 'onDeactivateClick' + 'click .js-user-deactivate': 'onDeactivateClick', + 'click .js-user-groups': 'onGroupsClick' }, initialize: function () { @@ -50,6 +52,11 @@ define([ this.deactivateUser(); }, + onGroupsClick: function (e) { + e.preventDefault(); + this.showGroups(); + }, + showMoreScm: function () { this.scmLimit = 10000; this.render(); @@ -73,6 +80,10 @@ define([ new DeactivateView({ model: this.model }).render(); }, + showGroups: function () { + new GroupsView({ model: this.model }).render(); + }, + serializeData: function () { var scmAccounts = this.model.get('scmAccounts'), scmAccountsLimit = scmAccounts.length > this.scmLimit ? this.scmLimit - 1 : this.scmLimit; diff --git a/server/sonar-web/src/main/js/apps/users/templates/users-groups.hbs b/server/sonar-web/src/main/js/apps/users/templates/users-groups.hbs new file mode 100644 index 00000000000..422716c7d9a --- /dev/null +++ b/server/sonar-web/src/main/js/apps/users/templates/users-groups.hbs @@ -0,0 +1,10 @@ + + + diff --git a/server/sonar-web/src/main/js/apps/users/templates/users-list-item.hbs b/server/sonar-web/src/main/js/apps/users/templates/users-list-item.hbs index ce816033e05..1cd782dd9ed 100644 --- a/server/sonar-web/src/main/js/apps/users/templates/users-list-item.hbs +++ b/server/sonar-web/src/main/js/apps/users/templates/users-list-item.hbs @@ -40,7 +40,7 @@
  • sonar-administrators ?
  • ? more - +
  • diff --git a/server/sonar-web/src/main/js/components/common/select-list.js b/server/sonar-web/src/main/js/components/common/select-list.js index d2ca6af8b27..480fbd9d690 100644 --- a/server/sonar-web/src/main/js/components/common/select-list.js +++ b/server/sonar-web/src/main/js/components/common/select-list.js @@ -28,9 +28,12 @@ define(function () { var SelectListCollection = Backbone.Collection.extend({ + initialize: function (options) { + this.options = options; + }, + parse: function (r) { - this.more = r.more; - return r.results; + return this.options.parse.call(this, r); }, fetch: function (options) { @@ -377,7 +380,9 @@ define(function () { window.SelectList = function (options) { this.settings = $.extend(window.SelectList.defaults, options); - this.collection = new SelectListCollection(); + this.collection = new SelectListCollection({ + parse: this.settings.parse + }); this.view = new SelectListView({ el: this.settings.el, @@ -421,6 +426,11 @@ define(function () { return item.value; }, + parse: function (r) { + this.more = r.more; + return r.results; + }, + labels: { selected: 'Selected', deselected: 'Deselected',