View Javadoc

1   package org.kuali.student.lum.lu.ui.course.client.configuration;
2   
3   import org.kuali.student.common.dto.DtoConstants;
4   import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle;
5   import org.kuali.student.common.ui.client.configurable.mvc.layouts.MenuSectionController;
6   import org.kuali.student.common.ui.client.configurable.mvc.sections.RequiredContainer;
7   import org.kuali.student.common.ui.client.configurable.mvc.sections.Section;
8   import org.kuali.student.common.ui.client.configurable.mvc.sections.VerticalSection;
9   import org.kuali.student.common.ui.client.configurable.mvc.views.VerticalSectionView;
10  import org.kuali.student.common.ui.client.mvc.Callback;
11  import org.kuali.student.common.ui.client.mvc.Controller;
12  import org.kuali.student.common.ui.client.mvc.DataModelDefinition;
13  import org.kuali.student.common.ui.client.mvc.View;
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.core.comments.ui.client.widgets.commenttool.CommentTool;
17  import org.kuali.student.core.comments.ui.client.widgets.commenttool.CommentTool.EditMode;
18  import org.kuali.student.core.document.ui.client.widgets.documenttool.DocumentTool;
19  import org.kuali.student.lum.common.client.lu.LUUIConstants;
20  import org.kuali.student.lum.lu.ui.course.client.controllers.CourseAdminController;
21  import org.kuali.student.lum.lu.ui.course.client.controllers.CourseProposalController;
22  import org.kuali.student.lum.lu.ui.course.client.requirements.CourseRequirementsViewController;
23  
24  import com.google.gwt.core.client.GWT;
25  import com.google.gwt.event.dom.client.ClickEvent;
26  import com.google.gwt.event.dom.client.ClickHandler;
27  import com.google.gwt.user.client.ui.Composite;
28  
29  
30  /**
31   * This is the screen configuration and layout for the create/modify admin screens
32   * 
33   * @author Will
34   *
35   */
36  public class CourseAdminConfigurer extends CourseProposalConfigurer{
37  
38      protected CourseRequirementsViewController requisitesSection;
39  
40      private RequiredContainer requiredContainer = new RequiredContainer();
41   
42  
43      /**
44       * Sets up all the views, sections, and views of the CourseAdminController.  This should be called
45       * once for initialization and setup per CourseAdminController instance.
46       * 
47       * @param layout
48       */
49      public void configure(final CourseProposalController layout) {
50      	type = "course";
51          state = DtoConstants.STATE_DRAFT;
52          nextState = DtoConstants.STATE_ACTIVE;
53          
54      	groupName = LUUIConstants.COURSE_GROUP_NAME;
55  
56          layout.addContentWidget(layout.getWfUtilities().getProposalStatusLabel());
57          if (modelDefinition.getMetadata().isCanEdit()) {
58              layout.addInfoWidget(requiredContainer);
59              layout.addView(generateCourseAdminView((CourseAdminController) layout));
60          } else {
61              CourseSummaryConfigurer summaryConfigurer = GWT.create(CourseSummaryConfigurer.class);
62              summaryConfigurer.init(type, state, groupName, (DataModelDefinition) modelDefinition, stmtTypes, (Controller) layout, COURSE_PROPOSAL_MODEL);
63              layout.removeMenuNavigation();
64              layout.addView(summaryConfigurer.generateProposalSummarySection(false));
65              final CommentTool commentTool = createCommentTool(layout);
66              commentTool.setEditMode(EditMode.VIEW_COMMENT);
67          }
68      }
69  
70  	/**
71  	 * Configuration for the course admin screens
72  	 * 
73  	 * @return view 
74  	 */
75      protected View generateCourseAdminView(final CourseAdminController layout) {
76          VerticalSectionView view = 
77          	new VerticalSectionView(CourseSections.COURSE_INFO, getLabel(LUUIConstants.INFORMATION_LABEL_KEY), COURSE_PROPOSAL_MODEL, false);
78          view.addStyleName(LUUIConstants.STYLE_SECTION);
79  
80          // Create course admin sections
81          Section courseSection = generateCourseInfoSection(initSection(LUUIConstants.INFORMATION_LABEL_KEY)); 
82          Section governanceSection = generateGovernanceSection(initSection(LUUIConstants.GOVERNANCE_LABEL_KEY));
83          Section logisticsSection = generateCourseLogisticsSection(initSection(LUUIConstants.LOGISTICS_LABEL_KEY));
84          Section loSection = initSection(LUUIConstants.LEARNING_OBJECTIVES_LABEL_KEY);
85          loSection.addSection(generateLearningObjectivesNestedSection());
86          Section activeDatesSection = generateActiveDatesSection(initSection(LUUIConstants.ACTIVE_DATES_LABEL_KEY));
87          Section financialSection = generateFinancialsSection(initSection(LUUIConstants.FINANCIALS_LABEL_KEY));
88          
89          //Create the requisite section
90          requisitesSection = new CourseRequirementsViewController(layout, getLabel(LUUIConstants.REQUISITES_LABEL_KEY), CourseSections.COURSE_REQUISITES, false, false);
91  
92          //Create the document upload section
93          
94          documentTool = new DocumentTool(LUUIConstants.REF_DOC_RELATION_PROPOSAL_TYPE,CourseSections.DOCUMENTS, getLabel(LUUIConstants.TOOL_DOCUMENTS_LABEL_KEY));
95          documentTool.setModelDefinition((DataModelDefinition)modelDefinition);
96          documentTool.setController(layout);
97          documentTool.setTitle(getLabel(LUUIConstants.TOOL_DOCUMENTS_LABEL_KEY));
98          documentTool.addStyleName(LUUIConstants.STYLE_SECTION);
99  
100         createCommentTool(layout);
101 
102         
103         //Add course admin sections to view
104         view.addSection(courseSection);
105         view.addSection(governanceSection);
106         view.addSection(logisticsSection);
107         view.addSection(loSection);
108         view.addSection(this.createHiddenRequisitesSection());
109         view.addView(requisitesSection);
110         view.addSection(LUUIConstants.ACTIVE_DATES_LABEL_KEY,activeDatesSection);
111         view.addSection(financialSection);
112         view.addView(documentTool);
113         
114         //Add menu items for sections
115         String sections = getLabel(LUUIConstants.COURSE_SECTIONS);
116         layout.addMenu(sections);
117         layout.addMenuItemSection(sections, getLabel(LUUIConstants.INFORMATION_LABEL_KEY), LUUIConstants.INFORMATION_LABEL_KEY, courseSection.getLayout());
118         layout.addMenuItemSection(sections, getLabel(LUUIConstants.GOVERNANCE_LABEL_KEY), LUUIConstants.GOVERNANCE_LABEL_KEY, governanceSection.getLayout());
119         layout.addMenuItemSection(sections, getLabel(LUUIConstants.LOGISTICS_LABEL_KEY), LUUIConstants.LOGISTICS_LABEL_KEY, logisticsSection.getLayout());
120         layout.addMenuItemSection(sections, getLabel(LUUIConstants.LEARNING_OBJECTIVE_LABEL_KEY), LUUIConstants.LEARNING_OBJECTIVE_LABEL_KEY, loSection.getLayout());
121         layout.addMenuItemSection(sections, getLabel(LUUIConstants.REQUISITES_LABEL_KEY), LUUIConstants.REQUISITES_LABEL_KEY, requisitesSection);
122         layout.addMenuItemSection(sections, getLabel(LUUIConstants.ACTIVE_DATES_LABEL_KEY), LUUIConstants.ACTIVE_DATES_LABEL_KEY, activeDatesSection.getLayout());
123         layout.addMenuItemSection(sections, getLabel(LUUIConstants.FINANCIALS_LABEL_KEY), LUUIConstants.FINANCIALS_LABEL_KEY, financialSection.getLayout());
124         layout.addMenuItemSection(sections, getLabel(LUUIConstants.TOOL_DOCUMENTS_LABEL_KEY), LUUIConstants.TOOL_DOCUMENTS_LABEL_KEY, documentTool);
125         
126         //Add buttons to top and bottom of view
127         layout.addButtonForView(CourseSections.COURSE_INFO, layout.getApproveAndActivateButton());
128         layout.addButtonForView(CourseSections.COURSE_INFO, layout.getSaveButton());
129         layout.addButtonForView(CourseSections.COURSE_INFO, layout.getCancelButton());
130         layout.addTopButtonForView(CourseSections.COURSE_INFO, layout.getApproveAndActivateButton());
131         layout.addTopButtonForView(CourseSections.COURSE_INFO, layout.getSaveButton());
132         layout.addTopButtonForView(CourseSections.COURSE_INFO, layout.getCancelButton());
133 
134         // Setup show/hide non-required fields configuration.
135         this.addDocToolLink();
136         requiredContainer.setMainSection(view);
137 
138         return view;
139     }
140 
141     private CommentTool createCommentTool(final MenuSectionController layout) {
142         //Create and add the comment tool
143         final CommentTool commentTool = new CommentTool(CourseSections.COMMENTS, getLabel(LUUIConstants.TOOL_COMMENTS_LABEL_KEY), "kuali.comment.type.generalRemarks", "Proposal Comments");
144         commentTool.setController(layout);        
145         layout.addContentWidget(new KSButton("Comments", ButtonStyle.DEFAULT_ANCHOR, new ClickHandler() {
146             
147             @Override
148             public void onClick(ClickEvent event) {
149                 commentTool.show();
150             }
151         }));
152         return commentTool;
153     }
154     
155     /**
156      * Gets the requisite view associated with the CourseAdminConfigurer
157      * 
158      * @param layout
159      * @return The requisite view used by this configurer
160      */
161     public CourseRequirementsViewController getRequisitesSection() {
162     	return requisitesSection;
163 	}
164     
165     /**
166      * Gets the Document Tool View associated with the CourseAdminConfigurer
167      * 
168      * @param layout
169      * @return The DocumentTool used by this configurer
170      */
171     public DocumentTool getDocumentTool() {
172         return documentTool;
173     }
174 
175     protected VerticalSection initSection(String labelKey) {
176         final VerticalSection section = initSection(SectionTitle.generateH2Title(getLabel(labelKey)), NO_DIVIDER);
177         // Add Show All Link on the sections.
178         section.addShowAllLink(requiredContainer.createShowAllLink(new ClickHandler() {
179 
180             @Override
181             public void onClick(ClickEvent event) {
182                 requiredContainer.processInnerSection(section, true);
183                 section.getShowAllLink().setVisible(false);
184             }
185         }));
186 
187         return section;
188     }
189     
190     private VerticalSection createHiddenRequisitesSection() {
191         final VerticalSection section = initSection(SectionTitle.generateH2Title(getLabel(LUUIConstants.REQUISITES_LABEL_KEY)), NO_DIVIDER);
192         // Add Show All Link on the sections.
193         section.addShowAllLink(requiredContainer.createShowAllLink(new ClickHandler() {
194 
195             @Override
196             public void onClick(ClickEvent event) {
197                 requisitesSection.asWidget().setVisible(true);
198                 section.getLayout().setVisible(false);
199                 section.setSectionId(LUUIConstants.REQUISITES_LABEL_KEY + "_Hidden");
200             }
201         }));
202         
203         // Setup show/hide non-required fields configuration.
204         requiredContainer.addCallback(new Callback<Boolean>() {
205 
206             @Override
207             public void exec(Boolean result) {
208                 requisitesSection.asWidget().setVisible(result);
209                 section.getLayout().setVisible(!result);
210                 if (result) {
211                     section.setSectionId(LUUIConstants.REQUISITES_LABEL_KEY + "_Hidden");
212                 } else {
213                     section.setSectionId(LUUIConstants.REQUISITES_LABEL_KEY);
214                 }
215             }
216         });
217         return section;
218     }
219     
220     private void addDocToolLink(){
221         Composite container = requiredContainer.createShowAllLink(new ClickHandler() {
222 
223             @Override
224             public void onClick(ClickEvent event) {
225                 documentTool.showShowAllLink(false);
226             }
227         });
228         
229         // Setup show/hide non-required fields configuration.
230         requiredContainer.addCallback(new Callback<Boolean>() {
231 
232             @Override
233             public void exec(Boolean result) {
234                 documentTool.showShowAllLink(!result);
235             }
236         });
237         documentTool.setShowAllLink(container);
238     }
239 }