Detail record selection for mwksbiblio
authorJason Skomorowski <jason@indexdata.com>
Thu, 28 Aug 2014 01:55:21 +0000 (21:55 -0400)
committerJason Skomorowski <jason@indexdata.com>
Thu, 28 Aug 2014 01:55:21 +0000 (21:55 -0400)
mkwsbiblio/mkwsbiblio/mkwsbiblio.py
mkwsbiblio/mkwsbiblio/static/css/mkwsbiblio.css [new file with mode: 0644]
mkwsbiblio/mkwsbiblio/static/html/settings.html
mkwsbiblio/mkwsbiblio/static/html/student.html
mkwsbiblio/mkwsbiblio/static/js/settings.js
mkwsbiblio/mkwsbiblio/static/js/src/EdxChooser.handlebars
mkwsbiblio/mkwsbiblio/static/js/src/EdxChosen.handlebars [new file with mode: 0644]
mkwsbiblio/mkwsbiblio/static/js/src/settings.js
mkwsbiblio/mkwsbiblio/static/js/src/student.js

index 83bc12a..3faa320 100644 (file)
@@ -16,6 +16,11 @@ class MKWSBiblio(XBlock):
       default="water",
       scope=Scope.content
     )
+    recid = String(
+      help="Record to display",
+      default="content: title modern water resources engineering",
+      scope=Scope.content
+    )
     display_name = String(
       default="MKWS bibliographic details",
       scope=Scope.settings
@@ -29,12 +34,14 @@ class MKWSBiblio(XBlock):
     def student_view(self, context=None):
         """The primary view of the MKWS XBlock, shown to students when viewing courses."""
         html = self.resource_string("static/html/student.html")
-        frag = Fragment(html.format(query=self.query, team=random.randint(0, 100000)))
+        frag = Fragment(html.format(query=self.query, recid=self.recid, team=random.randint(0, 100000)))
         # student.js uses require.js as it cannot guarantee mkws-complete.js has loaded 
         # in studio without it. We'll need to add it if we're in the LMS:
-        frag.add_javascript_url("/static/js/vendor/require.js");
+        #frag.add_javascript_url("/static/js/vendor/require.js");
+        frag.add_javascript_url("//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.14/require.min.js");
         # frag.add_resource_url("//mkws.indexdata.com/mkws-complete", "text/javascript", "head");
         # frag.add_resource('<script src="//mkws.indexdata.com/mkws-complete.js"></script>', "text/html", "head");
+        frag.add_css(self.resource_string("static/css/mkwsbiblio.css"))
         frag.add_javascript(self.resource_string("static/js/src/student.js"))
         frag.initialize_js('MKWSBiblio')
         return frag;
@@ -44,7 +51,8 @@ class MKWSBiblio(XBlock):
         # This should closely mirror the student_view. Here all we do is not include
         # require.js as it's already in Studio and the lms path won't work.
         html = self.resource_string("static/html/student.html")
-        frag = Fragment(html.format(query=self.query, team=random.randint(0, 100000)))
+        frag = Fragment(html.format(query=self.query, recid=self.recid, team=random.randint(0, 100000)))
+        frag.add_css(self.resource_string("static/css/mkwsbiblio.css"))
         frag.add_javascript(self.resource_string("static/js/src/student.js"))
         frag.initialize_js('MKWSBiblio')
         return frag;
@@ -52,7 +60,7 @@ class MKWSBiblio(XBlock):
     def studio_view(self, context=None):
         """Studio configuration view."""
         html = self.resource_string("static/html/settings.html")
-        frag = Fragment(html.format(query=self.query))
+        frag = Fragment(html.format(query=self.query, recid=self.recid))
         frag.add_javascript(self.resource_string("static/js/settings.js"))
         frag.initialize_js('MKWSBiblioSettings')
         return frag
@@ -61,6 +69,7 @@ class MKWSBiblio(XBlock):
     def update_settings(self, data, suffix=''):
         """Studio configuration callback."""
         self.query = data['query']
+        self.recid = data['recid']
         return {"result": "success"}
 
     @staticmethod
diff --git a/mkwsbiblio/mkwsbiblio/static/css/mkwsbiblio.css b/mkwsbiblio/mkwsbiblio/static/css/mkwsbiblio.css
new file mode 100644 (file)
index 0000000..f47acb2
--- /dev/null
@@ -0,0 +1,8 @@
+.mkwsDetails th {
+    text-align: right;
+    vertical-align: top;
+    padding-right: 0.6em;
+}
+.mkwsDetails th:after {
+    content: ":";
+}
index 6e0ab63..e6984a4 100644 (file)
@@ -2,8 +2,7 @@
   <ul class="list-input settings-list">
     <li class="field comp-setting-entry is-set">
       <div class="wrapper-comp-setting" id="mkwsCurrentRecordContainer">
-        <h3>Current selection:</h3>
-        <div class="mkwsRecords mkwsTeam_UNIQUE" id="mkwsCurrentRecord" autosearch="{query}" perpage="1">Loading record...</div>
+        <div class="mkwsDetails mkwsTeam_ConfiguredRecord" id="mkwsCurrentRecord" autosearch="{query}" data-mkws-recid="{recid}" data-mkws-config='{{ "template": "EdxChosen" }}'>Loading record...</div>
       </div>
     </li>
     <li class="field comp-setting-entry is-set">
@@ -11,7 +10,7 @@
         <h3>Choose a record:</h3>
         <div class="mkwsSearch mkwsTeam_BlockConfig"></div>
         <!-- NB: double braces needed to escape edx templateing -->
-        <div class="mkwsRecords mkwsTeam_BlockConfig" data-mkws-config='{{ "template": "EdxChooser", "perpage": 5 }}'></div>
+        <div class="mkwsRecords mkwsTeam_BlockConfig" perpage="5" data-mkws-config='{{ "template": "EdxChooser" }}'></div>
       </div>
     </li>
   </ul>
index 6df95ba..b8f2e61 100644 (file)
@@ -1,3 +1,3 @@
 <div class="mkwsbiblio_block">
-  <div class="mkwsRecords mkwsTeam_{team}" autosearch="{query}" perpage="1">Loading record...</div>
+  <div class="mkwsDetails mkwsTeam_{team}" autosearch="{query}" data-mkws-recid="{recid}">Loading record...</div>
 </div>
index f238e6c..50de002 100644 (file)
@@ -16,11 +16,9 @@ function program1(depth0,data) {
   if (helper = helpers.detailLinkId) { stack1 = helper.call(depth0, {hash:{},data:data}); }
   else { helper = (depth0 && depth0.detailLinkId); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
   buffer += escapeExpression(stack1)
-    + "\" onclick=\"$('#mkwsCurrentRecord').attr('autosearch', '";
-  if (helper = helpers['md-title']) { stack1 = helper.call(depth0, {hash:{},data:data}); }
-  else { helper = (depth0 && depth0['md-title']); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
-  buffer += escapeExpression(stack1)
-    + "'); mkws.init('Click select', $('#mkwsCurrentRecordContainer'));\">\n      <b>";
+    + "\" onclick=\" $('#mkwsCurrentRecord').attr('data-mkws-recid', '"
+    + escapeExpression(((stack1 = ((stack1 = (depth0 && depth0.recid)),stack1 == null || stack1 === false ? stack1 : stack1[0])),typeof stack1 === functionType ? stack1.apply(depth0) : stack1))
+    + "'); $('#mkwsCurrentRecord').attr('autosearch', mkws.teams['BlockConfig'].query()); delete mkws.teams.ConfiguredRecord; mkws.init('Click select', '#mkwsCurrentRecordContainer'); return false;\">\n      <b>";
   if (helper = helpers['md-title']) { stack1 = helper.call(depth0, {hash:{},data:data}); }
   else { helper = (depth0 && depth0['md-title']); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
   buffer += escapeExpression(stack1)
@@ -76,19 +74,38 @@ function program6(depth0,data) {
   return buffer;
   });
 })();
+(function() {
+  var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
+templates['EdxChosen'] = template(function (Handlebars,depth0,helpers,partials,data) {
+  this.compilerInfo = [4,'>= 1.0.0'];
+helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
+  var buffer = "", stack1, helper, functionType="function", escapeExpression=this.escapeExpression;
+
+
+  buffer += "<span>Current selection: ";
+  if (helper = helpers['md-title']) { stack1 = helper.call(depth0, {hash:{},data:data}); }
+  else { helper = (depth0 && depth0['md-title']); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
+  buffer += escapeExpression(stack1)
+    + "</span>\n";
+  return buffer;
+  });
+})();
 function MKWSBiblioSettings(runtime, element) {
   mkws.init("XBlock settings pane", "#settings-tab");
   $(element).find('.save-button').bind('click', function() {
     var handlerUrl = runtime.handlerUrl(element, 'update_settings');
     var data = {
-      query: $(element).find('#mkwsCurrentRecord').attr('autosearch')
+      query: mkws.teams["BlockConfig"].query(),
+      recid: $(element).find('#mkwsCurrentRecord').attr('data-mkws-recid')
     };
     $.post(handlerUrl, JSON.stringify(data)).done(function(response) {
       window.location.reload(false);
+      return false;
     });
   });
 
   $(element).find('.cancel-button').bind('click', function() {
     runtime.notify('cancel', {});
+    return false;
   });
-};
+}
index e3f8656..60ede8d 100644 (file)
@@ -10,7 +10,7 @@ hits:
 }}
 {{#each hits}}
   <div class="{{containerClass}}">
-    <a href="#" id="{{detailLinkId}}" onclick="$('#mkwsCurrentRecord').attr('autosearch', '{{md-title}}'); mkws.init('Click select', $('#mkwsCurrentRecordContainer'));">
+    <a href="#" id="{{detailLinkId}}" onclick=" $('#mkwsCurrentRecord').attr('data-mkws-recid', '{{recid.[0]}}'); $('#mkwsCurrentRecord').attr('autosearch', mkws.teams['BlockConfig'].query()); delete mkws.teams.ConfiguredRecord; mkws.init('Click select', '#mkwsCurrentRecordContainer'); return false;">
       <b>{{md-title}}</b>
     </a>
     {{#if md-title-remainder}}
diff --git a/mkwsbiblio/mkwsbiblio/static/js/src/EdxChosen.handlebars b/mkwsbiblio/mkwsbiblio/static/js/src/EdxChosen.handlebars
new file mode 100644 (file)
index 0000000..3a972ef
--- /dev/null
@@ -0,0 +1 @@
+<span>Current selection: {{md-title}}</span>
index 3d8e2d7..7bfa8d8 100644 (file)
@@ -3,14 +3,17 @@ function MKWSBiblioSettings(runtime, element) {
   $(element).find('.save-button').bind('click', function() {
     var handlerUrl = runtime.handlerUrl(element, 'update_settings');
     var data = {
-      query: $(element).find('#mkwsCurrentRecord').attr('autosearch')
+      query: mkws.teams["BlockConfig"].query(),
+      recid: $(element).find('#mkwsCurrentRecord').attr('data-mkws-recid')
     };
     $.post(handlerUrl, JSON.stringify(data)).done(function(response) {
       window.location.reload(false);
+      return false;
     });
   });
 
   $(element).find('.cancel-button').bind('click', function() {
     runtime.notify('cancel', {});
+    return false;
   });
-};
+}
index 406407c..a2770b7 100644 (file)
@@ -1,7 +1,8 @@
 window.mkws_noready = true;
 require.config({
   paths: {
-    mkws: "//mkws.local/mkws-complete",
+    //mkws: "//mkws.local/mkws-complete",
+    mkws: "//mkws.indexdata.com/mkws-compl-tmpl",
   },
   shim: {
     mkws: {