diff options
Diffstat (limited to 'js/io/system/fileio.js')
-rwxr-xr-x[-rw-r--r--] | js/io/system/fileio.js | 196 |
1 files changed, 158 insertions, 38 deletions
diff --git a/js/io/system/fileio.js b/js/io/system/fileio.js index 1d76a91b..f40aa96b 100644..100755 --- a/js/io/system/fileio.js +++ b/js/io/system/fileio.js | |||
@@ -3,22 +3,166 @@ 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/> | 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. | 4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. |
5 | </copyright> */ | 5 | </copyright> */ |
6 | /* ///////////////////////////////////////////////////////////////////// | ||
7 | //////////////////////////////////////////////////////////////////////// | ||
8 | NOTES: | ||
6 | 9 | ||
7 | //Required modules | 10 | For newFile, only the 'uri' is required, if contents is empty, such |
8 | var Serializer = require("montage/core/serializer").Serializer; | 11 | empty file will be created. 'contents' should be a string to be saved |
12 | as the file. 'contentType' is the mime type of the file. | ||
13 | |||
14 | Core API reference in NINJA: this.application.ninja.coreIoApi | ||
15 | |||
16 | //////////////////////////////////////////////////////////////////////// | ||
17 | ///////////////////////////////////////////////////////////////////// */ | ||
18 | // | ||
19 | var Montage = require("montage/core/core").Montage; | ||
20 | //////////////////////////////////////////////////////////////////////// | ||
9 | //Exporting as File I/O | 21 | //Exporting as File I/O |
10 | exports.FileIo = (require("montage/core/core").Montage).create(Object.prototype, { | 22 | exports.FileIo = Montage.create(Object.prototype, { |
11 | /* | ||
12 | create: { | ||
13 | enumerable: true, | ||
14 | value: function (type) { | ||
15 | // | ||
16 | } | ||
17 | }, | ||
18 | */ | ||
19 | //////////////////////////////////////////////////////////////////// | 23 | //////////////////////////////////////////////////////////////////// |
20 | // | 24 | //newFile Object (*required): {uri*, contents, contentType} |
21 | open: { | 25 | //Return codes |
26 | // 204: File exists | 400: File exists | 404: File does not exists | ||
27 | // 201: File succesfully created | 500: Unknown | undefined: Unknown | ||
28 | newFile: { | ||
29 | enumerable: true, | ||
30 | value: function(file) { | ||
31 | //Checking for API to be available | ||
32 | if (!this.application.ninja.coreIoApi.cloudAvailable()) { | ||
33 | //API not available, no IO action taken | ||
34 | return null; | ||
35 | } | ||
36 | //Peforming check for file to exist | ||
37 | var check = this.application.ninja.coreIoApi.fileExists(file.uri), status, create; | ||
38 | //Upon successful check, handling results | ||
39 | if (check.success) { | ||
40 | //Handling status of check | ||
41 | switch (check.status) { | ||
42 | case 204: | ||
43 | //Storing status to be returned (for UI handling) | ||
44 | status = check.status; | ||
45 | break; | ||
46 | case 404: | ||
47 | //File does not exists, ready to be created | ||
48 | create = this.application.ninja.coreIoApi.createFile(file); | ||
49 | //Storing status to be returned (for UI handling) | ||
50 | if (create.success) { | ||
51 | status = check.status; | ||
52 | } | ||
53 | break; | ||
54 | default: | ||
55 | //Unknown Error | ||
56 | break; | ||
57 | } | ||
58 | } else { | ||
59 | //Unknown Error | ||
60 | } | ||
61 | //Returning resulting code | ||
62 | return status; | ||
63 | } | ||
64 | }, | ||
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 | saveFile: { | ||
77 | enumerable: true, | ||
78 | value: function() { | ||
79 | //Checking for API to be available | ||
80 | if (!this.application.ninja.coreIoApi.cloudAvailable()) { | ||
81 | //API not available, no IO action taken | ||
82 | return null; | ||
83 | } | ||
84 | // | ||
85 | } | ||
86 | }, | ||
87 | copyFile: { | ||
88 | enumerable: true, | ||
89 | value: function() { | ||
90 | //Checking for API to be available | ||
91 | if (!this.application.ninja.coreIoApi.cloudAvailable()) { | ||
92 | //API not available, no IO action taken | ||
93 | return null; | ||
94 | } | ||
95 | // | ||
96 | } | ||
97 | }, | ||
98 | infoFile: { | ||
99 | enumerable: true, | ||
100 | value: function() { | ||
101 | //Checking for API to be available | ||
102 | if (!this.application.ninja.coreIoApi.cloudAvailable()) { | ||
103 | //API not available, no IO action taken | ||
104 | return null; | ||
105 | } | ||
106 | // | ||
107 | } | ||
108 | } | ||
109 | |||
110 | |||
111 | |||
112 | |||
113 | |||
114 | |||
115 | |||
116 | |||
117 | |||
118 | |||
119 | |||
120 | |||
121 | |||
122 | |||
123 | |||
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 | open: { | ||
22 | enumerable: true, | 166 | enumerable: true, |
23 | value: function(doc, type, uri, server) { | 167 | value: function(doc, type, uri, server) { |
24 | // | 168 | // |
@@ -70,32 +214,7 @@ create: { | |||
70 | enumerable: true, | 214 | enumerable: true, |
71 | value: function(type, id, components) { | 215 | value: function(type, id, components) { |
72 | 216 | ||
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 | 217 | ||
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 | |||
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 | 218 | ||
100 | // | 219 | // |
101 | var contents, counter = 0; | 220 | var contents, counter = 0; |
@@ -215,6 +334,7 @@ create: { | |||
215 | return css; | 334 | return css; |
216 | } | 335 | } |
217 | } | 336 | } |
337 | */ | ||
218 | 338 | ||
219 | 339 | ||
220 | 340 | ||