2 * A simple Hello World applet for documentation purpose.
3 * The only associated command is the "Close" command.
5 /* *************************************************
6 #asset(resource/org.argeo.security.ria/*)
7 ****************************************************/
8 qx
.Class
.define("org.argeo.security.ria.UsersApplet",
10 extend
: qx
.ui
.container
.Composite
,
11 implement
: [org
.argeo
.ria
.components
.IView
],
13 construct : function(){
15 this.setLayout(new qx
.ui
.layout
.VBox());
21 * The viewPane inside which this applet is added.
27 * Commands definition, see {@link org.argeo.ria.event.CommandsManager#definitions}
32 label
: "Reload Users",
33 icon
: "org.argeo.security.ria/view-refresh.png",
34 shortcut
: "Control+h",
38 callback : function(e
){
45 icon
: "org.argeo.security.ria/list-add.png",
46 shortcut
: "Control+n",
50 callback : function(e
){
51 // Call service to delete
52 var classObj
= org
.argeo
.security
.ria
.UserEditorApplet
;
53 var initData
= {USER
:null,ROLES_LIST
:this.getRolesList()};
54 var iView
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().initIViewClass(classObj
, "editor", initData
);
56 iView
.addListener("savedUser", function(e
){
57 this.refreshUserEntry(e
.getData());
63 label
: "Delete User",
64 icon
: "org.argeo.security.ria/list-remove.png",
65 shortcut
: "Control+s",
69 callback : function(e
){
70 // Call service to delete
71 var username
= this.getViewSelection().getNodes()[0];
72 var deleteService
= org
.argeo
.security
.ria
.SecurityAPI
.getDeleteUserService(username
);
73 deleteService
.addListener("completed", function(response
){
74 if(response
.getContent().status
&& response
.getContent().status
== "OK"){
78 // Check if tab is opened before closing!
79 var editorTabPane
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getViewPaneById("editor");
80 var iApplet
= editorTabPane
.contentExists(username
);
81 var modal
= new org
.argeo
.ria
.components
.Modal("Delete");
83 if(iApplet
.getModified()){
84 modal
.addConfirm("There are unsaved changes, are you sure you want to delete this user?");
85 modal
.addListener("ok", function(e
){
86 editorTabPane
.closeCurrent();
89 modal
.attachAndShow();
91 modal
.addConfirm("Are you sure you want to delete user " + username
+ "?");
92 modal
.addListener("ok", function(e
){
93 editorTabPane
.closeCurrent();
96 modal
.attachAndShow();
99 modal
.addConfirm("Are you sure you want to delete user " + username
+ "?");
100 modal
.addListener("ok", function(e
){
101 deleteService
.send();
103 modal
.attachAndShow();
106 selectionChange : function(viewName
, data
){
107 if(viewName
!= "users") return;
108 this.setEnabled(!(data
== null || !data
.length
|| data
.length
>1));
114 icon
: "org.argeo.security.ria/document-properties.png",
115 shortcut
: "Control+u",
119 callback : function(e
){
120 // Call service to delete
121 var crtUser
= this.getViewSelection().getNodes()[0];
122 var classObj
= org
.argeo
.security
.ria
.UserEditorApplet
;
123 var initData
= {USER
:crtUser
,ROLES_LIST
:this.getRolesList()};
124 var iView
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().initIViewClass(classObj
, "editor", initData
);
126 iView
.addListener("savedUser", function(e
){
127 this.refreshUserEntry(e
.getData());
130 selectionChange : function(viewName
, data
){
131 if(viewName
!= "users") return;
132 this.setEnabled(!(data
== null || !data
.length
|| data
.length
> 1));
141 apply
: "_applyGuiMode"
146 check
:"org.argeo.ria.components.ViewSelection"
150 apply
: "_applyUsersList",
151 event
: "changeUsersList"
156 instanceId
: {init
:""},
157 instanceLabel
: {init
:""}
163 * Called at applet creation. Just registers viewPane.
164 * @param viewPane {org.argeo.ria.components.ViewPane} The viewPane.
166 init : function(viewPane
){
167 this.setView(viewPane
);
168 this.setViewSelection(new org
.argeo
.ria
.components
.ViewSelection(viewPane
.getViewId()));
170 this.toolBar
= new qx
.ui
.toolbar
.ToolBar();
171 this.toolBarPart
= new qx
.ui
.toolbar
.Part();
172 this.toolBar
.add(this.toolBarPart
);
173 viewPane
.add(this.toolBar
);
175 this.tableModel
= new qx
.ui
.table
.model
.Filtered();
176 this.tableModel
.setColumns(["username", "roles"]);
177 this.table
= new qx
.ui
.table
.Table(this.tableModel
, {
178 tableColumnModel: function(obj
){
179 return new qx
.ui
.table
.columnmodel
.Resize(obj
)
182 this.table
.setStatusBarVisible(false);
183 this.table
.setShowCellFocusIndicator(false);
184 this.table
.setColumnVisibilityButtonVisible(false);
185 this.table
.highlightFocusedRow(false);
186 viewPane
.add(this.table
, {height
:"100%"});
187 this.table
.getSelectionModel().addListener("changeSelection", function(){
188 this._selectionToValues(this.table
.getSelectionModel(), this.getViewSelection());
190 this.table
.addListener("cellDblclick", function(cellEvent
){
191 this.getCommands()["edit_user"].command
.execute();
194 this.setRolesList([]);
195 this.setUsersList({});
196 this.setGuiMode("clear");
199 _applyGuiMode : function(newMode
, oldMode
){
200 this.table
.getSelectionModel().clearSelection();
201 this.resetHiddenRows();
202 if(newMode
== "filter"){
203 this.table
.getSelectionModel().setSelectionMode(qx
.ui
.table
.selection
.Model
.SINGLE_SELECTION
);
204 }else if(newMode
== "chooser"){
205 this.table
.getSelectionModel().setSelectionMode(qx
.ui
.table
.selection
.Model
.MULTIPLE_INTERVAL_SELECTION_TOGGLE
);
206 }else if(newMode
== "clear"){
207 this.table
.getSelectionModel().setSelectionMode(qx
.ui
.table
.selection
.Model
.SINGLE_SELECTION
);
211 _selectionToValues : function(selectionModel
, viewSelection
){
213 viewSelection
.setBatchMode(true);
214 viewSelection
.clear();
216 if(!selectionModel
.getSelectedCount()) return [];
217 var ranges
= selectionModel
.getSelectedRanges();
219 for(var i
=0;i
<ranges
.length
;i
++){
220 for(var j
=ranges
[i
].minIndex
;j
<=ranges
[i
].maxIndex
;j
++){
221 values
.push(this.tableModel
.getData()[j
][0]);
223 viewSelection
.addNode(this.tableModel
.getData()[j
][0]);
228 viewSelection
.setBatchMode(false);
234 * Load a given row : the data passed must be a simple data array.
235 * @param data {Element} The text xml description.
238 var commands
= this.getCommands();
239 this.toolBarPart
.add(commands
["new_user"].command
.getToolbarButton());
240 this.toolBarPart
.add(commands
["delete_user"].command
.getToolbarButton());
241 this.toolBarPart
.add(commands
["edit_user"].command
.getToolbarButton());
242 this.toolBar
.setShow("icon");
243 this.loadUsersList();
245 var rolesApplet
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getViewPaneById("roles").getContent();
246 rolesApplet
.addListener("changeRolesList", function(e
){
247 this.setRolesList(e
.getData());
248 this.loadUsersList();
253 loadUsersList : function(){
254 var selectionModel
= this.table
.getSelectionModel();
255 selectionModel
.clearSelection();
256 var request
= org
.argeo
.security
.ria
.SecurityAPI
.getListUsersService();
257 request
.addListener("completed", function(response
){
258 var jSon
= response
.getContent();
260 for(var i
=0;i
<jSon
.length
;i
++){
261 var user
= new org
.argeo
.security
.ria
.model
.User();
262 user
.load(jSon
[i
], "json");
263 usMap
[user
.getName()] = user
;
265 this.setUsersList(usMap
);
272 * @param {org.argeo.security.ria.model.User} userObject
274 refreshUserEntry : function(userObject
){
275 var userName
= userObject
.getName();
276 var data
= this.tableModel
.getDataAsMapArray();
279 for(index
=0;index
<data
.length
;index
++){
280 if(data
[index
].username
== userName
){
285 var newRows
= [{username
:userName
,roles
:userObject
.getRoles().join(",")}];
287 this.tableModel
.setRowsAsMapArray(newRows
, index
);
289 this.tableModel
.setRowsAsMapArray(newRows
, index
);
293 _applyUsersList : function(usList
){
295 qx
.lang
.Object
.getValues(usList
).forEach(function(usObject
){
296 data
.push([usObject
.getName(), usObject
.getRoles().join(",")]);
298 this.tableModel
.setData(data
);
301 applySelection : function(selectionValue
, target
, ignoreCase
){
302 var selectionModel
= this.table
.getSelectionModel();
303 selectionModel
.clearSelection();
307 selectionModel
.setBatchMode(true);
308 var data
= this.tableModel
.getData();
309 for(var i
=0;i
<this.tableModel
.getRowCount();i
++){
310 var value
= this.tableModel
.getRowDataAsMap(i
)[target
];
311 var pattern
= new RegExp(selectionValue
, "g"+(ignoreCase
?"i":""));
312 if(pattern
.test(value
)){
313 selectionModel
.addSelectionInterval(i
, i
);
316 selectionModel
.setBatchMode(false);
319 applyFilter : function(filterValues
, target
, ignoreCase
){
320 this.table
.clearSelection();
321 this.resetHiddenRows();
322 for(var i
=0;i
<filterValues
.length
;i
++){
323 this.tableModel
.addRegex("^((?!"+filterValues
[i
]+").)*$", target
, ignoreCase
);
325 this.tableModel
.applyFilters();
328 resetHiddenRows : function(){
329 this.tableModel
.resetHiddenRows();
332 addScroll : function(){