]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - ria/UserEditorApplet.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.UserEditorApplet",
10 extend
: qx
.ui
.container
.Composite
,
11 implement
: [org
.argeo
.ria
.components
.IView
],
13 construct : function(){
15 this.setLayout(new qx
.ui
.layout
.VBox(5));
19 "savedUser" : "qx.event.type.Data"
25 * The viewPane inside which this applet is added.
31 * Commands definition, see {@link org.argeo.ria.event.CommandsManager#definitions}
37 icon
: "org.argeo.security.ria/document-save.png",
38 shortcut
: "Control+s",
42 callback : function(e
){
43 // CALL SERVICE AND GET UP TO DATE USER
46 selectionChange : function(viewName
, data
){
47 if(viewName
!= "editor") return;
48 var iApplet
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getViewPaneById("editor").getContent();
49 this.setEnabled(iApplet
.getModified());
54 label
: "Add Nature ...",
55 icon
: "org.argeo.security.ria/list-add.png",
60 callback : function(e
){
62 submenuCallback : function(commandClass
){
63 this._addNatureTab(commandClass
, null, true);
66 {"label" : "Totot", "icon":"","commandId" : "toto"},
67 {"label" : "Totot", "icon":"","commandId" : "toto"}
69 selectionChange : function(viewName
, data
){
70 if(viewName
!= "editor") return;
71 var iApplet
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getViewPaneById("editor").getContent();
72 if(iApplet
&& iApplet
.getCurrentNatureTabs() && iApplet
.getAvailableNatures()
73 && iApplet
.getCurrentNatureTabs().length
< qx
.lang
.Object
.getLength(iApplet
.getAvailableNatures())){
74 this.setEnabled(true);
76 this.setEnabled(false);
82 label
: "Remove Nature",
83 icon
: "org.argeo.security.ria/list-remove.png",
88 callback : function(e
){
89 this.removeSelectedTab();
91 selectionChange : function(viewName
, data
){
92 if(viewName
!= "editor") return;
93 var iApplet
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getViewPaneById("editor").getContent();
94 if(iApplet
&& iApplet
.getSelectedNatureTab() && iApplet
.getSelectedNatureTab().getUserData("NATURE_CLASS")){
95 this.setEnabled(true);
97 this.setEnabled(false);
104 icon
: "org.argeo.security.ria/window-close.png",
105 shortcut
: "Control+w",
109 callback : function(e
){
110 // Call service to delete
111 var iApplet
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getViewPaneById("editor").getContent();
112 if(!iApplet
.getModified() && !iApplet
.getNaturesModified()){
113 this.getView().closeCurrent();
116 var modal
= new org
.argeo
.ria
.components
.Modal("Warning");
117 modal
.addConfirm("There are unsaved changes!\n Are you sure you want to close?");
118 modal
.addListener("ok", function(){
119 this.getView().closeCurrent();
121 modal
.attachAndShow();
129 check
:"org.argeo.ria.components.ViewSelection"
133 apply
: "_applyDetailsModified"
137 apply
: "_applyNaturesModified"
142 instanceId
: {init
:""},
143 instanceLabel
: {init
:"Editor"},
147 currentNatureTabs
: {
151 selectedNatureTab
: {
162 * Called at applet creation. Just registers viewPane.
163 * @param viewPane {org.argeo.ria.components.ViewPane} The viewPane.
165 init : function(viewPane
, data
){
167 var now
= new Date();
168 this.setInstanceId(now
.getTime());
169 this.setInstanceLabel("New User");
171 this.setInstanceId(data
.USER
);
172 this.setInstanceLabel("User " + data
.USER
);
174 this.setView(viewPane
);
175 this.setViewSelection(new org
.argeo
.ria
.components
.ViewSelection(viewPane
.getViewId()));
177 this.naturesManager
= new org
.argeo
.security
.ria
.components
.NaturesManager();
178 var detectedNatures
= this.naturesManager
.getDetectedNatures();
179 this.setAvailableNatures(detectedNatures
);
182 this.buttonGB
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.HBox(5, "right"));
183 this.add(this.buttonGB
);
185 this.setCurrentNatureTabs([]);
186 this.naturesTab
= new qx
.ui
.tabview
.TabView("top");
187 this.naturesTab
.addListener("changeSelected", function(e
){
188 this.setSelectedNatureTab(e
.getData());
189 this.getViewSelection().triggerEvent();
192 this.basicPage
= new qx
.ui
.tabview
.Page("Basic Information");
193 this.basicPage
.setLayout(new qx
.ui
.layout
.VBox(5));
197 this.basicGB
= new qx
.ui
.groupbox
.GroupBox("Base Informations");
198 var grid
= new qx
.ui
.layout
.Grid(5,5);
199 this.basicGB
.setLayout(grid
);
200 grid
.setColumnFlex(0,1);
201 grid
.setColumnAlign(0,"right", "middle");
202 grid
.setColumnFlex(1,2);
203 this._initializeGroupBox(this.basicGB
);
205 this.passGB
= new qx
.ui
.groupbox
.GroupBox("Set/Modify Password");
206 this.passGB
.setLayout(new qx
.ui
.layout
.VBox());
207 this._initializeGroupBox(this.passGB
);
209 this.add(this.basicGB
);
210 this.add(this.passGB
);
213 this.usernameField
= new qx
.ui
.form
.TextField();
214 this.basicGB
.add(new qx
.ui
.basic
.Label("Username"), {row
:0,column
:0});
215 this.basicGB
.add(this.usernameField
, {row
:0,column
:1});
217 this.rolesField
= new org
.argeo
.ria
.components
.ui
.MultipleComboBox();
218 this.rolesField
.setChoiceValues(data
.ROLES_LIST
);
219 this.basicGB
.add(new qx
.ui
.basic
.Label("Roles"), {row
:1,column
:0});
220 this.basicGB
.add(this.rolesField
, {row
:1,column
:1});
222 this.passPane
= new org
.argeo
.security
.ria
.components
.PasswordCredentialImpl();
223 this.passGB
.add(this.passPane
.getContainer());
225 //this.naturesTab.add(this.basicPage);
226 this.natureButtonGB
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.HBox(5, "right"));
227 this.natureButtonGB
.setMarginTop(15);
228 this.add(this.natureButtonGB
);
231 this.add(this.naturesTab
, {flex
:1});
233 this.naturesTab
.setVisibility("excluded");
234 this.fakePane
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.Canvas());
235 this.fakePane
.setVisibility("visible");
236 this.fakePane
.setDecorator("tabview-pane");
237 this.fakePane
.setMarginTop(30);
238 this.add(this.fakePane
, {flex
:1});
240 title
= new qx
.ui
.basic
.Atom("User Details", "org.argeo.security.ria/preferences-users.png");
241 title
.setFont(qx
.bom
.Font
.fromString("16px sans-serif bold"));
242 this.buttonGB
.add(title
);
243 this.buttonGB
.add(new qx
.ui
.core
.Spacer(), {flex
:1});
245 var title2
= new qx
.ui
.basic
.Atom("User Natures", "org.argeo.security.ria/identity.png");
246 title2
.setFont(qx
.bom
.Font
.fromString("16px sans-serif bold"));
247 this.natureButtonGB
.add(title2
);
248 this.natureButtonGB
.add(new qx
.ui
.core
.Spacer(), {flex
:1});
253 saveUser : function(){
254 var user
= this.getCurrentUser();
255 user
.setName(this.usernameField
.getValue());
256 user
.setRoles((this.rolesField
.getValue()||"").split(","));
257 // GO TO AND RETURN FROM SERVER
259 var userExists
= false;
260 var req
= org
.argeo
.security
.ria
.SecurityAPI
.getUserExistsService(user
.getName());
261 req
.addListener("completed", function(response
){
262 userExists
= response
.getContent().value
;
264 req
.setAsynchronous(false);
267 this.error("User already exists, choose another name!");
271 var userService
= user
.getSaveService();
273 userService
.addListener("completed", function(response
){
274 if(response
.getContent().status
&& response
.getContent().status
== "ERROR"){
277 this._setGuiInCreateMode(false);
278 user
.load(response
.getContent(), "json");
279 this.partialRefreshUser(user
, ["details","natures"]);
280 this.setModified(false);
281 this.getViewSelection().triggerEvent();
282 this.fireDataEvent("savedUser", user
);
286 _addNatureTab : function(natureClass
, natureData
, select
){
287 var crtTabs
= this.getCurrentNatureTabs();
288 if(qx
.lang
.Array
.contains(crtTabs
, natureClass
.NATURE_TYPE
)){
289 this.error("There can only be one instance of a given nature type!");
292 if(!this.naturesTab
.isVisible()){
293 if(this.fakePane
) this.fakePane
.setVisibility("excluded");
294 this.naturesTab
.setVisibility("visible");
296 var page
= new qx
.ui
.tabview
.Page("Nature : " + natureClass
.NATURE_LABEL
);
297 page
.setLayout(new qx
.ui
.layout
.Dock());
298 page
.setUserData("NATURE_CLASS", natureClass
);
299 var newClass
= new natureClass();
300 page
.add(newClass
.getContainer(), {edge
:"center"});
302 buttons
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.HBox(5, "center"));
303 var editB
= new qx
.ui
.form
.Button("Edit this Nature", "org.argeo.security.ria/document-properties-22.png");
304 var saveB
= new qx
.ui
.form
.Button("Save", "org.argeo.security.ria/dialog-apply.png");
305 var cancelB
= new qx
.ui
.form
.Button("Cancel", "org.argeo.security.ria/dialog-cancel.png");
308 buttons
.add(cancelB
);
309 page
.add(buttons
, {edge
:"south"});
310 editB
.addListener("execute", function(){
311 newClass
.setEditMode(true);
312 editB
.setVisibility("excluded");
313 saveB
.setVisibility("visible");
314 cancelB
.setVisibility("visible");
316 cancelB
.addListener("execute", function(){
317 if(newClass
.getIsNew()){
318 this._removeNatureTab(natureClass
);
320 newClass
.setEditMode(false);
321 editB
.setVisibility("visible");
322 saveB
.setVisibility("excluded");
323 cancelB
.setVisibility("excluded");
325 saveB
.addListener("execute", function(){
326 // SAVE CURRENT NATURE
327 var data
= newClass
.getData();
328 if(newClass
.getIsNew()){
329 this.getCurrentUser().addNature(data
);
331 this.getCurrentUser().updateNature(data
);
334 this.setNaturesModified(false);
335 newClass
.setEditMode(false);
336 editB
.setVisibility("visible");
337 saveB
.setVisibility("excluded");
338 cancelB
.setVisibility("excluded");
341 newClass
.setData(natureData
);
344 newClass
.setIsNew(true);
347 this.naturesTab
.add(page
);
348 crtTabs
.push(natureClass
.NATURE_TYPE
);
349 this.getViewSelection().triggerEvent();
350 newClass
.addListener("modified", function(){
351 this.setNaturesModified(true);
354 this.naturesTab
.setSelected(page
);
359 _removeNatureTab : function(natureClass
){
360 this.naturesTab
.getChildren().forEach(function(el
){
361 if(el
.getUserData("NATURE_CLASS") == natureClass
){
362 this.naturesTab
.remove(el
);
363 qx
.lang
.Array
.remove(this.getCurrentNatureTabs(), natureClass
.NATURE_TYPE
);
364 this.getViewSelection().triggerEvent();
367 if(this.naturesTab
.getChildren().length
== 0){
368 this.naturesTab
.setVisibility("excluded");
369 this.fakePane
.setVisibility("visible");
373 removeSelectedTab : function(){
374 var selected
= this.naturesTab
.getSelected();
375 var tabClass
= selected
.getUserData("NATURE_CLASS");
376 var user
= this.getCurrentUser();
377 user
.removeNature(tabClass
.NATURE_TYPE
);
379 this._removeNatureTab(tabClass
);
382 removeAllTabs : function(){
383 while(this.naturesTab
.getSelected()){
384 this._removeNatureTab(this.naturesTab
.getSelected().getUserData("NATURE_CLASS"));
388 _setGuiInCreateMode : function(bool
){
390 if(!this.natureButtonGB
.isVisible()) return;
391 this.natureButtonGB
.hide();
392 this.fakePane
.setVisibility("excluded");
394 if(this.natureButtonGB
.isVisible()) return;
395 this.natureButtonGB
.show();
396 this.fakePane
.setVisibility("visible");
400 _attachListeners : function(){
401 this.usernameField
.addListener("changeValue", function(){
402 this.setModified(true);
404 this.rolesField
.addListener("changeValue", function(){
405 this.setModified(true);
407 this.passPane
.addListener("modified", function(){
408 this.setModified(true);
412 _initializeGroupBox: function(groupBox
){
413 groupBox
.setPadding(0);
414 groupBox
.getChildrenContainer().setPadding(8);
417 _applyDetailsModified : function(value
){
418 if(value
) this.getViewSelection().triggerEvent();
421 _applyNaturesModified : function(value
){
422 if(value
) this.getViewSelection().triggerEvent();
425 loadUserData : function(userName
){
426 var userDataService
= org
.argeo
.security
.ria
.SecurityAPI
.getUserDetailsService(userName
);
427 userDataService
.addListener("completed", function(response
){
428 var user
= new org
.argeo
.security
.ria
.model
.User();
429 user
.load(response
.getContent(), "json");
430 this.setCurrentUser(user
);
431 this.usernameField
.setValue(user
.getName());
432 this.usernameField
.setReadOnly(true);
433 this.rolesField
.setValue(user
.getRoles());
434 var userNatureTabs
= this.naturesManager
.detectNaturesInData(user
.getNatures());
435 if(userNatureTabs
.length
){
436 userNatureTabs
.forEach(function(el
){
437 this._addNatureTab(el
.NATURE_CLASS
, el
.NATURE_DATA
);
440 this._attachListeners();
442 userDataService
.send();
445 partialRefreshUser : function(user
, target
){
446 if(!qx
.lang
.Array
.isArray(target
)) target
= [target
];
448 if(qx
.lang
.Array
.contains(target
,"natures")){
449 if(this.getSelectedNatureTab()){
450 var selectedTab
= this.getSelectedNatureTab().getUserData("NATURE_CLASS");
452 this.removeAllTabs();
453 var userNatureTabs
= this.naturesManager
.detectNaturesInData(user
.getNatures());
454 if(userNatureTabs
.length
){
455 userNatureTabs
.forEach(function(el
){
456 this._addNatureTab(el
.NATURE_CLASS
, el
.NATURE_DATA
, (selectedTab
&& selectedTab
== el
.NATURE_CLASS
));
460 if(qx
.lang
.Array
.contains(target
,"details")){
461 this.setInstanceLabel("User "+user
.getName());
462 this.usernameField
.setValue(user
.getName());
463 this.rolesField
.setValue(user
.getRoles());
464 this.usernameField
.setReadOnly(true);
469 * Load a given row : the data passed must be a simple data array.
470 * @param data {Element} The text xml description.
472 load : function(userName
){
473 if(this.getLoaded()){
476 // MUST BE DONE AFTER COMMANDS ARE INITIALIZED!
477 var commands
= this.getCommands();
478 var saveButton
= commands
["save_user"].command
.getFormButton();
479 var closeButton
= commands
["close"].command
.getFormButton();
480 var removeButton
= commands
["remove_nature"].command
.getFormButton();
481 var natureButton
= commands
["add_nature"].command
.getFormButton();
483 var detectedNatures
= this.getAvailableNatures();
485 for(var key
in detectedNatures
){
486 newMenu
.push({"label" : detectedNatures
[key
].NATURE_LABEL
, "icon":"", "commandId" : detectedNatures
[key
]});
488 commands
["add_nature"].command
.setMenu(newMenu
);
490 natureButton
.setShow("icon");
491 removeButton
.setShow("icon");
492 saveButton
.setShow("icon");
493 closeButton
.setShow("icon");
495 this.buttonGB
.add(saveButton
);
496 this.buttonGB
.add(closeButton
);
497 this.natureButtonGB
.add(natureButton
);
498 this.natureButtonGB
.add(removeButton
);
501 this.loadUserData(userName
);
502 this._setGuiInCreateMode(false);
504 this.setCurrentUser(new org
.argeo
.security
.ria
.model
.User());
505 this._setGuiInCreateMode(true);
506 this._attachListeners();
507 this.setModified(true);
511 this.setLoaded(true);
515 addScroll : function(){