diff options
Diffstat (limited to 'js/mediators/io-mediator.js')
-rw-r--r-- | js/mediators/io-mediator.js | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js new file mode 100644 index 00000000..f2f2f642 --- /dev/null +++ b/js/mediators/io-mediator.js | |||
@@ -0,0 +1,147 @@ | |||
1 | /* <copyright> | ||
2 | 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/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | //////////////////////////////////////////////////////////////////////// | ||
8 | // | ||
9 | var Montage = require("montage/core/core").Montage, | ||
10 | Component = require("montage/ui/component").Component, | ||
11 | FileIo = require("js/io/system/fileio").FileIo, | ||
12 | ProjectIo = require("js/io/system/projectio").ProjectIo; | ||
13 | //////////////////////////////////////////////////////////////////////// | ||
14 | // | ||
15 | exports.IoMediator = Montage.create(Component, { | ||
16 | //////////////////////////////////////////////////////////////////// | ||
17 | // | ||
18 | hasTemplate: { | ||
19 | enumerable: false, | ||
20 | value: false | ||
21 | }, | ||
22 | //////////////////////////////////////////////////////////////////// | ||
23 | // | ||
24 | deserializedFromTemplate: { | ||
25 | enumerable: false, | ||
26 | value: function () { | ||
27 | // | ||
28 | } | ||
29 | }, | ||
30 | //////////////////////////////////////////////////////////////////// | ||
31 | // | ||
32 | fio: { | ||
33 | enumerable: false, | ||
34 | value: FileIo | ||
35 | }, | ||
36 | //////////////////////////////////////////////////////////////////// | ||
37 | // | ||
38 | pio: { | ||
39 | enumerable: false, | ||
40 | value: ProjectIo | ||
41 | }, | ||
42 | //////////////////////////////////////////////////////////////////// | ||
43 | // | ||
44 | fileNew: { | ||
45 | enumerable: false, | ||
46 | value: function (file, template, callback) { | ||
47 | //Loading template from template URL | ||
48 | var xhr = new XMLHttpRequest(), result; | ||
49 | xhr.open("GET", template, false); | ||
50 | xhr.send(); | ||
51 | if (xhr.readyState === 4) { | ||
52 | //Making call to create file, checking for return code | ||
53 | switch (this.fio.newFile({uri: file, contents: xhr.response})) { | ||
54 | case 201: | ||
55 | result = {status: 201, success: true, uri: file}; | ||
56 | break; | ||
57 | case 204: | ||
58 | result = {status: 204, success: false, uri: file}; | ||
59 | break; | ||
60 | case 400: | ||
61 | result = {status: 400, success: false, uri: file}; | ||
62 | break; | ||
63 | default: | ||
64 | result = {status: 500, success: false, uri: file}; | ||
65 | break; | ||
66 | } | ||
67 | } else { | ||
68 | result = {status: 500, success: false, uri: file}; | ||
69 | } | ||
70 | //Sending result to callback if requested for handling | ||
71 | if (callback) callback(result); | ||
72 | //Codes | ||
73 | // 204: File exists | 400: File exists | ||
74 | // 201: File succesfully created | 500: Unknown (Probably cloud API not running) | ||
75 | } | ||
76 | }, | ||
77 | //////////////////////////////////////////////////////////////////// | ||
78 | // | ||
79 | fileOpen: { | ||
80 | enumerable: false, | ||
81 | value: function (file, callback) { | ||
82 | //Reading file (Ninja doesn't really open a file, all in browser memory) | ||
83 | var read = this.fio.readFile({uri: file}), result; | ||
84 | //Checking for status | ||
85 | switch(read.status) { | ||
86 | case 204: | ||
87 | //Creating and formatting result object for callbak | ||
88 | result = read.file.details; | ||
89 | //TODO: Add handling for converting HTML to Ninja format | ||
90 | result.content = read.file.content; | ||
91 | result.status = read.status; | ||
92 | // | ||
93 | if (callback) callback(result); | ||
94 | break; | ||
95 | case 404: | ||
96 | //File does not exists | ||
97 | if (callback) callback({status: read.status}); | ||
98 | break; | ||
99 | default: | ||
100 | //Unknown | ||
101 | if (callback) callback({status: 500}); | ||
102 | break; | ||
103 | } | ||
104 | /* | ||
105 | //////////////////////////////////////////////////////////// | ||
106 | //////////////////////////////////////////////////////////// | ||
107 | //Return Object Description | ||
108 | Object.status (Always presents for handling) | ||
109 | 204: File exists (Success) | ||
110 | 404: File does not exists (Failure) | ||
111 | 500: Unknown (Probably cloud API not running) | ||
112 | |||
113 | (Below only present if succesfull 204) | ||
114 | |||
115 | Object.content | ||
116 | Object.extension | ||
117 | Object.name | ||
118 | Object.uri | ||
119 | Object.creationDate | ||
120 | Object.modifiedDate | ||
121 | Object.readOnly | ||
122 | Object.size | ||
123 | //////////////////////////////////////////////////////////// | ||
124 | //////////////////////////////////////////////////////////// | ||
125 | */ | ||
126 | } | ||
127 | }, | ||
128 | //////////////////////////////////////////////////////////////////// | ||
129 | // | ||
130 | fileSave: { | ||
131 | enumerable: false, | ||
132 | value: function (file, callback) { | ||
133 | // | ||
134 | } | ||
135 | }, | ||
136 | //////////////////////////////////////////////////////////////////// | ||
137 | // | ||
138 | fileSaveAs: { | ||
139 | enumerable: false, | ||
140 | value: function (file, copy, callback) { | ||
141 | // | ||
142 | } | ||
143 | } | ||
144 | //////////////////////////////////////////////////////////////////// | ||
145 | }); | ||
146 | //////////////////////////////////////////////////////////////////////// | ||
147 | //////////////////////////////////////////////////////////////////////// \ No newline at end of file | ||