diff --git a/openedx_cmi5_xblock/openedx_cmi5_xblock.py b/openedx_cmi5_xblock/openedx_cmi5_xblock.py index 58aa1dc..16305ab 100644 --- a/openedx_cmi5_xblock/openedx_cmi5_xblock.py +++ b/openedx_cmi5_xblock/openedx_cmi5_xblock.py @@ -128,13 +128,6 @@ class CMI5XBlock(XBlock, CompletableXBlockMixin): scope=Scope.content, ) - launch_methods = List( - display_name=_('Launch Methods'), - help=_('List of launch methods of AU URLs'), - default=[], - scope=Scope.content, - ) - current_au_index = Integer( display_name=_('Current AU Index'), help=_('Index of the currently displayed AU URL'), @@ -200,7 +193,6 @@ def student_view(self, context=None): 'popup_width': self.width or 800, 'popup_height': self.height or 800, 'au_urls': self.au_urls, - 'launch_methods': self.launch_methods, 'current_au_index': self.current_au_index, 'total_au_count': self.total_au_count, }, @@ -536,12 +528,19 @@ def update_package_fields(self): au_elements = root.findall('.//{prefix}au'.format(prefix=prefix)) if au_elements: - au_urls = [au.find('./{prefix}url'.format(prefix=prefix)).text for au in au_elements] - launch_methods = [au.get('launchMethod', 'AnyWindow') for au in au_elements] + au_data_list = [] + for au in au_elements: + au_url = au.find('./{prefix}url'.format(prefix=prefix)).text + launch_method = au.get('launchMethod', 'AnyWindow') + + au_data = { + 'url': self.launch_au_url(au_url), + 'launch_method': launch_method + } + au_data_list.append(au_data) - self.index_page_path = au_urls[0] - self.au_urls = [self.launch_au_url(url) for url in au_urls] - self.launch_methods = launch_methods + self.index_page_path = au_data_list[0]['url'] + self.au_urls = au_data_list 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 81e2a2e..2d2be58 100644 --- a/openedx_cmi5_xblock/static/html/openedx_cmi5_xblock.html +++ b/openedx_cmi5_xblock/static/html/openedx_cmi5_xblock.html @@ -3,15 +3,17 @@
{{ 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 4d9b430..11dec21 100644 --- a/openedx_cmi5_xblock/static/js/src/openedx_cmi5_xblock.js +++ b/openedx_cmi5_xblock/static/js/src/openedx_cmi5_xblock.js @@ -11,7 +11,7 @@ function CMI5XBlock(runtime, element, settings) { /* Here's where you'd do things on page load. */ var nextButton = $('#nextButton'); var prevButton = $('#prevButton'); - console.log("the launch_methods are : ", settings.launch_methods) + console.log("the au_urls are : ", settings.au_urls) prevButton.prop('disabled', true) @@ -19,40 +19,27 @@ function CMI5XBlock(runtime, element, settings) { nextButton.prop('disabled', true) } - nextButton.click(function () { - - 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 () { - - 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]); - }); $('ol a').click(function (event) { - event.preventDefault(); // Prevent the default behavior of the link - var href = $(this).attr('href'); // Get the href attribute of the clicked link - updateIframeSrc(href); // Update the iframe src with the href value + event.preventDefault(); + var href = $(this).attr('href'); + updateIframeSrc(href); }); - function updateIframeSrc(src) { - $('.cmi5-embedded').attr('src', src); + function updateIframeSrc(href) { + var index = settings.au_urls.findIndex(function (au) { + return au.url === href; + }); + + if (index !== -1) { + if (settings.au_urls[index].launch_method === 'OwnWindow') { + // Open in a new browser window + window.open(href, '_blank'); + } else { + // Display in the iframe + $('.cmi5-embedded').attr('src', href); + } + } } }); }