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