Commit 8fb06ce1 by Prem Sichanugrist

Update code according to changes in 829e502b

parent de4d4874
...@@ -34,7 +34,7 @@ describe 'Courseware', -> ...@@ -34,7 +34,7 @@ describe 'Courseware', ->
<div class="course-content"> <div class="course-content">
<div id="video_1" class="video" data-streams="1.0:abc1234"></div> <div id="video_1" class="video" data-streams="1.0:abc1234"></div>
<div id="video_2" class="video" data-streams="1.0:def5678"></div> <div id="video_2" class="video" data-streams="1.0:def5678"></div>
<div id="problem_3" class="problems-wrapper" data-url="/example/url/"> <div id="problem_3" class="problems-wrapper" data-problem-id="3" data-url="/example/url/">
<div id="histogram_3" class="histogram" data-histogram="[[0, 1]]" style="height: 20px; display: block;"> <div id="histogram_3" class="histogram" data-histogram="[[0, 1]]" style="height: 20px; display: block;">
</div> </div>
</div> </div>
...@@ -46,7 +46,7 @@ describe 'Courseware', -> ...@@ -46,7 +46,7 @@ describe 'Courseware', ->
expect(window.Video).toHaveBeenCalledWith('2', '1.0:def5678') expect(window.Video).toHaveBeenCalledWith('2', '1.0:def5678')
it 'detect the problem element and convert it', -> it 'detect the problem element and convert it', ->
expect(window.Problem).toHaveBeenCalledWith('3', '/example/url/') expect(window.Problem).toHaveBeenCalledWith(3, 'problem_3', '/example/url/')
it 'detect the histrogram element and convert it', -> it 'detect the histrogram element and convert it', ->
expect(window.Histogram).toHaveBeenCalledWith('3', [[0, 1]]) expect(window.Histogram).toHaveBeenCalledWith('3', [[0, 1]])
...@@ -20,12 +20,12 @@ jasmine.stubRequests = -> ...@@ -20,12 +20,12 @@ jasmine.stubRequests = ->
settings.success data: jasmine.stubbedMetadata[match[1]] settings.success data: jasmine.stubbedMetadata[match[1]]
else if match = settings.url.match /static\/subs\/(.+)\.srt\.sjson/ else if match = settings.url.match /static\/subs\/(.+)\.srt\.sjson/
settings.success jasmine.stubbedCaption settings.success jasmine.stubbedCaption
else if settings.url.match /modx\/problem\/.+\/problem_get$/ else if settings.url.match /modx\/.+\/problem_get$/
settings.success html: readFixtures('problem_content.html') settings.success html: readFixtures('problem_content.html')
else if settings.url == '/calculate' || else if settings.url == '/calculate' ||
settings.url == '/6002x/modx/sequence/1/goto_position' || settings.url.match(/modx\/.+\/goto_position$/) ||
settings.url.match(/event$/) || settings.url.match(/event$/) ||
settings.url.match(/modx\/problem\/.+\/problem_(check|reset|show|save)$/) settings.url.match(/modx\/.+\/problem_(check|reset|show|save)$/)
# do nothing # do nothing
else else
throw "External request attempted for #{settings.url}, which is not defined." throw "External request attempted for #{settings.url}, which is not defined."
......
...@@ -17,7 +17,7 @@ describe 'Problem', -> ...@@ -17,7 +17,7 @@ describe 'Problem', ->
describe 'constructor', -> describe 'constructor', ->
beforeEach -> beforeEach ->
@problem = new Problem 1, '/problem/url/' @problem = new Problem 1, "problem_1", "/problem/url/"
it 'set the element', -> it 'set the element', ->
expect(@problem.el).toBe '#problem_1' expect(@problem.el).toBe '#problem_1'
...@@ -26,7 +26,7 @@ describe 'Problem', -> ...@@ -26,7 +26,7 @@ describe 'Problem', ->
beforeEach -> beforeEach ->
spyOn window, 'update_schematics' spyOn window, 'update_schematics'
MathJax.Hub.getAllJax.andReturn [@stubbedJax] MathJax.Hub.getAllJax.andReturn [@stubbedJax]
@problem = new Problem 1, '/problem/url/' @problem = new Problem 1, "problem_1", "/problem/url/"
it 'set mathjax typeset', -> it 'set mathjax typeset', ->
expect(MathJax.Hub.Queue).toHaveBeenCalled() expect(MathJax.Hub.Queue).toHaveBeenCalled()
...@@ -60,7 +60,7 @@ describe 'Problem', -> ...@@ -60,7 +60,7 @@ describe 'Problem', ->
describe 'render', -> describe 'render', ->
beforeEach -> beforeEach ->
@problem = new Problem 1, '/problem/url/' @problem = new Problem 1, "problem_1", "/problem/url/"
@bind = @problem.bind @bind = @problem.bind
spyOn @problem, 'bind' spyOn @problem, 'bind'
...@@ -88,7 +88,7 @@ describe 'Problem', -> ...@@ -88,7 +88,7 @@ describe 'Problem', ->
describe 'check', -> describe 'check', ->
beforeEach -> beforeEach ->
@problem = new Problem 1, '/problem/url/' @problem = new Problem 1, "problem_1", "/problem/url/"
@problem.answers = 'foo=1&bar=2' @problem.answers = 'foo=1&bar=2'
it 'log the problem_check event', -> it 'log the problem_check event', ->
...@@ -98,7 +98,7 @@ describe 'Problem', -> ...@@ -98,7 +98,7 @@ describe 'Problem', ->
it 'submit the answer for check', -> it 'submit the answer for check', ->
spyOn $, 'postWithPrefix' spyOn $, 'postWithPrefix'
@problem.check() @problem.check()
expect($.postWithPrefix).toHaveBeenCalledWith '/modx/problem/1/problem_check', 'foo=1&bar=2', jasmine.any(Function) expect($.postWithPrefix).toHaveBeenCalledWith '/modx/1/problem_check', 'foo=1&bar=2', jasmine.any(Function)
describe 'when the response is correct', -> describe 'when the response is correct', ->
it 'call render with returned content', -> it 'call render with returned content', ->
...@@ -121,7 +121,7 @@ describe 'Problem', -> ...@@ -121,7 +121,7 @@ describe 'Problem', ->
describe 'reset', -> describe 'reset', ->
beforeEach -> beforeEach ->
@problem = new Problem 1, '/problem/url/' @problem = new Problem 1, "problem_1", "/problem/url/"
it 'log the problem_reset event', -> it 'log the problem_reset event', ->
@problem.answers = 'foo=1&bar=2' @problem.answers = 'foo=1&bar=2'
...@@ -131,7 +131,7 @@ describe 'Problem', -> ...@@ -131,7 +131,7 @@ describe 'Problem', ->
it 'POST to the problem reset page', -> it 'POST to the problem reset page', ->
spyOn $, 'postWithPrefix' spyOn $, 'postWithPrefix'
@problem.reset() @problem.reset()
expect($.postWithPrefix).toHaveBeenCalledWith '/modx/problem/1/problem_reset', { id: 1 }, jasmine.any(Function) expect($.postWithPrefix).toHaveBeenCalledWith '/modx/1/problem_reset', { id: 1 }, jasmine.any(Function)
it 'render the returned content', -> it 'render the returned content', ->
spyOn($, 'postWithPrefix').andCallFake (url, answers, callback) -> spyOn($, 'postWithPrefix').andCallFake (url, answers, callback) ->
...@@ -141,7 +141,7 @@ describe 'Problem', -> ...@@ -141,7 +141,7 @@ describe 'Problem', ->
describe 'show', -> describe 'show', ->
beforeEach -> beforeEach ->
@problem = new Problem 1, '/problem/url/' @problem = new Problem 1, "problem_1", "/problem/url/"
@problem.el.prepend '<div id="answer_1_1" /><div id="answer_1_2" />' @problem.el.prepend '<div id="answer_1_1" /><div id="answer_1_2" />'
describe 'when the answer has not yet shown', -> describe 'when the answer has not yet shown', ->
...@@ -155,7 +155,7 @@ describe 'Problem', -> ...@@ -155,7 +155,7 @@ describe 'Problem', ->
it 'fetch the answers', -> it 'fetch the answers', ->
spyOn $, 'postWithPrefix' spyOn $, 'postWithPrefix'
@problem.show() @problem.show()
expect($.postWithPrefix).toHaveBeenCalledWith '/modx/problem/1/problem_show', jasmine.any(Function) expect($.postWithPrefix).toHaveBeenCalledWith '/modx/1/problem_show', jasmine.any(Function)
it 'show the answers', -> it 'show the answers', ->
spyOn($, 'postWithPrefix').andCallFake (url, callback) -> spyOn($, 'postWithPrefix').andCallFake (url, callback) ->
...@@ -220,7 +220,7 @@ describe 'Problem', -> ...@@ -220,7 +220,7 @@ describe 'Problem', ->
describe 'save', -> describe 'save', ->
beforeEach -> beforeEach ->
@problem = new Problem 1, '/problem/url/' @problem = new Problem 1, "problem_1", "/problem/url/"
@problem.answers = 'foo=1&bar=2' @problem.answers = 'foo=1&bar=2'
it 'log the problem_save event', -> it 'log the problem_save event', ->
...@@ -230,7 +230,7 @@ describe 'Problem', -> ...@@ -230,7 +230,7 @@ describe 'Problem', ->
it 'POST to save problem', -> it 'POST to save problem', ->
spyOn $, 'postWithPrefix' spyOn $, 'postWithPrefix'
@problem.save() @problem.save()
expect($.postWithPrefix).toHaveBeenCalledWith '/modx/problem/1/problem_save', 'foo=1&bar=2', jasmine.any(Function) expect($.postWithPrefix).toHaveBeenCalledWith '/modx/1/problem_save', 'foo=1&bar=2', jasmine.any(Function)
it 'alert to the user', -> it 'alert to the user', ->
spyOn window, 'alert' spyOn window, 'alert'
...@@ -240,7 +240,7 @@ describe 'Problem', -> ...@@ -240,7 +240,7 @@ describe 'Problem', ->
describe 'refreshMath', -> describe 'refreshMath', ->
beforeEach -> beforeEach ->
@problem = new Problem 1, '/problem/url/' @problem = new Problem 1, "problem_1", "/problem/url/"
$('#input_example_1').val 'E=mc^2' $('#input_example_1').val 'E=mc^2'
@problem.refreshMath target: $('#input_example_1').get(0) @problem.refreshMath target: $('#input_example_1').get(0)
...@@ -250,7 +250,7 @@ describe 'Problem', -> ...@@ -250,7 +250,7 @@ describe 'Problem', ->
describe 'updateMathML', -> describe 'updateMathML', ->
beforeEach -> beforeEach ->
@problem = new Problem 1, '/problem/url/' @problem = new Problem 1, "problem_1", "/problem/url/"
@stubbedJax.root.toMathML.andReturn '<MathML>' @stubbedJax.root.toMathML.andReturn '<MathML>'
describe 'when there is no exception', -> describe 'when there is no exception', ->
...@@ -270,7 +270,7 @@ describe 'Problem', -> ...@@ -270,7 +270,7 @@ describe 'Problem', ->
describe 'refreshAnswers', -> describe 'refreshAnswers', ->
beforeEach -> beforeEach ->
@problem = new Problem 1, '/problem/url/' @problem = new Problem 1, "problem_1", "/problem/url/"
@problem.el.html ''' @problem.el.html '''
<textarea class="CodeMirror" /> <textarea class="CodeMirror" />
<input id="input_1_1" name="input_1_1" class="schematic" value="one" /> <input id="input_1_1" name="input_1_1" class="schematic" value="one" />
......
...@@ -9,7 +9,7 @@ describe 'Sequence', -> ...@@ -9,7 +9,7 @@ describe 'Sequence', ->
describe 'constructor', -> describe 'constructor', ->
beforeEach -> beforeEach ->
@sequence = new Sequence '1', @items, 'sequence', 1 @sequence = new Sequence '1', 'sequence_1', @items, 'sequence', 1
it 'set the element', -> it 'set the element', ->
expect(@sequence.el).toEqual $('#sequence_1') expect(@sequence.el).toEqual $('#sequence_1')
...@@ -31,7 +31,7 @@ describe 'Sequence', -> ...@@ -31,7 +31,7 @@ describe 'Sequence', ->
describe 'toggleArrows', -> describe 'toggleArrows', ->
beforeEach -> beforeEach ->
@sequence = new Sequence '1', @items, 'sequence', 1 @sequence = new Sequence '1', 'sequence_1', @items, 'sequence', 1
describe 'when the first tab is active', -> describe 'when the first tab is active', ->
beforeEach -> beforeEach ->
...@@ -73,7 +73,7 @@ describe 'Sequence', -> ...@@ -73,7 +73,7 @@ describe 'Sequence', ->
describe 'render', -> describe 'render', ->
beforeEach -> beforeEach ->
spyOn $, 'postWithPrefix' spyOn $, 'postWithPrefix'
@sequence = new Sequence '1', @items, 'sequence' @sequence = new Sequence '1', 'sequence_1', @items, 'sequence'
spyOnEvent @sequence.el, 'contentChanged' spyOnEvent @sequence.el, 'contentChanged'
spyOn(@sequence, 'toggleArrows').andCallThrough() spyOn(@sequence, 'toggleArrows').andCallThrough()
...@@ -94,7 +94,7 @@ describe 'Sequence', -> ...@@ -94,7 +94,7 @@ describe 'Sequence', ->
expect($('[data-element="2"]')).toHaveClass 'seq_video_visited' expect($('[data-element="2"]')).toHaveClass 'seq_video_visited'
it 'save the new position', -> it 'save the new position', ->
expect($.postWithPrefix).toHaveBeenCalledWith '/modx/sequence/1/goto_position', position: 1 expect($.postWithPrefix).toHaveBeenCalledWith '/modx/1/goto_position', position: 1
it 'mark new tab as active', -> it 'mark new tab as active', ->
expect($('[data-element="1"]')).toHaveClass 'seq_video_active' expect($('[data-element="1"]')).toHaveClass 'seq_video_active'
...@@ -120,7 +120,7 @@ describe 'Sequence', -> ...@@ -120,7 +120,7 @@ describe 'Sequence', ->
describe 'goto', -> describe 'goto', ->
beforeEach -> beforeEach ->
jasmine.stubRequests() jasmine.stubRequests()
@sequence = new Sequence '1', @items, 'sequence', 2 @sequence = new Sequence '1', 'sequence_1', @items, 'sequence', 2
$('[data-element="3"]').click() $('[data-element="3"]').click()
it 'log the sequence goto event', -> it 'log the sequence goto event', ->
...@@ -132,7 +132,7 @@ describe 'Sequence', -> ...@@ -132,7 +132,7 @@ describe 'Sequence', ->
describe 'next', -> describe 'next', ->
beforeEach -> beforeEach ->
jasmine.stubRequests() jasmine.stubRequests()
@sequence = new Sequence '1', @items, 'sequence', 2 @sequence = new Sequence '1', 'sequence_1', @items, 'sequence', 2
$('.sequence-nav-buttons .next a').click() $('.sequence-nav-buttons .next a').click()
it 'log the next sequence event', -> it 'log the next sequence event', ->
...@@ -144,7 +144,7 @@ describe 'Sequence', -> ...@@ -144,7 +144,7 @@ describe 'Sequence', ->
describe 'previous', -> describe 'previous', ->
beforeEach -> beforeEach ->
jasmine.stubRequests() jasmine.stubRequests()
@sequence = new Sequence '1', @items, 'sequence', 2 @sequence = new Sequence '1', 'sequence_1', @items, 'sequence', 2
$('.sequence-nav-buttons .prev a').click() $('.sequence-nav-buttons .prev a').click()
it 'log the previous sequence event', -> it 'log the previous sequence event', ->
...@@ -155,5 +155,5 @@ describe 'Sequence', -> ...@@ -155,5 +155,5 @@ describe 'Sequence', ->
describe 'link_for', -> describe 'link_for', ->
it 'return a link for specific position', -> it 'return a link for specific position', ->
sequence = new Sequence '1', @items, 2 sequence = new Sequence '1', 'sequence_1', @items, 2
expect(sequence.link_for(2)).toBe '[data-element="2"]' expect(sequence.link_for(2)).toBe '[data-element="2"]'
...@@ -20,7 +20,7 @@ class @Courseware ...@@ -20,7 +20,7 @@ class @Courseware
id = $(this).attr('id').replace(/video_/, '') id = $(this).attr('id').replace(/video_/, '')
new Video id, $(this).data('streams') new Video id, $(this).data('streams')
$('.course-content .problems-wrapper').each -> $('.course-content .problems-wrapper').each ->
id = $(this).attr('problem-id') id = $(this).data('problem-id')
new Problem id, $(this).attr('id'), $(this).data('url') new Problem id, $(this).attr('id'), $(this).data('url')
$('.course-content .histogram').each -> $('.course-content .histogram').each ->
id = $(this).attr('id').replace(/histogram_/, '') id = $(this).attr('id').replace(/histogram_/, '')
......
class @Problem class @Problem
constructor: (@id, @element_id, url) -> constructor: (@id, @element_id, url) ->
@el = $("##{element_id}") @el = $("##{@element_id}")
@render() @render()
$: (selector) -> $: (selector) ->
......
class @Sequence class @Sequence
constructor: (@id, @element_id, @elements, @tag, position) -> constructor: (@id, @element_id, @elements, @tag, position) ->
@el = $("#sequence_#{@element_id}") @el = $("##{@element_id}")
@buildNavigation() @buildNavigation()
@initProgress() @initProgress()
@bind() @bind()
......
<section id="problem_${element_id}" class="problems-wrapper" problem-id="${id}" data-url="${ajax_url}"></section> <section id="problem_${element_id}" class="problems-wrapper" data-problem-id="${id}" data-url="${ajax_url}"></section>
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
<%block name="js_extra"> <%block name="js_extra">
<script type="text/javascript"> <script type="text/javascript">
$(function(){ $(function(){
new Sequence('${item_id}', '${element_id}', ${items}, '${tag}', ${position}); new Sequence('${item_id}', 'sequence_${element_id}', ${items}, '${tag}', ${position});
}); });
</script> </script>
</%block> </%block>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment