Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding advanced components on Library #14

Open
wants to merge 2 commits into
base: hawthorn
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions pdf/static/js/pdf_edit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/* Javascript for pdfXBlock. */
function pdfXBlockInitEdit(runtime, element) {

// check if it is a library
var usageId = element[0].dataset['usageId'];
var isLibrary = usageId.slice(0, 3) === "lib";

$(element).find('.action-cancel').bind('click', function () {
runtime.notify('cancel', {});
$('.pdf_placeholder').hide();
Expand Down Expand Up @@ -45,7 +50,11 @@ function pdfXBlockInitEdit(runtime, element) {
var formData = new FormData();
formData.append('file', file);
var request = new XMLHttpRequest();
var course_key = element[0].dataset['usageId'].split('+', 3).join('+').replace('block', 'course');
var splitCount = isLibrary ? 2 : 3;
var keyword = isLibrary ? 'lib-block' : 'block';
var replacement = isLibrary ? 'library' : 'course';
var course_key = usageId.split('+', splitCount).join('+').replace(keyword, replacement);

var upload_url = '/assets/' + course_key + '/';
var csrftoken = $.cookie('csrftoken');
var alertField = $('.alert-field');
Expand Down Expand Up @@ -107,7 +116,12 @@ function pdfXBlockInitEdit(runtime, element) {
var oFile = ev.dataTransfer.files[0];
var request = new XMLHttpRequest();
var reader = new FileReader();
var course_key = element[0].dataset['usageId'].split('+', 3).join('+').replace('block', 'course');

// this is the new code:
var splitCount = isLibrary ? 2 : 3;
var keyword = isLibrary ? 'lib-block' : 'block';
var replacement = isLibrary ? 'library' : 'course';
var course_key = usageId.split('+', splitCount).join('+').replace(keyword, replacement);
var upload_url = '/assets/' + course_key + '/';
var csrftoken = $.cookie('csrftoken');
var alertField = $('.alert-field');
Expand Down