aboutsummaryrefslogtreecommitdiff
path: root/js/mediators
diff options
context:
space:
mode:
Diffstat (limited to 'js/mediators')
-rwxr-xr-xjs/mediators/element-mediator.js6
-rw-r--r--js/mediators/io-mediator.js699
2 files changed, 45 insertions, 660 deletions
diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js
index f71a6f4d..1d5e9ade 100755
--- a/js/mediators/element-mediator.js
+++ b/js/mediators/element-mediator.js
@@ -48,7 +48,7 @@ exports.ElementMediator = Montage.create(Component, {
48 48
49 document.application.undoManager.add(undoLabel, this.removeElements, this, elements, notify); 49 document.application.undoManager.add(undoLabel, this.removeElements, this, elements, notify);
50 50
51 this.application.ninja.documentController.activeDocument.model.needsSave = true; 51 this.application.ninja.currentDocument.model.needsSave = true;
52 52
53 if(notify || notify === undefined) { 53 if(notify || notify === undefined) {
54 NJevent("elementAdded", elements); 54 NJevent("elementAdded", elements);
@@ -77,7 +77,7 @@ exports.ElementMediator = Montage.create(Component, {
77 77
78 document.application.undoManager.add(undoLabel, this.addElements, this, elements, null, notify); 78 document.application.undoManager.add(undoLabel, this.addElements, this, elements, null, notify);
79 79
80 this.application.ninja.documentController.activeDocument.model.needsSave = true; 80 this.application.ninja.currentDocument.model.needsSave = true;
81 81
82 NJevent("elementsRemoved", elements); 82 NJevent("elementsRemoved", elements);
83 } 83 }
@@ -92,7 +92,7 @@ exports.ElementMediator = Montage.create(Component, {
92 92
93 document.application.undoManager.add(undoLabel, this.replaceElement, this, oldChild, newChild); 93 document.application.undoManager.add(undoLabel, this.replaceElement, this, oldChild, newChild);
94 94
95 this.application.ninja.documentController.activeDocument.model.needsSave = true; 95 this.application.ninja.currentDocument.model.needsSave = true;
96 96
97 if(notify || notify === undefined) { 97 if(notify || notify === undefined) {
98 NJevent("elementReplaced", {type : "replaceElement", data: {"newChild": newChild, "oldChild": oldChild}}); 98 NJevent("elementReplaced", {type : "replaceElement", data: {"newChild": newChild, "oldChild": oldChild}});
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js
index e9ed86d7..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