From 2f61dfca4466661e1ea23888675a86b601b58c63 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Mon, 30 Jan 2012 14:35:11 -0800 Subject: Setting up new file Adding base functionality to creating files. --- js/io/system/coreioapi.js | 64 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 20 deletions(-) (limited to 'js/io/system/coreioapi.js') diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js index 1585fc33..a10063f5 100755 --- a/js/io/system/coreioapi.js +++ b/js/io/system/coreioapi.js @@ -7,7 +7,6 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot /* ///////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// NOTES: -These methods should only be access through the file and project IO classes. //////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// */ var Montage = require("montage/core/core").Montage, @@ -20,22 +19,29 @@ exports.CoreIoApi = Montage.create(Component, { deserializedFromTemplate: { enumerable: false, value: function () { - //////////////////////////////////////////////////////////// - - //TODO: Add logic for getting rooUrl from local storage - - //////////////////////////////////////////////////////////// - - - - //Checking for status of I/O API - this.ioDetected = this.isActive(); - //TODO: Add welcome screen logic, probably externally + //Checking for local storage of URL for IO + if (window.localStorage['ioRootUrl']) { + //Getting URL from local storage + this.rootUrl = window.localStorage['ioRootUrl']; + //Checks for IO API to be active + this.ioServiceDetected = this.isIoServiceActive(); + // + console.log('FileIO: localStorage URL detected | IO Service Detected: '+ this.ioServiceDetected); + // + } else { + //TODO: Remove, automatically prompt user on welcome + this.rootUrl = 'http://localhost:16380'; + //TODO: Changed to false, welcome screen prompts user + this.ioServiceDetected = this.isIoServiceActive(); + // + console.log('FileIO: localStorage URL NOT detected | IO Service Detected: '+ this.ioServiceDetected); + // + } } }, //////////////////////////////////////////////////////////////////// //Method to check status of I/O API, will return false if not active - isActive: { + isIoServiceActive: { enumerable: false, value: function () { //Doing a directory root check, a 200 status means running @@ -47,27 +53,27 @@ exports.CoreIoApi = Montage.create(Component, { } }, //////////////////////////////////////////////////////////////////// - //Root API URL - _ioDetected: { + // + _ioServiceDetected: { enumerable: false, value: false }, //////////////////////////////////////////////////////////////////// - // - ioDetected: { + //Checking for service availability on boot + ioServiceDetected: { enumerable: false, get: function() { - return this._ioDetected; + return this._ioServiceDetected; }, set: function(value) { - this._ioDetected = value; + this._ioServiceDetected = value; } }, //////////////////////////////////////////////////////////////////// //Root API URL _rootUrl: { enumerable: false, - value: 'http://localhost:16380' + value: null }, //////////////////////////////////////////////////////////////////// // @@ -78,6 +84,24 @@ exports.CoreIoApi = Montage.create(Component, { }, set: function(value) { this._rootUrl = value; + window.localStorage["ioRootUrl"] = value; + } + }, + //////////////////////////////////////////////////////////////////// + //API service URL + _apiServiceURL: { + enumerable: false, + value: '/' + }, + //////////////////////////////////////////////////////////////////// + // + apiServiceURL: { + enumerable: false, + get: function() { + return this.rootUrl+this._apiServiceURL; + }, + set: function(value) { + this._apiServiceURL = value; } }, //////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From 3b4291c783c4b8fb07f111a240049069277f3c49 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Mon, 30 Jan 2012 18:19:00 -0800 Subject: Core API initialization routine Setting up the core API routine to check for cloud API availability. Also cleaned up template files for IO and set up initial string contents. --- js/io/system/coreioapi.js | 58 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 14 deletions(-) (limited to 'js/io/system/coreioapi.js') diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js index a10063f5..33c7bc28 100755 --- a/js/io/system/coreioapi.js +++ b/js/io/system/coreioapi.js @@ -24,7 +24,7 @@ exports.CoreIoApi = Montage.create(Component, { //Getting URL from local storage this.rootUrl = window.localStorage['ioRootUrl']; //Checks for IO API to be active - this.ioServiceDetected = this.isIoServiceActive(); + this.ioServiceDetected = this.cloudAvailable(); // console.log('FileIO: localStorage URL detected | IO Service Detected: '+ this.ioServiceDetected); // @@ -32,7 +32,7 @@ exports.CoreIoApi = Montage.create(Component, { //TODO: Remove, automatically prompt user on welcome this.rootUrl = 'http://localhost:16380'; //TODO: Changed to false, welcome screen prompts user - this.ioServiceDetected = this.isIoServiceActive(); + this.ioServiceDetected = this.cloudAvailable(); // console.log('FileIO: localStorage URL NOT detected | IO Service Detected: '+ this.ioServiceDetected); // @@ -41,13 +41,16 @@ exports.CoreIoApi = Montage.create(Component, { }, //////////////////////////////////////////////////////////////////// //Method to check status of I/O API, will return false if not active - isIoServiceActive: { + cloudAvailable: { enumerable: false, value: function () { - //Doing a directory root check, a 200 status means running - if (this.getDirectoryContents({uri:'/'}).status === 200) { + // + if (this.getCloudStatus().status === 200) { + //Active return true; } else { + //Inactive + //TODO: Logic to prompt the user for cloud, otherwise return false return false; } } @@ -83,22 +86,21 @@ exports.CoreIoApi = Montage.create(Component, { return this._rootUrl; }, set: function(value) { - this._rootUrl = value; - window.localStorage["ioRootUrl"] = value; + this._rootUrl = window.localStorage["ioRootUrl"] = value; } }, //////////////////////////////////////////////////////////////////// //API service URL _apiServiceURL: { enumerable: false, - value: '/' + value: '/cloudstatus' }, //////////////////////////////////////////////////////////////////// // apiServiceURL: { enumerable: false, get: function() { - return this.rootUrl+this._apiServiceURL; + return String(this.rootUrl+this._apiServiceURL); }, set: function(value) { this._apiServiceURL = value; @@ -115,7 +117,7 @@ exports.CoreIoApi = Montage.create(Component, { fileServiceURL: { enumerable: false, get: function() { - return this.rootUrl+this._fileServiceURL; + return String(this.rootUrl+this._fileServiceURL); }, set: function(value) { this._fileServiceURL = value; @@ -132,7 +134,7 @@ exports.CoreIoApi = Montage.create(Component, { directoryServiceURL: { enumerable: false, get: function() { - return this.rootUrl+this._directoryServiceURL; + return String(this.rootUrl+this._directoryServiceURL); }, set: function(value) { this._directoryServiceURL = value; @@ -921,10 +923,38 @@ exports.CoreIoApi = Montage.create(Component, { } return retValue; } + }, + //////////////////////////////////////////////////////////////////// + // + getCloudStatus: { + enumerable: false, + writable:false, + value: function() { + // + var retValue = {success:null, status:null}; + // + try { + var serviceURL = this._prepareServiceURL(this.apiServiceURL, '/'), + xhr = new XMLHttpRequest(); + // + xhr.open("GET", serviceURL, false); + xhr.send(); + // + if (xhr.readyState === 4) { + retValue.status = xhr.status; + retValue.success = true; + } + } + catch(error) { + xhr = null; + retValue.success = false; + } + // + return retValue; + } } - - - + //////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////// }); //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// \ No newline at end of file -- cgit v1.2.3