-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmessaging.js
155 lines (150 loc) · 8.73 KB
/
messaging.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// MESSAGING
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class Messaging {
constructor() // CONSTRUCTOR
{
}
OnMessage(msg) { // ON MESSAGE
var v;
var source=msg.source; // Get source
msg=msg.data; // Extract just message
if (!msg || (typeof msg != "string")) // Nothing there
return; // Quit
v=msg.split("|"); // Chop into params
if (msg.match(/ShivaGraph=click/)) // On graph click
app.rul.CheckRules("click",app.doc.curLobId,v[2]); // Send to rules
else if (msg.match(/ShivaChart=click/)) // On chart click
MenuBarMsg("You clicked on "+v[2]); // React
else if (msg.match(/ShivaMap=click/)) // On map click
MenuBarMsg("You clicked on "+v[2]+","+v[3]); // React
else if (msg.match(/ShivaMap=marker/)) // On map click
MenuBarMsg("You clicked marker at "+v[3]+","+v[4]); // React
else if (msg.match(/Assess=ready/)) { // Assessment module loaded
var i,o;
var str='ScaleAct=data|{"pages":['; // Header
for (i=1;i<v.length-1;++i) { // For each step
o=app.doc.FindAskById(v[i]); // Point at step
if (!o) continue; // Invalid step
str+=o.step; // Add step
if (i != v.length-2) str+=",\n"; // Not last, add comma
else str+="]}"; // Last, close array/object
}
source.postMessage(str,"*"); // Send data to window
}
else if (msg.match(/Assess=done/)) { // Assessment module loaded
var id=app.doc.curLobId; // Save id to assessment
if (app.con.resumeId) // If a resume set
app.con.Draw(app.con.resumeId); // Init player
else{ // Normal end
app.doc.NextLob(); // Advance to next pos
app.Draw(); // Redraw
}
var j=app.doc.FindLobIndexById(v[1]); // Get assessment lob index
if (app.setDone && (j >= 0)) // If setting
app.doc.SetStatus(j,(v[2]-0 >= app.assessLevel-0) ? app.doc.statusThreshold : 0); // If after pass level, set status
app.con.resumeId=app.con.resumeTime=0; // Clear resume
app.rul.CheckRules("assess",id,Math.floor(v[2]*100)); // Send to rules
app.msg.SaveToForm("Assess"+v[1]+"="+Math.floor(v[2]*100)); // Save final score to form, if set
}
else if (msg.match(/Assess=answer/)) { // Assessment module loaded
if (app.con.resumeId) // In a trigger
app.rul.CheckRules("answer",app.con.triggerId+":"+v[2],v[3]); // Send trigger id to rule checker
else // Direct
app.rul.CheckRules("answer",app.doc.curLobId+":"+v[2],v[3]); // Send to rule checker
if (app.reportLevel == 1) // If reporting answers
app.msg.SaveToForm("Answer"+app.doc.curLobId+":"+v[2]+"="+v[3]); // Save answer to form, if set
}
else if (msg.match(/Assess=rule/)) { // Run a rule
app.rul.RunRule(v[1],v[2])
}
else if (msg.match(/ScaleVideo/)) { // Video event
if (msg.toLowerCase() == "scalevideo=next") { // Advance to next pos
app.doc.NextLob(); // Advance
app.Draw(); // Draw
return;
}
if (v[0].toLowerCase() == "scalevideo=notes") // Toggle notes
app.con.VideoNotes(); // Show notes dialog
if (v[0].toLowerCase() == "scalevideo=trans") // Toggle transcription
app.con.Transcript(v[1]); // Show transcription dialog
if (v[0].toLowerCase() == "scalevideo=toc") // Toggle TOC
app.con.TableOfContents(v[1]); // Show TOC dialog
if (v[0].toLowerCase() == "scalevideo=time") // Incoming time
app.con.playerNow=v[1];
if (msg.match(/trigger/)) { // Hit a trigger point
if (v[1].toLowerCase() == "next") { // Advance to next pos
app.doc.NextLob(); // Advance
app.Draw(); // Draw
return;
}
var o=app.doc.FindLobById(v[1]); // Point at triggered lob (typically an assessment)
if (!o) { // Look for skin
o=app.doc.FindLobById(v[1],app.ams.skins); // Get skin
app.ams.Draw(app.doc.curLobId,o,"#contentIF"); // Draw skin
return; // Quit
}
if (o.body.match(/assess\(/i)) { // If an assessment
app.con.triggerId=v[1]; // Store trigger id
app.con.resumeId=app.doc.curLobId; // Store resume id
app.con.resumeTime=v[2]; // Store resume time
}
if (app.skipDone && o && (o.status >= app.doc.statusThreshold)) // If seen and skipping
app.con.Draw(app.doc.curLobId); // Resume playing
else // Run trigger mob
app.con.Draw(v[1]); // Draw content
}
}
else if (msg.match(/ScalePreview/)) { // Preview call
app.doc.InitFromTSV(msg.substring(13)); // Init show
app.Draw(); // Redraw
}
else if (msg.match(/ActiveMediaSkin/)) { // AMS
if (msg.match(/show/)) // Show pane
app.con.Draw(v[1]-0); // Go
else if (msg.match(/goto/)) { // Goto pane
if (v[1].toLowerCase() == "next") // Advance to next pos
app.doc.NextLob(),app.Draw(); // Go
else // To a specific pane
app.Draw(app.doc.FindLobIndexById(v[1]-0)) // Go
}
else if (msg.match(/report/)) // REPORT
app.msg.SaveToForm("Skin"+v[2]+"="+v[1]); // Save value to form, if set
}
else if (msg.match(/ScaleSnap/)) { // SCALE
if (msg.match(/show/)) // Show pane
app.con.Draw(v[1]-0); // Go
else if (msg.match(/goto/)) { // Goto pane
if (v[1].toLowerCase() == "next") // Advance to next pos
app.doc.NextLob(),app.Draw(); // Go
else // To a specific pane
app.Draw(app.doc.FindLobIndexById(v[1]-0)) // Go
}
else if (msg.match(/report/)) // REPORT
app.msg.SaveToForm("Skin"+v[2]+"="+v[1]); // Save value to form, if set
}
else if (msg.match(/ScaleMedia/)) { // CHECK
v=msg.split("|"); // Chop into params
$("#scaleCheckBox-"+(v[1]-1)).css("color",(v[2].toLowerCase() == "on") ? "#009900" : "#ddd"); // Set check color
}
else if (msg.match(/ScaleTone/)) // TONE JS
if (msg.match(/play/)) app.con.ToneJS(v[1],v[2],v[3],v[4]); // Send to toneJS
else
trace(msg)
}
SaveToForm(data) // SAVE DATA TO FORM
{
let d={};
if (!app.reportLink) return; // Invalid link
let url=app.reportLink.split("/viewform?")[0]+"/formResponse"; // Extract post url
let nam=app.reportLink.match(/entry.[0-9]*=name/i)[0].split("="); // Extract name
let dat=app.reportLink.match(/entry.[0-9]*=data/i)[0].split("="); // Extract data
let sta=app.reportLink.match(/entry.[0-9]*=status/i)[0].split("="); // Extract status
let reqData={ url: url, data: d, type: "POST", dataType: "xml" }; // Request
d[nam[0]]=(app.namePrefix ? app.namePrefix+':' : "") + app.userName; // Use username from login
d[dat[0]]=data; // Set data
d[sta[0]]=app.doc.GetStatusArray().join(","); // Set status
if (sharedObject && sharedObject.token) reqData.headers={ authorization: "Bearer " + sharedObject.token }; // Add headers
else $.ajax(reqData); // May generate CORS error, but posts anyway
}
} // Messaging CLASS CLOSURE