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}
33 icon
: "org.argeo.security.ria/list-add.png",
34 shortcut
: "Control+n",
38 callback : function(e
){
39 // Call service to delete
40 var classObj
= org
.argeo
.security
.ria
.UserEditorApplet
;
41 var initData
= {USER
:null,ROLES_LIST
:this.getRolesList()};
42 var iView
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().initIViewClass(classObj
, "editor", initData
);
44 iView
.addListener("savedUser", function(e
){
45 this.refreshUserEntry(e
.getData());
51 label
: "Delete User",
52 icon
: "org.argeo.security.ria/list-remove.png",
53 shortcut
: "Control+d",
57 callback : function(e
){
58 // Call service to delete
59 var username
= this.getViewSelection().getNodes()[0];
60 var deleteService
= org
.argeo
.security
.ria
.SecurityAPI
.getDeleteUserService(username
);
61 deleteService
.addListener("completed", function(response
){
62 if(response
.getContent().status
&& response
.getContent().status
== "OK"){
66 // Check if tab is opened before closing!
67 var editorTabPane
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getViewPaneById("editor");
68 var iApplet
= editorTabPane
.contentExists(username
);
69 var modal
= new org
.argeo
.ria
.components
.Modal("Delete");
71 if(iApplet
.getModified()){
72 modal
.addConfirm("There are unsaved changes, are you sure you want to delete this user?");
73 modal
.addListener("ok", function(e
){
74 editorTabPane
.closeCurrent();
77 modal
.attachAndShow();
79 modal
.addConfirm("Are you sure you want to delete user " + username
+ "?");
80 modal
.addListener("ok", function(e
){
81 editorTabPane
.closeCurrent();
84 modal
.attachAndShow();
87 modal
.addConfirm("Are you sure you want to delete user " + username
+ "?");
88 modal
.addListener("ok", function(e
){
91 modal
.attachAndShow();
94 selectionChange : function(viewName
, data
){
95 if(viewName
!= "users") return;
96 this.setEnabled(!(data
== null || !data
.length
|| data
.length
>1));
102 icon
: "org.argeo.security.ria/document-properties.png",
103 shortcut
: "Control+u",
107 callback : function(e
){
108 // Call service to delete
109 var crtUser
= this.getViewSelection().getNodes()[0];
110 var classObj
= org
.argeo
.security
.ria
.UserEditorApplet
;
111 var initData
= {USER
:crtUser
,ROLES_LIST
:this.getRolesList()};
112 var iView
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().initIViewClass(classObj
, "editor", initData
);
114 iView
.addListener("savedUser", function(e
){
115 this.refreshUserEntry(e
.getData());
118 selectionChange : function(viewName
, data
){
119 if(viewName
!= "users") return;
120 this.setEnabled(!(data
== null || !data
.length
|| data
.length
> 1));
129 apply
: "_applyGuiMode"
134 check
:"org.argeo.ria.components.ViewSelection"
138 apply
: "_applyUsersList",
139 event
: "changeUsersList"
144 instanceId
: {init
:""},
145 instanceLabel
: {init
:""}
151 * Called at applet creation. Just registers viewPane.
152 * @param viewPane {org.argeo.ria.components.ViewPane} The viewPane.
154 init : function(viewPane
){
155 this.setView(viewPane
);
156 this.setViewSelection(new org
.argeo
.ria
.components
.ViewSelection(viewPane
.getViewId()));
158 this.toolBar
= new qx
.ui
.toolbar
.ToolBar();
159 this.toolBarPart
= new qx
.ui
.toolbar
.Part();
160 this.toolBar
.add(this.toolBarPart
);
161 viewPane
.add(this.toolBar
);
163 this.tableModel
= new qx
.ui
.table
.model
.Filtered();
164 this.tableModel
.setColumns(["username", "roles"]);
165 this.table
= new qx
.ui
.table
.Table(this.tableModel
, {
166 tableColumnModel: function(obj
){
167 return new qx
.ui
.table
.columnmodel
.Resize(obj
)
170 this.table
.setStatusBarVisible(false);
171 this.table
.setShowCellFocusIndicator(false);
172 this.table
.setColumnVisibilityButtonVisible(false);
173 this.table
.highlightFocusedRow(false);
174 viewPane
.add(this.table
, {height
:"100%"});
175 this.table
.getSelectionModel().addListener("changeSelection", function(){
176 this._selectionToValues(this.table
.getSelectionModel(), this.getViewSelection());
178 this.table
.addListener("cellDblclick", function(cellEvent
){
179 this.getCommands()["edit_user"].command
.execute();
182 this.setRolesList([]);
183 this.setUsersList({});
184 this.setGuiMode("clear");
187 _applyGuiMode : function(newMode
, oldMode
){
188 this.table
.getSelectionModel().clearSelection();
189 this.resetHiddenRows();
190 if(newMode
== "filter"){
191 this.table
.getSelectionModel().setSelectionMode(qx
.ui
.table
.selection
.Model
.SINGLE_SELECTION
);
192 }else if(newMode
== "chooser"){
193 this.table
.getSelectionModel().setSelectionMode(qx
.ui
.table
.selection
.Model
.MULTIPLE_INTERVAL_SELECTION_TOGGLE
);
194 }else if(newMode
== "clear"){
195 this.table
.getSelectionModel().setSelectionMode(qx
.ui
.table
.selection
.Model
.SINGLE_SELECTION
);
199 _selectionToValues : function(selectionModel
, viewSelection
){
201 viewSelection
.setBatchMode(true);
202 viewSelection
.clear();
204 if(!selectionModel
.getSelectedCount()) return [];
205 var ranges
= selectionModel
.getSelectedRanges();
207 for(var i
=0;i
<ranges
.length
;i
++){
208 for(var j
=ranges
[i
].minIndex
;j
<=ranges
[i
].maxIndex
;j
++){
209 values
.push(this.tableModel
.getData()[j
][0]);
211 viewSelection
.addNode(this.tableModel
.getData()[j
][0]);
216 viewSelection
.setBatchMode(false);
222 * Load a given row : the data passed must be a simple data array.
223 * @param data {Element} The text xml description.
226 var commands
= this.getCommands();
227 this.toolBarPart
.add(commands
["new_user"].command
.getToolbarButton());
228 this.toolBarPart
.add(commands
["delete_user"].command
.getToolbarButton());
229 this.toolBarPart
.add(commands
["edit_user"].command
.getToolbarButton());
230 this.toolBar
.setShow("icon");
231 this.loadUsersList();
233 var rolesApplet
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getViewPaneById("roles").getContent();
234 rolesApplet
.addListener("changeRolesList", function(e
){
235 this.setRolesList(e
.getData());
236 this.loadUsersList();
241 loadUsersList : function(){
242 var selectionModel
= this.table
.getSelectionModel();
243 selectionModel
.clearSelection();
244 var request
= org
.argeo
.security
.ria
.SecurityAPI
.getListUsersService();
245 request
.addListener("completed", function(response
){
246 var jSon
= response
.getContent();
248 for(var i
=0;i
<jSon
.length
;i
++){
249 var user
= new org
.argeo
.security
.ria
.model
.User();
250 user
.load(jSon
[i
], "json");
251 usMap
[user
.getName()] = user
;
253 this.setUsersList(usMap
);
260 * @param {org.argeo.security.ria.model.User} userObject
262 refreshUserEntry : function(userObject
){
263 var userName
= userObject
.getName();
264 var data
= this.tableModel
.getDataAsMapArray();
267 for(index
=0;index
<data
.length
;index
++){
268 if(data
[index
].username
== userName
){
273 var newRows
= [{username
:userName
,roles
:userObject
.getRoles().join(",")}];
275 this.tableModel
.setRowsAsMapArray(newRows
, index
);
277 this.tableModel
.setRowsAsMapArray(newRows
, index
);
281 _applyUsersList : function(usList
){
283 qx
.lang
.Object
.getValues(usList
).forEach(function(usObject
){
284 data
.push([usObject
.getName(), usObject
.getRoles().join(",")]);
286 this.tableModel
.setData(data
);
289 applySelection : function(selectionValue
, target
, ignoreCase
){
290 var selectionModel
= this.table
.getSelectionModel();
291 selectionModel
.clearSelection();
295 selectionModel
.setBatchMode(true);
296 var data
= this.tableModel
.getData();
297 for(var i
=0;i
<this.tableModel
.getRowCount();i
++){
298 var value
= this.tableModel
.getRowDataAsMap(i
)[target
];
299 var pattern
= new RegExp(selectionValue
, "g"+(ignoreCase
?"i":""));
300 if(pattern
.test(value
)){
301 selectionModel
.addSelectionInterval(i
, i
);
304 selectionModel
.setBatchMode(false);
307 applyFilter : function(filterValues
, target
, ignoreCase
){
308 this.table
.clearSelection();
309 this.resetHiddenRows();
310 for(var i
=0;i
<filterValues
.length
;i
++){
311 this.tableModel
.addRegex("^((?!"+filterValues
[i
]+").)*$", target
, ignoreCase
);
313 this.tableModel
.applyFilters();
316 resetHiddenRows : function(){
317 this.tableModel
.resetHiddenRows();
320 addScroll : function(){