UNPKG

unserver-unify

Version:

268 lines (258 loc) 7.07 kB
angular.module('bamboo.course').controller('EWordChapterCtrl', function($scope, $stateParams, ApiService) { this.cid = $stateParams.cid; console.log("--- EWordChapterCtrl"); var self = this; var resUrl = this.resUrl = ApiService.SHOST + '/lcourse/' + this.cid + '/resources/'; this.index = 0; this.currentPPT; this.slidePages = []; this.init = function(chapter) { self.chapter = chapter; self.slidePages.push({ ntype: 'title', }); self.slidePages.push({ ntype: 'objective', }); console.log(self.chapter); resUrl = this.resUrl = ApiService.SHOST + '/lcourse/' + self.chapter.cid + '/resources/'; angular.forEach(self.chapter.ppts, function(ppt, index) { ppt.ntype = "word"; ppt.index = index; self.slidePages.push(ppt); }) self.slidePages.push({ ntype: 'matchpic' }); self.slidePages.push({ ntype: 'matchtext' }); self.show(0); } this.code; var myAudio; this.playAudio = function(file) { if (!file) { return; } var filename = resUrl + file; try { //var myAudio = new Audio(filename); if(!myAudio){ myAudio = new Audio(filename); }else{ myAudio.pause(); myAudio.src=filename; } myAudio.play(); } catch (e) {} } this.nextPage = function() { self.index++; if (self.index >= self.slidePages.length) { self.index = 0; } self.show(self.index); } this.lastPage = function() { self.index--; if (self.index < 0) { self.index = self.slidePages.length - 1; } self.show(self.index); } this.toAarray = []; this.fromArray = []; function random() { return .5 - Math.random(); } this.testPPT; function generateArrays() { var source = []; angular.forEach(self.chapter.ppts, function(ppt, index) { if (ppt.test) { ppt.index = index; ppt.selected = false; ppt.selectIndex = -1; source.push(ppt); console.log(ppt); } }); var source1 = []; angular.forEach(self.chapter.ppts, function(ppt, index) { if (ppt.test) { ppt.index = index; ppt.selected = false; ppt.selectIndex = -1; ppt.ans = {}; ppt.drag = true; ppt.match = ''; source1.push(ppt); console.log(ppt); } }); self.forAarray = []; self.forAarray = self.forAarray.concat(source1); self.forAarray.sort(random); // console.log(source); self.toAarray = []; self.toAarray = self.toAarray.concat(source); self.toAarray.sort(random); self.fromArray = []; self.fromArray = self.fromArray.concat(source); self.fromArray.sort(random); self.testPPT = self.fromArray[0]; $scope.list5 = angular.copy(self.toAarray); console.log(self.forAarray); //self.fromArray.shift(); self.finish = false; self.pass = false; console.log(self.toAarray); console.log(self.fromArray); } this.refresh = function() { generateArrays() } function playEffect(success) { var filename = "assets/audio/quite-impressed.mp3"; if (!success) { filename = "assets/audio/fail.mp3"; } try { // var myAudio = new Audio(filename); if(!myAudio){ myAudio = new Audio(filename); }else{ myAudio.pause(); myAudio.src=filename; } myAudio.play(); } catch (e) {} } this.selectCurrent = function(ppt) { if (!self.fromArray || self.fromArray.length < 1) { return; } console.log(self.fromArray); console.log('selectCurrent'); ppt.selected = true; ppt.selectIndex = self.testPPT.index; self.fromArray.shift(); console.log(self.fromArray); if (self.fromArray.length < 1) { console.log('all selected'); self.finish = true; var unmatch = 0; angular.forEach(self.toAarray, function(ppt) { if (!ppt.selected || ppt.selectIndex != ppt.index) { unmatch++; } }) if (unmatch > 1) { playEffect(); self.pass = false } else { self.pass = true; playEffect(true); } } else { self.testPPT = self.fromArray[0]; console.log(self.testPPT.audio); } } this.show = function(index) { self.index = index; self.currentPPT = self.slidePages[index]; console.log(self.currentPPT); switch (self.currentPPT.ntype) { case 'word': self.playAudio(self.currentPPT.audio); break; case 'matchpic': case 'matchtext': generateArrays(); break; } } $scope.startCallback = function(event, ui, title) { console.log('You started draggin: ' + title.title); //$scope.draggedTitle = title.title; }; $scope.stopCallback = function(event, ui) { console.log('Why did you stop draggin me?'); }; $scope.dragCallback = function(event, ui) { console.log('hey, look I`m flying'); }; $scope.dropCallback = function(event, ui) { console.log('hey, you dumped me :-('); console.log($scope); self.select({opt:self.droptarget}); //$scope.$apply() }; $scope.overCallback = function(event, ui) { console.log('Look, I`m over you'); }; $scope.outCallback = function(event, ui, index) { console.log(index); self.dropIndex = index; console.log('I`m not, hehe'); }; $scope.list1 = []; $scope.myCallback = function(event, ui, index){ console.log(index); console.log('Dropped into something'); self.forAarray[index].drag = false; clearAns(); }; this.refreshDrag = function() { angular.forEach(self.forAarray, function(ppt, index) { ppt.ans = {}; ppt.drag = true; ppt.match = ''; self.pass = false; }); $scope.list5 = angular.copy(self.toAarray); console.log(self.forAarray); console.log($scope.list5); } $scope.myCallback1 = function(event, ui){ console.log('myCallback1 into something'); clearAns(); }; function clearAns() { var match = 0; var unmatch = 0; angular.forEach(self.forAarray, function(ppt, index) { if (!ppt.ans.index&&ppt.ans.index!=0) { console.log(index); ppt.ans = {}; ppt.drag = true; ppt.match = ''; } else if ((ppt.ans.index||ppt.ans.index==0)&&ppt.index==ppt.ans.index) { ppt.match = true; match++; } else { console.log(ppt); ppt.match = false; unmatch++; } }); self.pass = false; if(self.forAarray.length==match) { self.pass = true; playEffect(true); } else if(self.forAarray.length==(match+unmatch)) { playEffect(false); } console.log(self.forAarray); } });