]>
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
3aa2e2fd080381811454f93b9f5c0d5c26640b39
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"
28 apply
: "_applyDetailsModified"
32 apply
: "_applyNaturesModified"
43 check
: "org.argeo.security.ria.components.NaturesManager"
54 initGUI : function(ROLES_LIST
){
56 var naturesManager
= new org
.argeo
.security
.ria
.components
.NaturesManager();
57 this.setNaturesManager(naturesManager
);
60 this.buttonGB
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.HBox(5, "right"));
61 this.add(this.buttonGB
);
63 this.setCurrentNatureTabs([]);
64 this.naturesTab
= new qx
.ui
.tabview
.TabView("top");
65 this.naturesTab
.addListener("changeSelection", function(e
){
66 this.setSelectedNatureTab(e
.getData()[0] || null);
69 this.basicPage
= new qx
.ui
.tabview
.Page("Basic Information");
70 this.basicPage
.setLayout(new qx
.ui
.layout
.VBox(5));
74 this.basicGB
= new qx
.ui
.groupbox
.GroupBox("Base Informations");
75 var grid
= new qx
.ui
.layout
.Grid(5,5);
76 this.basicGB
.setLayout(grid
);
77 grid
.setColumnFlex(0,1);
78 grid
.setColumnAlign(0,"right", "middle");
79 grid
.setColumnFlex(1,2);
80 this._initializeGroupBox(this.basicGB
);
82 this.passGB
= new qx
.ui
.groupbox
.GroupBox("Set/Modify Password");
83 this.passGB
.setLayout(new qx
.ui
.layout
.VBox());
84 this._initializeGroupBox(this.passGB
);
86 this.add(this.basicGB
);
87 this.add(this.passGB
);
90 this.usernameField
= new qx
.ui
.form
.TextField();
91 this.basicGB
.add(new qx
.ui
.basic
.Label("Username"), {row
:0,column
:0});
92 this.basicGB
.add(this.usernameField
, {row
:0,column
:1});
94 this.rolesField
= new org
.argeo
.ria
.components
.ui
.MultipleComboBox();
96 this.rolesField
.setChoiceValues(ROLES_LIST
);
98 this.basicGB
.add(new qx
.ui
.basic
.Label("Roles"), {row
:1,column
:0});
99 this.basicGB
.add(this.rolesField
, {row
:1,column
:1});
101 this.passPane
= new org
.argeo
.security
.ria
.components
.PasswordCredentialImpl(this.getSelfEdition());
102 this.passGB
.add(this.passPane
.getContainer());
104 //this.naturesTab.add(this.basicPage);
105 this.natureButtonGB
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.HBox(5, "right"));
106 this.natureButtonGB
.setMarginTop(15);
107 this.add(this.natureButtonGB
);
110 this.add(this.naturesTab
, {flex
:1});
112 this.naturesTab
.setVisibility("excluded");
113 this.fakePane
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.Canvas());
114 this.fakePane
.setVisibility("visible");
115 this.fakePane
.setDecorator("tabview-pane");
116 this.fakePane
.setMarginTop(30);
117 this.add(this.fakePane
, {flex
:1});
119 title
= new qx
.ui
.basic
.Atom("User Details", "org.argeo.security.ria/preferences-users.png");
120 title
.setFont(qx
.bom
.Font
.fromString("16px sans-serif bold"));
121 this.buttonGB
.add(title
);
122 this.buttonGB
.add(new qx
.ui
.core
.Spacer(), {flex
:1});
124 var title2
= new qx
.ui
.basic
.Atom("User Natures", "org.argeo.security.ria/identity.png");
125 title2
.setFont(qx
.bom
.Font
.fromString("16px sans-serif bold"));
126 this.natureButtonGB
.add(title2
);
127 this.natureButtonGB
.add(new qx
.ui
.core
.Spacer(), {flex
:1});
132 saveUser : function(){
133 var user
= this.getCurrentUser();
134 if(this.basicGB
.getVisibility()!= "excluded"){
135 user
.setName(this.usernameField
.getValue());
136 var roles
= this.rolesField
.getValue();
137 if(roles
&& roles
!= ""){
138 user
.setRoles(roles
.split(","));
144 // GO TO AND RETURN FROM SERVER
146 if(!this.passPane
.validate()){
147 this.error("Warning, passwords differ!");
150 user
.setPassword(this.passPane
.getData());
152 var userExists
= false;
153 var req
= org
.argeo
.security
.ria
.SecurityAPI
.getUserExistsService(user
.getName());
154 req
.addListener("completed", function(response
){
155 userExists
= response
.getContent().value
;
157 req
.setAsynchronous(false);
160 this.error("User already exists, choose another name!");
164 var pass
= this.passPane
.getData();
165 if(pass
!= null && !this.passPane
.validate()){
166 this.error("Warning, passwords differ!");
170 this.passPane
.clear();
171 var saveCompletedCallback
= qx
.lang
.Function
.bind(function(){
172 this._setGuiInCreateMode(false);
173 this.partialRefreshUser(user
, ["details","natures"]);
174 this.setModified(false);
175 this.fireDataEvent("savedUser", user
);
177 var userService
= user
.getSaveService(this.getSelfEdition());
178 userService
.addListener("completed", function(response
){
179 if(response
.getContent().status
&& response
.getContent().status
== "ERROR"){
182 user
.load(response
.getContent(), "json");
185 if(!this.getSelfEdition()){
186 passService
= org
.argeo
.security
.ria
.SecurityAPI
.getUpdateUserPassService(user
.getName(), pass
);
188 passService
= org
.argeo
.security
.ria
.SecurityAPI
.getUpdatePassService(pass
.oldPass
, pass
.newPass
);
190 passService
.addListener("completed", function(response
){
191 if(response
.getContent().status
!= "ERROR"){
192 this.info(response
.getContent().message
);
194 saveCompletedCallback();
198 saveCompletedCallback();
204 _addNatureTab : function(natureClass
, natureData
, select
){
205 var crtTabs
= this.getCurrentNatureTabs();
206 if(qx
.lang
.Array
.contains(crtTabs
, natureClass
.NATURE_TYPE
)){
207 this.error("There can only be one instance of a given nature type!");
210 if(!this.naturesTab
.isVisible()){
211 if(this.fakePane
) this.fakePane
.setVisibility("excluded");
212 this.naturesTab
.setVisibility("visible");
214 var page
= new qx
.ui
.tabview
.Page("Nature : " + natureClass
.NATURE_LABEL
);
215 page
.setLayout(new qx
.ui
.layout
.Dock());
216 page
.setUserData("NATURE_CLASS", natureClass
);
217 var newClass
= new natureClass();
218 page
.add(new qx
.ui
.container
.Scroll(newClass
.getContainer()), {edge
:"center"});
220 buttons
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.HBox(5, "center"));
221 var editB
= new qx
.ui
.form
.Button("Edit this Nature", "org.argeo.security.ria/document-properties-22.png");
222 var saveB
= new qx
.ui
.form
.Button("Save", "org.argeo.security.ria/dialog-apply.png");
223 var cancelB
= new qx
.ui
.form
.Button("Cancel", "org.argeo.security.ria/dialog-cancel.png");
226 buttons
.add(cancelB
);
227 page
.add(buttons
, {edge
:"south"});
228 editB
.addListener("execute", function(){
229 newClass
.setEditMode(true);
230 editB
.setVisibility("excluded");
231 saveB
.setVisibility("visible");
232 cancelB
.setVisibility("visible");
234 cancelB
.addListener("execute", function(){
235 if(newClass
.getIsNew()){
236 this._removeNatureTab(natureClass
);
238 newClass
.setEditMode(false);
239 editB
.setVisibility("visible");
240 saveB
.setVisibility("excluded");
241 cancelB
.setVisibility("excluded");
243 saveB
.addListener("execute", function(){
244 // SAVE CURRENT NATURE
245 var data
= newClass
.getData();
246 if(newClass
.getIsNew()){
247 this.getCurrentUser().addNature(data
);
249 this.getCurrentUser().updateNature(data
);
252 this.setNaturesModified(false);
253 newClass
.setEditMode(false);
254 editB
.setVisibility("visible");
255 saveB
.setVisibility("excluded");
256 cancelB
.setVisibility("excluded");
259 newClass
.setData(natureData
);
262 newClass
.setIsNew(true);
265 this.naturesTab
.add(page
);
266 crtTabs
.push(natureClass
.NATURE_TYPE
);
267 newClass
.addListener("modified", function(){
268 this.setNaturesModified(true);
271 this.naturesTab
.setSelection([page
]);
276 _removeNatureTab : function(natureClass
){
277 this.naturesTab
.getChildren().forEach(function(el
){
278 if(el
.getUserData("NATURE_CLASS") == natureClass
){
279 this.naturesTab
.remove(el
);
280 qx
.lang
.Array
.remove(this.getCurrentNatureTabs(), natureClass
.NATURE_TYPE
);
283 if(this.naturesTab
.getChildren().length
== 0){
284 this.naturesTab
.setVisibility("excluded");
285 this.fakePane
.setVisibility("visible");
289 removeSelectedTab : function(){
290 if(this.naturesTab
.isSelectionEmpty()) return;
291 var selected
= this.naturesTab
.getSelection()[0];
292 var tabClass
= selected
.getUserData("NATURE_CLASS");
293 var user
= this.getCurrentUser();
294 user
.removeNature(tabClass
.NATURE_TYPE
);
296 this._removeNatureTab(tabClass
);
299 removeAllTabs : function(){
300 while(!this.naturesTab
.isSelectionEmpty()){
301 this._removeNatureTab(this.naturesTab
.getSelection()[0].getUserData("NATURE_CLASS"));
305 _setGuiInCreateMode : function(bool
){
307 if(!this.natureButtonGB
.isVisible()) return;
308 this.natureButtonGB
.hide();
309 this.fakePane
.setVisibility("excluded");
311 if(this.natureButtonGB
.isVisible()) return;
312 this.natureButtonGB
.show();
313 this.fakePane
.setVisibility("visible");
317 _attachListeners : function(){
318 this.usernameField
.addListener("changeValue", function(){
319 this.setModified(true);
321 this.rolesField
.addListener("changeValue", function(){
322 this.setModified(true);
324 this.passPane
.addListener("modified", function(){
325 this.setModified(true);
329 _initializeGroupBox: function(groupBox
){
330 groupBox
.setPadding(0);
331 groupBox
.getChildrenContainer().setPadding(8);
334 loadUserData : function(userName
){
335 var userDataService
= org
.argeo
.security
.ria
.SecurityAPI
.getUserDetailsService(userName
);
336 userDataService
.addListener("completed", function(response
){
337 var user
= new org
.argeo
.security
.ria
.model
.User();
338 user
.load(response
.getContent(), "json");
339 this.setCurrentUser(user
);
340 this.usernameField
.setValue(user
.getName());
341 this.usernameField
.setReadOnly(true);
342 this.rolesField
.setValue(user
.getRoles());
343 var userNatureTabs
= this.getNaturesManager().detectNaturesInData(user
.getNatures());
344 if(userNatureTabs
.length
){
345 userNatureTabs
.forEach(function(el
){
346 this._addNatureTab(el
.NATURE_CLASS
, el
.NATURE_DATA
);
349 this._attachListeners();
351 userDataService
.send();
354 clearUserData : function(){
355 this.usernameField
.setValue("");
356 this.rolesField
.setValue([]);
357 this.removeAllTabs();
360 partialRefreshUser : function(user
, target
){
361 if(!qx
.lang
.Type
.isArray(target
)) target
= [target
];
363 if(qx
.lang
.Array
.contains(target
,"natures")){
364 if(this.getSelectedNatureTab()){
365 var selectedTab
= this.getSelectedNatureTab().getUserData("NATURE_CLASS");
367 this.removeAllTabs();
368 var userNatureTabs
= this.getNaturesManager().detectNaturesInData(user
.getNatures());
369 if(userNatureTabs
.length
){
370 userNatureTabs
.forEach(function(el
){
371 this._addNatureTab(el
.NATURE_CLASS
, el
.NATURE_DATA
, (selectedTab
&& selectedTab
== el
.NATURE_CLASS
));
375 if(qx
.lang
.Array
.contains(target
,"details")){
376 this.usernameField
.setValue(user
.getName());
377 this.rolesField
.setValue(user
.getRoles());
378 this.usernameField
.setReadOnly(true);
379 this.fireEvent("saveUser");
383 _applyDetailsModified : function(value
){},
385 _applyNaturesModified : function(value
){}