]> 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
Open user on dblClick
[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 : qx.ui.container.Composite,
11 implement : [org.argeo.ria.components.IView],
12
13 construct : function(){
14 this.base(arguments);
15 this.setLayout(new qx.ui.layout.VBox());
16 //this.setDecorator("tabview-pane");
17 },
18
19 properties :
20 {
21 /**
22 * The viewPane inside which this applet is added.
23 */
24 view : {
25 init : null
26 },
27 /**
28 * Commands definition, see {@link org.argeo.ria.event.CommandsManager#definitions}
29 */
30 commands : {
31 init : {
32 "save_user" : {
33 label : "Save",
34 icon : "org.argeo.security.ria/document-save.png",
35 shortcut : "Control+s",
36 enabled : true,
37 menu : "Users",
38 toolbar : "user",
39 callback : function(e){
40
41 },
42 selectionChange : function(viewName, data){
43 if(viewName != "editor") return;
44 var iApplet = org.argeo.ria.components.ViewsManager.getInstance().getViewPaneById("editor").getContent();
45 if(iApplet == null) this.setEnabled(true);
46 this.setEnabled(iApplet.getModified());
47 //this.setEnabled(!(data == null || !data.length || data.length > 1));
48 },
49 command : null
50 },
51 "close" : {
52 label : "Close",
53 icon : "org.argeo.security.ria/window-close.png",
54 shortcut : "Control+w",
55 enabled : true,
56 menu : "Users",
57 toolbar : "user",
58 callback : function(e){
59 // Call service to delete
60 var iApplet = org.argeo.ria.components.ViewsManager.getInstance().getViewPaneById("editor").getContent();
61 if(!iApplet.getModified()){
62 this.getView().closeCurrent();
63 return;
64 }
65 var modal = new org.argeo.ria.components.Modal("Warning");
66 modal.addConfirm("There are unsaved changes!\n Are you sure you want to close?");
67 modal.addListener("ok", function(){
68 this.getView().closeCurrent();
69 }, this);
70 modal.attachAndShow();
71 },
72 command : null
73 }
74 }
75 },
76 viewSelection : {
77 nullable:false,
78 check:"org.argeo.ria.components.ViewSelection"
79 },
80 modified : {
81 init : false
82 },
83 rolesList : {
84
85 },
86 instanceId : {init:""},
87 instanceLabel : {init:"Editor"}
88 },
89
90 members :
91 {
92 /**
93 * Called at applet creation. Just registers viewPane.
94 * @param viewPane {org.argeo.ria.components.ViewPane} The viewPane.
95 */
96 init : function(viewPane, data){
97 if(!data){
98 var now = new Date();
99 this.setInstanceId(now.getTime());
100 this.setInstanceLabel("New User");
101 }else{
102 this.setInstanceId(data);
103 this.setInstanceLabel("User " + data);
104 }
105 this.setView(viewPane);
106 this.setViewSelection(new org.argeo.ria.components.ViewSelection(viewPane.getViewId()));
107
108 // GROUPBOXES
109 this.basicGB = new qx.ui.groupbox.GroupBox("Base Informations");
110 var grid = new qx.ui.layout.Grid(5,5);
111 this.basicGB.setLayout(grid);
112 grid.setColumnFlex(0,1);
113 grid.setColumnAlign(0,"right", "middle");
114 grid.setColumnFlex(1,2);
115 this._initializeGroupBox(this.basicGB);
116
117 this.passGB = new qx.ui.groupbox.GroupBox("Set/Modify Password");
118 this.passGB.setLayout(new qx.ui.layout.VBox());
119 this._initializeGroupBox(this.passGB);
120
121 this.naturesGB = new qx.ui.groupbox.GroupBox("User Natures");
122 this.naturesGB.setLayout(new qx.ui.layout.Dock());
123 this._initializeGroupBox(this.naturesGB);
124
125 this.add(this.basicGB);
126 this.add(this.passGB);
127 this.add(this.naturesGB, {flex:1});
128
129 // FIELDS
130 this.usernameField = new qx.ui.form.TextField();
131 this.basicGB.add(new qx.ui.basic.Label("Username"), {row:0,column:0});
132 this.basicGB.add(this.usernameField, {row:0,column:1});
133
134 this.rolesField = new org.argeo.ria.components.ui.MultipleComboBox();
135 this.rolesField.setChoiceValues(["ROLE_ADMIN", "ROLE_USER", "ROLE_USER1"]);
136 this.basicGB.add(new qx.ui.basic.Label("Roles"), {row:1,column:0});
137 this.basicGB.add(this.rolesField, {row:1,column:1});
138
139 this.passPane = new org.argeo.security.ria.components.PasswordCredentialImpl();
140 this.passGB.add(this.passPane.getContainer());
141
142 this.naturesTab = new qx.ui.tabview.TabView("top");
143 this.simpleNature = new org.argeo.security.ria.components.SimpleUserNatureImpl();
144
145 var page1 = new qx.ui.tabview.Page(this.simpleNature.getNatureLabel());
146 page1.setLayout(new qx.ui.layout.Dock());
147 page1.add(this.simpleNature.getContainer(), {edge:"center"});
148 this.naturesTab.add(page1);
149 this.naturesGB.add(this.naturesTab, {edge:"center"});
150
151 },
152
153 _attachListeners : function(){
154 this.usernameField.addListener("changeValue", function(){
155 this.setModified(true);
156 }, this);
157 this.rolesField.addListener("changeValue", function(){
158 this.setModified(true);
159 }, this);
160 this.passPane.addListener("modified", function(){
161 this.setModified(true);
162 }, this);
163 this.simpleNature.addListener("modified", function(){
164 this.setModified(true);
165 }, this);
166 },
167
168 _initializeGroupBox: function(groupBox){
169 groupBox.setPadding(0);
170 groupBox.getChildrenContainer().setPadding(8);
171 },
172
173 /**
174 * Load a given row : the data passed must be a simple data array.
175 * @param data {Element} The text xml description.
176 */
177 load : function(userData){
178 if(userData){
179 this.usernameField.setValue(userData);
180 }
181 this.setRolesList(["ROLE_ADMIN", "ROLE_USER"]);
182 this._attachListeners();
183 },
184
185 addScroll : function(){
186 return false;
187 },
188
189 close : function(){
190 return false;
191 }
192
193 }
194 });