--- /dev/null
+(function() {
+ "use strict";
+
+ angular
+ .module("nero.app.cdt")
+ .factory("cdtProperties", cdtProperties);
+
+ cdtProperties.$inject = ["panelService", "profileService", "sessionService"];
+
+ function cdtProperties(panelService, profileService, sessionService) {
+
+ var properties = {
+ onlyMySessions: false,
+ selectedClass: {},
+ classIds: [],
+ teacherIds: [],
+ selectedUser: {},
+ selectedSession: {},
+ selectedSessionElement: {},
+ selectedWeekNumber: undefined,
+ clipboard: {},
+ homeworkStartDate: "",
+ homeworkEndDate: ""
+ };
+
+ var userProperties = {
+ currentUserId: -1,
+ isEditor: false
+ };
+
+ var viewProperties = {
+ schoolConfigEnabled: undefined,
+ calendarConfig: {}
+ };
+
+ var homeworkSelected = {
+ homeworkId : 0,
+ targetDate : ""
+ }
+
+ return {
+ setClassIds: setClassIds,
+ getClassIds: getClassIds,
+ setTeacherIds: setTeacherIds,
+ getTeacherIds: getTeacherIds,
+ setSelectedClass: setSelectedClass,
+ getSelectedClass: getSelectedClass,
+ setSelectedUser: setSelectedUser,
+ getSelectedUser: getSelectedUser,
+ setCurrentUserId: setCurrentUserId,
+ getCurrentUserId: getCurrentUserId,
+ getCurrentUserProfile: getCurrentUserProfile,
+ setOnlyMySessions: setOnlyMySessions,
+ getOnlyMySessions: getOnlyMySessions,
+ setSelectedSession: setSelectedSession,
+ getSelectedSession: getSelectedSession,
+ setSelectedSessionElement: setSelectedSessionElement,
+ getSelectedSessionElement: getSelectedSessionElement,
+ getSelectedWeekNumber: getSelectedWeekNumber,
+ setSelectedWeekNumber: setSelectedWeekNumber,
+ getIsEditor: getIsEditor,
+ getCalendarConfig: getCalendarConfig,
+ setSchoolConfigEnabled: setSchoolConfigEnabled,
+ getSchoolConfigEnabled: getSchoolConfigEnabled,
+ setClipboard: setClipboard,
+ getClipboard: getClipboard,
+ setHomeworkStartDate: setHomeworkStartDate,
+ getHomeworkStartDate: getHomeworkStartDate,
+ setHomeworkEndDate: setHomeworkEndDate,
+ getHomeworkEndDate: getHomeworkEndDate,
+ setHomeworkSelectedId: setHomeworkSelectedId,
+ getHomeworkSelectedId: getHomeworkSelectedId,
+ setHomeworkSelectedTargetDate: setHomeworkSelectedTargetDate,
+ getHomeworkSelectedTargetDate: getHomeworkSelectedTargetDate
+ };
+
+ /*
+ Set user's class id list
+ */
+ function setClassIds(classIds) {
+ properties.classIds = classIds;
+ }
+
+ /*
+ Get user's class id list (Use to load sessions)
+ */
+ function getClassIds() {
+ return properties.classIds;
+ }
+
+ /*
+ Set teacher id list
+ */
+ function setTeacherIds(teacherIds) {
+ properties.teacherIds = teacherIds;
+ }
+
+ /*
+ Get teacher id list (Use to load sessions)
+ */
+ function getTeacherIds() {
+ return properties.teacherIds;
+ }
+
+ /*
+ Set the current selected class in the filter
+ */
+ function setSelectedClass(selectedClass) {
+ properties.selectedClass = selectedClass;
+ }
+
+ /*
+ Get the current selected class in the filter
+ */
+ function getSelectedClass() {
+ return properties.selectedClass;
+ }
+
+ /*
+ Set the current selected user in the filter (teacher or child)
+ */
+ function setSelectedUser(selectedUser) {
+ properties.selectedUser = selectedUser;
+ }
+
+ /*
+ Get the current selected user in the filter (teacher or child)
+ */
+ function getSelectedUser() {
+ return properties.selectedUser;
+ }
+
+ /*
+ Set current online user id
+ */
+ function setCurrentUserId(userId) {
+ userProperties.currentUserId = userId;
+ }
+
+ /*
+ Return current online user id
+ */
+ function getCurrentUserId() {
+ return userProperties.currentUserId;
+ }
+
+ /*
+ Set selected session
+ If the it is a summary session then we get the hole session from back-end
+ */
+ function setSelectedSession(session, isSummarySession, profile, isPersonalGroup) {
+ //TODO Admin role ?
+ properties.selectedSession.sessionId = session.sessionId;
+ if (isSummarySession) {
+ var studentId = undefined;
+ if (getSelectedUser() != undefined) {
+ studentId = getSelectedUser().userId;
+ }
+ sessionService.getSession(session.sessionId, profile, (session.isPersonalGroup || isPersonalGroup), studentId)
+ .then(function(data) {
+ manageNewSelectedSession(data);
+ var showSessionPanel = true;
+ panelService.enableSessionPanel(showSessionPanel);
+ })
+ //Catch error in view to display the toastr
+ } else {
+ manageNewSelectedSession(session);
+ var showSessionPanel = true;
+ panelService.enableSessionPanel(showSessionPanel);
+ }
+ }
+
+ /*
+ Set selected session and the editor mode
+ Cleared the descriptions and session details if not publish
+ */
+ function manageNewSelectedSession(session) {
+ setIsEditor( (session.isCurrentUserTeacher && !session.hasVisa) );
+ if (!getIsEditor() && !session.isPublish) {
+ session.title = "";
+ session.description = "";
+ session.attachFiles = [];
+ session.isCourse = false;
+ session.isTD = false;
+ session.isTP = false;
+ session.isTest = false;
+ session.isDS = false;
+ }
+ properties.selectedSession = session;
+ }
+
+ /*
+ Return the current selected session
+ */
+ function getSelectedSession() {
+ return properties.selectedSession;
+ }
+
+ /*
+ Set the current selected session (dom) element
+ */
+ function setSelectedSessionElement(element) {
+ if (properties.selectedSessionElement.className != undefined) {
+ var cssClasses = properties.selectedSessionElement.className;
+ properties.selectedSessionElement.className = cssClasses.replace(/ selected-event/g, "");
+ }
+ element.className += " selected-event";
+ properties.selectedSessionElement = element;
+ }
+
+ /*
+ Return the current selected session (dom) element
+ */
+ function getSelectedSessionElement() {
+ return properties.selectedSessionElement;
+ }
+
+ /**
+ Set the current se
+ */
+ function setSelectedWeekNumber(weekNumber) {
+ properties.selectedWeekNumber = weekNumber;
+ }
+
+ /*
+ Return the current selected week number
+ */
+ function getSelectedWeekNumber() {
+ return properties.selectedWeekNumber;
+ }
+
+ /*
+ Return the profile from online user
+ */
+ function getCurrentUserProfile() {
+ return profileService.getProfile(getCurrentUserId());
+ }
+
+ /*
+ Update the onlyMySessions variable when change the associated checkbox value
+ */
+ function setOnlyMySessions(onlyMySessions) {
+ properties.onlyMySessions = onlyMySessions;
+ }
+
+ /*
+ Return the onlyMySessions checkbox value
+ */
+ function getOnlyMySessions() {
+ return properties.onlyMySessions;
+ }
+
+ /*
+ Set if we are in editor mode (private method)
+ */
+ function setIsEditor(editor) {
+ userProperties.isEditor = editor;
+ }
+
+ /*
+ Get if we are editor mode
+ */
+ function getIsEditor() {
+ return userProperties.isEditor;
+ }
+
+ /*
+ Get school calendar configuration
+ */
+ function getCalendarConfig() {
+ return viewProperties.calendarConfig;
+ }
+
+ /*
+ Set if school has a config enabled
+ */
+ function setSchoolConfigEnabled(enabled) {
+ viewProperties.schoolConfigEnabled = enabled;
+ }
+
+ /*
+ Return true if school has a config enabled
+ */
+ function getSchoolConfigEnabled() {
+ return viewProperties.schoolConfigEnabled;
+ }
+
+ /*
+ Set the clipboard for copy action (session)
+ */
+ function setClipboard(clipboard) {
+ properties.clipboard = clipboard;
+ }
+
+ /*
+ Get the clipboard paste action (session)
+ */
+ function getClipboard() {
+ return properties.clipboard;
+ }
+
+ /*
+ Set the current start date for homework panel
+ */
+ function setHomeworkStartDate(startDate) {
+ properties.homeworkStartDate = startDate;
+ }
+
+ /*
+ Get the current start date for homework panel
+ */
+ function getHomeworkStartDate() {
+ return properties.homeworkStartDate;
+ }
+
+ /*
+ Set the current end date for homework panel
+ */
+ function setHomeworkEndDate(endDate) {
+ properties.homeworkEndDate = endDate;
+ }
+
+ /*
+ Get the current end date for homework panel
+ */
+ function getHomeworkEndDate() {
+ return properties.homeworkEndDate;
+ }
+
+ /*
+ Set the selected homework id
+ */
+ function setHomeworkSelectedId(homeworkId) {
+ homeworkSelected.homeworkId = homeworkId;
+ }
+
+ /*
+ Get the selected homework id
+ */
+ function getHomeworkSelectedId() {
+ return homeworkSelected.homeworkId;
+ }
+
+ /*
+ Set the target date for selected homework
+ */
+ function setHomeworkSelectedTargetDate(targetDate) {
+ homeworkSelected.targetDate = targetDate;
+ }
+
+ /*
+ Get the target date for selected homework
+ */
+ function getHomeworkSelectedTargetDate() {
+ return homeworkSelected.targetDate;
+ }
+
+ }
+})();