aboutsummaryrefslogtreecommitdiff
path: root/js/mediators
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-02-20 11:14:44 -0800
committerNivesh Rajbhandari2012-02-20 11:14:44 -0800
commitabf78e2d7a97d295ce5a1c425fd359d47379137e (patch)
treed08c91bd2aef31e6325e0b499b2ffc390018bec6 /js/mediators
parente80a79bff57fecf3aa9b869d8ed2de5fd815287c (diff)
parente23708721a71ca4c71365f5f8e8ac7d6113926db (diff)
downloadninja-abf78e2d7a97d295ce5a1c425fd359d47379137e.tar.gz
Merge branch 'refs/heads/ninja-internal' into ToolFixes
Diffstat (limited to 'js/mediators')
-rwxr-xr-x[-rw-r--r--]js/mediators/drag-drop-mediator.js17
-rwxr-xr-x[-rw-r--r--]js/mediators/element-mediator.js0
-rw-r--r--js/mediators/io-mediator.js237
-rwxr-xr-x[-rw-r--r--]js/mediators/keyboard-mediator.js6
-rwxr-xr-x[-rw-r--r--]js/mediators/mouse-mediator.js0
5 files changed, 254 insertions, 6 deletions
diff --git a/js/mediators/drag-drop-mediator.js b/js/mediators/drag-drop-mediator.js
index ede71383..bf22aed2 100644..100755
--- a/js/mediators/drag-drop-mediator.js
+++ b/js/mediators/drag-drop-mediator.js
@@ -24,6 +24,10 @@ exports.DragDropMediator = Montage.create(Component, {
24 writable: true 24 writable: true
25 }, 25 },
26 26
27 dropDelegate: {
28 value: null
29 },
30
27 deserializedFromTemplate: { 31 deserializedFromTemplate: {
28 value: function() { 32 value: function() {
29 this.eventManager.addEventListener("appLoaded", this, false); 33 this.eventManager.addEventListener("appLoaded", this, false);
@@ -69,13 +73,14 @@ exports.DragDropMediator = Montage.create(Component, {
69 73
70 xferString = evt.dataTransfer.getData("text/plain"); 74 xferString = evt.dataTransfer.getData("text/plain");
71 if(xferString) { 75 if(xferString) {
72 76 // If the drop is a component, call the delegate with the top,left coordinates
73 if(xferString.lastIndexOf("-Component") !== -1) { 77 if(xferString.indexOf("componentDrop") > -1) {
74 component = xferString.substring(0, xferString.lastIndexOf("-Component")); 78 if(this.dropDelegate && typeof this.dropDelegate === 'object') {
75 NJevent( "executeAddComponent", { "component": component, "dropX": this.baseX, "dropY": this.baseY }); 79 this.dropDelegate.handleComponentDrop(this.baseX, this.baseY);
76// ComponentPanelModule.ComponentsPanelBase.addComponentToStage(componentStr.substring(0, compInd), this.baseX, this.baseY); 80 return;
81 }
77 } 82 }
78 return; 83
79 } 84 }
80 85
81 // Verify that browser supports FileReader API. 86 // Verify that browser supports FileReader API.
diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js
index 95aec2a3..95aec2a3 100644..100755
--- a/js/mediators/element-mediator.js
+++ b/js/mediators/element-mediator.js
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js
new file mode 100644
index 00000000..56869839
--- /dev/null
+++ b/js/mediators/io-mediator.js
@@ -0,0 +1,237 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7////////////////////////////////////////////////////////////////////////
8//
9var Montage = require("montage/core/core").Montage,
10 Component = require("montage/ui/component").Component,
11 FileIo = require("js/io/system/fileio").FileIo,
12 ProjectIo = require("js/io/system/projectio").ProjectIo;
13////////////////////////////////////////////////////////////////////////
14//
15exports.IoMediator = Montage.create(Component, {
16 ////////////////////////////////////////////////////////////////////
17 //
18 hasTemplate: {
19 enumerable: false,
20 value: false
21 },
22 ////////////////////////////////////////////////////////////////////
23 //
24 deserializedFromTemplate: {
25 enumerable: false,
26 value: function () {
27 //
28 }
29 },
30 ////////////////////////////////////////////////////////////////////
31 //
32 fio: {
33 enumerable: false,
34 value: FileIo
35 },
36 ////////////////////////////////////////////////////////////////////
37 //
38 pio: {
39 enumerable: false,
40 value: ProjectIo
41 },
42 ////////////////////////////////////////////////////////////////////
43 //
44 fileNew: {
45 enumerable: false,
46 value: function (file, template, callback) {
47 //Loading template from template URL
48 var xhr = new XMLHttpRequest(), result;
49 xhr.open("GET", template, false);
50 xhr.send();
51 if (xhr.readyState === 4) {
52 //Making call to create file, checking for return code
53 switch (this.fio.newFile({uri: file, contents: xhr.response})) {
54 case 201:
55 result = {status: 201, success: true, uri: file};
56 break;
57 case 204:
58 result = {status: 204, success: false, uri: file};
59 break;
60 case 400:
61 result = {status: 400, success: false, uri: file};
62 break;
63 default:
64 result = {status: 500, success: false, uri: file};
65 break;
66 }
67 } else {
68 result = {status: 500, success: false, uri: file};
69 }
70 //Sending result to callback if requested for handling
71 if (callback) callback(result);
72 //Codes
73 // 204: File exists | 400: File exists
74 // 201: File succesfully created | 500: Unknown (Probably cloud API not running)
75 }
76 },
77 ////////////////////////////////////////////////////////////////////
78 //
79 fileOpen: {
80 enumerable: false,
81 value: function (file, callback) {
82 //Reading file (Ninja doesn't really open a file, all in browser memory)
83 var read = this.fio.readFile({uri: file}), result;
84 //Checking for status
85 switch(read.status) {
86 case 204:
87 //Creating and formatting result object for callbak
88 result = read.file.details;
89 result.root = read.file.details.uri.replace(read.file.details.name, "");
90 //Checking for type of content to returns
91 if (result.extension !== 'html' && result.extension !== 'htm') {
92 //Simple string
93 result.content = read.file.content;
94 } else {
95 //Object to be used by Ninja Template
96 result.content = this.parseHtmlToNinjaTemplate(read.file.content);
97 }
98 //Status of call
99 result.status = read.status;
100 //Calling back with result
101 if (callback) callback(result);
102 break;
103 case 404:
104 //File does not exists
105 if (callback) callback({status: read.status});
106 break;
107 default:
108 //Unknown
109 if (callback) callback({status: 500});
110 break;
111 }
112 /*
113 ////////////////////////////////////////////////////////////
114 ////////////////////////////////////////////////////////////
115 //Return Object Description
116 Object.status (Always presents for handling)
117 204: File exists (Success)
118 404: File does not exists (Failure)
119 500: Unknown (Probably cloud API not running)
120
121 (Below only present if succesfull 204)
122
123 Object.content
124 Object.extension
125 Object.name
126 Object.uri
127 Object.creationDate
128 Object.modifiedDate
129 Object.readOnly
130 Object.size
131 ////////////////////////////////////////////////////////////
132 ////////////////////////////////////////////////////////////
133 */
134 }
135 },
136 ////////////////////////////////////////////////////////////////////
137 //
138 fileSave: {
139 enumerable: false,
140 value: function (file, callback) {
141 //
142 var contents, save;
143 //
144 switch (file.mode) {
145 case 'html':
146 //Copy webGL library if needed
147 if (file.webgl.length > 0) {
148 for (var i in this.application.ninja.coreIoApi.ninjaLibrary.libs) {
149 //if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'Assets' || this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'RDGE') {
150 if (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name === 'RDGE') {
151 this.application.ninja.coreIoApi.ninjaLibrary.copyLibToCloud(file.document.root, (this.application.ninja.coreIoApi.ninjaLibrary.libs[i].name+this.application.ninja.coreIoApi.ninjaLibrary.libs[i].version).toLowerCase());
152 }
153 }
154 }
155 //
156 contents = this.parseNinjaTemplateToHtml(file);
157 break;
158 default:
159 contents = file.content;
160 break;
161 }
162 //
163 save = this.fio.saveFile({uri: file.document.uri, contents: contents});
164 //
165 if (callback) callback(save);
166 }
167 },
168 ////////////////////////////////////////////////////////////////////
169 //
170 fileSaveAs: {
171 enumerable: false,
172 value: function (copyTo, copyFrom, callback) {
173 //
174 }
175 },
176 ////////////////////////////////////////////////////////////////////
177 //
178 fileDelete: {
179 enumerable: false,