UNPKG

unserver-unify

Version:

1,463 lines (1,446 loc) 52.9 kB
'use strict'; angular.module('bamboo.course').controller('CourseVideoCtrl', function($scope, $uibModal, $rootScope, $stateParams, CourseApi, ApiService, CommonService, CourseService, $sce, $timeout, AppConfig, Lightbox, Fullscreen, loginService, $filter, $state, ScormService, pdfViewService, quizOpenCountService, examBizModel, $location, ExamService) { //var self = this; var _self = this; var schoolId = ApiService.gid; $scope.flag = false; //ii decide if show the quiz $scope.submit = false; $scope.show_overlay = true; $scope.displayQuizs = {}; $scope.displayQuizName = {}; $scope.currItem = {}; //$rootScope.hideHome = true; $rootScope.course_argbg_highlight_flag = ($state.current.name === "index.courses.course.section.video"); console.log($rootScope.course_argbg_highlight_flag); this.id = $stateParams.id; this.lid = $stateParams.cid; this.courseid = $stateParams.cid; this.cs = $stateParams.cs; console.log($location.absUrl()); this.encodedUrL = encodeURIComponent($location.absUrl()); console.log(_self.displayImg); var _cs = ApiService.getCheckSum($stateParams.cid); // console.log(this.cs); // console.log(_cs); if (this.cs != _cs) { return CommonService.showError('Invalid Access!'); } $scope.$on("$destroy", function() { console.log('-- destroy --'); $rootScope.course_argbg_highlight_flag = undefined; }); this.togglevslide = function() { if ($scope.slidevout) { $scope.slidevout = false; } else { $scope.slidevout = true; } } this.toggleslide = function() { if ($scope.slideout) { $scope.slideout = false; } else { $scope.slideout = true; } } this.toggleslidedrop = function(index) { console.log(index); $scope.slidedrop = index; } this.audioPause = true; this.onUpdateState = function($state) { console.log($state); _self.audioPause = ($state == 'pause') ? true : false; } this.mvsubject = {}; this.chapters = []; this.seekTimeFlag = false; this.index = CourseApi.getCoursewareIdx(_self.id); this.pptpicurl = this.pptaudiourl = this.ResUrl = ApiService.SHOST + '/lcourse/'; $scope.appUrl = ApiService.APPURL; this.imageFolderPrefix = ApiService.SHOST + '/examphoto/' + schoolId + '/'; this.sidemenu = []; this.allowaccessment = false; var views = []; this.showlist = true; this.exampic = ApiService.SHOST + '/public/images/exam_no_image.png'; this.defaultpic = ApiService.SHOST + '/public/images/videos.png'; this.examDefaultImage = 'assets/images/Exam_no-image1.jpg'; this.pptvideourl = ApiService.SHOST + '/lcourse/' + _self.lid + '/resources/'; $scope.tabs = 'chapter'; $scope.linkUrl = "/#/courselist//course/" + this.lid + "/v1/" + this.id + "/discuss/"; this.typename = { 'single': 'Select one answer', 'fill': 'Fill in the blank', 'mfill': 'Fill in all the blanks', 'tof': 'True or False', 'multiple': 'Multiple Choices, You can select more than one answer!', }; this.toggledrop = function() { if ($scope.dropdown) { $scope.dropdown = false; } else { $scope.dropdown = true; } } this.togglenotes = function() { if ($scope.notes) { $scope.notes = false; } else { $scope.notes = true; _self.getChapterNotes(); } } this.togglemore = function() { if ($scope.topWidget) { $scope.topWidget = false; } else { $scope.topWidget = true; } } this.changeItem = function(item) { $scope.currItem = item; } this.displaylist = function() { console.log("-- show list --"); _self.showlist = true; } // to get notes for this chapter this.chapterNotes = []; // array to save all notes under this chapter this.getChapterNotes = function() { CourseService.getChapterNotesByIds($stateParams.cid, $stateParams.id, $scope.chapter._id, function(data) { _self.chapterNotes = data || []; console.log(_self.chapterNotes); }) } this.shownote = function() { console.log("-- show note --"); _self.showlist = false; // load notes for this chapter _self.getChapterNotes(); } this.typeclassname = AppConfig.ResouceIcons; /* received all API from videogular when html was loaded*/ _self.API = null; this.onPlayerReady = function(API) { _self.API = API; }; this.videoCanPlay = function() { var previoustime = $scope.chapter.mp4time; if (previoustime) { $scope.chapter.mp4time = 0; // CourseApi.setMp4CurTime(0, 0); // remove the used playtime, avoid it been used again _self.API.stop(); // call stop to hide the buffering from page $timeout(function() { _self.seekTimeFlag && _self.API.seekTime(previoustime, false);  _self.API.play();  _self.seekTimeFlag = false; $scope.showScrubBar = true; }, 500); } }; this.onVideoFinished = function() { console.log("------------------- video play finished : " + $scope.chapter.taskFlag); if ($scope.chapter.taskFlag || $scope.chapter.score) { var currentvideo = _self.API.currentTime / 1000; var duration = $scope.chapter.duration; if (duration) { if (currentvideo + 10 > $scope.chapter.duration) { _historydetail[$scope.chapter._id] = { pass: true }; } } else { _historydetail[$scope.chapter._id] = { pass: true }; } recordUsage($scope.chapter); } }; //control function to generate above API structure this.mp4config = { sources: [{ // will fill in {src: ..., type: ...} }], theme: AppConfig.videogular_theme, }; this.replay = function() { clearresult($scope.displayQuizs); $scope.flag = false; $scope.submit = false; console.log(_self.lastCuePointTime); _self.API.seekTime(_self.lastCuePointTime, false); _self.API.play(); } this.getvideoUrl = function(url) { //var _url = url; return $sce.trustAsResourceUrl(_self.ResUrl + ($scope.chapter.rid || $scope.chapter.cid) + "/resources/" + encodeURI(url)); }; function initVideoUrl() { $scope.recordChapterVideoUrl = _self.ResUrl + ($scope.chapter.rid || $scope.chapter.cid) + "/resources/" + encodeURI(_self.chapter.video); } //initVideoUrl(); this.removePptVideo = function(index) { _self.ppts[index].mp4 = null; _self.updateChapter(); }; $scope.goFullscreen = function() { var ele = document.getElementById("videoshow"); // Fullscreen if (Fullscreen.isEnabled()) { Fullscreen.cancel(); $scope.isFullScreen = false; } else { Fullscreen.enable(ele); $scope.isFullScreen = true; } $timeout(pdfViewService.broadCastSizeUpdate, 100); }; if (document.addEventListener) { document.addEventListener('webkitfullscreenchange', exitHandler, false); document.addEventListener('mozfullscreenchange', exitHandler, false); document.addEventListener('fullscreenchange', exitHandler, false); document.addEventListener('MSFullscreenChange', exitHandler, false); document.addEventListener('webkitDisplayingFullscreen', exitHandler, false); document.addEventListener('webkitendfullscreen', exitHandler, false); document.addEventListener('webkitRequestFullScreen', exitHandler, false); } function exitHandler() { if (document.webkitIsFullScreen || document.mozFullScreen || document.msFullscreenElement !== null) { if (!Fullscreen.isEnabled()) { $scope.isFullScreen = false; console.log("exit detected"); $timeout(pdfViewService.broadCastSizeUpdate, 500); } } else { $scope.isFullScreen = false; console.log("esc detected"); $timeout(pdfViewService.broadCastSizeUpdate, 500); } } $scope.isFullScreen = false; $scope.toggleFullScreen = function() { console.log($scope.isFullscreen); $scope.isFullscreen = !$scope.isFullscreen; } $scope.goFullScreenViaWatcher = function() { $scope.isFullScreen = !$scope.isFullScreen; }; $rootScope.maxFlag = false; $scope.toggleMax = function() { $rootScope.maxFlag = !($rootScope.maxFlag); $timeout(pdfViewService.broadCastSizeUpdate); showFlash(); }; this.getMediaUrl = function() { var fullurl = _self.ResUrl + ($scope.chapter.rid || $scope.chapter.cid) + "/resources/" + encodeURI($scope.chapter.content); // flashplayer.html('<object type="application/x-shockwave-flash" width="100%" height="450" data="' + fullurl + '" > </object>'); return $sce.trustAsResourceUrl(fullurl); }; this.getSubUrl = function() { // var suburl=ApiService.MEDIAPATH+ '/lcourse/'+ ($scope.chapter.rid || $scope.chapter.cid) + "/resources/" + $scope.chapter.subtitle; var suburl = ApiService.MEDIAPATH + '/lcourse/' + ($scope.chapter.rid || $scope.chapter.cid) + "/resources/" + $scope.chapter.subtitle; console.log(suburl); if (ApiService.MEDIAPATH && $scope.chapter.subtitle) { return $sce.trustAsResourceUrl(encodeURI(suburl)); } else { return null; } } var _protocol = window.location.protocol; function getYoutubeUrl() { return CommonService.getYoutubeLinkfromUrl(_self.chapter.content); }; this.getYoutubeFromURL = function(url) { return CommonService.getYoutubeLinkfromUrl(url); } this.getYoukuUrl = function() { var re = /id_(\w+)/; var str = _self.chapter.content; var m; if ((m = re.exec(str)) !== null) { if (m.index === re.lastIndex) { re.lastIndex++; } } var url = "https://players.youku.com/player.php/sid/" + m[1] + "/v.swf"; return $sce.trustAsResourceUrl(url); } this.getPPtPicUrl = function(url) { // console.log(url); return $sce.trustAsResourceUrl(_self.ResUrl + ($scope.chapter.rid || $scope.chapter.cid) + "/resources/" + encodeURI(url)); }; $scope.showWiki = function(key) { CommonService.showWiki(key); }; $scope.showImage = function(src) { var images = []; images.push({ 'url': src }); Lightbox.openModal(images, 0); }; $scope.showVideo = function(title, url, isOnlineVideo) { var videos = []; var thisVideo = { caption: title, type: isOnlineVideo ? 'tube' : 'notTube', url: $sce.trustAsResourceUrl(encodeURI(url)) } videos.push(thisVideo); console.log(videos); CommonService.showVideo(videos, 0); } $scope.playerVars = { autoplay: 0, showinfo: 0 }; function getAudioUrl(url) { return $sce.trustAsResourceUrl(_self.ResUrl + ($scope.chapter.rid || $scope.chapter.cid) + "/resources/" + encodeURI(url)); } var _last_rid; var _lasttime = new Date(); var _historydetail = {}; var _total = 0; // $scope.$on("$destroy", function() { // $rootScope.hideHome = false; // if (!views || views.length < 1) { // return; // } // recordUsage($scope.chapter, true) // if (loginService.user) { // if ($scope.chapter && ($scope.chapter.type === 'mp4' || $scope.chapter.type === 'mp4ppt' || $scope.chapter.type === 'mp3ppt') && _self.API) { // $scope.chapter.mp4time = parseInt(_self.API.currentTime); // } // ApiService.submitActivityRecord(); // } else { // console.log("Already logout!"); // } // }); var rids = []; this.resourceRating = {}; function getResourceAccess() { if (CourseApi.course && CourseApi.course.assessment && loginService.school.resourceRatingFlag) { var info = { rids: rids, action: 'getresourcecounters', }; CourseApi.post('/rating', info, function(data) { $timeout(function() { _self.allowaccessment = true; _self.resourceRating = data; }, 100); }) } else if (!CourseApi.course) { $timeout(getResourceAccess, 1000); } } this.review = function(id) { $uibModal.open({ templateUrl: "components/dialog/rating-dlg.html", controller: "RatingDlgCtrl", controllerAs: 'ctrl', resolve: { title: function() { return _self.chapter.name; }, types: function() { return ["Knowledge", "Attraction", "Content"]; } } }).result.then(function(result) { console.log(result); var info = { action: "addresourceassessment", value: result.averageRating, object: result, id: id, } CourseApi.post('/rating', info, function(result) { _self.resourceRating[id] = 1; }); }); } var firstTime = true; var oldIndex = 0; this.getMvsubjectInfo = getMvsubjectInfo; function getMvsubjectInfo(flag) { $scope.id = _self.id; CourseApi.getInfo(_self.id, function(result) { _self.mvsubject = result; $scope.titleOfCourse = result.name; _self.chapters = _self.mvsubject.contents; console.log(_self.chapters); var allpass = true; var tasks = 0; if (!_self.chapters || _self.chapters.length == 0) { return; } var tindex = 0; var sindex = 0; var findex = 0; var lindex = 0; var leveldata = []; for (var i = 0; i < _self.chapters.length; i += 1) { var page = _self.chapters[i]; if (page._id) { rids.push(page._id); } if (page._id == _self.mvsubject.last_rid) { oldIndex = i; } if (!page.level || page.level == 0) { findex += 1; sindex = 0; tindex = 0; lindex = 0; page.level = 0; } else if (page.level == 1) { sindex += 1; tindex = 0; lindex = 0; } else if (page.level == 2) { tindex += 1; lindex = 0; } else { lindex += 1; } if (_self.mvsubject.manualindex) { page.title = page.name; } else { var idx = '' + findex; if (sindex > 0 || tindex > 0) { idx += '-' + sindex; } if (tindex > 0) { idx += '-' + tindex; } if (lindex > 0) { idx += '-' + lindex; } page.title = idx + '.' + page.name; } page.findex = findex; page.sindex = sindex; page.tindex = tindex; page.lindex = lindex; var info = { id: page._id, title: page.title, level: page.level, type: page.type, subType: page.subType, pass: page.pass, read: page.read, items: [], index: i, extFlag: false, taskFlag: page.taskFlag, score: page.score, }; if (page.disable) { info.disable = true; } if (page.taskFlag) { tasks++; if (!page.pass) { allpass = false; } } if (page.level == 0 || !page.level) { leveldata.push(info); } else if (page.level == 1) { if (findex < 1) { continue; } leveldata[findex - 1].items.push(info); } else if (page.level == 2) { if (findex < 1 || sindex < 1) { continue; } leveldata[findex - 1].items[sindex - 1].items.push(info); } else if (page.level == 3) { if (findex < 1 || sindex < 1 || tindex < 1) { continue; } leveldata[findex - 1].items[sindex - 1].items[tindex - 1].items.push(info); } } if (firstTime) { firstTime = false; if (allpass && tasks > 0 && _self.mvsubject.taskFlag && !_self.mvsubject.pass) { console.log(" --- need to submit pass result ---"); var info = { action: 'passmvsubject', id: _self.id, } CourseApi.mvApi(info, function(data) { console.log("--- updated ----"); }); } } console.log(leveldata); $scope.items = leveldata; $scope.currItem = $scope.items[0] || ""; if (rids.length > 0) { getResourceAccess(); } if (!flag && _self.chapters && _self.chapters.length > 0) { _self.topAudioPlaying = false; // init the bool to share if top audio is playing now // if url pass in chapterid(rid), open that chapter, else open user clicked chapter(index) if ($stateParams.rid) { _self.index = 0; for (var i = 0; i < _self.chapters.length; i += 1) { if (_self.chapters[i]._id == $stateParams.rid) { _self.index = i; break; } } _self.showchapter(_self.index); //if url passed shownote == true, toggle note page if ($stateParams.shownote) { _self.shownote(); } } else { _self.showchapter(_self.index); if (oldIndex && _self.index == 0) { CommonService.showConfirm('Will you resume the previous progress?', function(result) { _self.showchapter(oldIndex); }) } } } }, flag); } this.extItem = function(item) { item.extFlag = true; console.log(item); }; this.hideItem = function(item) { item.extFlag = false; }; // call back function to cuepoint this.onLeaveCuePoint = function(currentTime, timeLapse, params) {} this.onCompleteCuePoint = function(currentTime, timeLapse, params) { console.info("onCompleteCuePoint", currentTime, timeLapse, params); if (params.index == _self.currIndex) { $timeout(function() { _self.displayImg = null; }, 500); } } this.onEnterCuePoint2 = function(currentTime, timeLapse, params) { console.log("onEnterCuePoint", currentTime, timeLapse, params); _self.currIndex = params.index; $timeout(function() { _self.displayImg = params.displayImg; }, 500); } this.audioPptFinish = function() { _self.displayImg = undefined; } function recordUsage(prechapter, flag) { // console.log(flag); var res_id = _self.chapter._id; var _now = new Date(); if (_last_rid) { var delta = (_now - _lasttime) / 1000; _total += delta; if (!_historydetail[_last_rid]) { _historydetail[_last_rid] = { len: delta, } } else { if (!_historydetail[_last_rid].len) { _historydetail[_last_rid].len = 0; } _historydetail[_last_rid].len += delta; } } if (prechapter && (prechapter.type === 'mp4' || prechapter.type === 'mp4ppt' || prechapter.type === 'mp3ppt')) { var _chapterid = prechapter._id; prechapter.mp4time = parseInt(_self.API.currentTime / 1000); if (!_historydetail[_chapterid]) { _historydetail[_chapterid] = { mp4time: _self.API.currentTime, } } else { _historydetail[_chapterid].mp4time = parseInt(_self.API.currentTime / 1000); } } _last_rid = res_id; if (res_id && views.indexOf(res_id) < 0) { views.push(res_id); } _lasttime = _now; var trigger = false; var passed = false; var passedid = {}; if (flag) { trigger = true; } else { for (var key in _historydetail) { var record = _historydetail[key]; if (record.pass) { trigger = true; passed = true; passedid[key] = true; break; } } } if (trigger && loginService.user) { var info = { action: "resourceusage", ids: views, detail: _historydetail, total: _total, cid: _self.courseid, rid: _last_rid, mvid: _self.id, }; if (passed && _self.mvsubject.taskFlag && _self.chapters) { var _pass = true; for (var i = 0; i < _self.chapters.length; i++) { var item = _self.chapters[i]; if (item.taskFlag && !item.pass && !passedid[item.id]) { _pass = false; break; } } if (_pass) { info.passmvid = _self.id; } } CourseApi.mvApi(info, function(data) { _historydetail = {}; if (!flag) { console.log("-- called second time --"); getMvsubjectInfo(true); } }); } } this.showchapter = function(index, _item) { // $scope.videoFullScreen=false; _self.displayImg = null; console.log(index, _item); $scope.showScrubBar = true; _self.seekTimeFlag = true; if (_item && _item.disable) { CommonService.showInfo($filter('trans')({ eng: 'Please finish previous milestone task!', chn: '请完成前面的任务点!' })); return; } if (loginService.school.courseTheme == "fullscreen") { $timeout(function() { $scope.dropdown = false; }, 100) } var prechapter = _self.chapter; $scope.chapter = _self.chapter = _self.chapters[index]; console.log(_self.chapter); initVideoUrl(); if ($scope.chapter.taskFlag === true) { $scope.showScrubBar = false; } _self.index = index; CourseApi.setCoursewareIdx(_self.id, _self.index); if (_item && _item.items && _item.items.length > 0) { _item.extFlag = true; } else { if (index == 0 && $scope.items[0].items && $scope.items[0].items.length > 0) { $scope.items[0].extFlag = true; } } recordUsage(prechapter); switch ($scope.chapter.type) { case 'vimeo': var strings = $scope.chapter.content.split('vimeo.com/'); var idstr = strings[1].split('/'); var id = idstr[idstr.length - 1]; $scope.chapter.vimeourl = $sce.trustAsResourceUrl("//player.vimeo.com/video/" + id); $scope.topLevelAudio = $scope.audio = null; break; case 'ppts': _self.topAudioPlaying = false; // save the top level audio if any $scope.topLevelAudio = $scope.chapter.audio; showppt(0); break; case 'mp4': case 'mp3ppt': case 'mp4ppt': $state.go('.', {rid: $scope.chapter._id}); // _self.mp4config = { // sources: [{}], // theme: AppConfig.videogular_theme, // tracks: [{ // src: "", // kind: "subtitles", // srclang: "en", // label: "English", // default: "true" // }] // }; // _self.mp4config.sources[0].src = _self.getMediaUrl(); // _self.mp4config.sources[0].type = 'video/mp4'; // if ($scope.chapter.type == 'mp3ppt') { // _self.mp4config.sources[0].type = 'audio/mp3'; // } // _self.mp4config.tracks[0].src = _self.getSubUrl(); // $scope.topLevelAudio = $scope.audio = null; // if ($scope.chapter.type == 'mp4ppt' || $scope.chapter.type == 'mp3ppt') { // _self.uploadedImgs = $scope.chapter.ppts; // var cues = [] // console.info(_self.uploadedImgs); // for (var i = 0; i < _self.uploadedImgs.length; i += 1) { // // only care about linked imgs // //var endTime = getNextLinkCuePoint(i,_self.uploadedImgs); // //var endTime = null; // //console.log(endTime); // if (_self.uploadedImgs[i].linked) { // var endTime = _self.uploadedImgs[i].cueDuration && (_self.uploadedImgs[i].cueTime + (parseInt(_self.uploadedImgs[i].cueDuration) || 0)); // if (_self.uploadedImgs[i].forever) { // endTime = _self.uploadedImgs[i].cueDuration; // } // var cue = { // timeLapse: { // start: _self.uploadedImgs[i].cueTime, // end: endTime // }, // onEnter: _self.onEnterCuePoint2.bind(_self), // onLeave: _self.onLeaveCuePoint.bind(_self), // onUpdate: _self.onLeaveCuePoint.bind(_self), // onComplete: _self.onCompleteCuePoint.bind(_self), // params: { // displayImg: _self.uploadedImgs[i], // index: i, // } // } // if (!_self.uploadedImgs[i].cueDuration && _self.uploadedImgs[i].cueDuration != 0) { // delete cue.timeLapse.end; // } // cues.push(cue); // } // } // _self.mp4config.cuePoints = {}; // _self.mp4config.cuePoints.imgswitch = cues; // console.log(_self.mp4config); // // console.log(cues); // } break; case 'pdf': $scope.$on('pdf-end', function(event) { console.log('---- pdf end ---------'); console.log($scope.chapter); if ($scope.chapter.taskFlag && !$scope.chapter.pass && !_self.pdfProcess) { _self.pdfProcess = true; _historydetail[$scope.chapter._id] = { pass: true }; recordUsage($scope.chapter); } }); pdfViewService.setpdfUrl(_self.ResUrl + ($scope.chapter.rid || $scope.chapter.cid) + "/resources/" + encodeURI($scope.chapter.content)); $scope.audio = $scope.chapter.audio; $scope.video = $scope.chapter.video; setTimeout(showAudio, 100); break; case 'msoffice': var _protocol = window.location.protocol; var fullurl = _protocol + _self.ResUrl + ($scope.chapter.rid || $scope.chapter.cid) + "/resources/" + encodeURI($scope.chapter.content); console.log(fullurl); var refurl = "https://view.officeapps.live.com/op/embed.aspx?src=" + fullurl; $scope.chapter.fullurl = $sce.trustAsResourceUrl(refurl); $scope.audio = $scope.chapter.audio; $scope.video = $scope.chapter.video; setTimeout(showAudio, 100); break; case 'openoffice': var _protocol = window.location.protocol; var fullurl = _protocol + _self.ResUrl + ($scope.chapter.rid || $scope.chapter.cid) + "/resources/" + encodeURI($scope.chapter.content); console.log(fullurl); var refurl = "assets/libs/ViewerJS/#" + fullurl; $timeout(function() { $scope.chapter.openoffice = '<iframe allowfullscreen="" frameborder="0" mozallowfullscreen="" src="' + $sce.trustAsResourceUrl(refurl) + '" webkitallowfullscreen=""></iframe>'; }, 500); $scope.audio = $scope.chapter.audio; $scope.video = $scope.chapter.video; setTimeout(showAudio, 100); break; case 'html5': var mediaUrl = _self.ResUrl; if (ApiService.MEDIAPATH) { mediaUrl = ApiService.MEDIAPATH + "/lcourse/"; } $scope.chapter.ready = false; $timeout(function() { $scope.chapter.ready = true; }, 200); var defaulthtml = 'story_html5.html'; if ($scope.chapter.indexHtml) { defaulthtml = $scope.chapter.indexHtml; } // pdfViewService.setpdfUrl(_self.ResUrl + ($scope.chapter.rid || $scope.chapter.cid) + "/resources/" + $scope.chapter.content); var _tempurl = mediaUrl + ($scope.chapter.rid || $scope.chapter.cid) + "/resources/" + $scope.chapter.content + '/' + defaulthtml; $scope.chapter.fullurl = $sce.trustAsResourceUrl(encodeURI(_tempurl)); $scope.topLevelAudio = $scope.audio = null; console.log(_tempurl) break; case 'exam': CourseService.getExamInfoById($scope.chapter.content, function(data) { $scope.chapter.examinfo = data; $scope.topLevelAudio = $scope.audio = null; }); break; case 'coursesurvey': checkSurveyExist(); case 'bishun': case 'reading': case 'word': case 'idiom': case 'fillblank': case 'poetry': case 'audioexp': case 'lms2004': case 'lms': case 'ebook': case 'onlinequiz': console.log("----sub controller---------"); $scope.audio = null; if (prechapter && prechapter.type == $scope.chapter.type && $scope.chapter.type) { var _t_type = $scope.chapter.type; $scope.chapter.type = 'null'; $timeout(function() { $scope.chapter.type = _t_type; }, 10) } break; case 'quiz': CourseService.getQuizInfoById($scope.chapter.content, function(data) { $scope.chapter.quizinfo = data; $scope.topLevelAudio = $scope.audio = null; }); break; case 'assignment': if (prechapter && prechapter.type == 'assignment') { $scope.chapter.type = 'html'; $timeout(function() { $scope.chapter.type = "assignment"; }, 50); } $scope.topLevelAudio = $scope.audio = null; if ($scope.chapter.taskFlag && !$scope.chapter.pass) { var info = { aid: $scope.chapter.content, action: "checkuserassignmentdone" } ApiService.post('/exam', info).then(function(result) { if (result.data.success && result.data.data) { var res_id = $scope.chapter._id; if (!_historydetail[res_id]) { _historydetail[res_id] = {}; } _historydetail[res_id].pass = true; recordUsage($scope.chapter); } }); } break; case 'chapterexam': console.log("----chapterexam---"); console.log($scope.chapter); if ($scope.chapter.review || true) { var info = { action: "getmylastexamrecord", id: $scope.chapter._id, } ApiService.post('/exam', info).then(function(result) { console.log(result); if (result.data.success) { // console.log(result.data.data); $scope.chapter.result = result.data.data || {}; var eid = $scope.chapter.result.eid; eid && examBizModel.loadExamHistoryByEid(eid).then(function(data) { console.log(data); $scope.totalTakeExamCount = data.total || 0; }); } }) } var info = { id: $scope.chapter._id, action: "getresource", }; console.log(info); CourseApi.mvApi(info, function(result) { console.log(result); var photo = result.data.photo; if (photo) { $scope.chapterExamPhotoUrl = ApiService.SHOST + '/examphoto/' + schoolId + '/' + photo; } else { $scope.chapterExamPhotoUrl = null; } }); CourseService.getPaperinfo($scope.chapter.content, $scope.chapter.subType, function(data) { $scope.chapter.paperInfo = data; console.log(data); if ($scope.chapter.subType == "Dynamic" || $scope.chapter.subType == "Smart") { if ($scope.chapter.subType == "Smart") { $scope.chapter.paperInfo = data.paper; var tmp = data; data = data.paper; data.scores = tmp.scores; } var scores = 0; angular.forEach(data.contents, function(value, key) { scores += value.counter * value.score; }); $scope.chapter.paperInfo.scores = scores; } $scope.topLevelAudio = $scope.audio = null; }) break; case 'youtube': //$scope.youtubeid = _self.youtube_id_from_url(_self.chapter.content); _self.chapter.youtubeurl = getYoutubeUrl(); $scope.audio = $scope.chapter.audio; break; // case 'ebook': // if (_self.chapter.content) { // _self.chapter.bookurl = $sce.trustAsResourceUrl(encodeURI(_self.chapter.content)); // } // break; case 'article': _self.resUrl = ApiService.SHOST + '/lcourse/' + _self.chapter.cid + '/resources/'; console.log(_self.chapter); break; case 'test': convertQuestions(); default: console.log('type', $scope.chapter.type); $scope.audio = $scope.chapter.audio; setTimeout(showAudio, 100); showFlash(); break; }; } function checkSurveyExist() { _self.surveyResult = false; if ($scope.chapter.content) { _self.surveyId = $scope.chapter.content; var infor = { action: 'checksurveyexist', id: _self.surveyId }; if (!loginService.user) return; CourseApi.courseSurveyApi(infor, function(data) { console.log(data); if (data != 0) { _self.surveyResult = true; } else { getSruveyInfo(); } }); } } function getText(string) { return string.replace(/&nbsp;/g, '').replace(/<[^>]*>/g, "").replace(/\./g, ','); } function getSruveyInfo() { _self.questionInfo = {}; _self.qresults = {}; _self.lqinfo = {}; _self.item = {}; _self.reason = {}; var questions = {}; var info = { action: 'get', id: _self.surveyId }; CourseApi.courseSurveyApi(info, function(result) { console.log(result); _self.item = result; _self.qresults = {}; $rootScope.currentSurveyTitle = _self.item.name; if (!_self.item.sections) { _self.item.sections = []; } angular.forEach(_self.item.questions, function(val, index) { _self.questionInfo[val._id] = val; }) angular.forEach(_self.item.sections, function(item, index) { item.index = index; }); angular.forEach(_self.item.sections, function(item, index) { // item.index=index; item.sindex = index; var lqids = []; angular.forEach(item.questions, function(id) { var longid = id + '-' + index; lqids.push(longid); var info = { id: id, index: item.index, sindex: index, } _self.qresults[longid] = info; _self.lqinfo[longid] = angular.copy(_self.questionInfo[id]); }) item.lqids = lqids; console.log(item); }); console.log(_self.qresults); console.log(_self.lqinfo); }); } $scope.numToLetters = function(num) { return String.fromCharCode(65 + num); }; this.errorFlag = false; this.surveySubmit = function() { var allanswered = true; var lastunanswered = []; console.log("------------submit----------------"); console.log(_self.item); var result = {}; var _index = 0; console.log(_self.lqinfo); angular.forEach(_self.lqinfo, function(q, id) { console.log(q); if (q.type == 'multiple') { var _ans = []; angular.forEach(q.options, function(val, index) { if (val.selection) { _ans.push(val.text); } }) result[id] = _ans; if (_ans.length < 1) { allanswered = false; } } else if (q.selection != undefined && q.selection != '') { result[id] = q.selection; } else { allanswered = false; } }) console.log(result); if (!allanswered) { _self.errorFlag = true; CommonService.showNoBlockErr('Not all question answered!'); } else { var info = { id: _self.id, action: 'submitsurvey', object: { result: result, cid: _self.courseid, type: _self.reason.type, sid: _self.item._id, } }; console.log(info); CourseApi.courseSurveyApi(info, function(res) { checkSurveyExist(); if ($scope.chapter.taskFlag) { _historydetail[$scope.chapter._id] = { pass: true }; recordUsage($scope.chapter); } }); } }; function convertQuestions() { // console.log(_self.chapter); angular.forEach(_self.chapter.questions, function(q, index) { console.log('q to convert', index); ExamService.convertV1Question(q); if (q.type == 'single' || q.type == 'multiple') { q._options = _.shuffle(q._options); } }) } function showFlash() { if ($scope.chapter.type == 'flash') { $timeout(function() { var flashplayer = angular.element('#flashplayer'); var fullurl = _self.ResUrl + ($scope.chapter.rid || $scope.chapter.cid) + "/resources/" + encodeURI($scope.chapter.content); flashplayer.html('<object type="application/x-shockwave-flash" width="100%" height="' + ($scope.maxFlag ? 600 : 450) + '" data="' + fullurl + '" > </object>'); }, 50) } else if ($scope.chapter.type == 'ppts' && $scope.ppt.type == 'flash') { $timeout(function() { var flashplayer = angular.element('#flashppt'); var fullurl = _self.ResUrl + ($scope.chapter.rid || $scope.chapter.cid) + "/resources/" + $scope.ppt.flash; flashplayer.html('<object type="application/x-shockwave-flash" width="100%" height="' + ($scope.maxFlag ? 600 : 450) + '" data="' + fullurl + '" > </object>'); }, 50) } } var pptindex = 0; this.pptMourseOver = function(event) { if (!$scope.ppt.actions || !$scope.ppt.actions.length) { return; } // console.log(event); var picWidth = event.target.naturalWidth; var picHeight = event.target.naturalHeight; var currentWidth = event.target.width; var currentHeight = event.target.height; var x = parseInt(event.offsetX * picWidth / currentWidth); var y = parseInt(event.offsetY * picHeight / currentHeight); // console.log(picWidth, picHeight, x, y); var action; for (var i = 0; i < $scope.ppt.actions.length; i++) { var _action = $scope.ppt.actions[i]; // console.log(_action); if (_action.sx) { if (_action.sx < x && _action.ex > x && _action.sy < y && _action.ey > y) { // console.log('here!'); action = _action; break; } } } if (action) { event.target.style.cursor = "pointer"; } else { event.target.style.cursor = ""; } } this.pptAction = function(event) { console.log(event); var picWidth = event.target.naturalWidth; var picHeight = event.target.naturalHeight; var currentWidth = event.target.width; var currentHeight = event.target.height; var x = parseInt(event.offsetX * picWidth / currentWidth); var y = parseInt(event.offsetY * picHeight / currentHeight); console.log(picWidth, picHeight, x, y); var action; if ($scope.ppt.actions) { for (var i = 0; i < $scope.ppt.actions.length; i++) { var _action = $scope.ppt.actions[i]; // console.log(_action); if (_action.sx) { if (_action.sx < x && _action.ex > x && _action.sy < y && _action.ey > y) { console.log('here!'); action = _action; break; } } } } if (action) { switch (action.type) { case 'audio': var fullurl = _self.pptvideourl + action.audio; var _au = new Audio(fullurl); _au.play(); break; case 'video': var fullurl = _self.pptvideourl + action.video; var _au = $scope.showVideo($scope.ppt.title || $scope.chapter.name || 'video', fullurl) break; case 'link': showppt(action.index - 1); break; case 'text': CommonService.showInfo(action.comment); break; } } } function showppt(i) { if ($scope.chapter.type == 'ppts' && !$scope.chapter.pass && $scope.chapter.taskFlag && i == $scope.chapter.ppts.length - 1 && !_self.pptsProcess) { console.log($scope.chapter); _self.pptsProcess = true; _historydetail[$scope.chapter._id] = { pass: true }; recordUsage($scope.chapter); } if ($scope.chapter && ($scope.chapter.type == 'ppts' || $scope.chapter.type == 'bishun') && $scope.chapter.ppts && $scope.chapter.ppts.length > 0) { $scope.ppt = $scope.chapter.ppts[i]; //dealy to update video resource pptindex = i; //config mp4 type page for video player if ($scope.ppt.type == 'mp4') { // if mp4 file exist if ($scope.ppt.mp4) { $scope.ppt.mp4config = {}; $scope.ppt.mp4config.sources = [{}]; $scope.ppt.mp4config.sources[0].src = _self.getPPtPicUrl($scope.ppt.mp4); $scope.ppt.mp4config.sources[0].type = 'video/mp4'; // and if subtitle file exist if ($scope.ppt.mp4sub) { $scope.ppt.mp4config.tracks = [{}]; $scope.ppt.mp4config.tracks[0].src = _self.getPPtPicUrl($scope.ppt.mp4sub); $scope.ppt.mp4config.tracks[0].kind = "subtitles"; $scope.ppt.mp4config.tracks[0].srclang = "en"; $scope.ppt.mp4config.tracks[0].label = "English"; $scope.ppt.mp4config.tracks[0].default = 'true'; } } } else if ($scope.ppt.type == 'youtube') { // var newId = _self.youtube_id_from_url($scope.ppt.content); // $scope.ppt.youtubeurl = $sce.trustAsResourceUrl('//www.youtube.com/embed/' + newId + '?&controls=1&showinfo=0&autoplay=1'); //self.ppt.youtubeurl=getYoutubeUrl(); $scope.ppt.youtubeurl = CommonService.getYoutubeLinkfromUrl($scope.ppt.content); } else { if ($scope.ppt.type == 'test') { angular.forEach($scope.ppt.questions, function(q, index) { // console.log('q to convert', index); convertQ(q); }) } console.log($scope.ppt); var _mp4 = $scope.ppt.mp4; $scope.ppt.mp4 = null; $timeout(function() { $scope.ppt.mp4 = _mp4; }, 300); } if ($scope.ppt) { $scope.audio = $scope.ppt.audio; } $scope.pptindex = pptindex; } // console.log($scope.ppt); if ($scope.audio && $scope.ppt.type != 'mp4') { _self.topAudioPlaying = false; setTimeout(showAudio, 100); // play individual ppt audio if available } else if ($scope.topLevelAudio && _self.topAudioPlaying == false && $scope.ppt.type != 'mp4') { _self.topAudioPlaying = true; setTimeout(showTopAudio, 100); // play toplevel ppt audio if available } else { // play nothing } if ($scope.chapter.type == 'bishun') { var number = $scope.ppt.word.charCodeAt(0); var string = number.toString(16); $scope.ppt.code = string } showFlash(); } function showTopAudio() { var doc = angular.element($('#pptaudiodiv')); doc.empty(); if ($scope.topLevelAudio) { // console.log('show audio'); $scope.audiourl = getAudioUrl($scope.topLevelAudio); var audioElement = document.createElement('audio'); audioElement.src = $scope.audiourl; audioElement.autoplay = true; audioElement.controls = 'controls'; doc.append(audioElement); } } function showAudio() { var doc = angular.element($('#pptaudiodiv')); doc.empty(); if ($scope.audio) { // console.log('show audio'); $scope.audiourl = getAudioUrl($scope.audio); var audioElement = document.createElement('audio'); audioElement.src = $scope.audiourl; audioElement.autoplay = true; audioElement.controls = 'controls'; doc.append(audioElement); } } this.leftclick = function() { if (pptindex <= 0) { pptindex = $scope.chapter.ppts.length - 1; } else { pptindex -= 1; } showppt(pptindex); }; this.rightclick = function() { if (pptindex >= ($scope.chapter.ppts.length - 1)) { CommonService.confirm({ message: $filter('trans')({ eng: 'You have reached the end. Do you want to go back to the beginning?', chn: '这已经是最后一页。您想要回到课件首页吗?' }) }).then(function() { pptindex = 0; showppt(pptindex); }, function() { console.log('press no'); }); } else { pptindex += 1; showppt(pptindex); } }; $scope.numToLetters = function(num) { return String.fromCharCode(65 + num); }; $scope.resulticon = { Correct: "fa fa-check", Wrong: "fa fa-times", 'Not Attempted': "fa fa-times miss" }; function checkresult(questions) { // console.log(questions); var correct = 0; var wrong = 0; for (var i = 0; i < questions.length; i += 1) { var q = questions[i]; ExamService.checkQResult(q); if (q.judgement == 'Correct') { correct++; } else { wrong++; } } if (!_historydetail[_last_rid]) { _historydetail[_last_rid] = { len: 0, result: { correct: correct, wrong: wrong, }, count: 1, } } else { _historydetail[_last_rid].result = { correct: correct, wrong: wrong, } if (!_historydetail[_last_rid].count) { _historydetail[_last_rid].count = 1; } else { _historydetail[_last_rid].count++; } } if (!wrong) { _historydetail[_last_rid].pass = true; recordUsage(_self.chapter); } //console.log(_historydetail); } this.submitPPTTest = function(index) { if ($scope.ppt.type != 'test') { return console.log('wrong type ppt'); } //console.log($scope.ppt.questions); var ppt = angular.copy($scope.ppt); checkresult(ppt.questions); ppt.showresult = true; $scope.ppt = ppt; }; this.retestPPT = function(index) { $scope.ppt.showresult = false; }; this.submitChapterTest = function(index) { console.log('result'); if ($scope.chapter.type != 'test') { return console.log('wrong type ppt'); } //console.log($scope.ppt.questions); var chapter = angular.copy($scope.chapter); console.log('----'); console.log(chapter); checkresult(chapter.questions); chapter.showresult = true; $scope.chapter = chapter; }; this.submitChapterTestForVideoQuiz = function(quiz) { console.log(quiz); checkresult(quiz); console.log(quiz); $scope.chapter.showresult = true; $scope.submit = true; }; this.continueVideo = function() { clearresult($scope.displayQuizs); $scope.flag = false; $scope.submit = false; _self.API.play(); } var myAudio; this.playAudio = function(ppt) { console.log(ppt); if (!ppt.explainAudio) { return; } var filename = _self.pptvideourl + ppt.explainAudio; try { if (!myAudio) { myAudio = new Audio(filename); } else { myAudio.pause(); myAudio.src = filename; } myAudio.play(); } catch (e) {} }; function clearresult(questions) { console.log(questions); questions = questions || $scope.chapter.questions; console.log(questions); console.log("length:" + questions.length); for (var i = 0; i < questions.length; i++) { var q = questions[i]; console.log(i); console.log(questions[i]); switch (q.type) { case 'single': q.selection = undefined; q.select = undefined; q.judgement = undefined; case 'multiple': var opts = q._options; q.judgement = null; if (opts && opts.length > 0) { for (var j = 0; j < opts.length; j += 1) { opts[j].selection = null; } } break; case 'tof': q.selection = null; q.judgement = null; break; case 'fill': q.selection = null; q.judgement = null; break; case 'mfill': console.log(q.options); var opts = q._options; q.judgement = null; if (opts && opts.length > 0) { for (var j = 0; j < opts.length; j++) { opts[j].selection = null; } } } } } this.showdetailnote = function(note) { console.log(note); _self.API.seekTime(note.mp4time, false); _self.API.play(); } /* this.retestChapter = function(index) { clearresult($scope.chapter.questions); $scope.chapter.showresult = false; }; */ this.retestChapter = function(quiz) { clearresult(quiz); $scope.chapter.showresult = false; $scope.submit = false; } this.retestPPT = function(index) { $scope.ppt.showresult = false; }; getMvsubjectInfo();