aboutsummaryrefslogtreecommitdiff
path: root/js/io/system/fileio.js
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-01-30 14:35:11 -0800
committerJose Antonio Marquez2012-01-30 14:35:11 -0800
commit2f61dfca4466661e1ea23888675a86b601b58c63 (patch)
treea86bf1b6d3f98776f0b329f2f8f0a3cc2e2dc71c /js/io/system/fileio.js
parent4d5f9c451524829f55ddf26642cb9fc28228b6ce (diff)
downloadninja-2f61dfca4466661e1ea23888675a86b601b58c63.tar.gz
Setting up new file
Adding base functionality to creating files.
Diffstat (limited to 'js/io/system/fileio.js')
-rwxr-xr-xjs/io/system/fileio.js169
1 files changed, 131 insertions, 38 deletions
diff --git a/js/io/system/fileio.js b/js/io/system/fileio.js
index 1d76a91b..b3158a68 100755
--- a/js/io/system/fileio.js
+++ b/js/io/system/fileio.js
@@ -3,22 +3,139 @@ 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.isIoServiceActive()) {
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
83
84
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 /*
138open: {
22 enumerable: true, 139 enumerable: true,
23 value: function(doc, type, uri, server) { 140 value: function(doc, type, uri, server) {
24 // 141 //
@@ -70,32 +187,7 @@ create: {
70 enumerable: true, 187 enumerable: true,
71 value: function(type, id, components) { 188 value: function(type, id, components) {
72 189
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 190
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 191
100 // 192 //
101 var contents, counter = 0; 193 var contents, counter = 0;
@@ -215,6 +307,7 @@ create: {
215 return css; 307 return css;
216 } 308 }
217 } 309 }
310*/
218 311
219 312
220 313