001: package projectmanagement.presentation.worksheets;
002:
003: import projectmanagement.presentation.*;
004:
005: import projectmanagement.spec.*;
006: import projectmanagement.spec.timewage.*;
007: import projectmanagement.spec.project.*;
008: import projectmanagement.spec.employee.*;
009: import com.lutris.appserver.server.httpPresentation.*;
010: import org.enhydra.xml.xmlc.XMLObject;
011:
012: import org.w3c.dom.*;
013: import org.w3c.dom.html.*;
014:
015: import java.sql.Date;
016: import java.sql.Time;
017: import java.util.*;
018:
019: /**
020: * Manages all actions on worksheets.
021: *
022: * @author Sasa Bojanic
023: * @version 1.0
024: */
025: public class Edit extends BasePO {
026:
027: /**
028: * Constants
029: */
030: private static String EMPLOYEE = "cboEmployee";
031: private static String PROJECT = "cboProject";
032: private static String WORKING_DATE_YYYY = "txtWorkingDateYYYY";
033: private static String WORKING_DATE_MM = "txtWorkingDateMM";
034: private static String WORKING_DATE_DD = "txtWorkingDateDD";
035: private static String TIME_STARTED_hh = "txtTimeStartedhh";
036: private static String TIME_STARTED_mm = "txtTimeStartedmm";
037: private static String TIME_FINISHED_hh = "txtTimeFinishedhh";
038: private static String TIME_FINISHED_mm = "txtTimeFinishedmm";
039: private static String PERSONAL_COMMENT = "txtPersonalComment";
040: private static String COMMENT_FOR_CLIENT = "txtCommentForClient";
041:
042: private static String WORK_SHEET_ID = "workSheetID";
043: private static String SELECTED_EMPLOYEE_ID = "selectedEmployeeID";
044: private static String CONTEXT_PAGE = "Context.po";
045: private static String ADD = "add";
046: private static String DELETE = "delete";
047: private static String MODIFY = "modify";
048: private static String DETAILS = "showDetailsPage";
049: private static String POPULATE_PROJECTS = "populateProjects";
050: private static String IS_PERSONAL = "isPersonal";
051: private static String EVENT = "event";
052:
053: /**
054: * Superclass method override. Returns 1 or 2, depending on action.
055: */
056: protected int getRequiredAuthLevel() {
057: String isPersonal = "";
058: try {
059: isPersonal = this .getComms().request
060: .getParameter(IS_PERSONAL);
061: } catch (Exception ex) {
062: }
063:
064: if (isPersonal != null && isPersonal.equalsIgnoreCase("true")) {
065: return 1;
066: } else {
067: return 2;
068: }
069: }
070:
071: /**
072: * Default event. Just show the page for editing.
073: */
074: public XMLObject handleDefault() throws HttpPresentationException {
075: return showModifyPage(null, false);
076: }
077:
078: /**
079: * handle show add worksheet page event.
080: *
081: * @return html document
082: * @exception HttpPresentationException
083: */
084: public XMLObject handleShowAddPage()
085: throws HttpPresentationException {
086: return showAddPage(null);
087: }
088:
089: /**
090: * handle show details worksheet page event.
091: *
092: * @return html document
093: * @exception HttpPresentationException
094: */
095: public XMLObject handleShowDetailsPage()
096: throws HttpPresentationException {
097: return showModifyPage(null, true);
098: }
099:
100: /*
101: * Modifies an existing worksheet
102: *
103: * @return html document
104: * @exception HttpPresentationException
105: */
106: public XMLObject handleModify() throws HttpPresentationException {
107: String workSheetID = this .getComms().request
108: .getParameter(WORK_SHEET_ID);
109: WorkSheet workSheet = null;
110: // Try to get the worksheet by its ID
111: try {
112: WorkSheetManager workSheetManager = WorkSheetManagerFactory
113: .getWorkSheetManager("projectmanagement.business.timewage.WorkSheetManagerImpl");
114: workSheet = workSheetManager.findWorkSheetByID(workSheetID);
115:
116: } catch (Exception ex) {
117: this .getSessionData().setUserMessage(
118: "Please choose a valid worksheet to edit");
119: throw new ClientPageRedirectException(CONTEXT_PAGE);
120: }
121:
122: try {
123: saveWorkSheet(workSheet);
124: String isPersonal = "";
125: try {
126: isPersonal = this .getComms().request
127: .getParameter(IS_PERSONAL);
128: } catch (Exception ex) {
129: }
130: String redirectTo = CONTEXT_PAGE;
131: if (isPersonal != null
132: && isPersonal.equalsIgnoreCase("true")) {
133: redirectTo = redirectTo + "?isPersonal=true";
134: }
135: throw new ClientPageRedirectException(redirectTo);
136: } catch (Exception ex) {
137: return showModifyPage(
138: "To modify this worksheet, you must fill out fields properly!",
139: false);
140: }
141: }
142:
143: /*
144: * Adds a worksheet to the worksheet database
145: *
146: * @return html document
147: * @exception HttpPresentationException
148: */
149: public XMLObject handleAdd() throws HttpPresentationException {
150: try {
151: WorkSheetManager workSheetManager = WorkSheetManagerFactory
152: .getWorkSheetManager("projectmanagement.business.timewage.WorkSheetManagerImpl");
153: WorkSheet workSheet = workSheetManager.getWorkSheet();
154:
155: saveWorkSheet(workSheet);
156:
157: String isPersonal = "";
158: try {
159: isPersonal = this .getComms().request
160: .getParameter(IS_PERSONAL);
161: /*
162: * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run ProjectManagement_pres )
163: * We need to allow ProjectManagement_pres to be functional , response
164: * will be default HTML page
165: */
166: } catch (NullPointerException ex) {
167: return showAddPage("You cannot add works sheets while runing ProjectManagement_pres");
168:
169: } catch (Exception ex) {
170: }
171: String redirectTo = CONTEXT_PAGE;
172: if (isPersonal != null
173: && isPersonal.equalsIgnoreCase("true")) {
174: redirectTo = redirectTo + "?isPersonal=true";
175: }
176: throw new ClientPageRedirectException(redirectTo);
177:
178: } catch (Exception ex) {
179: return showAddPage("To add this worksheet, you must fill out fields properly!");
180: }
181: }
182:
183: /*
184: * Deletes a WorkSheet from the WorkSheet database
185: *
186: * @return html document
187: * @exception HttpPresentationException
188: */
189: public XMLObject handleDelete() throws HttpPresentationException,
190: ProjectManagementPresentationException {
191: String workSheetID = this .getComms().request
192: .getParameter(WORK_SHEET_ID);
193:
194: try {
195: WorkSheetManager workSheetManager = WorkSheetManagerFactory
196: .getWorkSheetManager("projectmanagement.business.timewage.WorkSheetManagerImpl");
197: WorkSheet workSheet = workSheetManager
198: .findWorkSheetByID(workSheetID);
199:
200: String workSheetName = "["
201: + workSheet.getPayRate().getEmployee()
202: .getFirstName()
203: + " "
204: + workSheet.getPayRate().getEmployee()
205: .getLastName() + ","
206: + workSheet.getPayRate().getProject().getName()
207: + "]";
208: workSheet.delete();
209: this .getSessionData()
210: .setUserMessage(
211: "The worksheet, " + workSheetName
212: + ", was deleted");
213: // Catch any possible database exception as well as the null pointer
214: // exception if the worksheet is not found and is null after findWorkSheetByID
215: } catch (Exception ex) {
216: this .getSessionData().setUserMessage(
217: "Please choose a valid worksheet to delete");
218: }
219:
220: String isPersonal = "";
221: try {
222: isPersonal = this .getComms().request
223: .getParameter(IS_PERSONAL);
224: } catch (Exception ex) {
225: }
226: String redirectTo = CONTEXT_PAGE;
227: if (isPersonal != null && isPersonal.equalsIgnoreCase("true")) {
228: redirectTo = redirectTo + "?isPersonal=true";
229: }
230: throw new ClientPageRedirectException(redirectTo);
231:
232: }
233:
234: /*
235: * Populates the projects combo based on the selected value of
236: * employee combo.
237: *
238: * @return html document
239: * @exception HttpPresentationException
240: */
241: public XMLObject handlePopulateProjects()
242: throws HttpPresentationException {
243: String workSheetID = this .getComms().request
244: .getParameter(WORK_SHEET_ID);
245: XMLObject page = showAddPage(null);
246: if (workSheetID != null && workSheetID.length() > 0) {
247: ((EditHTML) page).getElementWorkSheetID().setValue(
248: workSheetID);
249: ((EditHTML) page).getElementEvent().setValue(MODIFY);
250: }
251: return page;
252: }
253:
254: /**
255: * Produce HTML for this PO, populated by the worksheet information
256: * that the user wants to edit
257: *
258: * @param errorMsg, the error messages
259: * @param disabled, if controls are disabled
260: * @return html document
261: * @exception HttpPresentationException
262: */
263: public XMLObject showModifyPage(String errorMsg, boolean disabled)
264: throws HttpPresentationException,
265: ProjectManagementPresentationException {
266:
267: String employee = this .getComms().request
268: .getParameter(EMPLOYEE);
269: String project = this .getComms().request.getParameter(PROJECT);
270: String workingDateYYYY = this .getComms().request
271: .getParameter(WORKING_DATE_YYYY);
272: String workingDateMM = this .getComms().request
273: .getParameter(WORKING_DATE_MM);
274: String workingDateDD = this .getComms().request
275: .getParameter(WORKING_DATE_DD);
276: String timeStartedhh = this .getComms().request
277: .getParameter(TIME_STARTED_hh);
278: String timeStartedmm = this .getComms().request
279: .getParameter(TIME_STARTED_mm);
280: String timeFinishedhh = this .getComms().request
281: .getParameter(TIME_FINISHED_hh);
282: String timeFinishedmm = this .getComms().request
283: .getParameter(TIME_FINISHED_mm);
284: String personalComment = this .getComms().request
285: .getParameter(PERSONAL_COMMENT);
286: String commentForClient = this .getComms().request
287: .getParameter(COMMENT_FOR_CLIENT);
288:
289: String workSheetID = this .getComms().request
290: .getParameter(WORK_SHEET_ID);
291: // Instantiate the page object
292: EditHTML page = new EditHTML();
293:
294: WorkSheet workSheet = null;
295:
296: try {
297: WorkSheetManager workSheetManager = WorkSheetManagerFactory
298: .getWorkSheetManager("projectmanagement.business.timewage.WorkSheetManagerImpl");
299: workSheet = workSheetManager.findWorkSheetByID(workSheetID);
300: /*
301: * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run ProjectManagement_pres )
302: * We need to allow ProjectManagement_pres to be functional , response
303: * will be default HTML page
304: */
305:
306: } catch (NullPointerException ex) {
307: page.setTextErrorText("This is a default HTML page");
308: return page;
309: // Catch any possible database exception in findWorkSheetByID()
310: } catch (ProjectManagementException ex) {
311: this .getSessionData().setUserMessage(
312: "Please choose a valid worksheet to edit");
313: throw new ClientPageRedirectException(CONTEXT_PAGE);
314: }
315:
316: try {
317: // If we received a valid workSheetID then try to show the worksheet's contents,
318: // otherwise try to use the HTML input parameters
319: page.getElementWorkSheetID()
320: .setValue(workSheet.getHandle());
321:
322: HTMLSelectElement sel = page.getElementCboEmployee();
323: sel.setDisabled(disabled);
324:
325: if (null == employee || employee.length() == 0) {
326: employee = workSheet.getPayRate().getEmployee()
327: .getHandle();
328: }
329:
330: fillEmployeeSelection(page, sel, employee);
331:
332: sel = page.getElementCboProject();
333: if (null == project || project.length() == 0) {
334: project = workSheet.getPayRate().getProject()
335: .getHandle();
336: }
337: fillProjectSelection(page, sel, employee, project);
338: sel.setDisabled(disabled);
339:
340: HTMLInputElement el = page.getElementTxtWorkingDateYYYY();
341: el.setDisabled(disabled);
342: if (null != workingDateYYYY
343: && workingDateYYYY.length() != 0) {
344: el.setValue(workingDateYYYY);
345: } else {
346: Calendar cal = new GregorianCalendar();
347: cal.setTime(workSheet.getWorkingDate());
348: el.setValue(String.valueOf(cal.get(Calendar.YEAR)));
349: }
350:
351: el = page.getElementTxtWorkingDateMM();
352: el.setDisabled(disabled);
353: if (null != workingDateMM && workingDateMM.length() != 0) {
354: el.setValue(workingDateMM);
355: } else {
356: Calendar cal = new GregorianCalendar();
357: cal.setTime(workSheet.getWorkingDate());
358: el
359: .setValue(String.valueOf(cal
360: .get(Calendar.MONTH) + 1));
361: }
362:
363: el = page.getElementTxtWorkingDateDD();
364: el.setDisabled(disabled);
365: if (null != workingDateDD && workingDateDD.length() != 0) {
366: el.setValue(workingDateDD);
367: } else {
368: Calendar cal = new GregorianCalendar();
369: cal.setTime(workSheet.getWorkingDate());
370: el.setValue(String.valueOf(cal
371: .get(Calendar.DAY_OF_MONTH)));
372: }
373:
374: el = page.getElementTxtTimeStartedhh();
375: el.setDisabled(disabled);
376: if (null != timeStartedhh && timeStartedhh.length() != 0) {
377: el.setValue(timeStartedhh);
378: } else {
379: Calendar cal = new GregorianCalendar();
380: cal.setTime(workSheet.getTimeStarted());
381: el.setValue(String.valueOf(cal
382: .get(Calendar.HOUR_OF_DAY)));
383: }
384:
385: el = page.getElementTxtTimeStartedmm();
386: el.setDisabled(disabled);
387: if (null != timeStartedmm && timeStartedmm.length() != 0) {
388: el.setValue(timeStartedmm);
389: } else {
390: Calendar cal = new GregorianCalendar();
391: cal.setTime(workSheet.getTimeStarted());
392: el.setValue(String.valueOf(cal.get(Calendar.MINUTE)));
393: }
394:
395: el = page.getElementTxtTimeFinishedhh();
396: el.setDisabled(disabled);
397: if (null != timeFinishedhh && timeFinishedhh.length() != 0) {
398: el.setValue(timeFinishedhh);
399: } else {
400: Calendar cal = new GregorianCalendar();
401: cal.setTime(workSheet.getTimeFinished());
402: el.setValue(String.valueOf(cal
403: .get(Calendar.HOUR_OF_DAY)));
404: }
405:
406: el = page.getElementTxtTimeFinishedmm();
407: el.setDisabled(disabled);
408: if (null != timeFinishedmm && timeFinishedmm.length() != 0) {
409: el.setValue(timeFinishedmm);
410: } else {
411: Calendar cal = new GregorianCalendar();
412: cal.setTime(workSheet.getTimeFinished());
413: el.setValue(String.valueOf(cal.get(Calendar.MINUTE)));
414: }
415:
416: //HTMLTextAreaElement tael=page.getElementTxtPersonalComment();
417: el = page.getElementTxtPersonalComment();
418: el.setDisabled(disabled);
419: if (null != personalComment
420: && personalComment.length() != 0) {
421: el.setValue(personalComment);
422: } else {
423: el.setValue(workSheet.getPersonalComment());
424: }
425:
426: el = page.getElementTxtCommentForClient();
427: el.setDisabled(disabled);
428: if (null != commentForClient
429: && commentForClient.length() != 0) {
430: el.setValue(commentForClient);
431: } else {
432: el.setValue(workSheet.getCommentForClient());
433: }
434:
435: el = page.getElementBtnSave();
436: el.setDisabled(disabled);
437:
438: if (null == errorMsg) {
439: page.getElementErrorText().getParentNode().removeChild(
440: page.getElementErrorText());
441: } else {
442: page.setTextErrorText(errorMsg);
443: }
444: } catch (ProjectManagementException ex) {
445: throw new ProjectManagementPresentationException(
446: "Error populating page for worksheet editing", ex);
447: }
448:
449: page.getElementEvent().setValue(MODIFY);
450: return page;
451: }
452:
453: /**
454: * Produce HTML for this PO
455: *
456: * @param errorMsg, the error messages
457: * @return html document
458: * @exception HttpPresentationException
459: */
460: public XMLObject showAddPage(String errorMsg)
461: throws HttpPresentationException,
462: ProjectManagementPresentationException {
463: // Instantiate the page object
464: EditHTML page = new EditHTML();
465: try {
466: String employee = this .getComms().request
467: .getParameter(EMPLOYEE);
468: String project = this .getComms().request
469: .getParameter(PROJECT);
470: String workingDateYYYY = this .getComms().request
471: .getParameter(WORKING_DATE_YYYY);
472: String workingDateMM = this .getComms().request
473: .getParameter(WORKING_DATE_MM);
474: String workingDateDD = this .getComms().request
475: .getParameter(WORKING_DATE_DD);
476: String timeStartedhh = this .getComms().request
477: .getParameter(TIME_STARTED_hh);
478: String timeStartedmm = this .getComms().request
479: .getParameter(TIME_STARTED_mm);
480: String timeFinishedhh = this .getComms().request
481: .getParameter(TIME_FINISHED_hh);
482: String timeFinishedmm = this .getComms().request
483: .getParameter(TIME_FINISHED_mm);
484: String personalComment = this .getComms().request
485: .getParameter(PERSONAL_COMMENT);
486: String commentForClient = this .getComms().request
487: .getParameter(COMMENT_FOR_CLIENT);
488:
489: // set the worksheet id value to empty str
490: page.getElementWorkSheetID().setValue("");
491:
492: HTMLSelectElement sel = page.getElementCboEmployee();
493: fillEmployeeSelection(page, sel, employee);
494:
495: if (employee == null) {
496: sel.setSelectedIndex(0);
497: HTMLOptionElement sopt = (HTMLOptionElement) sel
498: .getOptions().item(0);
499: if (sopt != null) {
500: employee = sopt.getValue();
501: }
502: }
503:
504: sel = page.getElementCboProject();
505: fillProjectSelection(page, sel, employee, project);
506:
507: Calendar cal = new GregorianCalendar();
508: HTMLInputElement el = page.getElementTxtWorkingDateYYYY();
509: if (null != workingDateYYYY) {
510: el.setValue(workingDateYYYY);
511: } else {
512: el.setValue(String.valueOf(cal.get(Calendar.YEAR)));
513: }
514:
515: el = page.getElementTxtWorkingDateMM();
516: if (null != workingDateMM) {
517: el.setValue(workingDateMM);
518: } else {
519: el
520: .setValue(String.valueOf(cal
521: .get(Calendar.MONTH) + 1));
522: }
523:
524: el = page.getElementTxtWorkingDateDD();
525: if (null != workingDateDD) {
526: el.setValue(workingDateDD);
527: } else {
528: el.setValue(String.valueOf(cal
529: .get(Calendar.DAY_OF_MONTH)));
530: }
531:
532: el = page.getElementTxtTimeStartedhh();
533: if (null != timeStartedhh) {
534: el.setValue(timeStartedhh);
535: } else {
536: el.setValue("");
537: }
538:
539: el = page.getElementTxtTimeStartedmm();
540: if (null != timeStartedmm) {
541: el.setValue(timeStartedmm);
542: } else {
543: el.setValue("");
544: }
545:
546: el = page.getElementTxtTimeFinishedhh();
547: if (null != timeFinishedhh) {
548: el.setValue(timeFinishedhh);
549: } else {
550: el.setValue("");
551: }
552:
553: el = page.getElementTxtTimeFinishedmm();
554: if (null != timeFinishedmm) {
555: el.setValue(timeFinishedmm);
556: } else {
557: el.setValue("");
558: }
559:
560: //HTMLTextAreaElement tael=page.getElementTxtPersonalComment();
561: el = page.getElementTxtPersonalComment();
562: if (null != personalComment) {
563: el.setValue(personalComment);
564: } else {
565: el.setValue("");
566: }
567: el = page.getElementTxtCommentForClient();
568: if (null != commentForClient) {
569: el.setValue(commentForClient);
570: } else {
571: el.setValue("");
572: }
573:
574: if (null == errorMsg) {
575: page.getElementErrorText().getParentNode().removeChild(
576: page.getElementErrorText());
577: } else {
578: page.setTextErrorText(errorMsg);
579: }
580: } catch (NullPointerException e) {
581: page.setTextErrorText(errorMsg);
582: }
583: return page;
584: }
585:
586: /**
587: * Method to save a new or existing worksheet to the database
588: *
589: * @param workSheet, the worksheet to be saved
590: * @return html document
591: * @exception HttpPresentationException
592: */
593: protected void saveWorkSheet(WorkSheet theWorkSheet)
594: throws HttpPresentationException, NullPointerException {
595:
596: String employee = this .getComms().request
597: .getParameter(EMPLOYEE);
598: String project = this .getComms().request.getParameter(PROJECT);
599: String workingDateYYYY = this .getComms().request
600: .getParameter(WORKING_DATE_YYYY);
601: String workingDateMM = this .getComms().request
602: .getParameter(WORKING_DATE_MM);
603: String workingDateDD = this .getComms().request
604: .getParameter(WORKING_DATE_DD);
605: String timeStartedhh = this .getComms().request
606: .getParameter(TIME_STARTED_hh);
607: String timeStartedmm = this .getComms().request
608: .getParameter(TIME_STARTED_mm);
609: String timeFinishedhh = this .getComms().request
610: .getParameter(TIME_FINISHED_hh);
611: String timeFinishedmm = this .getComms().request
612: .getParameter(TIME_FINISHED_mm);
613: String personalComment = this .getComms().request
614: .getParameter(PERSONAL_COMMENT);
615: String commentForClient = this .getComms().request
616: .getParameter(COMMENT_FOR_CLIENT);
617:
618: if (isNullField(employee)
619: || isNullField(project)
620: || !areDateFieldsValid(workingDateYYYY, workingDateMM,
621: workingDateDD)
622: || !areTimeFieldsValid(timeStartedhh, timeStartedmm)
623: || !areTimeFieldsValid(timeFinishedhh, timeFinishedmm)) {
624: throw new ProjectManagementPresentationException(
625: "Error adding worksheet", new Exception());
626: }
627:
628: try {
629: String workingDate = workingDateYYYY + "-" + workingDateMM
630: + "-" + workingDateDD;
631: String timeStarted = timeStartedhh + ":" + timeStartedmm
632: + ":" + "00";
633: String timeFinished = timeFinishedhh + ":" + timeFinishedmm
634: + ":" + "00";
635:
636: PayRateManager payRateManager = PayRateManagerFactory
637: .getPayRateManager("projectmanagement.business.timewage.PayRateManagerImpl");
638: PayRate payRate = payRateManager
639: .findPayRateByEmployeeProjectAndDate(employee,
640: project, Date.valueOf(workingDate));
641:
642: theWorkSheet.setPayRate(payRate);
643: theWorkSheet.setWorkingDate(Date.valueOf(workingDate));
644: Time ts = Time.valueOf(timeStarted);
645: Time tf = Time.valueOf(timeFinished);
646: if (tf.getTime() < ts.getTime()) {
647: throw new ProjectManagementPresentationException(
648: "Error adding worksheet - times are not properly set",
649: null);
650: }
651: theWorkSheet.setTimeStarted(ts);
652: theWorkSheet.setTimeFinished(tf);
653: theWorkSheet.setPersonalComment(personalComment);
654: theWorkSheet.setCommentForClient(commentForClient);
655:
656: theWorkSheet.save();
657: } catch (NullPointerException ex) {
658: throw new NullPointerException();
659: } catch (Exception ex) {
660: throw new ProjectManagementPresentationException(
661: "Error adding worksheet", ex);
662: }
663: }
664:
665: private void fillEmployeeSelection(EditHTML page,
666: HTMLSelectElement cboEmployees, String selectedEmployeeID)
667: throws ProjectManagementPresentationException {
668:
669: String isPersonal = "";
670: try {
671: isPersonal = this .getComms().request
672: .getParameter(IS_PERSONAL);
673: } catch (Exception ex) {
674: }
675: if (isPersonal != null && isPersonal.equalsIgnoreCase("true")) {
676: HTMLInputElement ip = page.getElementIsPersonal();
677: ip.setValue("true");
678: HTMLAnchorElement a = page.getElementAncContext();
679: a.setHref("Context.po?isPersonal=true");
680: try {
681: selectedEmployeeID = getUser().getHandle();
682: } catch (Exception ex) {
683: }
684: }
685:
686: HTMLOptionElement optEmployee = page.getElementOptEmployee();
687: // Remove the dummy storyboard text from the prototype HTML
688: optEmployee.removeChild(optEmployee.getFirstChild());
689:
690: try {
691: EmployeeManager employeeManager = EmployeeManagerFactory
692: .getEmployeeManager("projectmanagement.business.employee.EmployeeManagerImpl");
693: Employee[] employees = employeeManager.getAllEmployees();
694: if (employees != null) {
695: for (int i = 0; i < employees.length; i++) {
696: Employee e = employees[i];
697: // if this is personal, fill the combo only with that employ
698: if (isPersonal != null
699: && isPersonal.equalsIgnoreCase("true")
700: && !e.getHandle()
701: .equals(selectedEmployeeID)) {
702: continue;
703: }
704: // Now populate the combo with employees
705: // This algorithm is obscure because options
706: // are not normal HTML elements
707: // First populate the option value (the employee database ID).
708: // Then append a text child as the option
709: // text, which is what is displayed as the text
710: // in each row of the select box
711: HTMLOptionElement clonedOption = (HTMLOptionElement) optEmployee
712: .cloneNode(true);
713: clonedOption.setValue(e.getHandle());
714: Node optionTextNode = clonedOption
715: .getOwnerDocument().createTextNode(
716: e.getFirstName() + " "
717: + e.getLastName());
718: clonedOption.appendChild(optionTextNode);
719: if (e.getHandle().equals(selectedEmployeeID)) {
720: clonedOption.setAttribute("selected",
721: "selected");
722: }
723: // Do only a shallow copy of the option as we don't want the text child
724: // of the node option
725: cboEmployees.appendChild(clonedOption);
726: // Alternative way to insert nodes below
727: // insertBefore(newNode, oldNode);
728: // discSelect.insertBefore(clonedOption, templateOption);
729: }
730: }
731: cboEmployees.removeChild(optEmployee);
732:
733: } catch (NullPointerException ex) {
734: } catch (Exception ex) {
735: this .writeDebugMsg("Error populating list of employees: "
736: + ex);
737: throw new ProjectManagementPresentationException(
738: "Error populating employee list: ", ex);
739: }
740:
741: }
742:
743: private void fillProjectSelection(EditHTML page,
744: HTMLSelectElement cboProjects, String selectedEmployeeID,
745: String selectedProjectID)
746: throws ProjectManagementPresentationException {
747:
748: HTMLOptionElement optProject = page.getElementOptProject();
749: // Remove the dummy storyboard text from the prototype HTML
750: optProject.removeChild(optProject.getFirstChild());
751:
752: try {
753: PayRate[] payRates;
754: PayRateManager payRateManager = PayRateManagerFactory
755: .getPayRateManager("projectmanagement.business.timewage.PayRateManagerImpl");
756:
757: if (selectedEmployeeID == null) {
758: payRates = payRateManager.getAllPayRates();
759: } else {
760: payRates = payRateManager.getAllPayRatesForEmployee(
761: selectedEmployeeID, true);
762: }
763: if (payRates != null) {
764: for (int i = 0; i < payRates.length; i++) {
765: Project p = payRates[i].getProject();
766: // Now populate the combo with projects
767: // This algorithm is obscure because options
768: // are not normal HTML elements
769: // First populate the option value (the project database ID).
770: // Then append a text child as the option
771: // text, which is what is displayed as the text
772: // in each row of the select box
773: HTMLOptionElement clonedOption = (HTMLOptionElement) optProject
774: .cloneNode(true);
775: clonedOption.setValue(p.getHandle());
776: Node optionTextNode = clonedOption
777: .getOwnerDocument().createTextNode(
778: p.getName());
779: clonedOption.appendChild(optionTextNode);
780: if (p.getHandle().equals(selectedProjectID)) {
781: clonedOption.setAttribute("selected",
782: "selected");
783: }
784: // Do only a shallow copy of the option as we don't want the text child
785: // of the node option
786: cboProjects.appendChild(clonedOption);
787: // Alternative way to insert nodes below
788: // insertBefore(newNode, oldNode);
789: // discSelect.insertBefore(clonedOption, templateOption);
790: }
791: }
792: cboProjects.removeChild(optProject);
793: } catch (NullPointerException ex) {
794: } catch (Exception ex) {
795: ex.printStackTrace();
796: this .writeDebugMsg("Error populating list of projects: "
797: + ex);
798: throw new ProjectManagementPresentationException(
799: "Error populating project list: ", ex);
800: }
801:
802: }
803:
804: private boolean areTimeFieldsValid(String hh, String mm) {
805: if (isNullField(hh) || isNullField(mm)) {
806: return false;
807: }
808: try {
809: int h = Integer.valueOf(hh).intValue();
810: int m = Integer.valueOf(mm).intValue();
811: if (h < 0 || h > 23 || m < 0 || m > 59) {
812: return false;
813: }
814: } catch (Exception ex) {
815: return false;
816: }
817: return true;
818: }
819: }
|