/* global _, angular, i18n, Ladda, Odometer */ 'use strict'; angular.module('Client.programs', []) /* course program */ .directive('courseContent', [function() { return { link: function(scope, element, attrs) { var $btState = $('').addClass('waves-effect waves-light btn z-depth-1 white-text red normal medium'); $btState.text('รายละเอียดเพิ่มเติม'); // element.append($btState); // attrs.$observe('courseContent', function(code) { // console.log(code+':'+!code.startsWith('2', 5)) if(code) { // if(!code.startsWith('2', 5)) { element.append($btState); element.removeAttr('course-content'); //console.log(element) if(element.hasClass('disabled')) { $btState.addClass('disabled').text('ปิดการเรียนชั่วคราว'); } $btState.addClass('more-detail').on('click', function() { scope.gotoUrl('/course/'+code); }); } }); } } }]) .directive('courseState', [function() { return { restrict: 'A', link: function(scope, element, attrs) { var $btState = $('').addClass('waves-effect waves-light btn z-depth-1 white-text red normal medium'); $btState.text('ลงทะเบียน'); // element.append($btState); attrs.$observe('courseState', function(code) { if(code) { // if(!code.startsWith('2', 5)) { element.removeAttr('course-state') // console.log(course) scope.service.course.state(code).then(function(state) { // console.log(state) //console.log(scope.service.user.token()) if(scope.service.user.token()=='') { state.text = 'ลงทะเบียน'; state.code = 'register'; } $btState.addClass(state.code).text(state.text).on('click', function() { element.find('a').addClass('normal regular disabled'); if(state.code=='register') { scope.gotoUrl('/signin') //scope.service.program.info().then(function(program) { //if(program.registration) { //scope.scrollToTop(); //$location.path('/register/'+program.registration); //} //}); } else { if(state.code=='enrol') { element.on('click', function() { element.find('a').addClass('normal regular disabled').text('กำลังโหลด...').unbind("click"); }); } //scope.service.program.info().then(function(program) { //console.log(program) //if(program.registration) { // scope.gotoPage('/register/'+program.registration); //} else { scope.service.course.apply(code, state) //} //}); //scope.service.course.apply(code, state).then(function(result) { //console.log(result) //}); } }); // setTimeout(function() { element.append($btState); // }, 300); // }); } }); } } }]) .directive('courseLearn', [function() { return { restrict: 'A', link: function(scope, element, attrs) { var $btState = $('').addClass('waves-effect waves-light btn z-depth-1 white-text red normal medium'); $btState.text('เรียน'); element.append($btState); attrs.$observe('courseLearn', function(code) { if(code) { element.removeAttr('course-learn') $btState.addClass('continue').on('click', function() { scope.service.course.learn(code) }); // scope.service.course.learn(code).then(function(state) { // //console.log(state) // //console.log(scope.service.user.token()) // if(scope.service.user.token()=='') { // state.text = 'ลงทะเบียน'; // state.code = 'register'; // } // $btState.addClass(state.code).text(state.text).on('click', function() { // if(state.code=='register') { // scope.gotoUrl(state.code) // //scope.service.program.info().then(function(program) { // //if(program.registration) { // //scope.scrollToTop(); // //$location.path('/register/'+program.registration); // //} // //}); // } else { // //scope.service.program.info().then(function(program) { // //console.log(program) // //if(program.registration) { // // scope.gotoPage('/register/'+program.registration); // //} else { // scope.service.course.apply(code, state) // //} // //}); // //scope.service.course.apply(code, state).then(function(result) { // //console.log(result) // //}); // } // }) // }); } }); } } }]) .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('แนะนำหลักสูตร'); 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 = $('