2 * A simple Hello World applet for documentation purpose.
3 * The only associated command is the "Close" command.
5 /* *************************************************
6 #asset(resource/org.argeo.ria.sample/window-close.png)
7 ****************************************************/
8 qx
.Class
.define("org.argeo.security.ria.RolesApplet",
10 extend
: qx
.ui
.container
.Composite
,
11 implement
: [org
.argeo
.ria
.components
.IView
],
13 construct : function(){
15 this.setLayout(new qx
.ui
.layout
.VBox());
21 * The viewPane inside which this applet is added.
27 * Commands definition, see {@link org.argeo.ria.event.CommandsManager#definitions}
33 icon
: "ria/window-close.png",
34 shortcut
: "Control+r",
38 callback : function(e
){
39 // Call service to delete
40 this.setGuiMode("edit");
42 selectionChange : function(viewName
, data
){
43 if(viewName
!= "roles") return;
44 this.setEnabled(!(data
== null || !data
.length
|| data
.length
> 1));
52 check
:"org.argeo.ria.components.ViewSelection"
55 apply
: "_applyGuiMode"
57 chooserOriginalSelection
: {},
58 chooserSelectionModified
: {
60 event
: "chooserSelectionWasModified"
62 instanceId
: {init
:""},
63 instanceLabel
: {init
:""}
69 * Called at applet creation. Just registers viewPane.
70 * @param viewPane {org.argeo.ria.components.ViewPane} The viewPane.
72 init : function(viewPane
){
73 this.setView(viewPane
);
74 this.setViewSelection(new org
.argeo
.ria
.components
.ViewSelection(viewPane
.getViewId()));
75 this.tableModel
= new qx
.ui
.table
.model
.Simple();
76 this.tableModel
.setColumns(["Role Name"]);
77 this.table
= new qx
.ui
.table
.Table(this.tableModel
, {
78 tableColumnModel: function(obj
){
79 return new qx
.ui
.table
.columnmodel
.Resize(obj
)
82 this.table
.setStatusBarVisible(false);
83 this.table
.setShowCellFocusIndicator(false);
84 this.table
.setColumnVisibilityButtonVisible(false);
85 this.table
.highlightFocusedRow(false);
86 viewPane
.add(this.table
, {height
:"100%"});
87 this.table
.getSelectionModel().addListener("changeSelection", function(){
88 this._selectionToValues(this.table
.getSelectionModel(), this.getViewSelection());
92 this.rolesUsersStub
= {"ROLE_ADMIN":["root","mbaudier"],"ROLE_USER":["mbaudier","cdujeu"]};
94 var buttonPane
= new qx
.ui
.container
.Composite(new qx
.ui
.layout
.HBox(2, "right"));
95 this.getView().header
.setPadding(0);
96 if(this.getView().headerLabel
) this.getView().headerLabel
.setMargin(8);
97 this.getView().header
.add(buttonPane
, {edge
:"east"});
99 this.toggleButton
= new qx
.ui
.form
.ToggleButton("Filter", "ria/go-right.png");
100 this.toggleButton
.set({
103 toolTip
:new qx
.ui
.tooltip
.ToolTip("Apply automatic filtering on Users list")
105 buttonPane
.add(this.toggleButton
);
107 // TOGGLE THE GUI MODES
108 this.toggleButton
.addListener("changeChecked", function(event
){
109 this.setGuiMode(event
.getData()?"filter":"clear");
112 this.saveButton
= new qx
.ui
.form
.Button("Save");
113 this.saveButton
.set({
116 toolTip
:new qx
.ui
.tooltip
.ToolTip("Save changes"),
117 visibility
: "excluded"
119 buttonPane
.add(this.saveButton
);
121 this.cancelButton
= new qx
.ui
.form
.Button("Cancel");
122 this.cancelButton
.set({
125 toolTip
:new qx
.ui
.tooltip
.ToolTip("Cancel changes"),
126 visibility
: "excluded"
128 buttonPane
.add(this.cancelButton
);
130 var listener = function(){
131 this.setGuiMode(this.initialState
);
133 this.saveButton
.addListener("execute", listener
, this);
134 this.cancelButton
.addListener("execute", listener
, this);
136 this.table
.addListener("cellDblclick", function(cellEvent
){
137 this.setGuiMode("edit");
140 this.setGuiMode("clear");
143 _applyGuiMode : function(guiMode
, previousMode
){
144 var selectionModel
= this.table
.getSelectionModel();
145 if(!this.usersAppletReference
){
146 var vManager
= org
.argeo
.ria
.components
.ViewsManager
.getInstance();
147 this.usersAppletReference
= vManager
.getViewPaneById("users").getContent();
150 this.saveButton
.setVisibility((guiMode
=="edit"?"visible":"excluded"));
151 this.cancelButton
.setVisibility((guiMode
=="edit"?"visible":"excluded"));
152 this.table
.setEnabled((guiMode
=="edit"?false:true));
153 this.toggleButton
.setVisibility((guiMode
=="edit"?"excluded":"visible"));
155 if(guiMode
== "filter"){
156 if(this.usersAppletReference
){
157 this.usersAppletReference
.setGuiMode(("filter"));
158 var viewSel
= this.usersAppletReference
.getViewSelection();
159 viewSel
.removeListener("changeSelection", this.monitorChooserSelectionChanges
, this);
161 selectionModel
.addListener("changeSelection", this.selectionToFilter
, this);
162 selectionModel
.setSelectionMode(qx
.ui
.table
.selection
.Model
.MULTIPLE_INTERVAL_SELECTION_TOGGLE
);
163 this.selectionToFilter();
164 }else if(guiMode
== "edit"){
165 if(!this.usersAppletReference
) return;
166 this.initialState
= previousMode
;
167 if(previousMode
== "filter"){
168 this.usersAppletReference
.setGuiMode(("clear"));
169 selectionModel
.removeListener("changeSelection", this.selectionToFilter
, this);
171 this.usersAppletReference
.setGuiMode(("chooser"));
172 this.selectionToChooser(); // Warning, to be called before calling listener!
173 var viewSel
= this.usersAppletReference
.getViewSelection();
174 viewSel
.addListener("changeSelection", this.monitorChooserSelectionChanges
, this);
175 }else if(guiMode
== "clear"){
176 if(this.usersAppletReference
){
177 this.usersAppletReference
.setGuiMode(("clear"));
178 var viewSel
= this.usersAppletReference
.getViewSelection();
179 viewSel
.removeListener("changeSelection", this.monitorChooserSelectionChanges
, this);
181 this.table
.setEnabled(true);
182 selectionModel
.removeListener("changeSelection", this.selectionToFilter
, this);
183 selectionModel
.setSelectionMode(qx
.ui
.table
.selection
.Model
.SINGLE_SELECTION
);
187 monitorChooserSelectionChanges : function(event
){
188 if(!this.usersAppletReference
|| this.getChooserSelectionModified()) return;
189 var initialSelection
= this.getChooserOriginalSelection();
190 var crtSelection
= event
.getTarget().getNodes();
191 if(!qx
.lang
.Array
.equals(initialSelection
.sort(), crtSelection
.sort())){
192 this.setChooserSelectionModified(true);
193 console
.log("Changed!");
194 this.saveButton
.setEnabled(true);
198 selectionToFilter : function(){
199 if(!this.usersAppletReference
) return;
200 var selectionModel
= this.table
.getSelectionModel();
201 if(!selectionModel
.getSelectedCount()){
202 this.usersAppletReference
.resetHiddenRows();
205 this.usersAppletReference
.applyFilter(this._selectionToValues(selectionModel
), "roles", true);
208 selectionToChooser : function(){
209 if(!this.usersAppletReference
) return;
210 var selectionModel
= this.table
.getSelectionModel();
211 if(!selectionModel
.getSelectedCount()){
212 this.usersAppletReference
.resetHiddenRows();
215 var uniqueValue
= this._selectionToValues(selectionModel
)[0];
216 var initSelection
= this.rolesUsersStub
[uniqueValue
];
217 this.setChooserOriginalSelection(initSelection
);
218 this.setChooserSelectionModified(false);
219 this.usersAppletReference
.applySelection(initSelection
, "username");
220 this.saveButton
.setEnabled(false);
223 _selectionToValues : function(selectionModel
, viewSelection
){
225 viewSelection
.setBatchMode(true);
226 viewSelection
.clear();
228 if(!selectionModel
.getSelectedCount()) return [];
229 var ranges
= selectionModel
.getSelectedRanges();
231 for(var i
=0;i
<ranges
.length
;i
++){
232 for(var j
=ranges
[i
].minIndex
;j
<=ranges
[i
].maxIndex
;j
++){
233 values
.push(this.tableModel
.getData()[j
][0]);
235 viewSelection
.addNode(this.tableModel
.getData()[j
][0]);
240 viewSelection
.setBatchMode(false);
246 * Load a given row : the data passed must be a simple data array.
247 * @param data {Element} The text xml description.
250 var data
= [["ROLE_ADMIN"],["ROLE_USER"]];
251 this.tableModel
.setData(data
);
254 addScroll : function(){