aboutsummaryrefslogtreecommitdiff
path: root/js/mediators
diff options
context:
space:
mode:
Diffstat (limited to 'js/mediators')
-rw-r--r--js/mediators/io-mediator.js712
1 files changed, 42 insertions, 670 deletions
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js
index 4dbf32d5..c9e10896 100644
--- a/js/mediators/io-mediator.js
+++ b/js/mediators/io-mediator.js
@@ -10,49 +10,58 @@ var Montage = require("montage/core/core").Montage,
10 Component = require("montage/ui/component").Component, 10 Component = require("montage/ui/component").Component,
11 FileIo = require("js/io/system/fileio").FileIo, 11 FileIo = require("js/io/system/fileio").FileIo,
12 ProjectIo = require("js/io/system/projectio").ProjectIo, 12 ProjectIo = require("js/io/system/projectio").ProjectIo,
13 TemplateCreator = require("node_modules/tools/template/template-creator").TemplateCreator; 13 TemplateMediator = require("js/document/mediators/template").TemplateDocumentMediator;
14//////////////////////////////////////////////////////////////////////// 14////////////////////////////////////////////////////////////////////////
15// 15//
16exports.IoMediator = Montage.create(Component, { 16exports.IoMediator = Montage.create(Component, {
17 //////////////////////////////////////////////////////////////////// 17 ////////////////////////////////////////////////////////////////////
18 // 18 //
19 hasTemplate: { 19 hasTemplate: {
20 enumerable: false,
21 value: false 20 value: false
22 }, 21 },
23 //////////////////////////////////////////////////////////////////// 22 ////////////////////////////////////////////////////////////////////
24 // 23 //
25 deserializedFromTemplate: { 24 deserializedFromTemplate: {
26 enumerable: false,
27 value: function () { 25 value: function () {
28 // 26 //
29 } 27 }
30 }, 28 },
31 //////////////////////////////////////////////////////////////////// 29 ////////////////////////////////////////////////////////////////////
32 // 30 //
31 tmplt: {
32 value: TemplateMediator
33 },
34 ////////////////////////////////////////////////////////////////////
35 //
33 fio: { 36 fio: {
34 enumerable: false,
35 value: FileIo 37 value: FileIo
36 }, 38 },
37 //////////////////////////////////////////////////////////////////// 39 ////////////////////////////////////////////////////////////////////
38 // 40 //
39 pio: { 41 pio: {
40 enumerable: false,
41 value: ProjectIo 42 value: ProjectIo
42 }, 43 },
43 //////////////////////////////////////////////////////////////////// 44 ////////////////////////////////////////////////////////////////////
44 // 45 //
45 getAppTemplatesUrlRegEx: { 46 parseToTemplate: {
46 enumerable: false, 47 value: function(content, template) {
47 value: function () { 48 //
48 var regex = new RegExp(chrome.extension.getURL('js/document/templates/montage-html').replace(/\//gi, '\\\/'), 'gi'); 49 if (template.name.toLowerCase() === 'banner' || template.name.toLowerCase() === 'animation') {
49 return regex; 50 //Getting dimensions of banner
50 } 51 var dimensions = template.id.split('x');
52 dimensions = {width: String(dimensions[0])+'px', height: String(dimensions[1])+'px'};
53 //
54 content = content.replace(/Dimensions@@@/gi, "Dimensions@@@"+template.id);
55 content = content.replace(/ninja-banner {}/gi, "ninja-banner {overflow: visible; width: "+dimensions.width+"; height: "+dimensions.height+"}");
56 content = content.replace(/ninja-content-wrapper {}/gi, "ninja-content-wrapper {overflow: hidden; width: "+dimensions.width+"; height: "+dimensions.height+"}");
57 }
58 //
59 return content;
60 }
51 }, 61 },
52 //////////////////////////////////////////////////////////////////// 62 ////////////////////////////////////////////////////////////////////
53 // 63 //
54 fileNew: { 64 fileNew: {
55 enumerable: false,
56 value: function (file, url, callback, template) { 65 value: function (file, url, callback, template) {
57 //Loading template from template URL 66 //Loading template from template URL
58 var xhr = new XMLHttpRequest(), result; 67 var xhr = new XMLHttpRequest(), result;
@@ -60,7 +69,7 @@ exports.IoMediator = Montage.create(Component, {
60 xhr.send(); 69 xhr.send();
61 if (xhr.readyState === 4) { 70 if (xhr.readyState === 4) {
62 //Making call to create file, checking for return code 71 //Making call to create file, checking for return code
63 switch (this.fio.newFile({ uri: file, contents: parseTemplate(xhr.response, template) })) { 72 switch (this.fio.newFile({ uri: file, contents: this.parseToTemplate(xhr.response, template) })) {
64 case 201: 73 case 201:
65 result = { status: 201, success: true, uri: file }; 74 result = { status: 201, success: true, uri: file };
66 break; 75 break;
@@ -74,21 +83,6 @@ exports.IoMediator = Montage.create(Component, {
74 result = { status: 500, success: false, uri: file }; 83 result = { status: 500, success: false, uri: file };
75 break; 84 break;
76 } 85 }
77 //TODO: Improve template data injection
78 function parseTemplate (content, template) {
79 //
80 if (template.name.toLowerCase() === 'banner' || template.name.toLowerCase() === 'animation') {
81 //Getting dimensions of banner
82 var dimensions = template.id.split('x');
83 dimensions = {width: String(dimensions[0])+'px', height: String(dimensions[1])+'px'};
84 //
85 content = content.replace(/Dimensions@@@/gi, "Dimensions@@@"+template.id);
86 content = content.replace(/ninja-banner {}/gi, "ninja-banner {overflow: visible; width: "+dimensions.width+"; height: "+dimensions.height+"}");
87 content = content.replace(/ninja-content-wrapper {}/gi, "ninja-content-wrapper {overflow: hidden; width: "+dimensions.width+"; height: "+dimensions.height+"}");
88 }
89 //
90 return content;
91 }
92 } else { 86 } else {
93 result = { status: 500, success: false, uri: file }; 87 result = { status: 500, success: false, uri: file };
94 } 88 }
@@ -102,7 +96,6 @@ exports.IoMediator = Montage.create(Component, {
102 //////////////////////////////////////////////////////////////////// 96 ////////////////////////////////////////////////////////////////////
103 // 97 //
104 fileOpen: { 98 fileOpen: {
105 enumerable: false,
106 value: function (file, callback) { 99 value: function (file, callback) {
107 //Reading file (Ninja doesn't really open a file, all in browser memory) 100 //Reading file (Ninja doesn't really open a file, all in browser memory)
108 var read = this.fio.readFile({ uri: file }), result; 101 var read = this.fio.readFile({ uri: file }), result;
@@ -118,7 +111,7 @@ exports.IoMediator = Montage.create(Component, {
118 result.content = read.file.content; 111 result.content = read.file.content;
119 } else { 112 } else {
120 //Object to be used by Ninja Template 113 //Object to be used by Ninja Template
121 result.content = this.parseHtmlToNinjaTemplate(read.file.content); 114 result.content = this.tmplt.parseHtmlToNinjaTemplate(read.file.content);
122 } 115 }
123 //Status of call 116 //Status of call
124 result.status = read.status; 117 result.status = read.status;
@@ -159,30 +152,38 @@ exports.IoMediator = Montage.create(Component, {
159 } 152 }
160 }, 153 },
161 //////////////////////////////////////////////////////////////////// 154 ////////////////////////////////////////////////////////////////////
162 // 155 //TODO: Optimize
163 fileSave: { 156 fileSave: {
164 enumerable: false, 157 value: function (doc, callback, libCopyCallback) {
165 value: function (doc, callback) {
166 // 158 //
167 var contents, save; 159 var content, parsedDoc, save;
168 // 160 //
169 switch (doc.mode) { 161 switch (doc.mode) {
170 case 'html': 162 case 'html':
171 //Getting content from function to properly handle saving assets (as in external if flagged) 163 //Getting content from function to properly handle saving assets (as in external if flagged)
172 if (doc.template && (doc.template.type === 'banner' || doc.template.type === 'animation')) { 164 if (doc.template && (doc.template.type === 'banner' || doc.template.type === 'animation')) {
173 contents = this.parseNinjaTemplateToHtml(doc, true); 165 parsedDoc = this.tmplt.parseNinjaTemplateToHtml(doc, true, libCopyCallback);
174 } else { 166 } else {
175 contents = this.parseNinjaTemplateToHtml(doc); 167 parsedDoc = this.tmplt.parseNinjaTemplateToHtml(doc, false, libCopyCallback);
176 } 168 }
177 break; 169 break;
178 default: 170 default:
179 contents = doc.content; 171 content = doc.content;
180 break; 172 break;
181 } 173 }
182 //Making call to save file 174 if (parsedDoc) {
183 save = this.fio.saveFile({ uri: doc.file.uri, contents: contents }); 175 //Making call to save file
184 //Checking for callback 176 save = this.fio.saveFile({uri: doc.file.uri, contents: parsedDoc.content});
185 if (callback) callback(save); 177 //Checking for callback
178 if (callback) callback(save);
179 //
180 if (!parsedDoc.libs && libCopyCallback) libCopyCallback(true);
181 } else {
182 //Making call to save file
183 save = this.fio.saveFile({uri: doc.file.uri, contents: content});
184 //Checking for callback
185 if (callback) callback(save);
186 }
186 } 187 }
187 }, 188 },
188 //////////////////////////////////////////////////////////////////// 189 ////////////////////////////////////////////////////////////////////
@@ -200,635 +201,6 @@ exports.IoMediator = Montage.create(Component, {
200 value: function (file, callback) { 201 value: function (file, callback) {
201 //TODO: Implement Delete functionality 202 //TODO: Implement Delete functionality
202 } 203 }
203 },
204 ////////////////////////////////////////////////////////////////////
205 //
206 getDataDirectory: {
207 value: function (path) {
208 //TODO: Implement user overwrite
209 return this._getUserDirectory(path+'data/');
210 }
211 },
212 ////////////////////////////////////////////////////////////////////
213 //
214 getNinjaDirectory: {
215 value: function (path) {
216 //TODO: Implement user overwrite
217 return this._getUserDirectory(this.getDataDirectory(path)+'ninja/');
218 }
219 },
220 ////////////////////////////////////////////////////////////////////
221 //
222 getCanvasDirectory: {
223 value: function (path) {
224 //TODO: Implement user overwrite
225</