From 84fd877fa483d986a9651b7d5555455cce978cae Mon Sep 17 00:00:00 2001 From: jmoenig Date: Tue, 2 Apr 2013 14:01:42 +0200 Subject: [PATCH] Project Sharing / Unsharing Support (frontend) Support for publishing and un-publishing projects in the cloud (not yet live in the current production version of the cloud backend) --- cloud.js | 28 +++++++++++--- gui.js | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++-- history.txt | 10 ++++- locale.js | Bin 13844 -> 13844 bytes 4 files changed, 134 insertions(+), 10 deletions(-) diff --git a/cloud.js b/cloud.js index ebe17d7f..86964b68 100644 --- a/cloud.js +++ b/cloud.js @@ -29,7 +29,7 @@ /*global modules, IDE_Morph, SnapSerializer, hex_sha512, alert, nop*/ -modules.cloud = '2013-March-22'; +modules.cloud = '2013-April-02'; // Global stuff @@ -82,6 +82,10 @@ Cloud.prototype.signup = function ( + email, true ); + request.setRequestHeader( + "Content-Type", + "application/x-www-form-urlencoded" + ); request.withCredentials = true; request.onreadystatechange = function () { if (request.readyState === 4) { @@ -127,6 +131,10 @@ Cloud.prototype.connect = function ( (this.hasProtocol() ? '' : 'http://') + this.url, true ); + request.setRequestHeader( + "Content-Type", + "application/x-www-form-urlencoded" + ); request.withCredentials = true; request.onreadystatechange = function () { if (request.readyState === 4) { @@ -318,7 +326,10 @@ Cloud.prototype.callURL = function (url, callBack, errorCall) { try { request.open('GET', url, true); request.withCredentials = true; - request.setRequestHeader('Content-Type', 'text/plain'); + request.setRequestHeader( + "Content-Type", + "application/x-www-form-urlencoded" + ); request.setRequestHeader('MioCracker', this.session); request.onreadystatechange = function () { if (request.readyState === 4) { @@ -355,11 +366,15 @@ Cloud.prototype.callService = function ( postDict; if (!this.session) { - errorCall.call('You are not connected', 'Cloud'); + errorCall.call(null, 'You are not connected', 'Cloud'); return; } if (!service) { - errorCall.call('service ' + serviceName + ' is not available', 'API'); + errorCall.call( + null, + 'service ' + serviceName + ' is not available', + 'API' + ); return; } if (args && args.length > 0) { @@ -371,7 +386,10 @@ Cloud.prototype.callService = function ( try { request.open(service.method, service.url, true); request.withCredentials = true; - request.setRequestHeader('Content-Type', 'text/plain'); + request.setRequestHeader( + "Content-Type", + "application/x-www-form-urlencoded" + ); request.setRequestHeader('MioCracker', this.session); request.onreadystatechange = function () { if (request.readyState === 4) { diff --git a/gui.js b/gui.js index b5fcd2bb..5642bde2 100644 --- a/gui.js +++ b/gui.js @@ -68,7 +68,7 @@ sb, CommentMorph, CommandBlockMorph*/ // Global stuff //////////////////////////////////////////////////////// -modules.gui = '2013-March-22'; +modules.gui = '2013-April-02'; // Declarations @@ -3325,6 +3325,9 @@ ProjectDialogMorph.prototype.init = function (ide, task) { this.preview = null; this.notesText = null; this.notesField = null; + this.deleteButton = null; + this.shareButton = null; + this.unshareButton = null; // initialize inherited properties: ProjectDialogMorph.uber.init.call( @@ -3458,7 +3461,13 @@ ProjectDialogMorph.prototype.buildContents = function () { if (this.task === 'open') { this.addButton('openProject', 'Open'); - this.addButton('deleteProject', 'Delete'); + + this.shareButton = this.addButton('shareProject', 'Share'); + this.unshareButton = this.addButton('unshareProject', 'Unshare'); + this.shareButton.hide(); + this.unshareButton.hide(); + + this.deleteButton = this.addButton('deleteProject', 'Delete'); this.action = 'openProject'; } else { // 'save' this.addButton('saveProject', 'Save'); @@ -3684,6 +3693,24 @@ ProjectDialogMorph.prototype.setSource = function (source) { }; } this.body.add(this.listField); + + if (this.task === 'open') { + if (this.source === 'cloud') { + this.shareButton.show(); + this.unshareButton.hide(); + this.deleteButton.show(); + } else { + this.shareButton.hide(); + this.unshareButton.hide(); + if (this.source === 'local') { + this.deleteButton.show(); + } else { // examples + this.deleteButton.hide(); + } + } + } + this.buttons.fixLayout(); + this.fixLayout(); if (this.task === 'open') { this.clearDetails(); @@ -3747,6 +3774,15 @@ ProjectDialogMorph.prototype.installCloudProjectList = function (pl) { myself.preview.texture = item.Thumbnail || null; myself.preview.cachedTexture = null; myself.preview.drawNew(); + if (item.Public === 'true') { + myself.shareButton.hide(); + myself.unshareButton.show(); + } else { + myself.unshareButton.hide(); + myself.shareButton.show(); + } + myself.buttons.fixLayout(); + myself.fixLayout(); } myself.edit(); }; @@ -3908,7 +3944,7 @@ ProjectDialogMorph.prototype.deleteProject = function () { ); // refresh list }, myself.ide.cloudError(), - [myself.listField.selected.ProjectName] + [proj.ProjectName] ); }, myself.ide.cloudError() @@ -3933,6 +3969,70 @@ ProjectDialogMorph.prototype.deleteProject = function () { } }; +ProjectDialogMorph.prototype.shareProject = function () { + var myself = this, + proj = this.listField.selected; + + if (proj) { + this.ide.confirm( + localize( + 'Are you sure you want to publish' + ) + '\n"' + proj.ProjectName + '"?', + 'Share Project', + function () { + SnapCloud.reconnect( + function () { + SnapCloud.callService( + 'publishProject', + function () { + SnapCloud.disconnect(); + proj.Public = 'true'; + myself.listField.select(proj); + myself.ide.showMessage('shared.', 2); + }, + myself.ide.cloudError(), + [proj.ProjectName] + ); + }, + myself.ide.cloudError() + ); + } + ); + } +}; + +ProjectDialogMorph.prototype.unshareProject = function () { + var myself = this, + proj = this.listField.selected; + + if (proj) { + this.ide.confirm( + localize( + 'Are you sure you want to unpublish' + ) + '\n"' + proj.ProjectName + '"?', + 'Unshare Project', + function () { + SnapCloud.reconnect( + function () { + SnapCloud.callService( + 'unpublishProject', + function () { + SnapCloud.disconnect(); + proj.Public = 'false'; + myself.listField.select(proj); + myself.ide.showMessage('unshared.', 2); + }, + myself.ide.cloudError(), + [proj.ProjectName] + ); + }, + myself.ide.cloudError() + ); + } + ); + } +}; + ProjectDialogMorph.prototype.edit = function () { if (this.nameField) { this.nameField.edit(); diff --git a/history.txt b/history.txt index eab382e3..b7f4b254 100755 --- a/history.txt +++ b/history.txt @@ -1360,7 +1360,7 @@ ______ * Blocks: Drawn symbols for TURN RIGHT / LEFT * continuations tweaks * revert of "returning 'undefined' to parent frame fix" (121204), breaks call/cc -* ScriptPane cleanUp teak for attached comments +* ScriptPane cleanUp tweak for attached comments 130111 ------ @@ -1564,4 +1564,10 @@ ______ ------ * Spanish translation! Yay, thanks, Victor Muratalla!! * Objects: Boolean value block representations are now translated, thanks, Victor, for the report -* Simplified Chinese translation update, thanks 邓江华 !! \ No newline at end of file +* Simplified Chinese translation update, thanks 邓江华 !! + +130402 +------ +* Japanese translations update, thanks, Kazuhiro Abe! +* Content-type support for Cloud backend +* sharing / unsharing projects support and GUI \ No newline at end of file diff --git a/locale.js b/locale.js index 40d4871bc92f7869c5bbb6124b7f8694b8ec353f..470b23368cd603d537e7af28c450b48cc5e38d9d 100644 GIT binary patch delta 28 jcmbP|GbLw39VfpdLjgk(LncEGgD!&sgVE+*&UPIDeQyWK delta 28 jcmbP|GbLw39VfppLn1>FLo!1KgD!&+gX!j8&UPIDeD4Rs