1 """Embed bibliographic widget from MKWS, the MasterKey Widget Set"""
6 from xblock.core import XBlock
7 from xblock.fields import Integer, Scope, String, Any, Boolean, Dict
8 from xblock.fragment import Fragment
10 class MKWSBiblio(XBlock):
11 """Embed bibliographic widget from MKWS, the MasterKey Widget Set"""
20 help="Record to display",
21 default="content: title modern water resources engineering",
24 display_name = String(
25 default="MKWS bibliographic details",
29 def resource_string(self, path):
30 """Helper for accessing resources."""
31 data = pkg_resources.resource_string(__name__, path)
32 return data.decode("utf8")
34 def student_view(self, context=None):
35 """The primary view of the MKWS XBlock, shown to students when viewing courses."""
36 html = self.resource_string("static/html/student.html")
37 frag = Fragment(html.format(query=self.query, recid=self.recid, team=random.randint(0, 100000)))
38 # student.js uses require.js as it cannot guarantee mkws-complete.js has loaded
39 # in studio without it. We'll need to add it if we're in the LMS:
40 #frag.add_javascript_url("/static/js/vendor/require.js");
41 frag.add_javascript_url("//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.14/require.min.js");
42 # frag.add_resource_url("//mkws.indexdata.com/mkws-complete", "text/javascript", "head");
43 # frag.add_resource('<script src="//mkws.indexdata.com/mkws-complete.js"></script>', "text/html", "head");
44 frag.add_css(self.resource_string("static/css/mkwsbiblio.css"))
45 frag.add_javascript(self.resource_string("static/js/src/student.js"))
46 frag.initialize_js('MKWSBiblio')
49 def author_view(self, context=None):
50 """The primary view of the MKWS XBlock, shown when authoring courses."""
51 # This should closely mirror the student_view. Here all we do is not include
52 # require.js as it's already in Studio and the lms path won't work.
53 html = self.resource_string("static/html/student.html")
54 frag = Fragment(html.format(query=self.query, recid=self.recid, team=random.randint(0, 100000)))
55 frag.add_css(self.resource_string("static/css/mkwsbiblio.css"))
56 frag.add_javascript(self.resource_string("static/js/src/student.js"))
57 frag.initialize_js('MKWSBiblio')
60 def studio_view(self, context=None):
61 """Studio configuration view."""
62 html = self.resource_string("static/html/settings.html")
63 frag = Fragment(html.format(query=self.query, recid=self.recid))
64 frag.add_javascript(self.resource_string("static/js/settings.js"))
65 frag.initialize_js('MKWSBiblioSettings')
69 def update_settings(self, data, suffix=''):
70 """Studio configuration callback."""
71 self.query = data['query']
72 self.recid = data['recid']
73 return {"result": "success"}
76 def workbench_scenarios():
77 """A canned scenario for display in the workbench."""