showing create course if auth\'ed and moving it to the right
[oweals/finalsclub.git] / public / javascripts / main.js
index 819f813935e496d755ee522e00e2ee717a2745cf..0aafffeb78b5ffad636b63196ea6d5fbd78bed87 100644 (file)
@@ -29,6 +29,7 @@ var router = {
     }
   },
   run: function(name, path) {
+    $('.nav').removeClass('active');
     checkUser(function() {
       if (router.routes[name].useAjax) {
         $.get(path, {cache: false}, function(data) {
@@ -46,13 +47,13 @@ var router = {
 
 function render(pageId, response) {
   if (user.name) {
-    $('.username').text(user.name);
+    $('.username').text("Hi, "+user.name+"!");
     $("#login_status").show();
     $('#login_link').text('Logout').attr('href', '/logout');
     $('#register_link').hide();
     $('#profile_link').show();
   } else {
-    $('.username').text('');
+    $('.username').text('Guest');
     $("#login_status").hide();
     $('#login_link').text('Login').attr('href', '/login');
     $('#register_link').show();
@@ -99,7 +100,11 @@ router.add('404', false, function() {
 
 router.add('home', false, function(cb) {
   $('#learnsomething').unbind();
+  $('.nav').removeClass('active');
        cb("home");
+  $('#signup').click(function(e) {
+    goPage('/register');
+  });
   $('#learnsomething').click(function(e) {
     $.get('/learn/random', function(data) {
       if (data.status === 'ok') {
@@ -116,7 +121,7 @@ router.add('home', false, function(cb) {
 
 // go to the page that lists the schools
 router.add('schools', function(data, cb) {
-
+  $('#school_link').addClass('active');
   var response = {
     id: 'school',
     data: data.schools
@@ -129,8 +134,9 @@ router.add('schools', function(data, cb) {
 
 // go to the page that lists the courses for a specific school
 router.add('school', function(data, cb) {
+  $('#school_link').addClass('active');
   $('.sub_menu').hide();
-  $('#new_course').unbind();
+  //$('#new_course').unbind();
   $('#form_course').hide().unbind();
   var response = {
     id: 'course',
@@ -141,27 +147,23 @@ router.add('school', function(data, cb) {
 
   if (data.school.authorized) {
     $('.sub_menu').show();
-    $('#new_course').click(function(e) {
-      e.preventDefault();
+    var form = $('#form_course');
 
-      var form = $('#form_course');
-
-      form.toggle();
+    form.toggle();
 
-      form.submit(function(e) {
-        e.preventDefault();
+    form.submit(function(e) {
+      e.preventDefault();
 
-        $.post(window.location.pathname, form.serialize(), function(data) {
-          if (data.status === 'error') {
-            message('error', data.message);
-          } else if (data.status === 'ok') {
-            form.hide();
-            goPage(window.location.pathname);
-            message('info', data.message);
-          }
-        });
-      })
-    });
+      $.post(window.location.pathname, form.serialize(), function(data) {
+        if (data.status === 'error') {
+          message('error', data.message);
+        } else if (data.status === 'ok') {
+          form.hide();
+          goPage(window.location.pathname);
+          message('info', data.message);
+        }
+      });
+    })
   }
   cb("courses", response)
 });
@@ -171,6 +173,7 @@ router.add('school', function(data, cb) {
 
 // go to the page that lists the lectures for a specific course
 router.add('course', function(data, cb) {
+  $('#school_link').addClass('active');
   $('.sub_menu').hide();
   $('#new_lecture').unbind();
   $('#form_lecture').hide().unbind();;
@@ -240,6 +243,7 @@ router.add('course', function(data, cb) {
 
 // go to the page that lists the note taking sessions for a specific lecture
 router.add('lecture', function(data, cb) {
+  $('#school_link').addClass('active');
   $('.sub_menu').hide();
   $('#new_note').unbind();
   $('#form_note').hide().unbind();;
@@ -304,6 +308,7 @@ router.add('lecture', function(data, cb) {
 
 // go to the page that lists the archived subject names
 router.add('archive', function(data, cb) {
+  $('#archive_link').addClass('active');
 
   var response = {
     id: 'archive_subject',
@@ -316,6 +321,8 @@ router.add('archive', function(data, cb) {
 
 
 router.add('archivesubject', function(data, cb) {
+  $('.nav').removeClass('active');
+  $('#archive_link').addClass('active');
 
   var response = {
     id: 'archive_course',
@@ -328,6 +335,7 @@ router.add('archivesubject', function(data, cb) {
 
 
 router.add('archivecourse', function(data, cb) {
+  $('#archive_link').addClass('active');
 
   var response = {
     id: 'archive_note',
@@ -340,6 +348,7 @@ router.add('archivecourse', function(data, cb) {
 
 
 router.add('archivenote', function(data, cb) {
+  $('#archive_link').addClass('active');
 
   var response = {
     id: 'archive_note_display',
@@ -353,6 +362,7 @@ router.add('archivenote', function(data, cb) {
 
 // go to the account registration page
 router.add('register', false, function(cb) {
+  $('#register_link').addClass('active');
   $('#form_register').submit(function(e) {
     e.preventDefault();
 
@@ -377,6 +387,7 @@ router.add('activate', function(data, cb) {
 });
 
 router.add('profile', false, function(cb) {
+  $('#profile_link').addClass('active');
   var form = $('#form_profile');
   $('input[type=password]','#form_profile').val('');
   $('#affiliation').attr('value', user.affil);
@@ -466,6 +477,7 @@ router.add('resetpw', false, function(cb) {
 
 // go to the press articles page
 router.add('press', false, function(cb) {
+  $('#press_link').addClass('active');
        cb("press");
 });