package fi.otavanopisto.pyramus.views.settings;
import java.util.List;
import java.util.Locale;
import fi.internetix.smvc.controllers.PageRequestContext;
import fi.otavanopisto.pyramus.I18N.Messages;
import fi.otavanopisto.pyramus.breadcrumbs.Breadcrumbable;
import fi.otavanopisto.pyramus.dao.DAOFactory;
import fi.otavanopisto.pyramus.dao.base.CurriculumDAO;
import fi.otavanopisto.pyramus.dao.grading.TransferCreditTemplateDAO;
import fi.otavanopisto.pyramus.domainmodel.base.Curriculum;
import fi.otavanopisto.pyramus.framework.PyramusViewController;
import fi.otavanopisto.pyramus.framework.UserRole;
import fi.otavanopisto.pyramus.util.JSONArrayExtractor;
/**
* The controller responsible of the List Grading Scales view of the application.
*/
public class ManageTransferCreditTemplatesViewController extends PyramusViewController implements Breadcrumbable {
/**
* Processes the page request by including the corresponding JSP page to the response.
*
* In order for the JSP page to build the view, all gradingScale objects are loaded in to "gradingScales" attribute
*
* @param pageRequestContext Page request context
*/
public void process(PageRequestContext pageRequestContext) {
TransferCreditTemplateDAO transferCreditTemplateDAO = DAOFactory.getInstance().getTransferCreditTemplateDAO();
CurriculumDAO curriculumDAO = DAOFactory.getInstance().getCurriculumDAO();
String jsonTransferCreditTemplates = new JSONArrayExtractor("name", "id").extractString(transferCreditTemplateDAO.listAll());
this.setJsDataVariable(pageRequestContext, "transferCreditTemplates", jsonTransferCreditTemplates);
List<Curriculum> curriculums = curriculumDAO.listUnarchived();
String jsonCurriculums = new JSONArrayExtractor("name", "id").extractString(curriculums);
setJsDataVariable(pageRequestContext, "curriculums", jsonCurriculums);
pageRequestContext.setIncludeJSP("/templates/settings/managetransfercredittemplates.jsp");
}
/**
* Returns the roles allowed to access this page.
*
* @return The roles allowed to access this page
*/
public UserRole[] getAllowedRoles() {
return new UserRole[] { UserRole.MANAGER, UserRole.STUDY_PROGRAMME_LEADER, UserRole.ADMINISTRATOR };
}
/**
* Returns the localized name of this page. Used e.g. for breadcrumb navigation.
*
* @param locale The locale to be used for the name
*
* @return The localized name of this page
*/
public String getName(Locale locale) {
return Messages.getInstance().getText(locale, "settings.manageTransferCreditTemplates.pageTitle");
}
}