diff options
Diffstat (limited to 'js/io/system/fileio.js')
-rwxr-xr-x[-rw-r--r--] | js/io/system/fileio.js | 217 |
1 files changed, 178 insertions, 39 deletions
diff --git a/js/io/system/fileio.js b/js/io/system/fileio.js index 1d76a91b..7bf4d41f 100644..100755 --- a/js/io/system/fileio.js +++ b/js/io/system/fileio.js | |||
@@ -4,21 +4,185 @@ 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 | /* ///////////////////////////////////////////////////////////////////// |
8 | var Serializer = require("montage/core/serializer").Serializer; | 8 | //////////////////////////////////////////////////////////////////////// |
9 | NOTES: | ||
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 | // | ||
20 | var Montage = require("montage/core/core").Montage, | ||
21 | Component = require("montage/ui/component").Component; | ||
22 | //////////////////////////////////////////////////////////////////////// | ||
9 | //Exporting as File I/O | 23 | //Exporting as File I/O |
10 | exports.FileIo = (require("montage/core/core").Montage).create(Object.prototype, { | 24 | exports.FileIo = Montage.create(Component, { |
11 | /* | ||
12 | create: { | ||
13 | enumerable: true, | ||
14 | value: function (type) { | ||
15 | // | ||
16 | } | ||
17 | }, | ||
18 | */ | ||
19 | //////////////////////////////////////////////////////////////////// | 25 | //////////////////////////////////////////////////////////////////// |
26 | //newFile Object (*required): {uri*, contents, contentType} | ||
27 | newFile: { | ||
28 | enumerable: true, | ||
29 | value: function(file) { | ||
30 | //Checking for API to be available | ||
31 | if (!this.application.ninja.coreIoApi.cloudAvailable()) { | ||
32 | //API not available, no IO action taken | ||
33 | return null; | ||
34 | } | ||
35 | //Peforming check for file to exist | ||
36 | var check = this.application.ninja.coreIoApi.fileExists({uri: file.uri}), status, create; | ||
37 | //Upon successful check, handling results | ||
38 | if (check.success) { | ||
39 | //Handling status of check | ||
40 | switch (check.status) { | ||
41 | case 204: | ||
42 | //Storing status to be returned (for UI handling) | ||
43 | status = check.status; | ||
44 | break; | ||
45 | case 404: | ||
46 | //File does not exists, ready to be created | ||
47 | create = this.application.ninja.coreIoApi.createFile(file); | ||
48 | status = create.status; | ||
49 | break; | ||
50 | default: | ||
51 | //Unknown Error | ||
52 | break; | ||
53 | } | ||
54 | } else { | ||
55 | //Unknown Error | ||
56 | } | ||
57 | //Returning resulting code | ||
58 | return status; | ||
59 | // 204: File exists | 400: File exists | 404: File does not exists | ||
60 | // 201: File succesfully created | 500: Unknown | undefined: Unknown | ||
61 | } | ||
62 | }, | ||
63 | //////////////////////////////////////////////////////////////////// | ||
20 | // | 64 | // |
21 | open: { | 65 | readFile: { |
66 | enumerable: true, | ||
67 | value: function() { | ||
68 | //Checking for API to be available | ||
69 | if (!this.application.ninja.coreIoApi.cloudAvailable()) { | ||
70 | //API not available, no IO action taken | ||
71 | return null; | ||
72 | } | ||
73 | // | ||
74 | } | ||
75 | }, | ||
76 | //////////////////////////////////////////////////////////////////// | ||
77 | // | ||
78 | saveFile: { | ||
79 | enumerable: true, | ||
80 | value: function() { | ||
81 | //Checking for API to be available | ||
82 | if (!this.application.ninja.coreIoApi.cloudAvailable()) { | ||
83 | //API not available, no IO action taken | ||
84 | return null; | ||
85 | } | ||
86 | // | ||
87 | } | ||
88 | }, | ||
89 | //////////////////////////////////////////////////////////////////// | ||
90 | // | ||
91 | deleteFile: { | ||
92 | enumerable: true, | ||
93 | value: function() { | ||
94 | //Checking for API to be available | ||
95 | if (!this.application.ninja.coreIoApi.cloudAvailable()) { | ||
96 | //API not available, no IO action taken | ||
97 | return null; | ||
98 | } | ||
99 | // | ||
100 | } | ||
101 | }, | ||
102 | //////////////////////////////////////////////////////////////////// | ||
103 | // | ||
104 | copyFile: { | ||
105 | enumerable: true, | ||
106 | value: function() { | ||
107 | //Checking for API to be available | ||
108 | if (!this.application.ninja.coreIoApi.cloudAvailable()) { | ||
109 | //API not available, no IO action taken | ||
110 | return null; | ||
111 | } | ||
112 | // | ||
113 | } | ||
114 | }, | ||
115 | //////////////////////////////////////////////////////////////////// | ||
116 | // | ||
117 | infoFile: { | ||
118 | enumerable: true, | ||
119 | value: function() { | ||
120 | //Checking for API to be available | ||
121 | if (!this.application.ninja.coreIoApi.cloudAvailable()) { | ||
122 | //API not available, no IO action taken | ||
123 | return null; | ||
124 | } | ||
125 | // | ||
126 | } | ||
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 | open: { | ||
22 | enumerable: true, | 186 | enumerable: true, |
23 | value: function(doc, type, uri, server) { | 187 | value: function(doc, type, uri, server) { |
24 | // | 188 | // |
@@ -70,32 +234,7 @@ create: { | |||
70 | enumerable: true, | 234 | enumerable: true, |
71 | value: function(type, id, components) { | 235 | value: function(type, id, components) { |
72 | 236 | ||
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 | 237 | ||
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 | 238 | ||
100 | // | 239 | // |
101 | var contents, counter = 0; | 240 | var contents, counter = 0; |
@@ -215,12 +354,12 @@ create: { | |||
215 | return css; | 354 | return css; |
216 | } | 355 | } |
217 | } | 356 | } |
357 | */ | ||
218 |