From faee7491fc3a4fca47575943ee74676f767c12e6 Mon Sep 17 00:00:00 2001 From: nunpa Date: Tue, 14 Mar 2023 19:42:48 +0100 Subject: [PATCH] object to iframe move --- pdf/__init__.py | 1 + pdf/pdf.py | 77 +++++++++++++++++++++++++++++++++++ pdf/static/css/pdf.css | 9 ++++ pdf/static/html/pdf.html | 7 ++++ pdf/static/html/pdf_edit.html | 31 ++++++++++++++ pdf/static/js/src/pdf_edit.js | 36 ++++++++++++++++ setup.py | 33 +++++++++++++++ 7 files changed, 194 insertions(+) create mode 100644 pdf/__init__.py create mode 100644 pdf/pdf.py create mode 100644 pdf/static/css/pdf.css create mode 100644 pdf/static/html/pdf.html create mode 100644 pdf/static/html/pdf_edit.html create mode 100644 pdf/static/js/src/pdf_edit.js create mode 100644 setup.py diff --git a/pdf/__init__.py b/pdf/__init__.py new file mode 100644 index 0000000..a79d8a3 --- /dev/null +++ b/pdf/__init__.py @@ -0,0 +1 @@ +from .pdf import pdfXBlock \ No newline at end of file diff --git a/pdf/pdf.py b/pdf/pdf.py new file mode 100644 index 0000000..bf120cc --- /dev/null +++ b/pdf/pdf.py @@ -0,0 +1,77 @@ +"""TO-DO: Write a description of what this XBlock is.""" + +import pkg_resources + +from xblock.core import XBlock +from xblock.fields import Scope, Integer, String +from xblock.fragment import Fragment + +class pdfXBlock(XBlock): + """ + TO-DO: document what your XBlock does. + """ + # Fields are defined on the class. You can access them in your code as + # self.. + # TO-DO: change the default href so it is included as a resource in the xblock, not an url + href = String(display_name="href", + default="http://www.upv.es/plano/directorio-es.pdf", + scope=Scope.content, + help="PDF file that will be shown in the XBlock") + + display_name = String(display_name="Display Name", + default="PDF File", + scope=Scope.settings, + help="Name of the component in the edxplatform") + + def resource_string(self, path): + """Handy helper for getting resources from our kit.""" + data = pkg_resources.resource_string(__name__, path) + return data.decode("utf8") + + + def student_view(self, context=None): + """ + The primary view of the pdfXBlock, shown to students + when viewing courses. + """ + html = self.resource_string("static/html/pdf.html") + frag = Fragment(html.format(self=self)) + frag.add_css(self.resource_string("static/css/pdf.css")) + return frag + + + def studio_view(self, context=None): + """ + The primary view of the paellaXBlock, shown to students + when viewing courses. + """ + html = self.resource_string("static/html/pdf_edit.html") + frag = Fragment(html.format(self=self)) + frag.add_javascript(self.resource_string("static/js/src/pdf_edit.js")) + frag.initialize_js('pdfXBlock') + return frag + + @XBlock.json_handler + def save_pdf(self, data, suffix=''): + """ + An example handler, which increments the data. + """ + self.href = data['href'] + self.display_name = data['display_name'] + + return { + 'result': 'success', + } + + # TO-DO: change this to create the scenarios you'd like to see in the + # workbench while developing your XBlock. + @staticmethod + def workbench_scenarios(): + """A canned scenario for display in the workbench.""" + return [ + ("pdfXBlock", + """ + + + """), + ] diff --git a/pdf/static/css/pdf.css b/pdf/static/css/pdf.css new file mode 100644 index 0000000..2488741 --- /dev/null +++ b/pdf/static/css/pdf.css @@ -0,0 +1,9 @@ +/* CSS for pdfXBlock */ + +.pdf_block .count { + font-weight: bold; +} + +.pdf_block p { + cursor: pointer; +} \ No newline at end of file diff --git a/pdf/static/html/pdf.html b/pdf/static/html/pdf.html new file mode 100644 index 0000000..09a661c --- /dev/null +++ b/pdf/static/html/pdf.html @@ -0,0 +1,7 @@ +
+ +
\ No newline at end of file diff --git a/pdf/static/html/pdf_edit.html b/pdf/static/html/pdf_edit.html new file mode 100644 index 0000000..11722c8 --- /dev/null +++ b/pdf/static/html/pdf_edit.html @@ -0,0 +1,31 @@ +
+
    +
  • +
    + + + The title of the PDF file that is displayed to the user +
    +
  • +
  • +
    + + + The url of the pdf file +
    +
  • +
+
+ + +
+
+ + diff --git a/pdf/static/js/src/pdf_edit.js b/pdf/static/js/src/pdf_edit.js new file mode 100644 index 0000000..11a2b4d --- /dev/null +++ b/pdf/static/js/src/pdf_edit.js @@ -0,0 +1,36 @@ +/* Javascript for pdfXBlock. */ +function pdfXBlock(runtime, element) { + + function paellaSaved(result) { + $('.server', element).text(); + $('.video_id', element).text(result.video_id); + $('.display_name', element).text(result.display_name); + } + + $(element).find('.cancel-button').bind('click', function() { + runtime.notify('cancel', {}); + }); + + $(element).find('.save-button').bind('click', function() { + var data = { + 'display_name': $(edit_display_name).context.value, + 'href':$(edit_href).context.value + }; + + $('.xblock-editor-error-message', element).html(); + $('.xblock-editor-error-message', element).css('display', 'none'); + var handlerUrl = runtime.handlerUrl(element, 'save_pdf'); + $.post(handlerUrl, JSON.stringify(data)).done(function(response) { + if (response.result === 'success') { + window.location.reload(false); + } else { + $('.xblock-editor-error-message', element).html('Error: '+response.message); + $('.xblock-editor-error-message', element).css('display', 'block'); + } + }); + }); + + $(function ($) { + /* Here's where you'd do things on page load. */ + }); +} \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..10ad52f --- /dev/null +++ b/setup.py @@ -0,0 +1,33 @@ +"""Setup for pdf 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='pdf-xblock', + version='0.1', + description='pdf XBlock', # TODO: write a better description. + packages=[ + 'pdf', + ], + install_requires=[ + 'XBlock', + ], + entry_points={ + 'xblock.v1': [ + 'pdf = pdf:pdfXBlock', + ] + }, + package_data=package_data("pdf", "static"), +) \ No newline at end of file