XBlock - Accessing course content and AJAX error

102 views
Skip to first unread message

Froont

unread,
Sep 6, 2017, 8:18:55 AM9/6/17
to General Open edX discussion
Hello All,
   I'm building a custom XBlock and I've run into a roadBlock (of sorts).  I have two issues that I've been troubleshooting and was wondering if someone else has overcome these.  In searching the XBlock depositories online, I can't find any other XBlocks that have this functionality.

Here's what I'm trying to do:  My XBlock has configuration parameters that apply to an entire course, but would be different for other courses on the same Open edX server.  In order to make the XBlock easier for course developers to work with, I want to create a config file for the XBlock that is unique to each course.  My preferred method to do this is via Studio (I don't want course developers messing with the shell or trying to edit python variables).  I upload my config file to the course content files & uploads so it becomes a static resource of the course.  Yes, I know this makes it accessible to users, but the config file doesn't contain anything sensitive.  Here are the problems I'm encountering:

1.  I've been unable to find a javascript function that provides the URL handler of static course content.  This URL handler changes the /static/config.txt into the /asset-v1:Org+Course_Run+type@asset+bl...@config.txt format.  Does anyone know of a javascript runtime URL handler that does this?  Is there another way to get the resource handle of static course content from within the XBlock javascript files?

2.  For testing, I hard coded the URL handler into a jQuery.get statement in the XBlock static/js/edit.js file.  The jQuery.get is supposed to retrieve the contents of my config file for parsing by further javascript.  I'm getting the console error "Studio AJAX Error" which traces back to a "base.js" that I can't locate - there are many base.js files in the cms construct.  Are custom AJAX gets not allowed in XBlocks?  Is there a way around this?  I can see that the AJAX request comes back with the payload from my config file with an HTTP 200, but it also contains the error message.

FYI - my development XBlock is running on Ficus 3.2.

Any insight anyone is willing to provide on either of these issues would be much appreciated.  Thank you in advance for your help!

Froont

Froont

unread,
Sep 6, 2017, 5:51:25 PM9/6/17
to General Open edX discussion
After a few more hours of work, I was able to get both 1 and 2 described above working, however in a marginal fashion.  I'll describe what I've done to overcome these challenges, but I'm still looking for input as I believe both of these problems have more elegant solutions than what I came up with.

1.  I scraped the asset handler from the studio page that launches the XBlock edit dialog.  I was able to extract the Org, Course, and Run parameters, and then construct a string out of them that gave me the asset resource handler.  This method works, but is pretty sloppy.  It also relies on the developers not changing the template of the page in cms, because I'm scraping a particular html tag by its id.  Any thoughts on a better way to do this?

2.  As mentioned above, I saw that the AJAX payload that returned with an error did include the expected strings from my configuration file.  I used the .error method of the get call to read the returned jqXHR and parse my expected result.  

    request.success(function(data) {

       
// This doesn't work - we have to get the AJAX reply in a failure message (unexpected format by cms)
   
});
    request
.error(function(jqXHR, textStatus, errorThrown) {
       
var data = jqXHR.responseText;

Counting an error as a success isn't the right way to go about this, but as stated above, it appears that raw AJAX isn't allowed for some reason in an XBlock.  The other annoying side effect of doing business this way is that I get the annoying "Studio's having trouble saving your work" banner that pops-up in studio when I'm using my XBlock edit dialog.  How can I do this better?

Thanks!

Froont
Reply all
Reply to author
Forward
0 new messages