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.js175
1 files changed, 137 insertions, 38 deletions
diff --git a/js/io/system/fileio.js b/js/io/system/fileio.js
index 1d76a91b..38ab05e8 100644..100755
--- a/js/io/system/fileio.js
+++ b/js/io/system/fileio.js
@@ -3,22 +3,145 @@ This 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/> 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. 4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */ 5</copyright> */
6/* /////////////////////////////////////////////////////////////////////
7////////////////////////////////////////////////////////////////////////
8NOTES:
6 9
7//Required modules 10 For newFile, only the 'uri' is required, if contents is empty, such
8var 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////////////////////////////////////////////////////////////////////////
15///////////////////////////////////////////////////////////////////// */
16//
17var Montage = require("montage/core/core").Montage,
18 CoreIoApi = require("js/io/system/coreioapi").CoreIoApi;
19////////////////////////////////////////////////////////////////////////
9//Exporting as File I/O 20//Exporting as File I/O
10exports.FileIo = (require("montage/core/core").Montage).create(Object.prototype, { 21exports.FileIo = Montage.create(Object.prototype, {
11 /*
12create: {
13 enumerable: true,
14 value: function (type) {
15 //
16 }
17 },
18*/
19 //////////////////////////////////////////////////////////////////// 22 ////////////////////////////////////////////////////////////////////
20 // 23 //newFile Object (*required): {uri*, contents, contentType}
21 open: { 24 //Return codes
25 // 204: File exists | 400: File exists | 404: File does not exists
26 // 201: File succesfully created | 500: Unknown | undefined: Unknown
27 newFile: {
28 enumerable: true,
29 value: function(file) {
30 //Checking for API to be available
31 if (!CoreIoApi.cloudAvailable()) {
32 //API not available, no IO action taken
33 return null;
34 }
35 //Peforming check for file to exist
36 var check = CoreIoApi.fileExists(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 = CoreIoApi.createFile(file);
48 //Storing status to be returned (for UI handling)
49 if (create.success) {
50 status = check.status;
51 }
52 break;
53 default:
54 //Unknown Error
55 break;
56 }
57 } else {
58 //Unknown Error
59 }
60 //Returning resulting code
61 return status;
62 }
63 },
64 readFile: {
65 enumerable: true,
66 value: function() {
67 //
68 }
69 },
70 saveFile: {
71 enumerable: true,
72 value: function() {
73 //
74 }
75 },
76 copyFile: {
77 enumerable: true,
78 value: function() {
79 //
80 }
81 },
82 infoFile: {
83 enumerable: true,
84 value: function() {
85 //
86 }
87 }
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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 /*
144open: {
22 enumerable: true, 145 enumerable: true,
23 value: function(doc, type, uri, server) { 146 value: function(doc, type, uri, server) {
24 // 147 //
@@ -70,32 +193,7 @@ create: {
70 enumerable: true, 193 enumerable: true,
71 value: function(type, id, components) { 194 value: function(type, id, components) {
72 195
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 196
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 197
100 // 198 //
101 var contents, counter = 0; 199 var contents, counter = 0;
@@ -215,6 +313,7 @@ create: {
215 return css; 313 return css;
216 } 314 }
217 } 315 }
316*/
218 317
219 318
220 319