diff options
author | Valerio Virgillito | 2012-04-04 15:58:49 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-04-04 15:58:49 -0700 |
commit | 347b4179be5581841fc94825dcb18901e625c670 (patch) | |
tree | 93556d56b049aa47c615a8b58add230cd96da166 /js/mediators | |
parent | 9f1806a7134ec4744a8009e6a7467f5cea04cabf (diff) | |
parent | e721a7c1009f298a1bd8fea583da14535e039880 (diff) | |
download | ninja-347b4179be5581841fc94825dcb18901e625c670.tar.gz |
Merge branch 'refs/heads/master' into components
Diffstat (limited to 'js/mediators')
-rw-r--r-- | js/mediators/io-mediator.js | 1096 |
1 files changed, 544 insertions, 552 deletions
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js index 1efbb8bb..057a849d 100644 --- a/js/mediators/io-mediator.js +++ b/js/mediators/io-mediator.js | |||
@@ -14,654 +14,646 @@ var Montage = require("montage/core/core").Montage, | |||
14 | //////////////////////////////////////////////////////////////////////// | 14 | //////////////////////////////////////////////////////////////////////// |
15 | // | 15 | // |
16 | exports.IoMediator = Montage.create(Component, { | 16 | exports.IoMediator = Montage.create(Component, { |
17 | //////////////////////////////////////////////////////////////////// | 17 | //////////////////////////////////////////////////////////////////// |
18 | // | 18 | // |
19 | hasTemplate: { | 19 | hasTemplate: { |
20 | enumerable: false, | 20 | enumerable: false, |
21 | value: false | 21 | value: false |
22 | }, | 22 | }, |
23 | //////////////////////////////////////////////////////////////////// | 23 | //////////////////////////////////////////////////////////////////// |
24 | // | 24 | // |
25 | deserializedFromTemplate: { | 25 | deserializedFromTemplate: { |
26 | enumerable: false, | 26 | enumerable: false, |
27 | value: function () { | 27 | value: function () { |
28 | // | 28 | // |
29 | } | 29 | } |
30 | }, | 30 | }, |
31 | //////////////////////////////////////////////////////////////////// | 31 | //////////////////////////////////////////////////////////////////// |
32 | // | 32 | // |
33 | fio: { | 33 | fio: { |
34 | enumerable: false, | 34 | enumerable: false, |
35 | value: FileIo | 35 | value: FileIo |
36 | }, | 36 | }, |
37 | //////////////////////////////////////////////////////////////////// | 37 | //////////////////////////////////////////////////////////////////// |
38 | // | 38 | // |
39 | pio: { | 39 | pio: { |
40 | enumerable: false, | 40 | enumerable: false, |
41 | value: ProjectIo | 41 | value: ProjectIo |
42 | }, | 42 | }, |
43 | //////////////////////////////////////////////////////////////////// | 43 | //////////////////////////////////////////////////////////////////// |
44 | // | 44 | // |
45 | getAppTemplatesUrlRegEx: { | 45 | getAppTemplatesUrlRegEx: { |
46 | enumerable: false, | 46 | enumerable: false, |
47 | value: function () { | 47 | value: function () { |
48 | var regex = new RegExp(chrome.extension.getURL('js/document/templates/montage-html').replace(/\//gi, '\\\/'), 'gi'); | 48 | var regex = new RegExp(chrome.extension.getURL('js/document/templates/montage-html').replace(/\//gi, '\\\/'), 'gi'); |
49 | return regex; | 49 | return regex; |
50 | } | 50 | } |
51 | }, | 51 | }, |
52 | //////////////////////////////////////////////////////////////////// | 52 | //////////////////////////////////////////////////////////////////// |
53 | // | 53 | // |
54 | fileNew: { | 54 | fileNew: { |
55 | enumerable: false, | 55 | enumerable: false, |
56 | value: function (file, template, callback) { | 56 | value: function (file, template, callback) { |
57 | //Loading template from template URL | 57 | //Loading template from template URL |
58 | var xhr = new XMLHttpRequest(), result; | 58 | var xhr = new XMLHttpRequest(), result; |
59 | xhr.open("GET", template, false); | 59 | xhr.open("GET", template, false); |
60 | xhr.send(); | 60 | xhr.send(); |
61 | if (xhr.readyState === 4) { | 61 | if (xhr.readyState === 4) { |
62 | //Making call to create file, checking for return code | 62 | //Making call to create file, checking for return code |
63 | switch (this.fio.newFile({uri: file, contents: xhr.response})) { | 63 | switch (this.fio.newFile({ uri: file, contents: xhr.response })) { |
64 | case 201: | 64 | case 201: |
65 | result = {status: 201, success: true, uri: file}; | 65 | result = { status: 201, success: true, uri: file }; |
66 | break; | 66 | break; |
67 | case 204: | 67 | case 204: |
68 | result = {status: 204, success: false, uri: file}; | 68 | result = { status: 204, success: false, uri: file }; |
69 | break; | 69 | break; |
70 | case 400: | 70 | case 400: |
71 | result = {status: 400, success: false, uri: file}; | 71 | result = { status: 400, success: false, uri: file }; |
72 | break; | 72 | break; |
73 | default: | 73 | default: |
74 | result = {status: 500, success: false, uri: file}; | 74 | result = { status: 500, success: false, uri: file }; |
75 | break; | 75 | break; |
76 | } | 76 | } |
77 | } else { | 77 | } else { |
78 | result = {status: 500, success: false, uri: file}; | 78 | result = { status: 500, success: false, uri: file }; |
79 | } | 79 | } |
80 | //Sending result to callback if requested for handling | 80 | //Sending result to callback if requested for handling |
81 | if (callback) callback(result); | 81 | if (callback) callback(result); |
82 | //Codes | 82 | //Codes |
83 | // 204: File exists | 400: File exists | 83 | // 204: File exists | 400: File exists |
84 | // 201: File succesfully created | 500: Unknown (Probably cloud API not running) | 84 | // 201: File succesfully created | 500: Unknown (Probably cloud API not running) |
85 | } | 85 | } |
86 | }, | 86 | }, |
87 | //////////////////////////////////////////////////////////////////// | 87 | //////////////////////////////////////////////////////////////////// |
88 | // | 88 | // |
89 | fileOpen: { | 89 | fileOpen: { |
90 | enumerable: false, | 90 | enumerable: false, |
91 | value: function (file, callback) { | 91 | value: function (file, callback) { |
92 | //Reading file (Ninja doesn't really open a file, all in browser memory) | 92 | //Reading file (Ninja doesn't really open a file, all in browser memory) |
93 | var read = this.fio.readFile({uri: file}), result; | 93 | var read = this.fio.readFile({ uri: file }), result; |
94 | //Checking for status | 94 | //Checking for status |
95 | switch(read.status) { | 95 | switch (read.status) { |
96 | case 204: | 96 | case 204: |
97 | //Creating and formatting result object for callbak | 97 | //Creating and formatting result object for callbak |
98 | result = read.file.details; | 98 | result = read.file.details; |
99 | result.root = read.file.details.uri.replace(read.file.details.name, ""); | 99 | result.root = read.file.details.uri.replace(read.file.details.name, ""); |
100 | //Checking for type of content to returns | 100 | //Checking for type of content to returns |
101 | if (result.extension !== 'html' && result.extension !== 'htm') { | 101 | if (result.extension !== 'html' && result.extension !== 'htm') { |
102 | //Simple string | 102 | //Simple string |
103 | result.content = read.file.content; | 103 | result.content = read.file.content; |
104 | } else { | 104 | } else { |
105 | //Object to be used by Ninja Template | 105 | //Object to be used by Ninja Template |
106 | result.content = this.parseHtmlToNinjaTemplate(read.file.content); | 106 | result.content = this.parseHtmlToNinjaTemplate(read.file.content); |
107 | } | 107 | } |
108 | //Status of call | 108 | //Status of call |
109 | result.status = read.status; | 109 | result.status = read.status; |
110 | //Calling back with result | 110 | //Calling back with result |
111 | if (callback) callback(result); | 111 | if (callback) callback(result); |
112 | break; | 112 | break; |
113 | case 404: | 113 | case 404: |
114 | //File does not exists | 114 | //File does not exists |
115 | if (callback) callback({status: read.status}); | 115 | if (callback) callback({ status: read.status }); |
116 | break; | 116 | break; |
117 | default: | 117 | default: |
118 | //Unknown | 118 | //Unknown |
119 | if (callback) callback({status: 500}); | 119 | if (callback) callback({ status: 500 }); |
120 | break; | 120 | break; |
121 | } | 121 | } |
122 | /* | 122 | /* |
123 | //////////////////////////////////////////////////////////// | 123 | //////////////////////////////////////////////////////////// |
124 | //////////////////////////////////////////////////////////// | 124 | //////////////////////////////////////////////////////////// |
125 | //Return Object Description | 125 | //Return Object Description |
126 | Object.status (Always presents for handling) | 126 | Object.status (Always presents for handling) |
127 | 204: File exists (Success) | 127 | 204: File exists (Success) |
128 | 404: File does not exists (Failure) | 128 | 404: File does not exists (Failure) |
129 | 500: Unknown (Probably cloud API not running) | 129 | 500: Unknown (Probably cloud API not running) |
130 | 130 | ||
131 | (Below only present if succesfull 204) | 131 | (Below only present if succesfull 204) |
132 | 132 | ||
133 | Object.content | 133 | Object.content |
134 | Object.extension | 134 | Object.extension |
135 | Object.name | 135 | Object.name |
136 | Object.uri | 136 | Object.uri |
137 | Object.creationDate | 137 | Object.creationDate |
138 | Object.modifiedDate | 138 | Object.modifiedDate |
139 | Object.readOnly | 139 | Object.readOnly |
140 | Object.size | 140 | Object.size |
141 | //////////////////////////////////////////////////////////// | 141 | //////////////////////////////////////////////////////////// |
142 | //////////////////////////////////////////////////////////// | 142 | //////////////////////////////////////////////////////////// |
143 | */ | 143 | */ |
144 | } | 144 | } |
145 | }, | 145 | }, |
146 | //////////////////////////////////////////////////////////////////// | 146 | //////////////////////////////////////////////////////////////////// |
147 | // | 147 | // |
148 | fileSave: { | 148 | fileSave: { |
149 | enumerable: false, | 149 | enumerable: false, |
150 | value: function (file, callback) { | 150 | value: function (file, callback) { |
151 | // | 151 | // |
152 | var contents, save; | 152 | var contents, save; |