]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/RolesApplet.js
Start preparing 0.3.0
[lgpl/argeo-commons.git] / security / runtime / org.argeo.security.ria / src / argeo-ria-lib / security / class / org / argeo / security / ria / RolesApplet.js
index 65b5427b30259fbe5dc1a968744151cbad0d73f1..9ae4eff77880d494cfdb1ab25bd869b369353e5b 100644 (file)
@@ -3,7 +3,7 @@
  * The only associated command is the "Close" command.
  */
 /* *************************************************
-#asset(resource/org.argeo.ria.sample/window-close.png)
+#asset(org/argeo/ria/sample/window-close.png)
 ****************************************************/
 qx.Class.define("org.argeo.security.ria.RolesApplet",
 {
@@ -28,10 +28,22 @@ qx.Class.define("org.argeo.security.ria.RolesApplet",
         */
        commands : {
                init : {
+                       "reload" : {
+                               label           : "Reload Data",
+                               icon            : "org/argeo/security/ria/view-refresh.png",
+                               shortcut        : "Control+h",
+                               enabled         : true,
+                               menu            : "Roles",
+                               toolbar         : "roles",
+                               callback        : function(e){
+                                       this.loadRolesList();
+                               },
+                               command         : null
+                       },                      
                        "new_role" : {
                                label           : "Create Role", 
-                               icon            : "org.argeo.security.ria/list-add.png",
-                               shortcut        : "Control+n",
+                               icon            : "org/argeo/security/ria/list-add.png",
+                               shortcut        : null,
                                enabled         : true,
                                menu            : "Roles",
                                toolbar         : null,
@@ -51,21 +63,26 @@ qx.Class.define("org.argeo.security.ria.RolesApplet",
                        },      
                        "delete_role" : {
                                label           : "Delete Role", 
-                               icon            : "org.argeo.security.ria/list-remove.png",
-                               shortcut        : "Control+s",
+                               icon            : "org/argeo/security/ria/list-remove.png",
+                               shortcut        : null,
                                enabled         : true,
                                menu            : "Roles",
                                toolbar         : null,
                                callback        : function(e){
                                        // Call service to delete
                                        var roles = this.getViewSelection().getNodes();
-                                       for(var i=0;i<roles.length;i++){
-                                               var service = org.argeo.security.ria.SecurityAPI.getDeleteRoleService(roles[i]);
-                                               service.addListener("completed", function(response){
-                                                       this.loadRolesList();
-                                               }, this);
-                                               service.send();
-                                       }
+                                       var modal = new org.argeo.ria.components.Modal("Delete");                                       
+                                       modal.addConfirm("Are you sure you want to delete the selected roles?");
+                                       modal.addListener("ok", function(e){
+                                               for(var i=0;i<roles.length;i++){
+                                                       var service = org.argeo.security.ria.SecurityAPI.getDeleteRoleService(roles[i]);
+                                                       service.addListener("completed", function(response){
+                                                               this.loadRolesList();
+                                                       }, this);
+                                                       service.send();
+                                               }
+                                       }, this);
+                                       modal.attachAndShow();                                  
                                },
                                selectionChange : function(viewName, data){
                                        if(viewName != "roles") return;
@@ -75,7 +92,7 @@ qx.Class.define("org.argeo.security.ria.RolesApplet",
                        },                                              
                        "edit_role" : {
                                label           : "Edit Role", 
-                               icon            : "org.argeo.security.ria/document-properties.png",
+                               icon            : "org/argeo/security/ria/document-properties.png",
                                shortcut        : "Control+r",
                                enabled         : true,
                                menu            : "Roles",
@@ -145,7 +162,7 @@ qx.Class.define("org.argeo.security.ria.RolesApplet",
                
                this.rolesUsersStub = {"ROLE_ADMIN":["gandalf"],"ROLE_USER":["demo","frodo","gandalf"]};
                                        
-               this.toggleButton = new qx.ui.form.ToggleButton("Filter", "org.argeo.security.ria/go-next.png");
+               this.toggleButton = new qx.ui.form.ToggleButton("Filter", "org/argeo/security/ria/go-next.png");
                this.toggleButton.set({
                        show:"icon",
                        margin:2,
@@ -153,11 +170,11 @@ qx.Class.define("org.argeo.security.ria.RolesApplet",
                });
                                
                // TOGGLE THE GUI MODES                 
-               this.toggleButton.addListener("changeChecked", function(event){
+               this.toggleButton.addListener("changeValue", function(event){
                        this.setGuiMode(event.getData()?"filter":"clear");
                }, this);
                
-               this.saveButton = new qx.ui.form.Button("Save", "org.argeo.security.ria/document-save.png");
+               this.saveButton = new qx.ui.form.Button("Save", "org/argeo/security/ria/document-save.png");
                this.saveButton.set({
                        show:"icon",
                        margin:2,
@@ -165,7 +182,7 @@ qx.Class.define("org.argeo.security.ria.RolesApplet",
                        visibility : "excluded"
                });
                
-               this.cancelButton = new qx.ui.form.Button("Cancel", "org.argeo.security.ria/window-close.png");
+               this.cancelButton = new qx.ui.form.Button("Cancel", "org/argeo/security/ria/window-close.png");
                this.cancelButton.set({
                        show:"icon",
                        margin:2,
@@ -227,7 +244,13 @@ qx.Class.define("org.argeo.security.ria.RolesApplet",
                                viewSel.removeListener("changeSelection", this.monitorChooserSelectionChanges, this);                   
                        }
                        selectionModel.addListener("changeSelection", this.selectionToFilter, this);
+                       if(selectionModel.getSelectedCount()){
+                               var orig = selectionModel.getSelectedRanges()[0].minIndex;
+                       }
                        selectionModel.setSelectionMode(qx.ui.table.selection.Model.MULTIPLE_INTERVAL_SELECTION_TOGGLE);
+                       if(orig){
+                               selectionModel.addSelectionInterval(orig, orig);
+                       }
                        this.selectionToFilter();                       
                }else if(guiMode == "edit"){
                        if(!this.usersAppletReference) return;
@@ -248,13 +271,17 @@ qx.Class.define("org.argeo.security.ria.RolesApplet",
                        }
                        this.table.setEnabled(true);
                        selectionModel.removeListener("changeSelection", this.selectionToFilter, this);
+                       if(selectionModel.getSelectedCount()){
+                               var orig = selectionModel.getSelectedRanges()[0].minIndex;
+                       }
                        selectionModel.setSelectionMode(qx.ui.table.selection.Model.SINGLE_SELECTION);                          
+                       if(orig){
+                               selectionModel.addSelectionInterval(orig, orig);
+                       }
                }
        },
        
        saveRoleModifications : function(deltaPlus, deltaMinus){
-               //console.log(deltaPlus);
-               //console.log(deltaMinus);
                // LOAD CONCERNED USERS
                var selectionModel = this.table.getSelectionModel();
                if(!selectionModel.getSelectedCount()){
@@ -263,6 +290,8 @@ qx.Class.define("org.argeo.security.ria.RolesApplet",
                var roleValue = this._selectionToValues(selectionModel)[0];
                
                var users = deltaPlus.concat(deltaMinus);
+               var modal = new org.argeo.ria.components.Modal("Batch Update", "", "Please wait, updating roles for selected users");
+               modal.attachAndShow();
                for(var i=0;i<users.length;i++){
                        var user = users[i];
                        var userDetailService = org.argeo.security.ria.SecurityAPI.getUserDetailsService(users[i]);
@@ -274,13 +303,15 @@ qx.Class.define("org.argeo.security.ria.RolesApplet",
                                        qx.lang.Array.remove(userRoles, roleValue);
                                }
                                var userSaveService = org.argeo.security.ria.SecurityAPI.getUpdateUserService(response.getContent());
-                               userSaveService.addListener("completed", function(e){
-                                       this.fireDataEvent("changeRolesList", this.getRolesList());
-                               }, this);
+                               userSaveService.setAsynchronous(false);
                                userSaveService.send();
                        }, this);
+                       userDetailService.setAsynchronous(false);
                        userDetailService.send();
                }
+               this.fireDataEvent("changeRolesList", this.getRolesList());
+               modal.hide();
+               modal.destroy();
        },
        
        monitorChooserSelectionChanges : function(event){