From ea54a6e676895cff64f28cfe2097e4715e25bf7d Mon Sep 17 00:00:00 2001 From: "fcdev@sleepless.com" Date: Sun, 13 Nov 2011 02:31:35 +0000 Subject: [PATCH] more work on 1page --- public/index.html | 28 ++++++++++++---- public/javascripts/main.js | 61 +++++++++++++++++++++++++--------- public/javascripts/protodiv.js | 12 ++++--- public/stylesheets/fc2.css | 17 +++++++--- 4 files changed, 87 insertions(+), 31 deletions(-) diff --git a/public/index.html b/public/index.html index e2c1b61..a7a0aac 100644 --- a/public/index.html +++ b/public/index.html @@ -87,9 +87,12 @@

Universities

-
- __name__ - (__numCourses__ courses) +
__name__
+
__description__
+
@@ -98,10 +101,23 @@

Courses for

+
+
__department__
+ +
+
- + + +
+

Lectures for

+
+
+ __name__ +
+
diff --git a/public/javascripts/main.js b/public/javascripts/main.js index f33d601..7273f79 100644 --- a/public/javascripts/main.js +++ b/public/javascripts/main.js @@ -25,15 +25,16 @@ function showPage(id) { -var schools = [] // go to the page that lists the schools +var schools = [] function goSchools() { + ProtoDiv.reset("PROTO_school"); hideAllPages(); $.get("/schools", {}, function(response) { - if(typeof response == 'object') + if(typeof response == 'object') { schools = response.schools - ProtoDiv.reset("PROTO_school"); + } ProtoDiv.replicate("PROTO_school", schools); showPage("schools") }); @@ -41,23 +42,51 @@ function goSchools() { -var courses = [] - // go to the page that lists the courses for a specific school -function goCourses(name) { +var courses = [] +function goCourses(schoolName, schoolId, a) { + ProtoDiv.reset("PROTO_course"); hideAllPages(); - $("#school_name").html(name); -// $.get("/courses", {}, function(response) { -// if(typeof response == 'object') -// courses = response.courses -var courses = [ -{ id: "4e6d1e9b42bbef522c000a8f", name: "History 12: Introduction to the Middle East" }, -{ id: "4e8aa3f62e4b97e67b001f47", name: "ANTH160AC/ISF 160: The Forms of Folklorek" } -] - ProtoDiv.reset("PROTO_course"); + $.get("/school/"+schoolId, {}, function(response) { + courses = [] + if(typeof response == 'object') { + var school = response.school + $("#school_name").html(school.name); + courses = school.courses + } ProtoDiv.replicate("PROTO_course", courses); showPage("courses") -// }); + }); +} + + + + +// go to the page that lists the lectures for a specific course +var lectures = [] +function goLectures(courseId) { + ProtoDiv.reset("PROTO_lecture"); + hideAllPages(); + $.get("/course/"+courseId, {}, function(response) { + +response = { + course: { + name: "FooCourse", + lectures: [ + { _id: 1, name: "lecture 1" }, + { _id: 2, name: "lecture 2" }, + ] + } +} + lectures = [] + if(typeof response == 'object') { + var course = response.course + $("#course_name").html(course.name); + lectures = course.lectures + } + ProtoDiv.replicate("PROTO_lecture", lectures); + showPage("lectures") + }); } diff --git a/public/javascripts/protodiv.js b/public/javascripts/protodiv.js index fa741d6..e74f143 100644 --- a/public/javascripts/protodiv.js +++ b/public/javascripts/protodiv.js @@ -46,7 +46,9 @@ ProtoDiv.map = function(node, list, cb) { } } -ProtoDiv.substitute = function(s, obj) { +ProtoDiv.substitute = function(s, obj, i) { + if(i !== undefined) + s = s.replace(/__i__/g, i); for(var key in obj) { re = new RegExp("__"+key+"__", "g") s = s.replace(re, obj[key]) @@ -54,14 +56,14 @@ ProtoDiv.substitute = function(s, obj) { return s } -ProtoDiv.inject = function(id, obj) { +ProtoDiv.inject = function(id, obj, n) { var proto = ProtoDiv.elem(id) - proto.innerHTML = ProtoDiv.substitute(proto.innerHTML, obj) + proto.innerHTML = ProtoDiv.substitute(proto.innerHTML, obj, n) for(var i = 0; i < proto.attributes.length; i++) { var a = proto.attributes[i] - a.textContent = ProtoDiv.substitute(a.textContent, obj) + a.textContent = ProtoDiv.substitute(a.textContent, obj, n) } for(var key in obj) { @@ -109,7 +111,7 @@ ProtoDiv.replicate = function(id, arr, keep) { var e = proto.cloneNode(true) delete e.id mom.insertBefore(e, sib) - ProtoDiv.inject(e, obj) + ProtoDiv.inject(e, obj, i) } if(!keep) diff --git a/public/stylesheets/fc2.css b/public/stylesheets/fc2.css index 77cc7f0..9c4a236 100644 --- a/public/stylesheets/fc2.css +++ b/public/stylesheets/fc2.css @@ -616,9 +616,6 @@ div.school { } -.school h2 { -} - /* .content .container1 h1 { background: #778899; @@ -654,11 +651,23 @@ div.menubar { text-align: right; } -div.school h2 { +div.school div.name { + font-weight: bold; font-size: 120%; margin: 0 0; } +div.school div.desc { + font-size: 90%; + color: #888; + font-style: italic; + margin: 0 0; +} + +div.course { + margin: 1em 0; +} + #messages { margin: 0em 5%; } -- 2.25.1