diff --git a/openedx_cmi5_xblock/openedx_cmi5_xblock.py b/openedx_cmi5_xblock/openedx_cmi5_xblock.py index f32a01e..200e2f7 100644 --- a/openedx_cmi5_xblock/openedx_cmi5_xblock.py +++ b/openedx_cmi5_xblock/openedx_cmi5_xblock.py @@ -21,7 +21,7 @@ from webob import Response from xblock.completable import CompletableXBlockMixin from xblock.core import XBlock -from xblock.fields import Boolean, DateTime, Dict, Float, Integer, Scope, String +from xblock.fields import Boolean, DateTime, Dict, Float, Integer, Scope, String, List from xblock.fragment import Fragment from openedx_cmi5_xblock.utils.utility import ( @@ -121,6 +121,27 @@ class CMI5XBlock(XBlock, CompletableXBlockMixin): scope=Scope.settings, ) + au_urls = List( + display_name=_('AU URLs'), + help=_('List of AU URLs'), + default=[], + scope=Scope.content, + ) + + current_au_index = Integer( + display_name=_('Current AU Index'), + help=_('Index of the currently displayed AU URL'), + default=0, + scope=Scope.user_state, + ) + + total_au_count = Integer( + display_name=_('Total AU Count'), + help=_('Total number of AU URLs'), + default=0, + scope=Scope.content, + ) + has_author_view = True def author_view(self, context=None): @@ -171,9 +192,13 @@ def student_view(self, context=None): 'CMI5XBlock', json_args={ 'popup_width': self.width or 800, 'popup_height': self.height or 800, + 'au_urls': self.au_urls, + 'current_au_index': self.current_au_index, + 'total_au_count': self.total_au_count, }, ) return frag + @XBlock.handler def lrs_endpoint(self, request, _suffix): @@ -260,6 +285,22 @@ def studio_submit(self, request, _suffix): response['errors'].append(e.args[0]) return json_response(response) + def launch_au_url(self, url): + """Handles the multiple AUs and append launch params with url.""" + if not self.package_meta or not url: + return '' + + lms_cmi5_url = '' + if is_url(url): + lms_cmi5_url = url + else: + folder = self.extract_folder_path + lms_cmi5_url = requests.utils.unquote(self.storage.url(os.path.join(folder, url))) + + params_joining_symbol = '&' if is_params_exist(lms_cmi5_url) else '?' + lms_cmi5_url = lms_cmi5_url + params_joining_symbol + self.get_launch_url_params() + return lms_cmi5_url + # getters and setters def get_credentials(self): """ @@ -397,6 +438,7 @@ def index_page_url(self): lms_cmi5_url = lms_cmi5_url + params_joining_symbol return lms_cmi5_url + self.get_launch_url_params() + @property def extract_folder_path(self): """ @@ -486,9 +528,11 @@ def update_package_fields(self): prefix = '{' + namespace + '}' if namespace else '' self.set_course_detail(prefix, root) - au_url = root.find('.//{prefix}au/{prefix}url'.format(prefix=prefix)) - if au_url is not None: - self.index_page_path = au_url.text + au_urls = root.findall('.//{prefix}au/{prefix}url'.format(prefix=prefix)) + if au_urls is not None: + self.index_page_path = au_urls[0].text + self.au_urls = [self.launch_au_url(au_url.text) for au_url in au_urls] + self.total_au_count = len(self.au_urls) else: self.index_page_path = self.find_relative_file_path('index.html') diff --git a/openedx_cmi5_xblock/static/html/openedx_cmi5_xblock.html b/openedx_cmi5_xblock/static/html/openedx_cmi5_xblock.html index 1d0bfda..548680b 100644 --- a/openedx_cmi5_xblock/static/html/openedx_cmi5_xblock.html +++ b/openedx_cmi5_xblock/static/html/openedx_cmi5_xblock.html @@ -11,6 +11,8 @@
{{ message }}
diff --git a/openedx_cmi5_xblock/static/js/src/openedx_cmi5_xblock.js b/openedx_cmi5_xblock/static/js/src/openedx_cmi5_xblock.js index b3aa533..ee98851 100644 --- a/openedx_cmi5_xblock/static/js/src/openedx_cmi5_xblock.js +++ b/openedx_cmi5_xblock/static/js/src/openedx_cmi5_xblock.js @@ -1,5 +1,5 @@ /* Javascript for CMI5XBlock. */ -function CMI5XBlock(runtime, element) { +function CMI5XBlock(runtime, element, settings) { $(function ($) { @@ -10,5 +10,55 @@ function CMI5XBlock(runtime, element) { */ /* Here's where you'd do things on page load. */ + var nextButton = $('#nextButton'); + var prevButton = $('#prevButton'); + prevButton.prop('disabled', true) + if(settings.total_au_count === 1){ + nextButton.prop('disabled', true) + } + + nextButton.click(function () { + + console.log("the au_urls are : ", settings.au_urls) + console.log("total au count : ", settings.total_au_count) + console.log("current au index: ", settings.current_au_index) + + + + if(settings.current_au_index < settings.total_au_count-1){ + settings.current_au_index+=1 + prevButton.prop('disabled', false) + + if(settings.current_au_index === settings.total_au_count-1){ + nextButton.prop('disabled', true) + } + + } + + + $('.cmi5-embedded').attr('src', settings.au_urls[settings.current_au_index]); + + }); + + prevButton.click(function () { + + console.log("the au_urls are : ", settings.au_urls) + console.log("total au count : ", settings.total_au_count) + console.log("current au index: ", settings.current_au_index) + + if(settings.current_au_index > 0){ + settings.current_au_index-=1 + nextButton.prop('disabled', false) + + if(settings.current_au_index === 0){ + prevButton.prop('disabled', true); + } + } + + + $('.cmi5-embedded').attr('src', settings.au_urls[settings.current_au_index]); + + }); + }); }