Permalink
Browse files

Merge branch 'pre-amd'

Minimal changes to use AMD, start up without error, and show all
of user interface elements.  Consent form works.
There are a large number of requires in index.html which
might not all be necessary.
No mouse events are handled correctly, however.
  • Loading branch information...
2 parents a977495 + 6598646 commit 7197bc8f89fdd00ed4283b1c1fba2c8ea766d922 @bvds committed Jan 1, 2014
View
@@ -4,14 +4,12 @@
-->
<script type="text/javascript">
- require(["andes/api"],function(api){
- consentResponse=function(reply){
- console.log("Dialog button response: ",reply);
- api.recordAction({type:"set-preference", name: "informed-consent",
- value: reply + ":default-consent-asu"});
- dijit.byId("consentDialog").hide();
- };
- });
+ consentResponse=function(reply){
+ console.log("Dialog button response: ",reply);
+ window.andes.api.recordAction({type:"set-preference", name: "informed-consent",
+ value: reply + ":default-consent-asu"});
+ dijit.byId("consentDialog").hide();
+ };
</script>
<h2 class="tall">Consent Form</h2>
View
@@ -1,11 +1,10 @@
define([
- "andes/startup",
"dojox/drawing/util/oo",
"dojo/on",
"dojo/_base/array"
-],function(andes,oo,on,array){
+],function(oo,on,array){
-andes.Combo = oo.declare(
+window.andes.Combo = oo.declare(
// summary:
// A special object used to combine an Andes Stencil
// (Vector, Rect, Ellipse)
@@ -40,7 +39,7 @@ andes.Combo = oo.declare(
var s = this.statement;
var m = this.master;
- console.warn("combo statement:", this.statement);
+ console.warn("combo statement:", this.statement);
this.statement.connectMult([
[this.statement, "onChangeData", this, "textPositionEdit"],
@@ -95,7 +94,7 @@ andes.Combo = oo.declare(
// split in two parts. First is textEdit which triggers
// onChangeData for final text changes. TextPositionEdit handles
// position changes.
- var label = andes.variablename.parse(value);
+ var label = window.andes.variablename.parse(value);
var ol = this.master.getLabel();
if(label){
console.log("textEdit: LABEL=", label," text=",value);
@@ -141,7 +140,7 @@ andes.Combo = oo.declare(
},
onDelete: function(value){ // value or 'this' ?
- console.log("combo delete ", value);
+ console.log("combo delete ", value);
// summary:
// Stub - fires when master or an item is deleted
// (which makes this _Connection worthless and it
@@ -208,7 +207,7 @@ andes.Combo = oo.declare(
}
);
-andes.buttonCombo = dojox.drawing.util.oo.declare(
+window.andes.buttonCombo = oo.declare(
// summary:
// A special object used to combine a Button and a Statement.
//
@@ -1,19 +1,18 @@
// Pre-AMD version had a function wrapper.
+// pre-AMD version had no requires.
define([
- "andes/startup",
- "andes/api"
-],function(andes,api){
+],function(){
// Summary:
// User preferences that can be saved are registered here.
// When preferences are updated this saves them to the server
// via the api, while the opposite direction allows the
// server to update values that register here.
// Example api:
- // api.recordAction({type:"set-preference", name: "display-timer", value: true});
- _prefs = {};
+ // andes.api.recordAction({type:"set-preference", name: "display-timer", value: true});
+ var _prefs = {};
- return {
+ window.andes.preferenceRegistry = {
// Prefs are name value pairs with scope so that the server
// can update them.
registerPref: function(/*String*/pref, /*function*/setter, scope){
@@ -31,7 +30,7 @@ define([
}else{
if(_prefs[pref].value != value){
// This is user changed
- api.recordAction({type:"set-preference", name:pref, value:value });
+ window.andes.api.recordAction({type:"set-preference", name:pref, value:value });
}
return true;
}
View
@@ -1,11 +1,10 @@
define([
'dojo/_base/declare',
- 'andes/startup',
'dojo/on',
"dojo/dom",
- "andes/api",
"dojo/domReady!" // Needed to locate "conEdit"
-], function(declare,andes,on,dom,api){
+ // pre-AMD version had no requires
+], function(declare,on,dom){
return declare(null,{
// Summary:
@@ -40,7 +39,7 @@ define([
console.log("andes.WordTip.textMonitor this=",this);
var tx = dojo.trim(this.conEdit.innerHTML);//this.statement.cleanText(conEdit.innerHTML);
tx = this.removeBreaks(tx);
- var symbol = andes.variablename.parse(tx);
+ var symbol = window.andes.variablename.parse(tx);
console.log("---Text for word-suggest----> ", tx,symbol);
this.sendToServer(tx,symbol);
};
@@ -50,7 +49,7 @@ define([
var cn = on(document,"mouseup",this, function(evt){
cn.remove();
dijit.hideTooltip(this.conEdit);
- });
+ });
},
removeBreaks: function(txt){
@@ -63,7 +62,7 @@ define([
sendToServer: function(text,symbol){
console.assert(this.theDrawing,"WordTip needs drawing initialized");
var current;
- var andesTypes = andes.convert.andesTypes;
+ var andesTypes = window.andes.convert.andesTypes;
// The most recent stencil will either be the last selected or the last
// tool. Thus find out the id, if it matches the last selected that's
@@ -88,7 +87,7 @@ define([
};
// console.log("current: ",current);
if(current && this.hasTip[current]){
- api.suggestWord({type: current, text: text, symbol:symbol});
+ window.andes.api.suggestWord({type: current, text: text, symbol:symbol});
}
},
View
@@ -1,11 +1,10 @@
define([
- "dojo",
- "andes/startup",
+ // pre-AMD version requires:
+ "andes/timer",
"andes/rpc",
- "andes/messages",
- "andes/help",
- "andes/error"
-],function(dojo,andes,rpc,messages,help){ // Pre-AMD version had a function wrapper.
+ "andes/error",
+ "andes/messages"
+],function(timer){ // Pre-AMD version had a function wrapper.
var startTime = null,
requestInFlight = false,
@@ -15,6 +14,18 @@ define([
var MAX_RETRIES = 5,
RETRY_TIMEOUT = 2000; // milliseconds
+ // AOP-style function replacement that performs before-advice
+ // to add to the headers on all XHR requests. See dojox/rpc/Client.js
+ (function(){
+ console.info("api set headers", window.andes.sessionId);
+ window.andes._originalXhr = dojo.xhr;
+ dojo.xhr = function(method,args){
+ var headers = args.headers = args.headers || {};
+ headers["Client-Id"] = window.andes.sessionId;
+ return window.andes._originalXhr.apply(dojo,arguments);
+ };
+ })();
+
function prepRequest(req){
// add common elements to our requests
var tm = ((new Date()).getTime() - (startTime || (new Date()).getTime()))/1000.0;
@@ -26,14 +37,14 @@ define([
var request = prepRequest(req.params);
requestInFlight = true;
req.startTime = (new Date()).getTime();
- rpc[req.method](request).addCallbacks(
+ window.andes.rpc[req.method](request).addCallbacks(
function(result){
requestInFlight = false;
var dt=(new Date()).getTime()-req.startTime;
// log any server latency larger than cutoff in ms.
// Should match Andes server timeout.
if(dt>15000){
- andes.errorLog({
+ window.andes.errorLog({
title: "latency",
message: dt + " ms for " + req.method
});
@@ -50,16 +61,16 @@ define([
// the RPC action to open-problemo
//
req.dfd.errback(error);
- var mo = messages.server();
+ var mo = window.andes.messages.server();
var msg = "<p>"+mo.message+"</p><div class='errMsg'>" + error.name + ": " + error.message;
if(error._rpcErrorObject.code){
msg += "\n(code " + error._rpcErrorObject.code + ")";
}
msg += "</div><div class='action'>"+mo.action+"</div>";
- andes.error({
+ window.andes.error({
title: mo.title,
message: msg,
- errorType: andes.error.OK
+ errorType: window.andes.error.OK
});
}else{
//
@@ -68,18 +79,18 @@ define([
// Can be generated by changing the SMD URL
//
if(++tries <= MAX_RETRIES){
- setTimeout(function(){
+ window.setTimeout(function(){
sendRequest(req);
}, RETRY_TIMEOUT);
}else{
req.dfd.errback(error);
console.error(error);
- var mo = messages.connection(MAX_RETRIES);
- console.dir(mo);
- andes.error({
+ var mo = window.andes.messages.connection(MAX_RETRIES);
+ console.dir(mo);
+ window.andes.error({
title: mo.title,
message: mo.message+"<div class='action'>"+mo.action+"</div>",
- dialogType: andes.error.OK
+ dialogType: window.andes.error.OK
});
}
}
@@ -109,28 +120,17 @@ define([
return dfd;
}
- return {
-
- // AOP-style function replacement that performs before-advice
- // to add to the headers on all XHR requests. See dojox/rpc/Client.js
- setHeaders: function(){
- console.info("api set headers", andes.sessionId);
- andes._originalXhr = dojo.xhr;
- dojo.xhr = function(method,args){
- var headers = args.headers = args.headers || {};
- headers["Client-Id"] = andes.sessionId;
- return andes._originalXhr.apply(dojo,arguments);
- };
- },
-
+ window.andes.api = {
open: function(params){
//console.info("andes.api.open", params);
+ startTime = (new Date()).getTime();
+ window.andes.timer = new timer(startTime);
var dfd = queueRequest("open-problem", params);
dfd.addCallback(function(result){
// look for help embedded in the returned result, so we can
// queue it up in case the user opens the Tutor pane
- help.processStep(result);
+ window.andes.help.processStep(result);
});
return dfd;
},
@@ -141,7 +141,7 @@ define([
dfd.addCallback(function(result){
// look for help embedded in the returned result, so we can
// queue it up in case the user opens the Tutor pane
- help.processStep(result);
+ window.andes.help.processStep(result);
});
return dfd;
},
@@ -155,7 +155,7 @@ define([
//console.info("andes.api.suggestWord", params);
var dfd = queueRequest("suggest-word", params);
dfd.addCallback(function(result){
- andes.WordTip.processResults(result);
+ window.andes.WordTip.processResults(result);
});
return dfd;
},
Oops, something went wrong.

0 comments on commit 7197bc8

Please sign in to comment.