From 45cfffd9261ab1aa714554c584f0d0d8fe627c91 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Fri, 3 Feb 2012 18:04:26 -0800 Subject: allow to open html file in design view, integrated file open with io mediator Signed-off-by: Ananya Sen --- js/io/document/document-controller.js | 42 ++++++++++++++--------------------- 1 file changed, 17 insertions(+), 25 deletions(-) (limited to 'js/io/document/document-controller.js') diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js index b900dee4..ca6b4533 100755 --- a/js/io/document/document-controller.js +++ b/js/io/document/document-controller.js @@ -105,7 +105,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value:function(newFileObj){ //console.log(newFileObj);//contains the template uri and the new file uri if(!newFileObj) return; - this.application.ninja.ioMediator.fileNew(newFileObj.newFilePath, newFileObj.fileTemplateUri, this.openNewFile, this); + this.application.ninja.ioMediator.fileNew(newFileObj.newFilePath, newFileObj.fileTemplateUri, {"operation":this.openNewFileCallback, "thisScope":this}); if((newFileObj.fileExtension !== ".html") && (newFileObj.fileExtension !== ".htm")){//open code view @@ -123,7 +123,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, * source : file content * uri : file uri */ - openNewFile:{ + openNewFileCallback:{ value:function(doc){ if(!doc){ doc = {"type": "js", "name": "filename", "source": "test file content", "uri": "/fs/fsd/"} ; @@ -140,20 +140,21 @@ var DocumentController = exports.DocumentController = Montage.create(Component, } //console.log("URI is: ", uri); - if(!!uri){ - response = this.application.ninja.coreIoApi.openFile({"uri":uri}); - if((response.success === true) && ((response.status === 200) || (response.status === 304))){ - fileContent = response.content; - } - - //console.log("$$$ "+uri+"\n content = \n\n\n"+ fileContent+"\n\n\n"); - filename = this.getFileNameFromPath(uri); - if(uri.indexOf('.') != -1){ - fileType = uri.substr(uri.lastIndexOf('.') + 1); - } - this.openDocument({"type": ""+fileType, "name": ""+filename, "source": fileContent, "uri": uri}); - } + this.application.ninja.ioMediator.fileOpen({"uri":uri}, {"operation":this.openFileCallback, "thisScope":this}); + } + }, + /** + * Public method + * doc contains: + * type : file type, like js, css, etc + * name : file name + * source : file content + * uri : file uri + */ + openFileCallback:{ + value:function(doc){ + this.openDocument(doc); } }, @@ -460,14 +461,5 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value: function() { return "userDocument_" + (this._iframeCounter++); } - }, - - ///// Return the last part of a path (e.g. filename) - getFileNameFromPath : { - value: function(path) { - path = path.replace(/[/\\]$/g,""); - path = path.replace(/\\/g,"/"); - return path.substr(path.lastIndexOf('/') + 1); - } - } + } }); \ No newline at end of file -- cgit v1.2.3