1 | |
package org.kuali.student.lum.common.client.widgets; |
2 | |
|
3 | |
import java.text.SimpleDateFormat; |
4 | |
import java.util.ArrayList; |
5 | |
import java.util.Date; |
6 | |
import java.util.HashMap; |
7 | |
import java.util.List; |
8 | |
import java.util.Map; |
9 | |
|
10 | |
import org.kuali.student.common.search.dto.SearchParam; |
11 | |
import org.kuali.student.common.ui.client.mvc.Callback; |
12 | |
import org.kuali.student.common.ui.client.reporting.ReportExportWidget; |
13 | |
import org.kuali.student.common.ui.client.util.ExportElement; |
14 | |
import org.kuali.student.common.ui.client.widgets.KSButton; |
15 | |
import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle; |
16 | |
import org.kuali.student.common.ui.client.widgets.KSLabel; |
17 | |
import org.kuali.student.common.ui.client.widgets.notification.KSNotification; |
18 | |
import org.kuali.student.common.ui.client.widgets.notification.KSNotifier; |
19 | |
import org.kuali.student.common.ui.client.widgets.progress.BlockingTask; |
20 | |
import org.kuali.student.common.ui.client.widgets.progress.KSBlockingProgressIndicator; |
21 | |
import org.kuali.student.common.ui.shared.IdAttributes.IdType; |
22 | |
import org.kuali.student.lum.lu.dto.CluSetInfo; |
23 | |
import org.kuali.student.lum.lu.dto.MembershipQueryInfo; |
24 | |
|
25 | |
import com.google.gwt.dom.client.Style; |
26 | |
import com.google.gwt.event.dom.client.ClickEvent; |
27 | |
import com.google.gwt.event.dom.client.ClickHandler; |
28 | |
import com.google.gwt.user.client.Window; |
29 | |
import com.google.gwt.user.client.ui.Anchor; |
30 | |
import com.google.gwt.user.client.ui.Composite; |
31 | |
import com.google.gwt.user.client.ui.FlexTable; |
32 | |
import com.google.gwt.user.client.ui.HTML; |
33 | |
import com.google.gwt.user.client.ui.HTMLPanel; |
34 | |
import com.google.gwt.user.client.ui.HorizontalPanel; |
35 | |
import com.google.gwt.user.client.ui.SimplePanel; |
36 | |
|
37 | 0 | public class CluSetDetailsWidget extends Composite implements ReportExportWidget { |
38 | |
|
39 | |
private CluSetInformation cluSetInformation; |
40 | |
private SimplePanel mainPanel; |
41 | 0 | private FlexTable detailsTable = new FlexTable(); |
42 | |
private boolean showClus; |
43 | 0 | private Map<String, Boolean> showCluSetFlags = new HashMap<String, Boolean>(); |
44 | |
|
45 | |
private CluSetRetriever cluSetRetriever; |
46 | |
|
47 | 0 | private BlockingTask retrievingTask = new BlockingTask("Retrieving details"); |
48 | |
|
49 | 0 | public CluSetDetailsWidget(CluSetInformation cluSetInformation, CluSetRetriever cluSetRetriever) { |
50 | 0 | mainPanel = new SimplePanel(); |
51 | 0 | this.initWidget(mainPanel); |
52 | 0 | this.cluSetRetriever = cluSetRetriever; |
53 | 0 | setCluSetInformation(cluSetInformation); |
54 | 0 | redraw(); |
55 | 0 | } |
56 | |
|
57 | 0 | public CluSetDetailsWidget(String cluSetId, CluSetRetriever cluSetRetriever) { |
58 | 0 | mainPanel = new SimplePanel(); |
59 | 0 | this.initWidget(mainPanel); |
60 | 0 | this.cluSetRetriever = cluSetRetriever; |
61 | |
|
62 | 0 | KSBlockingProgressIndicator.addTask(retrievingTask); |
63 | 0 | cluSetRetriever.getCluSetInformation(cluSetId, new Callback<CluSetInformation>() { |
64 | |
@Override |
65 | |
public void exec(CluSetInformation result) { |
66 | 0 | if (result != null) { |
67 | 0 | setCluSetInformation(result); |
68 | 0 | redraw(); |
69 | |
} |
70 | 0 | KSBlockingProgressIndicator.removeTask(retrievingTask); |
71 | 0 | } |
72 | |
}); |
73 | 0 | } |
74 | |
|
75 | |
private void redraw() { |
76 | 0 | List<CluInformation> clus = null; |
77 | 0 | List<CluSetInfo> cluSets = null; |
78 | 0 | MembershipQueryInfo membershipQueryInfo = null; |
79 | 0 | List<CluInformation> clusInRange = null; |
80 | 0 | int rowIndex = 0; |
81 | 0 | mainPanel.clear(); |
82 | 0 | detailsTable.clear(); |
83 | 0 | if (cluSetInformation == null) { |
84 | 0 | return; |
85 | |
} else { |
86 | 0 | clus = cluSetInformation.getClus(); |
87 | 0 | cluSets = cluSetInformation.getCluSets(); |
88 | 0 | membershipQueryInfo = cluSetInformation.getMembershipQueryInfo(); |
89 | 0 | clusInRange = cluSetInformation.getClusInRange(); |
90 | |
} |
91 | 0 | StringBuilder titleTextSb = new StringBuilder(); |
92 | 0 | titleTextSb.append("INDIVIDUAL COURSE(S)"); |
93 | 0 | KSLabel coursesHeader = new KSLabel(titleTextSb.toString()); |
94 | |
|
95 | 0 | detailsTable.setWidget(rowIndex, 0, coursesHeader); |
96 | 0 | detailsTable.getFlexCellFormatter().setColSpan(rowIndex, 0, 2); |
97 | 0 | if (cluSets != null && cluSets.size() > 0 || clusInRange != null && clusInRange.size() > 0) { |
98 | 0 | coursesHeader.setVisible(true); |
99 | |
} else { |
100 | 0 | coursesHeader.setVisible(false); |
101 | |
} |
102 | |
{ |
103 | |
|
104 | 0 | int numClus = (clus == null) ? 0 : clus.size(); |
105 | 0 | StringBuilder hideClusTextSb = new StringBuilder(); |
106 | 0 | showClus = true; |
107 | 0 | if (showClus) { |
108 | 0 | hideClusTextSb.append("Hide courses(").append(numClus).append(")"); |
109 | |
} else { |
110 | 0 | hideClusTextSb.append("Show courses(").append(numClus).append(")"); |
111 | |
} |
112 | 0 | KSButton hideClusButton = new KSButton(hideClusTextSb.toString(), ButtonStyle.DEFAULT_ANCHOR); |
113 | 0 | detailsTable.setWidget(rowIndex, 1, hideClusButton); |
114 | 0 | hideClusButton.addClickHandler(new ClickHandler() { |
115 | |
@Override |
116 | |
public void onClick(ClickEvent event) { |
117 | 0 | showClus = !showClus; |
118 | 0 | redraw(); |
119 | 0 | } |
120 | |
}); |
121 | 0 | if (numClus > 10) { |
122 | 0 | hideClusButton.setVisible(true); |
123 | |
} else { |
124 | 0 | hideClusButton.setVisible(false); |
125 | |
} |
126 | |
} |
127 | |
|
128 | 0 | rowIndex++; |
129 | 0 | if (clus != null && showClus) { |
130 | 0 | for (CluInformation clu : clus) { |
131 | 0 | addClusDisplayToTable(rowIndex, clu); |
132 | 0 | rowIndex++; |
133 | |
} |
134 | |
} |
135 | 0 | if (cluSets != null) { |
136 | 0 | if (cluSets.size() > 0) { |
137 | 0 | KSLabel spacer = new KSLabel(); |
138 | 0 | spacer.getElement().getStyle().setPaddingTop(10, Style.Unit.PX); |
139 | 0 | detailsTable.setWidget(rowIndex, 0, spacer); |
140 | 0 | detailsTable.getFlexCellFormatter().setColSpan(rowIndex, 0, 3); |
141 | 0 | rowIndex++; |
142 | |
} |
143 | 0 | for (final CluSetInfo cluSet : cluSets) { |
144 | 0 | int columnIndex = 0; |
145 | 0 | final String cluSetId = cluSet.getId(); |
146 | 0 | HorizontalPanel cluSetNamePanel = new HorizontalPanel(); |
147 | 0 | Anchor cluSetNameLabel = new Anchor(cluSet.getName()); |
148 | 0 | cluSetNameLabel.addClickHandler(new ClickHandler() { |
149 | |
|
150 | |
@Override |
151 | |
public void onClick(ClickEvent event) { |
152 | 0 | String url = "http://" + Window.Location.getHost() + Window.Location.getPath() + "?view=" + AppLocations.Locations.VIEW_CLU_SET + "&docId=" + cluSetId; |
153 | 0 | String features = "height=600,width=960,dependent=0,directories=1," + "fullscreen=1,location=1,menubar=1,resizable=1,scrollbars=1,status=1,toolbar=1"; |
154 | 0 | Window.open(url, HTMLPanel.createUniqueId(), features); |
155 | |
|
156 | 0 | } |
157 | |
}); |
158 | 0 | KSLabel itemType = new KSLabel("Course Set"); |
159 | 0 | itemType.getElement().getStyle().setProperty("color", "grey"); |
160 | 0 | itemType.getElement().getStyle().setPaddingLeft(5, Style.Unit.PX); |
161 | 0 | cluSetNamePanel.add(cluSetNameLabel); |
162 | 0 | cluSetNamePanel.add(itemType); |
163 | 0 | boolean showCluSet = (showCluSetFlags.get(cluSet.getId()) == null) ? false : showCluSetFlags.get(cluSet.getId()).booleanValue(); |
164 | 0 | detailsTable.setWidget(rowIndex, columnIndex, cluSetNamePanel); |
165 | 0 | detailsTable.getFlexCellFormatter().setColSpan(rowIndex, columnIndex, 1); |
166 | 0 | columnIndex++; |
167 | |
|
168 | |
|
169 | |
|
170 | 0 | columnIndex++; |
171 | 0 | StringBuilder hideCluSetTextSb = new StringBuilder(); |
172 | 0 | if (showCluSet) { |
173 | 0 | hideCluSetTextSb.append("Hide Courses"); |
174 | |
} else { |
175 | 0 | hideCluSetTextSb.append("Show Courses"); |
176 | |
} |
177 | 0 | KSButton hideCluSetButton = new KSButton(hideCluSetTextSb.toString(), ButtonStyle.DEFAULT_ANCHOR); |
178 | 0 | detailsTable.setWidget(rowIndex, columnIndex, hideCluSetButton); |
179 | 0 | rowIndex++; |
180 | 0 | hideCluSetButton.addClickHandler(new ClickHandler() { |
181 | |
@Override |
182 | |
public void onClick(ClickEvent event) { |
183 | 0 | Boolean showCluSetDetails = showCluSetFlags.get(cluSet.getId()); |
184 | 0 | showCluSetDetails = (showCluSetDetails == null) ? false : showCluSetDetails; |
185 | 0 | showCluSetFlags.put(cluSet.getId(), !showCluSetDetails); |
186 | 0 | Boolean newShowCluSetDetails = !showCluSetDetails; |
187 | 0 | if (newShowCluSetDetails) { |
188 | 0 | CluSetInformation subCluSetInformation = cluSetInformation.getSubCluSetInformations().get(cluSet.getId()); |
189 | 0 | if (subCluSetInformation == null) { |
190 | 0 | cluSetRetriever.getCluSetInformation(cluSet.getId(), new Callback<CluSetInformation>() { |
191 | |
@Override |
192 | |
public void exec(CluSetInformation result) { |
193 | 0 | if (result != null) { |
194 | 0 | cluSetInformation.getSubCluSetInformations().put(cluSet.getId(), result); |
195 | 0 | redraw(); |
196 | |
} |
197 | 0 | } |
198 | |
}); |
199 | |
} else { |
200 | 0 | redraw(); |
201 | |
} |
202 | 0 | } else { |
203 | 0 | redraw(); |
204 | |
} |
205 | 0 | } |
206 | |
}); |
207 | 0 | if (showCluSet) { |
208 | 0 | CluSetInformation subCluSetInformation = cluSetInformation.getSubCluSetInformations().get(cluSet.getId()); |
209 | 0 | CluSetDetailsWidget subCluSetWidget = new CluSetDetailsWidget(subCluSetInformation, cluSetRetriever); |
210 | 0 | subCluSetWidget.getElement().getStyle().setPaddingLeft(20, Style.Unit.PX); |
211 | 0 | detailsTable.setWidget(rowIndex, 0, subCluSetWidget); |
212 | 0 | detailsTable.getFlexCellFormatter().setColSpan(rowIndex, 0, 3); |
213 | 0 | rowIndex++; |
214 | |
} |
215 | |
|
216 | 0 | } |
217 | |
} |
218 | 0 | if (membershipQueryInfo != null) { |
219 | 0 | List<SearchParam> searchParams = membershipQueryInfo.getQueryParamValueList(); |
220 | 0 | if (searchParams != null) { |
221 | 0 | HorizontalPanel queryDisplayPanel = new HorizontalPanel(); |
222 | 0 | for (SearchParam searchParam : searchParams) { |
223 | 0 | KSLabel paramDescLabel = new KSLabel(); |
224 | 0 | KSLabel paramValueLabel = new KSLabel(); |
225 | 0 | String paramDesc = translateSearchKey(searchParam.getKey()); |
226 | 0 | paramDescLabel.setText(paramDesc); |
227 | 0 | Object value = searchParam.getValue(); |
228 | 0 | String displayValue = ""; |
229 | 0 | if (value instanceof Date) { |
230 | 0 | SimpleDateFormat DT_FOMRAT = new SimpleDateFormat("MM/dd/yyyy"); |
231 | 0 | displayValue = DT_FOMRAT.format((Date) value); |
232 | 0 | } else { |
233 | 0 | displayValue = value.toString(); |
234 | |
} |
235 | 0 | paramDescLabel.getElement().getStyle().setProperty("color", "grey"); |
236 | 0 | paramDescLabel.getElement().getStyle().setPaddingRight(5, Style.Unit.PX); |
237 | 0 | paramValueLabel.setText(displayValue); |
238 | 0 | paramValueLabel.getElement().getStyle().setPaddingRight(10, Style.Unit.PX); |
239 | 0 | queryDisplayPanel.getElement().getStyle().setPaddingTop(10, Style.Unit.PX); |
240 | 0 | queryDisplayPanel.add(paramDescLabel); |
241 | 0 | queryDisplayPanel.add(paramValueLabel); |
242 | 0 | } |
243 | 0 | detailsTable.setWidget(rowIndex, 0, queryDisplayPanel); |
244 | 0 | detailsTable.getFlexCellFormatter().setColSpan(rowIndex, 0, 2); |
245 | 0 | rowIndex++; |
246 | |
} |
247 | 0 | if (clusInRange != null) { |
248 | 0 | for (CluInformation clu : clusInRange) { |
249 | 0 | addClusDisplayToTable(rowIndex, clu); |
250 | 0 | rowIndex++; |
251 | |
} |
252 | |
} else { |
253 | 0 | Window.alert("num clusInRange is null"); |
254 | |
} |
255 | |
} |
256 | 0 | mainPanel.setWidget(detailsTable); |
257 | 0 | } |
258 | |
|
259 | |
private void addClusDisplayToTable(int rowIndex, final CluInformation clu) { |
260 | 0 | int columnIndex = 0; |
261 | 0 | KSButton cluCodeLink = new KSButton(clu.getCode(), ButtonStyle.DEFAULT_ANCHOR); |
262 | 0 | cluCodeLink.getElement().getStyle().setPaddingLeft(10, Style.Unit.PX); |
263 | 0 | detailsTable.setWidget(rowIndex, columnIndex, cluCodeLink); |
264 | 0 | detailsTable.getFlexCellFormatter().setColSpan(rowIndex, columnIndex, 1); |
265 | 0 | cluCodeLink.addClickHandler(new ClickHandler() { |
266 | |
@Override |
267 | |
public void onClick(ClickEvent event) { |
268 | 0 | String url = "http://" + Window.Location.getHost() + Window.Location.getPath(); |
269 | 0 | if("kuali.lu.type.Variation".equals(clu.getType())){ |
270 | 0 | url += "?view=" + AppLocations.Locations.VIEW_VARIATION + "&idType=" + IdType.OBJECT_ID; |
271 | 0 | url += "&docId=" + clu.getParentCluId() + "&variationId=" + clu.getVerIndependentId(); |
272 | 0 | }else if("kuali.lu.type.MajorDiscipline".equals(clu.getType())){ |
273 | 0 | url += "?view=" + AppLocations.Locations.VIEW_PROGRAM + "&idType=" + IdType.OBJECT_ID; |
274 | 0 | url += "&docId=" + clu.getVerIndependentId(); |
275 | 0 | }else if("kuali.lu.type.CreditCourse".equals(clu.getType())){ |
276 | 0 | url += "?view=" + AppLocations.Locations.VIEW_COURSE + "&idType=" + IdType.OBJECT_ID; |
277 | 0 | url += "&docId=" + clu.getVerIndependentId(); |
278 | 0 | }else if("kuali.lu.type.CoreProgram".equals(clu.getType())){ |
279 | 0 | url += "?view=" + AppLocations.Locations.VIEW_CORE_PROGRAM + "&idType=" + IdType.OBJECT_ID; |
280 | 0 | url += "&docId=" + clu.getVerIndependentId(); |
281 | 0 | }else if("kuali.lu.type.credential.Baccalaureate".equals(clu.getType())){ |
282 | 0 | url += "?view=" + AppLocations.Locations.VIEW_BACC_PROGRAM + "&idType=" + IdType.OBJECT_ID; |
283 | 0 | url += "&docId=" + clu.getVerIndependentId(); |
284 | 0 | }else if("kuali.lu.type.credential.Doctoral".equals(clu.getType())){ |
285 | 0 | url += "?view=" + AppLocations.Locations.VIEW_BACC_PROGRAM + "&idType=" + IdType.OBJECT_ID; |
286 | 0 | url += "&docId=" + clu.getVerIndependentId(); |
287 | 0 | }else if("kuali.lu.type.credential.Masters".equals(clu.getType())){ |
288 | 0 | url += "?view=" + AppLocations.Locations.VIEW_BACC_PROGRAM + "&idType=" + IdType.OBJECT_ID; |
289 | 0 | url += "&docId=" + clu.getVerIndependentId(); |
290 | |
}else{ |
291 | |
|
292 | 0 | KSNotifier.add(new KSNotification("This widget does not know how to open learning units of type "+clu.getType(), false, true, 5000)); |
293 | 0 | return; |
294 | |
} |
295 | 0 | String features = "height=600,width=960,dependent=0,directories=1," + "fullscreen=1,location=1,menubar=1,resizable=1,scrollbars=1,status=1,toolbar=1"; |
296 | 0 | Window.open(url, HTMLPanel.createUniqueId().replace("-", "_"), features); |
297 | 0 | } |
298 | |
}); |
299 | 0 | columnIndex++; |
300 | |
|
301 | 0 | HTML cluTitleLabel = new HTML("<h5>" + clu.getTitle() + "</h5>"); |
302 | 0 | detailsTable.setWidget(rowIndex, columnIndex, cluTitleLabel); |
303 | 0 | detailsTable.getFlexCellFormatter().setColSpan(rowIndex, columnIndex, 1); |
304 | 0 | columnIndex++; |
305 | |
|
306 | 0 | if (clu.getCredits() != null && !clu.getCredits().trim().isEmpty()) { |
307 | 0 | HTML cluCreditsLabel = new HTML("<h5>" + clu.getCredits() + " credits" + "</h5>"); |
308 | 0 | detailsTable.setWidget(rowIndex, columnIndex, cluCreditsLabel); |
309 | 0 | detailsTable.getFlexCellFormatter().setColSpan(rowIndex, columnIndex, 1); |
310 | 0 | columnIndex++; |
311 | |
} |
312 | 0 | } |
313 | |
|
314 | |
private String translateSearchKey(String searchKey) { |
315 | 0 | String result = ""; |
316 | 0 | if (searchKey != null && searchKey.equals("lu.queryParam.luOptionalDivision")) { |
317 | 0 | result = "Department"; |
318 | 0 | } else if (searchKey != null && searchKey.equals("lu.queryParam.luOptionalCrsNoRange")) { |
319 | 0 | result = "Course Number Range"; |
320 | 0 | } else if (searchKey != null && searchKey.equals("lo.queryParam.loDescPlain")) { |
321 | 0 | result = "Description"; |
322 | 0 | } else if (searchKey != null && searchKey.equals("lu.queryParam.luOptionalEffectiveDate1")) { |
323 | 0 | result = "Effective From"; |
324 | 0 | } else if (searchKey != null && searchKey.equals("lu.queryParam.luOptionalEffectiveDate2")) { |
325 | 0 | result = "Effective To"; |
326 | 0 | } else if (searchKey != null && searchKey.equals("lu.queryParam.luOptionalEffectiveDate2")) { |
327 | |
|
328 | |
} |
329 | |
|
330 | 0 | return result; |
331 | |
} |
332 | |
|
333 | |
public CluSetInformation getCluSetInformation() { |
334 | 0 | return cluSetInformation; |
335 | |
} |
336 | |
|
337 | |
public void setCluSetInformation(CluSetInformation cluSetInformation) { |
338 | 0 | this.cluSetInformation = cluSetInformation; |
339 | 0 | } |
340 | |
|
341 | |
public String toString() { |
342 | 0 | return detailsTable.toString(); |
343 | |
} |
344 | |
|
345 | |
@Override |
346 | |
public boolean isExportElement() { |
347 | 0 | return true; |
348 | |
} |
349 | |
|
350 | |
@Override |
351 | |
public List<ExportElement> getExportElementSubset(ExportElement parent) { |
352 | 0 | List<CluInformation> items = this.cluSetInformation.getClus(); |
353 | 0 | ArrayList<ExportElement> subItems = new ArrayList<ExportElement>(); |
354 | 0 | for (int i = 0; i < items.size(); i++) { |
355 | 0 | ExportElement subelement = new ExportElement(parent.getViewName(), parent.getSectionName()); |
356 | 0 | subelement.setFieldValue("<b>" + items.get(i).getCode() + " " + items.get(i).getTitle() + "</b>"); |
357 | 0 | subelement.setFieldValue2(items.get(i).getCredits() + " credits"); |
358 | 0 | subelement.setPrintType(ExportElement.PROPOSAL); |
359 | 0 | subItems.add(subelement); |
360 | |
} |
361 | 0 | return subItems; |
362 | |
} |
363 | |
|
364 | |
@Override |
365 | |
public String getExportFieldValue() { |
366 | 0 | return null; |
367 | |
} |
368 | |
|
369 | |
} |