diff options
author | Valerio Virgillito | 2012-02-15 16:09:47 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-02-15 16:09:47 -0800 |
commit | d366c0bd1af6471511217ed574083e15059519b5 (patch) | |
tree | c8c9f9af761457e3c5f4c6774fb0fbba851df0c4 /js/mediators | |
parent | 997ce3fb65f27b3d6f331f63b5dc22d3c7fb8f1e (diff) | |
parent | b85bfb54aaca3ccca3c1ef09115de925cd67f4e9 (diff) | |
download | ninja-d366c0bd1af6471511217ed574083e15059519b5.tar.gz |
Merge branch 'refs/heads/integration'
Diffstat (limited to 'js/mediators')
-rwxr-xr-x[-rw-r--r--] | js/mediators/drag-drop-mediator.js | 17 | ||||
-rwxr-xr-x[-rw-r--r--] | js/mediators/element-mediator.js | 0 | ||||
-rw-r--r-- | js/mediators/io-mediator.js | 209 | ||||
-rwxr-xr-x[-rw-r--r--] | js/mediators/keyboard-mediator.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | js/mediators/mouse-mediator.js | 0 |
5 files changed, 220 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..95e775a0 --- /dev/null +++ b/js/mediators/io-mediator.js | |||
@@ -0,0 +1,209 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No 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 | // | ||
9 | var 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 | // | ||
15 | exports.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 | //Checking for type of content to returns | ||
90 | if (result.extension !== 'html' && result.extension !== 'htm') { | ||
91 | //Simple string | ||
92 | result.content = read.file.content; | ||
93 | } else { | ||
94 | //Object to be used by Ninja Template | ||
95 | result.content = this.parseHtmlToNinjaTemplate(read.file.content); | ||
96 | } | ||
97 | //Status of call | ||
98 | result.status = read.status; | ||
99 | //Calling back with result | ||
100 | if (callback) callback(result); | ||
101 | break; | ||
102 | case 404: | ||
103 | //File does not exists | ||
104 | if (callback) callback({status: read.status}); | ||
105 | break; | ||
106 | default: | ||
107 | //Unknown | ||
108 | if (callback) callback({status: 500}); | ||
109 | break; | ||
110 | } | ||
111 | /* | ||
112 | //////////////////////////////////////////////////////////// | ||
113 | //////////////////////////////////////////////////////////// | ||
114 | //Return Object Description | ||
115 | Object.status (Always presents for handling) | ||
116 | 204: File exists (Success) | ||
117 | 404: File does not exists (Failure) | ||
118 | 500: Unknown (Probably cloud API not running) | ||
119 | |||
120 | (Below only present if succesfull 204) | ||
121 | |||
122 | Object.content | ||
123 | Object.extension | ||
124 | Object.name | ||
125 | Object.uri | ||
126 | Object.creationDate | ||
127 | Object.modifiedDate | ||
128 | Object.readOnly | ||
129 | Object.size | ||
130 | //////////////////////////////////////////////////////////// | ||
131 | //////////////////////////////////////////////////////////// | ||
132 | */ | ||
133 | } | ||
134 | }, | ||
135 | //////////////////////////////////////////////////////////////////// | ||
136 | // | ||
137 | fileSave: { | ||
138 | enumerable: false, | ||
139 | value: function (file, callback) { | ||
140 | // | ||
141 | var contents, save; | ||
142 | // | ||
143 | switch (file.mode) { | ||
144 | case 'html': | ||
145 | file.document.content.document.body.innerHTML = file.body; | ||
146 | file.document.content.document.head.innerHTML = file.head; | ||
147 | if (file.style) { | ||
148 | file.document.content.document.head.getElementsByTagName('style')[0].innerHTML = this.getCssFromRules(file.style.cssRules); | ||
149 | } | ||
150 | contents = file.document.content.document.documentElement.outerHTML; | ||
151 | break; | ||
152 | default: | ||
153 | contents = file.content; | ||
154 | break; | ||
155 | } | ||
156 | // | ||
157 | save = this.fio.saveFile({uri: file.document.uri, contents: contents}); | ||
158 | if(save.status === 204){ | ||
159 | callback(); | ||
160 | } | ||
161 | } | ||
162 | }, | ||
163 | //////////////////////////////////////////////////////////////////// | ||
164 | // | ||
165 | fileSaveAs: { | ||
166 | enumerable: false, | ||
167 | value: function (copyTo, copyFrom, callback) { | ||
168 | // | ||
169 | } | ||
170 | }, | ||
171 | //////////////////////////////////////////////////////////////////// | ||
172 | // | ||
173 | parseHtmlToNinjaTemplate: { | ||
174 | enumerable: false, | ||
175 | value: function (html) { | ||
176 | //Creating temp object to mimic HTML | ||
177 | var doc = window.document.implementation.createHTMLDocument(), template; | ||
178 | //Setting content to temp | ||
179 | doc.getElementsByTagName('html')[0].innerHTML = html; | ||
180 | //Creating return object | ||
181 | return {hea |