Multiple fixes
authorchapel <jacob.chapel@gmail.com>
Sat, 19 Nov 2011 22:22:46 +0000 (14:22 -0800)
committerchapel <jacob.chapel@gmail.com>
Sat, 19 Nov 2011 22:22:46 +0000 (14:22 -0800)
- Fix not found errors
- Fix pass reset link in html
- Fix protodiv error in IE
- Fix button for new items showing when it shouldn't
- Move login info to use jquery to fill name

app.js
public/index.html
public/javascripts/main.js
public/javascripts/protodiv.js

diff --git a/app.js b/app.js
index 27d2fc544e06f8bb795a4f5b92e33767a7d933bd..62c543cb4567a6e669d45c3f8ed5577cd99d6442 100644 (file)
--- a/app.js
+++ b/app.js
@@ -327,7 +327,7 @@ function loadSchool( req, res, next ) {
       });
     } else {
       // If no school is found, display an appropriate error.
-      sendJson(res,  {status: 'error', message: 'Invalid school specified!'} );
+      sendJson(res,  {status: 'not_found', message: 'Invalid school specified!'} );
     }
   });
 }
@@ -351,7 +351,7 @@ function loadCourse( req, res, next ) {
       });
     } else {
       // If no course is found, display an appropriate error.
-      sendJson(res,  {status: 'error', message: 'Invalid course specified!'} );
+      sendJson(res,  {status: 'not_found', message: 'Invalid course specified!'} );
     }
   });
 }
@@ -375,7 +375,7 @@ function loadLecture( req, res, next ) {
       });
     } else {
       // If no lecture is found, display an appropriate error.
-      sendJson(res,  {status: 'error', message: 'Invalid lecture specified!'} );
+      sendJson(res,  {status: 'not_found', message: 'Invalid lecture specified!'} );
     }
   });
 }
index 5b5d069ecc8fc834dac195b23b0a4fdc0fe21b25..cd42b6cb6f2bfff065a5aad0f347de99321a0a36 100644 (file)
@@ -24,7 +24,7 @@
 
                <div class="masthead">
                        <div class="logbar">
-        <div class="loginstatus"><div id="login_status"><div id="PROTO_login_info">Currently logged in as <span class="username">__name__</span></div></div></div>
+        <div class="loginstatus"><div id="login_status" style="display:none;">Currently logged in as <span class="username"></span></div></div>
                        </div>
                        <div class="navbar">
                                <table>
                                        </div>
                                </div>
         <div>
-          <span class="sub_menu">
-            <a href="" id="new_course" style="display:none;">New Course</a>
+          <span class="sub_menu" style="display:none;">
+            <a href="" id="new_course">New Course</a>
           </span>
           <form method="POST" id="form_course" style="display:none;">
             <h1>Create New Course</h1>
                                        </div>
                                </div>
         <div>
-          <span class="sub_menu">
-            <a href="" id="new_lecture" style="display:none;">New Lecture</a>
+          <span class="sub_menu" style="display:none;">
+            <a href="" id="new_lecture">New Lecture</a>
           </span>
           <form method="POST" id="form_lecture" style="display:none;">
             <h1>Create New Lecture</h1>
                                        </div>
                                </div>
         <div>
-          <span class="sub_menu">
-            <a href="" id="new_note" style="display:none;">New Note Pad</a>
+          <span class="sub_menu" style="display:none;">
+            <a href="" id="new_note">New Note Pad</a>
           </span>
           <form method="POST" id="form_note" style="display:none;">
             <h1>Create New Note Pad</h1>
                                                        <div class="field">
                                                                <button class="major">Login</button>
                                                                <span class="reglink">
-                                                                       <a href="/resetpw">Forgot password?</a>
+                                                                       <a href="/resetpass">Forgot password?</a>
                                                                </span>
                                                        </div>
                                                </div>
index 62809a7be3b4045a2207d753f4d096abaebb1abb..6607b07d99220e3b4dfa71d6830e8f73610b64ca 100644 (file)
@@ -46,13 +46,13 @@ var router = {
 
 function render(pageId, response) {
   if (user.name) {
-    ProtoDiv.inject("PROTO_login_info", user)
+    $('.username').text(user.name);
     $("#login_status").show();
     $('#login_link').text('Logout').attr('href', '/logout');
     $('#register_link').hide();
     $('#profile_link').show();
   } else {
-    ProtoDiv.reset("PROTO_login_info");
+    $('.username').text('');
     $("#login_status").hide();
     $('#login_link').text('Login').attr('href', '/login');
     $('#register_link').show();
@@ -61,7 +61,6 @@ function render(pageId, response) {
   if (response) {
     if (response instanceof Array) {
       $.each(response, function() {
-        console.log(this.id, this.data)
         ProtoDiv.reset("PROTO_" + this.id)
         ProtoDiv.replicate("PROTO_" + this.id, this.data)
       })
@@ -130,7 +129,8 @@ router.add('schools', function(data, cb) {
 
 // go to the page that lists the courses for a specific school
 router.add('school', function(data, cb) {
-  $('#new_course').hide().unbind();
+  $('.sub_menu').hide();
+  $('#new_course').unbind();
   $('#form_course').hide().unbind();
   var response = {
     id: 'course',
@@ -140,7 +140,7 @@ router.add('school', function(data, cb) {
   $("#school_name").html(data.school.name);
 
   if (data.school.authorized) {
-    $('#new_course').show();
+    $('.sub_menu').show();
     $('#new_course').click(function(e) {
       e.preventDefault();
 
@@ -171,7 +171,8 @@ router.add('school', function(data, cb) {
 
 // go to the page that lists the lectures for a specific course
 router.add('course', function(data, cb) {
-  $('#new_lecture').hide().unbind();
+  $('.sub_menu').hide();
+  $('#new_lecture').unbind();
   $('#form_lecture').hide().unbind();;
 
   var response = [];
@@ -209,7 +210,7 @@ router.add('course', function(data, cb) {
   }
 
   if (data.course.authorized) {
-    $('#new_lecture').show();
+    $('.sub_menu').show();
     $('#new_lecture').click(function(e) {
       e.preventDefault();
 
@@ -239,7 +240,8 @@ 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) {
-  $('#new_note').hide().unbind();
+  $('.sub_menu').hide();
+  $('#new_note').unbind();
   $('#form_note').hide().unbind();;
 
   var response = [];
@@ -274,7 +276,7 @@ router.add('lecture', function(data, cb) {
   }
   
   if (data.lecture.authorized) {
-    $('#new_note').show();
+    $('.sub_menu').show();
     $('#new_note').click(function(e) {
       e.preventDefault();
 
@@ -354,7 +356,6 @@ router.add('register', false, function(cb) {
   $('#form_register').submit(function(e) {
     e.preventDefault();
 
-    console.log('register')
     var form = $(this);
 
     $.post(window.location.pathname, form.serialize(), function(data) {
@@ -383,7 +384,6 @@ router.add('profile', false, function(cb) {
   form.find('.email').text(user.email);
   form.find('input[name=name]').val(user.name);
   form.submit(function(e) {
-    console.log('test')
     e.preventDefault();
 
     $.post(window.location.pathname, form.serialize(), function(data) {
index bf07460a5e2c417ce5fa9fa51cf1f5e1672ecf27..09569f437d15c7a38cb282ff5fe5c244922f4fb9 100644 (file)
@@ -46,29 +46,29 @@ ProtoDiv.map = function(node, list, cb) {
        }
 }
 
-ProtoDiv.substitute = function(s, obj, i) {
-       if(i !== undefined)
-               s = s.replace(/__i__/g, i);
-       for(var key in obj) {
+ProtoDiv.substitute = function(s, obj) {
+       for(key in obj) {
                re = new RegExp("__"+key+"__", "g")
                s = s.replace(re, obj[key])
        }
        return s
 }
 
-ProtoDiv.inject = function(id, obj, n) {
+ProtoDiv.inject = function(id, obj) {
        var proto = ProtoDiv.elem(id)
+       var i
 
-       proto.innerHTML = ProtoDiv.substitute(proto.innerHTML, obj, n)
+       proto.innerHTML = ProtoDiv.substitute(proto.innerHTML, obj)
 
-       for(var i = 0; i < proto.attributes.length; i++) {
-               var a = proto.attributes[i]
-               a.textContent = ProtoDiv.substitute(a.textContent, obj, n)
+       for(i = 0; i < proto.attributes.length; i++) {
+               a = proto.attributes[i]
+    var x = a.textContent ? 'textContent' : 'value';
+               a[x] = ProtoDiv.substitute(a[x], obj)
        }
 
-       for(var key in obj) {
-               var c = key.substring(1)
-               var list = []
+       for(key in obj) {
+               c = key.substring(1)
+               list = []
                switch(key.substring(0,1)) {
                case "#":
                        ProtoDiv.map(proto, list, function(e) {
@@ -106,14 +106,12 @@ ProtoDiv.replicate = function(id, arr, keep) {
                proto.origDisplay = proto.style.display
        }
 
-       for(var i = 0; i < l; i++) {
+       for(i = 0; i < l; i++) {
                obj = arr[i]
-               var e = proto.cloneNode(true)
+               e = proto.cloneNode(true)
                delete e.id
                mom.insertBefore(e, sib)
-               ProtoDiv.inject(e, obj, i)
-               if(ProtoDiv.each)
-                       ProtoDiv.each(e, i, obj, mom)
+               ProtoDiv.inject(e, obj)
        }
 
        if(!keep)
@@ -134,5 +132,3 @@ ProtoDiv.reset = function(id) {
        }
        return proto
 }
-
-