aboutsummaryrefslogtreecommitdiff
path: root/js/mediators
diff options
context:
space:
mode:
Diffstat (limited to 'js/mediators')
-rwxr-xr-x[-rw-r--r--]js/mediators/drag-drop-mediator.js0
-rwxr-xr-x[-rw-r--r--]js/mediators/element-mediator.js0
-rw-r--r--js/mediators/io-mediator.js167
-rwxr-xr-x[-rw-r--r--]js/mediators/keyboard-mediator.js0
-rwxr-xr-x[-rw-r--r--]js/mediators/mouse-mediator.js0
5 files changed, 167 insertions, 0 deletions
diff --git a/js/mediators/drag-drop-mediator.js b/js/mediators/drag-drop-mediator.js
index ede71383..ede71383 100644..100755
--- a/js/mediators/drag-drop-mediator.js
+++ b/js/mediators/drag-drop-mediator.js
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..2f286e5e
--- /dev/null
+++ b/js/mediators/io-mediator.js
@@ -0,0 +1,167 @@
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 //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 }
142 },
143 ////////////////////////////////////////////////////////////////////
144 //
145 fileSaveAs: {
146 enumerable: false,
147 value: function (copyTo, copyFrom, callback) {
148 //
149 }
150 },
151 ////////////////////////////////////////////////////////////////////
152 //
153 parseHtmlToNinjaTemplate: {
154 enumerable: false,
155 value: function (html) {
156 //Creating temp object to mimic HTML
157 var doc = window.document.implementation.createHTMLDocument(), template;
158 //Setting content to temp
159 doc.getElementsByTagName('html')[0].innerHTML = html;
160 //Creating return object
161 return {head: doc.head.innerHTML, body: doc.body.innerHTML, document: doc};
162 }
163 }
164 ////////////////////////////////////////////////////////////////////
165});
166////////////////////////////////////////////////////////////////////////
167//////////////////////////////////////////////////////////////////////// \ No newline at end of file
diff --git a/js/mediators/keyboard-mediator.js b/js/mediators/keyboard-mediator.js
index a1fdead3..a1fdead3 100644..100755
--- a/js/mediators/keyboard-mediator.js
+++ b/js/mediators/keyboard-mediator.js
diff --git a/js/mediators/mouse-mediator.js b/js/mediators/mouse-mediator.js
index cef6c6c4..cef6c6c4 100644..100755
--- a/js/mediators/mouse-mediator.js
+++ b/js/mediators/mouse-mediator.js