Run eslint autofixer on /cms

This commit is contained in:
Brian Jacobel
2016-08-05 12:28:50 -04:00
parent c7042c4879
commit d43e915dab
240 changed files with 7119 additions and 7257 deletions

View File

@@ -1,8 +1,8 @@
define([
'backbone',
'js/programs/utils/auth_utils'
],
function( Backbone, auth ) {
'backbone',
'js/programs/utils/auth_utils'
],
function(Backbone, auth) {
'use strict';
return Backbone.Collection.extend(auth.autoSync);

View File

@@ -1,11 +1,11 @@
define([
'backbone',
'jquery',
'js/programs/utils/api_config',
'js/programs/collections/auto_auth_collection',
'jquery.cookie'
],
function( Backbone, $, apiConfig, AutoAuthCollection ) {
'backbone',
'jquery',
'js/programs/utils/api_config',
'js/programs/collections/auto_auth_collection',
'jquery.cookie'
],
function(Backbone, $, apiConfig, AutoAuthCollection) {
'use strict';
return AutoAuthCollection.extend({
@@ -43,7 +43,7 @@ define([
// Adds a run back into the model for selection
addRun: function(id) {
var courseRun = _.findWhere( this.allRuns, { id: id });
var courseRun = _.findWhere(this.allRuns, {id: id});
this.create(courseRun);
},

View File

@@ -1,9 +1,9 @@
define([
'backbone',
'jquery',
'js/programs/models/program_model'
],
function( Backbone, $, ProgramModel ) {
'backbone',
'jquery',
'js/programs/models/program_model'
],
function(Backbone, $, ProgramModel) {
'use strict';
return Backbone.Collection.extend({

View File

@@ -1,7 +1,7 @@
define([
'backbone'
],
function( Backbone ) {
'backbone'
],
function(Backbone) {
'use strict';
return Backbone.Model.extend({

View File

@@ -1,8 +1,8 @@
define([
'backbone',
'js/programs/utils/auth_utils'
],
function( Backbone, auth ) {
'backbone',
'js/programs/utils/auth_utils'
],
function(Backbone, auth) {
'use strict';
return Backbone.Model.extend(auth.autoSync);

View File

@@ -1,12 +1,12 @@
define([
'backbone',
'jquery',
'js/programs/utils/api_config',
'js/programs/models/auto_auth_model',
'jquery.cookie',
'gettext'
],
function( Backbone, $, apiConfig, AutoAuthModel ) {
'backbone',
'jquery',
'js/programs/utils/api_config',
'js/programs/models/auto_auth_model',
'jquery.cookie',
'gettext'
],
function(Backbone, $, apiConfig, AutoAuthModel) {
'use strict';
return AutoAuthModel.extend({

View File

@@ -1,7 +1,7 @@
define([
'backbone'
],
function( Backbone ) {
'backbone'
],
function(Backbone) {
'use strict';
return Backbone.Model.extend({

View File

@@ -1,8 +1,8 @@
define([
'js/programs/utils/api_config',
'js/programs/models/auto_auth_model'
],
function( apiConfig, AutoAuthModel ) {
'js/programs/utils/api_config',
'js/programs/models/auto_auth_model'
],
function(apiConfig, AutoAuthModel) {
'use strict';
return AutoAuthModel.extend({

View File

@@ -1,12 +1,12 @@
define([
'backbone',
'jquery',
'js/programs/utils/api_config',
'js/programs/models/auto_auth_model',
'gettext',
'jquery.cookie'
],
function( Backbone, $, apiConfig, AutoAuthModel, gettext ) {
'backbone',
'jquery',
'js/programs/utils/api_config',
'js/programs/models/auto_auth_model',
'gettext',
'jquery.cookie'
],
function(Backbone, $, apiConfig, AutoAuthModel, gettext) {
'use strict';
return AutoAuthModel.extend({
@@ -37,7 +37,7 @@ define([
this.url = apiConfig.get('programsApiUrl') + 'programs/' + this.id + '/';
},
validateOrganizations: function( orgArray ) {
validateOrganizations: function(orgArray) {
/**
* The array passed to this method contains a single object representing
* the selected organization; the object contains the organization's key.
@@ -46,61 +46,61 @@ define([
var i,
len = orgArray ? orgArray.length : 0;
for ( i = 0; i < len; i++ ) {
if ( orgArray[i].key === 'false' ) {
for (i = 0; i < len; i++) {
if (orgArray[i].key === 'false') {
return gettext('Please select a valid organization.');
}
}
},
getConfig: function( options ) {
getConfig: function(options) {
var patch = options && options.patch,
params = patch ? this.get('id') + '/' : '',
config = _.extend({ validate: true, parse: true }, {
config = _.extend({validate: true, parse: true}, {
type: patch ? 'PATCH' : 'POST',
url: apiConfig.get('programsApiUrl') + 'programs/' + params,
contentType: patch ? 'application/merge-patch+json' : 'application/json',
context: this,
// NB: setting context fails in tests
success: _.bind( this.saveSuccess, this ),
error: _.bind( this.saveError, this )
success: _.bind(this.saveSuccess, this),
error: _.bind(this.saveError, this)
});
if ( patch ) {
config.data = JSON.stringify( options.update ) || this.attributes;
if (patch) {
config.data = JSON.stringify(options.update) || this.attributes;
}
return config;
},
patch: function( data ) {
patch: function(data) {
this.save({
patch: true,
update: data
});
},
save: function( options ) {
save: function(options) {
var method,
patch = options && options.patch ? true : false,
config = this.getConfig( options );
config = this.getConfig(options);
/**
* Simplified version of code from the default Backbone save function
* http://backbonejs.org/docs/backbone.html#section-87
*/
method = this.isNew() ? 'create' : ( patch ? 'patch' : 'update' );
method = this.isNew() ? 'create' : (patch ? 'patch' : 'update');
this.sync( method, this, config );
this.sync(method, this, config);
},
saveError: function( jqXHR ) {
this.trigger( 'error', jqXHR );
saveError: function(jqXHR) {
this.trigger('error', jqXHR);
},
saveSuccess: function( data ) {
this.set({ id: data.id });
this.trigger( 'sync', this );
saveSuccess: function(data) {
this.set({id: data.id});
this.trigger('sync', this);
}
});
}

View File

@@ -1,9 +1,9 @@
(function() {
'use strict';
require([
'js/programs/views/program_admin_app_view'
],
function( ProgramAdminAppView ) {
'js/programs/views/program_admin_app_view'
],
function(ProgramAdminAppView) {
return new ProgramAdminAppView();
}
);

View File

@@ -1,10 +1,10 @@
define([
'backbone',
'js/programs/views/program_creator_view',
'js/programs/views/program_details_view',
'js/programs/models/program_model'
],
function( Backbone, ProgramCreatorView, ProgramDetailsView, ProgramModel ) {
'backbone',
'js/programs/views/program_creator_view',
'js/programs/views/program_details_view',
'js/programs/models/program_model'
],
function(Backbone, ProgramCreatorView, ProgramDetailsView, ProgramModel) {
'use strict';
return Backbone.Router.extend({
@@ -15,7 +15,7 @@ define([
':id': 'programDetails'
},
initialize: function( options ) {
initialize: function(options) {
this.homeUrl = options.homeUrl;
},
@@ -30,7 +30,7 @@ define([
},
programCreator: function() {
if ( this.programCreatorView ) {
if (this.programCreatorView) {
this.programCreatorView.destroy();
}
@@ -39,20 +39,20 @@ define([
});
},
programDetails: function( id ) {
this.programModel = new ProgramModel({
programDetails: function(id) {
this.programModel = new ProgramModel({
id: id
});
this.programModel.on( 'sync', this.loadProgramDetails, this );
this.programModel.on('sync', this.loadProgramDetails, this);
this.programModel.fetch();
},
/**
* Starts the router.
*/
start: function () {
if ( !Backbone.history.started ) {
start: function() {
if (!Backbone.history.started) {
Backbone.history.start({
pushState: true,
root: this.root

View File

@@ -6,14 +6,14 @@
(function() {
'use strict';
if ( !window.gettext ) {
window.gettext = function (text) {
if (!window.gettext) {
window.gettext = function(text) {
return text;
};
}
if ( !window.interpolate ) {
window.interpolate = function (text) {
if (!window.interpolate) {
window.interpolate = function(text) {
return text;
};
}

View File

@@ -1,7 +1,7 @@
define([
'js/programs/models/api_config_model'
],
function( ApiConfigModel ) {
'js/programs/models/api_config_model'
],
function(ApiConfigModel) {
'use strict';
/**
@@ -16,6 +16,5 @@ define([
}
return instance;
}
);

View File

@@ -1,9 +1,9 @@
define([
'jquery',
'underscore',
'js/programs/utils/api_config'
],
function( $, _, apiConfig ) {
'jquery',
'underscore',
'js/programs/utils/api_config'
],
function($, _, apiConfig) {
'use strict';
var auth = {
@@ -20,11 +20,10 @@ define([
* implementation.
*
*/
sync: function( method, model, options ) {
sync: function(method, model, options) {
var oldError = options.error;
this._setHeaders( options );
this._setHeaders(options);
options.notifyOnError = false; // suppress Studio error pop-up that will happen if we get a 401
@@ -38,7 +37,7 @@ define([
delete options.xhr; // remove the failed (401) xhr from the last try.
// update authorization header
this._setHeaders( options );
this._setHeaders(options);
Backbone.sync.call(this, method, model, options);
}.bind(this));
@@ -54,11 +53,11 @@ define([
* Fix up headers on an imminent AJAX sync, ensuring that the JWT token is enclosed
* and that credentials are included when the request is being made cross-domain.
*/
_setHeaders: function( ajaxOptions ) {
ajaxOptions.headers = _.extend ( ajaxOptions.headers || {}, {
Authorization: 'JWT ' + apiConfig.get( 'idToken' )
_setHeaders: function(ajaxOptions) {
ajaxOptions.headers = _.extend(ajaxOptions.headers || {}, {
Authorization: 'JWT ' + apiConfig.get('idToken')
});
ajaxOptions.xhrFields = _.extend( ajaxOptions.xhrFields || {}, {
ajaxOptions.xhrFields = _.extend(ajaxOptions.xhrFields || {}, {
withCredentials: true
});
},
@@ -67,8 +66,7 @@ define([
* Fetch a new id token from the configured endpoint, update the api config,
* and invoke the specified callback.
*/
_updateToken: function( success ) {
_updateToken: function(success) {
$.ajax({
url: apiConfig.get('authUrl'),
xhrFields: {
@@ -76,10 +74,10 @@ define([
withCredentials: true
},
crossDomain: true
}).done(function ( data ) {
}).done(function(data) {
// save the newly-retrieved id token
apiConfig.set( 'idToken', data.id_token );
}).done( success );
apiConfig.set('idToken', data.id_token);
}).done(success);
}
}
};

View File

@@ -1,10 +1,10 @@
define([
'backbone',
'backbone.validation',
'underscore',
'gettext'
],
function( Backbone, BackboneValidation, _, gettext ) {
'backbone',
'backbone.validation',
'underscore',
'gettext'
],
function(Backbone, BackboneValidation, _, gettext) {
'use strict';
var errorClass = 'has-error',
@@ -14,52 +14,52 @@ define([
// These are the same messages provided by Backbone.Validation,
// marked for translation.
// See: http://thedersen.com/projects/backbone-validation/#overriding-the-default-error-messages.
_.extend( Backbone.Validation.messages, {
required: gettext( '{0} is required' ),
acceptance: gettext( '{0} must be accepted' ),
min: gettext( '{0} must be greater than or equal to {1}' ),
max: gettext( '{0} must be less than or equal to {1}' ),
range: gettext( '{0} must be between {1} and {2}' ),
length: gettext( '{0} must be {1} characters' ),
minLength: gettext( '{0} must be at least {1} characters' ),
maxLength: gettext( '{0} must be at most {1} characters' ),
rangeLength: gettext( '{0} must be between {1} and {2} characters' ),
oneOf: gettext( '{0} must be one of: {1}' ),
equalTo: gettext( '{0} must be the same as {1}' ),
digits: gettext( '{0} must only contain digits' ),
number: gettext( '{0} must be a number' ),
email: gettext( '{0} must be a valid email' ),
url: gettext( '{0} must be a valid url' ),
inlinePattern: gettext( '{0} is invalid' )
_.extend(Backbone.Validation.messages, {
required: gettext('{0} is required'),
acceptance: gettext('{0} must be accepted'),
min: gettext('{0} must be greater than or equal to {1}'),
max: gettext('{0} must be less than or equal to {1}'),
range: gettext('{0} must be between {1} and {2}'),
length: gettext('{0} must be {1} characters'),
minLength: gettext('{0} must be at least {1} characters'),
maxLength: gettext('{0} must be at most {1} characters'),
rangeLength: gettext('{0} must be between {1} and {2} characters'),
oneOf: gettext('{0} must be one of: {1}'),
equalTo: gettext('{0} must be the same as {1}'),
digits: gettext('{0} must only contain digits'),
number: gettext('{0} must be a number'),
email: gettext('{0} must be a valid email'),
url: gettext('{0} must be a valid url'),
inlinePattern: gettext('{0} is invalid')
});
_.extend( Backbone.Validation.callbacks, {
_.extend(Backbone.Validation.callbacks, {
// Gets called when a previously invalid field in the
// view becomes valid. Removes any error message.
valid: function( view, attr, selector ) {
var $input = view.$( '[' + selector + '~="' + attr + '"]' ),
$message = $input.siblings( messageEl );
valid: function(view, attr, selector) {
var $input = view.$('[' + selector + '~="' + attr + '"]'),
$message = $input.siblings(messageEl);
$input.removeClass( errorClass )
.removeAttr( 'data-error' );
$input.removeClass(errorClass)
.removeAttr('data-error');
$message.removeClass( errorClass )
.find( messageContent )
.text( '' );
$message.removeClass(errorClass)
.find(messageContent)
.text('');
},
// Gets called when a field in the view becomes invalid.
// Adds a error message.
invalid: function( view, attr, error, selector ) {
var $input = view.$( '[' + selector + '~="' + attr + '"]' ),
$message = $input.siblings( messageEl );
invalid: function(view, attr, error, selector) {
var $input = view.$('[' + selector + '~="' + attr + '"]'),
$message = $input.siblings(messageEl);
$input.addClass( errorClass )
.attr( 'data-error', error );
$input.addClass(errorClass)
.attr('data-error', error);
$message.addClass( errorClass )
.find( messageContent )
.text( $input.data('error') );
$message.addClass(errorClass)
.find(messageContent)
.text($input.data('error'));
}
});

View File

@@ -1,13 +1,13 @@
define([
'backbone',
'jquery',
'underscore',
'js/programs/utils/constants',
'text!templates/programs/confirm_modal.underscore',
'edx-ui-toolkit/js/utils/html-utils',
'gettext'
],
function( Backbone, $, _, constants, ModalTpl, HtmlUtils ) {
'backbone',
'jquery',
'underscore',
'js/programs/utils/constants',
'text!templates/programs/confirm_modal.underscore',
'edx-ui-toolkit/js/utils/html-utils',
'gettext'
],
function(Backbone, $, _, constants, ModalTpl, HtmlUtils) {
'use strict';
return Backbone.View.extend({
@@ -17,17 +17,17 @@ define([
'keydown': 'handleKeydown'
},
tpl: HtmlUtils.template( ModalTpl ),
tpl: HtmlUtils.template(ModalTpl),
initialize: function( options ) {
this.$parentEl = $( options.parentEl );
initialize: function(options) {
this.$parentEl = $(options.parentEl);
this.callback = options.callback;
this.content = options.content;
this.render();
},
render: function() {
HtmlUtils.setHtml(this.$el, this.tpl( this.content ));
HtmlUtils.setHtml(this.$el, this.tpl(this.content));
HtmlUtils.setHtml(this.$parentEl, HtmlUtils.HTML(this.$el));
this.postRender();
},
@@ -47,10 +47,10 @@ define([
this.$parentEl.html('');
},
handleKeydown: function( event ) {
handleKeydown: function(event) {
var keyCode = event.keyCode;
if ( keyCode === constants.keyCodes.esc ) {
if (keyCode === constants.keyCodes.esc) {
this.destroy();
}
}

View File

@@ -1,19 +1,19 @@
define([
'backbone',
'backbone.validation',
'jquery',
'underscore',
'js/programs/models/course_model',
'js/programs/models/course_run_model',
'js/programs/models/program_model',
'js/programs/views/course_run_view',
'text!templates/programs/course_details.underscore',
'edx-ui-toolkit/js/utils/html-utils',
'gettext',
'js/programs/utils/validation_config'
],
function( Backbone, BackboneValidation, $, _, CourseModel, CourseRunModel,
ProgramModel, CourseRunView, ListTpl, HtmlUtils ) {
'backbone',
'backbone.validation',
'jquery',
'underscore',
'js/programs/models/course_model',
'js/programs/models/course_run_model',
'js/programs/models/program_model',
'js/programs/views/course_run_view',
'text!templates/programs/course_details.underscore',
'edx-ui-toolkit/js/utils/html-utils',
'gettext',
'js/programs/utils/validation_config'
],
function(Backbone, BackboneValidation, $, _, CourseModel, CourseRunModel,
ProgramModel, CourseRunView, ListTpl, HtmlUtils) {
'use strict';
return Backbone.View.extend({
@@ -27,19 +27,19 @@ define([
'click .js-add-course-run': 'addCourseRun'
},
tpl: HtmlUtils.template( ListTpl ),
tpl: HtmlUtils.template(ListTpl),
initialize: function( options ) {
initialize: function(options) {
this.model = new CourseModel();
Backbone.Validation.bind( this );
this.$parentEl = $( this.parentEl );
Backbone.Validation.bind(this);
this.$parentEl = $(this.parentEl);
// For managing subViews
this.courseRunViews = [];
this.courseRuns = options.courseRuns;
this.programModel = options.programModel;
if ( options.courseData ) {
if (options.courseData) {
this.model.set(options.courseData);
} else {
this.model.set({run_modes: []});
@@ -53,13 +53,13 @@ define([
render: function() {
HtmlUtils.setHtml(this.$el, this.tpl(this.formatData()));
this.$parentEl.append( this.$el );
this.$parentEl.append(this.$el);
this.postRender();
},
postRender: function() {
var runs = this.model.get('run_modes');
if ( runs && runs.length > 0 ) {
if (runs && runs.length > 0) {
this.addCourseRuns();
}
},
@@ -81,7 +81,7 @@ define([
$parentEl: $runsContainer
});
this.courseRunViews.push( runView );
this.courseRunViews.push(runView);
},
addCourseRuns: function() {
@@ -89,7 +89,7 @@ define([
var runs = this.model.get('run_modes'),
$runsContainer = this.$el.find('.js-course-runs');
_.each( runs, function( run ) {
_.each(runs, function(run) {
var runModel = new CourseRunModel(),
runView;
@@ -103,20 +103,20 @@ define([
$parentEl: $runsContainer
});
this.courseRunViews.push( runView );
this.courseRunViews.push(runView);
return runView;
}.bind(this) );
}.bind(this));
},
addCourseToProgram: function() {
var courseCodes = this.programModel.get('course_codes'),
courseData = this.model.toJSON();
if ( this.programModel.isValid( true ) ) {
if (this.programModel.isValid(true)) {
// We don't want to save the cid so omit it
courseCodes.push( _.omit(courseData, 'cid') );
this.programModel.patch({ course_codes: courseCodes });
courseCodes.push(_.omit(courseData, 'cid'));
this.programModel.patch({course_codes: courseCodes});
}
},
// Delete this view
@@ -131,16 +131,16 @@ define([
destroyChildren: function() {
var runs = this.courseRunViews;
_.each( runs, function( run ) {
_.each(runs, function(run) {
run.removeRun();
});
},
// Format data to be passed to the template
formatData: function() {
var data = $.extend( {},
{ courseRuns: this.courseRuns.models },
_.omit( this.programModel.toJSON(), 'run_modes'),
var data = $.extend({},
{courseRuns: this.courseRuns.models},
_.omit(this.programModel.toJSON(), 'run_modes'),
this.model.toJSON()
);
@@ -153,14 +153,14 @@ define([
name = this.model.get('display_name'),
update = [];
update = _.reject( courseCodes, function(course) {
update = _.reject(courseCodes, function(course) {
return course.key === key && course.display_name === name;
});
this.programModel.patch({ course_codes: update });
this.programModel.patch({course_codes: update});
},
setCourse: function( event ) {
setCourse: function(event) {
var $form = this.$('.js-course-form'),
title = $form.find('.display-name').val(),
key = $form.find('.course-key').val();
@@ -173,7 +173,7 @@ define([
organization: this.programModel.get('organizations')[0]
});
if ( this.model.isValid(true) ) {
if (this.model.isValid(true)) {
this.addCourseToProgram();
this.updateDOM();
this.addCourseRuns();
@@ -181,7 +181,7 @@ define([
},
updateDOM: function() {
HtmlUtils.setHtml(this.$el, this.tpl( this.formatData() ) );
HtmlUtils.setHtml(this.$el, this.tpl(this.formatData()));
},
updateRuns: function() {
@@ -190,13 +190,13 @@ define([
name = this.model.get('display_name'),
index;
if ( this.programModel.isValid( true ) ) {
index = _.findIndex( courseCodes, function(course) {
if (this.programModel.isValid(true)) {
index = _.findIndex(courseCodes, function(course) {
return course.key === key && course.display_name === name;
});
courseCodes[index] = this.model.toJSON();
this.programModel.patch({ course_codes: courseCodes });
this.programModel.patch({course_codes: courseCodes});
}
}
});

View File

@@ -1,11 +1,11 @@
define([
'backbone',
'jquery',
'underscore',
'text!templates/programs/course_run.underscore',
'edx-ui-toolkit/js/utils/html-utils'
],
function ( Backbone, $, _, CourseRunTpl, HtmlUtils ) {
'backbone',
'jquery',
'underscore',
'text!templates/programs/course_run.underscore',
'edx-ui-toolkit/js/utils/html-utils'
],
function(Backbone, $, _, CourseRunTpl, HtmlUtils) {
'use strict';
return Backbone.View.extend({
@@ -14,9 +14,9 @@ define([
'click .js-remove-run': 'removeRun'
},
tpl: HtmlUtils.template( CourseRunTpl ),
tpl: HtmlUtils.template(CourseRunTpl),
initialize: function( options ) {
initialize: function(options) {
/**
* Need the run model for the template, and the courseModel
* to keep parent view up to date with run changes
@@ -37,12 +37,12 @@ define([
data.programStatus = this.programStatus;
if ( !!this.courseRuns ) {
if (!!this.courseRuns) {
data.courseRuns = this.courseRuns.toJSON();
}
HtmlUtils.setHtml(this.$el, this.tpl( data ) );
this.$parentEl.append( this.$el );
HtmlUtils.setHtml(this.$el, this.tpl(data));
this.$parentEl.append(this.$el);
},
// Delete this view
@@ -52,7 +52,7 @@ define([
},
// Data returned from courseList API is not the correct format
formatData: function( data ) {
formatData: function(data) {
return {
course_key: data.id,
mode_slug: 'verified',
@@ -72,7 +72,7 @@ define([
runs = _.clone(this.courseModel.get('run_modes')),
updatedRuns = [];
updatedRuns = _.reject( runs, function( obj ) {
updatedRuns = _.reject(runs, function(obj) {
return obj.start_date === startDate &&
obj.course_key === courseKey;
});
@@ -96,7 +96,7 @@ define([
runs = _.clone(this.courseModel.get('run_modes')),
data = this.formatData(runObj);
this.model.set( data );
this.model.set(data);
runs.push(data);
this.courseModel.set({run_modes: runs});
this.courseRuns.removeRun(id);
@@ -104,7 +104,7 @@ define([
// If a run has not been selected update the dropdown options
updateDropdown: function() {
if ( !this.model.get('course_key') ) {
if (!this.model.get('course_key')) {
this.render();
}
}

View File

@@ -2,11 +2,11 @@
'use strict';
define([
'backbone',
'js/programs/router',
'js/programs/utils/api_config'
],
function( Backbone, ProgramRouter, apiConfig ) {
'backbone',
'js/programs/router',
'js/programs/utils/api_config'
],
function(Backbone, ProgramRouter, apiConfig) {
return Backbone.View.extend({
el: '.js-program-admin',
@@ -37,14 +37,14 @@
* @param {Event} event - Event being handled.
* @returns {boolean} - Indicates if event handling succeeded (always true).
*/
navigate: function (event) {
var url = $(event.target).attr('href').replace( this.app.root, '' );
navigate: function(event) {
var url = $(event.target).attr('href').replace(this.app.root, '');
/**
* Handle the cases where the user wants to open the link in a new tab/window.
* event.which === 2 checks for the middle mouse button (https://api.jquery.com/event.which/)
*/
if ( event.ctrlKey || event.shiftKey || event.metaKey || event.which === 2 ) {
if (event.ctrlKey || event.shiftKey || event.metaKey || event.which === 2) {
return true;
}
@@ -52,14 +52,14 @@
event.preventDefault();
// Process the navigation in the app/router.
if ( url === Backbone.history.getFragment() && url === '' ) {
if (url === Backbone.history.getFragment() && url === '') {
/**
* Note: We must call the index directly since Backbone
* does not support routing to the same route.
*/
this.app.index();
} else {
this.app.navigate( url, { trigger: true } );
this.app.navigate(url, {trigger: true});
}
}
});

View File

@@ -1,16 +1,16 @@
define([
'backbone',
'backbone.validation',
'jquery',
'underscore',
'js/programs/models/organizations_model',
'js/programs/models/program_model',
'text!templates/programs/program_creator_form.underscore',
'edx-ui-toolkit/js/utils/html-utils',
'gettext',
'js/programs/utils/validation_config'
],
function ( Backbone, BackboneValidation, $, _, OrganizationsModel, ProgramModel, ListTpl, HtmlUtils ) {
'backbone',
'backbone.validation',
'jquery',
'underscore',
'js/programs/models/organizations_model',
'js/programs/models/program_model',
'text!templates/programs/program_creator_form.underscore',
'edx-ui-toolkit/js/utils/html-utils',
'gettext',
'js/programs/utils/validation_config'
],
function(Backbone, BackboneValidation, $, _, OrganizationsModel, ProgramModel, ListTpl, HtmlUtils) {
'use strict';
return Backbone.View.extend({
@@ -21,21 +21,21 @@ define([
'click .js-abort-view': 'abort'
},
tpl: HtmlUtils.template( ListTpl ),
tpl: HtmlUtils.template(ListTpl),
initialize: function( options ) {
this.$parentEl = $( this.parentEl );
initialize: function(options) {
this.$parentEl = $(this.parentEl);
this.model = new ProgramModel();
this.model.on( 'sync', this.saveSuccess, this );
this.model.on( 'error', this.saveError, this );
this.model.on('sync', this.saveSuccess, this);
this.model.on('error', this.saveError, this);
// Hook up validation.
// See: http://thedersen.com/projects/backbone-validation/#validation-binding.
Backbone.Validation.bind( this );
Backbone.Validation.bind(this);
this.organizations = new OrganizationsModel();
this.organizations.on( 'sync', this.render, this );
this.organizations.on('sync', this.render, this);
this.organizations.fetch();
this.router = options.router;
@@ -44,31 +44,31 @@ define([
render: function() {
HtmlUtils.setHtml(
this.$el,
this.tpl( {
this.tpl({
orgs: this.organizations.get('results')
})
);
HtmlUtils.setHtml(this.$parentEl, HtmlUtils.HTML( this.$el ));
HtmlUtils.setHtml(this.$parentEl, HtmlUtils.HTML(this.$el));
},
abort: function( event ) {
abort: function(event) {
event.preventDefault();
this.router.goHome();
},
createProgram: function( event ) {
createProgram: function(event) {
var data = this.getData();
event.preventDefault();
this.model.set( data );
this.model.set(data);
// Check if the model is valid before saving. Invalid attributes are looked
// up by name. The corresponding elements receieve an `invalid` class and a
// `data-error` attribute. Both are removed when formerly invalid attributes
// become valid.
// See: http://thedersen.com/projects/backbone-validation/#isvalid.
if ( this.model.isValid(true) ) {
if (this.model.isValid(true)) {
this.model.save();
}
},
@@ -84,28 +84,28 @@ define([
getData: function() {
return {
name: this.$el.find( '.program-name' ).val(),
subtitle: this.$el.find( '.program-subtitle' ).val(),
category: this.$el.find( '.program-type' ).val(),
marketing_slug: this.$el.find( '.program-marketing-slug' ).val(),
name: this.$el.find('.program-name').val(),
subtitle: this.$el.find('.program-subtitle').val(),
category: this.$el.find('.program-type').val(),
marketing_slug: this.$el.find('.program-marketing-slug').val(),
organizations: [{
key: this.$el.find( '.program-org' ).val()
key: this.$el.find('.program-org').val()
}]
};
},
goToView: function( uri ) {
Backbone.history.navigate( uri, { trigger: true } );
goToView: function(uri) {
Backbone.history.navigate(uri, {trigger: true});
this.destroy();
},
// TODO: add user messaging to show errors
saveError: function( jqXHR ) {
console.log( 'saveError: ', jqXHR );
saveError: function(jqXHR) {
console.log('saveError: ', jqXHR);
},
saveSuccess: function() {
this.goToView( String( this.model.get( 'id' ) ) );
this.goToView(String(this.model.get('id')));
}
});
}

View File

@@ -1,20 +1,20 @@
define([
'backbone',
'backbone.validation',
'jquery',
'underscore',
'js/programs/collections/course_runs_collection',
'js/programs/models/program_model',
'js/programs/views/confirm_modal_view',
'js/programs/views/course_details_view',
'text!templates/programs/program_details.underscore',
'edx-ui-toolkit/js/utils/html-utils',
'gettext',
'js/programs/utils/validation_config'
],
function( Backbone, BackboneValidation, $, _, CourseRunsCollection,
'backbone',
'backbone.validation',
'jquery',
'underscore',
'js/programs/collections/course_runs_collection',
'js/programs/models/program_model',
'js/programs/views/confirm_modal_view',
'js/programs/views/course_details_view',
'text!templates/programs/program_details.underscore',
'edx-ui-toolkit/js/utils/html-utils',
'gettext',
'js/programs/utils/validation_config'
],
function(Backbone, BackboneValidation, $, _, CourseRunsCollection,
ProgramModel, ModalView, CourseView, ListTpl,
HtmlUtils ) {
HtmlUtils) {
'use strict';
return Backbone.View.extend({
@@ -27,10 +27,10 @@ define([
'click .js-publish-program': 'confirmPublish'
},
tpl: HtmlUtils.template( ListTpl ),
tpl: HtmlUtils.template(ListTpl),
initialize: function() {
Backbone.Validation.bind( this );
Backbone.Validation.bind(this);
this.courseRuns = new CourseRunsCollection([], {
organization: this.model.get('organizations')[0]
@@ -41,25 +41,25 @@ define([
},
render: function() {
HtmlUtils.setHtml(this.$el, this.tpl( this.model.toJSON() ) );
HtmlUtils.setHtml(this.$el, this.tpl(this.model.toJSON()));
this.postRender();
},
postRender: function() {
var courses = this.model.get( 'course_codes' );
var courses = this.model.get('course_codes');
_.each( courses, function( course ) {
_.each(courses, function(course) {
var title = course.key + 'Course';
this[ title ] = new CourseView({
this[title] = new CourseView({
courseRuns: this.courseRuns,
programModel: this.model,
courseData: course
});
}.bind(this) );
}.bind(this));
// Stop listening to the model sync set when publishing
this.model.off( 'sync' );
this.model.off('sync');
},
addCourse: function() {
@@ -69,7 +69,7 @@ define([
});
},
checkEdit: function( event ) {
checkEdit: function(event) {
var $input = $(event.target),
$span = $input.prevAll('.js-model-value'),
$btn = $input.next('.js-enable-edit'),
@@ -83,12 +83,12 @@ define([
$btn.removeClass('is-hidden');
$span.removeClass('is-hidden');
if ( this.model.get( key ) !== value ) {
this.model.set( data );
if (this.model.get(key) !== value) {
this.model.set(data);
if ( this.model.isValid( true ) ) {
this.model.patch( data );
$span.text( value );
if (this.model.isValid(true)) {
this.model.patch(data);
$span.text(value);
}
}
},
@@ -97,7 +97,7 @@ define([
* Loads modal that user clicks a confirmation button
* in to publish the course (or they can cancel out of it)
*/
confirmPublish: function( event ) {
confirmPublish: function(event) {
event.preventDefault();
/**
@@ -106,10 +106,10 @@ define([
* the program creation form and is only happening here
* it makes sense to have the validation at the view level
*/
if ( this.model.isValid( true ) && this.validateMarketingSlug() ) {
if (this.model.isValid(true) && this.validateMarketingSlug()) {
this.modalView = new ModalView({
model: this.model,
callback: _.bind( this.publishProgram, this ),
callback: _.bind(this.publishProgram, this),
content: this.getModalContent(),
parentEl: '.js-publish-modal',
parentView: this
@@ -117,21 +117,21 @@ define([
}
},
editField: function( event ) {
editField: function(event) {
/**
* Making the assumption that users can only see
* programs that they have permission to edit
*/
var $btn = $( event.currentTarget ),
$el = $btn.prev( 'input' );
var $btn = $(event.currentTarget),
$el = $btn.prev('input');
event.preventDefault();
$el.prevAll( '.js-model-value' ).addClass( 'is-hidden' );
$el.removeClass( 'is-hidden' )
.addClass( 'edit' )
$el.prevAll('.js-model-value').addClass('is-hidden');
$el.removeClass('is-hidden')
.addClass('edit')
.focus();
$btn.addClass( 'is-hidden' );
$btn.addClass('is-hidden');
},
getModalContent: function() {
@@ -153,9 +153,9 @@ define([
status: 'active'
};
this.model.set( data, { silent: true } );
this.model.on( 'sync', this.render, this );
this.model.patch( data );
this.model.set(data, {silent: true});
this.model.on('sync', this.render, this);
this.model.patch(data);
},
setAvailableCourseRuns: function() {
@@ -165,12 +165,12 @@ define([
availableRuns = allRuns;
if (courses.length) {
selectedRuns = _.pluck( courses, 'run_modes' );
selectedRuns = _.flatten( selectedRuns );
selectedRuns = _.pluck(courses, 'run_modes');
selectedRuns = _.flatten(selectedRuns);
}
availableRuns = _.reject(allRuns, function(run) {
var selectedCourseRun = _.findWhere( selectedRuns, {
var selectedCourseRun = _.findWhere(selectedRuns, {
course_key: run.id,
start_date: run.start
});
@@ -186,17 +186,17 @@ define([
$input = {},
$message = {};
if ( this.model.get( 'marketing_slug' ).length > 0 ) {
if (this.model.get('marketing_slug').length > 0) {
isValid = true;
} else {
$input = this.$el.find( '#program-marketing-slug' );
$message = $input.siblings( '.field-message' );
$input = this.$el.find('#program-marketing-slug');
$message = $input.siblings('.field-message');
// Update DOM
$input.addClass( 'has-error' );
$message.addClass( 'has-error' );
$message.find( '.field-message-content' )
.text( gettext( 'Marketing Slug is required.') );
$input.addClass('has-error');
$message.addClass('has-error');
$message.find('.field-message-content')
.text(gettext('Marketing Slug is required.'));
}
return isValid;