diff options
Diffstat (limited to 'js/io/system')
-rwxr-xr-x | js/io/system/coreioapi.js | 105 | ||||
-rwxr-xr-x | js/io/system/fileio.js | 11 |
2 files changed, 96 insertions, 20 deletions
diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js index 43812b3c..3a007028 100755 --- a/js/io/system/coreioapi.js +++ b/js/io/system/coreioapi.js | |||
@@ -10,7 +10,9 @@ NOTES: | |||
10 | //////////////////////////////////////////////////////////////////////// | 10 | //////////////////////////////////////////////////////////////////////// |
11 | ///////////////////////////////////////////////////////////////////// */ | 11 | ///////////////////////////////////////////////////////////////////// */ |
12 | var Montage = require("montage/core/core").Montage, | 12 | var Montage = require("montage/core/core").Montage, |
13 | Component = require("montage/ui/component").Component; | 13 | Component = require("montage/ui/component").Component, |
14 | Popup = require("js/components/popup.reel").Popup, | ||
15 | CloudPopup = require("js/io/ui/cloudpopup.reel").CloudPopup; | ||
14 | //////////////////////////////////////////////////////////////////////// | 16 | //////////////////////////////////////////////////////////////////////// |
15 | //Exporting as Project I/O | 17 | //Exporting as Project I/O |
16 | exports.CoreIoApi = Montage.create(Component, { | 18 | exports.CoreIoApi = Montage.create(Component, { |
@@ -25,17 +27,9 @@ exports.CoreIoApi = Montage.create(Component, { | |||
25 | this.rootUrl = window.localStorage['ioRootUrl']; | 27 | this.rootUrl = window.localStorage['ioRootUrl']; |
26 | //Checks for IO API to be active | 28 | //Checks for IO API to be active |
27 | this.ioServiceDetected = this.cloudAvailable(); | 29 | this.ioServiceDetected = this.cloudAvailable(); |
28 | // | ||
29 | console.log('FileIO: localStorage URL detected | IO Service Detected: '+ this.ioServiceDetected); | ||
30 | // | ||
31 | } else { | 30 | } else { |
32 | //TODO: Remove, automatically prompt user on welcome | 31 | //IO API to be inactive |
33 | this.rootUrl = 'http://localhost:16380'; | 32 | this.ioServiceDetected = false; |
34 | //TODO: Changed to false, welcome screen prompts user | ||
35 | this.ioServiceDetected = this.cloudAvailable(); | ||
36 | // | ||
37 | console.log('FileIO: localStorage URL NOT detected | IO Service Detected: '+ this.ioServiceDetected); | ||
38 | // | ||
39 | } | 33 | } |
40 | } | 34 | } |
41 | }, | 35 | }, |
@@ -44,19 +38,98 @@ exports.CoreIoApi = Montage.create(Component, { | |||
44 | cloudAvailable: { | 38 | cloudAvailable: { |
45 | enumerable: false, | 39 | enumerable: false, |
46 | value: function () { | 40 | value: function () { |
41 | var cloud = this.getCloudStatus(); | ||
47 | // | 42 | // |
48 | if (this.getCloudStatus().status === 200) { | 43 | if (this.rootUrl && cloud.status === 200) { |
49 | //Active | 44 | //Active |
45 | this.cloudData.name = cloud.response['name']; | ||
46 | this.cloudData.root = cloud.response['server-root']; | ||
50 | return true; | 47 | return true; |
51 | } else { | 48 | } else { |
52 | //Inactive | 49 | //Inactive |
53 | //TODO: Logic to prompt the user for cloud, otherwise return false | 50 | if (!this._cloudDialogOpen && this.application.ninja) { |
51 | this.showCloudDialog(); | ||
52 | } | ||
54 | return false; | 53 | return false; |
55 | } | 54 | } |
56 | } | 55 | } |
57 | }, | 56 | }, |
58 | //////////////////////////////////////////////////////////////////// | 57 | //////////////////////////////////////////////////////////////////// |
59 | // | 58 | // |
59 | _cloudDialogOpen: { | ||
60 | enumerable: false, | ||
61 | value: false | ||
62 | }, | ||
63 | //////////////////////////////////////////////////////////////////// | ||
64 | // | ||
65 | cloudData: { | ||
66 | enumerable: false, | ||
67 | value: {name: null, root: ''} | ||
68 | }, | ||
69 | //////////////////////////////////////////////////////////////////// | ||
70 | // | ||
71 | _cloudDialogComponents: { | ||
72 | enumerable: false, | ||
73 | value: {blackout: null, popup: null, dialog: null} | ||
74 | }, | ||
75 | //////////////////////////////////////////////////////////////////// | ||
76 | // | ||
77 | showCloudDialog: { | ||
78 | enumerable: false, | ||
79 | value: function () { | ||
80 | // | ||
81 | this._cloudDialogOpen = true; | ||
82 | // | ||
83 | this._cloudDialogComponents.blackout = document.createElement('div'); | ||
84 | this._cloudDialogComponents.blackout.style.width = '100%'; | ||
85 | this._cloudDialogComponents.blackout.style.height = '100%'; | ||
86 | this._cloudDialogComponents.blackout.style.background = '-webkit-radial-gradient(center, ellipse cover, rgba(0,0,0,.65) 0%, rgba(0,0,0,0.8) 80%)'; | ||
87 | this.application.ninja.popupManager.addPopup(this._cloudDialogComponents.blackout); | ||
88 | // | ||
89 | //////////////////////////////////////////////////// | ||
90 | //Creating popup from m-js component | ||
91 | var popup = document.createElement('div'); | ||
92 | // | ||
93 | this._cloudDialogComponents.dialog = CloudPopup.create(); | ||
94 | // | ||
95 | document.body.appendChild(popup); | ||
96 | // | ||
97 | this._cloudDialogComponents.dialog.element = popup; | ||
98 | this._cloudDialogComponents.dialog.needsDraw = true; | ||
99 | this._cloudDialogComponents.dialog.element.style.opacity = 0; | ||
100 | // | ||
101 | this._cloudDialogComponents.dialog.addEventListener('firstDraw', this, false); | ||
102 | } | ||
103 | }, | ||
104 | //////////////////////////////////////////////////////////////////// | ||
105 | // | ||
106 | handleFirstDraw: { | ||
107 | value: function (e) { | ||
108 | if (e._target._element.className === 'cloud_popup') { | ||
109 | this._cloudDialogComponents.dialog.removeEventListener('firstDraw', this, false); | ||
110 | // | ||
111 | this._cloudDialogComponents.popup = this.application.ninja.popupManager.createPopup(this._cloudDialogComponents.dialog.element, {x: '50%', y: '50%'}); | ||
112 | this._cloudDialogComponents.popup.addEventListener('firstDraw', this, false); | ||
113 | } else { | ||
114 | // | ||
115 | this._cloudDialogComponents.dialog.element.style.opacity = 1; | ||
116 | this._cloudDialogComponents.popup.element.style.opacity = 1; | ||
117 | this._cloudDialogComponents.popup.element.style.margin = '-100px 0px 0px -190px'; | ||
118 | } | ||
119 | } | ||
120 | }, | ||
121 | //////////////////////////////////////////////////////////////////// | ||
122 | // | ||
123 | hideCloudDialog: { | ||
124 | enumerable: false, | ||
125 | value: function () { | ||
126 | // | ||
127 | this.application.ninja.popupManager.removePopup(this._cloudDialogComponents.blackout); | ||
128 | this.application.ninja.popupManager.removePopup(this._cloudDialogComponents.popup.element); | ||
129 | } | ||
130 | }, | ||
131 | //////////////////////////////////////////////////////////////////// | ||
132 | // | ||
60 | _ioServiceDetected: { | 133 | _ioServiceDetected: { |
61 | enumerable: false, | 134 | enumerable: false, |
62 | value: false | 135 | value: false |
@@ -134,6 +207,7 @@ exports.CoreIoApi = Montage.create(Component, { | |||
134 | directoryServiceURL: { | 207 | directoryServiceURL: { |
135 | enumerable: false, | 208 | enumerable: false, |
136 | get: function() { | 209 | get: function() { |
210 | console.log(this); | ||
137 | return String(this.rootUrl+this._directoryServiceURL); | 211 | return String(this.rootUrl+this._directoryServiceURL); |
138 | }, | 212 | }, |
139 | set: function(value) { | 213 | set: function(value) { |
@@ -156,8 +230,8 @@ exports.CoreIoApi = Montage.create(Component, { | |||
156 | if((urlOut.length > 1) && (urlOut.charAt(urlOut.length - 1) === "/")){ | 230 | if((urlOut.length > 1) && (urlOut.charAt(urlOut.length - 1) === "/")){ |
157 | urlOut = urlOut.substring(0, (urlOut.length - 1)); | 231 | urlOut = urlOut.substring(0, (urlOut.length - 1)); |
158 | } | 232 | } |
159 | 233 | // | |
160 | return serviceURL + urlOut; | 234 | return String(serviceURL+urlOut); |
161 | } | 235 | } |
162 | }, | 236 | }, |
163 | //////////////////////////////////////////////////////////////////// | 237 | //////////////////////////////////////////////////////////////////// |
@@ -899,6 +973,7 @@ exports.CoreIoApi = Montage.create(Component, { | |||
899 | // | 973 | // |
900 | if (xhr.readyState === 4) { | 974 | if (xhr.readyState === 4) { |
901 | retValue.status = xhr.status; | 975 | retValue.status = xhr.status; |
976 | retValue.response = JSON.parse(xhr.response); | ||
902 | retValue.success = true; | 977 | retValue.success = true; |
903 | } | 978 | } |
904 | } | 979 | } |
diff --git a/js/io/system/fileio.js b/js/io/system/fileio.js index 38ab05e8..ac5812e9 100755 --- a/js/io/system/fileio.js +++ b/js/io/system/fileio.js | |||
@@ -11,11 +11,12 @@ NOTES: | |||
11 | empty file will be created. 'contents' should be a string to be saved | 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. | 12 | as the file. 'contentType' is the mime type of the file. |
13 | 13 | ||
14 | coreIoApi: this.application.ninja.coreIoApi | ||
15 | |||
14 | //////////////////////////////////////////////////////////////////////// | 16 | //////////////////////////////////////////////////////////////////////// |
15 | ///////////////////////////////////////////////////////////////////// */ | 17 | ///////////////////////////////////////////////////////////////////// */ |
16 | // | 18 | // |
17 | var Montage = require("montage/core/core").Montage, | 19 | var Montage = require("montage/core/core").Montage; |
18 | CoreIoApi = require("js/io/system/coreioapi").CoreIoApi; | ||
19 | //////////////////////////////////////////////////////////////////////// | 20 | //////////////////////////////////////////////////////////////////////// |
20 | //Exporting as File I/O | 21 | //Exporting as File I/O |
21 | exports.FileIo = Montage.create(Object.prototype, { | 22 | exports.FileIo = Montage.create(Object.prototype, { |
@@ -28,12 +29,12 @@ exports.FileIo = Montage.create(Object.prototype, { | |||
28 | enumerable: true, | 29 | enumerable: true, |
29 | value: function(file) { | 30 | value: function(file) { |
30 | //Checking for API to be available | 31 | //Checking for API to be available |
31 | if (!CoreIoApi.cloudAvailable()) { | 32 | if (!this.application.ninja.coreIoApi.cloudAvailable()) { |
32 | //API not available, no IO action taken | 33 | //API not available, no IO action taken |
33 | return null; | 34 | return null; |
34 | } | 35 | } |
35 | //Peforming check for file to exist | 36 | //Peforming check for file to exist |
36 | var check = CoreIoApi.fileExists(file.uri), status, create; | 37 | var check = this.application.ninja.coreIoApi.fileExists(file.uri), status, create; |
37 | //Upon successful check, handling results | 38 | //Upon successful check, handling results |
38 | if (check.success) { | 39 | if (check.success) { |
39 | //Handling status of check | 40 | //Handling status of check |
@@ -44,7 +45,7 @@ exports.FileIo = Montage.create(Object.prototype, { | |||
44 | break; | 45 | break; |
45 | case 404: | 46 | case 404: |
46 | //File does not exists, ready to be created | 47 | //File does not exists, ready to be created |
47 | create = CoreIoApi.createFile(file); | 48 | create = this.application.ninja.coreIoApi.createFile(file); |
48 | //Storing status to be returned (for UI handling) | 49 | //Storing status to be returned (for UI handling) |
49 | if (create.success) { | 50 | if (create.success) { |
50 | status = check.status; | 51 | status = check.status; |