Files
edx-platform/cms/static/js/views/utils/create_course_utils.js
Zia Fazal 2cb2233dde initial change set. add org autocomplete
added unit tests and fixed JS tests

added bok choy tests

fixed broken botchoy tests

fixed course discovery broken test

removed monkey patch at class level

changes after feedback from matte
2015-12-11 18:39:55 +05:00

37 lines
1.6 KiB
JavaScript

/**
* Provides utilities for validating courses during creation, for both new courses and reruns.
*/
define(["jquery", "gettext", "common/js/components/utils/view_utils", "js/views/utils/create_utils_base"],
function ($, gettext, ViewUtils, CreateUtilsFactory) {
"use strict";
return function (selectors, classes) {
var keyLengthViolationMessage = gettext("The combined length of the organization, course number, and course run fields cannot be more than <%=limit%> characters.");
var keyFieldSelectors = [selectors.org, selectors.number, selectors.run];
var nonEmptyCheckFieldSelectors = [selectors.name, selectors.org, selectors.number, selectors.run];
CreateUtilsFactory.call(this, selectors, classes, keyLengthViolationMessage, keyFieldSelectors, nonEmptyCheckFieldSelectors);
this.setupOrgAutocomplete = function(){
$.getJSON('/organizations', function (data) {
$(selectors.org).autocomplete({
source: data
});
});
};
this.create = function (courseInfo, errorHandler) {
$.postJSON(
'/course/',
courseInfo,
function (data) {
if (data.url !== undefined) {
ViewUtils.redirect(data.url);
} else if (data.ErrMsg !== undefined) {
errorHandler(data.ErrMsg);
}
}
);
};
};
});