]> 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/UserEditorApplet.js
clear/load data on userChange in editorPrefPane
[lgpl/argeo-commons.git] / security / runtime / org.argeo.security.ria / src / argeo-ria-lib / security / class / org / argeo / security / ria / UserEditorApplet.js
1 /**
2 * A simple Hello World applet for documentation purpose.
3 * The only associated command is the "Close" command.
4 */
5 /* *************************************************
6 #asset(resource/org.argeo.security.ria/*)
7 ****************************************************/
8 qx.Class.define("org.argeo.security.ria.UserEditorApplet",
9 {
10 extend : org.argeo.security.ria.components.UserEditor,
11 implement : [org.argeo.ria.components.IView],
12
13 construct : function(){
14 this.base(arguments);
15 },
16
17 properties :
18 {
19 /**
20 * The viewPane inside which this applet is added.
21 */
22 view : {
23 init : null
24 },
25 /**
26 * Commands definition, see {@link org.argeo.ria.event.CommandsManager#definitions}
27 */
28 commands : {
29 init : {
30 "save_user" : {
31 label : "Save",
32 icon : "org.argeo.security.ria/document-save.png",
33 shortcut : "Control+s",
34 enabled : true,
35 menu : "Users",
36 toolbar : "user",
37 callback : function(e){
38 // CALL SERVICE AND GET UP TO DATE USER
39 this.saveUser();
40 },
41 selectionChange : function(viewName, data){
42 if(viewName != "editor") return;
43 var iApplet = org.argeo.ria.components.ViewsManager.getInstance().getViewPaneById("editor").getContent();
44 this.setEnabled(iApplet.getModified());
45 },
46 command : null
47 },
48 "add_nature" : {
49 label : "Add Nature ...",
50 icon : "org.argeo.security.ria/list-add.png",
51 shortcut : null,
52 enabled : true,
53 menu : "Natures",
54 toolbar : null,
55 callback : function(e){
56 },
57 submenuCallback : function(commandClass){
58 this._addNatureTab(commandClass, null, true);
59 },
60 submenu : [
61 {"label" : "Totot", "icon":"","commandId" : "toto"},
62 {"label" : "Totot", "icon":"","commandId" : "toto"}
63 ],
64 selectionChange : function(viewName, data){
65 if(viewName != "editor") return;
66 var iApplet = org.argeo.ria.components.ViewsManager.getInstance().getViewPaneById("editor").getContent();
67 if(iApplet && iApplet.getCurrentNatureTabs() && iApplet.getAvailableNatures()
68 && iApplet.getCurrentNatureTabs().length < qx.lang.Object.getLength(iApplet.getAvailableNatures())){
69 this.setEnabled(true);
70 }else{
71 this.setEnabled(false);
72 }
73 },
74 command : null
75 },
76 "remove_nature" : {
77 label : "Remove Nature",
78 icon : "org.argeo.security.ria/list-remove.png",
79 shortcut : null,
80 enabled : true,
81 menu : "Natures",
82 toolbar : null,
83 callback : function(e){
84 this.removeSelectedTab();
85 },
86 selectionChange : function(viewName, data){
87 if(viewName != "editor") return;
88 var iApplet = org.argeo.ria.components.ViewsManager.getInstance().getViewPaneById("editor").getContent();
89 if(iApplet && iApplet.getSelectedNatureTab() && iApplet.getSelectedNatureTab().getUserData("NATURE_CLASS")){
90 this.setEnabled(true);
91 }else{
92 this.setEnabled(false);
93 }
94 },
95 command : null
96 },
97 "close" : {
98 label : "Close",
99 icon : "org.argeo.security.ria/window-close.png",
100 shortcut : "Control+w",
101 enabled : true,
102 menu : "Users",
103 toolbar : "user",
104 callback : function(e){
105 // Call service to delete
106 var iApplet = org.argeo.ria.components.ViewsManager.getInstance().getViewPaneById("editor").getContent();
107 if(!iApplet.getModified() && !iApplet.getNaturesModified()){
108 this.getView().closeCurrent();
109 return;
110 }
111 var modal = new org.argeo.ria.components.Modal("Warning");
112 modal.addConfirm("There are unsaved changes!\n Are you sure you want to close?");
113 modal.addListener("ok", function(){
114 this.getView().closeCurrent();
115 }, this);
116 modal.attachAndShow();
117 },
118 command : null
119 }
120 }
121 },
122 viewSelection : {
123 nullable:false,
124 check:"org.argeo.ria.components.ViewSelection"
125 },
126 instanceId : {
127 init:"",
128 event : "changeInstanceId"
129 },
130 instanceLabel : {
131 init:"Editor",
132 event : "changeInstanceLabel"
133 }
134 },
135
136 members :
137 {
138 /**
139 * Called at applet creation. Just registers viewPane.
140 * @param viewPane {org.argeo.ria.components.ViewPane} The viewPane.
141 */
142 init : function(viewPane, data){
143 if(!data.USER){
144 var now = new Date();
145 this.setInstanceId(now.getTime());
146 this.setInstanceLabel("New User");
147 }else{
148 this.setInstanceId(data.USER);
149 this.setInstanceLabel("User " + data.USER);
150 }
151 this.setView(viewPane);
152 this.setViewSelection(new org.argeo.ria.components.ViewSelection(viewPane.getViewId()));
153
154 this.initGUI(data.ROLES_LIST);
155
156 this.addListener("savedUser", function(e){
157 if(this.getCurrentUser()){
158 this.setInstanceLabel("User " + this.getCurrentUser().getName());
159 this.setInstanceId(this.getCurrentUser().getName());
160 }
161 }, this);
162
163 },
164
165 /**
166 * Load a given row : the data passed must be a simple data array.
167 * @param data {Element} The text xml description.
168 */
169 load : function(userName){
170 if(this.getLoaded()){
171 return;
172 }
173 // MUST BE DONE AFTER COMMANDS ARE INITIALIZED!
174 var commands = this.getCommands();
175 var saveButton = commands["save_user"].command.getFormButton();
176 var closeButton = commands["close"].command.getFormButton();
177 var removeButton = commands["remove_nature"].command.getFormButton();
178 var natureButton = commands["add_nature"].command.getFormButton();
179
180 var detectedNatures = this.getAvailableNatures();
181 var newMenu = [];
182 for(var key in detectedNatures){
183 newMenu.push({"label" : detectedNatures[key].NATURE_LABEL, "icon":"", "commandId" : detectedNatures[key]});
184 }
185 commands["add_nature"].command.setMenu(newMenu);
186
187 natureButton.setShow("icon");
188 removeButton.setShow("icon");
189 saveButton.setShow("icon");
190 closeButton.setShow("icon");
191
192 this.buttonGB.add(saveButton);
193 this.buttonGB.add(closeButton);
194 this.natureButtonGB.add(natureButton);
195 this.natureButtonGB.add(removeButton);
196
197 if(userName){
198 this.loadUserData(userName);
199 this._setGuiInCreateMode(false);
200 }else{
201 this.setCurrentUser(new org.argeo.security.ria.model.User());
202 this._setGuiInCreateMode(true);
203 this._attachListeners();
204 this.setModified(true);
205 }
206
207
208 this.setLoaded(true);
209
210 },
211
212 _applyDetailsModified : function(value){
213 if(value) this.getViewSelection().triggerEvent();
214 },
215
216 _applyNaturesModified : function(value){
217 if(value) this.getViewSelection().triggerEvent();
218 },
219
220 addScroll : function(){
221 return false;
222 },
223
224 close : function(){
225 return false;
226 }
227
228 }
229 });