aboutsummaryrefslogtreecommitdiff
path: root/js/io/document
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-02-04 22:35:28 -0800
committerJose Antonio Marquez2012-02-04 22:35:28 -0800
commitd1fda420f898965b5dd57de0c8340886cef308a8 (patch)
tree2fad2e890c1142a7eee30c45710f1f0b78adfdde /js/io/document
parentcc64cfc5aaa570ed9f72545fc135200019d62311 (diff)
parent45cfffd9261ab1aa714554c584f0d0d8fe627c91 (diff)
downloadninja-d1fda420f898965b5dd57de0c8340886cef308a8.tar.gz
Merge branch 'refs/heads/AnanyaFileIO' into FileIO
Diffstat (limited to 'js/io/document')
-rwxr-xr-xjs/io/document/base-document.js7
-rwxr-xr-xjs/io/document/document-controller.js84
-rwxr-xr-xjs/io/document/html-document.js33
-rwxr-xr-xjs/io/document/text-document.js16
4 files changed, 118 insertions, 22 deletions
diff --git a/js/io/document/base-document.js b/js/io/document/base-document.js
index d3601de5..ecc92447 100755
--- a/js/io/document/base-document.js
+++ b/js/io/document/base-document.js
@@ -87,7 +87,12 @@ var BaseDocument = exports.BaseDocument = Montage.create(Montage, {
87 value: function() { 87 value: function() {
88 // Have the XHR here? 88 // Have the XHR here?
89 } 89 }
90 } 90 },
91 91
92 save:{
93 value:function(){
94 //base function - to be overridden
95 }
96 }
92 97
93}); \ No newline at end of file 98}); \ No newline at end of file
diff --git a/js/io/document/document-controller.js b/js/io/document/document-controller.js
index d7a19e35..ca6b4533 100755
--- a/js/io/document/document-controller.js
+++ b/js/io/document/document-controller.js
@@ -15,7 +15,6 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
15var Montage = require("montage/core/core").Montage, 15var Montage = require("montage/core/core").Montage,
16 Component = require("montage/ui/component").Component, 16 Component = require("montage/ui/component").Component,
17 Uuid = require("montage/core/uuid").Uuid, 17 Uuid = require("montage/core/uuid").Uuid,
18 //nj= ("js/lib/NJUtils.js").NJUtils,
19 HTMLDocument = require("js/io/document/html-document").HTMLDocument, 18 HTMLDocument = require("js/io/document/html-document").HTMLDocument,
20 TextDocument = require("js/io/document/text-document").TextDocument; 19 TextDocument = require("js/io/document/text-document").TextDocument;
21 20
@@ -71,8 +70,8 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
71 deserializedFromTemplate: { 70 deserializedFromTemplate: {
72 value: function() { 71 value: function() {
73 this.eventManager.addEventListener("appLoaded", this, false); 72 this.eventManager.addEventListener("appLoaded", this, false);
74
75 this.eventManager.addEventListener("executeFileOpen", this, false); 73 this.eventManager.addEventListener("executeFileOpen", this, false);
74 this.eventManager.addEventListener("executeNewFile", this, false);
76 } 75 }
77 }, 76 },
78 77
@@ -93,6 +92,46 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
93 } 92 }
94 }, 93 },
95 94
95 handleExecuteNewFile: {
96 value: function(event) {
97 var newFileSettings = event._event.settings || {};
98 newFileSettings.callback = this.createNewFile;
99 newFileSettings.callbackScope = this;
100 this.application.ninja.newFileController.showNewFileDialog(newFileSettings);
101 }
102 },
103
104 createNewFile:{
105 value:function(newFileObj){
106 //console.log(newFileObj);//contains the template uri and the new file uri
107 if(!newFileObj) return;
108 this.application.ninja.ioMediator.fileNew(newFileObj.newFilePath, newFileObj.fileTemplateUri, {"operation":this.openNewFileCallback, "thisScope":this});
109
110 if((newFileObj.fileExtension !== ".html") && (newFileObj.fileExtension !== ".htm")){//open code view
111
112 }else{
113 //open design view
114 }
115 }
116 },
117
118 /**
119 * Public method
120 * doc contains:
121 * type : file type, like js, css, etc
122 * name : file name
123 * source : file content
124 * uri : file uri
125 */
126 openNewFileCallback:{
127 value:function(doc){
128 if(!doc){
129 doc = {"type": "js", "name": "filename", "source": "test file content", "uri": "/fs/fsd/"} ;
130 }
131 this.openDocument(doc);
132 }
133 },
134
96 openFileWithURI: { 135 openFileWithURI: {
97 value: function(uriArrayObj) { 136 value: function(uriArrayObj) {
98 var uri = "", fileContent = "", response=null, filename="", fileType="js"; 137 var uri = "", fileContent = "", response=null, filename="", fileType="js";
@@ -101,20 +140,21 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
101 } 140 }
102 //console.log("URI is: ", uri); 141 //console.log("URI is: ", uri);
103 142
104 if(!!uri){ 143 this.application.ninja.ioMediator.fileOpen({"uri":uri}, {"operation":this.openFileCallback, "thisScope":this});
105 response = this.application.ninja.coreIoApi.openFile({"uri":uri}); 144 }
106 if((response.success === true) && ((response.status === 200) || (response.status === 304))){ 145 },
107 fileContent = response.content;
108 }
109
110 //console.log("$$$ "+uri+"\n content = \n\n\n"+ fileContent+"\n\n\n");
111 filename = nj.getFileNameFromPath(uri);
112 if(uri.indexOf('.') != -1){
113 fileType = uri.substr(uri.lastIndexOf('.') + 1);
114 }
115 this.openDocument({"type": ""+fileType, "name": ""+filename, "source": fileContent, "uri": uri});
116 }
117 146
147 /**
148 * Public method
149 * doc contains:
150 * type : file type, like js, css, etc
151 * name : file name
152 * source : file content
153 * uri : file uri
154 */
155 openFileCallback:{
156 value:function(doc){
157 this.openDocument(doc);
118 } 158 }
119 }, 159 },
120 160
@@ -146,7 +186,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
146 newDoc.initialize(doc, docUuid, textArea, textArea.parentNode); 186 newDoc.initialize(doc, docUuid, textArea, textArea.parentNode);
147 187
148 // Tmp this will be filled with the real content 188 // Tmp this will be filled with the real content
149 newDoc.textArea.innerHTML = doc.source; //this.tmpSourceForTesting; 189 newDoc.textArea.value = doc.source; //this.tmpSourceForTesting;
150 190
151 this.textDocumentOpened(newDoc); 191 this.textDocumentOpened(newDoc);
152 192
@@ -161,7 +201,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
161 textDocumentOpened: { 201 textDocumentOpened: {
162 value: function(doc) { 202 value: function(doc) {
163 203
164 this.activeDocument = doc; 204
165 205
166 this.application.ninja.stage.stageView.createTextView(doc); 206 this.application.ninja.stage.stageView.createTextView(doc);
167 207
@@ -363,7 +403,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
363 value: function() { 403 value: function() {
364 if(this.activeDocument) { 404 if(this.activeDocument) {
365 this.activeDocument.container.style["display"] = "none"; 405 this.activeDocument.container.style["display"] = "none";
366 //if(this.activeDocument.documentType === "htm" || this.activeDocument.documentType === "html") this.application.ninja.stage.toggleCanvas(); 406 if(this.activeDocument.currentView === "design" || this.activeDocument.currentView === "design"){
407 this.activeDocument.container.parentNode.style["display"] = "none";
408 this.application.ninja.stage.hideCanvas(true);
409 }
367 } 410 }
368 } 411 }
369 }, 412 },
@@ -372,7 +415,10 @@ var DocumentController = exports.DocumentController = Montage.create(Component,
372 value: function() { 415 value: function() {
373 if(this.activeDocument) { 416 if(this.activeDocument) {
374 this.activeDocument.container.style["display"] = "block"; 417 this.activeDocument.container.style["display"] = "block";
375 //if(this.activeDocument.documentType === "htm" || this.activeDocument.documentType === "html") this.application.ninja.stage.toggleCanvas(); 418 if(this.activeDocument.currentView === "design" || this.activeDocument.currentView === "design"){
419 this.activeDocument.container.parentNode.style["display"] = "block";
420 this.application.ninja.stage.hideCanvas(false);
421 }
376 } 422 }
377 } 423 }
378 }, 424 },
diff --git a/js/io/document/html-document.js b/js/io/document/html-document.js
index fc7dd05b..da1bbe4a 100755
--- a/js/io/document/html-document.js
+++ b/js/io/document/html-document.js
@@ -43,9 +43,16 @@ var HTMLDocument = exports.HTMLDocument = Montage.create(baseDocumentModule.Base
43 } 43 }
44 }, 44 },
45 45
46
46 // PUBLIC MEMBERS 47 // PUBLIC MEMBERS
47 cssLoadInterval: { value: null, enumerable: false }, 48 cssLoadInterval: { value: null, enumerable: false },
48 49
50 codeViewDocument:{
51 writable: true,
52 enumerable: true,
53 value:null
54 },
55
49 /* 56 /*
50 * PUBLIC API 57 * PUBLIC API
51 */ 58 */
@@ -209,8 +216,9 @@ var HTMLDocument = exports.HTMLDocument = Montage.create(baseDocumentModule.Base
209 value: function(doc, uuid, iframe, callback) { 216 value: function(doc, uuid, iframe, callback) {
210 // Shell mode is not used anymore 217 // Shell mode is not used anymore
211 //if(!window.IsInShellMode()) { 218 //if(!window.IsInShellMode()) {
212 219 if(!doc.name){doc.name = "index-cloud"};
213 this.init("index-cloud", this._cloudTemplateUri, doc.type, iframe, uuid, callback); 220 if(!doc.uri){doc.uri = this._cloudTemplateUri};
221 this.init(doc.name, doc.uri, doc.type, iframe, uuid, callback);
214 /* 222 /*
215 } else { 223 } else {
216 var tmpurl = doc.uri.split('\\'); 224 var tmpurl = doc.uri.split('\\');
@@ -432,5 +440,26 @@ var HTMLDocument = exports.HTMLDocument = Montage.create(baseDocumentModule.Base
432 */ 440 */
433 } 441