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 ++++++++++++++++++---- js/io/templates/descriptor.json | 34 ++++++------- .../new-file-options-navigator.js | 8 +-- .../new-file-workflow-controller.js | 2 +- 4 files changed, 69 insertions(+), 32 deletions(-) (limited to 'js/io') 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."); + } + } }, diff --git a/js/io/templates/descriptor.json b/js/io/templates/descriptor.json index 20870934..acc03979 100644 --- a/js/io/templates/descriptor.json +++ b/js/io/templates/descriptor.json @@ -6,60 +6,60 @@ "name":"Blank File", "uri":"/", "type":"directory", - "children":["/js/io/templates/files/html.txt", "/js/io/templates/files/files/js.txt", "/js/io/templates/files/css.txt", "/js/io/templates/files/json.txt", "/js/io/templates/files/php.txt", "/js/io/templates/files/pl.txt", "/js/io/templates/files/py.txt", "/js/io/templates/files/rb.txt"] + "children":["js/io/templates/files/html.txt", "js/io/templates/files/js.txt", "js/io/templates/files/css.txt", "js/io/templates/files/json.txt", "js/io/templates/files/php.txt", "js/io/templates/files/pl.txt", "js/io/templates/files/py.txt", "js/io/templates/files/rb.txt"] }, - "/js/io/templates/files/html.txt":{ + "js/io/templates/files/html.txt":{ "name":"HTML", - "uri":"/js/io/templates/files/html.txt", + "uri":"js/io/templates/files/html.txt", "type":"file", "fileExtension":".html", "children":["defaultTemplate"] }, - "/js/io/templates/files/files/js.txt":{ + "js/io/templates/files/js.txt":{ "name":"JavaScript", - "uri":"/js/io/templates/files/files/js.txt", + "uri":"js/io/templates/files/js.txt", "type":"file", "fileExtension":".js", "children":["defaultTemplate"] }, - "/js/io/templates/files/css.txt":{ + "js/io/templates/files/css.txt":{ "name":"Cascading Style Sheets", - "uri":"/js/io/templates/files/css.txt", + "uri":"js/io/templates/files/css.txt", "type":"file", "fileExtension":".css", "children":["defaultTemplate"] }, - "/js/io/templates/files/json.txt":{ + "js/io/templates/files/json.txt":{ "name":"JSON", - "uri":"/js/io/templates/files/json.txt", + "uri":"js/io/templates/files/json.txt", "type":"file", "fileExtension":".json", "children":["defaultTemplate"] }, - "/js/io/templates/files/php.txt":{ + "js/io/templates/files/php.txt":{ "name":"PHP", - "uri":"/js/io/templates/files/php.txt", + "uri":"js/io/templates/files/php.txt", "type":"file", "fileExtension":".php", "children":["defaultTemplate"] }, - "/js/io/templates/files/pl.txt":{ + "js/io/templates/files/pl.txt":{ "name":"Perl", - "uri":"/js/io/templates/files/pl.txt", + "uri":"js/io/templates/files/pl.txt", "type":"file", "fileExtension":".pl", "children":["defaultTemplate"] }, - "/js/io/templates/files/py.txt":{ + "js/io/templates/files/py.txt":{ "name":"Python", - "uri":"/js/io/templates/files/py.txt", + "uri":"js/io/templates/files/py.txt", "type":"file", "fileExtension":".py", "children":["defaultTemplate"] }, - "/js/io/templates/files/rb.txt":{ + "js/io/templates/files/rb.txt":{ "name":"Ruby", - "uri":"/js/io/templates/files/rb.txt", + "uri":"js/io/templates/files/rb.txt", "type":"file", "fileExtension":".rb", "children":["defaultTemplate"] diff --git a/js/io/ui/new-file-dialog/new-file-options-navigator.reel/new-file-options-navigator.js b/js/io/ui/new-file-dialog/new-file-options-navigator.reel/new-file-options-navigator.js index bcb9d123..f514b81a 100644 --- a/js/io/ui/new-file-dialog/new-file-options-navigator.reel/new-file-options-navigator.js +++ b/js/io/ui/new-file-dialog/new-file-options-navigator.reel/new-file-options-navigator.js @@ -230,10 +230,10 @@ var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(C ){ this.error.innerHTML=""; //console.log("$$$ new file selections: \n" + selectionlog); - if(!!this.newFileModel.callback && !!this.newFileModel.callbackScope){//inform document-controller if save successful - this.newFileModel.callback.call(this.newFileModel.callbackScope, {"fileTemplateUri":selectedProjectTypeID, - "newFilePath":newFilePath, - "fileExtension":fileExtension});//document-controller api + if(!!this.newFileModel.callback){//inform document-controller if save successful + this.newFileModel.callback({"fileTemplateUri":selectedProjectTypeID, + "newFilePath":newFilePath, + "fileExtension":fileExtension});//document-controller api }else{ //send selection event var newFileSelectionEvent = document.createEvent("Events"); diff --git a/js/io/ui/new-file-dialog/new-file-workflow-controller.js b/js/io/ui/new-file-dialog/new-file-workflow-controller.js index 6cf2a2ae..7b7f4572 100755 --- a/js/io/ui/new-file-dialog/new-file-workflow-controller.js +++ b/js/io/ui/new-file-dialog/new-file-workflow-controller.js @@ -44,7 +44,7 @@ var NewFileWorkflowController = exports.NewFileWorkflowController = Montage.cre this.model.projectTypeData = this.loadDescriptor("js/io/templates/descriptor.json"); //get default project type - this.model.defaultProjectType = "/js/io/templates/files/html.txt"; + this.model.defaultProjectType = "js/io/templates/files/html.txt"; this.model.callback = data.callback || null; this.model.callbackScope = data.callbackScope || null; -- 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') 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') 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