diff options
Diffstat (limited to 'js/mediators')
-rwxr-xr-x[-rw-r--r--] | js/mediators/drag-drop-mediator.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | js/mediators/element-mediator.js | 0 | ||||
-rw-r--r-- | js/mediators/io-mediator.js | 120 | ||||
-rwxr-xr-x[-rw-r--r--] | js/mediators/keyboard-mediator.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | js/mediators/mouse-mediator.js | 0 |
5 files changed, 120 insertions, 0 deletions
diff --git a/js/mediators/drag-drop-mediator.js b/js/mediators/drag-drop-mediator.js index ede71383..ede71383 100644..100755 --- a/js/mediators/drag-drop-mediator.js +++ b/js/mediators/drag-drop-mediator.js | |||
diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js index 9aefbca6..9aefbca6 100644..100755 --- a/js/mediators/element-mediator.js +++ b/js/mediators/element-mediator.js | |||
diff --git a/js/mediators/io-mediator.js b/js/mediators/io-mediator.js new file mode 100644 index 00000000..66fea8b3 --- /dev/null +++ b/js/mediators/io-mediator.js | |||
@@ -0,0 +1,120 @@ | |||
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 | fileNew: { | ||
39 | enumerable: false, | ||
40 | value: function (file, template, callback) { | ||
41 | // | ||
42 | var xhr = new XMLHttpRequest(), result; | ||
43 | xhr.open("GET", template, false); | ||
44 | xhr.send(); | ||
45 | if (xhr.readyState === 4) { | ||
46 | // | ||
47 | switch (this.fio.newFile({uri: file, contents: xhr.response})) { | ||
48 | case 201: | ||
49 | result = {status: 201, success: true, uri: file}; | ||
50 | break; | ||
51 | case 204: | ||
52 | result = {status: 204, success: false, uri: file}; | ||
53 | break; | ||
54 | case 400: | ||
55 | result = {status: 400, success: false, uri: file}; | ||
56 | break; | ||
57 | default: | ||
58 | result = {status: 500, success: false, uri: file}; | ||
59 | break; | ||
60 | } | ||
61 | } else { | ||
62 | result = {status: 500, success: false, uri: file}; | ||
63 | } | ||
64 | // | ||
65 | if (callback) callback(result); | ||
66 | } | ||
67 | }, | ||
68 | //////////////////////////////////////////////////////////////////// | ||
69 | // | ||
70 | fileOpen: { | ||
71 | enumerable: false, | ||
72 | value: function (file, callback) { | ||
73 | var response = "", fileContent="", filename="", fileType="js", returnObj=null; | ||
74 | |||
75 | response = this.application.ninja.coreIoApi.openFile({"uri":file.uri}); | ||
76 | if((response.success === true) && ((response.status === 200) || (response.status === 304))){ | ||
77 | fileContent = response.content; | ||
78 | } | ||
79 | |||
80 | |||
81 | //TODO : format html content to render in design view | ||
82 | |||
83 | |||
84 | filename = this.getFileNameFromPath(file.uri); | ||
85 | if(file.uri.indexOf('.') != -1){ | ||
86 | fileType = file.uri.substr(file.uri.lastIndexOf('.') + 1); | ||
87 | } | ||
88 | returnObj = {"type": ""+fileType, "name": ""+filename, "source": fileContent, "uri": file.uri}; | ||
89 | callback(returnObj); | ||
90 | } | ||
91 | }, | ||
92 | //////////////////////////////////////////////////////////////////// | ||
93 | // | ||
94 | fileSave: { | ||
95 | enumerable: false, | ||
96 | value: function (file, callback) { | ||
97 | // | ||
98 | } | ||
99 | }, | ||
100 | //////////////////////////////////////////////////////////////////// | ||
101 | // | ||
102 | fileSaveAs: { | ||
103 | enumerable: false, | ||
104 | value: function (file, copy, callback) { | ||
105 | // | ||
106 | } | ||
107 | }, | ||
108 | //////////////////////////////////////////////////////////////////// | ||
109 | ///// Return the last part of a path (e.g. filename) | ||
110 | getFileNameFromPath : { | ||
111 | value: function(path) { | ||
112 | path = path.replace(/[/\\]$/g,""); | ||
113 | path = path.replace(/\\/g,"/"); | ||
114 | return path.substr(path.lastIndexOf('/') + 1); | ||
115 | } | ||
116 | } | ||
117 | //////////////////////////////////////////////////////////////////// | ||
118 | }); | ||
119 | //////////////////////////////////////////////////////////////////////// | ||
120 | //////////////////////////////////////////////////////////////////////// \ No newline at end of file | ||
diff --git a/js/mediators/keyboard-mediator.js b/js/mediators/keyboard-mediator.js index a1fdead3..a1fdead3 100644..100755 --- a/js/mediators/keyboard-mediator.js +++ b/js/mediators/keyboard-mediator.js | |||
diff --git a/js/mediators/mouse-mediator.js b/js/mediators/mouse-mediator.js index cef6c6c4..cef6c6c4 100644..100755 --- a/js/mediators/mouse-mediator.js +++ b/js/mediators/mouse-mediator.js | |||