]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/components/UserEditor.js
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.components.UserEditor",
10 extend
: qx
.ui
.container
.Composite
,
12 construct : function(){
14 this.setLayout(new qx
.ui
.layout
.VBox(5));
18 "savedUser" : "qx.event.type.Data"
25 apply
: "_applyDetailsModified"
29 apply
: "_applyNaturesModified"
50 initGUI : function(ROLES_LIST
){
52 this.naturesManager
= new org
.argeo
.security
.ria
.components
.NaturesManager();
53 var detectedNatures
= this.naturesManager
.getDetectedNatures();
54 this.setAvailableNatures(detectedNatures
);
57 this.buttonGB
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.HBox(5, "right"));
58 this.add(this.buttonGB
);
60 this.setCurrentNatureTabs([]);
61 this.naturesTab
= new qx
.ui
.tabview
.TabView("top");
62 this.naturesTab
.addListener("changeSelection", function(e
){
63 this.setSelectedNatureTab(e
.getData()[0] || null);
66 this.basicPage
= new qx
.ui
.tabview
.Page("Basic Information");
67 this.basicPage
.setLayout(new qx
.ui
.layout
.VBox(5));
71 this.basicGB
= new qx
.ui
.groupbox
.GroupBox("Base Informations");
72 var grid
= new qx
.ui
.layout
.Grid(5,5);
73 this.basicGB
.setLayout(grid
);
74 grid
.setColumnFlex(0,1);
75 grid
.setColumnAlign(0,"right", "middle");
76 grid
.setColumnFlex(1,2);
77 this._initializeGroupBox(this.basicGB
);
79 this.passGB
= new qx
.ui
.groupbox
.GroupBox("Set/Modify Password");
80 this.passGB
.setLayout(new qx
.ui
.layout
.VBox());
81 this._initializeGroupBox(this.passGB
);
83 this.add(this.basicGB
);
84 this.add(this.passGB
);
87 this.usernameField
= new qx
.ui
.form
.TextField();
88 this.basicGB
.add(new qx
.ui
.basic
.Label("Username"), {row
:0,column
:0});
89 this.basicGB
.add(this.usernameField
, {row
:0,column
:1});
91 this.rolesField
= new org
.argeo
.ria
.components
.ui
.MultipleComboBox();
93 this.rolesField
.setChoiceValues(ROLES_LIST
);
95 this.basicGB
.add(new qx
.ui
.basic
.Label("Roles"), {row
:1,column
:0});
96 this.basicGB
.add(this.rolesField
, {row
:1,column
:1});
98 this.passPane
= new org
.argeo
.security
.ria
.components
.PasswordCredentialImpl();
99 this.passGB
.add(this.passPane
.getContainer());
101 //this.naturesTab.add(this.basicPage);
102 this.natureButtonGB
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.HBox(5, "right"));
103 this.natureButtonGB
.setMarginTop(15);
104 this.add(this.natureButtonGB
);
107 this.add(this.naturesTab
, {flex
:1});
109 this.naturesTab
.setVisibility("excluded");
110 this.fakePane
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.Canvas());
111 this.fakePane
.setVisibility("visible");
112 this.fakePane
.setDecorator("tabview-pane");
113 this.fakePane
.setMarginTop(30);
114 this.add(this.fakePane
, {flex
:1});
116 title
= new qx
.ui
.basic
.Atom("User Details", "org.argeo.security.ria/preferences-users.png");
117 title
.setFont(qx
.bom
.Font
.fromString("16px sans-serif bold"));
118 this.buttonGB
.add(title
);
119 this.buttonGB
.add(new qx
.ui
.core
.Spacer(), {flex
:1});
121 var title2
= new qx
.ui
.basic
.Atom("User Natures", "org.argeo.security.ria/identity.png");
122 title2
.setFont(qx
.bom
.Font
.fromString("16px sans-serif bold"));
123 this.natureButtonGB
.add(title2
);
124 this.natureButtonGB
.add(new qx
.ui
.core
.Spacer(), {flex
:1});
129 saveUser : function(){
130 var user
= this.getCurrentUser();
131 if(this.basicGB
.getVisibility()!= "excluded"){
132 user
.setName(this.usernameField
.getValue());
133 var roles
= this.rolesField
.getValue();
134 if(roles
&& roles
!= ""){
135 user
.setRoles(roles
.split(","));
141 // GO TO AND RETURN FROM SERVER
143 if(!this.passPane
.validate()){
144 this.error("Warning, passwords differ!");
147 user
.setPassword(this.passPane
.getData());
149 var userExists
= false;
150 var req
= org
.argeo
.security
.ria
.SecurityAPI
.getUserExistsService(user
.getName());
151 req
.addListener("completed", function(response
){
152 userExists
= response
.getContent().value
;
154 req
.setAsynchronous(false);
157 this.error("User already exists, choose another name!");
161 var pass
= this.passPane
.getData();
162 if(pass
!= null && !this.passPane
.validate()){
163 this.error("Warning, passwords differ!");
167 this.passPane
.clear();
168 var saveCompletedCallback
= qx
.lang
.Function
.bind(function(){
169 this._setGuiInCreateMode(false);
170 this.partialRefreshUser(user
, ["details","natures"]);
171 this.setModified(false);
172 this.fireDataEvent("savedUser", user
);
174 var userService
= user
.getSaveService();
175 userService
.addListener("completed", function(response
){
176 if(response
.getContent().status
&& response
.getContent().status
== "ERROR"){
179 user
.load(response
.getContent(), "json");
181 var passService
= org
.argeo
.security
.ria
.SecurityAPI
.getUpdateUserPassService(user
.getName(), pass
);
182 passService
.addListener("completed", function(response
){
183 if(response
.getContent().status
){
184 this.info(response
.getContent().message
);
186 saveCompletedCallback();
190 saveCompletedCallback();
196 _addNatureTab : function(natureClass
, natureData
, select
){
197 var crtTabs
= this.getCurrentNatureTabs();
198 if(qx
.lang
.Array
.contains(crtTabs
, natureClass
.NATURE_TYPE
)){
199 this.error("There can only be one instance of a given nature type!");
202 if(!this.naturesTab
.isVisible()){
203 if(this.fakePane
) this.fakePane
.setVisibility("excluded");
204 this.naturesTab
.setVisibility("visible");
206 var page
= new qx
.ui
.tabview
.Page("Nature : " + natureClass
.NATURE_LABEL
);
207 page
.setLayout(new qx
.ui
.layout
.Dock());
208 page
.setUserData("NATURE_CLASS", natureClass
);
209 var newClass
= new natureClass();
210 page
.add(newClass
.getContainer(), {edge
:"center"});
212 buttons
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.HBox(5, "center"));
213 var editB
= new qx
.ui
.form
.Button("Edit this Nature", "org.argeo.security.ria/document-properties-22.png");
214 var saveB
= new qx
.ui
.form
.Button("Save", "org.argeo.security.ria/dialog-apply.png");
215 var cancelB
= new qx
.ui
.form
.Button("Cancel", "org.argeo.security.ria/dialog-cancel.png");
218 buttons
.add(cancelB
);
219 page
.add(buttons
, {edge
:"south"});
220 editB
.addListener("execute", function(){
221 newClass
.setEditMode(true);
222 editB
.setVisibility("excluded");
223 saveB
.setVisibility("visible");
224 cancelB
.setVisibility("visible");
226 cancelB
.addListener("execute", function(){
227 if(newClass
.getIsNew()){
228 this._removeNatureTab(natureClass
);
230 newClass
.setEditMode(false);
231 editB
.setVisibility("visible");
232 saveB
.setVisibility("excluded");
233 cancelB
.setVisibility("excluded");
235 saveB
.addListener("execute", function(){
236 // SAVE CURRENT NATURE
237 var data
= newClass
.getData();
238 if(newClass
.getIsNew()){
239 this.getCurrentUser().addNature(data
);
241 this.getCurrentUser().updateNature(data
);
244 this.setNaturesModified(false);
245 newClass
.setEditMode(false);
246 editB
.setVisibility("visible");
247 saveB
.setVisibility("excluded");
248 cancelB
.setVisibility("excluded");
251 newClass
.setData(natureData
);
254 newClass
.setIsNew(true);
257 this.naturesTab
.add(page
);
258 crtTabs
.push(natureClass
.NATURE_TYPE
);
259 newClass
.addListener("modified", function(){
260 this.setNaturesModified(true);
263 this.naturesTab
.setSelection([page
]);
268 _removeNatureTab : function(natureClass
){
269 this.naturesTab
.getChildren().forEach(function(el
){
270 if(el
.getUserData("NATURE_CLASS") == natureClass
){
271 this.naturesTab
.remove(el
);
272 qx
.lang
.Array
.remove(this.getCurrentNatureTabs(), natureClass
.NATURE_TYPE
);
275 if(this.naturesTab
.getChildren().length
== 0){
276 this.naturesTab
.setVisibility("excluded");
277 this.fakePane
.setVisibility("visible");
281 removeSelectedTab : function(){
282 if(this.naturesTab
.isSelectionEmpty()) return;
283 var selected
= this.naturesTab
.getSelection()[0];
284 var tabClass
= selected
.getUserData("NATURE_CLASS");
285 var user
= this.getCurrentUser();
286 user
.removeNature(tabClass
.NATURE_TYPE
);
288 this._removeNatureTab(tabClass
);
291 removeAllTabs : function(){
292 while(!this.naturesTab
.isSelectionEmpty()){
293 this._removeNatureTab(this.naturesTab
.getSelection()[0].getUserData("NATURE_CLASS"));
297 _setGuiInCreateMode : function(bool
){
299 if(!this.natureButtonGB
.isVisible()) return;
300 this.natureButtonGB
.hide();
301 this.fakePane
.setVisibility("excluded");
303 if(this.natureButtonGB
.isVisible()) return;
304 this.natureButtonGB
.show();
305 this.fakePane
.setVisibility("visible");
309 _attachListeners : function(){
310 this.usernameField
.addListener("changeValue", function(){
311 this.setModified(true);
313 this.rolesField
.addListener("changeValue", function(){
314 this.setModified(true);
316 this.passPane
.addListener("modified", function(){
317 this.setModified(true);
321 _initializeGroupBox: function(groupBox
){
322 groupBox
.setPadding(0);
323 groupBox
.getChildrenContainer().setPadding(8);
326 loadUserData : function(userName
){
327 var userDataService
= org
.argeo
.security
.ria
.SecurityAPI
.getUserDetailsService(userName
);
328 userDataService
.addListener("completed", function(response
){
329 var user
= new org
.argeo
.security
.ria
.model
.User();
330 user
.load(response
.getContent(), "json");
331 this.setCurrentUser(user
);
332 this.usernameField
.setValue(user
.getName());
333 this.usernameField
.setReadOnly(true);
334 this.rolesField
.setValue(user
.getRoles());
335 var userNatureTabs
= this.naturesManager
.detectNaturesInData(user
.getNatures());
336 if(userNatureTabs
.length
){
337 userNatureTabs
.forEach(function(el
){
338 this._addNatureTab(el
.NATURE_CLASS
, el
.NATURE_DATA
);
341 this._attachListeners();
343 userDataService
.send();
346 clearUserData : function(){
347 this.usernameField
.setValue("");
348 this.rolesField
.setValue([]);
349 this.removeAllTabs();
352 partialRefreshUser : function(user
, target
){
353 if(!qx
.lang
.Type
.isArray(target
)) target
= [target
];
355 if(qx
.lang
.Array
.contains(target
,"natures")){
356 if(this.getSelectedNatureTab()){
357 var selectedTab
= this.getSelectedNatureTab().getUserData("NATURE_CLASS");
359 this.removeAllTabs();
360 var userNatureTabs
= this.naturesManager
.detectNaturesInData(user
.getNatures());
361 if(userNatureTabs
.length
){
362 userNatureTabs
.forEach(function(el
){
363 this._addNatureTab(el
.NATURE_CLASS
, el
.NATURE_DATA
, (selectedTab
&& selectedTab
== el
.NATURE_CLASS
));
367 if(qx
.lang
.Array
.contains(target
,"details")){
368 this.usernameField
.setValue(user
.getName());
369 this.rolesField
.setValue(user
.getRoles());
370 this.usernameField
.setReadOnly(true);
371 this.fireEvent("saveUser");
375 _applyDetailsModified : function(value
){},
377 _applyNaturesModified : function(value
){}