]> source.dussan.org Git - archiva.git/commitdiff
ui rewrite add bulk save mode in role edition screen
authorOlivier Lamy <olamy@apache.org>
Sat, 11 Feb 2012 22:17:20 +0000 (22:17 +0000)
committerOlivier Lamy <olamy@apache.org>
Sat, 11 Feb 2012 22:17:20 +0000 (22:17 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1243170 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/roles.js
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/redback/templates/roles-tmpl.html

index 9877fedadc8a0b801c996051706a0713da39185d..ebf0390e4e155716bc4cb5234f8f3c58d392bfec 100644 (file)
@@ -19,6 +19,9 @@
 $(function() {
 
   Role = function(name,description,assignable,childRoleNames,parentRoleNames,users,parentsRolesUsers,permissions,otherUsers){
+
+    var self=this;
+
     this.name = ko.observable(name);
     this.name.subscribe(function(newValue){self.modified(true)});
 
@@ -52,6 +55,8 @@ $(function() {
 
     this.modified=ko.observable(false);
 
+    this.usersModified=ko.observable(false);
+
     this.updateDescription=function(){
       var url = "restServices/redbackServices/roleManagementService/updateRoleDescription?";
       var roleName = this.name();
@@ -72,7 +77,7 @@ $(function() {
         }
       );
     }
-    var self=this;
+
     this.updateUsers=function(){
       var url = "restServices/redbackServices/roleManagementService/updateRoleUsers";
       $.ajax(url,
@@ -130,20 +135,50 @@ $(function() {
          dataType: 'json',
          success: function(data) {
            var mappedRole = mapRole(data.role);
-           role.parentRoleNames=mappedRole.parentRoleNames;
-           role.parentsRolesUsers=mappedRole.parentsRolesUsers;
-           role.users=mappedRole.users;
-           role.otherUsers=mappedRole.otherUsers;
+           role.parentRoleNames(mappedRole.parentRoleNames());
+           role.parentsRolesUsers(mappedRole.parentsRolesUsers());
+           role.users(mappedRole.users());
+           role.otherUsers(mappedRole.otherUsers());
+           role.modified(false);
            var viewModel = new RoleViewModel(role);
            ko.applyBindings(viewModel,mainContent.find("#roles-view-tabs-content #role-edit").get(0));
            activateRoleEditTab();
-           mainContent.find("#role-view-users ").tabs("show");
+           mainContent.find("#role-view-users").tabs("show");
            mainContent.find("#role-edit-users-tabs-content #role-view-users").addClass("active");
          }
         }
       );
     }
 
+    this.bulkSave=function(){
+      $.log("bulkSave");
+      return getModifiedRoles().length>0;
+    }
+
+    getModifiedRoles=function(){
+      var prx = $.grep(self.roles(),
+          function (role,i) {
+            return role.modified()||role.usersModified();
+          });
+      return prx;
+    }
+
+    updateModifiedRoles=function(){
+      var modifiedRoles = getModifiedRoles();
+      $.log("modifiedRoles:"+modifiedRoles);
+      for(i=0;i<modifiedRoles.length;i++){
+        var modifiedRole=modifiedRoles[i];
+        if (modifiedRole.modified()){
+          modifiedRole.updateDescription();
+          modifiedRole.modified(false);
+        }
+        if (modifiedRole.usersModified()){
+          modifiedRole.updateUsers();
+          modifiedRole.usersModified(false);
+        }
+      }
+    }
+
   }
 
   displayRolesGrid = function(){
@@ -161,7 +196,7 @@ $(function() {
           var rolesViewModel = new RolesViewModel();
           rolesViewModel.roles(mappedRoles);
           mainContent.html($("#rolesTabs").tmpl());
-          ko.applyBindings(rolesViewModel,mainContent.find("#rolesTable").get(0));
+          ko.applyBindings(rolesViewModel,mainContent.find("#roles-view").get(0));
           mainContent.find("#roles-view-tabs #roles-view-tabs-a-roles-grid").tab("show");
           activateRolesGridTab();
           removeMediumSpinnerImg();
@@ -184,7 +219,8 @@ $(function() {
       for (var i = 0; i < removed.length; i++) {
         $.log("add user:"+removed[i].username());
         currentRole.users.push(removed[i]);
-        role.modified(true);
+        //role.modified(true);
+        role.usersModified(true);
       }
       selectedOtherUsers([]);
       activateRoleUsersEditTab();
@@ -195,7 +231,8 @@ $(function() {
       for (var i = 0; i < added.length; i++) {
         currentRole.otherUsers.push(added[i]);
         currentRole.removedUsers.push(added[i]);
-        role.modified(true);
+        //role.modified(true);
+        role.usersModified(true);
       }
       selectedUsers([]);
       activateRoleUsersEditTab()
index 608f29525f7472e142d56cee8ab55d7dc2037503..8113a78fc450d159b8efb253a0552af8608bb4ed 100644 (file)
@@ -31,6 +31,9 @@
   </ul>
   <div id="roles-view-tabs-content" class="tab-content">
     <div id="roles-view" class="tab-pane">
+        <div data-bind="style: { display: bulkSave() ? '' : 'none' }">
+          <button data-bind="click: updateModifiedRoles" class="btn">${$.i18n.prop('save.all')}</button>
+        </div>
         <table class="table table-striped table-bordered" id="rolesTable"
                data-bind="simpleGrid: gridViewModel,simpleGridTemplate:'ko_rolesGrid',pageLinksId:'rolesPagination'">
         </table>
           <h3>${$.i18n.prop('role.edit.users.defined.in.current.role')}</h3>
         </div>
         <div id="role-list-users">
-          {{if $data.users}}
+          {{if users().length>0}}
               <ul>
-              {{each users}}
-                <li>${$value.fullName} - ( ${$value.username} - ${$value.email} ) </li>
+              {{each(j, user) users()}}
+                <li>${user.fullName()} - ( ${user.username()} - ${user.email()} ) </li>
               {{/each}}
               </ul>
           {{else}}
   </thead>
   <tbody>
       {{each(i, row) itemsOnCurrentPage()}}
-          <tr data-bind="css:{ 'modified': row.modified()}">
+          <tr data-bind="css:{ 'modified': row.modified()||row.usersModified()}">
               {{each(j, columnDefinition) columns}}
               {{var val = (typeof columnDefinition.rowText == 'function' ? columnDefinition.rowText(row) : row[columnDefinition.rowText])}}
               <td id="role-${columnDefinition.rowText}-${row.name()}">