/** * Файл создает страницу со списоком лекций в курсе */ /* exported tma__courses__initLecturesList */ /** * Устанавливает список лекций в курсе */ function tma__courses__initLecturesList() { var rootElem = tma__checkContainerDiv('tlk-courses'); var objProfile = tma__getProfileObjFromLS(); var path = tma__getPath(); tma__onFuncLoad('tma__userbar__drawWidget', function () { tma__userbar__drawWidget(); }); var formData = JSON.stringify({ coursealias: path[2], projectid: objProfile.projectid, token: objProfile.token, tzoffset: new Date().getTimezoneOffset(), }); tma__request('/api/getlectures/', formData, '', function (response) { if (response.status === 'ok' && typeof response.data === 'object') { window.tildaMembers.courseLectures = response.data; tma__courses__addHeaderFooter(); var breadcrumbs = [{ label: tma__translate('{{personal_account}}', 'courses_dict'), href: '/members/' }]; if (response.data.course && response.data.course.name) { breadcrumbs.push({ label: response.data.course.name, href: '/members/courses/' + response.data.course.alias, }); } tma__initBreadcrumbsCssVariables(); var html = tma__courses__getLecturesListHtml(response.data, breadcrumbs); rootElem.innerHTML = tma__translate(html, 'courses_dict'); document.title = response.data.course.name; tma__courses__addTooltipEvents(); tma__showDocumentReady(); } else { document.location.replace('/members/'); } }); } /** * Находит и возвращает лекцию, которую необходимо пройти для открытия следующей лекции * * @param {string} id - id лекции * @returns {object} */ function tma__courses__getLecturesListAfterLecture(id) { var partitions = window.tildaMembers.courseLectures.course.partitions; var objLecture; for (var i = 0; i < partitions.length; i++) { var lectures = partitions[i].lectures; if (objLecture) break; for (var j = 0; j < lectures.length; j++) { var lecture = lectures[j]; if (Number(id) === Number(lecture.id)) { objLecture = lecture; break; } } } return objLecture; } /** * Функция получает строку с временем и склоняемым к нему словом * * @param {string} timeType - тип времени * @param {number} time - время * @returns {string} - возвращает время */ function tma__courses__getLecturesListAfterOffsetLecture(timeType, time) { var text = time + ' '; var array = []; if (timeType === 'hours') { array = [ tma__translate('{{lectures_has_after_offset_lecture_hour_1}}', 'courses_dict'), tma__translate('{{lectures_has_after_offset_lecture_hour_2}}', 'courses_dict'), tma__translate('{{lectures_has_after_offset_lecture_hour_3}}', 'courses_dict'), ]; } else if (timeType === 'days') { array = [ tma__translate('{{lectures_has_after_offset_lecture_day_1}}', 'courses_dict'), tma__translate('{{lectures_has_after_offset_lecture_day_2}}', 'courses_dict'), tma__translate('{{lectures_has_after_offset_lecture_day_3}}', 'courses_dict'), ]; } else if (timeType === 'weeks') { array = [ tma__translate('{{lectures_has_after_offset_lecture_week_1}}', 'courses_dict'), tma__translate('{{lectures_has_after_offset_lecture_week_2}}', 'courses_dict'), tma__translate('{{lectures_has_after_offset_lecture_week_3}}', 'courses_dict'), ]; } text += tma__courses__getDeclinationlNumber(time, array); return text; } /** * Шаблон списка страниц * * @param {object} props - данные доступных страниц * @param {Array} breadcrumbs - массив хлебных крошек * @returns {string} - шаблон страницы */ function tma__courses__getLecturesListHtml(props, breadcrumbs) { var html = ''; if (window.tildaMembers.is_init_store) { html += tma__createBreadcrumbsHTML(breadcrumbs); } html += '
'; html += '
'; html += '
'; if (props.course.logo) { html += ''; } html += '
'; html += '
' + props.course.name + '
'; if (props.course.description) { html += '
' + tma__courses__addBreakLineHtml(props.course.description) + '
'; } if (props.istutor) { html += '
'; html += ''; html += '
'; } html += '
'; html += '
'; html += '
'; for (var i = 0; i < props.course.partitions.length; i++) { html += tma__courses__getLecturesListPartitionHtml({ item: props.course.partitions[i], indexPartition: i, urlCourses: props.course.alias, isHideNumber: props.course.hideserialnum, }); } html += '
'; html += '
'; html += '
'; return html; } /** * Шаблон курса * * @param {object} props - данные курса * @returns {string} - шаблон курса */ function tma__courses__getLecturesListPartitionHtml(props) { var item = props.item; var html = ''; html += '
'; html += '
'; html += '
'; if (!props.isHideNumber) { html += '{{lectures_title_partition}} ' + (props.indexPartition + 1) + ': '; } html += item.name; html += '
'; for (var i = 0; i < item.lectures.length; i++) { props.item = item.lectures[i]; props.indexLecture = i; html += tma__courses__getLecturesListPartitionPageHtml(props); } html += '
'; html += '
'; return html; } /** * Шаблон лекции * * @param {object} props - данные лекции * @returns {string} - шаблон карточки с лекцией */ function tma__courses__getLecturesListPartitionPageHtml(props) { var item = props.item; var isAccess = item.hasaccess; var html = ''; html += '
'; html += ''; html += '
'; html += '
'; if (item.statusid === 'complete') { html += '
'; html += ''; html += '
'; } else if (item.statusid === 'viewed') { html += ''; } else { html += ''; } if (!props.isHideNumber) { html += '' + (props.indexPartition + 1) + '.' + (props.indexLecture + 1) + ''; } html += '
'; html += '
'; html += '' + item.name + ''; if (item.hasnotifications) { html += ''; } if (item.description) { html += '
' + tma__courses__addBreakLineHtml(item.description) + '
'; } if (item.startdate) { html += '
' + tma__courses__getDateWebinar(item.startdate) + '
'; } if (!isAccess) { var hasLecture = tma__courses__getLecturesListAfterLecture(item.accessdata.afterlectureid); html += '
'; if (item.accessdata.afterlectureid && !item.accessdata.afterlectureoffsettype) { html += tma__translate('{{lectures_has_after_lecture}}', 'courses_dict', { lecturetype: hasLecture ? tma__translate('{{lectures_has_after_lecture_' + hasLecture.typeid + '}}', 'courses_dict') : ' ', lecturename: hasLecture ? hasLecture.name : tma__translate('{{lectures_has_after_lecture_empty}}', 'courses_dict'), }); } else if (item.accessdata.afterdate) { html += '{{lectures_has_after_date}} ' + tma__getformatDate(item.accessdata.afterdate) + ' ' + tma__getformatDate(item.accessdata.afterdate, 'h:m'); } else if (item.accessdata.afterlectureid && item.accessdata.afterlectureoffsettype) { html += tma__translate('{{lectures_has_after_offset_lecture}}', 'courses_dict', { lecturetime: tma__courses__getLecturesListAfterOffsetLecture( item.accessdata.afterlectureoffsettype, item.accessdata.afterlectureoffset ), lecturename: hasLecture ? hasLecture.name : tma__translate('{{lectures_has_after_lecture_empty}}', 'courses_dict'), }); } html += '
'; } html += '
'; html += '
'; html += '
'; html += '
'; return html; } function tma__courses__addTooltipEvents() { var disabledLectures = document.querySelectorAll('.tlk-lectures__course-card_disabled'); for (var i = 0; i < disabledLectures.length; i++) { var lecture = disabledLectures[i]; lecture.addEventListener('mouseenter', function (event) { var hasLecture = event.target.querySelector('.tlk-lectures__course-card-has-lecture'); if (!hasLecture) return; hasLecture.classList.add('tlk-lectures__course-card-has-lecture_show'); }); lecture.addEventListener('mouseleave', function (event) { var hasLecture = event.target.querySelector('.tlk-lectures__course-card-has-lecture'); if (!hasLecture) return; hasLecture.classList.remove('tlk-lectures__course-card-has-lecture_show'); }); } // var taskcheckButton = document.querySelector('.tlk-lectures__taskcheck-button'); // var arrayTask = ['{{lectures_btn_task_1}}', '{{lectures_btn_task_2}}', '{{lectures_btn_task_3}}']; // var arrayComments = ['{{lectures_btn_comment_1}}', '{{lectures_btn_comment_2}}', '{{lectures_btn_comment_3}}']; // var textTask = tma__courses__getDeclinationlNumber(1, arrayTask) + ' {{lectures_btn_task_check}}'; // var textComments = tma__courses__getDeclinationlNumber(1, arrayComments); // var text = tma__translate(textTask + '
' + textComments, 'courses_dict', { taskcount: 1, commentcount: 1 }); // var options = { // element: taskcheckButton, // text: text, // position: 'top', // timeout: 500, // gap: 8, // zIndex: 1 // } // tma__courses__drawTooltip(options); } /** * Создает разметку хлебных крошек для навигации. * * @param {Breadcrumb[]} breadcrumbs - Массив объектов, представляющих пункты хлебных крошек. * @returns {string} Разметка хлебных крошек в виде HTML-строки. */ function tma__createBreadcrumbsHTML(breadcrumbs) { // Создаем контейнер для хлебных крошек var breadcrumbsEl = tma__createElementFromString('
'); var breadcrumbsWrapper = tma__createElementFromString('
'); breadcrumbsEl.appendChild(breadcrumbsWrapper); // Создаем домашнюю кнопку var homeButton = document.createElement('a'); homeButton.href = '/'; homeButton.className = 'tlk-breadcrumbs__home'; var homeIcon = tma__createHomeIconElement(); homeButton.appendChild(homeIcon); breadcrumbsWrapper.appendChild(homeButton); breadcrumbsWrapper.appendChild(tma__createDivider()); // Создаем хлебные крошки на основе массива объектов breadcrumbs.forEach(function (breadcrumb, index) { var isLast = index === breadcrumbs.length - 1; // Если это последний пункт, делаем его неактивным if (isLast) { var breadcrumbCurrent = document.createElement('span'); breadcrumbCurrent.className = 'tlk-breadcrumbs__item tlk-breadcrumbs__item_current'; breadcrumbCurrent.textContent = breadcrumb.label; breadcrumbsWrapper.appendChild(breadcrumbCurrent); return; } var breadcrumbItem; if (breadcrumb.onClick) { breadcrumbItem = document.createElement('button'); breadcrumbItem.addEventListener('click', breadcrumb.onClick); } else if (breadcrumb.href) { breadcrumbItem = document.createElement('a'); breadcrumbItem.href = breadcrumb.href; } else { breadcrumbItem = document.createElement('span'); } breadcrumbItem.className = 'tlk-breadcrumbs__item'; breadcrumbItem.textContent = breadcrumb.label; breadcrumbsWrapper.appendChild(breadcrumbItem); breadcrumbsWrapper.appendChild(tma__createDivider()); }); return breadcrumbsEl.outerHTML; } /** * Создает разделитель для хлебных крошек. * * @returns {HTMLElement} Элемент разделителя. */ function tma__createDivider() { var dividerSpan = document.createElement('span'); dividerSpan.className = 'tlk-breadcrumbs__divider'; dividerSpan.textContent = '/'; return dividerSpan; } /** * Создает элемент из строки или пустой div, если создать элемент не удалось * @param {string} str * @return {HTMLElement} */ function tma__createElementFromString(str) { var div = document.createElement('div'); if (!str) { console.info('Error creating element from string: empty or undefined string was used. Empty div used.'); return div; } div.insertAdjacentHTML('afterbegin', str.trim()); var el = div.firstElementChild; if (!el) { console.info('Error creating element from string. Used string:', str); return div; } return /** @type {HTMLElement} */ (el); } /** * Создаёт SVG-иконку с домом * * @returns {Element} Элемент дома */ function tma__createHomeIconElement() { var iconHtml = ''; iconHtml += ''; iconHtml += ''; iconHtml += ''; return tma__createElementFromString(iconHtml); } /** * В breadcrumbs кладём переменные из настроек ЛК или настроек проекта, * если она не определены, задаём значения по умолчанию */ function tma__initBreadcrumbsCssVariables() { var projectSettings = window.tildaMembers.settingStyles.fonts; var startPageSettings = window.tildaMembers.settingStyles.welcomepage; // в соответствии с приоритетом выставляем значение цвета текста хлебных крошек // 1. из настроек стартовой страницы Л // 2. из настроек проекта // 3. по умолчанию - #000000 var textColor = (startPageSettings && startPageSettings.textColor) || (projectSettings && projectSettings.textcolor) || '#000000'; var styleVariables = ''; styleVariables += '.tlk-breadcrumbs {'; styleVariables += '--text-color: ' + textColor + ';'; styleVariables += '}'; document.head.insertAdjacentHTML( 'beforeend', '' ); }