1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.common.ui.client.widgets.containers; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.Arrays; |
20 | |
import java.util.List; |
21 | |
import java.util.Map; |
22 | |
|
23 | |
import org.kuali.student.common.ui.client.application.Application; |
24 | |
import org.kuali.student.common.ui.client.application.KSAsyncCallback; |
25 | |
import org.kuali.student.common.ui.client.mvc.Callback; |
26 | |
import org.kuali.student.common.ui.client.service.ServerPropertiesRpcService; |
27 | |
import org.kuali.student.common.ui.client.service.ServerPropertiesRpcServiceAsync; |
28 | |
import org.kuali.student.common.ui.client.theme.Theme; |
29 | |
import org.kuali.student.common.ui.client.widgets.KSButton; |
30 | |
import org.kuali.student.common.ui.client.widgets.KSLabel; |
31 | |
import org.kuali.student.common.ui.client.widgets.KSLightBox; |
32 | |
import org.kuali.student.common.ui.client.widgets.NavigationHandler; |
33 | |
import org.kuali.student.common.ui.client.widgets.StylishDropDown; |
34 | |
import org.kuali.student.common.ui.client.widgets.headers.KSHeader; |
35 | |
import org.kuali.student.common.ui.client.widgets.menus.KSMenuItemData; |
36 | |
import org.kuali.student.common.ui.client.widgets.menus.KSMenu.MenuImageLocation; |
37 | |
|
38 | |
import com.google.gwt.core.client.GWT; |
39 | |
import com.google.gwt.event.dom.client.ClickEvent; |
40 | |
import com.google.gwt.event.dom.client.ClickHandler; |
41 | |
import com.google.gwt.event.dom.client.MouseOutEvent; |
42 | |
import com.google.gwt.event.dom.client.MouseOutHandler; |
43 | |
import com.google.gwt.event.dom.client.MouseOverEvent; |
44 | |
import com.google.gwt.event.dom.client.MouseOverHandler; |
45 | |
import com.google.gwt.user.client.Window; |
46 | |
import com.google.gwt.user.client.ui.Anchor; |
47 | |
import com.google.gwt.user.client.ui.Composite; |
48 | |
import com.google.gwt.user.client.ui.FlowPanel; |
49 | |
import com.google.gwt.user.client.ui.FocusPanel; |
50 | |
import com.google.gwt.user.client.ui.Frame; |
51 | |
import com.google.gwt.user.client.ui.HTML; |
52 | |
import com.google.gwt.user.client.ui.PopupPanel; |
53 | |
import com.google.gwt.user.client.ui.SimplePanel; |
54 | |
import com.google.gwt.user.client.ui.VerticalPanel; |
55 | |
import com.google.gwt.user.client.ui.Widget; |
56 | |
|
57 | |
|
58 | 0 | public class KSWrapper extends Composite{ |
59 | |
|
60 | |
private static final String LUM_APP_URL = "lum.application.url"; |
61 | |
private static final String APP_URL = "application.url"; |
62 | |
private static final String DOC_SEARCH_URL = "ks.rice.docSearch.serviceAddress"; |
63 | |
private static final String RICE_URL = "ks.rice.url"; |
64 | |
private static final String RICE_LINK_LABEL = "ks.rice.label"; |
65 | |
private static final String APP_VERSION = "ks.application.version"; |
66 | |
|
67 | |
|
68 | |
private static final String CODE_SERVER = "ks.gwt.codeServer"; |
69 | |
|
70 | 0 | private ServerPropertiesRpcServiceAsync serverPropertiesRpcService = GWT.create(ServerPropertiesRpcService.class); |
71 | |
|
72 | 0 | private FlowPanel layout = new FlowPanel(); |
73 | |
|
74 | 0 | private KSHeader ksHeader = new KSHeader(); |
75 | |
|
76 | 0 | private StylishDropDown navDropDown = new StylishDropDown(getMessage("wrapperPanelTitleHome")); |
77 | 0 | private Anchor versionAnchor = new Anchor(" ( Version ) "); |
78 | |
|
79 | |
|
80 | 0 | private SimplePanel content = new SimplePanel(); |
81 | 0 | private KSLightBox docSearchDialog = new KSLightBox(); |
82 | |
|
83 | |
private Frame docSearch; |
84 | 0 | private String docSearchUrl = ""; |
85 | 0 | private String appUrl = ".."; |
86 | 0 | private String lumAppUrl = ".."; |
87 | 0 | private String riceURL =".."; |
88 | 0 | private String riceLinkLabel="Rice"; |
89 | 0 | private String appVersion = ""; |
90 | 0 | private String codeServer = ""; |
91 | |
|
92 | 0 | private boolean loaded = false; |
93 | |
|
94 | |
private static class WrapperNavigationHandler extends NavigationHandler{ |
95 | |
public WrapperNavigationHandler(String url) { |
96 | 0 | super(url); |
97 | 0 | } |
98 | |
|
99 | |
@Override |
100 | |
public void beforeNavigate(Callback<Boolean> callback) { |
101 | |
|
102 | |
|
103 | 0 | callback.exec(true); |
104 | 0 | } |
105 | |
} |
106 | 0 | public KSWrapper(){ |
107 | 0 | this.initWidget(layout); |
108 | 0 | } |
109 | |
protected void onLoad() { |
110 | 0 | super.onLoad(); |
111 | 0 | if (!loaded){ |
112 | 0 | List<String> serverPropertyList = Arrays.asList(APP_URL, DOC_SEARCH_URL, LUM_APP_URL,RICE_URL,RICE_LINK_LABEL, APP_VERSION, CODE_SERVER); |
113 | |
|
114 | 0 | serverPropertiesRpcService.get(serverPropertyList, new KSAsyncCallback<Map<String,String>>() { |
115 | |
public void handleFailure(Throwable caught) { |
116 | |
|
117 | 0 | init(); |
118 | 0 | } |
119 | |
|
120 | |
public void onSuccess(Map<String,String> result) { |
121 | 0 | GWT.log("ServerProperties fetched: "+result.toString(), null); |
122 | 0 | if(result != null){ |
123 | 0 | appUrl = result.get(APP_URL); |
124 | 0 | docSearchUrl = result.get(DOC_SEARCH_URL); |
125 | 0 | lumAppUrl = result.get(LUM_APP_URL); |
126 | 0 | riceURL = result.get(RICE_URL); |
127 | 0 | riceLinkLabel = result.get(RICE_LINK_LABEL); |
128 | 0 | appVersion = result.get(APP_VERSION); |
129 | 0 | Application.getApplicationContext().setVersion(appVersion); |
130 | 0 | if (result.get(CODE_SERVER) != null){ |
131 | 0 | codeServer = result.get(CODE_SERVER); |
132 | |
} |
133 | |
} |
134 | 0 | init(); |
135 | 0 | } |
136 | |
|
137 | |
}); |
138 | |
|
139 | 0 | loaded = false; |
140 | |
} |
141 | 0 | } |
142 | |
private void init(){ |
143 | |
|
144 | 0 | createUserDropDown(); |
145 | |
|
146 | 0 | ksHeader.setHiLabelText("Hi,"); |
147 | 0 | ksHeader.setUserName(Application.getApplicationContext().getSecurityContext().getUserId()); |
148 | 0 | Anchor logoutLink = new Anchor(getMessage("wrapperPanelLogout")); |
149 | 0 | logoutLink.addClickHandler(new WrapperNavigationHandler("j_spring_security_logout")); |
150 | 0 | ksHeader.addLogout(logoutLink); |
151 | 0 | ksHeader.addLogout(versionAnchor); |
152 | |
|
153 | |
|
154 | 0 | createHelpInfo(); |
155 | 0 | createNavDropDown(); |
156 | 0 | ksHeader.addNavigation(navDropDown); |
157 | |
|
158 | |
|
159 | 0 | List<KSLabel> topLinks = new ArrayList<KSLabel>(); |
160 | |
|
161 | 0 | topLinks.add(buildLink(riceLinkLabel,riceLinkLabel,riceURL+"/portal.do")); |
162 | 0 | setHeaderCustomLinks(topLinks); |
163 | |
|
164 | 0 | layout.add(ksHeader); |
165 | 0 | layout.add(content); |
166 | |
|
167 | 0 | navDropDown.addStyleName("KS-Navigation-DropDown"); |
168 | 0 | content.addStyleName("KS-Wrapper-Content"); |
169 | 0 | layout.addStyleName("KS-Wrapper"); |
170 | 0 | } |
171 | |
|
172 | |
private void createHelpInfo(){ |
173 | 0 | versionAnchor.addClickHandler(new ClickHandler(){ |
174 | |
|
175 | |
public void onClick(ClickEvent event) { |
176 | 0 | final PopupPanel helpPopup = new PopupPanel(true); |
177 | 0 | helpPopup.setWidget(new HTML("<br><h3> " + appVersion + " <h3>")); |
178 | |
|
179 | 0 | helpPopup.setPopupPositionAndShow(new PopupPanel.PositionCallback() { |
180 | |
public void setPosition(int offsetWidth, int offsetHeight) { |
181 | 0 | int left = (Window.getClientWidth() - offsetWidth); |
182 | 0 | int top = 0; |
183 | 0 | helpPopup.setPopupPosition(left, top); |
184 | 0 | } |
185 | |
}); |
186 | 0 | } |
187 | |
}); |
188 | 0 | } |
189 | |
|
190 | |
private void createUserDropDown() { |
191 | 0 | List<KSMenuItemData> items = new ArrayList<KSMenuItemData>(); |
192 | 0 | items.add(new KSMenuItemData(getMessage("wrapperPanelLogout"),new WrapperNavigationHandler("j_spring_security_logout"))); |
193 | 0 | } |
194 | |
|
195 | |
private void createNavDropDown() { |
196 | 0 | navDropDown.setImageLocation(MenuImageLocation.LEFT); |
197 | |
|
198 | 0 | List<KSMenuItemData> items = new ArrayList<KSMenuItemData>(); |
199 | |
|
200 | 0 | items.add(new KSMenuItemData(getMessage("wrapperPanelTitleHome"),Theme.INSTANCE.getCommonImages().getSpacerIcon(), |
201 | |
new WrapperNavigationHandler( |
202 | |
"#")) |
203 | |
); |
204 | 0 | items.add(new KSMenuItemData(getMessage("wrapperPanelTitleMyActionList"),Theme.INSTANCE.getCommonImages().getApplicationIcon(), |
205 | |
new WrapperNavigationHandler( |
206 | |
lumAppUrl+"/org.kuali.student.lum.lu.ui.main.LUMMain/LUMMain.jsp"+(codeServer.isEmpty()?"":"?"+codeServer))) |
207 | |
); |
208 | 0 | items.add(new KSMenuItemData(getMessage("wrapperPanelTitleCurriculumManagement"),Theme.INSTANCE.getCommonImages().getBookIcon(), |
209 | |
new WrapperNavigationHandler( |
210 | |
lumAppUrl+"/org.kuali.student.lum.lu.ui.main.LUMMain/LUMMain.jsp?view=CURRICULUM_MANAGEMENT"+(codeServer.isEmpty()?"":"&"+codeServer))) |
211 | |
); |
212 | 0 | items.add(new KSMenuItemData(getMessage("wrapperPanelTitleOrg"), Theme.INSTANCE.getCommonImages().getPeopleIcon(), |
213 | |
new WrapperNavigationHandler( |
214 | |
lumAppUrl+"/org.kuali.student.core.organization.ui.OrgEntry/OrgEntry.jsp")) |
215 | |
); |
216 | 0 | items.add(new KSMenuItemData(getMessage("wrapperPanelTitleWorkflowDocSearch"), Theme.INSTANCE.getCommonImages().getNodeIcon(), |
217 | 0 | new ClickHandler(){ |
218 | |
|
219 | |
@Override |
220 | |
public void onClick(ClickEvent event) { |
221 | 0 | buildDocSearchPanel(); |
222 | 0 | docSearchDialog.show(); |
223 | 0 | }}) |
224 | |
); |
225 | 0 | items.add(new KSMenuItemData(getMessage("wrapperPanelTitleRice"), Theme.INSTANCE.getCommonImages().getRiceIcon(), |
226 | |
new WrapperNavigationHandler( |
227 | |
riceURL+"/portal.do?selectedTab=main")) |
228 | |
); |
229 | |
|
230 | 0 | navDropDown.setShowSelectedItem(true); |
231 | 0 | navDropDown.setItems(items); |
232 | 0 | navDropDown.setArrowImage(Theme.INSTANCE.getCommonImages().getDropDownIconWhite()); |
233 | |
|
234 | 0 | } |
235 | |
|
236 | |
public void setContent(Widget wrappedContent){ |
237 | 0 | content.setWidget(wrappedContent); |
238 | 0 | } |
239 | |
|
240 | |
public void setHeaderCustomLinks(List<KSLabel> links){ |
241 | 0 | for(KSLabel link: links){ |
242 | 0 | FocusPanel panel = new FocusPanel(); |
243 | 0 | panel.setWidget(link); |
244 | |
|
245 | 0 | panel.addStyleName("KS-Wrapper-Header-Custom-Link-Panel"); |
246 | 0 | link.addStyleName("KS-Wrapper-Header-Custom-Link"); |
247 | 0 | } |
248 | 0 | } |
249 | |
|
250 | |
public void setFooterLinks(List<KSLabel> links){ |
251 | 0 | for(KSLabel link: links){ |
252 | |
|
253 | 0 | link.addStyleName("KS-Wrapper-Footer-Link"); |
254 | |
} |
255 | 0 | } |
256 | |
|
257 | |
|
258 | |
private KSLabel buildLink(final String text, final String title, final String actionUrl) { |
259 | |
|
260 | |
|
261 | 0 | final KSLabel link = new KSLabel(text); |
262 | 0 | link.addStyleName("KS-Header-Link"); |
263 | 0 | link.setTitle(title); |
264 | 0 | link.addMouseOverHandler(new MouseOverHandler() { |
265 | |
|
266 | |
@Override |
267 | |
public void onMouseOver(MouseOverEvent event) { |
268 | 0 | link.addStyleName("KS-Header-Link-Focus"); |
269 | 0 | }}); |
270 | |
|
271 | 0 | link.addMouseOutHandler(new MouseOutHandler() { |
272 | |
|
273 | |
@Override |
274 | |
public void onMouseOut(MouseOutEvent event) { |
275 | 0 | link.removeStyleName("KS-Header-Link-Focus"); |
276 | |
|
277 | 0 | }}); |
278 | 0 | link.addClickHandler(new ClickHandler() { |
279 | |
|
280 | |
@Override |
281 | |
public void onClick(ClickEvent event) { |
282 | 0 | Window.Location.assign(actionUrl); |
283 | 0 | }}); |
284 | |
|
285 | 0 | return link; |
286 | |
|
287 | |
} |
288 | |
|
289 | |
|
290 | |
private void buildDocSearchPanel(){ |
291 | 0 | if (docSearch == null){ |
292 | 0 | docSearch = new Frame(); |
293 | 0 | docSearch.setSize("700px", "500px"); |
294 | 0 | docSearch.setUrl(docSearchUrl); |
295 | |
|
296 | 0 | VerticalPanel docSearchPanel = new VerticalPanel(); |
297 | 0 | docSearchPanel.add(docSearch); |
298 | |
|
299 | 0 | KSButton closeActionButton = new KSButton(getMessage("wrapperPanelClose")); |
300 | 0 | closeActionButton.addClickHandler(new ClickHandler(){ |
301 | |
public void onClick(ClickEvent event) { |
302 | 0 | docSearchDialog.hide(); |
303 | 0 | } |
304 | |
}); |
305 | |
|
306 | 0 | docSearchPanel.add(closeActionButton); |
307 | 0 | docSearchDialog.setWidget(docSearchPanel); |
308 | 0 | docSearchDialog.setSize(750, 550); |
309 | |
} |
310 | 0 | } |
311 | |
|
312 | |
private static String getMessage(final String messageId) { |
313 | 0 | return Application.getApplicationContext().getMessage(messageId); |
314 | |
} |
315 | |
} |