From c9affdf51c9c78c221c5b888158403605cd2a81a Mon Sep 17 00:00:00 2001 From: Jason Skomorowski Date: Mon, 28 Jul 2014 17:38:37 -0400 Subject: [PATCH] Initial commit --- .gitignore | 3 ++ mkwsxb/__init__.py | 1 + mkwsxb/mkwsxb.py | 58 ++++++++++++++++++++++++++++++++++ mkwsxb/static/css/mkws-widget-ru.css | 37 ++++++++++++++++++++++ mkwsxb/static/html/mkwsxb.html | 3 ++ mkwsxb/static/html/settings.html | 21 ++++++++++++ mkwsxb/static/js/src/mkwsxb.js | 6 ++++ mkwsxb/static/js/src/settings.js | 16 ++++++++++ requirements.txt | 1 + setup.py | 33 +++++++++++++++++++ 10 files changed, 179 insertions(+) create mode 100644 .gitignore create mode 100644 mkwsxb/__init__.py create mode 100644 mkwsxb/mkwsxb.py create mode 100644 mkwsxb/static/css/mkws-widget-ru.css create mode 100644 mkwsxb/static/html/mkwsxb.html create mode 100644 mkwsxb/static/html/settings.html create mode 100644 mkwsxb/static/js/src/mkwsxb.js create mode 100644 mkwsxb/static/js/src/settings.js create mode 100644 requirements.txt create mode 100644 setup.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..665e2d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.pyc +*.swp +mkwsxb_xblock.egg-info/ diff --git a/mkwsxb/__init__.py b/mkwsxb/__init__.py new file mode 100644 index 0000000..ac8aa9b --- /dev/null +++ b/mkwsxb/__init__.py @@ -0,0 +1 @@ +from .mkwsxb import MKWSXB \ No newline at end of file diff --git a/mkwsxb/mkwsxb.py b/mkwsxb/mkwsxb.py new file mode 100644 index 0000000..42240e0 --- /dev/null +++ b/mkwsxb/mkwsxb.py @@ -0,0 +1,58 @@ +"""Embed widgets from MKWS, the MasterKey Widget Set""" + +import pkg_resources + +from xblock.core import XBlock +from xblock.fields import Integer, Scope, String, Any, Boolean, Dict +from xblock.fragment import Fragment + +class MKWSXB(XBlock): + """Embed widgets from MKWS, the MasterKey Widget Set""" + + # Fields + query = String( + help="Search query", + default="water", + scope=Scope.content + ) + + def resource_string(self, path): + """Helper for accessing resources.""" + data = pkg_resources.resource_string(__name__, path) + return data.decode("utf8") + + 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/mkwsxb.html") + frag = Fragment(html.format(query=self.query)) + frag.add_javascript_url("//mkws.indexdata.com/mkws-complete.js") + frag.add_javascript_url("//example.indexdata.com/mkws-widget-ru.js") + frag.add_css(self.resource_string("static/css/mkws-widget-ru.css")) + frag.add_javascript(self.resource_string("static/js/src/mkwsxb.js")) + frag.initialize_js('MKWSXB') + return frag; + + 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.add_javascript(self.resource_string("static/js/settings.js")) + frag.initialize_js('MKWSXBSettings') + return frag + + @XBlock.json_handler + def update_settings(self, data, suffix=''): + """Studio configuration callback.""" + self.query = data['query'] + return {"result": "success"} + + @staticmethod + def workbench_scenarios(): + """A canned scenario for display in the workbench.""" + return [ + ("MKWSXB", + """ + + + """), + ] diff --git a/mkwsxb/static/css/mkws-widget-ru.css b/mkwsxb/static/css/mkws-widget-ru.css new file mode 100644 index 0000000..74f6f48 --- /dev/null +++ b/mkwsxb/static/css/mkws-widget-ru.css @@ -0,0 +1,37 @@ +.mkwsReferenceUniverse { + font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; + background: #FCFBFA; + padding: 0.5em 1em 0.25em; + box-shadow: 0 0 2px 0 #7F8F93; + border-radius: 0 0 1.5em; + -moz-border-radius: 0 0 1.5em; + -webkit-border-radius: 0 0 1.5em; + line-height: 1.4; + color: #86979B; + background: radial-gradient(ellipse at center, #ffffff 0%,#f8f8f8 100%); +} + +.mkwsReferenceUniverse h2 { + font-size: 100%; + color: #4A5456; + padding-bottom: .5em; +} + +.mkwsReferenceUniverse ul { + margin: 0; + padding: 0; +} + +.mkwsReferenceUniverse li { + margin: .95em .25em; + padding-top: .75em; + border-top: 1px dotted #BEC8CC; + font-size: 90%; + list-style: none; +} + +.mkwsReferenceUniverse a { + text-decoration: none; + font-weight:bold; + color: #2B77AF; +} diff --git a/mkwsxb/static/html/mkwsxb.html b/mkwsxb/static/html/mkwsxb.html new file mode 100644 index 0000000..e5627d9 --- /dev/null +++ b/mkwsxb/static/html/mkwsxb.html @@ -0,0 +1,3 @@ +
+
Searching Reference Universe...
+
diff --git a/mkwsxb/static/html/settings.html b/mkwsxb/static/html/settings.html new file mode 100644 index 0000000..2bf5f56 --- /dev/null +++ b/mkwsxb/static/html/settings.html @@ -0,0 +1,21 @@ +
+ +
+ +
+
diff --git a/mkwsxb/static/js/src/mkwsxb.js b/mkwsxb/static/js/src/mkwsxb.js new file mode 100644 index 0000000..88b9042 --- /dev/null +++ b/mkwsxb/static/js/src/mkwsxb.js @@ -0,0 +1,6 @@ +/* Javascript for MKWSXB. */ +function MKWSXB(runtime, element) { + $(function ($) { + mkws.init(); + }); +} diff --git a/mkwsxb/static/js/src/settings.js b/mkwsxb/static/js/src/settings.js new file mode 100644 index 0000000..07d5f83 --- /dev/null +++ b/mkwsxb/static/js/src/settings.js @@ -0,0 +1,16 @@ +function MKWSXBSettings(runtime, element) { + $(element).find('.save-button').bind('click', function() { + var handlerUrl = runtime.handlerUrl(element, 'update_settings'); + var data = { + query: $(element).find('input[name=query]').val() + }; + console.log($(element).find('input[query]')); + $.post(handlerUrl, JSON.stringify(data)).done(function(response) { + window.location.reload(false); + }); + }); + + $(element).find('.cancel-button').bind('click', function() { + runtime.notify('cancel', {}); + }); +}; diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d6e1198 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +-e . diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..a564fbf --- /dev/null +++ b/setup.py @@ -0,0 +1,33 @@ +"""Setup for mkwsxb XBlock.""" + +import os +from setuptools import setup + + +def package_data(pkg, root): + """Generic function to find package_data for `pkg` under `root`.""" + data = [] + for dirname, _, files in os.walk(os.path.join(pkg, root)): + for fname in files: + data.append(os.path.relpath(os.path.join(dirname, fname), pkg)) + + return {pkg: data} + + +setup( + name='mkwsxb-xblock', + version='0.1', + description='XBlock to embed MKWS widgets.', + packages=[ + 'mkwsxb', + ], + install_requires=[ + 'XBlock', + ], + entry_points={ + 'xblock.v1': [ + 'mkwsxb = mkwsxb:MKWSXB', + ] + }, + package_data=package_data("mkwsxb", "static"), +) -- 1.7.10.4