").html(data).evalScripts();
+ //alert($('param', data).each(function(){alert($(this).attr('value'));}));
+ return data;
+ }
+})
+
diff --git a/lms/static/js/jquery.autocomplete.js b/lms/static/js/jquery.autocomplete.js
new file mode 100644
index 0000000000..8a43f12a36
--- /dev/null
+++ b/lms/static/js/jquery.autocomplete.js
@@ -0,0 +1,1091 @@
+/**
+ * @fileOverview jquery-autocomplete, the jQuery Autocompleter
+ * @author
Dylan Verheul
+ * @requires jQuery 1.6+
+ *
+ * Copyright 2005-2012, Dylan Verheul
+ *
+ * Use under either MIT, GPL or Apache 2.0. See LICENSE.txt
+ *
+ * Project home: https://github.com/dyve/jquery-autocomplete
+ */
+
+(function($) {
+ "use strict";
+
+ /**
+ * jQuery autocomplete plugin
+ * @param {object|string} options
+ * @returns (object} jQuery object
+ */
+ $.fn.autocomplete = function(options) {
+ var url;
+ if (arguments.length > 1) {
+ url = options;
+ options = arguments[1];
+ options.url = url;
+ } else if (typeof options === 'string') {
+ url = options;
+ options = { url: url };
+ }
+ var opts = $.extend({}, $.fn.autocomplete.defaults, options);
+ return this.each(function() {
+ var $this = $(this);
+ $this.data('autocompleter', new $.Autocompleter(
+ $this,
+ $.meta ? $.extend({}, opts, $this.data()) : opts
+ ));
+ });
+ };
+
+ /**
+ * Store default options
+ * @type {object}
+ */
+ $.fn.autocomplete.defaults = {
+ inputClass: 'acInput',
+ loadingClass: 'acLoading',
+ resultsClass: 'acResults',
+ selectClass: 'acSelect',
+ queryParamName: 'q',
+ extraParams: {},
+ remoteDataType: false,
+ lineSeparator: '\n',
+ cellSeparator: '|',
+ minChars: 2,
+ maxItemsToShow: 10,
+ delay: 400,
+ useCache: true,
+ maxCacheLength: 10,
+ matchSubset: true,
+ matchCase: false,
+ matchInside: true,
+ mustMatch: false,
+ selectFirst: false,
+ selectOnly: false,
+ showResult: null,
+ preventDefaultReturn: true,
+ preventDefaultTab: false,
+ autoFill: false,
+ filterResults: true,
+ sortResults: true,
+ sortFunction: null,
+ onItemSelect: null,
+ onNoMatch: null,
+ onFinish: null,
+ matchStringConverter: null,
+ beforeUseConverter: null,
+ autoWidth: 'min-width',
+ useDelimiter: false,
+ delimiterChar: ',',
+ delimiterKeyCode: 188,
+ processData: null,
+ onError: null
+ };
+
+ /**
+ * Sanitize result
+ * @param {Object} result
+ * @returns {Object} object with members value (String) and data (Object)
+ * @private
+ */
+ var sanitizeResult = function(result) {
+ var value, data;
+ var type = typeof result;
+ if (type === 'string') {
+ value = result;
+ data = {};
+ } else if ($.isArray(result)) {
+ value = result[0];
+ data = result.slice(1);
+ } else if (type === 'object') {
+ value = result.value;
+ data = result.data;
+ }
+ value = String(value);
+ if (typeof data !== 'object') {
+ data = {};
+ }
+ return {
+ value: value,
+ data: data
+ };
+ };
+
+ /**
+ * Sanitize integer
+ * @param {mixed} value
+ * @param {Object} options
+ * @returns {Number} integer
+ * @private
+ */
+ var sanitizeInteger = function(value, stdValue, options) {
+ var num = parseInt(value, 10);
+ options = options || {};
+ if (isNaN(num) || (options.min && num < options.min)) {
+ num = stdValue;
+ }
+ return num;
+ };
+
+ /**
+ * Create partial url for a name/value pair
+ */
+ var makeUrlParam = function(name, value) {
+ return [name, encodeURIComponent(value)].join('=');
+ };
+
+ /**
+ * Build an url
+ * @param {string} url Base url
+ * @param {object} [params] Dictionary of parameters
+ */
+ var makeUrl = function(url, params) {
+ var urlAppend = [];
+ $.each(params, function(index, value) {
+ urlAppend.push(makeUrlParam(index, value));
+ });
+ if (urlAppend.length) {
+ url += url.indexOf('?') === -1 ? '?' : '&';
+ url += urlAppend.join('&');
+ }
+ return url;
+ };
+
+ /**
+ * Default sort filter
+ * @param {object} a
+ * @param {object} b
+ * @param {boolean} matchCase
+ * @returns {number}
+ */
+ var sortValueAlpha = function(a, b, matchCase) {
+ a = String(a.value);
+ b = String(b.value);
+ if (!matchCase) {
+ a = a.toLowerCase();
+ b = b.toLowerCase();
+ }
+ if (a > b) {
+ return 1;
+ }
+ if (a < b) {
+ return -1;
+ }
+ return 0;
+ };
+
+ /**
+ * Parse data received in text format
+ * @param {string} text Plain text input
+ * @param {string} lineSeparator String that separates lines
+ * @param {string} cellSeparator String that separates cells
+ * @returns {array} Array of autocomplete data objects
+ */
+ var plainTextParser = function(text, lineSeparator, cellSeparator) {
+ var results = [];
+ var i, j, data, line, value, lines;
+ // Be nice, fix linebreaks before splitting on lineSeparator
+ lines = String(text).replace('\r\n', '\n').split(lineSeparator);
+ for (i = 0; i < lines.length; i++) {
+ line = lines[i].split(cellSeparator);
+ data = [];
+ for (j = 0; j < line.length; j++) {
+ data.push(decodeURIComponent(line[j]));
+ }
+ value = data.shift();
+ results.push({ value: value, data: data });
+ }
+ return results;
+ };
+
+ /**
+ * Autocompleter class
+ * @param {object} $elem jQuery object with one input tag
+ * @param {object} options Settings
+ * @constructor
+ */
+ $.Autocompleter = function($elem, options) {
+
+ /**
+ * Assert parameters
+ */
+ if (!$elem || !($elem instanceof $) || $elem.length !== 1 || $elem.get(0).tagName.toUpperCase() !== 'INPUT') {
+ throw new Error('Invalid parameter for jquery.Autocompleter, jQuery object with one element with INPUT tag expected.');
+ }
+
+ /**
+ * @constant Link to this instance
+ * @type object
+ * @private
+ */
+ var self = this;
+
+ /**
+ * @property {object} Options for this instance
+ * @public
+ */
+ this.options = options;
+
+ /**
+ * @property object Cached data for this instance
+ * @private
+ */
+ this.cacheData_ = {};
+
+ /**
+ * @property {number} Number of cached data items
+ * @private
+ */
+ this.cacheLength_ = 0;
+
+ /**
+ * @property {string} Class name to mark selected item
+ * @private
+ */
+ this.selectClass_ = 'jquery-autocomplete-selected-item';
+
+ /**
+ * @property {number} Handler to activation timeout
+ * @private
+ */
+ this.keyTimeout_ = null;
+
+ /**
+ * @property {number} Handler to finish timeout
+ * @private
+ */
+ this.finishTimeout_ = null;
+
+ /**
+ * @property {number} Last key pressed in the input field (store for behavior)
+ * @private
+ */
+ this.lastKeyPressed_ = null;
+
+ /**
+ * @property {string} Last value processed by the autocompleter
+ * @private
+ */
+ this.lastProcessedValue_ = null;
+
+ /**
+ * @property {string} Last value selected by the user
+ * @private
+ */
+ this.lastSelectedValue_ = null;
+
+ /**
+ * @property {boolean} Is this autocompleter active (showing results)?
+ * @see showResults
+ * @private
+ */
+ this.active_ = false;
+
+ /**
+ * @property {boolean} Is this autocompleter allowed to finish on blur?
+ * @private
+ */
+ this.finishOnBlur_ = true;
+
+ /**
+ * Sanitize options
+ */
+ this.options.minChars = sanitizeInteger(this.options.minChars, $.fn.autocomplete.defaults.minChars, { min: 1 });
+ this.options.maxItemsToShow = sanitizeInteger(this.options.maxItemsToShow, $.fn.autocomplete.defaults.maxItemsToShow, { min: 0 });
+ this.options.maxCacheLength = sanitizeInteger(this.options.maxCacheLength, $.fn.autocomplete.defaults.maxCacheLength, { min: 1 });
+ this.options.delay = sanitizeInteger(this.options.delay, $.fn.autocomplete.defaults.delay, { min: 0 });
+
+ /**
+ * Init DOM elements repository
+ */
+ this.dom = {};
+
+ /**
+ * Store the input element we're attached to in the repository
+ */
+ this.dom.$elem = $elem;
+
+ /**
+ * Switch off the native autocomplete and add the input class
+ */
+ this.dom.$elem.attr('autocomplete', 'off').addClass(this.options.inputClass);
+
+ /**
+ * Create DOM element to hold results, and force absolute position
+ */
+ this.dom.$results = $('
').hide().addClass(this.options.resultsClass).css({
+ position: 'absolute'
+ });
+ $('body').append(this.dom.$results);
+
+ /**
+ * Attach keyboard monitoring to $elem
+ */
+ $elem.keydown(function(e) {
+ self.lastKeyPressed_ = e.keyCode;
+ switch(self.lastKeyPressed_) {
+
+ case self.options.delimiterKeyCode: // comma = 188
+ if (self.options.useDelimiter && self.active_) {
+ self.selectCurrent();
+ }
+ break;
+
+ // ignore navigational & special keys
+ case 35: // end
+ case 36: // home
+ case 16: // shift
+ case 17: // ctrl
+ case 18: // alt
+ case 37: // left
+ case 39: // right
+ break;
+
+ case 38: // up
+ e.preventDefault();
+ if (self.active_) {
+ self.focusPrev();
+ } else {
+ self.activate();
+ }
+ return false;
+
+ case 40: // down
+ e.preventDefault();
+ if (self.active_) {
+ self.focusNext();
+ } else {
+ self.activate();
+ }
+ return false;
+
+ case 9: // tab
+ if (self.active_) {
+ self.selectCurrent();
+ if (self.options.preventDefaultTab) {
+ e.preventDefault();
+ return false;
+ }
+ }
+ break;
+
+ case 13: // return
+ if (self.active_) {
+ self.selectCurrent();
+ if (self.options.preventDefaultReturn) {
+ e.preventDefault();
+ return false;
+ }
+ }
+ break;
+
+ case 27: // escape
+ if (self.active_) {
+ e.preventDefault();
+ self.deactivate(true);
+ return false;
+ }
+ break;
+
+ default:
+ self.activate();
+
+ }
+ });
+
+ /**
+ * Finish on blur event
+ * Use a timeout because instant blur gives race conditions
+ */
+ $elem.blur(function() {
+ if (self.finishOnBlur_) {
+ self.finishTimeout_ = setTimeout(function() { self.deactivate(true); }, 200);
+ }
+ });
+
+ };
+
+ /**
+ * Position output DOM elements
+ * @private
+ */
+ $.Autocompleter.prototype.position = function() {
+ var offset = this.dom.$elem.offset();
+ this.dom.$results.css({
+ top: offset.top + this.dom.$elem.outerHeight(),
+ left: offset.left
+ });
+ };
+
+ /**
+ * Read from cache
+ * @private
+ */
+ $.Autocompleter.prototype.cacheRead = function(filter) {
+ var filterLength, searchLength, search, maxPos, pos;
+ if (this.options.useCache) {
+ filter = String(filter);
+ filterLength = filter.length;
+ if (this.options.matchSubset) {
+ searchLength = 1;
+ } else {
+ searchLength = filterLength;
+ }
+ while (searchLength <= filterLength) {
+ if (this.options.matchInside) {
+ maxPos = filterLength - searchLength;
+ } else {
+ maxPos = 0;
+ }
+ pos = 0;
+ while (pos <= maxPos) {
+ search = filter.substr(0, searchLength);
+ if (this.cacheData_[search] !== undefined) {
+ return this.cacheData_[search];
+ }
+ pos++;
+ }
+ searchLength++;
+ }
+ }
+ return false;
+ };
+
+ /**
+ * Write to cache
+ * @private
+ */
+ $.Autocompleter.prototype.cacheWrite = function(filter, data) {
+ if (this.options.useCache) {
+ if (this.cacheLength_ >= this.options.maxCacheLength) {
+ this.cacheFlush();
+ }
+ filter = String(filter);
+ if (this.cacheData_[filter] !== undefined) {
+ this.cacheLength_++;
+ }
+ this.cacheData_[filter] = data;
+ return this.cacheData_[filter];
+ }
+ return false;
+ };
+
+ /**
+ * Flush cache
+ * @public
+ */
+ $.Autocompleter.prototype.cacheFlush = function() {
+ this.cacheData_ = {};
+ this.cacheLength_ = 0;
+ };
+
+ /**
+ * Call hook
+ * Note that all called hooks are passed the autocompleter object
+ * @param {string} hook
+ * @param data
+ * @returns Result of called hook, false if hook is undefined
+ */
+ $.Autocompleter.prototype.callHook = function(hook, data) {
+ var f = this.options[hook];
+ if (f && $.isFunction(f)) {
+ return f(data, this);
+ }
+ return false;
+ };
+
+ /**
+ * Set timeout to activate autocompleter
+ */
+ $.Autocompleter.prototype.activate = function() {
+ var self = this;
+ if (this.keyTimeout_) {
+ clearTimeout(this.keyTimeout_);
+ }
+ this.keyTimeout_ = setTimeout(function() {
+ self.activateNow();
+ }, this.options.delay);
+ };
+
+ /**
+ * Activate autocompleter immediately
+ */
+ $.Autocompleter.prototype.activateNow = function() {
+ var value = this.beforeUseConverter(this.dom.$elem.val());
+ if (value !== this.lastProcessedValue_ && value !== this.lastSelectedValue_) {
+ this.fetchData(value);
+ }
+ };
+
+ /**
+ * Get autocomplete data for a given value
+ * @param {string} value Value to base autocompletion on
+ * @private
+ */
+ $.Autocompleter.prototype.fetchData = function(value) {
+ var self = this;
+ var processResults = function(results, filter) {
+ if (self.options.processData) {
+ results = self.options.processData(results);
+ }
+ self.showResults(self.filterResults(results, filter), filter);
+ };
+ this.lastProcessedValue_ = value;
+ if (value.length < this.options.minChars) {
+ processResults([], value);
+ } else if (this.options.data) {
+ processResults(this.options.data, value);
+ } else {
+ this.fetchRemoteData(value, function(remoteData) {
+ processResults(remoteData, value);
+ });
+ }
+ };
+
+ /**
+ * Get remote autocomplete data for a given value
+ * @param {string} filter The filter to base remote data on
+ * @param {function} callback The function to call after data retrieval
+ * @private
+ */
+ $.Autocompleter.prototype.fetchRemoteData = function(filter, callback) {
+ var data = this.cacheRead(filter);
+ if (data) {
+ callback(data);
+ } else {
+ var self = this;
+ var dataType = self.options.remoteDataType === 'json' ? 'json' : 'text';
+ var ajaxCallback = function(data) {
+ var parsed = false;
+ if (data !== false) {
+ parsed = self.parseRemoteData(data);
+ self.cacheWrite(filter, parsed);
+ }
+ self.dom.$elem.removeClass(self.options.loadingClass);
+ callback(parsed);
+ };
+ this.dom.$elem.addClass(this.options.loadingClass);
+ $.ajax({
+ url: this.makeUrl(filter),
+ success: ajaxCallback,
+ error: function(jqXHR, textStatus, errorThrown) {
+ if($.isFunction(self.options.onError)) {
+ self.options.onError(jqXHR, textStatus, errorThrown);
+ } else {
+ ajaxCallback(false);
+ }
+ },
+ dataType: dataType
+ });
+ }
+ };
+
+ /**
+ * Create or update an extra parameter for the remote request
+ * @param {string} name Parameter name
+ * @param {string} value Parameter value
+ * @public
+ */
+ $.Autocompleter.prototype.setExtraParam = function(name, value) {
+ var index = $.trim(String(name));
+ if (index) {
+ if (!this.options.extraParams) {
+ this.options.extraParams = {};
+ }
+ if (this.options.extraParams[index] !== value) {
+ this.options.extraParams[index] = value;
+ this.cacheFlush();
+ }
+ }
+ };
+
+ /**
+ * Build the url for a remote request
+ * If options.queryParamName === false, append query to url instead of using a GET parameter
+ * @param {string} param The value parameter to pass to the backend
+ * @returns {string} The finished url with parameters
+ */
+ $.Autocompleter.prototype.makeUrl = function(param) {
+ var self = this;
+ var url = this.options.url;
+ var params = $.extend({}, this.options.extraParams);
+
+ if (this.options.queryParamName === false) {
+ url += encodeURIComponent(param);
+ } else {
+ params[this.options.queryParamName] = param;
+ }
+
+ return makeUrl(url, params);
+ };
+
+ /**
+ * Parse data received from server
+ * @param remoteData Data received from remote server
+ * @returns {array} Parsed data
+ */
+ $.Autocompleter.prototype.parseRemoteData = function(remoteData) {
+ var remoteDataType;
+ var data = remoteData;
+ if (this.options.remoteDataType === 'json') {
+ remoteDataType = typeof(remoteData);
+ switch (remoteDataType) {
+ case 'object':
+ data = remoteData;
+ break;
+ case 'string':
+ data = $.parseJSON(remoteData);
+ break;
+ default:
+ throw new Error("Unexpected remote data type: " + remoteDataType);
+ }
+ return data;
+ }
+ return plainTextParser(data, this.options.lineSeparator, this.options.cellSeparator);
+ };
+
+ /**
+ * Filter result
+ * @param {Object} result
+ * @param {String} filter
+ * @returns {boolean} Include this result
+ * @private
+ */
+ $.Autocompleter.prototype.filterResult = function(result, filter) {
+ if (!result.value) {
+ return false;
+ }
+ if (this.options.filterResults) {
+ var pattern = this.matchStringConverter(filter);
+ var testValue = this.matchStringConverter(result.value);
+ if (!this.options.matchCase) {
+ pattern = pattern.toLowerCase();
+ testValue = testValue.toLowerCase();
+ }
+ var patternIndex = testValue.indexOf(pattern);
+ if (this.options.matchInside) {
+ return patternIndex > -1;
+ } else {
+ return patternIndex === 0;
+ }
+ }
+ return true;
+ };
+
+ /**
+ * Filter results
+ * @param results
+ * @param filter
+ */
+ $.Autocompleter.prototype.filterResults = function(results, filter) {
+ var filtered = [];
+ var i, result;
+
+ for (i = 0; i < results.length; i++) {
+ result = sanitizeResult(results[i]);
+ if (this.filterResult(result, filter)) {
+ filtered.push(result);
+ }
+ }
+ if (this.options.sortResults) {
+ filtered = this.sortResults(filtered, filter);
+ }
+ if (this.options.maxItemsToShow > 0 && this.options.maxItemsToShow < filtered.length) {
+ filtered.length = this.options.maxItemsToShow;
+ }
+ return filtered;
+ };
+
+ /**
+ * Sort results
+ * @param results
+ * @param filter
+ */
+ $.Autocompleter.prototype.sortResults = function(results, filter) {
+ var self = this;
+ var sortFunction = this.options.sortFunction;
+ if (!$.isFunction(sortFunction)) {
+ sortFunction = function(a, b, f) {
+ return sortValueAlpha(a, b, self.options.matchCase);
+ };
+ }
+ results.sort(function(a, b) {
+ return sortFunction(a, b, filter, self.options);
+ });
+ return results;
+ };
+
+ /**
+ * Convert string before matching
+ * @param s
+ * @param a
+ * @param b
+ */
+ $.Autocompleter.prototype.matchStringConverter = function(s, a, b) {
+ var converter = this.options.matchStringConverter;
+ if ($.isFunction(converter)) {
+ s = converter(s, a, b);
+ }
+ return s;
+ };
+
+ /**
+ * Convert string before use
+ * @param s
+ * @param a
+ * @param b
+ */
+ $.Autocompleter.prototype.beforeUseConverter = function(s, a, b) {
+ s = this.getValue();
+ var converter = this.options.beforeUseConverter;
+ if ($.isFunction(converter)) {
+ s = converter(s, a, b);
+ }
+ return s;
+ };
+
+ /**
+ * Enable finish on blur event
+ */
+ $.Autocompleter.prototype.enableFinishOnBlur = function() {
+ this.finishOnBlur_ = true;
+ };
+
+ /**
+ * Disable finish on blur event
+ */
+ $.Autocompleter.prototype.disableFinishOnBlur = function() {
+ this.finishOnBlur_ = false;
+ };
+
+ /**
+ * Create a results item (LI element) from a result
+ * @param result
+ */
+ $.Autocompleter.prototype.createItemFromResult = function(result) {
+ var self = this;
+ var $li = $('
' + this.showResult(result.value, result.data) + '');
+ $li.data({value: result.value, data: result.data})
+ .click(function() {
+ self.selectItem($li);
+ })
+ .mousedown(self.disableFinishOnBlur)
+ .mouseup(self.enableFinishOnBlur)
+ ;
+ return $li;
+ };
+
+ /**
+ * Get all items from the results list
+ * @param result
+ */
+ $.Autocompleter.prototype.getItems = function() {
+ return $('>ul>li', this.dom.$results);
+ };
+
+ /**
+ * Show all results
+ * @param results
+ * @param filter
+ */
+ $.Autocompleter.prototype.showResults = function(results, filter) {
+ var numResults = results.length;
+ var self = this;
+ var $ul = $('
');
+ var i, result, $li, autoWidth, first = false, $first = false;
+
+ if (numResults) {
+ for (i = 0; i < numResults; i++) {
+ result = results[i];
+ $li = this.createItemFromResult(result);
+ $ul.append($li);
+ if (first === false) {
+ first = String(result.value);
+ $first = $li;
+ $li.addClass(this.options.firstItemClass);
+ }
+ if (i === numResults - 1) {
+ $li.addClass(this.options.lastItemClass);
+ }
+ }
+
+ // Always recalculate position before showing since window size or
+ // input element location may have changed.
+ this.position();
+
+ this.dom.$results.html($ul).show();
+ if (this.options.autoWidth) {
+ autoWidth = this.dom.$elem.outerWidth() - this.dom.$results.outerWidth() + this.dom.$results.width();
+ this.dom.$results.css(this.options.autoWidth, autoWidth);
+ }
+ this.getItems().hover(
+ function() { self.focusItem(this); },
+ function() { /* void */ }
+ );
+ if (this.autoFill(first, filter) || this.options.selectFirst || (this.options.selectOnly && numResults === 1)) {
+ this.focusItem($first);
+ }
+ this.active_ = true;
+ } else {
+ this.hideResults();
+ this.active_ = false;
+ }
+ };
+
+ $.Autocompleter.prototype.showResult = function(value, data) {
+ if ($.isFunction(this.options.showResult)) {
+ return this.options.showResult(value, data);
+ } else {
+ return value;
+ }
+ };
+
+ $.Autocompleter.prototype.autoFill = function(value, filter) {
+ var lcValue, lcFilter, valueLength, filterLength;
+ if (this.options.autoFill && this.lastKeyPressed_ !== 8) {
+ lcValue = String(value).toLowerCase();
+ lcFilter = String(filter).toLowerCase();
+ valueLength = value.length;
+ filterLength = filter.length;
+ if (lcValue.substr(0, filterLength) === lcFilter) {
+ var d = this.getDelimiterOffsets();
+ var pad = d.start ? ' ' : ''; // if there is a preceding delimiter
+ this.setValue( pad + value );
+ var start = filterLength + d.start + pad.length;
+ var end = valueLength + d.start + pad.length;
+ this.selectRange(start, end);
+ return true;
+ }
+ }
+ return false;
+ };
+
+ $.Autocompleter.prototype.focusNext = function() {
+ this.focusMove(+1);
+ };
+
+ $.Autocompleter.prototype.focusPrev = function() {
+ this.focusMove(-1);
+ };
+
+ $.Autocompleter.prototype.focusMove = function(modifier) {
+ var $items = this.getItems();
+ modifier = sanitizeInteger(modifier, 0);
+ if (modifier) {
+ for (var i = 0; i < $items.length; i++) {
+ if ($($items[i]).hasClass(this.selectClass_)) {
+ this.focusItem(i + modifier);
+ return;
+ }
+ }
+ }
+ this.focusItem(0);
+ };
+
+ $.Autocompleter.prototype.focusItem = function(item) {
+ var $item, $items = this.getItems();
+ if ($items.length) {
+ $items.removeClass(this.selectClass_).removeClass(this.options.selectClass);
+ if (typeof item === 'number') {
+ if (item < 0) {
+ item = 0;
+ } else if (item >= $items.length) {
+ item = $items.length - 1;
+ }
+ $item = $($items[item]);
+ } else {
+ $item = $(item);
+ }
+ if ($item) {
+ $item.addClass(this.selectClass_).addClass(this.options.selectClass);
+ }
+ }
+ };
+
+ $.Autocompleter.prototype.selectCurrent = function() {
+ var $item = $('li.' + this.selectClass_, this.dom.$results);
+ if ($item.length === 1) {
+ this.selectItem($item);
+ } else {
+ this.deactivate(false);
+ }
+ };
+
+ $.Autocompleter.prototype.selectItem = function($li) {
+ var value = $li.data('value');
+ var data = $li.data('data');
+ var displayValue = this.displayValue(value, data);
+ var processedDisplayValue = this.beforeUseConverter(displayValue);
+ this.lastProcessedValue_ = processedDisplayValue;
+ this.lastSelectedValue_ = processedDisplayValue;
+ var d = this.getDelimiterOffsets();
+ var delimiter = this.options.delimiterChar;
+ var elem = this.dom.$elem;
+ var extraCaretPos = 0;
+ if ( this.options.useDelimiter ) {
+ // if there is a preceding delimiter, add a space after the delimiter
+ if ( elem.val().substring(d.start-1, d.start) == delimiter && delimiter != ' ' ) {
+ displayValue = ' ' + displayValue;
+ }
+ // if there is not already a delimiter trailing this value, add it
+ if ( elem.val().substring(d.end, d.end+1) != delimiter && this.lastKeyPressed_ != this.options.delimiterKeyCode ) {
+ displayValue = displayValue + delimiter;
+ } else {
+ // move the cursor after the existing trailing delimiter
+ extraCaretPos = 1;
+ }
+ }
+ this.setValue(displayValue);
+ this.setCaret(d.start + displayValue.length + extraCaretPos);
+ this.callHook('onItemSelect', { value: value, data: data });
+ this.deactivate(true);
+ elem.focus();
+ };
+
+ $.Autocompleter.prototype.displayValue = function(value, data) {
+ if ($.isFunction(this.options.displayValue)) {
+ return this.options.displayValue(value, data);
+ }
+ return value;
+ };
+
+ $.Autocompleter.prototype.hideResults = function() {
+ this.dom.$results.hide();
+ };
+
+ $.Autocompleter.prototype.deactivate = function(finish) {
+ if (this.finishTimeout_) {
+ clearTimeout(this.finishTimeout_);
+ }
+ if (this.keyTimeout_) {
+ clearTimeout(this.keyTimeout_);
+ }
+ if (finish) {
+ if (this.lastProcessedValue_ !== this.lastSelectedValue_) {
+ if (this.options.mustMatch) {
+ this.setValue('');
+ }
+ this.callHook('onNoMatch');
+ }
+ if (this.active_) {
+ this.callHook('onFinish');
+ }
+ this.lastKeyPressed_ = null;
+ this.lastProcessedValue_ = null;
+ this.lastSelectedValue_ = null;
+ this.active_ = false;
+ }
+ this.hideResults();
+ };
+
+ $.Autocompleter.prototype.selectRange = function(start, end) {
+ var input = this.dom.$elem.get(0);
+ if (input.setSelectionRange) {
+ input.focus();
+ input.setSelectionRange(start, end);
+ } else if (input.createTextRange) {
+ var range = input.createTextRange();
+ range.collapse(true);
+ range.moveEnd('character', end);
+ range.moveStart('character', start);
+ range.select();
+ }
+ };
+
+ /**
+ * Move caret to position
+ * @param {Number} pos
+ */
+ $.Autocompleter.prototype.setCaret = function(pos) {
+ this.selectRange(pos, pos);
+ };
+
+ /**
+ * Get caret position
+ */
+ $.Autocompleter.prototype.getCaret = function() {
+ var elem = this.dom.$elem;
+ if ($.browser.msie) {
+ // ie
+ var selection = document.selection;
+ if (elem[0].tagName.toLowerCase() != 'textarea') {
+ var val = elem.val();
+ var range = selection.createRange().duplicate();
+ range.moveEnd('character', val.length);
+ var s = ( range.text == '' ? val.length : val.lastIndexOf(range.text) );
+ range = selection.createRange().duplicate();
+ range.moveStart('character', -val.length);
+ var e = range.text.length;
+ } else {
+ var range = selection.createRange();
+ var stored_range = range.duplicate();
+ stored_range.moveToElementText(elem[0]);
+ stored_range.setEndPoint('EndToEnd', range);
+ var s = stored_range.text.length - range.text.length;
+ var e = s + range.text.length;
+ }
+ } else {
+ // ff, chrome, safari
+ var s = elem[0].selectionStart;
+ var e = elem[0].selectionEnd;
+ }
+ return {
+ start: s,
+ end: e
+ };
+ };
+
+ /**
+ * Set the value that is currently being autocompleted
+ * @param {String} value
+ */
+ $.Autocompleter.prototype.setValue = function(value) {
+ if ( this.options.useDelimiter ) {
+ // set the substring between the current delimiters
+ var val = this.dom.$elem.val();
+ var d = this.getDelimiterOffsets();
+ var preVal = val.substring(0, d.start);
+ var postVal = val.substring(d.end);
+ value = preVal + value + postVal;
+ }
+ this.dom.$elem.val(value);
+ };
+
+ /**
+ * Get the value currently being autocompleted
+ * @param {String} value
+ */
+ $.Autocompleter.prototype.getValue = function() {
+ var val = this.dom.$elem.val();
+ if ( this.options.useDelimiter ) {
+ var d = this.getDelimiterOffsets();
+ return val.substring(d.start, d.end).trim();
+ } else {
+ return val;
+ }
+ };
+
+ /**
+ * Get the offsets of the value currently being autocompleted
+ */
+ $.Autocompleter.prototype.getDelimiterOffsets = function() {
+ var val = this.dom.$elem.val();
+ if ( this.options.useDelimiter ) {
+ var preCaretVal = val.substring(0, this.getCaret().start);
+ var start = preCaretVal.lastIndexOf(this.options.delimiterChar) + 1;
+ var postCaretVal = val.substring(this.getCaret().start);
+ var end = postCaretVal.indexOf(this.options.delimiterChar);
+ if ( end == -1 ) end = val.length;
+ end += this.getCaret().start;
+ } else {
+ start = 0;
+ end = val.length;
+ }
+ return {
+ start: start,
+ end: end
+ };
+ };
+
+})(jQuery);
diff --git a/lms/static/js/jquery.tagsinput.js b/lms/static/js/jquery.tagsinput.js
new file mode 100644
index 0000000000..b05a87ca99
--- /dev/null
+++ b/lms/static/js/jquery.tagsinput.js
@@ -0,0 +1,364 @@
+/*
+
+ jQuery Tags Input Plugin 1.3.3
+
+ Copyright (c) 2011 XOXCO, Inc
+
+ Documentation for this plugin lives here:
+ http://xoxco.com/clickable/jquery-tags-input
+
+ Licensed under the MIT license:
+ http://www.opensource.org/licenses/mit-license.php
+
+ ben@xoxco.com
+
+*/
+
+(function($) {
+
+ var delimiter = new Array();
+ var tags_callbacks = new Array();
+ $.fn.doAutosize = function(o){
+ var minWidth = $(this).data('minwidth'),
+ maxWidth = $(this).data('maxwidth'),
+ val = '',
+ input = $(this),
+ testSubject = $('#'+$(this).data('tester_id'));
+
+ if (val === (val = input.val())) {return;}
+
+ // Enter new content into testSubject
+ var escaped = val.replace(/&/g, '&').replace(/\s/g,' ').replace(//g, '>');
+ testSubject.html(escaped);
+ // Calculate new width + whether to change
+ var testerWidth = testSubject.width(),
+ newWidth = (testerWidth + o.comfortZone) >= minWidth ? testerWidth + o.comfortZone : minWidth,
+ currentWidth = input.width(),
+ isValidWidthChange = (newWidth < currentWidth && newWidth >= minWidth)
+ || (newWidth > minWidth && newWidth < maxWidth);
+
+ // Animate width
+ if (isValidWidthChange) {
+ input.width(newWidth);
+ }
+
+
+ };
+ $.fn.resetAutosize = function(options){
+ // alert(JSON.stringify(options));
+ var minWidth = $(this).data('minwidth') || options.minInputWidth || $(this).width(),
+ maxWidth = $(this).data('maxwidth') || options.maxInputWidth || ($(this).closest('.tagsinput').width() - options.inputPadding),
+ val = '',
+ input = $(this),
+ testSubject = $('
').css({
+ position: 'absolute',
+ top: -9999,
+ left: -9999,
+ width: 'auto',
+ fontSize: input.css('fontSize'),
+ fontFamily: input.css('fontFamily'),
+ fontWeight: input.css('fontWeight'),
+ letterSpacing: input.css('letterSpacing'),
+ whiteSpace: 'nowrap'
+ }),
+ testerId = $(this).attr('id')+'_autosize_tester';
+ if(! $('#'+testerId).length > 0){
+ testSubject.attr('id', testerId);
+ testSubject.appendTo('body');
+ }
+
+ input.data('minwidth', minWidth);
+ input.data('maxwidth', maxWidth);
+ input.data('tester_id', testerId);
+ input.css('width', minWidth);
+ };
+
+ $.fn.addTag = function(value,options) {
+ options = jQuery.extend({focus:false,callback:true},options);
+ this.each(function() {
+ var id = $(this).attr('id');
+
+ var tagslist = $(this).val().split(delimiter[id]);
+ if (tagslist[0] == '') {
+ tagslist = new Array();
+ }
+
+ value = jQuery.trim(value);
+
+ if (options.unique) {
+ var skipTag = $(this).tagExist(value);
+ if(skipTag == true) {
+ //Marks fake input as not_valid to let styling it
+ $('#'+id+'_tag').addClass('not_valid');
+ }
+ } else {
+ var skipTag = false;
+ }
+
+ if (value !='' && skipTag != true) {
+ $('
').addClass('tag').append(
+ $('').text(value).append(' '),
+ $('', {
+ href : '#',
+ title : 'Removing tag',
+ text : 'x'
+ }).click(function () {
+ return $('#' + id).removeTag(escape(value));
+ })
+ ).insertBefore('#' + id + '_addTag');
+
+ tagslist.push(value);
+
+ $('#'+id+'_tag').val('');
+ if (options.focus) {
+ $('#'+id+'_tag').focus();
+ } else {
+ $('#'+id+'_tag').blur();
+ }
+
+ $.fn.tagsInput.updateTagsField(this,tagslist);
+
+ if (options.callback && tags_callbacks[id] && tags_callbacks[id]['onAddTag']) {
+ var f = tags_callbacks[id]['onAddTag'];
+ f.call(this, value);
+ }
+ if(tags_callbacks[id] && tags_callbacks[id]['onChange'])
+ {
+ var i = tagslist.length;
+ var f = tags_callbacks[id]['onChange'];
+ f.call(this, $(this), tagslist[i-1]);
+ }
+ }
+
+ });
+
+ return false;
+ };
+
+ $.fn.removeTag = function(value) {
+ value = unescape(value);
+ this.each(function() {
+ var id = $(this).attr('id');
+
+ var old = $(this).val().split(delimiter[id]);
+
+ $('#'+id+'_tagsinput .tag').remove();
+ str = '';
+ for (i=0; i< old.length; i++) {
+ if (old[i]!=value) {
+ str = str + delimiter[id] +old[i];
+ }
+ }
+
+ $.fn.tagsInput.importTags(this,str);
+
+ if (tags_callbacks[id] && tags_callbacks[id]['onRemoveTag']) {
+ var f = tags_callbacks[id]['onRemoveTag'];
+ f.call(this, value);
+ }
+ });
+
+ return false;
+ };
+
+ $.fn.tagExist = function(val) {
+ var id = $(this).attr('id');
+ var tagslist = $(this).val().split(delimiter[id]);
+ return (jQuery.inArray(val, tagslist) >= 0); //true when tag exists, false when not
+ };
+
+ // clear all existing tags and import new ones from a string
+ $.fn.importTags = function(str) {
+ id = $(this).attr('id');
+ $('#'+id+'_tagsinput .tag').remove();
+ $.fn.tagsInput.importTags(this,str);
+ }
+
+ $.fn.tagsInput = function(options) {
+ var settings = jQuery.extend({
+ interactive:true,
+ defaultText:'add a tag',
+ minChars:0,
+ width:'300px',
+ height:'100px',
+ autocomplete: {selectFirst: false },
+ 'hide':true,
+ 'delimiter':',',
+ 'unique':true,
+ removeWithBackspace:true,
+ placeholderColor:'#666666',
+ autosize: true,
+ comfortZone: 20,
+ inputPadding: 6*2
+ },options);
+
+ this.each(function() {
+ if (settings.hide) {
+ $(this).hide();
+ }
+ var id = $(this).attr('id');
+ if (!id || delimiter[$(this).attr('id')]) {
+ id = $(this).attr('id', 'tags' + new Date().getTime()).attr('id');
+ }
+
+ var data = jQuery.extend({
+ pid:id,
+ real_input: '#'+id,
+ holder: '#'+id+'_tagsinput',
+ input_wrapper: '#'+id+'_addTag',
+ fake_input: '#'+id+'_tag'
+ },settings);
+
+ delimiter[id] = data.delimiter;
+
+ if (settings.onAddTag || settings.onRemoveTag || settings.onChange) {
+ tags_callbacks[id] = new Array();
+ tags_callbacks[id]['onAddTag'] = settings.onAddTag;
+ tags_callbacks[id]['onRemoveTag'] = settings.onRemoveTag;
+ tags_callbacks[id]['onChange'] = settings.onChange;
+ }
+
+ var markup = '';
+
+ $(markup).insertAfter(this);
+
+
+ $(data.holder).css('width',settings.width);
+ $(data.holder).css('min-height',settings.height);
+ $(data.holder).css('height','100%');
+
+ if ($(data.real_input).val()!='') {
+ $.fn.tagsInput.importTags($(data.real_input),$(data.real_input).val());
+ }
+ if (settings.interactive) {
+ $(data.fake_input).val($(data.fake_input).attr('data-default'));
+ $(data.fake_input).css('color',settings.placeholderColor);
+ $(data.fake_input).resetAutosize(settings);
+
+ $(data.fake_input).doAutosize(settings);
+ $(data.holder).bind('click',data,function(event) {
+ $(event.data.fake_input).focus();
+ });
+
+ $(data.fake_input).bind('focus',data,function(event) {
+ if ($(event.data.fake_input).val()==$(event.data.fake_input).attr('data-default')) {
+ $(event.data.fake_input).val('');
+ }
+ $(event.data.fake_input).css('color','#000000');
+ });
+
+ if (settings.autocomplete_url != undefined) {
+ autocomplete_options = {source: settings.autocomplete_url};
+ for (attrname in settings.autocomplete) {
+ autocomplete_options[attrname] = settings.autocomplete[attrname];
+ }
+
+ if (jQuery.Autocompleter !== undefined) {
+ onSelectCallback = settings.autocomplete.onItemSelect;
+ settings.autocomplete.onItemSelect = function() {
+ $(data.real_input).addTag($(data.fake_input).val(), {focus: true, unique: (settings.unique)});
+ $(data.fake_input).resetAutosize(settings);
+ if (onSelectCallback) {
+ onSelectCallback();
+ }
+ }
+ $(data.fake_input).autocomplete(settings.autocomplete_url, settings.autocomplete);
+ $(data.fake_input).bind('result',data,function(event,data,formatted) {
+ if (data) {
+ $('#'+id).addTag(data[0] + "",{focus:true,unique:(settings.unique)});
+ }
+ });
+ } else if (jQuery.ui.autocomplete !== undefined) {
+ $(data.fake_input).autocomplete(autocomplete_options);
+ $(data.fake_input).bind('autocompleteselect',data,function(event,ui) {
+ $(event.data.real_input).addTag(ui.item.value,{focus:true,unique:(settings.unique)});
+
+ return false;
+ });
+ }
+
+
+ } else {
+ // if a user tabs out of the field, create a new tag
+ // this is only available if autocomplete is not used.
+ $(data.fake_input).bind('blur',data,function(event) {
+ var d = $(this).attr('data-default');
+ if ($(event.data.fake_input).val()!='' && $(event.data.fake_input).val()!=d) {
+ if( (event.data.minChars <= $(event.data.fake_input).val().length) && (!event.data.maxChars || (event.data.maxChars >= $(event.data.fake_input).val().length)) )
+ $(event.data.real_input).addTag($(event.data.fake_input).val(),{focus:true,unique:(settings.unique)});
+ } else {
+ $(event.data.fake_input).val($(event.data.fake_input).attr('data-default'));
+ $(event.data.fake_input).css('color',settings.placeholderColor);
+ }
+ return false;
+ });
+
+ }
+ // if user types a comma, create a new tag
+ $(data.fake_input).bind('keypress',data,function(event) {
+ if (event.which==event.data.delimiter.charCodeAt(0) || event.which==13 ) {
+ event.preventDefault();
+ if( (event.data.minChars <= $(event.data.fake_input).val().length) && (!event.data.maxChars || (event.data.maxChars >= $(event.data.fake_input).val().length)) )
+ $(event.data.real_input).addTag($(event.data.fake_input).val(),{focus:true,unique:(settings.unique)});
+ $(event.data.fake_input).resetAutosize(settings);
+ return false;
+ } else if (event.data.autosize) {
+ $(event.data.fake_input).doAutosize(settings);
+ }
+ });
+ //Delete last tag on backspace
+ data.removeWithBackspace && $(data.fake_input).bind('keydown', function(event)
+ {
+ if(event.keyCode == 8 && $(this).val() == '')
+ {
+ event.preventDefault();
+ var last_tag = $(this).closest('.tagsinput').find('.tag:last').text();
+ var id = $(this).attr('id').replace(/_tag$/, '');
+ last_tag = last_tag.replace(/[\s]+x$/, '');
+ $('#' + id).removeTag(escape(last_tag));
+ $(this).trigger('focus');
+ }
+ });
+ $(data.fake_input).blur();
+
+ //Removes the not_valid class when user changes the value of the fake input
+ if(data.unique) {
+ $(data.fake_input).keydown(function(event){
+ if(event.keyCode == 8 || String.fromCharCode(event.which).match(/\w+|[áéíóúÁÉÍÓÚñÑ,/]+/)) {
+ $(this).removeClass('not_valid');
+ }
+ });
+ }
+ } // if settings.interactive
+ });
+
+ return this;
+
+ };
+
+ $.fn.tagsInput.updateTagsField = function(obj,tagslist) {
+ var id = $(obj).attr('id');
+ $(obj).val(tagslist.join(delimiter[id]));
+ };
+
+ $.fn.tagsInput.importTags = function(obj,val) {
+ $(obj).val('');
+ var id = $(obj).attr('id');
+ var tags = val.split(delimiter[id]);
+ for (i=0; i -0400
+ return new Date(s);
+ },
+ datetime: function(elem) {
+ var iso8601 = $t.isTime(elem) ? $(elem).attr("datetime") : $(elem).attr("title");
+ return $t.parse(iso8601);
+ },
+ isTime: function(elem) {
+ // jQuery's `is()` doesn't play well with HTML5 in IE
+ return $(elem).get(0).tagName.toLowerCase() === "time"; // $(elem).is("time");
+ }
+ });
+
+ $.fn.timeago = function() {
+ var self = this;
+ self.each(refresh);
+
+ var $s = $t.settings;
+ if ($s.refreshMillis > 0) {
+ setInterval(function() { self.each(refresh); }, $s.refreshMillis);
+ }
+ return self;
+ };
+
+ function refresh() {
+ var data = prepareData(this);
+ if (!isNaN(data.datetime)) {
+ $(this).text(inWords(data.datetime));
+ }
+ return this;
+ }
+
+ function prepareData(element) {
+ element = $(element);
+ if (!element.data("timeago")) {
+ element.data("timeago", { datetime: $t.datetime(element) });
+ var text = $.trim(element.text());
+ if (text.length > 0 && !($t.isTime(element) && element.attr("title"))) {
+ element.attr("title", text);
+ }
+ }
+ return element.data("timeago");
+ }
+
+ function inWords(date) {
+ return $t.inWords(distance(date));
+ }
+
+ function distance(date) {
+ return (new Date().getTime() - date.getTime());
+ }
+
+ // fix for IE6 suckage
+ document.createElement("abbr");
+ document.createElement("time");
+}(jQuery));
diff --git a/lms/static/js/mustache.js b/lms/static/js/mustache.js
new file mode 100644
index 0000000000..aab62f9ddc
--- /dev/null
+++ b/lms/static/js/mustache.js
@@ -0,0 +1,613 @@
+/*!
+ * mustache.js - Logic-less {{mustache}} templates with JavaScript
+ * http://github.com/janl/mustache.js
+ */
+
+var Mustache;
+
+(function (exports) {
+ if (typeof module !== "undefined") {
+ module.exports = exports; // CommonJS
+ } else if (typeof define === "function") {
+ define(exports); // AMD
+ } else {
+ Mustache = exports; //
+
+
%block>
<%include file="/courseware/course_navigation.html" args="active_page='courseware'" />
diff --git a/lms/templates/discussion/_accordion.html b/lms/templates/discussion/_accordion.html
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/lms/templates/discussion/_ajax_single_thread.html b/lms/templates/discussion/_ajax_single_thread.html
new file mode 100644
index 0000000000..ab52a31d94
--- /dev/null
+++ b/lms/templates/discussion/_ajax_single_thread.html
@@ -0,0 +1,2 @@
+<%namespace name="renderer" file="_content_renderer.html"/>
+${renderer.render_comments(thread.get('children'))}
diff --git a/lms/templates/discussion/_blank_slate.html b/lms/templates/discussion/_blank_slate.html
new file mode 100644
index 0000000000..b8c8f58dda
--- /dev/null
+++ b/lms/templates/discussion/_blank_slate.html
@@ -0,0 +1,7 @@
+
+ % if performed_search:
+ Sorry! We can't find anything matching your search. Please try another search.
+ % else:
+ There are no posts here yet. Be the first one to post!
+ % endif
+
diff --git a/lms/templates/discussion/_content.mustache b/lms/templates/discussion/_content.mustache
new file mode 100644
index 0000000000..8f3a284510
--- /dev/null
+++ b/lms/templates/discussion/_content.mustache
@@ -0,0 +1,62 @@
+
+
+
+
▲
+
{{content.votes.point}}
+
▼
+
+
+
+ {{#thread}}
+
{{{content.displayed_title}}}
+
{{{content.title}}}
+ {{/thread}}
+
+
+
{{{content.displayed_body}}}
+
{{{content.body}}}
+ {{#thread}}
+
+
{{content.raw_tags}}
+ {{/thread}}
+
+
+
+
+
diff --git a/lms/templates/discussion/_content_renderer.html b/lms/templates/discussion/_content_renderer.html
new file mode 100644
index 0000000000..88b87da4a2
--- /dev/null
+++ b/lms/templates/discussion/_content_renderer.html
@@ -0,0 +1,22 @@
+<%! import django_comment_client.helpers as helpers %>
+
+<%def name="render_content(content)">
+ ${helpers.render_content(content)}
+%def>
+
+<%def name="render_content_with_comments(content)">
+
+ ${render_content(content)}
+ % if content.get('children') is not None:
+ ${render_comments(content['children'])}
+ % endif
+
+%def>
+
+<%def name="render_comments(comments)">
+
+%def>
diff --git a/lms/templates/discussion/_discussion_module.html b/lms/templates/discussion/_discussion_module.html
new file mode 100644
index 0000000000..3d92f242a1
--- /dev/null
+++ b/lms/templates/discussion/_discussion_module.html
@@ -0,0 +1,3 @@
+
diff --git a/lms/templates/discussion/_forum.html b/lms/templates/discussion/_forum.html
new file mode 100644
index 0000000000..21dd182002
--- /dev/null
+++ b/lms/templates/discussion/_forum.html
@@ -0,0 +1,26 @@
+<%namespace name="renderer" file="_content_renderer.html"/>
+
+
+
+
+
+ <%include file="_search_bar.html" />
+
+
+ % if len(threads) == 0:
+
+ <%include file="_blank_slate.html" />
+
+
+ % else:
+ <%include file="_sort.html" />
+
+ % for thread in threads:
+ ${renderer.render_content_with_comments(thread)}
+ % endfor
+
+ <%include file="_paginator.html" />
+ % endif
+
+
+<%include file="_js_data.html" />
diff --git a/lms/templates/discussion/_inline.html b/lms/templates/discussion/_inline.html
new file mode 100644
index 0000000000..1737e2e558
--- /dev/null
+++ b/lms/templates/discussion/_inline.html
@@ -0,0 +1,16 @@
+<%namespace name="renderer" file="_content_renderer.html"/>
+
+
+
+
+
+
+ % for thread in threads:
+ ${renderer.render_content_with_comments(thread)}
+ % endfor
+
+
+ <%include file="_paginator.html" />
+
+
+<%include file="_js_data.html" />
diff --git a/lms/templates/discussion/_js_data.html b/lms/templates/discussion/_js_data.html
new file mode 100644
index 0000000000..3e1dc4c280
--- /dev/null
+++ b/lms/templates/discussion/_js_data.html
@@ -0,0 +1,10 @@
+<%! from django.template.defaultfilters import escapejs %>
+
+
diff --git a/lms/templates/discussion/_js_dependencies.html b/lms/templates/discussion/_js_dependencies.html
new file mode 100644
index 0000000000..588ca1830c
--- /dev/null
+++ b/lms/templates/discussion/_js_dependencies.html
@@ -0,0 +1,31 @@
+<%namespace name='static' file='../static_content.html'/>
+
+
+
+## This must appear after all mathjax-config blocks, so it is after the imports from the other templates.
+## It can't be run through static.url because MathJax uses crazy url introspection to do lazy loading of MathJax extension libraries
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/lms/templates/discussion/_paginator.html b/lms/templates/discussion/_paginator.html
new file mode 100644
index 0000000000..25d2c06213
--- /dev/null
+++ b/lms/templates/discussion/_paginator.html
@@ -0,0 +1,62 @@
+<%! from urllib import urlencode %>
+
+<%
+ def merge(dic1, dic2):
+ return dict(dic1.items() + dic2.items())
+
+ def url_for_page(_page):
+ return base_url + '?' + urlencode(merge(query_params, {'page': _page}))
+%>
+
+<%def name="link_to_page(_page, text)">
+ ${text}
+%def>
+
+<%def name="div_page(_page)">
+ % if _page != page:
+
+ ${link_to_page(_page, str(_page))}
+
+ % else:
+ ${_page}
+ % endif
+%def>
+
+<%def name="list_pages(*args)">
+ % for arg in args:
+ % if arg == 'dots':
+ ...
+ % elif isinstance(arg, list):
+ % for _page in arg:
+ ${div_page(_page)}
+ % endfor
+ % else:
+ ${div_page(arg)}
+ % endif
+ % endfor
+%def>
+
+
+
+ % if page > 1:
+ ${link_to_page(page - 1, "< Previous page")}
+ % endif
+
+
+ % if num_pages <= 2 * pages_nearby_delta + 2:
+ ${list_pages(range(1, num_pages + 1))}
+ % else:
+ % if page <= 2 * pages_nearby_delta:
+ ${list_pages(range(1, 2 * pages_nearby_delta + 2), 'dots', num_pages)}
+ % elif num_pages - page + 1 <= 2 * pages_nearby_delta:
+ ${list_pages(1, 'dots', range(num_pages - 2 * pages_nearby_delta, num_pages + 1))}
+ % else:
+ ${list_pages(1, 'dots', range(page - pages_nearby_delta, page + pages_nearby_delta + 1), 'dots', num_pages)}
+ % endif
+ % endif
+
+ % if page < num_pages:
+ ${link_to_page(page + 1, "Next page >")}
+ % endif
+
+
diff --git a/lms/templates/discussion/_recent_active_posts.html b/lms/templates/discussion/_recent_active_posts.html
new file mode 100644
index 0000000000..8fdf7d95e7
--- /dev/null
+++ b/lms/templates/discussion/_recent_active_posts.html
@@ -0,0 +1,13 @@
+% if recent_active_threads:
+
+% endif
diff --git a/lms/templates/discussion/_search_bar.html b/lms/templates/discussion/_search_bar.html
new file mode 100644
index 0000000000..e93b46efb2
--- /dev/null
+++ b/lms/templates/discussion/_search_bar.html
@@ -0,0 +1,18 @@
+<%! from urllib import urlencode %>
+<%
+
+def merge(dic1, dic2):
+ return dict(dic1.items() + dic2.items())
+
+def base_url_for_search():
+ return base_url + '?' + urlencode(merge(query_params, {'page': 1}))
+%>
+
+
diff --git a/lms/templates/discussion/_single_thread.html b/lms/templates/discussion/_single_thread.html
new file mode 100644
index 0000000000..523945be56
--- /dev/null
+++ b/lms/templates/discussion/_single_thread.html
@@ -0,0 +1,8 @@
+<%namespace name="renderer" file="_content_renderer.html"/>
+
+
+ Discussion
+ ${renderer.render_content_with_comments(thread)}
+
+
+<%include file="_js_data.html" />
diff --git a/lms/templates/discussion/_sort.html b/lms/templates/discussion/_sort.html
new file mode 100644
index 0000000000..8045e3936e
--- /dev/null
+++ b/lms/templates/discussion/_sort.html
@@ -0,0 +1,41 @@
+<%! from urllib import urlencode %>
+
+<%def name="link_to_sort(key, title)">
+ % if key == sort_key:
+ ${_link_to_sort(key, None, title + '', 'sorted')}
+
+ % else:
+ ${_link_to_sort(key, 'desc', title)}
+ % endif
+%def>
+
+<%def name="_link_to_sort(key, order, title, cls='')">
+ <%
+ def merge(dic1, dic2):
+ return dict(dic1.items() + dic2.items())
+
+ def url_for_sort(key, order):
+ if order is None:
+ return ''
+ else:
+ return base_url + '?' + urlencode(merge(query_params, {'page': 1, 'sort_key': key, 'sort_order': order}))
+ %>
+ ${title}
+%def>
+
+
+ Sort by:
+ ${link_to_sort('activity', 'top')}
+
+ ${link_to_sort('date', 'date')}
+
+ ${link_to_sort('votes', 'votes')}
+
+ ${link_to_sort('comments', 'comments')}
+
diff --git a/lms/templates/discussion/_trending_tags.html b/lms/templates/discussion/_trending_tags.html
new file mode 100644
index 0000000000..2f9e874280
--- /dev/null
+++ b/lms/templates/discussion/_trending_tags.html
@@ -0,0 +1,12 @@
+% if trending_tags:
+
+% endif
diff --git a/lms/templates/discussion/_user_active_threads.html b/lms/templates/discussion/_user_active_threads.html
new file mode 100644
index 0000000000..c3f5d0c403
--- /dev/null
+++ b/lms/templates/discussion/_user_active_threads.html
@@ -0,0 +1,16 @@
+<%namespace name="renderer" file="_thread.html"/>
+
+
+
+
+
+
+ % for thread in threads:
+ ${renderer.render_thread(course_id, thread, show_comments=True)}
+ % endfor
+
+
+ <%include file="_paginator.html" />
+
+
+<%include file="_js_data.html" />
diff --git a/lms/templates/discussion/_user_profile.html b/lms/templates/discussion/_user_profile.html
new file mode 100644
index 0000000000..6d7bc13e8c
--- /dev/null
+++ b/lms/templates/discussion/_user_profile.html
@@ -0,0 +1,23 @@
+<%! from django_comment_client.utils import pluralize %>
+<%! from django_comment_client.permissions import has_permission, check_permissions_by_view %>
+<%! from operator import attrgetter %>
+
+
+
+ <%
+ role_names = sorted(map(attrgetter('name'), django_user.roles.all()))
+ %>
+
+
+
+
+ % if check_permissions_by_view(user, course.id, content=None, name='update_moderator_status'):
+ % if "Moderator" in role_names:
+
+ % else:
+
+ % endif
+ % endif
+
diff --git a/lms/templates/discussion/ajax_create_comment.html b/lms/templates/discussion/ajax_create_comment.html
new file mode 100644
index 0000000000..92f78f9e52
--- /dev/null
+++ b/lms/templates/discussion/ajax_create_comment.html
@@ -0,0 +1,3 @@
+<%namespace name="renderer" file="_content_renderer.html"/>
+
+${renderer.render_content_with_comments(content)}
diff --git a/lms/templates/discussion/ajax_create_thread.html b/lms/templates/discussion/ajax_create_thread.html
new file mode 100644
index 0000000000..92f78f9e52
--- /dev/null
+++ b/lms/templates/discussion/ajax_create_thread.html
@@ -0,0 +1,3 @@
+<%namespace name="renderer" file="_content_renderer.html"/>
+
+${renderer.render_content_with_comments(content)}
diff --git a/lms/templates/discussion/ajax_update_comment.html b/lms/templates/discussion/ajax_update_comment.html
new file mode 100644
index 0000000000..2a451bb34c
--- /dev/null
+++ b/lms/templates/discussion/ajax_update_comment.html
@@ -0,0 +1,3 @@
+<%namespace name="renderer" file="_content_renderer.html"/>
+
+${renderer.render_content(content)}
diff --git a/lms/templates/discussion/ajax_update_thread.html b/lms/templates/discussion/ajax_update_thread.html
new file mode 100644
index 0000000000..2a451bb34c
--- /dev/null
+++ b/lms/templates/discussion/ajax_update_thread.html
@@ -0,0 +1,3 @@
+<%namespace name="renderer" file="_content_renderer.html"/>
+
+${renderer.render_content(content)}
diff --git a/lms/templates/discussion/ajax_user_profile.html b/lms/templates/discussion/ajax_user_profile.html
new file mode 100644
index 0000000000..c24081845f
--- /dev/null
+++ b/lms/templates/discussion/ajax_user_profile.html
@@ -0,0 +1 @@
+<%include file="_user_profile.html" />
diff --git a/lms/templates/discussion/index.html b/lms/templates/discussion/index.html
new file mode 100644
index 0000000000..9b0494dfff
--- /dev/null
+++ b/lms/templates/discussion/index.html
@@ -0,0 +1,36 @@
+<%inherit file="../main.html" />
+<%namespace name='static' file='../static_content.html'/>
+<%block name="bodyclass">discussion%block>
+<%block name="title">Discussion – MITx 6.002x%block>
+
+<%block name="headextra">
+<%static:css group='course'/>
+%block>
+
+<%block name="js_extra">
+<%include file="_js_dependencies.html" />
+%block>
+
+<%include file="/courseware/course_navigation.html" args="active_page='discussion'" />
+
+
+
+
+
+
+
+
+
+
diff --git a/lms/templates/discussion/user_profile.html b/lms/templates/discussion/user_profile.html
new file mode 100644
index 0000000000..c4d0d85607
--- /dev/null
+++ b/lms/templates/discussion/user_profile.html
@@ -0,0 +1,40 @@
+<%! from django.template.defaultfilters import escapejs %>
+<%namespace name="renderer" file="_thread.html"/>
+
+<%inherit file="../main.html" />
+<%namespace name='static' file='../static_content.html'/>
+<%block name="bodyclass">discussion%block>
+<%block name="title">Discussion – MITx 6.002x%block>
+
+<%block name="headextra">
+<%static:css group='course'/>
+%block>
+
+<%block name="js_extra">
+<%include file="_js_dependencies.html" />
+%block>
+
+<%include file="/courseware/course_navigation.html" args="active_page='discussion'" />
+
+
+
+
diff --git a/lms/templates/main.html b/lms/templates/main.html
index 891d770637..51b8d6030e 100644
--- a/lms/templates/main.html
+++ b/lms/templates/main.html
@@ -14,6 +14,7 @@
<%static:js group='main_vendor'/>
<%block name="headextra"/>
+
diff --git a/lms/templates/news.html b/lms/templates/news.html
new file mode 100644
index 0000000000..2c37975e2a
--- /dev/null
+++ b/lms/templates/news.html
@@ -0,0 +1,22 @@
+<%inherit file="main.html" />
+<%namespace name='static' file='static_content.html'/>
+<%block name="bodyclass">courseware news%block>
+<%block name="title">News – MITx 6.002x%block>
+
+<%block name="headextra">
+<%static:css group='course'/>
+%block>
+
+<%block name="js_extra">
+%block>
+
+<%include file="/courseware/course_navigation.html" args="active_page='news'" />
+
+
+
+
+ Updates to Discussion Posts You Follow
+ ${content}
+
+
+
diff --git a/lms/templates/notifications.html b/lms/templates/notifications.html
new file mode 100644
index 0000000000..986a09500b
--- /dev/null
+++ b/lms/templates/notifications.html
@@ -0,0 +1,79 @@
+<%! from django.core.urlresolvers import reverse %>
+
+<%
+def url_for_thread(discussion_id, thread_id):
+ return reverse('django_comment_client.forum.views.single_thread', args=[course.id, discussion_id, thread_id])
+%>
+
+<%
+def url_for_comment(discussion_id, thread_id, comment_id):
+ return url_for_thread(discussion_id, thread_id) + "#" + comment_id
+%>
+
+<%
+def url_for_discussion(discussion_id):
+ return reverse('django_comment_client.forum.views.forum_form_discussion', args=[course.id, discussion_id])
+%>
+
+<%
+def discussion_title(discussion_id):
+ return get_discussion_title(discussion_id=discussion_id)
+%>
+
+<%
+def url_for_user(user_id): #TODO
+ return "javascript:void(0)"
+%>
+
+
+
+ % for notification in notifications:
+ ${render_notification(notification)}
+ % endfor
+
+
+<%def name="render_user_link(notification)">
+ <% info = notification['info'] %>
+ % if notification.get('actor_id', None):
+ ${info['actor_username']}
+ % else:
+ Anonymous
+ % endif
+%def>
+
+<%def name="render_thread_link(notification)">
+ <% info = notification['info'] %>
+ ${info['thread_title']}
+%def>
+
+<%def name="render_comment_link(notification)">
+ <% info = notification['info'] %>
+ comment
+%def>
+
+<%def name="render_discussion_link(notification)">
+ <% info = notification['info'] %>
+ ${discussion_title(info['commentable_id'])}
+%def>
+
+<%def name="render_notification(notification)">
+
+ % if notification['notification_type'] == 'post_reply':
+ ${render_user_link(notification)} posted a ${render_comment_link(notification)}
+ to the thread ${render_thread_link(notification)} in discussion ${render_discussion_link(notification)}
+ % elif notification['notification_type'] == 'post_topic':
+ ${render_user_link(notification)} posted a new thread ${render_thread_link(notification)}
+ in discussion ${render_discussion_link(notification)}
+ % elif notification['notification_type'] == 'at_user':
+ ${render_user(info)} mentioned you in
+ % if notification['info']['content_type'] == 'thread':
+ the thread ${render_thread_link(notification)}
+ in discussion ${render_discussion_link(notification)}
+ % else:
+ ${render_comment_link(notification)}
+ to the thread ${render_thread_link(notification)} in discussion ${render_discussion_link(notification)}
+ % endif
+ % endif
+
+
+%def>
diff --git a/lms/urls.py b/lms/urls.py
index a3c6c9cdad..a4626896d2 100644
--- a/lms/urls.py
+++ b/lms/urls.py
@@ -147,6 +147,7 @@ if settings.COURSEWARE_ENABLED:
# For the instructor
url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/instructor$',
'courseware.views.instructor_dashboard', name="instructor_dashboard"),
+
url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/gradebook$',
'courseware.views.gradebook', name='gradebook'),
url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/grade_summary$',
@@ -154,6 +155,16 @@ if settings.COURSEWARE_ENABLED:
)
+ # discussion forums live within courseware, so courseware must be enabled first
+ if settings.MITX_FEATURES.get('ENABLE_DISCUSSION_SERVICE'):
+
+ urlpatterns += (
+ url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/news$',
+ 'courseware.views.news', name="news"),
+ url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/discussion/',
+ include('django_comment_client.urls'))
+ )
+
# Multicourse wiki
if settings.WIKI_ENABLED:
from wiki.urls import get_pattern as wiki_pattern
@@ -189,6 +200,8 @@ if settings.ASKBOT_ENABLED:
# url(r'^robots.txt$', include('robots.urls')),
)
+
+
if settings.DEBUG:
## Jasmine
urlpatterns=urlpatterns + (url(r'^_jasmine/', include('django_jasmine.urls')),)