@@ -26,6 +26,7 @@ ShortAnswer.prototype = new RunestoneBase();
2626ShortAnswer . prototype . init = function ( opts ) {
2727 RunestoneBase . apply ( this , arguments ) ;
2828 var orig = opts . orig ; // entire <p> element that will be replaced by new HTML
29+ this . useRunestoneServies = opts . useRunestoneServices || eBookConfig . useRunestoneServices ;
2930 this . origElem = orig ;
3031 this . divid = orig . id ;
3132 this . question = this . origElem . innerHTML ;
@@ -139,82 +140,45 @@ ShortAnswer.prototype.loadJournal = function () {
139140 // Ask the server to send the latest
140141 var loadAnswer = function ( data , status , whatever ) {
141142 var len = localStorage . length ;
142- var answer = "" ;
143- console . log ( data ) ;
143+ var answer = { } ;
144144 if ( ! jQuery . isEmptyObject ( data ) ) {
145145 answer = data ;
146+ } else {
147+ answer . answer = "" ;
146148 }
147- console . log ( answer . toString ( ) ) ;
148149 var solution = $ ( "#" + this . divid + "_solution" ) ;
149150 if ( len > 0 ) {
150- var ex = localStorage . getItem ( this . divid ) ;
151+ var ex = storage . get ( this . divid ) ;
151152 if ( ex !== null ) {
152- if ( storage . is_new ( answer . divid , new Date ( answer . timestamp ) ) ) {
153- solution . text ( localStorage . getItem ( this . divid ) ) ;
153+ if ( ! storage . is_new ( answer . divid , new Date ( answer . timestamp ) ) ) {
154+ solution . text ( storage . get ( this . divid ) ) ;
154155 // now send the newer answer to the server...
155156 } else {
156157 solution . text ( answer . answer ) ;
157158 }
158159 } else {
159- solution . text ( answer ) ;
160+ solution . text ( answer . answer ) ;
160161 }
162+ } else {
163+ solution . text ( answer . answer ) ;
161164 }
162165 } . bind ( this ) ;
163166 var data = { 'div_id' : this . divid } ;
164- jQuery . get ( eBookConfig . ajaxURL + 'getlastanswer' , data , loadAnswer ) ;
167+ if ( this . useRunestoneServies ) {
168+ jQuery . get ( eBookConfig . ajaxURL + 'getlastanswer' , data , loadAnswer ) ;
169+ } else {
170+ loadAnswer ( { } , null , null ) ;
171+ }
165172} ;
166173
167- /*
168-
169- <div id='%(divid)s' class='journal alert alert-%(optional)s'>
170- <form id='%(divid)s_journal' name='%(divid)s_journal' action="">
171- <fieldset>
172- <legend>Short Answer</legend>
173- <div class='journal-question'>%(qnum)s: %(content)s</div>
174- <div id='%(divid)s_journal_input'>
175- <div class='journal-options'>
176- <label class='radio-inline'>
177- <textarea id='%(divid)s_solution' class="form-control" style="display:inline; width: 530px;"
178- rows='4' cols='50'></textarea>
179- </label>
180- </div><br />
181- <div><button class="btn btn-default" onclick="submitJournal('%(divid)s');">Save</button></div>
182- Instructor's Feedback:
183- <div class='journal-options' style='padding-left:20px'>
184- <div class='bg-info form-control' style='width:530px; background-color: #eee; font-style:italic'
185- id='%(divid)s_feedback'>
186- There is no feedback yet.
187- </div>
188- </div><br />
189- </div>
190- </fieldset>
191- </form>
192- <div id='%(divid)s_results'></div>
193- <script type='text/javascript'>
194- // check if the user has already answered this journal
195- $(function() {
196- loadJournal('%(divid)s');
197- });
198- </script>
199- </div>
200-
201-
202-
203- */
204-
205-
206-
207-
208-
209-
210174
211175/*=================================
212176== Find the custom HTML tags and ==
213177== execute our code on them ==
214178=================================*/
215179$ ( document ) . ready ( function ( ) {
216180 $ ( "[data-component=shortanswer]" ) . each ( function ( index ) {
217- saList [ this . id ] = new ShortAnswer ( { "orig" : this } ) ;
181+ saList [ this . id ] = new ShortAnswer ( { "orig" : this , 'useRunestoneServices' : eBookConfig . useRunestoneServices } ) ;
218182 } ) ;
219183
220184} ) ;
0 commit comments