aboutsummaryrefslogtreecommitdiff
path: root/js/mediators/io-mediator.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/mediators/io-mediator.js')
-rw-r--r--js/mediators/io-mediator.js35
1 files changed, 31 insertions, 4 deletions
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js
index 8d0a671e..76f78a7d 100644
--- a/js/mediators/io-mediator.js
+++ b/js/mediators/io-mediator.js
@@ -11,14 +11,17 @@ var Montage = require("montage/core/core").Montage,
11 ProjectIo = require("js/io/system/projectio").ProjectIo; 11 ProjectIo = require("js/io/system/projectio").ProjectIo;
12//////////////////////////////////////////////////////////////////////// 12////////////////////////////////////////////////////////////////////////
13// 13//
14exports.IoMediator = Montage.create(Object.prototype, { 14exports.IoMediator = Montage.create(require("montage/ui/component").Component, {
15 //////////////////////////////////////////////////////////////////// 15 ////////////////////////////////////////////////////////////////////
16 // 16 //
17 fileNew: { 17 fileNew: {
18 enumerable: false, 18 enumerable: false,
19 value: function (file, template, callback) { 19 value: function (file, template, callback) {
20 // 20 //
21 21
22
23 var returnObj = null; //like {"type": "js", "name": "filename", "source": "test file content", "uri": "/fs/fsd/"}
24 callback.operation.call(callback.thisScope, returnObj);
22 } 25 }
23 }, 26 },
24 //////////////////////////////////////////////////////////////////// 27 ////////////////////////////////////////////////////////////////////
@@ -26,7 +29,23 @@ exports.IoMediator = Montage.create(Object.prototype, {
26 fileOpen: { 29 fileOpen: {
27 enumerable: false, 30 enumerable: false,
28 value: function (file, callback) { 31 value: function (file, callback) {
29 // 32 var response = "", fileContent="", filename="", fileType="js", returnObj=null;
33
34 response = this.application.ninja.coreIoApi.openFile({"uri":file.uri});
35 if((response.success === true) && ((response.status === 200) || (response.status === 304))){
36 fileContent = response.content;
37 }
38
39
40 //TODO : format html content to render in design view
41
42
43 filename = this.getFileNameFromPath(file.uri);
44 if(file.uri.indexOf('.') != -1){
45 fileType = file.uri.substr(file.uri.lastIndexOf('.') + 1);
46 }
47 returnObj = {"type": ""+fileType, "name": ""+filename, "source": fileContent, "uri": file.uri};
48 callback.operation.call(callback.thisScope, returnObj);
30 } 49 }
31 }, 50 },
32 //////////////////////////////////////////////////////////////////// 51 ////////////////////////////////////////////////////////////////////
@@ -44,8 +63,16 @@ exports.IoMediator = Montage.create(Object.prototype, {
44 value: function (file, copy, callback) { 63 value: function (file, copy, callback) {
45 // 64 //
46 } 65 }
47 } 66 },
48 //////////////////////////////////////////////////////////////////// 67 ////////////////////////////////////////////////////////////////////
68 ///// Return the last part of a path (e.g. filename)
69 getFileNameFromPath : {
70 value: function(path) {
71 path = path.replace(/[/\\]$/g,"");
72 path = path.replace(/\\/g,"/");
73 return path.substr(path.lastIndexOf('/') + 1);
74 }
75 }
49 //////////////////////////////////////////////////////////////////// 76 ////////////////////////////////////////////////////////////////////
50}); 77});
51//////////////////////////////////////////////////////////////////////// 78////////////////////////////////////////////////////////////////////////