]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6565 add select list for groups
authorStas Vilchik <vilchiks@gmail.com>
Mon, 25 May 2015 12:24:45 +0000 (14:24 +0200)
committerStas Vilchik <vilchiks@gmail.com>
Mon, 25 May 2015 12:53:25 +0000 (14:53 +0200)
server/sonar-web/src/main/js/apps/users/groups-view.js [new file with mode: 0644]
server/sonar-web/src/main/js/apps/users/list-item-view.js
server/sonar-web/src/main/js/apps/users/templates/users-groups.hbs [new file with mode: 0644]
server/sonar-web/src/main/js/apps/users/templates/users-list-item.hbs
server/sonar-web/src/main/js/components/common/select-list.js

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 (file)
index 0000000..8b49948
--- /dev/null
@@ -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 + '<br><span class="note">' + item.description + '</span>';
+        },
+        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;
+        }
+      });
+    }
+  });
+
+});
index 0a3e62ace4438e0f22e32d5ada3dae7afe455ea6..d36925e2d0df8ee9f064cf50010b42b80ad7f510 100644 (file)
@@ -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 (file)
index 0000000..422716c
--- /dev/null
@@ -0,0 +1,10 @@
+<div class="modal-head">
+  <h2>Update Groups</h2>
+</div>
+<div class="modal-body">
+  <div class="js-modal-messages"></div>
+  <div id="users-groups"></div>
+</div>
+<div class="modal-foot">
+  <a href="#" class="js-modal-close" id="users-groups-done">Done</a>
+</div>
index ce816033e05f6f8ef47aa00843b818f076e24bb7..1cd782dd9ed657edbd63dec74d6c480978bbc8de 100644 (file)
@@ -40,7 +40,7 @@
     <li class="spacer-left little-spacer-bottom">sonar-administrators ?</li>
     <li class="spacer-left little-spacer-bottom">
       <a class="js-user-more-groups" href="#">? more</a>
-      <a class="icon-bullet-list spacer-left" title="Update Groups" data-toggle="tooltip" href="#"></a>
+      <a class="js-user-groups icon-bullet-list spacer-left" title="Update Groups" data-toggle="tooltip" href="#"></a>
     </li>
   </ul>
 </div>
index d2ca6af8b27334ef0bf0c9e14251a9679be88b35..480fbd9d69059df2a64e780ead8e235e0fd32243 100644 (file)
@@ -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',