// /* global _, angular, i18n, Ladda, Odometer */
'use strict';
angular.module('PromptSkill.learners', [])
.directive('courseIntro', [function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
attrs.$observe('courseIntro', function(code)
{
if(code) {
var background = scope.course.poster;
var videoUrl = scope.course.video_url;
var $introduction = $('
').addClass('bold underline-text short').text(scope.$eval("'Course Recommendation' | phrase:locale"));
var $backgroundBlur = $('').addClass('background-blur valign-wrapper');
var $container = $('').addClass('container');
$container.append($introduction);
if(background != '' && videoUrl == '') {
var $bannerIntro = $('
').attr('src', background).attr('width', '100%');
$container.append($bannerIntro);
element.append($backgroundBlur.append($container));
}
else if(videoUrl != '') {
var $video = $('').addClass('responsive-video').attr('controls', 'controls').attr('muted', 'muted').attr('width', '100%');
var $source = $('').attr('type', 'video/mp4');
// poster
if(background) {
$video.attr('poster', background);
}
$source.attr('src', videoUrl);
$video.append($source);
$container.append($video);
element.append($backgroundBlur.append($container));
}
else element.remove();
}
//
});
}
}
}])
.directive('courseInstructor', [function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
attrs.$observe('courseInstructor', function()
{
// console.log(scope.course);
if(scope.course.instructors) {
var $container = $('').addClass('container');
var $row = $('').addClass('row grid');
var $title = $('').addClass('bold underline-text short');
if(scope.course.title_text.instruction) {
$container.append($title.text(scope.$eval("'"+scope.course.title_text.instruction+"' | phrase:locale")))
}
if(scope.course.instructors[1]) {
angular.forEach(scope.course.instructors, function(instructor, key) {
var $col = $('
').addClass('col s6 m4 l3');
var $gradient = $('').css({position:'absolute',top:0,width:'100%',height:'100%'}).addClass('Black');
var $photo = $('').addClass('shadow gradient photo');
$photo.css('background-color', '#666666');
$photo.css('background-image', "url('"+instructor.image+"')");
$photo.css('padding-top', 670 / 400 * 100+'%');
$photo.css('position','relative');
var $instructor = $('').addClass('bottom wrapper center white-text');
var $fullname = $('').addClass('name');
$fullname.html(instructor.name.firstname + '
' + instructor.name.lastname);
$instructor.append($fullname);
if(instructor.title) {
var $divPosition = $('');
// var $hr = $('
').addClass('thick short').css('background-color', '#EE7115');
var $hr = $('
').addClass('thick short').css('background-color', 'red');
var $position = $('').addClass('brief').html(instructor.title);
$divPosition.append($hr).append($position);
$instructor.append($divPosition);
}
$photo.append($gradient).append($instructor);
$col.append($photo);
$container.append($row.append($col));
});
}else {
element.remove();
}
element.append($container);
}
});
}
}
}])
.directive('courseReview', [function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
attrs.$observe('courseReview', function(code)
{
if(code) {
// console.log(scope.course)
if(scope.course.reviews.length) {
let section_header = 'Course Review';
// change header text insight cv course
if(code=='PS66002') {
section_header = 'InsightCV Testimonials';
}
const $valignWrapper = $('').addClass('valign-wrapper');
const $container = $('').addClass('container');
const $title = $('').addClass('bold underline-text short').text(scope.$eval(`'${section_header}' | phrase:locale`));
const $carousel = $('').addClass('carousel carousel-slider');
const $btnPrev = $('').addClass('btn-prev').append($('
').attr('src', '//services.promptskill.com/app/public/img/icon/icon-arrow-prev.svg'));
const $btnNext = $('').addClass('btn-next').append($('
').attr('src', '//services.promptskill.com/app/public/img/icon/icon-arrow-next.svg'));
//
angular.forEach(scope.course.reviews, function(item) {
const $carouselItem = $('').addClass('carousel-item').attr('href', '');
const $img = $('
').attr('src', item);
$carouselItem.append($img);
$carousel.append($carouselItem);
});
$carousel.append($btnPrev).append($btnNext);
$container.append($title).append($carousel);
$valignWrapper.append($container);
element.append($valignWrapper);
//
scope.$watch(element, function(){
$carousel.carousel({
fullWidth: true,
indicators: true
});
$carousel.find('.btn-prev').click(function(e) {
e.preventDefault();
e.stopPropagation();
$carousel.carousel('prev');
});
$carousel.find('.btn-next').click(function(e) {
e.preventDefault();
e.stopPropagation();
$carousel.carousel('next');
});
});
} else {
element.remove();
}
}
});
}
}
}])
.directive('courseSupport', [function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
attrs.$observe('courseSupport', function(code)
{
if(code) {
if(scope.course.supports.length) {
let section_header = 'Course Support';
// change header text insight cv course
if(code=='PS66002') {
section_header = 'Career Support';
}
const $valignWrapper = $('').addClass('valign-wrapper');
const $container = $('').addClass('container');
const $title = $('').addClass('bold underline-text short').text(scope.$eval(`'${section_header}' | phrase:locale`));
const $carousel = $('').addClass('carousel carousel-slider');
const $btnPrev = $('').addClass('btn-prev').append($('
').attr('src', '//services.promptskill.com/app/public/img/icon/icon-arrow-prev.svg'));
const $btnNext = $('').addClass('btn-next').append($('
').attr('src', '//services.promptskill.com/app/public/img/icon/icon-arrow-next.svg'));
//
angular.forEach(scope.course.supports, function(item) {
const $carouselItem = $('').addClass('carousel-item').attr('href', '');
const $img = $('
').attr('src', item);
$carouselItem.append($img);
$carousel.append($carouselItem);
});
$carousel.append($btnPrev).append($btnNext);
$container.append($title).append($carousel);
$valignWrapper.append($container);
element.append($valignWrapper);
//
element.ready(function() {
$carousel.carousel({
fullWidth: true,
indicators: true
});
$carousel.find('.btn-prev').click(function(e) {
e.preventDefault();
e.stopPropagation();
$carousel.carousel('prev');
});
$carousel.find('.btn-next').click(function(e) {
e.preventDefault();
e.stopPropagation();
$carousel.carousel('next');
});
});
} else {
element.remove();
}
}
});
}
}
}])
.directive('courseOutline', ['$filter', '$timeout', function($filter, $timeout) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
attrs.$observe('courseOutline', function(total) {
//
if(total) {
var $container = $('').addClass('container');
var $row = $('').addClass('row');
var $title = $('').addClass('head-text underline-text')
if(scope.course.title_text.outline) {
$container.append($title.text(scope.course.title_text.outline))
}
//
if(scope.course.outlines.length) {
let outlineShow = 0;
angular.forEach(scope.course.outlines, function(outline, key) {
if(outline.show) {
var $outline = $('
').addClass('outline col s12 m4 l4');
var $title = $('').addClass('title dbadman bold relative');
var $chapter = $('').addClass('outdent right-align').text(outline.item);
var $brief = $('').addClass('brief normal light').append($('').text(outline.brief));
var $btnReadMore = $('').addClass('btn-flat btn-read-more small regular text-transform-unset').text($filter('phrase')('Read more', scope.locale));
//
$title.append($chapter).append($('').text(outline.title));
$outline.append($title).append($brief);
$timeout(function() {
const textElement = $brief.find('span');
const lineHeight = parseFloat(textElement.css('line-height'));
const maxLines = parseFloat($brief.css('-webkit-line-clamp'));
//
const maxHeight = lineHeight * maxLines;
const actualHeight = textElement.height();
if (actualHeight > maxHeight) $outline.append($btnReadMore);
}, 400);
$btnReadMore.on('click', function() {
$('.outlines .outline .btn-flat').show();
$('.outlines .outline .brief').css({
overflow: 'hidden',
height: '9em',
marginBottom: '0',
webkitBoxOrient: 'vertical',
webkitLineClamp: '6'
});
//
$brief.css({
overflow: 'visible',
height: 'fit-content',
marginBottom: $btnReadMore.height(),
webkitBoxOrient: 'unset',
webkitLineClamp: 'unset'
});
$('.outlines .outline .btn-flat').css('margin-bottom', $brief.height() - 162 + 'px');
$btnReadMore.hide();
});
$container.append($row.append($outline));
if(scope.course.type=='live') {
$outline.append($('').addClass('date-calendar normal medium').text(outline.type.textdate))
$outline.append($('').addClass('time normal medium').text(outline.type.time))
$outline.append($('
').attr('src', outline.type.icon).css('margin-top', '1em'))
}
outlineShow++;
}
});
//
if(outlineShow == 0) {
element.remove();
}
}else {
element.remove();
}
// Background
if(scope.course.bg_outline) {
var img = new Image();
img.onload = function() {
element.css('height', this.height);
}
if (scope.course.bg_outline.indexOf("http://") != 0 || scope.course.bg_outline.indexOf("https://") != 0) {
img.src = 'https:' + scope.course.bg_outline;
}
img.src = scope.course.bg_outline;
element.css("background-image", "url('"+scope.course.bg_outline+"')").addClass('cover');
// element.css('background-image', 'url('+scope.course.bg_outline+')').addClass('cover');
}
element.append($container);
}
});
}
}
}])
.directive('courseDocument', [function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
attrs.$observe('courseDocument', function(code) {
//
if(code && !_.isUndefined(scope.course.books)) {
// console.log(scope.course.books);
if(Object.keys(scope.course.books).length) {
var $container = $('').addClass('container').css('margin-top', '2em');
var $header = $('').addClass('black-text bold').text('เอกสารประกอบการเรียน');
var $msg = $('').addClass('red-text regular center-align').css('margin', '6rem 0');
var $row = $('').addClass('row');
$container.append($header);
// check enroll course
scope.service.course.state(code).then(function(response) {
var state = response.code;
// console.log(response);
//
if(code && !_.isUndefined(state)) {
if(state=='continue' || state=='review' || state=='start') {
//
angular.forEach(scope.course.books, function(item) {
if(item.file) {
var cover = item.cover ? item.cover : '/public/img/background/background-no-picture-500x500.jpg';
//
var $col = $('').addClass('col s6 m3 l2');
var $action = $('').attr('href', item.file).attr('target', '_blank').attr('download', item.title);
var $image = $('
').addClass('document-image').attr('src', cover).attr('alt', item.title);
var $title = $('').addClass('document-title black-text regular truncate-3').text(item.title);
//
$action.append($image).append($title);
$row.append($col.append($action));
}
});
$container.append($row);
} else {
$msg.text('กรุณาลงทะเบียนเรียน เพื่อดาวน์โหลดเอกสารประกอบการเรียน');
$container.append($msg);
}
} else {
$msg.text('กรุณาลงทะเบียนเรียน เพื่อดาวน์โหลดเอกสารประกอบการเรียน');
$container.append($msg);
}
element.append($container).show();
});
//
} else element.hide();
} else element.hide();
//
});
}
}
}])
.directive('courseType', [function() {
return {
restrict: 'A',
link: function(scope, element, attrs)
{
attrs.$observe('courseType', function(type)
{
if(type) {
var image = '//services.promptskill.com/app/public/img/icon/icon-'+type+'.png';
var $img = $('
').css('width', '8.5em');
$img.css('margin-top', '2em');
var img = new Image();
img.onload = function() {
$img.attr('src', image);
element.append($img);
}
img.src = 'https:' + image;
}
});
}
}
}])
.directive('courseActivity', [function() {
return {
restrict: 'A',
link: function(scope, element, attrs)
{
attrs.$observe('courseActivity', function (code) {
if(code) {
// console.log(scope.course)
scope.service.user.lrsConnect(code).then(function(result) {
// console.log(result)
scope.$parent.lrs = result.lrs;
scope.$parent.lrs['id'] = result.lrsid;
// console.log(scope.lrs)
result.sess.then(function(sess) {
// console.log(sess.data)
scope.$parent.lrs.token = sess.data.token;
scope.activity = scope.course.activity;
// console.log(scope.activity)
})
scope.outline = scope.course.outline;
});
}
});
}
}
}])
.directive('courseNavigator', ['$location', '$timeout', '$window', function($location, $timeout, $window) {
return {
restrict: 'A',
templateUrl: '/templates/blocks/course-navigator.promptskill',
link: function(scope, element, attrs) {
//
var navigator = '';
//
var nav = 0;
var navi = [];
var path = $location.path();
//
attrs.$observe('courseNavigator', function(data) {
if(data !='') {
element.removeAttr('course-navigator');
scope.service.course.navigator(angular.fromJson(data)).then(function(course) {
scope.navigator = course;
navigator = course.control;
// console.log(scope.lrs)
// console.log(navigator)
//
// console.log(course)
/*
navi = course.navigator;
//console.log(course.navigator)
angular.forEach(course.navigator, function(value, index) {
//console.log(index)
if($location.path().indexOf(value) >0) {
nav = index;
}
});
*/
})
}
});
// call function
scope.prevActivity = function() {
scope.scrollToTop();
if(navigator.prev.activity=='') $location.path('/course/'+scope.navigator.code);
//
$location.path('/course/'+scope.navigator.code+'/'+navigator.prev.activity);
}
scope.nextActivity = function() {
//
if(navigator.next.activity!='') {
// scope.scrollToTop();
// console.log(navigator.next.activity)
// if(navigator.next.activity=='next') {
// console.log($location.path().split('/')[4])
scope.service.learner.completion(scope.navigator.code, $location.path().split('/')[4])
.then(function(activity) {
// console.log(activity); return;
// console.log(navigator.next.activity)
if(activity == 'payment'){
Swal.fire({
title: "มีบางอย่างผิดพลาด",
text: "ท่านอยู่ในช่วงทดลองเรียน\nกรุณาชำระเงินเพื่อเรียนต่อ\nในบทถัดไป",
icon: "warning",
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#d33",
confirmButtonText: "ชำระเงิน"
}).then((result) => {
if (result.isConfirmed) {
$window.location = '/enrol/'+scope.navigator.code;
}
});
return;
}
if(activity !='alert') {
//
if(scope.activity.type=='test') {
var grade = scope.lrs.url+'/mod/'+scope.activity.module+'/review.php?id=869&course=56'+'&userid='+scope.lrs.id;
scope.service.learner.grade(grade)
}
// console.log(navigator.next.activity); return;
if(navigator.next.activity !='next') {
if(navigator.next.activity=='certificate') {
scope.service.user.certificate(scope.navigator.code)
scope.service.course.completion(scope.navigator.code).then(function(status) {
// console.log(status)
// console.log(scope.service.user.certificate());
scope.service.user.certificate(status.course);
scope.scrollToTop();
$location.path(`/course/${scope.navigator.code}/certificate`);
// scope.$parent.alert = {"msg":'ระบบออกใบประกาศ'};
});
} else if (navigator.next.activity=='complete') {
scope.service.course.completion(scope.navigator.code).then(function(status) {
// console.log(status)
// console.log(scope.service.user.certificate());
scope.scrollToTop();
// $location.path(`/course/${scope.navigator.code}/complete`);
$window.location.href = scope.gotoParamUrl('https://promptskill.com/dashboard');
// scope.$parent.alert = {"msg":'ระบบออกใบประกาศ'};
});
}
else {
if(navigator.next.activity!='schedule') {
scope.scrollToTop();
$location.path('/course/'+scope.navigator.code+'/'+navigator.next.activity);
}
}
} else {
scope.scrollToTop();
$location.path('/course/'+scope.navigator.code+'/'+activity);
}
} else {
scope.$parent.alert = {"msg":'กรุณาเรียนให้จบหรือตอบคำถามให้ครบ
ก่อนเรียนบทต่อไป'};
}
});
// } else {
// if(navigator.next.activity=='certificate') {
// scope.scrollToTop();
// scope.certificate = {"course":scope.navigator.code};
//$location.path('/certificate');
//else $location.path('/course/'+scope.navigator.code+'/'+navigator.next.activity);
// }
// }
} else {
scope.$parent.alert = {"msg":'กรุณาเรียนให้จบหรือตอบคำถามให้ครบ
ก่อนเรียนบทต่อไป'};
//console.log(scope.alert)
}
}
scope.showPanel = function() {
//console.log('show panel');
var $panel = angular.element('#course-navigator .panel')
var $coursePanel = angular.element('#course-navigator .course-panel');
//
if ($coursePanel.hasClass('show')) {
$coursePanel.removeClass('show')
//$coursePanel.attr('style', null);
//$coursePanel.children('.message-wrapper').remove();
//$coursePanel.children('.timeline-wrapper').show();
} else {
scope.$parent.alert = {"msg":""};
//var fontSize = parseFloat($coursePanel.css('font-size'));
$coursePanel.addClass('show');
// $timeout(function() {
// $coursePanel.removeClass('show')
// }, 7000);
}
}
scope.gotoActivity = function(outline, activity) {
if(activity!=undefined) {
scope.scrollToTop().then(function() {
$location.path('/course/'+scope.navigator.code+'/'+outline+'/'+activity);
});
}
}
}
}
}])
/* .directive('toggle', [function() {
return {
restrict: 'C',
link: function(scope, element, attr)
{
element.on('click', function() {
//console.log(element)
if (element.hasClass('current')) {
element.removeClass('current')
//element.addClass('done')
} else {
$(element).parent().find('.toggle.current').removeClass('current');
element.addClass('current')
}
});
}
}
}]) */
/* learner */
.directive('courseProgress', [function() {
return {
restrict: 'A',
templateUrl: 'templates/blocks/course-progress.promptskill',
link: function(scope, element, attrs)
{
//console.log(attrs.scale)
attrs.$observe('courseProgress', function(progress) {
//scope.service.user.courseProgress(code).then(function(data) {
scope.scale = attrs.scale;
scope.progress = progress;
//scope.scored = data.scored;
//});
});
}
}
}])
.directive('courseCertificate', ['$routeParams', function($routeParams) {
return {
restrict: 'A',
link: function(scope, element, attrs)
{
// console.log('courseCert');
var code = !_.isUndefined($routeParams.code) ? $routeParams.code : scope.service.user.certificate();
// var code = $routeParams.code;
var course = {code: code};
// console.log(code)
//scope.service.program.info().then(function(program) {
//course['course_id'] = program.program_id;
scope.service.course.content(course).then(function(content) {
// console.log(content)
scope.$parent.course = content;
//console.log(scope.course)
});
//});
scope.service.course.certificate(code).then(function(cert) {
// console.log(cert)
scope.cert = cert;
})
}
}
}])
.directive('embedCert', ['$routeParams', function($routeParams) {
return {
restrict: 'A',
link: function(scope, element, attrs)
{
var $iframe = $('').css({width:'100%',height:'100%',position:'absolute',border:'none',top:0, left:0});
attrs.$observe('embedCert', function(certcode)
{
if(certcode) {
// console.log(certcode)
element.removeAttr('embed-cert');
var width = 60;
var height = (11.25 / 16) * width;
element.css('padding-bottom', height + '%');
element.css('width', width + '%');
element.css('margin', '4em auto');
element.css('position', 'relative');
//
var course = !_.isUndefined($routeParams.code) ? $routeParams.code : scope.service.user.certificate();
var download = scope.service.member.center('certificate')+'/download/';
// console.log(course);
scope.service.course.certificated(course).then(function(reference) {
console.log(reference)
if(reference) {
$iframe.attr('src', scope.service.member.center('certificate')+'/viewed/'+reference);
download = download + reference;
} else {
scope.service.user.certificated(certcode).then(function(certificated) {
scope.service.course.certificated(course, certificated);
reference = certificated.reference;
download = download + reference;
$iframe.attr('src', scope.service.member.center('certificate')+'/viewed/'+reference);
});
}
//console.log(download)
$('').addClass('waves-effect waves-light btn z-depth-1 btn-theme normal medium').attr('href', download)
.attr('target','_blank').text(scope.$eval("'Download' | phrase:locale")).appendTo(element.parent());
});
/*
scope.service.user.certificated(certcode).then(function(certificated) {
//console.log(certificated)
var course = scope.service.user.certificate();
scope.service.course.certificated(course, certificated);
});
*/
element.append($iframe);
}
});
}
}
}])
/* LRS */
.directive('activityEmbed', ['$location', function($location) {
return {
restrict: 'A',
link: function(scope, element, attrs)
{
attrs.$observe('activityEmbed', function(module)
{
// console.log('module : '+module)
if(module !='') {
var $script = $('').attr('src', scope.lrs.url+'/mod/hvp/library/js/h5p-resizer.js');
var $iframe = $('').css({width:'100%',height:'100%',border:'none',position:'relative',top:0});
var src = scope.lrs.url+'/mod/'+scope.activity.module+'/embed.php';
var height = scope.activity.height;
$iframe.css('height', parseInt(element.width() * height / 100)+'px');
// element.css('padding-bottom', height+'%');
//element.css('min-height', "16em");
// console.log(height);
//element.css('padding-top', "3em");
//element.css("background-color", "#ffffff");
element.css('position', 'relative');
//
// scope.service.learner.completed($location.path().split('/')[2], $location.path().split('/')[4]).then(function(activity) {
// console.log('type:'+scope.activity.type);
if(scope.activity.module !='hvp') {
// console.log(scope.activity.schedule.end);
// src = '/module/'+scope.activity.module+'/embed.php#learnerid='+scope.navigator.learnerid+'&course='+scope.navigator.code+'&token='+btoa(angular.toJson(activity));
src = '/module/'+scope.activity.module+'/embed.php#learnerid='+scope.navigator.learnerid+'&course='+scope.navigator.code+'&token='+scope.service.user.token();
if(scope.activity.schedule.end) src += '&expired='+scope.activity.schedule.end;
// console.log(src);
}else {
src += '?id='+module
if(['quiz','test'].includes(scope.activity.type)) {
$iframe.css('padding', '1em 2em 0').addClass('white');
$iframe.attr('scrolling', 'yes');
}
}
$iframe.attr('src', src);
// });
//
// if(module !='') {
//console.log(scope.lrs.token)
//console.log(src + '?id='+module + '&secret='+scope.lrs.token + '&userid='+scope.lrs.id)
element.append($iframe);
// $iframe.attr('src', src);
//console.log($('#moobed'))
//$iframe.onload = function() {
//console.log(script)
//element.append($script);
//}
if(scope.activity.module =='hvp') {
if(scope.mobile || scope.tablet) {
element.append($script);
}
}
}
});
}
}
}])
.factory('learner', function($q, $http, $window, $location,$cookies, program) {
//
var baseUrl = '//cms.promptskill.com/restapi/learner';
var serviceUrl = '//services.promptskill.com/restful';
return {
clear: function() {
store.set('user', {});
store.set('token', '');
//store.destroy();
},
token: function() {
return $cookies.get('token');
// return _.isUndefined(store.get('token')) ?'' :store.get('token');
},
sesskey: function(sess) {
var user = _.isUndefined(store.get('user')) ? {} : store.get('user');
if(sess!=undefined) {
user.sesskey = sess;
store.set('user');
}
return user.sesskey;
},
grade: function(url) {
$http.get(url).then(function(response) {
data = response.data;
console.log(data)
})
},
// enrol: function(course) {
// var deferred = $q.defer();
// var postdata = {};
// postdata['program'] = program.key();
// // console.log(postdata)
// $http.post(baseUrl + '/enrol/' + course , postdata, {
// headers: {
// 'Authorization': 'Bearer ' + this.token(),
// },
// }).then(function(response) {
// deferred.resolve(response.data)
// });
// return deferred.promise;
// },
activity: function(course, outline, module) {
var postdata = {};
postdata['program'] = program.key();
postdata['outline'] = outline;
postdata['module'] = module;
//console.log(postdata)
$http.post(baseUrl + '/activity/' + course , postdata, {
headers: {
'Authorization': 'Bearer ' + this.token(),
},
}).then(function(response) {
})
},
lrsConnect: function(code) {
var deferred = $q.defer();
console.log(this.token())
// console.log(baseUrl + '/lrs/' + code);
$http.get(baseUrl + '/lrs/' + code, {
headers: {
'Authorization': 'Bearer ' + this.token(),
},
}).then(function(response) {
var userdata = response.data;
//console.log(userdata)
var endpoint = userdata.lrs.url+'/login/token.php?';
var params = 'username='+userdata.username+'&password='+userdata.password+'&service=moodle_mobile_app';
var config = {withCredentials: true, origin:true};
//console.log(endpoint + params)
deferred.resolve({lrsid:userdata.lrsid, lrs:userdata.lrs, sess:$http.get(endpoint + params, config)});
})
return deferred.promise;
},
lrsDisconnect: function(lrs) {
var deferred = $q.defer();
//console.log(lrs)
var endpoint = lrs.url+'/login/logout.php?';
var params = 'sesskey='+lrs.token;
var config = {withCredentials: true, origin:true};
// console.log(endpoint + params)
deferred.resolve($http.get(endpoint + params, config));
return deferred.promise;
},
completion: function(course, activity) {
var deferred = $q.defer();
// console.log(this.token());
// console.log(baseUrl+'/completion/'+course+'/'+activity)
$http.get(baseUrl+'/completion/'+course+'/'+activity, {
headers: {
'Authorization': 'Bearer ' + this.token(),
}
}).then(function(response) {
// console.log(response.data);
deferred.resolve(response.data);
});
return deferred.promise;
},
completed: function(course, activity) {
var deferred = $q.defer();
// console.log(baseUrl+'/completed/'+course+'/'+activity)
$http.get(baseUrl+'/completed/'+course+'/'+activity, {
headers: {
'Authorization': 'Bearer ' + this.token(),
}
}).then(function(response) {
//console.log(response.data);
deferred.resolve(response.data);
});
return deferred.promise;
},
progress: function(course) {
var deferred = $q.defer();
$http.get(baseUrl+'/progress/'+course, {
headers: {
'Authorization': 'Bearer ' + this.token(),
}
}).then(function(response) {
// console.log(response.data);
deferred.resolve(response.data);
})
return deferred.promise;
},
certificate: function(code) {
if(_.isUndefined(code))
return _.isUndefined(store.get('certificate')) ?'' :store.get('certificate');
// console.log(code)
store.set('certificate', code);
},
certificated: function(certcode) {
var deferred = $q.defer();
$http.get(serviceUrl + '/certificate/issued/'+certcode).then(function(response) {
// console.log(response.data);
deferred.resolve(response.data);
});
return deferred.promise;
}
}
})