@@ -131,18 +131,37 @@ ShortAnswer.prototype.submitJournal = function () {
131131 function(data) {
132132 console.log(data.message);
133133 }); */
134- this . logBookEvent ( { 'event' : 'shortanswer' , 'act' : JSON . stringify ( value ) , 'div_id' : directive_id } ) ;
134+ this . logBookEvent ( { 'event' : 'shortanswer' , 'act' : JSON . stringify ( value ) , 'div_id' : this . divid } ) ;
135135} ;
136136
137137ShortAnswer . prototype . loadJournal = function ( ) {
138- var len = localStorage . length ;
139- if ( len > 0 ) {
140- var ex = localStorage . getItem ( this . divid ) ;
141- if ( ex !== null ) {
142- var solution = $ ( "#" + this . divid + "_solution" ) ;
143- solution . text ( localStorage . getItem ( this . divid ) ) ;
138+
139+ // Ask the server to send the latest
140+ var loadAnswer = function ( data , status , whatever ) {
141+ var len = localStorage . length ;
142+ var answer = "" ;
143+ console . log ( data ) ;
144+ if ( ! jQuery . isEmptyObject ( data ) ) {
145+ answer = data ;
144146 }
145- }
147+ console . log ( answer . toString ( ) ) ;
148+ var solution = $ ( "#" + this . divid + "_solution" ) ;
149+ if ( len > 0 ) {
150+ var ex = localStorage . getItem ( this . divid ) ;
151+ if ( ex !== null ) {
152+ if ( storage . is_new ( answer . divid , new Date ( answer . timestamp ) ) ) {
153+ solution . text ( localStorage . getItem ( this . divid ) ) ;
154+ // now send the newer answer to the server...
155+ } else {
156+ solution . text ( answer . answer ) ;
157+ }
158+ } else {
159+ solution . text ( answer ) ;
160+ }
161+ }
162+ } . bind ( this ) ;
163+ var data = { 'div_id' : this . divid } ;
164+ jQuery . get ( eBookConfig . ajaxURL + 'getlastanswer' , data , loadAnswer ) ;
146165} ;
147166
148167/*
0 commit comments