* fix: eslint operator-linebreak issue * fix: eslint quotes issue * fix: react jsx indent and props issues * fix: eslint trailing spaces issues * fix: eslint line around directives issue * fix: eslint semi rule * fix: eslint newline per chain rule * fix: eslint space infix ops rule * fix: eslint space-in-parens issue * fix: eslint space before function paren issue * fix: eslint space before blocks issue * fix: eslint arrow body style issue * fix: eslint dot-location issue * fix: eslint quotes issue * fix: eslint quote props issue * fix: eslint operator assignment issue * fix: eslint new line after import issue * fix: indent issues * fix: operator assignment issue * fix: all autofixable eslint issues * fix: all react related fixable issues * fix: autofixable eslint issues * chore: remove all template literals * fix: remaining autofixable issues * chore: apply amnesty on all existing issues * fix: failing xss-lint issues * refactor: apply amnesty on remaining issues * refactor: apply amnesty on new issues * fix: remove file level suppressions * refactor: apply amnesty on new issues
83 lines
2.9 KiB
JavaScript
83 lines
2.9 KiB
JavaScript
// eslint-disable-next-line no-shadow-restricted-names
|
|
(function(define, undefined) {
|
|
'use strict';
|
|
|
|
define([
|
|
'jquery', 'underscore', 'backbone', 'js/edxnotes/utils/template',
|
|
'js/edxnotes/utils/logger', 'edx-ui-toolkit/js/utils/html-utils'
|
|
], function($, _, Backbone, templateUtils, NotesLogger, HtmlUtils) {
|
|
var NoteItemView = Backbone.View.extend({
|
|
tagName: 'article',
|
|
className: 'note',
|
|
id: function() {
|
|
return 'note-' + _.uniqueId();
|
|
},
|
|
events: {
|
|
'click .note-excerpt-more-link': 'moreHandler',
|
|
'click .reference-unit-link': 'unitLinkHandler',
|
|
'click .reference-tags': 'tagHandler'
|
|
},
|
|
|
|
initialize: function(options) {
|
|
this.options = _.extend({}, options);
|
|
this.template = templateUtils.loadTemplate('note-item');
|
|
this.logger = NotesLogger.getLogger('note_item', options.debug);
|
|
this.listenTo(this.model, 'change:is_expanded', this.render);
|
|
},
|
|
|
|
render: function() {
|
|
var context = this.getContext();
|
|
this.$el.html(HtmlUtils.HTML(this.template(context)).toString());
|
|
return this;
|
|
},
|
|
|
|
getContext: function() {
|
|
return $.extend({}, this.model.toJSON(), {
|
|
message: this.model.getQuote()
|
|
});
|
|
},
|
|
|
|
toggleNote: function() {
|
|
var value = !this.model.get('is_expanded');
|
|
this.model.set('is_expanded', value);
|
|
},
|
|
|
|
moreHandler: function(event) {
|
|
event.preventDefault();
|
|
this.toggleNote();
|
|
},
|
|
|
|
unitLinkHandler: function(event) {
|
|
var REQUEST_TIMEOUT = 2000;
|
|
event.preventDefault();
|
|
this.logger.emit('edx.course.student_notes.used_unit_link', {
|
|
note_id: this.model.get('id'),
|
|
component_usage_id: this.model.get('usage_id'),
|
|
view: this.options.view
|
|
}, REQUEST_TIMEOUT).always(_.bind(function() {
|
|
this.redirectTo(event.target.href);
|
|
}, this));
|
|
},
|
|
|
|
tagHandler: function(event) {
|
|
event.preventDefault();
|
|
if (!_.isUndefined(this.options.scrollToTag)) {
|
|
this.options.scrollToTag(event.currentTarget.text);
|
|
}
|
|
},
|
|
|
|
redirectTo: function(uri) {
|
|
window.location = uri;
|
|
},
|
|
|
|
remove: function() {
|
|
this.logger.destroy();
|
|
Backbone.View.prototype.remove.call(this);
|
|
return this;
|
|
}
|
|
});
|
|
|
|
return NoteItemView;
|
|
});
|
|
}).call(this, define || RequireJS.define);
|