]>
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));
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/document-save.png",
34 shortcut
: "Control+s",
38 callback : function(e
){
39 // CALL SERVICE AND GET UP TO DATE USER
42 selectionChange : function(viewName
, data
){
43 if(viewName
!= "editor") return;
44 var iApplet
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getViewPaneById("editor").getContent();
45 this.setEnabled(iApplet
.getModified());
50 label
: "Add Nature ...",
51 icon
: "org.argeo.security.ria/list-add.png",
56 callback : function(e
){
58 submenuCallback : function(commandClass
){
59 this._addNatureTab(commandClass
, null, true);
62 {"label" : "Totot", "icon":"","commandId" : "toto"},
63 {"label" : "Totot", "icon":"","commandId" : "toto"}
65 selectionChange : function(viewName
, data
){
66 if(viewName
!= "editor") return;
67 var iApplet
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getViewPaneById("editor").getContent();
68 if(iApplet
&& iApplet
.getCurrentNatureTabs() && iApplet
.getAvailableNatures()
69 && iApplet
.getCurrentNatureTabs().length
< qx
.lang
.Object
.getLength(iApplet
.getAvailableNatures())){
70 this.setEnabled(true);
72 this.setEnabled(false);
78 label
: "Remove Nature",
79 icon
: "org.argeo.security.ria/list-remove.png",
84 callback : function(e
){
85 this.removeSelectedTab();
87 selectionChange : function(viewName
, data
){
88 if(viewName
!= "editor") return;
89 var iApplet
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getViewPaneById("editor").getContent();
90 if(iApplet
&& iApplet
.getSelectedNatureTab() && iApplet
.getSelectedNatureTab().getUserData("NATURE_CLASS")){
91 this.setEnabled(true);
93 this.setEnabled(false);
100 icon
: "org.argeo.security.ria/window-close.png",
101 shortcut
: "Control+w",
105 callback : function(e
){
106 // Call service to delete
107 var iApplet
= org
.argeo
.ria
.components
.ViewsManager
.getInstance().getViewPaneById("editor").getContent();
108 if(!iApplet
.getModified() && !iApplet
.getNaturesModified()){
109 this.getView().closeCurrent();
112 var modal
= new org
.argeo
.ria
.components
.Modal("Warning");
113 modal
.addConfirm("There are unsaved changes!\n Are you sure you want to close?");
114 modal
.addListener("ok", function(){
115 this.getView().closeCurrent();
117 modal
.attachAndShow();
125 check
:"org.argeo.ria.components.ViewSelection"
129 apply
: "_applyDetailsModified"
133 apply
: "_applyNaturesModified"
138 instanceId
: {init
:""},
139 instanceLabel
: {init
:"Editor"},
143 currentNatureTabs
: {
147 selectedNatureTab
: {
158 * Called at applet creation. Just registers viewPane.
159 * @param viewPane {org.argeo.ria.components.ViewPane} The viewPane.
161 init : function(viewPane
, data
){
163 var now
= new Date();
164 this.setInstanceId(now
.getTime());
165 this.setInstanceLabel("New User");
167 this.setInstanceId(data
);
168 this.setInstanceLabel("User " + data
);
170 this.setView(viewPane
);
171 this.setViewSelection(new org
.argeo
.ria
.components
.ViewSelection(viewPane
.getViewId()));
173 this.naturesManager
= new org
.argeo
.security
.ria
.components
.NaturesManager();
174 var detectedNatures
= this.naturesManager
.getDetectedNatures();
175 this.setAvailableNatures(detectedNatures
);
178 this.buttonGB
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.HBox(5, "right"));
179 this.add(this.buttonGB
);
181 this.setCurrentNatureTabs([]);
182 this.naturesTab
= new qx
.ui
.tabview
.TabView("top");
183 this.naturesTab
.addListener("changeSelected", function(e
){
184 this.setSelectedNatureTab(e
.getData());
185 this.getViewSelection().triggerEvent();
188 this.basicPage
= new qx
.ui
.tabview
.Page("Basic Information");
189 this.basicPage
.setLayout(new qx
.ui
.layout
.VBox(5));
193 this.basicGB
= new qx
.ui
.groupbox
.GroupBox("Base Informations");
194 var grid
= new qx
.ui
.layout
.Grid(5,5);
195 this.basicGB
.setLayout(grid
);
196 grid
.setColumnFlex(0,1);
197 grid
.setColumnAlign(0,"right", "middle");
198 grid
.setColumnFlex(1,2);
199 this._initializeGroupBox(this.basicGB
);
201 this.passGB
= new qx
.ui
.groupbox
.GroupBox("Set/Modify Password");
202 this.passGB
.setLayout(new qx
.ui
.layout
.VBox());
203 this._initializeGroupBox(this.passGB
);
205 this.add(this.basicGB
);
206 this.add(this.passGB
);
209 this.usernameField
= new qx
.ui
.form
.TextField();
210 this.basicGB
.add(new qx
.ui
.basic
.Label("Username"), {row
:0,column
:0});
211 this.basicGB
.add(this.usernameField
, {row
:0,column
:1});
213 this.rolesField
= new org
.argeo
.ria
.components
.ui
.MultipleComboBox();
214 this.rolesField
.setChoiceValues(["ROLE_ADMIN", "ROLE_USER", "ROLE_USER1"]);
215 this.basicGB
.add(new qx
.ui
.basic
.Label("Roles"), {row
:1,column
:0});
216 this.basicGB
.add(this.rolesField
, {row
:1,column
:1});
218 this.passPane
= new org
.argeo
.security
.ria
.components
.PasswordCredentialImpl();
219 this.passGB
.add(this.passPane
.getContainer());
221 //this.naturesTab.add(this.basicPage);
222 this.natureButtonGB
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.HBox(5, "right"));
223 this.natureButtonGB
.setMarginTop(15);
224 this.add(this.natureButtonGB
);
227 this.add(this.naturesTab
, {flex
:1});
229 this.naturesTab
.setVisibility("excluded");
230 this.fakePane
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.Canvas());
231 this.fakePane
.setVisibility("visible");
232 this.fakePane
.setDecorator("tabview-pane");
233 this.fakePane
.setMarginTop(30);
234 this.add(this.fakePane
, {flex
:1});
236 title
= new qx
.ui
.basic
.Atom("User Details", "org.argeo.security.ria/preferences-users.png");
237 title
.setFont(qx
.bom
.Font
.fromString("16px sans-serif bold"));
238 this.buttonGB
.add(title
);
239 this.buttonGB
.add(new qx
.ui
.core
.Spacer(), {flex
:1});
241 var title2
= new qx
.ui
.basic
.Atom("User Natures", "org.argeo.security.ria/identity.png");
242 title2
.setFont(qx
.bom
.Font
.fromString("16px sans-serif bold"));
243 this.natureButtonGB
.add(title2
);
244 this.natureButtonGB
.add(new qx
.ui
.core
.Spacer(), {flex
:1});
249 saveUser : function(){
250 var user
= this.getCurrentUser();
251 user
.setName(this.usernameField
.getValue());
252 user
.setRoles((this.rolesField
.getValue()||"").split(","));
253 // GO TO AND RETURN FROM SERVER
259 "type" : "org.argeo.security.nature.SimpleUserNature"
262 this.partialRefreshUser(user
, ["details","natures"]);
263 this.setModified(false);
266 _addNatureTab : function(natureClass
, natureData
, select
){
267 var crtTabs
= this.getCurrentNatureTabs();
268 if(qx
.lang
.Array
.contains(crtTabs
, natureClass
.NATURE_TYPE
)){
269 this.error("There can only be one instance of a given nature type!");
272 if(!this.naturesTab
.isVisible()){
273 if(this.fakePane
) this.fakePane
.setVisibility("excluded");
274 this.naturesTab
.setVisibility("visible");
276 var page
= new qx
.ui
.tabview
.Page("Nature : " + natureClass
.NATURE_LABEL
);
277 page
.setLayout(new qx
.ui
.layout
.Dock());
278 page
.setUserData("NATURE_CLASS", natureClass
);
279 var newClass
= new natureClass();
280 page
.add(newClass
.getContainer(), {edge
:"center"});
282 buttons
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.HBox(5, "center"));
283 var editB
= new qx
.ui
.form
.Button("Edit this Nature", "org.argeo.security.ria/document-properties-22.png");
284 var saveB
= new qx
.ui
.form
.Button("Save", "org.argeo.security.ria/dialog-apply.png");
285 var cancelB
= new qx
.ui
.form
.Button("Cancel", "org.argeo.security.ria/dialog-cancel.png");
288 buttons
.add(cancelB
);
289 page
.add(buttons
, {edge
:"south"});
290 editB
.addListener("execute", function(){
291 newClass
.setEditMode(true);
292 editB
.setVisibility("excluded");
293 saveB
.setVisibility("visible");
294 cancelB
.setVisibility("visible");
296 cancelB
.addListener("execute", function(){
297 newClass
.setEditMode(false);
298 editB
.setVisibility("visible");
299 saveB
.setVisibility("excluded");
300 cancelB
.setVisibility("excluded");
302 saveB
.addListener("execute", function(){
303 // SAVE CURRENT NATURE
304 this.setNaturesModified(false);
305 newClass
.setEditMode(false);
306 editB
.setVisibility("visible");
307 saveB
.setVisibility("excluded");
308 cancelB
.setVisibility("excluded");
311 newClass
.setData(natureData
);
316 this.naturesTab
.add(page
);
317 crtTabs
.push(natureClass
.NATURE_TYPE
);
318 this.getViewSelection().triggerEvent();
319 newClass
.addListener("modified", function(){
320 this.setNaturesModified(true);
323 this.naturesTab
.setSelected(page
);
328 _removeNatureTab : function(natureClass
){
329 this.naturesTab
.getChildren().forEach(function(el
){
330 if(el
.getUserData("NATURE_CLASS") == natureClass
){
331 this.naturesTab
.remove(el
);
332 qx
.lang
.Array
.remove(this.getCurrentNatureTabs(), natureClass
.NATURE_TYPE
);
333 this.getViewSelection().triggerEvent();
336 if(this.naturesTab
.getChildren().length
== 0){
337 this.naturesTab
.setVisibility("excluded");
338 this.fakePane
.setVisibility("visible");
342 removeSelectedTab : function(){
343 var selected
= this.naturesTab
.getSelected();
344 this._removeNatureTab(selected
.getUserData("NATURE_CLASS"));
347 removeAllTabs : function(){
348 while(this.naturesTab
.getSelected()){
349 this._removeNatureTab(this.naturesTab
.getSelected().getUserData("NATURE_CLASS"));
353 _attachListeners : function(){
354 this.usernameField
.addListener("changeValue", function(){
355 this.setModified(true);
357 this.rolesField
.addListener("changeValue", function(){
358 this.setModified(true);
360 this.passPane
.addListener("modified", function(){
361 this.setModified(true);
365 _initializeGroupBox: function(groupBox
){
366 groupBox
.setPadding(0);
367 groupBox
.getChildrenContainer().setPadding(8);
370 _applyDetailsModified : function(value
){
371 if(value
) this.getViewSelection().triggerEvent();
374 _applyNaturesModified : function(value
){
375 if(value
) this.getViewSelection().triggerEvent();
378 loadUserData : function(user
){
379 this.setCurrentUser(user
);
380 this.usernameField
.setValue(user
.getName());
381 this.usernameField
.setReadOnly(true);
382 this.rolesField
.setValue(user
.getRoles());
383 var userNatureTabs
= this.naturesManager
.detectNaturesInData(user
.getNatures());
384 if(userNatureTabs
.length
){
385 userNatureTabs
.forEach(function(el
){
386 this._addNatureTab(el
.NATURE_CLASS
, el
.NATURE_DATA
);
391 partialRefreshUser : function(user
, target
){
392 if(!qx
.lang
.Array
.isArray(target
)) target
= [target
];
394 if(qx
.lang
.Array
.contains(target
,"natures")){
395 this.removeAllTabs();
396 var userNatureTabs
= this.naturesManager
.detectNaturesInData(user
.getNatures());
397 if(userNatureTabs
.length
){
398 userNatureTabs
.forEach(function(el
){
399 this._addNatureTab(el
.NATURE_CLASS
, el
.NATURE_DATA
);
403 if(qx
.lang
.Array
.contains(target
,"details")){
404 this.setInstanceLabel("User "+user
.getName());
405 this.usernameField
.setValue(user
.getName());
406 this.rolesField
.setValue(user
.getRoles());
407 this.usernameField
.setReadOnly(true);
412 * Load a given row : the data passed must be a simple data array.
413 * @param data {Element} The text xml description.
415 load : function(user
){
416 if(this.getLoaded()){
419 this.setRolesList(["ROLE_ADMIN", "ROLE_USER"]);
421 // MUST BE DONE AFTER COMMANDS ARE INITIALIZED!
422 var commands
= this.getCommands();
423 var saveButton
= commands
["save_user"].command
.getFormButton();
424 var closeButton
= commands
["close"].command
.getFormButton();
425 var removeButton
= commands
["remove_nature"].command
.getFormButton();
426 var natureButton
= commands
["add_nature"].command
.getFormButton();
428 var detectedNatures
= this.getAvailableNatures();
430 for(var key
in detectedNatures
){
431 newMenu
.push({"label" : detectedNatures
[key
].NATURE_LABEL
, "icon":"", "commandId" : detectedNatures
[key
]});
433 commands
["add_nature"].command
.setMenu(newMenu
);
435 natureButton
.setShow("icon");
436 removeButton
.setShow("icon");
437 saveButton
.setShow("icon");
438 closeButton
.setShow("icon");
440 this.buttonGB
.add(saveButton
);
441 this.buttonGB
.add(closeButton
);
442 this.natureButtonGB
.add(natureButton
);
443 this.natureButtonGB
.add(removeButton
);
446 this.loadUserData(user
);
447 this._attachListeners();
449 this.setCurrentUser(new org
.argeo
.security
.ria
.model
.User());
450 this._attachListeners();
451 this.setModified(true);
455 this.setLoaded(true);
459 addScroll : function(){