]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.webapp/src/main/webapp/argeo-ria-src/class/org/argeo/ria/components/ViewPane.js
"Confirm" mode in Modal
[gpl/argeo-slc.git] / org.argeo.slc.webapp / src / main / webapp / argeo-ria-src / class / org / argeo / ria / components / ViewPane.js
1 /**
2 * A standard view container, referenced in the application by its unique id.
3 * It is managed by the ViewsManager singleton that works as the "View" part of an MVC model.
4 * @see org.argeo.ria.components.ViewsManager
5 * @author Charles
6 */
7 qx.Class.define("org.argeo.ria.components.ViewPane",
8 {
9 extend : qx.ui.container.Composite,
10 implement : [org.argeo.ria.components.ILoadStatusable],
11
12 /**
13 * @param viewId {String} Unique id of this viewPane
14 * @param viewTitle {String} Readable Title of this viewPane
15 * @param splitPaneData {Map} Additionnal data to be used by splitpanes implementations.
16 */
17 construct : function(viewId, viewTitle, splitPaneData){
18 this.base(arguments);
19 this.setViewId(viewId);
20 this._defaultViewTitle = viewTitle;
21 this.setViewTitle(viewTitle);
22 if(splitPaneData){
23 this.setSplitPaneData(splitPaneData);
24 }
25 this.setFocusable(true);
26 this.addListener("click", function(e){
27 this.fireDataEvent("changeFocus", this);
28 }, this);
29 this.createGui();
30 },
31
32 events : {
33 "changeFocus" : "qx.event.type.Data",
34 "changeSelection" : "qx.event.type.Event"
35 },
36
37 properties :
38 {
39 /**
40 * Unique id of the pane
41 */
42 viewId : {init:""},
43 /**
44 * Human-readable title for this view
45 */
46 viewTitle : {init:"", event:"changeViewTitle"},
47 /**
48 * Has its own scrollable content
49 */
50 ownScrollable : {init: false, check:"Boolean"},
51 /**
52 * Data concerning the split pane
53 */
54 splitPaneData : {init : null, check:"Map"},
55 /**
56 * Map of commands definition
57 * @see org.argeo.ria.event.Command
58 */
59 commands : {init : null, nullable:true, check:"Map"},
60 /**
61 * The real business content.
62 */
63 content : {
64 init: null,
65 nullable : true,
66 check : "org.argeo.ria.components.IView",
67 apply : "_applyContent"
68 }
69 },
70
71 /*
72 *****************************************************************************
73 MEMBERS
74 *****************************************************************************
75 */
76
77 members :
78 {
79 /**
80 * Creates a standard GUI for the viewPane, including a container for an IView.
81 */
82 createGui : function(){
83 this.setLayout(new qx.ui.layout.VBox());
84 this.header = new qx.ui.container.Composite();
85 this.header.setLayout(new qx.ui.layout.Dock());
86 this.loadImage = new qx.ui.basic.Image('resource/slc/ajax-loader.gif');
87 this.header.set({appearance:"app-header", height:34});
88 this.headerLabel = new qx.ui.basic.Label(this.getViewTitle());
89 this.header.add(this.headerLabel, {edge:"west"});
90 this.addListener("changeViewTitle", function(e){
91 var newTitle = e.getData();
92 if(newTitle != ""){
93 this.headerLabel.setContent(newTitle);
94 if(e.getOldData() == ""){
95 this.header.add(this.headerLabel, {edge:"west"});
96 }
97 }else{
98 this.header.remove(this.headerLabel);
99 }
100 }, this);
101 this.add(this.header);
102 this.setDecorator(new qx.ui.decoration.Single(1,"solid","#000"));
103 /*
104 // Open close button of splitPane, not very useful at the moment.
105 if(this.getSplitPaneData()){
106 var data = this.getSplitPaneData();
107 var imgName = (data.orientation=="horizontal"?"go-left":"go-bottom");
108 var image = new qx.ui.basic.Image("resource/slc/"+imgName+".png");
109 image.addListener("click", function(e){
110 var image = e.getTarget();
111 var data = this.getSplitPaneData();
112 var functionDim = (data.orientation=="horizontal"?"Width":"Height");
113 var objectToResize = data.object || this;
114 var crtDim = objectToResize["get"+functionDim]();
115 var minimize = (data.orientation=="horizontal"?"go-right":"go-top");
116 var maximize = (data.orientation=="horizontal"?"go-left":"go-bottom");
117 if(crtDim > data.min){
118 objectToResize["set"+functionDim](data.min);
119 image.setSource("resource/slc/"+minimize+".png");
120 this.origDimension = crtDim;
121 }else{
122 if(this.origDimension){
123 objectToResize["set"+functionDim](this.origDimension);
124 image.setSource("resource/slc/"+maximize+".png");
125 }
126 }
127 }, this);
128 this.header.add(image,{edge:"east"});
129 }
130 */
131 },
132
133 getViewSelection : function(){
134 if(this.getContent()){
135 return this.getContent().getViewSelection();
136 }
137 return null;
138 },
139
140 contentExists : function(iViewId){
141 return false;
142 },
143
144 /**
145 * Sets the content of this pane.
146 * @param content {org.argeo.ria.components.IView} An IView implementation
147 */
148 _applyContent : function(content){
149 if(content == null) return;
150 var addScrollable = (content.addScroll?content.addScroll():false);
151 if(addScrollable){
152 this.setOwnScrollable(true);
153 this.scrollable = new qx.ui.container.Scroll(content);
154 this.add(this.scrollable, {flex: 1});
155 }else{
156 this.guiContent = content;
157 this.add(this.guiContent, {flex:1});
158 }
159 content.getViewSelection().addListener("changeSelection", function(e){
160 this.fireEvent("changeSelection");
161 }, this);
162 },
163 /**
164 * Adds a graphical component too the header of the view pane.
165 * It is added as "center" in the dock layout, and will override the view pane title label.
166 * For example, you can add your own title, or add a switch, or buttons, etc.
167 * @param component {qx.ui.core.Widget} The graphical component to add.
168 */
169 addHeaderComponent : function(component){
170 this.header.setPadding(4);
171 this.header.add(component, {edge:"center"});
172 component.setTextColor("#1a1a1a");
173 this.loadImage.setMargin(4);
174 },
175
176 /**
177 * Implementation of the ILoadStatusable interface.
178 * @see org.argeo.ria.components.ILoadStatusable
179 * @param load {Boolean} The loading status
180 */
181 setOnLoad : function(load){
182 if(load){
183 this.header.add(this.loadImage, {edge:"east"});
184 }else{
185 this.header.remove(this.loadImage);
186 }
187 },
188
189 /**
190 * Removes and destroy the IView content of this viewPane.
191 */
192 empty: function(){
193 if(this.getOwnScrollable() && this.scrollable){
194 this.remove(this.scrollable);
195 }else if(this.guiContent){
196 this.remove(this.guiContent);
197 }
198 if(this.getCommands()){
199 org.argeo.ria.event.CommandsManager.getInstance().removeCommands(this.getCommands());
200 this.setCommands(null);
201 }
202 if(this.getContent()){
203 this.getContent().close();
204 }
205 this.setViewTitle(this._defaultViewTitle);
206 this.setContent(null);
207 },
208
209 focus : function(){
210 if(this.hasFocus) return;
211 this.setDecorator(new qx.ui.decoration.Single(1,"solid","#065fb2"));
212 this.fireEvent("changeSelection");
213 this.hasFocus = true;
214 },
215 blur : function(){
216 this.hasFocus = false;
217 this.setDecorator(new qx.ui.decoration.Single(1,"solid","#000"));
218 }
219
220 }
221 });