Commit 044a69d6 by Joe Blaylock

Merge pull request #52 from edx/nate/simple-chat

Simple port of Class2Go's chat feature
parents 4a127e51 50c90673
...@@ -192,9 +192,8 @@ class CourseFields(object): ...@@ -192,9 +192,8 @@ class CourseFields(object):
}}, }},
scope=Scope.content) scope=Scope.content)
show_calculator = Boolean(help="Whether to show the calculator in this course", default=False, scope=Scope.settings) show_calculator = Boolean(help="Whether to show the calculator in this course", default=False, scope=Scope.settings)
display_name = String( display_name = String(help="Display name for this module", default="Empty", display_name="Display Name", scope=Scope.settings)
help="Display name for this module", default="Empty", show_chat = Boolean(help="Whether to show the chat widget in this course", default=False, scope=Scope.settings)
display_name="Display Name", scope=Scope.settings)
tabs = List(help="List of tabs to enable in this course", scope=Scope.settings) tabs = List(help="List of tabs to enable in this course", scope=Scope.settings)
end_of_course_survey_url = String(help="Url for the end-of-course survey", scope=Scope.settings) end_of_course_survey_url = String(help="Url for the end-of-course survey", scope=Scope.settings)
discussion_blackouts = List(help="List of pairs of start/end dates for discussion blackouts", scope=Scope.settings) discussion_blackouts = List(help="List of pairs of start/end dates for discussion blackouts", scope=Scope.settings)
......
...@@ -6,6 +6,7 @@ from django.http import Http404 ...@@ -6,6 +6,7 @@ from django.http import Http404
from django.test.utils import override_settings from django.test.utils import override_settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.test.client import RequestFactory from django.test.client import RequestFactory
from django.conf import settings
from student.models import CourseEnrollment from student.models import CourseEnrollment
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
...@@ -124,3 +125,26 @@ class ViewsTestCase(TestCase): ...@@ -124,3 +125,26 @@ class ViewsTestCase(TestCase):
self.assertContains(result, expected_end_text) self.assertContains(result, expected_end_text)
else: else:
self.assertNotContains(result, "Classes End") self.assertNotContains(result, "Classes End")
def test_chat_settings(self):
mock_user = MagicMock()
mock_user.username = "johndoe"
mock_course = MagicMock()
mock_course.id = "a/b/c"
# Stub this out in the case that it's not in the settings
domain = "jabber.edx.org"
settings.JABBER_DOMAIN = domain
chat_settings = views.chat_settings(mock_course, mock_user)
# Test the proper format of all chat settings
self.assertEquals(chat_settings['domain'], domain)
self.assertEquals(chat_settings['room'], "a-b-c_class")
self.assertEquals(chat_settings['username'], "johndoe@%s" % domain)
# TODO: this needs to be changed once we figure out how to
# generate/store a real password.
self.assertEquals(chat_settings['password'], "johndoe@%s" % domain)
...@@ -40,7 +40,6 @@ log = logging.getLogger("mitx.courseware") ...@@ -40,7 +40,6 @@ log = logging.getLogger("mitx.courseware")
template_imports = {'urllib': urllib} template_imports = {'urllib': urllib}
def user_groups(user): def user_groups(user):
""" """
TODO (vshnayder): This is not used. When we have a new plan for groups, adjust appropriately. TODO (vshnayder): This is not used. When we have a new plan for groups, adjust appropriately.
...@@ -236,6 +235,36 @@ def update_timelimit_module(user, course_id, model_data_cache, timelimit_descrip ...@@ -236,6 +235,36 @@ def update_timelimit_module(user, course_id, model_data_cache, timelimit_descrip
return context return context
def chat_settings(course, user):
"""
Returns a dict containing the settings required to connect to a
Jabber chat server and room.
"""
domain = getattr(settings, "JABBER_DOMAIN", None)
if domain is None:
log.warning('You must set JABBER_DOMAIN in the settings to '
'enable the chat widget')
return None
return {
'domain': domain,
# Jabber doesn't like slashes, so replace with dashes
'room': "{ID}_class".format(ID=course.id.replace('/', '-')),
'username': "{USER}@{DOMAIN}".format(
USER=user.username, DOMAIN=domain
),
# TODO: clearly this needs to be something other than the username
# should also be something that's not necessarily tied to a
# particular course
'password': "{USER}@{DOMAIN}".format(
USER=user.username, DOMAIN=domain
),
}
@login_required @login_required
@ensure_csrf_cookie @ensure_csrf_cookie
@cache_control(no_cache=True, no_store=True, must_revalidate=True) @cache_control(no_cache=True, no_store=True, must_revalidate=True)
...@@ -300,6 +329,18 @@ def index(request, course_id, chapter=None, section=None, ...@@ -300,6 +329,18 @@ def index(request, course_id, chapter=None, section=None,
'xqa_server': settings.MITX_FEATURES.get('USE_XQA_SERVER', 'http://xqa:server@content-qa.mitx.mit.edu/xqa') 'xqa_server': settings.MITX_FEATURES.get('USE_XQA_SERVER', 'http://xqa:server@content-qa.mitx.mit.edu/xqa')
} }
# Only show the chat if it's enabled by the course and in the
# settings.
show_chat = course.show_chat and settings.MITX_FEATURES['ENABLE_CHAT']
if show_chat:
context['chat'] = chat_settings(course, user)
# If we couldn't load the chat settings, then don't show
# the widget in the courseware.
if context['chat'] is None:
show_chat = False
context['show_chat'] = show_chat
chapter_descriptor = course.get_child_by(lambda m: m.url_name == chapter) chapter_descriptor = course.get_child_by(lambda m: m.url_name == chapter)
if chapter_descriptor is not None: if chapter_descriptor is not None:
save_child_position(course_module, chapter) save_child_position(course_module, chapter)
......
...@@ -144,6 +144,10 @@ MITX_FEATURES = { ...@@ -144,6 +144,10 @@ MITX_FEATURES = {
# Allow use of the hint managment instructor view. # Allow use of the hint managment instructor view.
'ENABLE_HINTER_INSTRUCTOR_VIEW': False, 'ENABLE_HINTER_INSTRUCTOR_VIEW': False,
# Toggle to enable chat availability (configured on a per-course
# basis in Studio)
'ENABLE_CHAT': False
} }
# Used for A/B testing # Used for A/B testing
......
Simple Smileys is a set of 49 clean, free as in freedom, Public Domain smileys.
For more packages or older versions, visit http://simplesmileys.org
/*
* Date Format 1.2.3
* (c) 2007-2009 Steven Levithan <stevenlevithan.com>
* MIT license
*
* Includes enhancements by Scott Trenda <scott.trenda.net>
* and Kris Kowal <cixar.com/~kris.kowal/>
*
* Accepts a date, a mask, or a date and a mask.
* Returns a formatted version of the given date.
* The date defaults to the current date/time.
* The mask defaults to dateFormat.masks.default.
*
* @link http://blog.stevenlevithan.com/archives/date-time-format
*/
var dateFormat = function () {
var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,
timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
timezoneClip = /[^-+\dA-Z]/g,
pad = function (val, len) {
val = String(val);
len = len || 2;
while (val.length < len) val = "0" + val;
return val;
};
// Regexes and supporting functions are cached through closure
return function (date, mask, utc) {
var dF = dateFormat;
// You can't provide utc if you skip other args (use the "UTC:" mask prefix)
if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) {
mask = date;
date = undefined;
}
// Passing date through Date applies Date.parse, if necessary
date = date ? new Date(date) : new Date;
if (isNaN(date)) throw SyntaxError("invalid date");
mask = String(dF.masks[mask] || mask || dF.masks["default"]);
// Allow setting the utc argument via the mask
if (mask.slice(0, 4) == "UTC:") {
mask = mask.slice(4);
utc = true;
}
var _ = utc ? "getUTC" : "get",
d = date[_ + "Date"](),
D = date[_ + "Day"](),
m = date[_ + "Month"](),
y = date[_ + "FullYear"](),
H = date[_ + "Hours"](),
M = date[_ + "Minutes"](),
s = date[_ + "Seconds"](),
L = date[_ + "Milliseconds"](),
o = utc ? 0 : date.getTimezoneOffset(),
flags = {
d: d,
dd: pad(d),
ddd: dF.i18n.dayNames[D],
dddd: dF.i18n.dayNames[D + 7],
m: m + 1,
mm: pad(m + 1),
mmm: dF.i18n.monthNames[m],
mmmm: dF.i18n.monthNames[m + 12],
yy: String(y).slice(2),
yyyy: y,
h: H % 12 || 12,
hh: pad(H % 12 || 12),
H: H,
HH: pad(H),
M: M,
MM: pad(M),
s: s,
ss: pad(s),
l: pad(L, 3),
L: pad(L > 99 ? Math.round(L / 10) : L),
t: H < 12 ? "a" : "p",
tt: H < 12 ? "am" : "pm",
T: H < 12 ? "A" : "P",
TT: H < 12 ? "AM" : "PM",
Z: utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
o: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
S: ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
};
return mask.replace(token, function ($0) {
return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
});
};
}();
// Some common format strings
dateFormat.masks = {
"default": "ddd mmm dd yyyy HH:MM:ss",
shortDate: "m/d/yy",
mediumDate: "mmm d, yyyy",
longDate: "mmmm d, yyyy",
fullDate: "dddd, mmmm d, yyyy",
shortTime: "h:MM TT",
mediumTime: "h:MM:ss TT",
longTime: "h:MM:ss TT Z",
isoDate: "yyyy-mm-dd",
isoTime: "HH:MM:ss",
isoDateTime: "yyyy-mm-dd'T'HH:MM:ss",
isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
};
// Internationalization strings
dateFormat.i18n = {
dayNames: [
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
],
monthNames: [
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
]
};
// For convenience...
Date.prototype.format = function (mask, utc) {
return dateFormat(this, mask, utc);
};
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
$(window).load(function() {
var isInIframe = (window.location != window.parent.location) ? true : false;
if (isInIframe) {
$('#chat-pane #chat-tabs').prepend('<div id="chat-expand-arrow"><em class="icon-chevron-right"></em></div>');
} else {
$('#candy').addClass('poppedOut').append('<a href="#" onclick="event.preventDefault();" title="Pop-In Chat Window" class="icon-signin" id="chatPopin"></a>');
}
var collapseMessageForm = function() {
$('#candy').animate({width: '230px'}, 'slow', function() {
$('#chat-expand-arrow em').toggleClass('icon-chevron-left').toggleClass('icon-chevron-right');
$('#chat-pane').toggleClass('collapsed-message-pane');
});
$('#chat-pane .roster-pane').animate({top: '0px'}, 'slow');
$('#chat-rooms .message-pane-wrapper, #chat-rooms .message-form-wrapper, form.message-form').fadeOut('slow');
}
var expandMessageForm = function() {
$('#chat-pane').toggleClass('collapsed-message-pane');
$('#candy').animate({width: '100%'}, 'slow', function() {
$('#chat-expand-arrow em').toggleClass('icon-chevron-left').toggleClass('icon-chevron-right');
});
$('#chat-pane .roster-pane').animate({top: '30px'}, 'slow');
$('#chat-rooms .message-pane-wrapper, #chat-rooms .message-form-wrapper, form.message-form').fadeIn('slow');
}
var activeTab;
$('#chat-expand-arrow').click(function() {
if ($('#chat-pane').hasClass('collapsed-message-pane')) {
activeTab.addClass('active');
expandMessageForm();
} else {
activeTab = $('#chat-tabs li.active');
$('#chat-tabs li').removeClass('active');
collapseMessageForm();
}
});
$('#chat-tabs').click(function(event) {
if ($(this).has(event.target).length && $('#chat-pane').hasClass('collapsed-message-pane')) {
expandMessageForm();
}
});
$('#chatPopin').click(function() {
window.close();
});
});
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
@import 'course/courseware/amplifier'; @import 'course/courseware/amplifier';
@import 'course/layout/calculator'; @import 'course/layout/calculator';
@import 'course/layout/timer'; @import 'course/layout/timer';
@import 'course/layout/chat';
// course-specific courseware (all styles in these files should be gated by a // course-specific courseware (all styles in these files should be gated by a
// course-specific class). This should be replaced with a better way of // course-specific class). This should be replaced with a better way of
......
/* Chat
-------------------------------------------------- */
#chat-wrapper {
position: fixed;
bottom: 0;
left: 0;
z-index: 1000;
}
#chat-toggle {
position: absolute;
left: 0;
top: -45px;
height: 25px;
width: 170px;
padding: 10px 15px;
background: #333;
border-top-right-radius: 10px;
span {
color: #dcdcdc;
font-weight: bold;
font-size: 18px;
}
cursor: pointer;
}
#chat-toggle:hover {
text-decoration: none;
}
#chat-open {
display: inline;
}
#chat-close {
display: none;
}
#chat-toggle em {
position: absolute;
right: 20px;
top: 12px;
font-size: 28px !important;
}
#chat-block {
position: relative;
float: left;
width: 600px;
height: 0px;
bottom: 0;
right: 0;
margin: 0 !important;
border: none !important;
display: none;
}
...@@ -6,6 +6,13 @@ ...@@ -6,6 +6,13 @@
<%block name="headextra"> <%block name="headextra">
<%static:css group='course'/> <%static:css group='course'/>
<%include file="../discussion/_js_head_dependencies.html" /> <%include file="../discussion/_js_head_dependencies.html" />
% if show_chat:
<link rel="stylesheet" href="${static.url('css/vendor/ui-lightness/jquery-ui-1.8.22.custom.css')}" />
## It'd be better to have this in a place like lms/css/vendor/candy,
## but the candy_res/ folder contains images and other junk, and it
## all needs to stay together for the Candy.js plugin to work.
<link rel="stylesheet" href="${static.url('candy_res/candy_full.css')}" />
% endif
</%block> </%block>
<%block name="js_extra"> <%block name="js_extra">
...@@ -108,6 +115,40 @@ ...@@ -108,6 +115,40 @@
</script> </script>
% endif % endif
% if show_chat:
<script type="text/javascript" src="${static.url('js/vendor/candy_libs/libs.min.js')}"></script>
<script type="text/javascript" src="${static.url('js/vendor/candy.min.js')}"></script>
<script type="text/javascript">
// initialize the Candy.js plugin
$(document).ready(function() {
Candy.init("http://${chat['domain']}:5280/http-bind/", {
core: { debug: true, autojoin: ["${chat['room']}@conference.${chat['domain']}"] },
view: { resources: "${static.url('candy_res/')}"}
});
Candy.Core.connect("${chat['username']}", "${chat['password']}");
// show/hide the chat widget
$('#chat-toggle').click(function() {
var toggle = $(this);
if (toggle.hasClass('closed')) {
$('#chat-block').show().animate({height: '400px'}, 'slow', function() {
$('#chat-open').hide();
$('#chat-close').show();
});
} else {
$('#chat-block').animate({height: '0px'}, 'slow', function() {
$('#chat-open').show();
$('#chat-close').hide();
$(this).hide(); // do this at the very end
});
}
toggle.toggleClass('closed');
});
});
</script>
% endif
</%block> </%block>
% if timer_expiration_duration: % if timer_expiration_duration:
...@@ -148,6 +189,18 @@ ...@@ -148,6 +189,18 @@
</div> </div>
</section> </section>
% if show_chat:
<div id="chat-wrapper">
<div id="chat-toggle" class="closed">
<span id="chat-open">Open Chat <em class="icon-chevron-up"></em></span>
<span id="chat-close">Close Chat <em class="icon-chevron-down"></em></span>
</div>
<div id="chat-block">
## The Candy.js plugin wants to render in an element with #candy
<div id="candy"></div>
</div>
</div>
% endif
% if course.show_calculator: % if course.show_calculator:
<div class="calc-main"> <div class="calc-main">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment