diff options
author | hwc487 | 2012-05-31 17:11:08 -0700 |
---|---|---|
committer | hwc487 | 2012-05-31 17:11:08 -0700 |
commit | 1c445cf5d905f79937998cf2f1115594ea8c1074 (patch) | |
tree | 35271ad7ffec86fde9102af3dd954fa3a2974582 /js/mediators | |
parent | 335ce503996e3ccbd2909086328d0a31fbd03370 (diff) | |
parent | 6042bdc5f2aada4412912fd01602d32c9088dc26 (diff) | |
download | ninja-1c445cf5d905f79937998cf2f1115594ea8c1074.tar.gz |
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into Textures
Conflicts:
js/io/system/ninjalibrary.json
Diffstat (limited to 'js/mediators')
-rwxr-xr-x | js/mediators/element-mediator.js | 10 | ||||
-rw-r--r-- | js/mediators/io-mediator.js | 410 | ||||
-rwxr-xr-x | js/mediators/keyboard-mediator.js | 33 |
3 files changed, 295 insertions, 158 deletions
diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js index 020f875f..7657112f 100755 --- a/js/mediators/element-mediator.js +++ b/js/mediators/element-mediator.js | |||
@@ -54,7 +54,7 @@ exports.ElementMediator = Montage.create(Component, { | |||
54 | 54 | ||
55 | document.application.undoManager.add(undoLabel, this.removeElements, this, elements, notify); | 55 | document.application.undoManager.add(undoLabel, this.removeElements, this, elements, notify); |
56 | 56 | ||
57 | this.application.ninja.documentController.activeDocument.needsSave = true; | 57 | this.application.ninja.documentController.activeDocument.model.needsSave = true; |
58 | 58 | ||
59 | if(notify || notify === undefined) { | 59 | if(notify || notify === undefined) { |
60 | NJevent("elementAdded", elements); | 60 | NJevent("elementAdded", elements); |
@@ -83,7 +83,7 @@ exports.ElementMediator = Montage.create(Component, { | |||
83 | 83 | ||
84 | document.application.undoManager.add(undoLabel, this.addElements, this, elements, null, notify); | 84 | document.application.undoManager.add(undoLabel, this.addElements, this, elements, null, notify); |
85 | 85 | ||
86 | this.application.ninja.documentController.activeDocument.needsSave = true; | 86 | this.application.ninja.documentController.activeDocument.model.needsSave = true; |
87 | 87 | ||
88 | NJevent("elementsRemoved", elements); | 88 | NJevent("elementsRemoved", elements); |
89 | } | 89 | } |
@@ -92,13 +92,13 @@ exports.ElementMediator = Montage.create(Component, { | |||
92 | replaceElement: { | 92 | replaceElement: { |
93 | value: function(newChild, oldChild, notify) { | 93 | value: function(newChild, oldChild, notify) { |
94 | 94 | ||
95 | this.application.ninja.currentDocument.documentRoot.replaceChild(newChild, oldChild); | 95 | this.application.ninja.currentDocument.model.documentRoot.replaceChild(newChild, oldChild); |
96 | 96 | ||
97 | var undoLabel = "replace element"; | 97 | var undoLabel = "replace element"; |
98 | 98 | ||
99 | document.application.undoManager.add(undoLabel, this.replaceElement, this, oldChild, newChild); | 99 | document.application.undoManager.add(undoLabel, this.replaceElement, this, oldChild, newChild); |
100 | 100 | ||
101 | this.application.ninja.documentController.activeDocument.needsSave = true; | 101 | this.application.ninja.documentController.activeDocument.model.needsSave = true; |
102 | 102 | ||
103 | if(notify || notify === undefined) { | 103 | if(notify || notify === undefined) { |
104 | NJevent("elementReplaced", {type : "replaceElement", data: {"newChild": newChild, "oldChild": oldChild}}); | 104 | NJevent("elementReplaced", {type : "replaceElement", data: {"newChild": newChild, "oldChild": oldChild}}); |
@@ -526,7 +526,7 @@ exports.ElementMediator = Montage.create(Component, { | |||
526 | value: function(layersDraggedArray, layerDroppedAfter) { | 526 | value: function(layersDraggedArray, layerDroppedAfter) { |
527 | var documentRoot,length; | 527 | var documentRoot,length; |
528 | 528 | ||
529 | documentRoot = this.application.ninja.currentDocument.documentRoot; | 529 | documentRoot = this.application.ninja.currentDocument.model.documentRoot; |
530 | length = layersDraggedArray.length; | 530 | length = layersDraggedArray.length; |
531 | 531 | ||
532 | for(var i=0; documentRoot.children[i]; i++) { | 532 | for(var i=0; documentRoot.children[i]; i++) { |
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index 057a849d..e9ed86d7 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js | |||
@@ -10,7 +10,7 @@ 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-creator").TemplateCreator; | 13 | TemplateCreator = require("node_modules/tools/template/template-creator").TemplateCreator; |
14 | //////////////////////////////////////////////////////////////////////// | 14 | //////////////////////////////////////////////////////////////////////// |
15 | // | 15 | // |
16 | exports.IoMediator = Montage.create(Component, { | 16 | exports.IoMediator = Montage.create(Component, { |
@@ -53,14 +53,14 @@ exports.IoMediator = Montage.create(Component, { | |||
53 | // | 53 | // |
54 | fileNew: { | 54 | fileNew: { |
55 | enumerable: false, | 55 | enumerable: false, |
56 | value: function (file, template, callback) { | 56 | value: function (file, url, callback, template) { |
57 | //Loading template from template URL | 57 | //Loading template from template URL |
58 | var xhr = new XMLHttpRequest(), result; | 58 | var xhr = new XMLHttpRequest(), result; |
59 | xhr.open("GET", template, false); | 59 | xhr.open("GET", url, false); |
60 | xhr.send(); | 60 | xhr.send(); |
61 | if (xhr.readyState === 4) { | 61 | if (xhr.readyState === 4) { |
62 | //Making call to create file, checking for return code | 62 | //Making call to create file, checking for return code |
63 | switch (this.fio.newFile({ uri: file, contents: xhr.response })) { | 63 | switch (this.fio.newFile({ uri: file, contents: parseTemplate(xhr.response, template) })) { |
64 | case 201: | 64 | case 201: |
65 | result = { status: 201, success: true, uri: file }; | 65 | result = { status: 201, success: true, uri: file }; |
66 | break; | 66 | break; |
@@ -74,6 +74,21 @@ exports.IoMediator = Montage.create(Component, { | |||
74 | result = { status: 500, success: false, uri: file }; | 74 | result = { status: 500, success: false, uri: file }; |
75 | break; | 75 | break; |
76 | } | 76 | } |
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 | } | ||
77 | } else { | 92 | } else { |
78 | result = { status: 500, success: false, uri: file }; | 93 | result = { status: 500, success: false, uri: file }; |
79 | } | 94 | } |
@@ -147,25 +162,25 @@ exports.IoMediator = Montage.create(Component, { | |||
147 | // | 162 | // |
148 | fileSave: { | 163 | fileSave: { |
149 | enumerable: false, | 164 | enumerable: false, |
150 | value: function (file, callback) { | 165 | value: function (doc, callback) { |
151 | // | 166 | // |
152 | var contents, save; | 167 | var contents, save; |
153 | // | 168 | // |
154 | switch (file.mode) { | 169 | switch (doc.mode) { |
155 | case 'html': | 170 | case 'html': |
156 | |||
157 | |||
158 | //TODO: Add check for Monatage library to copy | ||
159 | |||
160 | //Getting content from function to properly handle saving assets (as in external if flagged) | 171 | //Getting content from function to properly handle saving assets (as in external if flagged) |
161 | contents = this.parseNinjaTemplateToHtml(file); | 172 | if (doc.template && (doc.template.type === 'banner' || doc.template.type === 'animation')) { |
173 | contents = this.parseNinjaTemplateToHtml(doc, true); | ||
174 | } else { | ||
175 | contents = this.parseNinjaTemplateToHtml(doc); | ||
176 | } | ||
162 | break; | 177 | break; |
163 | default: | 178 | default: |
164 | contents = file.content; | 179 | contents = doc.content; |
165 | break; | 180 | break; |
166 | } | 181 | } |
167 | //Making call to save file | 182 | //Making call to save file |
168 | save = this.fio.saveFile({ uri: file.document.uri, contents: contents }); | 183 | save = this.fio.saveFile({ uri: doc.file.uri, contents: contents }); |
169 | //Checking for callback | 184 | //Checking for callback |
170 | if (callback) callback(save); | 185 | if (callback) callback(save); |
171 | } | 186 | } |
@@ -188,6 +203,59 @@ exports.IoMediator = Montage.create(Component, { | |||
188 | }, | 203 | }, |
189 | //////////////////////////////////////////////////////////////////// | 204 | //////////////////////////////////////////////////////////////////// |
190 | // | 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 | return this._getUserDirectory(this.getNinjaDirectory(path)+'canvas/'); | ||
226 | } | ||
227 | }, | ||
228 | //////////////////////////////////////////////////////////////////// | ||
229 | // | ||
230 | _getUserDirectory: { | ||
231 | value: function (path) { | ||
232 | //Checking for data directory | ||
233 | var check = this.application.ninja.coreIoApi.fileExists({uri: path}), directory; | ||
234 | //Creating directory if doesn't exists | ||
235 | switch (check.status) { | ||
236 | case 204: //Exists | ||
237 | directory = path; | ||
238 | break; | ||
239 | case 404: //Doesn't exists | ||
240 | directory = this.application.ninja.coreIoApi.createDirectory({uri: path}); | ||
241 | //Checking for success | ||
242 | if (directory.status === 201) { | ||
243 | directory = path; | ||
244 | } else { | ||
245 | //Error | ||
246 | directory = null; | ||
247 | } | ||
248 | break; | ||
249 | default: //Error | ||
250 | directory = null; | ||
251 | break; | ||
252 | } | ||
253 | //Returning the path to the directory on disk (null for any error) | ||
254 | return directory; | ||
255 | } | ||
256 | }, | ||
257 | //////////////////////////////////////////////////////////////////// | ||
258 | // | ||
191 | parseHtmlToNinjaTemplate: { | 259 | parseHtmlToNinjaTemplate: { |
192 | enumerable: false, | 260 | enumerable: false, |
193 | value: function (html) { | 261 | value: function (html) { |
@@ -196,23 +264,65 @@ exports.IoMediator = Montage.create(Component, { | |||
196 | //Setting content to temp |