From b6cf206fc72db36ac13e48a96541e2aa7902132e Mon Sep 17 00:00:00 2001 From: ichuang Date: Sun, 24 Feb 2013 01:54:29 +0000 Subject: [PATCH 1/3] fix latex high-level-source editor --- cms/templates/widgets/source-edit.html | 91 ++++++++++++++++++++++++-- 1 file changed, 87 insertions(+), 4 deletions(-) diff --git a/cms/templates/widgets/source-edit.html b/cms/templates/widgets/source-edit.html index f0922831e1..d3afbdf040 100644 --- a/cms/templates/widgets/source-edit.html +++ b/cms/templates/widgets/source-edit.html @@ -10,7 +10,7 @@

High Level Source Editing

-
+
@@ -18,6 +18,9 @@ +
+ +
@@ -32,12 +35,43 @@ $('#hls-trig-${hlskey}').click(function(){slow_refresh_hls($('#hls-modal-${hlskey}'))}) + // file upload button + $('#hls-modal-${hlskey}').find('.hls-upload').click(function(){ + $('#hls-modal-${hlskey}').find('#hlsfile').trigger('click'); + }); + + $('#hls-modal-${hlskey}').find('#hlsfile').change(function() { + console.log('handler for hlsfile input called'); + var file = $('#hls-modal-${hlskey}').find('#hlsfile')[0].files[0]; + el = $('#hls-modal-${hlskey}'); + console.log(file); + + var reader = new FileReader(); + reader.onload = function(event) { + var contents = event.target.result; + process_file_contents(el, contents); + }; + reader.readAsText(file); + }); + + // file upload processing + function process_file_contents(el, contents){ + // console.log("File contents: " + contents); + editor = el.data('editor'); + editor.setValue(contents); + console.log('doing compile and save'); + // trigger compile & save + el.find('.hls-compile').trigger('click'); + } + // refresh button $('#hls-modal-${hlskey}').find('.hls-refresh').click(function(){refresh_hls($('#hls-modal-${hlskey}'))}); function refresh_hls(el){ el.data('editor').refresh(); + // hide gray overlay + $('#lean_overlay').hide(); } function slow_refresh_hls(el){ @@ -52,15 +86,55 @@ // compile & save button - $('#hls-modal-${hlskey}').find('.hls-compile').click(compile_hls_${hlskey}); + // $('#hls-modal-${hlskey}').find('.hls-compile').click(compile_hls_${hlskey}); + $('#hls-modal-${hlskey}').find('.hls-compile').click(function(){ + el = $('#hls-modal-${hlskey}'); + compile_hls(el); + }); - function compile_hls_${hlskey}(){ + // connect to server using POST (requires cross-domain-access) + + function compile_hls(el){ + editor = el.data('editor') + hlsdata = editor.getValue(); + // console.log('hlsdata=' + hlsdata); + + $.ajax({ + url: "https://studio-input-filter.mitx.mit.edu/latex2edx?raw=1", + type: "POST", + data: ""+hlsdata, + crossDomain: true, + processData: false, + success: function(data){ + console.log('latex2edx success!'); + console.log(data); + xml = data.xml; + if (xml.length==0){ + alert('Conversion failed! error:'+ data.message); + //set_status(el, "Conversion failed - please try another file", false); + }else{ + //set_status(el, "Done!", true); + // post_images(el, location, data, file); + // post_source_code(el, location, file); + el.closest('.component').find('.CodeMirror-wrap')[0].CodeMirror.setValue(xml); + save_hls(el); + } + }, + error: function() { + alert('Error: cannot connect to word2edx server'); + console.log('error!'); + } + }); + } + + ## this version uses JSONP and GET, which limits file sizes + function old_compile_hls_${hlskey}(){ editor = $('#hls-modal-${hlskey}').data('editor') var myquery = { latexin: editor.getValue() }; $.ajax({ - url: '${metadata.get('source_processor_url','https://qisx.mit.edu:5443/latex2edx')}', + url: '${metadata.get('source_processor_url','https://studio-input-filter.mitx.mit.edu/latex2edx')}', type: 'GET', contentType: 'application/json', data: escape(JSON.stringify(myquery)), @@ -109,4 +183,13 @@ el.closest('.component').find('.save-button').click(); } + ## add upload and download links / buttons to component edit box + $('#hls-modal-${hlskey}').closest('.component').find('.component-actions').append(''); + $('#link-${hlskey}').html('upload'); + $('#upload-${hlskey}').click(function(){ + $('#hls-modal-${hlskey}').closest('.component').find('.edit-button').trigger('click'); // open up editor window + $('#hls-trig-${hlskey}').trigger('click'); // open up HLS editor window + $('#hls-modal-${hlskey}').find('#hlsfile').trigger('click'); + }); + From b75ccbdcce2af0969239f32f1e432b5dc536f9fa Mon Sep 17 00:00:00 2001 From: ichuang Date: Thu, 28 Feb 2013 04:18:16 +0000 Subject: [PATCH 2/3] address Christina's comments re js in latex2edx source-edit.html --- cms/templates/widgets/source-edit.html | 262 ++++++++++++------------- 1 file changed, 121 insertions(+), 141 deletions(-) diff --git a/cms/templates/widgets/source-edit.html b/cms/templates/widgets/source-edit.html index d3afbdf040..c7460c9cf7 100644 --- a/cms/templates/widgets/source-edit.html +++ b/cms/templates/widgets/source-edit.html @@ -18,7 +18,7 @@ -
+ @@ -28,168 +28,148 @@ - From 9fe9e2fbf6de1b7b8f53af60882e194f82306815 Mon Sep 17 00:00:00 2001 From: ichuang Date: Thu, 28 Feb 2013 04:19:39 +0000 Subject: [PATCH 3/3] upadte latex2edx url in latex-problem template --- common/lib/xmodule/xmodule/templates/problem/latex_problem.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/templates/problem/latex_problem.yaml b/common/lib/xmodule/xmodule/templates/problem/latex_problem.yaml index 434354e4c7..81cb9dc353 100644 --- a/common/lib/xmodule/xmodule/templates/problem/latex_problem.yaml +++ b/common/lib/xmodule/xmodule/templates/problem/latex_problem.yaml @@ -1,7 +1,7 @@ --- metadata: display_name: Problem Written in LaTeX - source_processor_url: https://qisx.mit.edu:5443/latex2edx + source_processor_url: https://studio-input-filter.mitx.mit.edu/latex2edx source_code: | % Nearly any kind of edX problem can be authored using Latex as % the source language. Write latex as usual, including equations. The