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 +++++++++++++-------------------- js/io/document/html-document.js | 5 ++-- js/mediators/io-mediator.js | 32 +++++++++++++++++++++---- js/stage/stage-view.reel/stage-view.css | 1 + 4 files changed, 49 insertions(+), 31 deletions(-) (limited to '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 diff --git a/js/io/document/html-document.js b/js/io/document/html-document.js index 24d4e7e4..da1bbe4a 100755 --- a/js/io/document/html-document.js +++ b/js/io/document/html-document.js @@ -216,8 +216,9 @@ var HTMLDocument = exports.HTMLDocument = Montage.create(baseDocumentModule.Base value: function(doc, uuid, iframe, callback) { // Shell mode is not used anymore //if(!window.IsInShellMode()) { - - this.init("index-cloud", this._cloudTemplateUri, doc.type, iframe, uuid, callback); + if(!doc.name){doc.name = "index-cloud"}; + if(!doc.uri){doc.uri = this._cloudTemplateUri}; + this.init(doc.name, doc.uri, doc.type, iframe, uuid, callback); /* } else { var tmpurl = doc.uri.split('\\'); diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index 3d75771f..76f78a7d 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js @@ -16,12 +16,12 @@ exports.IoMediator = Montage.create(require("montage/ui/component").Component, { // fileNew: { enumerable: false, - value: function (file, template, callback, callbackScope) { + value: function (file, template, callback) { // var returnObj = null; //like {"type": "js", "name": "filename", "source": "test file content", "uri": "/fs/fsd/"} - callback.call(callbackScope, returnObj); + callback.operation.call(callback.thisScope, returnObj); } }, //////////////////////////////////////////////////////////////////// @@ -29,7 +29,23 @@ exports.IoMediator = Montage.create(require("montage/ui/component").Component, { fileOpen: { enumerable: false, value: function (file, callback) { - // + var response = "", fileContent="", filename="", fileType="js", returnObj=null; + + response = this.application.ninja.coreIoApi.openFile({"uri":file.uri}); + if((response.success === true) && ((response.status === 200) || (response.status === 304))){ + fileContent = response.content; + } + + + //TODO : format html content to render in design view + + + filename = this.getFileNameFromPath(file.uri); + if(file.uri.indexOf('.') != -1){ + fileType = file.uri.substr(file.uri.lastIndexOf('.') + 1); + } + returnObj = {"type": ""+fileType, "name": ""+filename, "source": fileContent, "uri": file.uri}; + callback.operation.call(callback.thisScope, returnObj); } }, //////////////////////////////////////////////////////////////////// @@ -47,8 +63,16 @@ exports.IoMediator = Montage.create(require("montage/ui/component").Component, { value: function (file, copy, callback) { // } - } + }, //////////////////////////////////////////////////////////////////// + ///// 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); + } + } //////////////////////////////////////////////////////////////////// }); //////////////////////////////////////////////////////////////////////// diff --git a/js/stage/stage-view.reel/stage-view.css b/js/stage/stage-view.reel/stage-view.css index f00a5f8a..ce7072c7 100755 --- a/js/stage/stage-view.reel/stage-view.css +++ b/js/stage/stage-view.reel/stage-view.css @@ -13,6 +13,7 @@ background-color: #ffffff; width: 100%; height: 100%; + overflow:auto; /*display: none;*/ } -- cgit v1.2.3