From 8f249e63bb07f978322fc1fa68b44ca70062dda5 Mon Sep 17 00:00:00 2001 From: jmoenig Date: Thu, 4 Apr 2013 17:47:26 +0200 Subject: [PATCH] Loading shared cloud projects in presentation mode and exporting URLs for shared projects --- cloud.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++- gui.js | 24 ++++++++++++++++++---- history.txt | 6 +++++- 3 files changed, 82 insertions(+), 6 deletions(-) diff --git a/cloud.js b/cloud.js index 86964b68..56ac6fef 100644 --- a/cloud.js +++ b/cloud.js @@ -29,7 +29,7 @@ /*global modules, IDE_Morph, SnapSerializer, hex_sha512, alert, nop*/ -modules.cloud = '2013-April-02'; +modules.cloud = '2013-April-04'; // Global stuff @@ -37,6 +37,8 @@ var Cloud; var SnapCloud = new Cloud( 'https://snapcloud.miosoft.com/miocon/app/login?_app=SnapCloud' + // '192.168.2.108:8087/miocon/app/login?_app=SnapCloud' + // 'localhost/miocon/app/login?_app=SnapCloud' ); // Cloud ///////////////////////////////////////////////////////////// @@ -118,6 +120,60 @@ Cloud.prototype.signup = function ( } }; +Cloud.prototype.getPublicProject = function ( + id, + callBack, + errorCall +) { + // id is Username=username&projectName=projectname, + // where the values are url-component encoded + // callBack is a single argument function, errorCall take two args + var request = new XMLHttpRequest(), + myself = this; + try { + request.open( + "GET", + (this.hasProtocol() ? '' : 'http://') + + this.url + 'Public' + + '&' + + id, + true + ); + request.setRequestHeader( + "Content-Type", + "application/x-www-form-urlencoded" + ); + request.withCredentials = true; + request.onreadystatechange = function () { + if (request.readyState === 4) { + if (request.responseText) { + if (request.responseText.indexOf('ERROR') === 0) { + errorCall.call( + this, + request.responseText + ); + } else { + callBack.call( + null, + request.responseText, + 'Published Project' + ); + } + } else { + errorCall.call( + null, + myself.url + 'Public', + 'could not connect to:' + ); + } + } + }; + request.send(null); + } catch (err) { + errorCall.call(this, err.toString(), 'Snap!Cloud'); + } +}; + Cloud.prototype.connect = function ( callBack, errorCall diff --git a/gui.js b/gui.js index d051dc19..6e180608 100644 --- a/gui.js +++ b/gui.js @@ -68,7 +68,7 @@ sb, CommentMorph, CommandBlockMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.gui = '2013-April-02'; +modules.gui = '2013-April-04'; // Declarations @@ -150,7 +150,7 @@ IDE_Morph.prototype.init = function (isAutoFill) { }; IDE_Morph.prototype.openIn = function (world) { - var hash, usr, motd; + var hash, usr, motd, myself = this; this.buildPanes(); world.add(this); @@ -245,6 +245,15 @@ IDE_Morph.prototype.openIn = function (world) { } this.toggleAppMode(true); this.runScripts(); + } else if (location.hash.substr(0, 9) === '#present:') { + SnapCloud.getPublicProject( + location.hash.substr(9), + function (projectData) { + myself.rawOpenProjectString(projectData); + myself.toggleAppMode(true); + }, + this.cloudError() + ); } else if (location.hash.substr(0, 6) === '#lang:') { this.setLanguage(location.hash.substr(6)); this.newProject(); @@ -3831,7 +3840,8 @@ ProjectDialogMorph.prototype.openSelectedCloudProject = function () { }; ProjectDialogMorph.prototype.rawOpenSelectedCloudProject = function () { - var myself = this; + var myself = this, + proj = this.listField.selected; SnapCloud.reconnect( function () { SnapCloud.callService( @@ -3840,9 +3850,15 @@ ProjectDialogMorph.prototype.rawOpenSelectedCloudProject = function () { SnapCloud.disconnect(); myself.ide.source = 'cloud'; myself.ide.droppedText(response[0].SourceCode); + if (proj.Public === 'true') { + location.hash = '#present:Username=' + + encodeURIComponent(SnapCloud.username) + + '&ProjectName=' + + encodeURIComponent(proj.ProjectName); + } }, myself.ide.cloudError(), - [myself.listField.selected.ProjectName] + [proj.ProjectName] ); }, myself.ide.cloudError() diff --git a/history.txt b/history.txt index 9929d4cd..e69d7011 100755 --- a/history.txt +++ b/history.txt @@ -1578,4 +1578,8 @@ ______ 130403 ------ * YPR converter fix: No more text area in upper left corner of the Snap! IDE -* Blocks, BYOB, Store: PrototypeHatBlocks in the BlockEditor accept anchored comments \ No newline at end of file +* Blocks, BYOB, Store: PrototypeHatBlocks in the BlockEditor accept anchored comments + +130404 +------ +* loading shared projects in presentation mode, exporting URL for shared projects