aboutsummaryrefslogtreecommitdiff
path: root/js/io/system/fileio.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/io/system/fileio.js')
-rwxr-xr-x[-rw-r--r--]js/io/system/fileio.js220
1 files changed, 181 insertions, 39 deletions
diff --git a/js/io/system/fileio.js b/js/io/system/fileio.js
index 1d76a91b..2c49e849 100644..100755
--- a/js/io/system/fileio.js
+++ b/js/io/system/fileio.js
@@ -4,21 +4,188 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. 4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */ 5</copyright> */
6 6
7//Required modules 7/* /////////////////////////////////////////////////////////////////////
8var Serializer = require("montage/core/serializer").Serializer; 8////////////////////////////////////////////////////////////////////////
9NOTES:
10
11 For newFile, only the 'uri' is required, if contents is empty, such
12 empty file will be created. 'contents' should be a string to be saved
13 as the file. 'contentType' is the mime type of the file.
14
15 Core API reference in NINJA: this.application.ninja.coreIoApi
16
17////////////////////////////////////////////////////////////////////////
18///////////////////////////////////////////////////////////////////// */
19//
20var Montage = require("montage/core/core").Montage;
21////////////////////////////////////////////////////////////////////////
9//Exporting as File I/O 22//Exporting as File I/O
10exports.FileIo = (require("montage/core/core").Montage).create(Object.prototype, { 23exports.FileIo = Montage.create(Object.prototype, {
11 /*
12create: {
13 enumerable: true,
14 value: function (type) {
15 //
16 }
17 },
18*/
19 //////////////////////////////////////////////////////////////////// 24 ////////////////////////////////////////////////////////////////////
25 //newFile Object (*required): {uri*, contents, contentType}
26 //Return codes
27 // 204: File exists | 400: File exists | 404: File does not exists
28 // 201: File succesfully created | 500: Unknown | undefined: Unknown
29 newFile: {
30 enumerable: true,
31 value: function(file) {
32 //Checking for API to be available
33 if (!this.application.ninja.coreIoApi.cloudAvailable()) {
34 //API not available, no IO action taken
35 return null;
36 }
37 //Peforming check for file to exist
38 var check = this.application.ninja.coreIoApi.fileExists(file.uri), status, create;
39 //Upon successful check, handling results
40 if (check.success) {
41 //Handling status of check
42 switch (check.status) {
43 case 204:
44 //Storing status to be returned (for UI handling)
45 status = check.status;
46 break;
47 case 404:
48 //File does not exists, ready to be created
49 create = this.application.ninja.coreIoApi.createFile(file);
50 //Storing status to be returned (for UI handling)
51 if (create.success) {
52 status = check.status;
53 }
54 break;
55 default:
56 //Unknown Error
57 break;
58 }
59 } else {
60 //Unknown Error
61 }
62 //Returning resulting code
63 return status;
64 }
65 },
66 ////////////////////////////////////////////////////////////////////
20 // 67 //
21 open: { 68 readFile: {
69 enumerable: true,
70 value: function() {
71 //Checking for API to be available
72 if (!this.application.ninja.coreIoApi.cloudAvailable()) {
73 //API not available, no IO action taken
74 return null;
75 }
76 //
77 }
78 },
79 ////////////////////////////////////////////////////////////////////
80 //
81 saveFile: {
82 enumerable: true,
83 value: function() {
84 //Checking for API to be available
85 if (!this.application.ninja.coreIoApi.cloudAvailable()) {
86 //API not available, no IO action taken
87 return null;
88 }
89 //
90 }
91 },
92 ////////////////////////////////////////////////////////////////////
93 //
94 deleteFile: {
95 enumerable: true,
96 value: function() {
97 //Checking for API to be available
98 if (!this.application.ninja.coreIoApi.cloudAvailable()) {
99 //API not available, no IO action taken
100 return null;
101 }
102 //
103 }
104 },
105 ////////////////////////////////////////////////////////////////////
106 //
107 copyFile: {
108 enumerable: true,
109 value: function() {
110 //Checking for API to be available
111 if (!this.application.ninja.coreIoApi.cloudAvailable()) {
112 //API not available, no IO action taken
113 return null;
114 }
115 //
116 }
117 },
118 ////////////////////////////////////////////////////////////////////
119 //
120 infoFile: {
121 enumerable: true,
122 value: function() {
123 //Checking for API to be available
124 if (!this.application.ninja.coreIoApi.cloudAvailable()) {
125 //API not available, no IO action taken
126 return null;
127 }
128 //
129 }
130 }
131 ////////////////////////////////////////////////////////////////////
132 ////////////////////////////////////////////////////////////////////
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187 /*
188open: {
22 enumerable: true, 189 enumerable: true,
23 value: function(doc, type, uri, server) { 190 value: function(doc, type, uri, server) {
24 // 191 //
@@ -70,32 +237,7 @@ create: {
70 enumerable: true, 237 enumerable: true,
71 value: function(type, id, components) { 238 value: function(type, id, components) {
72 239
73 /*
74
75 GETS HTML IN LOADED DOCUMENT
76 document.getElementById('userDocument').contentDocument.documentElement.outerHTML
77
78 GETS HTML IN <HEAD> AND <BODY> OR ANYTHING INSIDE <HTML>
79 document.getElementById('userDocument').contentDocument.documentElement.innerHTML
80
81 THE ABOVE METHOD SEEMS TO BE BETTER JUST IN CASE PEOPLE REMOVE THE BODY TAG SINCE NOT REQUIRED IN HTML5
82
83 GETS HTML IN <BODY> ONLY
84 document.getElementById('userDocument').contentDocument.body.innerHTML
85
86 HACK TO GET THE STYLES OF THE ELEMENTS ADDED WHILE DRAWING
87 document.getElementById('userDocument').contentDocument.styleSheets[document.getElementById('userDocument').contentDocument.styleSheets.length-1]
88 240
89 CSS SEEMS TO BE RESERVED WHEN APPENDED, MEANING 0 IN THE ARRAY IS ACTUALLY THE LAST DEFINED STYLE IN THE CSS
90
91 //GETS CSS RULES APPLIED TO ALL OBJECTS CREATED BY THE APP
92 document.getElementById('userDocument').contentDocument.styleSheets[document.getElementById('userDocument').contentDocument.styleSheets.length-1].cssRules
93
94 document.getElementById('userDocument').contentDocument.getElementById('userHead').innerHTML
95 document.getElementById('userDocument').contentDocument.getElementById('UserContent').innerHTML
96 this.getCssFromRules(document.getElementById('userDocument').contentDocument.styleSheets[document.getElementById('userDocument').contentDocument.styleSheets.length-1].cssRules)
97
98 */
99 241
100 // 242 //
101 var contents, counter = 0; 243 var contents, counter = 0;
@@ -215,12 +357,12 @@ create: {
215 return css; 357 return css;
216 }