@@ -20,7 +20,8 @@ var EvoRoom = {
2020 /********************************************* INCOMING EVENTS *******************************************/
2121 start_step : function ( ev ) {
2222 if ( ev . payload . username && ev . payload . username === Sail . app . session . account . login ) {
23- if ( ev . payload . step_id ) {
23+ if ( ev . payload . step_id ) { ev
24+
2425 if ( ev . payload . step_id === "STEP_1" ) {
2526 console . log ( "Received start_step for step1 - nothing done with it right now!" ) ;
2627 } else if ( ev . payload . step_id === "STEP_2" ) {
@@ -143,7 +144,7 @@ var EvoRoom = {
143144 $ ( '#rotation-prediction .current-rainforest' ) . text ( Sail . app . formatRainforestString ( Sail . app . currentRainforest ) ) ;
144145 $ ( '#rotation-prediction' ) . show ( ) ;
145146 }
146- else if ( ev . payload . task === "guide_prediction_looker_upper " ) {
147+ else if ( ev . payload . task === "other " ) {
147148 $ ( '#rotation-field-guide .current-rainforest' ) . text ( Sail . app . formatRainforestString ( Sail . app . currentRainforest ) ) ;
148149 $ ( '#rotation-field-guide-and-prediction' ) . show ( ) ;
149150 }
@@ -152,6 +153,13 @@ var EvoRoom = {
152153 console . warn ( "task_assignment event received, but payload is incomplete" ) ;
153154 }
154155 } ,
156+
157+ rainforest_guess_submitted : function ( ev ) {
158+ if ( ( ev . payload . groupCode === Sail . app . currentGroupCode ) && ( ev . payload . author != Sail . app . session . account . login ) ) {
159+ Sail . app . hidePageElements ( ) ;
160+ $ ( '#loading-page' ) . show ( ) ;
161+ }
162+ } ,
155163
156164 /*****************************************EVENTS ADDED FOR STEP 3***********************************************/
157165
@@ -214,11 +222,29 @@ var EvoRoom = {
214222 } ,
215223
216224 connected : function ( ev ) {
217- Sail . app . setupPageLayout ( ) ;
218- Sail . app . restoreState ( ) ;
225+ Sail . app . rollcall . request ( Sail . app . rollcall . url + "/users/" + Sail . app . session . account . login + ".json" , "GET" , { } , function ( data ) {
226+ Sail . app . currentGroupCode = data . user . groups [ 0 ] . name ;
227+ Sail . app . user_metadata = data . user . metadata ;
228+ console . log ( 'metadata assigned' ) ;
229+ Sail . app . setupPageLayout ( ) ;
230+ Sail . app . restoreState ( ) ;
231+ } ) ;
219232 } ,
220233
221234 unauthenticated : function ( ev ) {
235+ Sail . app . user_metadata = null ;
236+ Sail . app . currentGroupCode = null ;
237+ Sail . app . currentRainforest = false ;
238+ Sail . app . organismsRainforestsCompleted = false ;
239+ Sail . app . firstRainforestAssigned = false ;
240+ Sail . app . targetRainforest = null ;
241+ Sail . app . rotationRainforestsCompleted = false ;
242+ Sail . app . firstInterview = false ;
243+ Sail . app . secondInterview = false ;
244+ Sail . app . rationaleAssigned = null ;
245+
246+ Sail . app . hidePageElements ( ) ;
247+
222248 Rollcall . Authenticator . requestRun ( ) ;
223249 }
224250 } ,
@@ -259,13 +285,8 @@ var EvoRoom = {
259285 Rollcall . Authenticator . requestLogin ( ) ;
260286 } else {
261287 Sail . app . rollcall . fetchSessionForToken ( Sail . app . token , function ( data ) {
262- Sail . app . session = data . session ;
263- Sail . app . rollcall . request ( Sail . app . rollcall . url + "/users/" + Sail . app . session . account . login + ".json" ,
264- "GET" , { } , function ( data ) {
265- Sail . app . currentGroupCode = data . user . groups [ 0 ] . name ;
266- Sail . app . user_metadata = data . user . metadata ;
267- $ ( Sail . app ) . trigger ( 'authenticated' ) ;
268- } ) ;
288+ Sail . app . session = data . session ;
289+ $ ( Sail . app ) . trigger ( 'authenticated' ) ;
269290 } ,
270291 function ( error ) {
271292 console . warn ( "Token '" + Sail . app . token + "' is invalid. Will try to re-authenticate..." ) ;
@@ -282,7 +303,7 @@ var EvoRoom = {
282303 $ ( '#survey-welcome' ) . hide ( ) ;
283304 $ ( '#rainforest-scan-failure' ) . hide ( ) ;
284305 $ ( '#rotation-scan-failure' ) . hide ( ) ;
285- $ ( '#student-chosen-organisms' ) . hide ( ) ;
306+ // $('#student-chosen-organisms').hide(); // hidePageElements is called repeatedly during step 1, so we can't include this one
286307 $ ( '#survey-organisms' ) . hide ( ) ;
287308 $ ( '#survey-organisms .next-rainforest' ) . hide ( ) ;
288309 $ ( '#survey-organisms .finished' ) . hide ( ) ;
@@ -330,7 +351,8 @@ var EvoRoom = {
330351 $ ( '#room-scan-failure .big-button' ) . click ( function ( ) {
331352 // hide everything
332353 Sail . app . hidePageElements ( ) ;
333- // show start page
354+ // show start page and organisms
355+ $ ( '#student-chosen-organisms' ) . show ( ) ;
334356 $ ( '#log-in-success' ) . show ( ) ;
335357 } ) ;
336358
@@ -352,6 +374,7 @@ var EvoRoom = {
352374 } ) ;
353375
354376 $ ( '#survey-welcome .big-button' ) . click ( function ( ) {
377+
355378 // trigger the QR scan screen/module to scan rainforests
356379 if ( window . plugins . barcodeScanner ) {
357380 window . plugins . barcodeScanner . scan ( Sail . app . barcodeScanRainforestSuccess , Sail . app . barcodeScanRainforestFailure ) ;
@@ -376,6 +399,7 @@ var EvoRoom = {
376399 // hide everything
377400 Sail . app . hidePageElements ( ) ;
378401 // wait
402+ $ ( '#student-chosen-organisms' ) . show ( ) ;
379403 $ ( '#loading-page' ) . show ( ) ;
380404 } ) ;
381405
@@ -419,6 +443,7 @@ var EvoRoom = {
419443 // on-click event to finish step1
420444 $ ( '#survey-organisms .small-button' ) . click ( function ( ) {
421445 Sail . app . hidePageElements ( ) ;
446+ $ ( '#student-chosen-organisms' ) . hide ( ) ;
422447
423448 // we also need to submit the organisms_present event
424449 if ( $ ( '.first-radios' ) . is ( ':checked' ) && $ ( '.second-radios' ) . is ( ':checked' ) ) {
@@ -582,9 +607,33 @@ var EvoRoom = {
582607 Sail . app . hidePageElements ( ) ;
583608 $ ( '#final-picks-choice' ) . show ( ) ;
584609 } ) ;
610+
611+ // on-click listeners for rainforest QR scanning error resolution
612+ $ ( '#final-picks-scan-failure .big-button' ) . click ( function ( ) {
613+ // hide everything
614+ Sail . app . hidePageElements ( ) ;
615+ // show start page
616+ $ ( '#final-picks-choice' ) . show ( ) ;
617+ } ) ;
618+
619+ $ ( '#final-picks-scan-failure .small-error-resolver-button' ) . click ( function ( ) {
620+ // send out event check_in
621+ Sail . app . currentRainforest = $ ( this ) . data ( 'rainforest' ) ;
622+ Sail . app . submitCheckIn ( ) ;
623+ // hide everything
624+ Sail . app . hidePageElements ( ) ;
625+ $ ( '#final-picks-debrief' ) . show ( ) ;
626+ } ) ;
585627
586628 $ ( '#final-picks-choice .big-button' ) . click ( function ( ) {
587- window . plugins . barcodeScanner . scan ( Sail . app . barcodeScanSuccessRainforest , Sail . app . barcodeScanFailure ) ;
629+ // trigger the QR scan screen/module to scan rainforests
630+ if ( window . plugins . barcodeScanner ) {
631+ window . plugins . barcodeScanner . scan ( Sail . app . barcodeScanFinalPicksSuccess , Sail . app . barcodeScanFinalPicksFailure ) ;
632+ } else {
633+ // call the error handler to get alternative
634+ Sail . app . barcodeScanFinalPicksFailure ( 'No scanner, probably desktop browser' ) ;
635+ }
636+ //window.plugins.barcodeScanner.scan(Sail.app.barcodeScanSuccessRainforest, Sail.app.barcodeScanFailure);
588637 Sail . app . hidePageElements ( ) ;
589638 $ ( '#final-picks-debrief' ) . show ( ) ;
590639 } ) ;
@@ -603,6 +652,20 @@ var EvoRoom = {
603652 $ ( '#rotation-intro .current-rainforest' ) . text ( Sail . app . formatRainforestString ( Sail . app . user_metadata . currently_assigned_location ) ) ;
604653 $ ( '#rotation-next-rainforest .next-rainforest' ) . text ( Sail . app . formatRainforestString ( Sail . app . user_metadata . currently_assigned_location ) ) ;
605654 $ ( '#rotation-next-rainforest' ) . show ( ) ;
655+ } else if ( Sail . app . user_metadata . state === 'AT_ASSIGNED_GUESS_LOCATION' ) {
656+ // wait for task_assignment message (from agent once all team members are at this state)
657+ Sail . app . targetRainforest = Sail . app . user_metadata . currently_assigned_location ;
658+ $ ( '#loading-page' ) . show ( ) ;
659+ } else if ( Sail . app . user_metadata . state === 'GUESS_TASK_ASSIGNED' ) {
660+ Sail . app . currentRainforest = Sail . app . user_metadata . currently_assigned_location ;
661+ if ( Sail . app . user_metadata . currently_assigned_task === 'scribe' ) {
662+ $ ( '#rotation-note-taker' ) . show ( ) ;
663+ } else {
664+ $ ( '#rotation-field-guide-and-prediction' ) . show ( ) ;
665+ }
666+ }
667+ else {
668+ console . warn ( 'restoreState: read state <' + Sail . app . user_metadata . state + '> which is not handled currently.' ) ;
606669 }
607670 } ,
608671
@@ -617,8 +680,8 @@ var EvoRoom = {
617680 } ,
618681
619682 submitOrganismsPresent : function ( ) {
620- var formattedOrg1 = Sail . app . formatOrganismString ( Sail . app . organism_1 ) ;
621- var formattedOrg2 = Sail . app . formatOrganismString ( Sail . app . organism_2 ) ;
683+ var formattedOrg1 = Sail . app . formatOrganismString ( Sail . app . user_metadata . assigned_organism_1 ) ;
684+ var formattedOrg2 = Sail . app . formatOrganismString ( Sail . app . user_metadata . assigned_organism_2 ) ;
622685 var formattedRadio1 = Sail . app . formatStringToBoolean ( $ ( 'input:radio[name=first-organism-yn]:checked' ) . val ( ) ) ;
623686 var formattedRadio2 = Sail . app . formatStringToBoolean ( $ ( 'input:radio[name=second-organism-yn]:checked' ) . val ( ) ) ;
624687 var sev = new Sail . Event ( 'organism_present' , {
@@ -742,6 +805,24 @@ var EvoRoom = {
742805 Sail . app . hidePageElements ( ) ;
743806 $ ( '#rainforest-scan-failure' ) . show ( ) ;
744807 } ,
808+
809+ barcodeScanFinalPicksSuccess : function ( result ) {
810+ console . log ( "Got Barcode: " + result ) ;
811+ // send out event check_in
812+ Sail . app . currentRainforest = result ;
813+ Sail . app . submitCheckIn ( ) ;
814+ // hide everything
815+ Sail . app . hidePageElements ( ) ;
816+ // show waiting page
817+ $ ( '#final-picks-debrief' ) . show ( ) ;
818+ } ,
819+
820+ barcodeScanFinalPicksFailure : function ( msg ) {
821+ console . warn ( "SCAN FAILED: " + msg ) ;
822+ // hide everything
823+ Sail . app . hidePageElements ( ) ;
824+ $ ( '#final-picks-scan-failure' ) . show ( ) ;
825+ } ,
745826
746827 barcodeScanCheckLocationAssignmentSuccess : function ( result ) {
747828 console . log ( "Got Barcode: " + result ) ;
0 commit comments