1 package org.kuali.student.lum.lu.ui.main.client.configuration;
2
3 import java.util.List;
4
5 import org.kuali.student.common.assembly.data.Metadata;
6 import org.kuali.student.common.rice.StudentIdentityConstants;
7 import org.kuali.student.common.ui.client.application.Application;
8 import org.kuali.student.common.ui.client.application.ViewContext;
9 import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle;
10 import org.kuali.student.common.ui.client.mvc.Callback;
11 import org.kuali.student.common.ui.client.widgets.KSLightBox;
12 import org.kuali.student.common.ui.client.widgets.layout.ContentBlockLayout;
13 import org.kuali.student.common.ui.client.widgets.layout.LinkContentBlock;
14 import org.kuali.student.common.ui.client.widgets.search.KSPicker;
15 import org.kuali.student.common.ui.client.widgets.search.SearchPanel;
16 import org.kuali.student.common.ui.client.widgets.search.SelectedResults;
17 import org.kuali.student.common.ui.shared.IdAttributes.IdType;
18 import org.kuali.student.lum.common.client.widgets.AppLocations;
19 import org.kuali.student.lum.lu.ui.course.client.widgets.RecentlyViewedBlock;
20 import org.kuali.student.lum.program.client.ProgramClientConstants;
21 import org.kuali.student.lum.program.client.ProgramConstants;
22 import org.kuali.student.lum.program.client.ProgramRegistry;
23
24 import com.google.gwt.event.dom.client.ClickEvent;
25 import com.google.gwt.event.dom.client.ClickHandler;
26 import com.google.gwt.event.logical.shared.ValueChangeEvent;
27 import com.google.gwt.event.logical.shared.ValueChangeHandler;
28 import com.google.gwt.user.client.ui.Anchor;
29 import com.google.gwt.user.client.ui.Hyperlink;
30 import com.google.gwt.user.client.ui.Label;
31 import com.google.gwt.user.client.ui.Widget;
32
33 public class CurriculumHomeConfigurer implements CurriculumHomeConstants {
34
35 protected Metadata searchMetadata;
36
37 public Widget configure(Metadata searchMeta) {
38 this.searchMetadata = searchMeta;
39 ContentBlockLayout layout = new ContentBlockLayout(getMessage(CURRICULUM_MANAGEMENT));
40 layout.addContentTitleWidget(getHowToWidget());
41 layout.addContentTitleWidget(getActionListLink());
42
43
44 LinkContentBlock create = new LinkContentBlock(
45 getMessage(CREATE),
46 getMessage(CREATE_DESC));
47 create.addNavLinkWidget(getMessage(CREATE_COURSE), AppLocations.Locations.COURSE_PROPOSAL.getLocation());
48 create.addNavLinkWidget(getMessage(CREATE_PROGRAM), AppLocations.Locations.EDIT_PROGRAM.getLocation());
49
50
51
52 LinkContentBlock viewModify = new LinkContentBlock(
53 getMessage(VIEW_MODIFY),
54 getMessage(VIEW_MODIFY_DESC));
55 SectionTitle courses = SectionTitle.generateH4Title(getMessage("courses"));
56 courses.addStyleName("bold");
57 viewModify.add(courses);
58 viewModify.addNavLinkWidget(getMessage(BROWSE_CATALOG), AppLocations.Locations.BROWSE_CATALOG.getLocation());
59 viewModify.add(getFindCoursesWidget());
60 viewModify.add(getFindProposalsWidget());
61 SectionTitle programs = SectionTitle.generateH4Title(getMessage("programs"));
62 programs.addStyleName("bold");
63 viewModify.add(programs);
64 viewModify.addNavLinkWidget(getMessage(BROWSE_PROGRAM), AppLocations.Locations.BROWSE_PROGRAM.getLocation());
65 viewModify.add(getFindMajorsWidget());
66 viewModify.add(getFindCoreProgramWidget());
67 viewModify.add(getFindCredentialProgramWidget());
68
69
70 RecentlyViewedBlock recent = new RecentlyViewedBlock(
71 getMessage(RECENTLY_VIEWED),
72 getMessage(RV_DESC));
73 recent.addStyleName("recentlyViewed-block");
74
75
76 LinkContentBlock tools = new LinkContentBlock(
77 getMessage(TOOLS),
78 getMessage(TOOLS_DESC));
79 tools.addNavLinkWidget(getMessage(COURSE_SETS), AppLocations.Locations.MANAGE_CLU_SETS.getLocation());
80 tools.addNavLinkWidget(getMessage(LO_CATEGORIES), AppLocations.Locations.MANAGE_LO_CATEGORIES.getLocation());
81 tools.addNavLinkWidget(getMessage(DEP_ANALYSIS), AppLocations.Locations.DEPENDENCY_ANALYSIS.getLocation());
82
83
84 Label learningObjectives = new Label(getMessage(LOS));
85 learningObjectives.setTitle("Coming Soon");
86 learningObjectives.setStyleName("contentBlock-navLink-disabled");
87 tools.add(learningObjectives);
88
89
90 layout.addContentBlock(create);
91 layout.addContentBlock(viewModify);
92 recent.addBlock(tools);
93 layout.addContentBlock(recent);
94
95 return layout;
96 }
97
98 private Widget getFindCredentialProgramWidget() {
99 Anchor anchor = createNavigationWidget(getMessage(FIND_CREDENTIALS));
100 anchor.addClickHandler(new ClickHandler() {
101 @Override
102 public void onClick(ClickEvent event) {
103 ProgramRegistry.setCreateNew(true);
104 ViewContext baccViewContext = new ViewContext();
105 baccViewContext.setId(ProgramClientConstants.CREDENTIAL_BACCALAUREATE_PROGRAM);
106 Application.navigate(AppLocations.Locations.VIEW_BACC_PROGRAM.getLocation(), baccViewContext);
107 }
108 });
109 return anchor;
110 }
111
112 private Widget getFindCoreProgramWidget() {
113 Anchor anchor = createNavigationWidget(getMessage(FIND_CORES));
114 anchor.addClickHandler(new ClickHandler() {
115 @Override
116 public void onClick(ClickEvent event) {
117 ProgramRegistry.setCreateNew(true);
118 Application.navigate(AppLocations.Locations.VIEW_CORE_PROGRAM.getLocation());
119 }
120 });
121 return anchor;
122 }
123
124
125 protected Widget getFindProposalsWidget() {
126 final Widget searchWidget;
127 if (searchMetadata != null) {
128 Metadata metadata = searchMetadata.getProperties().get("findProposal");
129 searchWidget = new KSPicker(metadata.getInitialLookup(), metadata.getAdditionalLookups());
130 SearchPanel panel = ((KSPicker) searchWidget).getSearchPanel();
131 if (panel != null) {
132 panel.setMutipleSelect(false);
133 }
134 ((KSPicker) searchWidget).setAdvancedSearchCallback(new Callback<List<SelectedResults>>() {
135
136 @Override
137 public void exec(List<SelectedResults> result) {
138 if (result != null && result.size() > 0) {
139 SelectedResults value = result.get(0);
140 ViewContext viewContext = new ViewContext();
141 viewContext.setId(value.getResultRow().getId());
142 viewContext.setAttribute(StudentIdentityConstants.DOCUMENT_TYPE_NAME, value.getResultRow().getValue("proposal.resultColumn.proposalType"));
143 viewContext.setIdType(IdType.KS_KEW_OBJECT_ID);
144 Application.navigate(AppLocations.Locations.COURSE_PROPOSAL.getLocation(), viewContext);
145 ((KSPicker) searchWidget).getSearchWindow().hide();
146 }
147 }
148 });
149 } else {
150 searchWidget = new Label(getMessage(FIND_PROPOSALS));
151 searchWidget.setStyleName("contentBlock-navLink-disabled");
152 }
153 searchWidget.setStyleName("contentBlock-navLink");
154 return searchWidget;
155 }
156
157 protected Widget getFindCoursesWidget() {
158 Widget searchWidget;
159 if (searchMetadata != null) {
160 Metadata metadata = searchMetadata.getProperties().get("findCourse");
161 searchWidget = new KSPicker(metadata.getInitialLookup(), metadata.getAdditionalLookups());
162 SearchPanel panel = ((KSPicker) searchWidget).getSearchPanel();
163 if (panel != null) {
164 panel.setMutipleSelect(false);
165 }
166 ((KSPicker) searchWidget).addValuesChangeHandler(new ValueChangeHandler<List<String>>() {
167 public void onValueChange(ValueChangeEvent<List<String>> event) {
168 List<String> selection = event.getValue();
169 ViewContext viewContext = new ViewContext();
170 viewContext.setId(selection.get(0));
171 viewContext.setIdType(IdType.OBJECT_ID);
172 Application.navigate(AppLocations.Locations.VIEW_COURSE.getLocation(), viewContext);
173 }
174 });
175 searchWidget.setStyleName("contentBlock-navLink");
176 } else {
177 searchWidget = new Label(getMessage(FIND_COURSES));
178 searchWidget.setStyleName("contentBlock-navLink-disabled");
179 }
180 return searchWidget;
181 }
182
183 protected Widget getFindMajorsWidget() {
184 final Widget searchWidget;
185 if (searchMetadata != null) {
186 Metadata metadata = searchMetadata.getProperties().get("findMajor");
187 searchWidget = new KSPicker(metadata.getInitialLookup(), metadata.getAdditionalLookups());
188 SearchPanel panel = ((KSPicker) searchWidget).getSearchPanel();
189 if (panel != null) {
190 panel.setMutipleSelect(false);
191 }
192 ((KSPicker) searchWidget).setAdvancedSearchCallback(new Callback<List<SelectedResults>>() {
193
194 @Override
195 public void exec(List<SelectedResults> result) {
196 SelectedResults value = result.get(0);
197 ViewContext viewContext = new ViewContext();
198 viewContext.setId(value.getResultRow().getId());
199 String cluType = value.getResultRow().getValue("lu.resultColumn.luOptionalType");
200 if (cluType != null) {
201 viewContext.setAttribute(ProgramConstants.TYPE, cluType);
202 }
203 String variationId = value.getResultRow().getValue("lu.resultColumn.variationId");
204 if (variationId != null && !variationId.trim().isEmpty()) {
205 viewContext.setAttribute(ProgramConstants.VARIATION_ID, variationId);
206 }
207 viewContext.setIdType(IdType.OBJECT_ID);
208 ProgramRegistry.setCreateNew(true);
209 Application.navigate(AppLocations.Locations.VIEW_PROGRAM.getLocation(), viewContext);
210 ((KSPicker) searchWidget).getSearchWindow().hide();
211 }
212 });
213
214 } else {
215 searchWidget = new Label(getMessage(FIND_MAJORS));
216 searchWidget.setStyleName("contentBlock-navLink-disabled");
217 }
218 searchWidget.setStyleName("contentBlock-navLink");
219 return searchWidget;
220 }
221
222 protected Widget getHowToWidget() {
223 Anchor widget = new Anchor(getMessage(HOW_TO));
224 widget.addClickHandler(new ClickHandler() {
225
226 @Override
227 public void onClick(ClickEvent event) {
228 final KSLightBox pop = new KSLightBox();
229 pop.setWidget(new CurriculumHomeHelpTable());
230 pop.setSize(800, 600);
231 pop.show();
232 }
233 });
234 widget.setStyleName("contentBlock-navLink");
235 return widget;
236 }
237
238 protected Widget getActionListLink() {
239 Hyperlink widget = new Hyperlink(getMessage(ACTIONLIST), AppLocations.Locations.HOME.getLocation());
240 widget.setStyleName("contentBlock-navLink");
241 return widget;
242 }
243
244 private String getMessage(String key) {
245 return Application.getApplicationContext().getMessage(key);
246 }
247
248 private Anchor createNavigationWidget(String title) {
249 Anchor anchor = new Anchor(title);
250 anchor.addStyleName("contentBlock-navLink");
251 return anchor;
252 }
253
254 }