|
From: <tre...@us...> - 2007-09-02 15:57:49
|
Revision: 329
http://ogoglio.svn.sourceforge.net/ogoglio/?rev=329&view=rev
Author: trevorolio
Date: 2007-09-02 08:13:20 -0700 (Sun, 02 Sep 2007)
Log Message:
-----------
Fixed up the whiteboard to use the context menus and info panels.
Now it's very easy to update the whiteboard text, though we don't do images or save slide shows (yet?).
Modified Paths:
--------------
maven/trunk/ogoglio-server/src/main/resources/populate/template-28/WhiteBoard.js
Modified: maven/trunk/ogoglio-server/src/main/resources/populate/template-28/WhiteBoard.js
===================================================================
--- maven/trunk/ogoglio-server/src/main/resources/populate/template-28/WhiteBoard.js 2007-09-02 00:48:15 UTC (rev 328)
+++ maven/trunk/ogoglio-server/src/main/resources/populate/template-28/WhiteBoard.js 2007-09-02 15:13:20 UTC (rev 329)
@@ -1,16 +1,125 @@
var thingID = -1;
var pageID = -1;
+var htmlPrefix = '<html><body style="padding: 10px;">';
+var htmlSuffix = '</body></html>';
-var defaultPicture = "http://trevor.smith.name/T3SWeb.jpg";
+var defaultText = "<center><h1>Whiteboard</h1></center>";
+var textSettingKey = null;
function construct(id){
thingID = id;
+ textSettingKey = "thing." + thingID + ".whiteboard.text";
+
+ pageID = space.createTextPage(thingID, 4, 2, htmlPrefix + formatBoardText(getTextSetting()) + htmlSuffix, 0, 2, 0.1, 0, math.PI, 0);
+}
- pageID = space.createTextPage(thingID, 4, 2, " ", 0, 2, 0.1, 0, math.PI, 0);
+function formatBoardText(text){
+ var result = '';
+ for(var i=0; i < text.length - 2; i++){
+ if((text[i] == '\n' || text[i] == '\r') && (text[i + 1] == '\n' || text[i + 1] == '\r')){
+ result += '<br>';
+ } else {
+ result += text[i];
+ }
+ }
+ return result;
+}
- setImage(defaultPicture);
+function getTextSetting(){
+ var setting = space.getSetting(textSettingKey);
+ if(setting == null || setting.length == 0){
+ return defaultText;
+ }
+ return setting;
}
+function setTextSetting(text){
+ if(typeof text == "undefined" || text == null || text.length == 0){
+ space.removeSetting(textSettingKey);
+ } else {
+ space.putSetting(textSettingKey, text);
+ }
+}
+
+// this "object" defines the context menu items
+function Action(theDisplayName, theNonce){
+ this.displayName = theDisplayName;
+ this.nonce = theNonce;
+}
+
+var actions = new Array();
+actions[actions.length] = new Action("Set...", "set_text");
+actions[actions.length] = new Action("Clear", "clear"); //clear must always be last in this array
+
+function onContextClick(username, shapeName){
+ var items = new Array();
+ for(var i=0; i < actions.length; i++){
+ items[items.length] = new ContextMenuInfo(actions[i].displayName, true, actions[i].nonce);
+ }
+ return items;
+}
+
+function onContextMenuItemChosen(username, nonce){
+ if(actions[actions.length - 1].nonce == nonce){
+ space.setTextPageContent(thingID, pageID, htmlPrefix + '' + htmlSuffix);
+ space.removeSetting(textSettingKey);
+ return;
+ }
+ space.showInfoPanel(thingID, username, nonce);
+}
+
+function getParameterValue(paramName, parameterNames, parameterValues){
+ for(var i=0; i < parameterNames.length; i++){
+ if(parameterNames[i] == paramName){
+ return parameterValues[i] + ""; //this forces the values to be pure javascript strings instead of Rhino java strings (annoying)
+ }
+ }
+ return null;
+}
+
+function createServiceHTML(message){
+ var html = htmlPrefix;
+ if(message != null){
+ html += '<h3>' + message + '</h3>';
+ }
+
+ html += '<form action="service?nonce=set_text" method="post">';
+ html += '<textarea rows="5" style="width: 100%;" name="new_text"></textarea>';
+ html += '<input type="submit" value="update whiteboard" />';
+ html += '</form>';
+ html += '<hr>';
+ html += '<form action="service?nonce=clear" method="post">';
+ html += '<input type="submit" value="clear whiteboard" />';
+ html += '</form>';
+
+ html += htmlSuffix;
+ return html;
+}
+
+function onService(method, parameterNames, parameterValues){
+ var nonce = getParameterValue("nonce", parameterNames, parameterValues);
+ if(parameterNames.length == 0 || nonce == null){
+ return new HTTPResponse(200, createServiceHTML(null), "text/html");
+ }
+
+ if(method == "GET"){
+ return new HTTPResponse(200, createServiceHTML(null), 'text/html');
+ } else if(method == "POST") {
+ if(nonce == actions[actions.length - 1].nonce){
+ space.setTextPageContent(thingID, pageID, '');
+ setTextSetting(null);
+ return new HTTPResponse(200, createServiceHTML('Cleared'), 'text/html');
+ }
+ var newText = getParameterValue('new_text', parameterNames, parameterValues);
+ if(newText != null){
+ space.setTextPageContent(thingID, pageID, htmlPrefix + formatBoardText(newText) + htmlSuffix);
+ setTextSetting(newText);
+ return new HTTPResponse(200, createServiceHTML('Updated'), 'text/html');
+ }
+ }
+ return new HTTPResponse(200, createServiceHTML(null), 'text/html');
+}
+
function setImage(url){
var imageReq = new HTTPRequest(thingID, "GET", url, handleImageResponse);
imageReq.setDestinationPage(space, thingID, pageID);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|