Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
221 changes: 211 additions & 10 deletions admin/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ angular.module("easylearncode.admin.core", ["ngRoute", "ngResource", "services.u
]);
;
angular.module("easylearncode.admin.home", ["easylearncode.admin.core"]);
angular.module("easylearncode.admin.course", ["easylearncode.admin.core"])
angular.module("easylearncode.admin.course", ["easylearncode.admin.core", "com.2fdevs.videogular", "com.2fdevs.videogular.plugins.controls", "com.2fdevs.videogular.plugins.overlayplay", "com.2fdevs.videogular.plugins.buffering", "com.2fdevs.videogular.plugins.poster", "info.vietnamcode.nampnq.videogular.plugins.youtube", "info.vietnamcode.nampnq.videogular.plugins.quiz"])
.config(["$locationProvider", "$routeProvider", function ($locationProvider, $routeProvider) {
$routeProvider
.when("/",
Expand Down Expand Up @@ -190,8 +190,8 @@ angular.module("easylearncode.admin.course", ["easylearncode.admin.core"])
headers: {'Content-Type': undefined },
transformRequest: angular.identity
}).success(function (data) {
course.img = data.image_url;
}).error();
course.img = data.image_url;
}).error();
})

};
Expand Down Expand Up @@ -538,7 +538,7 @@ angular.module("easylearncode.admin.course", ["easylearncode.admin.core"])

};

var ModalInstanceCtrl = function ($scope, $modalInstance, form) {
var ModalInstanceCtrl = function ($scope, $modalInstance, form) {

$scope.form = form;

Expand All @@ -551,9 +551,210 @@ angular.module("easylearncode.admin.course", ["easylearncode.admin.core"])
};
};
}])
.controller("QuestionAdminCtrl", ["$scope", "api", "$routeParams", '$modal', '$http', function ($scope, api, $routeParams, $modal, $http) {
$scope.lecture = api.Model.get({type: 'lectures', id: $routeParams.lectureId, recurse: true});
.controller("QuestionAdminCtrl", ["$scope", "api", "$routeParams", '$modal', '$http', '$sce', '$compile', '$rootScope', "VG_EVENTS", function ($scope, api, $routeParams, $modal, $http, $sce, $compile, $rootScope, VG_EVENTS) {
var addForm = {
"form_id": 1,
"form_name": "Add Question",
"form_fields": [
{
"field_id": 1,
"field_title": "title",
"field_type": "textfield",
"field_value": "",
"field_required": true
},
{
"field_id": 2,
"field_title": "description",
"field_type": "code",
"field_language": "python",
"field_value": "",
"field_required": true
}
]
}

var ModalInstanceCtrl = function ($scope, $modalInstance, form) {

$scope.form = form;

$scope.ok = function (data) {
$modalInstance.close($scope.form);
};

$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
};

$scope.showAddModal = function () {
var modalInstance = $modal.open({
templateUrl: 'myModalContent.html',
controller: ModalInstanceCtrl,
resolve: {
form: function () {
return addForm;
}
}
});
modalInstance.result.then(function (addForm) {
lecture = {}
_.each(addForm.form_fields, function (ele) {
lecture[ele.field_title] = ele.field_value;
});
// api.Model.save({type: 'lectures'}, lecture, function (data) {
// api.Model.get({type: 'lessons', id: $routeParams.lessonId}, function (lesson) {
// lesson.lecture_keys.push(data.Id);
// api.Model.save({type: 'lessons', id: lesson.Id}, lesson, function () {
// $scope.lesson.lecture_keys.push(data);
// });
// });
// })
}, function () {
console.log('Modal dismissed at: ' + new Date());
});

};

$scope.lecture = api.Model.get({type: 'lectures', id: $routeParams.lectureId, recurse: true}, function (data) {
$scope.currentTime = 0;
$scope.totalTime = 0;
$scope.state = null;
$scope.volume = 1;
$scope.isCompleted = false;
$scope.API = null;

$scope.onPlayerReady = function (API) {
$scope.API = API;
};

$scope.onCompleteVideo = function () {
$scope.isCompleted = true;
};

$scope.onUpdateState = function (state) {
$scope.state = state;
};

$scope.pauseVideo = function () {
$scope.API.pause();
};

$rootScope.$on(VG_EVENTS.ON_EXIT_FULLSCREEN, function () {
$scope.API.setSize(700, 380);
});
//
// $rootScope.$on(VG_EVENTS.ON_ENTER_FULLSCREEN, function(){
// alert($scope.config.width);
// $scope.config.width = 700;
// $scope.config.height = 380;
// });

$scope.onUpdateTime = function (currentTime, totalTime) {
$scope.currentTime = currentTime;
$scope.totalTime = totalTime;
// angular.forEach(codes, function (code) {
// if (code.time < currentTime) {
// if ($scope.state == 'play')
// $scope.code = code.code;
// }
// });
};

$scope.onUpdateVolume = function (newVol) {
$scope.volume = newVol;
};

$scope.onUpdateSize = function (width, height) {
$scope.config.width = width;
$scope.config.height = height;
};

$scope.onQuizSubmit = function (data) {
return {
result: true,
description: "Correct"
}
}

$scope.stretchModes = [
{
label: "None",
value: "none"
},
{
label: "Fit",
value: "fit"
},
{
label: "Fill",
value: "fill"
}
];
$scope.goLecture = function (lecture) {
// $location.path("/").search('lecture_id', lecture.Id).replace();
// $scope.lecture = lecture;
// $scope.loadLecture();
}
$scope.loadLecture = function () {
$scope.youtubeUrl = $sce.trustAsResourceUrl("http://www.youtube.com/watch?v=" + $scope.lecture.youtube_id);
$scope.show = false;
if (angular.isDefined($scope.vgScope)) {
$scope.vgScope.$destroy();
}
$scope.vgScope = $scope.$new(false);
$('#video').html($compile("<videogular id=\"khung-video\"\r\n vg-player-ready=\"onPlayerReady\" vg-complete=\"onCompleteVideo\" vg-update-time=\"onUpdateTime\" vg-update-size=\"onUpdateSize\" vg-update-volume=\"onUpdateVolume\" vg-update-state=\"onUpdateState\"\r\n vg-width=\"config.width\" vg-height=\"config.height\" vg-theme=\"config.theme.url\" vg-autoplay=\"config.autoPlay\" vg-stretch=\"config.stretch.value\" vg-responsive=\"config.responsive\">\r\n<video preload='metadata' id=\"video_content\">\r\n<source type=\"video/youtube\" src=\"" + $scope.youtubeUrl + "\" /></video>\r\n <vg-youtube></vg-youtube>\r\n <vg-quiz vg-data='config.plugins.quiz.data' vg-quiz-submit=\"onQuizSubmit\" vg-quiz-skip=\"onQuizSkip\" vg-quiz-continue=\"onQuizContinue\" vg-quiz-show-explanation=\"onQuizShowExplanation\"></vg-quiz>\r\n <vg-poster-image vg-url='config.plugins.poster.url' vg-stretch=\"config.stretch.value\"></vg-poster-image>\r\n <vg-buffering></vg-buffering>\r\n <vg-overlay-play vg-play-icon=\"config.theme.playIcon\"></vg-overlay-play>\r\n\r\n <vg-controls vg-autohide=\"config.autoHide\" vg-autohide-time=\"config.autoHideTime\" style=\"height: 50px;\">\r\n <vg-play-pause-button vg-play-icon=\"config.theme.playIcon\" vg-pause-icon=\"config.theme.pauseIcon\"></vg-play-pause-button>\r\n <vg-timeDisplay>{{ currentTime }}</vg-timeDisplay>\r\n <vg-scrubBar>\r\n <vg-scrubbarcurrenttime></vg-scrubbarcurrenttime>\r\n </vg-scrubBar>\r\n <vg-timeDisplay>{{ totalTime }}</vg-timeDisplay>\r\n <vg-volume>\r\n <vg-mutebutton\r\n vg-volume-level-3-icon=\"config.theme.volumeLevel3Icon\"\r\n vg-volume-level-2-icon=\"config.theme.volumeLevel2Icon\"\r\n vg-volume-level-1-icon=\"config.theme.volumeLevel1Icon\"\r\n vg-volume-level-0-icon=\"config.theme.volumeLevel0Icon\"\r\n vg-mute-icon=\"config.theme.muteIcon\">\r\n </vg-mutebutton>\r\n <vg-volumebar></vg-volumebar>\r\n </vg-volume>\r\n <vg-fullscreenButton vg-enter-full-screen-icon=\"config.theme.enterFullScreenIcon\" vg-exit-full-screen-icon=\"config.theme.exitFullScreenIcon\"></vg-fullscreenButton>\r\n </vg-controls>\r\n </videogular>")($scope.vgScope));
$("#gplus-cm").html("Loading G+ Comments");
}

$scope.config = {
width: 700,
height: 380,
autoHide: true,
autoHideTime: 3000,
autoPlay: false,
responsive: false,
stretch: $scope.stretchModes[1],
theme: {
url: "/application/css/videogular/videogular.css",
playIcon: "&#xe000;",
pauseIcon: "&#xe001;",
volumeLevel3Icon: "&#xe002;",
volumeLevel2Icon: "&#xe003;",
volumeLevel1Icon: "&#xe004;",
volumeLevel0Icon: "&#xe005;",
muteIcon: "&#xe006;",
enterFullScreenIcon: "&#xe007;",
exitFullScreenIcon: "&#xe008;"
},
plugins: {
poster: {
url: "http://upload.wikimedia.org/wikipedia/commons/4/4a/Python3-powered_hello-world.svg"
},
quiz: {
data: [
{
"time": "164",
"question_id": "70d70be689d73e08687496a6d12b2b0d",
"html": "<div style=\"position:absolute;\">Select the restaurant(s) that serve Canadian cuisine for a price of $$$.\n\n<small>\n<pre>Georgie Porgie\n87%\n$$$\nCanadian,Pub Food\n\nSilver Spoon\n97%\n$$$$\nCanadian\n\nCoffee Cafe\n77%\n$$\nCoffee/Tea,Diner\n</pre>\n</small>\n</div>\n<div class=\"quiz-option\" style=\"position:absolute; left: 470px; top: 50px;\">\n<input dir=\"auto\" class=\"quiz-input\" type=\"checkbox\" name=\"answer[70d70be689d73e08687496a6d12b2b0d][]\" id=\"gensym_52be3ad71a1f5\" value=\"d5c5ec0ff53ebf35958c5ba02c30ce24\"><label for=\"gensym_52be3ad71a1f5\" style=\"cursor:pointer;\">Georgie Porgie</label>\n</div>\n<div class=\"quiz-option\" style=\"position:absolute; left: 470px; top: 140px; /* width:370px; */ /* height:80px; */ \">\n<input dir=\"auto\" class=\"quiz-input\" type=\"checkbox\" name=\"answer[70d70be689d73e08687496a6d12b2b0d][]\" id=\"gensym_52be3ad71a71f\" value=\"cfc6db592e488051decbce17bd7b98b8\"><label for=\"gensym_52be3ad71a71f\" style=\"cursor:pointer;\">Silver Spoon</label>\n</div>\n<div class=\"quiz-option\" style=\"position:absolute; left: 470px; top: 230px; /* width:370px; */ /* height:80px; */ \">\n<input dir=\"auto\" class=\"quiz-input\" type=\"checkbox\" name=\"answer[70d70be689d73e08687496a6d12b2b0d][]\" id=\"gensym_52be3ad71ac52\" value=\"b387d47429de02592f973814b393e51d\"><label for=\"gensym_52be3ad71ac52\" style=\"cursor:pointer;\">Coffee Cafe</label>\n</div>",
"background": "color",
"background_src": "white",
"post_answer_url": "https:\/\/class.coursera.org\/programming2-001\/quiz\/video_quiz_attempt?method=post_question_answer&quiz_id=20&preview=0&question_id=70d70be689d73e08687496a6d12b2b0d"
},
{
"time": "180",
"question_id": "9326a7b17e15cfc69f8e46f9357bf6c5",
"html": "<div dir=\"auto\" class=\"quiz-question-text\" style=\"position:absolute;\">\n<small>\n<pre>def is_palindrome_v3(s):\n i = 0\n j = len(s) - 1\n while i &lt; j and s[i] == s[j]:\n i = i + 1\n j = j - 1\n\n return j &lt;= i\n</pre>\n</small>\nIf <code>s</code> refers to a single-character string such as 'x', when the return statement is reached, which of the following expressions evaluates to <code>True</code>?</div>\n<div class=\"quiz-option\" style=\"position:absolute; left:40px; top: 250px; /* width:370px; */ /* height:80px; */ \">\n<input dir=\"auto\" class=\"quiz-input\" type=\"radio\" name=\"answer[9326a7b17e15cfc69f8e46f9357bf6c5][]\" id=\"gensym_52bed85054bc8\" value=\"ad32510af7c53e2fa6cce4d764c09800\"><label for=\"gensym_52bed85054bc8\" style=\"cursor:pointer;\"><code>i == 0 and j == -1</code> </label>\n</div>\n<div class=\"quiz-option\" style=\"position:absolute; left:40px; top: 320px; /* width:370px; */ /* height:80px; */ \">\n<input dir=\"auto\" class=\"quiz-input\" type=\"radio\" name=\"answer[9326a7b17e15cfc69f8e46f9357bf6c5][]\" id=\"gensym_52bed85055221\" value=\"8d53ca2fa487cfbb4479ce2bf7f2e295\"><label for=\"gensym_52bed85055221\" style=\"cursor:pointer;\"><code>i == 0 and j == 0</code> </label>\n</div>\n<div class=\"quiz-option\" style=\"position:absolute; left:430px; top: 250px; /* width:380px; */ /* height:80px; */ \">\n<input dir=\"auto\" class=\"quiz-input\" type=\"radio\" name=\"answer[9326a7b17e15cfc69f8e46f9357bf6c5][]\" id=\"gensym_52bed850558b5\" value=\"94023160fe66f684740c119a18e39a9e\"><label for=\"gensym_52bed850558b5\" style=\"cursor:pointer;\"><code>i == 0 and j == 1</code> </label>\n</div>\n<div class=\"quiz-option\" style=\"position:absolute; left:430px; top: 320px; /* width:380px; */ /* height:80px; */ \">\n<input dir=\"auto\" class=\"quiz-input\" type=\"radio\" name=\"answer[9326a7b17e15cfc69f8e46f9357bf6c5][]\" id=\"gensym_52bed85055eba\" value=\"ff8f062afa22c18eb5c2d4c557bcd44b\"><label for=\"gensym_52bed85055eba\" style=\"cursor:pointer;\"><code>i == 1 and j == 0</code> </label>\n</div>",
"background": "color",
"background_src": "white",
"post_answer_url": "https:\/\/class.coursera.org\/programming2-001\/quiz\/video_quiz_attempt?method=post_question_answer&quiz_id=18&preview=0&question_id=9326a7b17e15cfc69f8e46f9357bf6c5"
}
]
}
}
};
$scope.loadLecture();
});
}]);
angular.module("easylearncode.admin.quiz", ["easylearncode.admin.core"])
.config(["$locationProvider", "$routeProvider", function ($locationProvider, $routeProvider) {
Expand Down Expand Up @@ -611,10 +812,10 @@ angular.module("easylearncode.admin.quiz", ["easylearncode.admin.core"])
modalInstance.result.then(function (addForm) {
quiz = {}
_.each(addForm.form_fields, function (ele) {
if(ele.field_type == "date"){
if (ele.field_type == "date") {
ele.field_value = new Date(ele.field_value);
}
if(ele.field_title == "week"){
if (ele.field_title == "week") {
ele.field_value = parseInt(ele.field_value);
}
quiz[ele.field_title] = ele.field_value;
Expand Down Expand Up @@ -645,10 +846,10 @@ angular.module("easylearncode.admin.quiz", ["easylearncode.admin.core"])
modalInstance.result.then(function (addForm) {
quiz_tmp = {}
_.each(addForm.form_fields, function (ele) {
if(ele.field_type == "date"){
if (ele.field_type == "date") {
ele.field_value = new Date(ele.field_value);
}
if(ele.field_title == "week"){
if (ele.field_title == "week") {
ele.field_value = parseInt(ele.field_value);
}
quiz_tmp[ele.field_title] = ele.field_value;
Expand Down
Loading