UNPKG

unserver-unify

Version:

81 lines (72 loc) 2.27 kB
angular.module('bamboo.course').controller('ChooseAnswerChapterCtrl', function($scope, $stateParams, ApiService) { this.cid = $stateParams.cid; var self = this; var resUrl = this.resUrl = ApiService.SHOST + '/lcourse/' + this.cid + '/resources/'; this.init = function(chapter) { self.chapter = chapter; self.answers = _.shuffle(angular.copy(self.chapter.options)); $scope.multiTargetList = initTargetList(); self.submitted = false; console.log(chapter); } function initTargetList() { var multiTargetList = []; for (var i = 0; i < (self.chapter.ppts.length-1); i++) { multiTargetList.push({jqyoui_pos:0}); } return multiTargetList; } $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 :-(', $scope.draggedTitle); }; $scope.overCallback = function(event, ui) { console.log('Look, I`m over you'); }; $scope.outCallback = function(event, ui) { console.log('I`m not, hehe'); }; $scope.selectMultiMatch = function(opt,idx){ console.log(idx); } 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.submit = function(){ self.ans = 0; angular.forEach(self.chapter.ppts,function(val,idx){ if($scope.multiTargetList[idx]&&val.ans==$scope.multiTargetList[idx].text){ self.ans+=1; } }); self.submitted = true; } this.reset = function(){ self.answers = _.shuffle(angular.copy(self.chapter.options)); $scope.multiTargetList = initTargetList(); self.submitted = false; } });