From ad0ee69be3512325ede94738f23597086a141a3e Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Fri, 10 Feb 2012 01:55:30 -0800 Subject: file open and file new integrated again Signed-off-by: Ananya Sen --- js/io/document/document-controller.js | 57 +++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 10 deletions(-) (limited to 'js/io/document') diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js index e36181bf..6f67b57c 100755 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js @@ -78,8 +78,9 @@ var DocumentController = exports.DocumentController = Montage.create(Component, handleExecuteFileOpen: { value: function(event) { var pickerSettings = event._event.settings || {}; - pickerSettings.callback = this.openFileWithURI; - pickerSettings.callbackScope = this; + pickerSettings.callback = this.openFileWithURI.bind(this); + pickerSettings.pickerMode = "read"; + pickerSettings.inFileMode = true; this.application.ninja.filePickerController.showFilePicker(pickerSettings); } }, @@ -87,8 +88,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, handleExecuteNewFile: { value: function(event) { var newFileSettings = event._event.settings || {}; - newFileSettings.callback = this.createNewFile; - newFileSettings.callbackScope = this; + newFileSettings.callback = this.createNewFile.bind(this); this.application.ninja.newFileController.showNewFileDialog(newFileSettings); } }, @@ -123,9 +123,9 @@ var DocumentController = exports.DocumentController = Montage.create(Component, */ openNewFileCallback:{ value:function(doc){ - var response = doc || {"uri":"/Users/xhdq84/Documents/test.js", "success":true};//default just for testing + var response = doc || null;//default just for testing if(!!response && response.success && !!response.uri){ - this.application.ninja.ioMediator.fileOpen({"uri":response.uri}, this.openFileCallback.bind(this)); + this.application.ninja.ioMediator.fileOpen(response.uri, this.openFileCallback.bind(this)); } } }, @@ -137,8 +137,9 @@ var DocumentController = exports.DocumentController = Montage.create(Component, uri = uriArrayObj.uri[0]; } //console.log("URI is: ", uri); - - this.application.ninja.ioMediator.fileOpen({"uri":uri}, this.openFileCallback.bind(this)); + if(!!uri){ + this.application.ninja.ioMediator.fileOpen(uri, this.openFileCallback.bind(this)); + } } }, @@ -151,8 +152,44 @@ var DocumentController = exports.DocumentController = Montage.create(Component, * uri : file uri */ openFileCallback:{ - value:function(doc){ - this.openDocument(doc); + value:function(response){ + //Return Object Description +// Object.status (Always presents for handling) +// 204: File exists (Success) +// 404: File does not exists (Failure) +// 500: Unknown (Probably cloud API not running) +// +// (Below only present if succesfull 204) +// +// Object.content +// Object.extension +// Object.name +// Object.uri +// Object.creationDate +// Object.modifiedDate +// Object.readOnly +// Object.size + + var fileDetails = {}; + if(!!response && (response.status === 204)){ + /** + * fileDetails format: + * {"type": "js", "name": "test", "source": fileContent, "uri": uri} + */ + fileDetails.type = response.extension; + fileDetails.source = response.content; + fileDetails.name = response.name; + fileDetails.uri = response.uri; + + this.openDocument(fileDetails); + }else if(!!response && (response.status === 404)){ + alert("Unable to open file.\n [Error: File does not exist]"); + }else if(!!response && (response.status === 500)){ + alert("Unable to open file.\n Check if Ninja Local Cloud is running."); + }else{ + alert("Unable to open file."); + } + } }, -- cgit v1.2.3 From 1cd0642cd26f8ae5afadea4918110bdd9f7e89b3 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Fri, 10 Feb 2012 02:07:37 -0800 Subject: removed temporary test to open ninja without default document, since it is breaking other things. Signed-off-by: Ananya Sen --- js/io/document/document-controller.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/io/document') diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js index 16643a58..14231c64 100755 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js @@ -68,13 +68,13 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.eventManager.addEventListener("recordStyleChanged", this, false); // Temporary testing opening a new file after Ninja has loaded - this.eventManager.addEventListener("executeNewProject", this, false); + //this.eventManager.addEventListener("executeNewProject", this, false); } }, handleAppLoaded: { value: function() { - //this.openDocument({"type": "html"}); + this.openDocument({"type": "html"}); } }, -- cgit v1.2.3 From 8c40940f030adb74f534c3c5ad8d845e41f09b30 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Fri, 10 Feb 2012 11:04:42 -0800 Subject: hide iframeContainer if we want to open code view as the first document after ninja launches Signed-off-by: Ananya Sen --- js/io/document/document-controller.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'js/io/document') diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js index 14231c64..c2a2dab6 100755 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js @@ -68,13 +68,13 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.eventManager.addEventListener("recordStyleChanged", this, false); // Temporary testing opening a new file after Ninja has loaded - //this.eventManager.addEventListener("executeNewProject", this, false); + this.eventManager.addEventListener("executeNewProject", this, false); } }, handleAppLoaded: { value: function() { - this.openDocument({"type": "html"}); + //this.openDocument({"type": "html"}); } }, @@ -402,7 +402,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this.application.ninja.stage.restoreScroll(); this.application.ninja.stage.hideCanvas(false); this.application.ninja.stage.stageView.showRulers(); - } + }else{ + //hide the iframe when switching to code view + document.getElementById("iframeContainer").style.display="none"; + } } } }, -- cgit v1.2.3