Skip to content
Browse files

Generalize

  • Loading branch information...
1 parent 32af443 commit 698c19da12cf72c04afad39c8f39d8f220e0e365 @MasseR committed Apr 7, 2013
Showing with 63 additions and 47 deletions.
  1. +8 −4 code/Main.hs
  2. +55 −43 code/public/js/doThings.js
View
12 code/Main.hs
@@ -130,12 +130,12 @@ parseThesis path = do
return $ zipWith (\name course -> Thesis name (S.fromList $ map snd course)) names courses
studentModal :: Html
-studentModal = H.div ! A.id "modal_student" ! A.class_ "modal hide fade" $ do
+studentModal = H.div ! A.id "modal" ! A.class_ "modal hide fade" $ do
H.div ! A.class_ "modal-header" $ do
H.button ! A.type_ "button" ! A.class_ "close" ! data_dismiss "modal" ! aria_hidden "true" $
"x"
H.h3 ! A.id "student_header" $ mempty
- H.div ! A.class_ "modal-body" ! A.id "studentBody" $ do
+ H.div ! A.class_ "modal-body" ! A.id "modalBody" $ do
mempty
H.div ! A.class_ "modal-footer" $ do
H.a ! A.href "#" ! A.class_ "btn close" $ "Close"
@@ -277,8 +277,12 @@ mainView students = H.docTypeHtml $ do
uploadForm "thesisFile" "Update thesis file" "thesis/upload"
uploadForm "creditsFile" "Update credits file" "credits/upload"
H.div ! A.class_ "span9" $ do
- H.div ! A.class_ "hero-unit" $ do
- H.table ! A.id "databox" $ mempty
+ H.div ! A.id "userData" ! A.class_ "hero-unit" $ do
+ H.table ! A.class_ "databox" $ mempty
+ H.div ! A.id "degreeData" ! A.style "display: none" ! A.class_ "hero-unit" $ do
+ H.table ! A.class_ "databox" $ mempty
+ H.div ! A.id "creditData" ! A.style "display: none" ! A.class_ "hero-unit" $ do
+ H.table ! A.class_ "databox" $ mempty
where
data_toggle = attribute "data-toggle" " data-toggle=\""
data_target = attribute "data-target" " data-target=\""
View
98 code/public/js/doThings.js
@@ -4,53 +4,65 @@ $(document).ready(function() {
return $(ev.currentTarget).attr('data-target');
}).toProperty('students').skipDuplicates();
- // Initialize (students) datatables with constant data
- var modalTemplate = $("#studentModalTemplate").text();
- var dstudents = $("#databox").dataTable( {
- "bJQueryUI": true,
- "aaData" : studentData,
- "aoColumns": [
+ var initPage = function(settings) {
+ var modalTemplate = settings.template
+ var dtable = settings.dtElem.dataTable( {
+ "bJQueryUI": true,
+ "aoColumns": settings.dtColumns
+ });
+
+ var touch = function() {
+ $.get(settings.dataUri, function(data) {
+ dtable.fnClearTable();
+ dtable.fnAddData(data);
+ });
+ };
+
+ var dataClickStream = settings.dtElem.
+ asEventStream("click", "tr").
+ filter(function(ev) {
+ var trg = $(ev.currentTarget);
+ if(trg.attr("class") == "odd" || trg.attr("class") == "even")
+ return true;
+ return false;
+ }).map(function(ev) {
+ return dtable.fnGetData(ev.currentTarget);
+ });
+ var templateProperty = dataClickStream.flatMap(function(data) {
+ return Bacon.fromPromise(settings.moreInfo(data));
+ }).map(function(json) {
+ return Mustache.render(modalTemplate, json);
+ }).toProperty("");
+ var modalClose = $("#modal a.close").asEventStream("click").map(false);
+ var modalOpen = dataClickStream.map(true);
+
+
+ modalClose.merge(modalOpen).skipDuplicates().onValue(function(open) {
+ if(open)
+ $("#modal").modal('show');
+ else
+ $("#modal").modal('hide');
+ });
+
+ templateProperty.assign($('#modalBody'), 'html');
+ touch();
+
+ return touch;
+ }
+
+ window.touchStudents = initPage({
+ template: $("#studentModalTemplate").text(),
+ dtElem: $("#userData .databox"),
+ dtColumns: [
{ "sTitle": "Student number" },
{ "sTitle": "Name" },
{ "sTitle": "Degree" },
{ "sTitle": "Major" },
{ "sTitle": "Student points"},
{ "sTitle": "Enrollment date"}
- ]
- });
- window.touchStudents = function() {
- $.get("/student/data", function(data) {
- dstudents.fnClearTable();
- dstudents.fnAddData(data);
- });
- };
-
- var dataClicks = $("#databox").
- asEventStream("click", "tr").
- filter(function(ev) {
- var trg = $(ev.currentTarget);
- if(trg.attr("class") == "odd" || trg.attr("class") == "even")
- return true;
- return false;
- }).map(function(ev) {
- return dstudents.fnGetData(ev.currentTarget);
- });
- var studentQueries = dataClicks.flatMap(function(data) {
- return Bacon.fromPromise($.get("/student", {studentId: data[0]}));
- }).map(function(json) {
- return Mustache.render(modalTemplate, json);
- }).toProperty("");
- var studentModalClose = $("#modal_student a.close").asEventStream("click").map(false);
- var studentModalOpen = dataClicks.map(true);
-
-
- studentModalClose.merge(studentModalOpen).skipDuplicates().onValue(function(open) {
- console.log(open);
- if(open)
- $("#modal_student").modal('show');
- else
- $("#modal_student").modal('hide');
- });
-
- studentQueries.assign($('#studentBody'), 'html');
+ ],
+ moreInfo: function(data) { return $.get("/student", {studentId: data[0]}); },
+ dataUri: "/student/data"
+ });
+
});

0 comments on commit 698c19d

Please sign in to comment.
Something went wrong with that request. Please try again.