{"size": 3607, "ext": "js", "max_stars_repo_path": "src/assets/js/students/my_plan/my_plan_helper.js", "max_stars_repo_name": "WingsUpete/courschemaster", "max_stars_repo_stars_event_min_datetime": "2019-09-26T07:12:18.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-29T06:26:52.000Z", "max_issues_repo_path": "src/assets/js/students/my_plan/my_plan_helper.js", "max_issues_repo_name": "WingsUpete/courschemaster", "max_issues_repo_issues_event_min_datetime": "2020-12-16T08:04:27.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-16T08:22:08.000Z", "max_forks_repo_path": "src/assets/js/students/my_plan/my_plan_helper.js", "max_forks_repo_name": "WingsUpete/courschemaster", "max_forks_repo_forks_event_min_datetime": "2019-09-27T03:51:11.000Z", "max_forks_repo_forks_event_max_datetime": "2019-09-27T03:51:11.000Z"}
{"max_stars_count": 8, "max_issues_count": 1, "max_forks_count": 1, "avg_line_length": 26.7185185185, "max_line_length": 227, "alphanum_fraction": 0.5980038813}
(function () {

    'use strict';

    /**
     * MyPlanHelper Class
     *
     * This class contains the methods that are used in the My Plan page.
     *
     * @class MyPlanHelper
     */
    function MyPlanHelper() {
		this.planCourses = [];
        this.courseMarket = [];
    }

    /**
     * Binds the default event handlers of the My Plan page.
     */
    MyPlanHelper.prototype.bindEventHandlers = function () {
        var instance = this;

		// Listners
		
		/**
		 * Input New Plan Name
		 */
		var t_npn = null;
		$('#new_plan_name').on('keyup', function() {
			if (t_npn) {
				clearTimeout(t_npn);
			}
			var obj = $(this);
			t_npn = setTimeout(function() {
				if (!GeneralFunctions.checkEmpty(obj)) {
					return;
				}
				if (!GeneralFunctions.checkTooManyWords(obj, 100)) {
					return;
				}
				//	true
				obj.removeClass('is-valid, is-invalid').addClass('is-valid');
			}, 300);
		}).trigger('keyup');
		
		$('#new_plan-submit').click(function() {
			instance.addPlan();
		});
		
	};

	//	Additional Methods
	
	/**
     * get my plan
     */
    MyPlanHelper.prototype.getPlans = function () {
		//	AJAX
        var postUrl = GlobalVariables.baseUrl + '/index.php/my_plans_api/ajax_get_my_plans';
        var postData = {
            csrfToken: GlobalVariables.csrfToken,
			courschema_id: GlobalVariables.courschemaId
        };
		
		var obj = this;
		
        return $.post(postUrl, postData, function (response) {
			//	Test whether response is an exception or a warning
            if (!GeneralFunctions.handleAjaxExceptions(response)) {
                return;
            }
			
			console.log(response);
			obj.planCourses = response;
			
        }.bind(this), 'json').fail(GeneralFunctions.ajaxFailureHandler);
    };
	
	/**
     * get my plan
     */
    MyPlanHelper.prototype.addPlan = function () {
		if ($('#new_plan_name').hasClass('is-invalid')) {
			GeneralFunctions.displayMessageAlert(SCLang.invalid_feedback, 'danger', 6000);
			return;
		}
		//	AJAX
        var postUrl = GlobalVariables.baseUrl + '/index.php/my_plans_api/ajax_add_plan';
        var postData = {
            csrfToken: GlobalVariables.csrfToken,
			plan_name: JSON.stringify($('#new_plan_name').val())
        };
		
		var obj = this;
		
        return $.post(postUrl, postData, function (response) {
			//	Test whether response is an exception or a warning
            if (!GeneralFunctions.handleAjaxExceptions(response)) {
                return;
            }
			
			console.log(response);
			$('.plan-titles').append('<li class=""nav-item><a class="nav-link font-weight-bold" data-toggle="tab" data-plan=id="' + response.plan_id + '" href="javascript:void(0); role="tab">' + $('#new_plan_name').val() + '</a></li>');
			$('#newPlanWindow').modal('hide');
			
        }.bind(this), 'json').fail(GeneralFunctions.ajaxFailureHandler);
    };
	
	/**
     * get details of courses
     */
    MyPlanHelper.prototype.retrieveCourses = function () {
		//	AJAX
        var postUrl = GlobalVariables.baseUrl + '/index.php/course_api/ajax_get_all_course_full_info';
        var postData = {
            csrfToken: GlobalVariables.csrfToken
        };
		
		var obj = this;
		
        return $.post(postUrl, postData, function (response) {
			//	Test whether response is an exception or a warning
            if (!GeneralFunctions.handleAjaxExceptions(response)) {
                return;
            }
			
//			console.log(response);
			obj.courseMarket = response;
			
        }.bind(this), 'json').fail(GeneralFunctions.ajaxFailureHandler);
    };
	
    window.MyPlanHelper = MyPlanHelper;
})();
