aboutsummaryrefslogtreecommitdiff
path: root/js/io/system
diff options
context:
space:
mode:
authorPierre Frisch2011-12-22 07:25:50 -0800
committerValerio Virgillito2012-01-27 11:18:17 -0800
commitb89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch)
tree0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /js/io/system
parent2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff)
downloadninja-b89a7ee8b956c96a1dcee995ea840feddc5d4b27.tar.gz
First commit of Ninja to ninja-internal
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'js/io/system')
-rw-r--r--js/io/system/config.xml6
-rw-r--r--js/io/system/fileio.js226
-rw-r--r--js/io/system/filesystem.js723
-rw-r--r--js/io/system/projectio.js63
-rw-r--r--js/io/system/shellapi.js806
5 files changed, 1824 insertions, 0 deletions
diff --git a/js/io/system/config.xml b/js/io/system/config.xml
new file mode 100644
index 00000000..4660d647
--- /dev/null
+++ b/js/io/system/config.xml
@@ -0,0 +1,6 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<!-- COPY TO 'MainApp/cloud' and set your own URLs -->
3<services>
4 <file><![CDATA[http://file.services.ninja.motorola.com/]]></file>
5 <directory><![CDATA[http://directory.services.ninja.motorola.com/]]></directory>
6</services>
diff --git a/js/io/system/fileio.js b/js/io/system/fileio.js
new file mode 100644
index 00000000..1d76a91b
--- /dev/null
+++ b/js/io/system/fileio.js
@@ -0,0 +1,226 @@
1/* <copyright>
2This 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/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7//Required modules
8var Serializer = require("montage/core/serializer").Serializer;
9//Exporting as File I/O
10exports.FileIo = (require("montage/core/core").Montage).create(Object.prototype, {
11 /*
12create: {
13 enumerable: true,
14 value: function (type) {
15 //
16 }
17 },
18*/
19 ////////////////////////////////////////////////////////////////////
20 //
21 open: {
22 enumerable: true,
23 value: function(doc, type, uri, server) {
24 //
25 var file = {}, head, body, h, b;
26 file.uri = uri;
27 file.server = server;
28 //
29 if (doc.content) {
30 if (type === 'html' || type === 'htm') {
31 //
32 h = doc.content.split('</head>');
33 h = h[0].split('<head>');
34 head = h[1];
35 //
36 b = doc.content.split('</body>');
37 b = b[0].split('<body>');
38 body = b[1];
39 //
40 file.type = 'html';
41 file.head = head;
42 file.body = body;
43 } else {
44 //TODO: Add other file type routines
45 file.type = type;
46 file.content = doc.content;
47 }
48 } else {
49 //TODO: File is empty
50 if (type === 'html' || type === 'htm') {
51 head = '';
52 body = '';
53 //
54 file.type = 'html';
55 file.head = head;
56 file.body = body;
57 } else {
58 //TODO: Add other file type routines
59 file.type = type;
60 file.content = doc.content;
61 }
62 }
63 //TODO: Load contents into App
64 //documentManagerModule.DocumentManager.openDocument(file);
65 }
66 },
67 ////////////////////////////////////////////////////////////////////
68 //
69 save: {
70 enumerable: true,
71 value: function(type, id, components) {
72
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
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
100 //
101 var contents, counter = 0;
102 //Checking for document type to go through saving routine
103 switch (type.toLowerCase()) {
104 case 'html':
105 //Checking for components in components panel
106 if (components) {
107 var comps = '', comp, html, mbind, hackParams = '', compSerializer = Serializer.create();
108 //TODO: Check if this is needed since compSerializer was localized
109 compSerializer._serializedObjects = [];
110 //
111 html = document.getElementById(id).contentDocument.getElementById('UserContent').innerHTML;
112 //
113 for(var i in components){
114 //
115 comp = compSerializer.serializeObject(components[i]);
116 //TODO: Remove this HACK
117 if (components[i]._montage_metadata.__proto__.objectName == 'PhotoEditor') {
118 if (components[i].pathToJSON) {
119 hackParams = '"pathToJSON": "'+components[i].pathToJSON+'",\n';
120 }
121 } else {
122
123 }
124 var split = comp.split('"element":U("m-obj://undefined/'+components[i]._element.uuid);
125 comp = split[0]+hackParams+'\t"element":E("#'+components[i]._element.id+split[1];
126 if (document.getElementById(id).contentDocument.getElementById(components[i]._originalElementId).innerHTML.length > 2) {
127 split = html.split(document.getElementById(id).contentDocument.getElementById(components[i]._originalElementId).innerHTML);
128 html = split[0]+split[1];
129 }
130 //
131 if (counter > 0) {
132 comps += ',\n'+comp;
133 } else {
134 comps += comp;
135 }
136 counter++;
137 }
138
139 for(var i in components){
140 //
141 if (components[i]._bindingDescriptors){
142 var split = comps.split('U("m-obj://undefined/'+components[i]._bindingDescriptors.uuid+'", {\n })');
143 comps = split[0]+'\n'+
144 '{\n'+
145 '"'+components[i].binding.sourceProperty+'": {\n'+
146 '"boundObject": U("m-obj://'+components[i].binding.target._montage_metadata.__proto__.objectName+'/'+components[i].binding.target.uuid+'?mId='+components[i].binding.target._montage_metadata.__proto__.moduleId+'"),\n'+
147 '"boundObjectPropertyPath": "'+components[i].binding.targetProperty+'"\n'+
148 '}\n'+
149 '}\n'+
150 split[1];
151 }
152 }
153 var montage = '<script type="text/m-objects">\n\t\t\t{\n'+
154 '\t\t\t"$rootObject": U("m-obj://Application/application-uuid?mId=montage/application", {\n'+
155 '\t\t\t\t"components": [\n'+
156 comps+
157 '\n\t\t\t\t]\n\t\t\t})\n\t\t\t}\n\t\t</script>';
158
159 contents = '<html>\n\t<head>'+document.getElementById(id).contentDocument.getElementById('userHead').innerHTML+'\n\t\t'+montage+'\n\t</head>\n\t<body>\n'+html+'\n\t</body>\n</html>';
160 } else {
161 //No m-js components in file, so saving plain document HTML
162 contents = '<html>\n\t<head>'+document.getElementById(id).contentDocument.getElementById('userHead').innerHTML+'\n\t</head>\n\t<body>\n'+document.getElementById(id).contentDocument.getElementById('UserContent').innerHTML+'\n\t</body>\n</html>';
163 }
164 break;
165 case 'css':
166 contents = this.getCssFromRules(document.getElementById(id).contentDocument.styleSheets[document.getElementById(id).contentDocument.styleSheets.length-1].cssRules);
167 break;
168 case 'js':
169 break;
170 case 'text':
171 break;
172 default:
173 break;
174 }
175
176
177 return contents;
178
179
180
181 }
182 },
183 ////////////////////////////////////////////////////////////////////
184 //
185 saveAs: {
186 enumerable: true,
187 value: function(e) {
188 //TODO: Add functionality
189 console.log('FileIO: saveFileAs');
190 }
191 },
192
193
194
195
196 ////////////////////////////////////////////////////////////////////
197 //Method to return a string from CSS rules (to be saved to a file)
198 getCssFromRules: {
199 enumerable: false,
200 value: function (list) {
201 //Variable to store CSS definitions
202 var i, str, css = '';
203 //Looping through list
204 if (list && list.length > 0) {
205 //Adding each list item to string and also adding breaks
206 for (i = 0; list[i]; i++) {
207 str = list[i].cssText+' ';
208 str = str.replace( new RegExp( "{", "gi" ), "{\n\t" );
209 str = str.replace( new RegExp( "}", "gi" ), "}\n" );