UNPKG

unserver-unify

Version:

117 lines (116 loc) 4.57 kB
angular.module('bamboo.course').controller('Scorm2004ChapterCtrl', function($sce, Scorm2004, $http,CommonService, $stateParams, ApiService, $scope) { // console.log(loginService.user._id); var self = this; self.lmsready = false; self.ResUrl = ApiService.SHOST + '/lcourse/'; var courseid = $stateParams.cid; var mvId=$stateParams.id; var resInfos = {}; this.currentRef; var rootPath; this.gotoScoItem = function(item) { console.log(item); if(!item._identifierref){ return; } self.currentRef = item._identifierref; var _tempurl = rootPath + resInfos[self.currentRef]; console.log(_tempurl); self.fullurl = $sce.trustAsResourceUrl(encodeURI(_tempurl)); $scope.$parent.ctrl.toggleslide(); } function getMenuItems(item, menu) { if (item._identifier) { console.log(item); var menuItem = angular.copy(item); //menuItem.url=resInfos[item._identifierref]; if (menuItem.item) { delete menuItem.item; menuItem.menu = []; getMenuItems(item.item, menuItem.menu) } menu.push(menuItem); return; } for (var i = 0; i < item.length; i++) { var _subItem = item[i]; getMenuItems(_subItem, menu) } return; } this.init = function(chapter,successCallBack) { self.chapter = chapter; console.log(chapter); var api = Scorm2004.scorm2004Local(courseid,mvId, chapter._id,successCallBack, function() { self.lmsready = true; console.log("--- ready ---"); }); window.API = window.API_1484_11 = Scorm2004.API_1484_11; var mediaUrl = self.ResUrl; if (ApiService.MEDIAPATH) { mediaUrl = ApiService.MEDIAPATH + "/lcourse/"; } rootPath=mediaUrl + courseid + '/resources/' + self.chapter.content + "/"; // rootPath="assets/debug/CARREFOUR_cap_bien_etre_M04_Alternative/"; // rootPath="assets/debug/SequencingPostTestRollup4thEd_SCORM20044thEdition/"; // rootPath="assets/debug/SequencingPostTestRollup4thEd_SCORM20044thEdition/"; //rootPath = "assets/debug/demo_resp_1/"; var fullpath = rootPath + "imsmanifest.xml"; $http.get(fullpath, { transformResponse: function(cnv) { var x2js = new X2JS(); var aftCnv = x2js.xml_str2json(cnv); console.log(aftCnv.manifest); if (aftCnv.manifest && aftCnv.manifest.organizations && aftCnv.manifest.organizations.organization && aftCnv.manifest.organizations.organization.item) { var resources = aftCnv.manifest.resources.resource; console.log(resources); if (resources._href) { var id = resources._identifier; var strname = ""; if (resources['_xml:base']) { strname += resources['_xml:base']; } resInfos[id] = strname + resources._href; } else if (resources.length) { for (var i = 0; i < resources.length; i++) { var _r = resources[i]; var id = _r._identifier; // console.log(_r); if (id && _r._href) { var strname = ""; if (_r['_xml:base']) { strname += _r['_xml:base']; } resInfos[id] = strname + _r._href; } // break; } } console.log(resInfos); var items = aftCnv.manifest.organizations.organization.item; console.log(items); var menus = []; getMenuItems(items, menus); self.menuItems = menus; console.log(menus); } else { return CommonService.showError('Incompleted parameters'); } } }).then(function(response) { console.log(response); }); console.log(mediaUrl); var indexHtml = 'index_lms_html5.html'; if (chapter.indexHtml) { indexHtml = chapter.indexHtml; } //var _tempurl = mediaUrl + ($scope.chapter.rid || $scope.chapter.cid) + "/resources/" + $scope.chapter.content + '/' + 'index.html';//indexHtml; // var _tempurl = mediaUrl + ($scope.chapter.rid || $scope.chapter.cid) + "/resources/" + $scope.chapter.content + '/' + indexHtml; //var _tempurl = rootPath+"shared/launchpage.html?content=playing"; //var _tempurl = rootPath + "sco/act491684.html" var _tempurl = rootPath + indexHtml;; console.log(_tempurl); self.fullurl = $sce.trustAsResourceUrl(encodeURI(_tempurl)); } });