tutorial: factor setting tutorial status into a function.

(imported from commit 3ec355e3bcad25bbe8dceb9a1fdb9e8cce5156ca)
This commit is contained in:
Jessica McKellar
2013-04-12 15:33:00 -04:00
parent df9c29984e
commit 6a0c1f66d8

View File

@@ -232,6 +232,15 @@ function add_to_tutorial_stream() {
}
}
function set_tutorial_status(status, callback) {
$.ajax({
type: 'POST',
url: '/json/tutorial_status',
data: {status: status},
success: callback
});
}
exports.start = function () {
if (tutorial_running) {
// Not more than one of these at once!
@@ -240,13 +249,7 @@ exports.start = function () {
tutorial_running = true;
add_to_tutorial_stream();
run_tutorial(0);
$.ajax({
type: 'POST',
url: '/json/tutorial_status',
data: {status: 'started'}
});
set_tutorial_status("started");
};
// This technique is not actually that awesome, because it's pretty
@@ -263,16 +266,10 @@ exports.stop = function () {
if (tutorial_running) {
subs.tutorial_unsubscribe_me_from(my_tutorial_stream);
tutorial_running = false;
$.ajax({
type: 'POST',
url: '/json/tutorial_status',
data: {status: 'finished'},
success: function () {
// We need to reload the streams list so the sidebar is populated
// with the new streams
subs.reload_subscriptions({clear_first: true});
}
set_tutorial_status("finished", function () {
// We need to reload the streams list so the sidebar is populated
// with the new streams
subs.reload_subscriptions({clear_first: true});
});
}
};