From 409361a7f7653ddb09f9a7463e9ea4ce47caa960 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Tue, 3 Jul 2012 14:26:19 -0700 Subject: Removing the youtube hack now that we have the proper fix from montage Removing the saved instance of the component when opening a file containing the youtube component. Montage made the fix where the instance is now serialized property. Signed-off-by: Valerio Virgillito --- js/io/system/ninjalibrary.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/io/system') diff --git a/js/io/system/ninjalibrary.json b/js/io/system/ninjalibrary.json index 86134b97..7f8ee94f 100644 --- a/js/io/system/ninjalibrary.json +++ b/js/io/system/ninjalibrary.json @@ -1,6 +1,6 @@ { "libraries": [ - {"name": "Montage", "path": "/node_modules/descriptor.json", "version": "0.11.2.0"}, + {"name": "Montage", "path": "/node_modules/descriptor.json", "version": "0.11.2.1"}, {"name": "RDGE", "path": "/assets/descriptor.json", "version": "0.6.0.3"} ] } \ No newline at end of file -- cgit v1.2.3 From 648ee61ae84216d0236e0dbc211addc13b2cfa3a Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Fri, 6 Jul 2012 11:52:06 -0700 Subject: Expand tabs --- js/io/system/chromeapi.js | 352 +++++++++++++-------------- js/io/system/coreioapi.js | 564 +++++++++++++++++++++---------------------- js/io/system/fileio.js | 348 +++++++++++++------------- js/io/system/ninjalibrary.js | 488 ++++++++++++++++++------------------- js/io/system/projectio.js | 98 ++++---- 5 files changed, 925 insertions(+), 925 deletions(-) (limited to 'js/io/system') diff --git a/js/io/system/chromeapi.js b/js/io/system/chromeapi.js index 0650385f..3561a617 100644 --- a/js/io/system/chromeapi.js +++ b/js/io/system/chromeapi.js @@ -32,9 +32,9 @@ POSSIBILITY OF SUCH DAMAGE. //////////////////////////////////////////////////////////////////////// NOTES: - The init function starts up the file system API, and a size must be - set, no unlimited available as of now. - + The init function starts up the file system API, and a size must be + set, no unlimited available as of now. + //////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// */ // @@ -42,31 +42,31 @@ var Montage = require("montage/core/core").Montage; //////////////////////////////////////////////////////////////////////// // exports.ChromeApi = Montage.create(Object.prototype, { - //////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////// //Needs size in MBs for fileSystem init init: { - enumerable: true, - value: function(size) { - // - if (window.webkitRequestFileSystem) { - //Current way to init Chrome's fileSystem API - window.webkitRequestFileSystem(window.PERSISTENT, size*1024*1024, function (fs) { - //Storing reference to instance - this.fileSystem = fs; - //Dispatching action ready event - var readyEvent = document.createEvent("CustomEvent"); - readyEvent.initEvent('ready', true, true); - this.dispatchEvent(readyEvent); - //Building data of local Ninja Library - this._listNinjaChromeLibrary(); - }.bind(this), function (e) {return false}); //Returns false on error (not able to init) - // - return true; - } else { - //No fileSystem API - return false; - } - } + enumerable: true, + value: function(size) { + // + if (window.webkitRequestFileSystem) { + //Current way to init Chrome's fileSystem API + window.webkitRequestFileSystem(window.PERSISTENT, size*1024*1024, function (fs) { + //Storing reference to instance + this.fileSystem = fs; + //Dispatching action ready event + var readyEvent = document.createEvent("CustomEvent"); + readyEvent.initEvent('ready', true, true); + this.dispatchEvent(readyEvent); + //Building data of local Ninja Library + this._listNinjaChromeLibrary(); + }.bind(this), function (e) {return false}); //Returns false on error (not able to init) + // + return true; + } else { + //No fileSystem API + return false; + } + } }, //////////////////////////////////////////////////////////////////// // @@ -77,213 +77,213 @@ exports.ChromeApi = Montage.create(Object.prototype, { //////////////////////////////////////////////////////////////////// // fileSystem: { - enumerable: false, - get: function() { + enumerable: false, + get: function() { return this._fileSystem; }, set: function(value) { - this._fileSystem = value; + this._fileSystem = value; } }, //////////////////////////////////////////////////////////////////// // fileNew: { - enumerable: true, - value: function(filePath, content, callback) { - // - this.fileSystem.root.getFile(filePath, {create: true}, function(f) { - // - f.createWriter(function(writer) { - // - var mime, blob = new window.WebKitBlobBuilder, type = filePath.split('.'); - type = type[type.length-1]; - switch (type) { - case 'bmp': - mime = 'image/bmp'; - break; - case 'gif': - mime = 'image/gif'; - break; - case 'jpeg': - mime = 'image/jpeg'; - break; - case 'jpg': - mime = 'image/jpeg'; - break; - case 'png': - mime = 'image/png'; - break; - case 'rtf': - mime = 'application/rtf'; - break; - case 'tif': - mime = 'image/tiff'; - break; - case 'tiff': - mime = 'image/tiff'; - break; - case 'pdf': - mime = 'application/pdf'; - break; - case 'zip': - mime = 'application/zip'; - break; - case 'svg': - mime = 'image/svg+xml'; - break; - default: - mime = 'text/'+type; - break; - } - // - blob.append(content); - writer.write(blob.getBlob(mime)); - // - if (callback) callback(true); - }, function (e) {if (callback) callback(false)}); - }, function (e) {if (callback) callback(false)}); - } + enumerable: true, + value: function(filePath, content, callback) { + // + this.fileSystem.root.getFile(filePath, {create: true}, function(f) { + // + f.createWriter(function(writer) { + // + var mime, blob = new window.WebKitBlobBuilder, type = filePath.split('.'); + type = type[type.length-1]; + switch (type) { + case 'bmp': + mime = 'image/bmp'; + break; + case 'gif': + mime = 'image/gif'; + break; + case 'jpeg': + mime = 'image/jpeg'; + break; + case 'jpg': + mime = 'image/jpeg'; + break; + case 'png': + mime = 'image/png'; + break; + case 'rtf': + mime = 'application/rtf'; + break; + case 'tif': + mime = 'image/tiff'; + break; + case 'tiff': + mime = 'image/tiff'; + break; + case 'pdf': + mime = 'application/pdf'; + break; + case 'zip': + mime = 'application/zip'; + break; + case 'svg': + mime = 'image/svg+xml'; + break; + default: + mime = 'text/'+type; + break; + } + // + blob.append(content); + writer.write(blob.getBlob(mime)); + // + if (callback) callback(true); + }, function (e) {if (callback) callback(false)}); + }, function (e) {if (callback) callback(false)}); + } }, //////////////////////////////////////////////////////////////////// // fileDelete: { - enumerable: true, - value: function(filePath, callback) { - this.fileSystem.root.getFile(filePath, {create: false}, function(file) { - file.remove(function() { - if (callback) callback(true); - }); - }, function (e) {if (callback) callback(false)}); - } + enumerable: true, + value: function(filePath, callback) { + this.fileSystem.root.getFile(filePath, {create: false}, function(file) { + file.remove(function() { + if (callback) callback(true); + }); + }, function (e) {if (callback) callback(false)}); + } }, //////////////////////////////////////////////////////////////////// // fileContent: { - enumerable: true, - value: function(filePath, callback) { - // - this.fileSystem.root.getFile(filePath, {}, function(f) { - f.file(function(file) { - var reader = new FileReader(); - reader.onloadend = function(e) { - if (callback) { - callback({content: this.result, data: file, file: f, url: f.toURL()}); - } - }; - reader.readAsArrayBuffer(file); - }, function (e) {if (callback) callback(false)}); - }, function (e) {if (callback) callback(false)}); - } + enumerable: true, + value: function(filePath, callback) { + // + this.fileSystem.root.getFile(filePath, {}, function(f) { + f.file(function(file) { + var reader = new FileReader(); + reader.onloadend = function(e) { + if (callback) { + callback({content: this.result, data: file, file: f, url: f.toURL()}); + } + }; + reader.readAsArrayBuffer(file); + }, function (e) {if (callback) callback(false)}); + }, function (e) {if (callback) callback(false)}); + } }, //////////////////////////////////////////////////////////////////// // fileCopy: { - enumerable: true, - value: function() { - } + enumerable: true, + value: function() { + } }, //////////////////////////////////////////////////////////////////// // fileRename: { - enumerable: true, - value: function() { - } + enumerable: true, + value: function() { + } }, //////////////////////////////////////////////////////////////////// // fileMove: { - enumerable: true, - value: function() { - } + enumerable: true, + value: function() { + } }, //////////////////////////////////////////////////////////////////// //Creating directory from path, callback optional directoryNew: { - enumerable: true, - value: function(directoryPath, callback) { - //Checking for directory not to already exist - this.fileSystem.root.getDirectory(directoryPath, {}, function(dir) { - if (callback) callback(false); - return false; //Directory already exists - }); - //Creating new directory - this.fileSystem.root.getDirectory(directoryPath, {create: true}, function(dir) { - if (callback) callback(true); - }, function (e) {if (callback) callback(false)}); - } + enumerable: true, + value: function(directoryPath, callback) { + //Checking for directory not to already exist + this.fileSystem.root.getDirectory(directoryPath, {}, function(dir) { + if (callback) callback(false); + return false; //Directory already exists + }); + //Creating new directory + this.fileSystem.root.getDirectory(directoryPath, {create: true}, function(dir) { + if (callback) callback(true); + }, function (e) {if (callback) callback(false)}); + } }, //////////////////////////////////////////////////////////////////// // directoryDelete: { - enumerable: true, - value: function(directoryPath, callback) { - // - this.fileSystem.root.getDirectory(directoryPath, {}, function(dir) { - // - dir.removeRecursively(function() { - if (callback) callback(true); - }); - }, function (e) {if (callback) callback(false)}); - } + enumerable: true, + value: function(directoryPath, callback) { + // + this.fileSystem.root.getDirectory(directoryPath, {}, function(dir) { + // + dir.removeRecursively(function() { + if (callback) callback(true); + }); + }, function (e) {if (callback) callback(false)}); + } }, //////////////////////////////////////////////////////////////////// //Returns the directory contents to a callback function directoryContents: { - enumerable: true, - value: function(directory, callback) { - //Creating instance of directory reader - this.fileSystem.directoryReader = directory.createReader(); - //Getting directory contents and sending results to callback - this.fileSystem.directoryReader.readEntries(function(results) { - //Calling callback with results (null if invalid directory) - callback(results); - }, function (e) {callback(null)}); - } + enumerable: true, + value: function(directory, callback) { + //Creating instance of directory reader + this.fileSystem.directoryReader = directory.createReader(); + //Getting directory contents and sending results to callback + this.fileSystem.directoryReader.readEntries(function(results) { + //Calling callback with results (null if invalid directory) + callback(results); + }, function (e) {callback(null)}); + } }, //////////////////////////////////////////////////////////////////// // directoryCopy: { - enumerable: true, - value: function() { - } + enumerable: true, + value: function() { + } }, //////////////////////////////////////////////////////////////////// // directoryRename: { - enumerable: true, - value: function() { - } + enumerable: true, + value: function() { + } }, //////////////////////////////////////////////////////////////////// // directoryMove: { - enumerable: true, - value: function() { - } + enumerable: true, + value: function() { + } }, //////////////////////////////////////////////////////////////////// // _listNinjaChromeLibrary: { - enumerable: false, + enumerable: false, value: function () { - function parseLibrary (contents) { - // - var lib = []; - // - for(var i=0; contents[i]; i++) { - // - if (contents[i].isDirectory) { - lib.push(contents[i].name); - } - } - //Dispatching action ready event - var libraryEvent = document.createEvent("CustomEvent"); - libraryEvent.initEvent('library', true, true); - libraryEvent.ninjaChromeLibrary = lib; - this.dispatchEvent(libraryEvent); - }; - // - this.directoryContents(this.fileSystem.root, parseLibrary.bind(this)); + function parseLibrary (contents) { + // + var lib = []; + // + for(var i=0; contents[i]; i++) { + // + if (contents[i].isDirectory) { + lib.push(contents[i].name); + } + } + //Dispatching action ready event + var libraryEvent = document.createEvent("CustomEvent"); + libraryEvent.initEvent('library', true, true); + libraryEvent.ninjaChromeLibrary = lib; + this.dispatchEvent(libraryEvent); + }; + // + this.directoryContents(this.fileSystem.root, parseLibrary.bind(this)); } } //////////////////////////////////////////////////////////////////// diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js index d3977106..121b4410 100755 --- a/js/io/system/coreioapi.js +++ b/js/io/system/coreioapi.js @@ -32,87 +32,87 @@ POSSIBILITY OF SUCH DAMAGE. //////////////////////////////////////////////////////////////////////// NOTES: - Core API reference in NINJA: this.application.ninja.coreIoApi - + Core API reference in NINJA: this.application.ninja.coreIoApi + //////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// */ -var Montage = require("montage/core/core").Montage, - Component = require("montage/ui/component").Component, - Popup = require("js/components/popup.reel").Popup, - CloudPopup = require("js/io/ui/cloudpopup.reel").CloudPopup, - ChromeApi = require("js/io/system/chromeapi").ChromeApi, - NinjaLibrary = require("js/io/system/ninjalibrary").NinjaLibrary; +var Montage = require("montage/core/core").Montage, + Component = require("montage/ui/component").Component, + Popup = require("js/components/popup.reel").Popup, + CloudPopup = require("js/io/ui/cloudpopup.reel").CloudPopup, + ChromeApi = require("js/io/system/chromeapi").ChromeApi, + NinjaLibrary = require("js/io/system/ninjalibrary").NinjaLibrary; //////////////////////////////////////////////////////////////////////// //Exporting as Project I/O exports.CoreIoApi = Montage.create(Component, { //////////////////////////////////////////////////////////////////// // - deserializedFromTemplate: { - enumerable: false, - value: function () { - //////////////////////////////////////////////////////////// - //Checking for local storage of URL for IO + deserializedFromTemplate: { + enumerable: false, + value: function () { + //////////////////////////////////////////////////////////// + //Checking for local storage of URL for IO if (this.application.localStorage.getItem("ioRootUrl")) { - //Getting URL from local storage + //Getting URL from local storage this.rootUrl = this.application.localStorage.getItem("ioRootUrl"); - //Checks for IO API to be active - this.ioServiceDetected = this.cloudAvailable(); - } else { - //IO API to be inactive - this.ioServiceDetected = false; - } - //////////////////////////////////////////////////////////// - //Instance of ninja library - this.ninjaLibrary = NinjaLibrary; - this.ninjaLibrary.coreApi = this; - //Getting reference of chrome file system API - this.chromeFileSystem = ChromeApi; - //Sending size in MBs for file system storage - var chromeFs = this.chromeFileSystem.init(20); - //Checking for availability of API - if (chromeFs) { - this.chromeFileSystem.addEventListener('ready', this, false); - } else { - //Error, Chrome File System API not detected - } - //////////////////////////////////////////////////////////// - } - }, - //////////////////////////////////////////////////////////////////// + //Checks for IO API to be active + this.ioServiceDetected = this.cloudAvailable(); + } else { + //IO API to be inactive + this.ioServiceDetected = false; + } + //////////////////////////////////////////////////////////// + //Instance of ninja library + this.ninjaLibrary = NinjaLibrary; + this.ninjaLibrary.coreApi = this; + //Getting reference of chrome file system API + this.chromeFileSystem = ChromeApi; + //Sending size in MBs for file system storage + var chromeFs = this.chromeFileSystem.init(20); + //Checking for availability of API + if (chromeFs) { + this.chromeFileSystem.addEventListener('ready', this, false); + } else { + //Error, Chrome File System API not detected + } + //////////////////////////////////////////////////////////// + } + }, + //////////////////////////////////////////////////////////////////// // - handleReady: { - enumerable: false, + handleReady: { + enumerable: false, value: function (e) { - //Removing events - this.chromeFileSystem.removeEventListener('ready', this, false); - //Listening for library to be copied event (builds list) - this.chromeFileSystem.addEventListener('library', this, false); - //TODO: Add sync loading screen logic (Add screen here) + //Removing events + this.chromeFileSystem.removeEventListener('ready', this, false); + //Listening for library to be copied event (builds list) + this.chromeFileSystem.addEventListener('library', this, false); + //TODO: Add sync loading screen logic (Add screen here) } - }, - //////////////////////////////////////////////////////////////////// + }, + //////////////////////////////////////////////////////////////////// // - handleLibrary: { - enumerable: false, + handleLibrary: { + enumerable: false, value: function (e) { - //Removing events - this.chromeFileSystem.removeEventListener('library', this, false); - //Listening for synced library event - this.ninjaLibrary.addEventListener('sync', this, false); - //Sending library to be synced to chrome - this.ninjaLibrary.synchronize(e._event.ninjaChromeLibrary, this.chromeFileSystem); - + //Removing events + this.chromeFileSystem.removeEventListener('library', this, false); + //Listening for synced library event + this.ninjaLibrary.addEventListener('sync', this, false); + //Sending library to be synced to chrome + this.ninjaLibrary.synchronize(e._event.ninjaChromeLibrary, this.chromeFileSystem); + } - }, - //////////////////////////////////////////////////////////////////// + }, + //////////////////////////////////////////////////////////////////// // - handleSync: { - enumerable: false, + handleSync: { + enumerable: false, value: function (e) { - console.log('Ninja Local Library: Ready'); - //Removing events - this.ninjaLibrary.removeEventListener('sync', this, false); - //TODO: Add sync loading screen logic (Remove screen here) + console.log('Ninja Local Library: Ready'); + //Removing events + this.ninjaLibrary.removeEventListener('sync', this, false); + //TODO: Add sync loading screen logic (Remove screen here) } }, //////////////////////////////////////////////////////////////////// @@ -124,12 +124,12 @@ exports.CoreIoApi = Montage.create(Component, { //////////////////////////////////////////////////////////////////// // chromeNinjaLibrary: { - enumerable: false, - get: function() { + enumerable: false, + get: function() { return this._chromeNinjaLibrary; }, set: function(value) { - this._chromeNinjaLibrary = value; + this._chromeNinjaLibrary = value; } }, //////////////////////////////////////////////////////////////////// @@ -141,15 +141,15 @@ exports.CoreIoApi = Montage.create(Component, { //////////////////////////////////////////////////////////////////// // chromeFileSystem: { - enumerable: false, - get: function() { + enumerable: false, + get: function() { return this._chromeFileSystem; }, set: function(value) { - this._chromeFileSystem = value; + this._chromeFileSystem = value; } }, - //////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////// // _ioServiceDetected: { enumerable: false, @@ -158,15 +158,15 @@ exports.CoreIoApi = Montage.create(Component, { //////////////////////////////////////////////////////////////////// //Checking for service availability on boot ioServiceDetected: { - enumerable: false, - get: function() { + enumerable: false, + get: function() { return this._ioServiceDetected; }, set: function(value) { - this._ioServiceDetected = value; + this._ioServiceDetected = value; } }, - //////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////// //Root API URL _rootUrl: { enumerable: false, @@ -175,15 +175,15 @@ exports.CoreIoApi = Montage.create(Component, { //////////////////////////////////////////////////////////////////// // rootUrl: { - enumerable: false, - get: function() { + enumerable: false, + get: function() { return this._rootUrl; }, set: function(value) { - this._rootUrl = this.application.localStorage.setItem("ioRootUrl", value); + this._rootUrl = this.application.localStorage.setItem("ioRootUrl", value); } }, - //////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////// //API service URL _apiServiceURL: { enumerable: false, @@ -192,15 +192,15 @@ exports.CoreIoApi = Montage.create(Component, { //////////////////////////////////////////////////////////////////// // apiServiceURL: { - enumerable: false, - get: function() { + enumerable: false, + get: function() { return String(this.rootUrl+this._apiServiceURL); }, set: function(value) { - this._apiServiceURL = value; + this._apiServiceURL = value; } }, - //////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////// //File service API URL _fileServiceURL: { enumerable: false, @@ -209,12 +209,12 @@ exports.CoreIoApi = Montage.create(Component, { //////////////////////////////////////////////////////////////////// // fileServiceURL: { - enumerable: false, - get: function() { + enumerable: false, + get: function() { return String(this.rootUrl+this._fileServiceURL); }, set: function(value) { - this._fileServiceURL = value; + this._fileServiceURL = value; } }, //////////////////////////////////////////////////////////////////// @@ -226,15 +226,15 @@ exports.CoreIoApi = Montage.create(Component, { //////////////////////////////////////////////////////////////////// // webServiceURL: { - enumerable: false, - get: function() { + enumerable: false, + get: function() { return String(this.rootUrl+this._webServiceURL); }, set: function(value) { - this._webServiceURL = value; + this._webServiceURL = value; } }, - //////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////// //Directory service API URL _directoryServiceURL: { enumerable: false, @@ -243,15 +243,15 @@ exports.CoreIoApi = Montage.create(Component, { //////////////////////////////////////////////////////////////////// // directoryServiceURL: { - enumerable: false, - get: function() { + enumerable: false, + get: function() { return String(this.rootUrl+this._directoryServiceURL); }, set: function(value) { - this._directoryServiceURL = value; + this._directoryServiceURL = value; } }, - //////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////// // private helper to parse URIs and append them to the service URL _prepareServiceURL: { enumerable: false, @@ -267,104 +267,104 @@ exports.CoreIoApi = Montage.create(Component, { if((urlOut.length > 1) && (urlOut.charAt(urlOut.length - 1) === "/")){ urlOut = urlOut.substring(0, (urlOut.length - 1)); } - // + // return String(serviceURL+urlOut); } }, //////////////////////////////////////////////////////////////////// //Method to check status of I/O API, will return false if not active - cloudAvailable: { - enumerable: false, - value: function () { - var cloud = this.getCloudStatus(); - // - if (this.rootUrl && cloud.status === 200) { - //Active - this.cloudData.name = cloud.response['name']; - this.cloudData.root = cloud.response['server-root']; - return true; - } else { - //Inactive - if (!this._cloudDialogOpen && this.application.ninja) { - this.showCloudDialog(); - } - return false; - } - } - }, - //////////////////////////////////////////////////////////////////// + cloudAvailable: { + enumerable: false, + value: function () { + var cloud = this.getCloudStatus(); + // + if (this.rootUrl && cloud.status === 200) { + //Active + this.cloudData.name = cloud.response['name']; + this.cloudData.root = cloud.response['server-root']; + return true; + } else { + //Inactive + if (!this._cloudDialogOpen && this.application.ninja) { + this.showCloudDialog(); + } + return false; + } + } + }, + //////////////////////////////////////////////////////////////////// // _cloudDialogOpen: { - enumerable: false, - value: false + enumerable: false, + value: false }, //////////////////////////////////////////////////////////////////// // cloudData: { - enumerable: false, - value: {name: null, root: ''} + enumerable: false, + value: {name: null, root: ''} }, //////////////////////////////////////////////////////////////////// // _cloudDialogComponents: { - enumerable: false, - value: {blackout: null, popup: null, dialog: null} + enumerable: false, + value: {blackout: null, popup: null, dialog: null} }, //////////////////////////////////////////////////////////////////// // showCloudDialog: { - enumerable: false, - value: function () { - // - this._cloudDialogOpen = true; - // - this._cloudDialogComponents.blackout = document.createElement('div'); - this._cloudDialogComponents.blackout.style.width = '100%'; - this._cloudDialogComponents.blackout.style.height = '100%'; - this._cloudDialogComponents.blackout.style.background = '-webkit-radial-gradient(center, ellipse cover, rgba(0,0,0,.65) 0%, rgba(0,0,0,0.8) 80%)'; - this.application.ninja.popupManager.addPopup(this._cloudDialogComponents.blackout); - // - //////////////////////////////////////////////////// - //Creating popup from m-js component - var popup = document.createElement('div'); - // - this._cloudDialogComponents.dialog = CloudPopup.create(); - // - document.body.appendChild(popup); - // - this._cloudDialogComponents.dialog.element = popup; - this._cloudDialogComponents.dialog.needsDraw = true; - this._cloudDialogComponents.dialog.element.style.opacity = 0; - // - this._cloudDialogComponents.dialog.addEventListener('firstDraw', this, false); - } + enumerable: false, + value: function () { + // + this._cloudDialogOpen = true; + // + this._cloudDialogComponents.blackout = document.createElement('div'); + this._cloudDialogComponents.blackout.style.width = '100%'; + this._cloudDialogComponents.blackout.style.height = '100%'; + this._cloudDialogComponents.blackout.style.background = '-webkit-radial-gradient(center, ellipse cover, rgba(0,0,0,.65) 0%, rgba(0,0,0,0.8) 80%)'; + this.application.ninja.popupManager.addPopup(this._cloudDialogComponents.blackout); + // + //////////////////////////////////////////////////// + //Creating popup from m-js component + var popup = document.createElement('div'); + // + this._cloudDialogComponents.dialog = CloudPopup.create(); + // + document.body.appendChild(popup); + // + this._cloudDialogComponents.dialog.element = popup; + this._cloudDialogComponents.dialog.needsDraw = true; + this._cloudDialogComponents.dialog.element.style.opacity = 0; + // + this._cloudDialogComponents.dialog.addEventListener('firstDraw', this, false); + } }, //////////////////////////////////////////////////////////////////// // handleFirstDraw: { - value: function (e) { - if (e._target._element.className === 'cloud_popup') { - this._cloudDialogComponents.dialog.removeEventListener('firstDraw', this, false); - // - this._cloudDialogComponents.popup = this.application.ninja.popupManager.createPopup(this._cloudDialogComponents.dialog.element, {x: '50%', y: '50%'}); - this._cloudDialogComponents.popup.addEventListener('firstDraw', this, false); - } else { - // - this._cloudDialogComponents.dialog.element.style.opacity = 1; - this._cloudDialogComponents.popup.element.style.opacity = 1; - this._cloudDialogComponents.popup.element.style.margin = '-170px 0px 0px -190px'; - } - } + value: function (e) { + if (e._target._element.className === 'cloud_popup') { + this._cloudDialogComponents.dialog.removeEventListener('firstDraw', this, false); + // + this._cloudDialogComponents.popup = this.application.ninja.popupManager.createPopup(this._cloudDialogComponents.dialog.element, {x: '50%', y: '50%'}); + this._cloudDialogComponents.popup.addEventListener('firstDraw', this, false); + } else { + // + this._cloudDialogComponents.dialog.element.style.opacity = 1; + this._cloudDialogComponents.popup.element.style.opacity = 1; + this._cloudDialogComponents.popup.element.style.margin = '-170px 0px 0px -190px'; + } + } }, //////////////////////////////////////////////////////////////////// // hideCloudDialog: { - enumerable: false, - value: function () { - // - this.application.ninja.popupManager.removePopup(this._cloudDialogComponents.blackout); - this.application.ninja.popupManager.removePopup(this._cloudDialogComponents.popup.element); - } + enumerable: false, + value: function () { + // + this.application.ninja.popupManager.removePopup(this._cloudDialogComponents.blackout); + this.application.ninja.popupManager.removePopup(this._cloudDialogComponents.popup.element); + } }, //////////////////////////////////////////////////////////////////// // Checks for the existence of a file @@ -382,18 +382,18 @@ exports.CoreIoApi = Montage.create(Component, { fileExists: { enumerable: false, value: function(file) { - // + // var retValue = { success:null, status:null }; // if(file && file.uri && file.uri.length) { try { var serviceURL = this._prepareServiceURL(this.fileServiceURL, file.uri), - xhr = new XMLHttpRequest(); - // + xhr = new XMLHttpRequest(); + // xhr.open("GET", serviceURL, false); xhr.setRequestHeader("check-existence-only", "true"); xhr.send(); - // + // if (xhr.readyState === 4) { retValue.status = xhr.status; retValue.success = true; @@ -404,7 +404,7 @@ exports.CoreIoApi = Montage.create(Component, { retValue.success = false; } } - // + // return retValue; } }, @@ -425,13 +425,13 @@ exports.CoreIoApi = Montage.create(Component, { // 400 - the file already exists and could not be created // 500 - unknown server error occurred createFile: { - enumerable: false, - value: function(file) { + enumerable: false, + value: function(file) { var retValue = { success:null, status:null }; if(file && file.uri && file.uri.length) { try { var serviceURL = this._prepareServiceURL(this.fileServiceURL, file.uri), - xhr = new XMLHttpRequest(); + xhr = new XMLHttpRequest(); // xhr.open("POST", serviceURL, false); //xhr.responseType = "arraybuffer"; @@ -443,7 +443,7 @@ exports.CoreIoApi = Montage.create(Component, { if (file.contents) xhr.send(file.contents); else - xhr.send(); + xhr.send(); if (xhr.readyState === 4) { retValue.status = xhr.status; @@ -457,7 +457,7 @@ exports.CoreIoApi = Montage.create(Component, { } return retValue; - } + } }, //////////////////////////////////////////////////////////////////// // Save contents into an existing file at the specified path @@ -476,13 +476,13 @@ exports.CoreIoApi = Montage.create(Component, { // 404 - the file specified does not exist // 500 - unknown server error occurred updateFile: { - enumerable: false, - value: function(file) { + enumerable: false, + value: function(file) { var retValue = { success:null, status:null }; if(file && file.uri && file.uri.length && file.contents) { try { var serviceURL = this._prepareServiceURL(this.fileServiceURL, file.uri), - xhr = new XMLHttpRequest(); + xhr = new XMLHttpRequest(); // xhr.open("PUT", serviceURL, false); if(file.contentType && file.contentType.length) @@ -504,7 +504,7 @@ exports.CoreIoApi = Montage.create(Component, { } return retValue; - } + } }, //////////////////////////////////////////////////////////////////// // Copies a file from one location to another @@ -523,23 +523,23 @@ exports.CoreIoApi = Montage.create(Component, { // 404 - the file specified in sourceUri does not exist // 500 - unknown server error occurred copyFile: { - enumerable: false, - value: function(file) { + enumerable: false, + value: function(file) { var retValue = { success:null, status:null }; if(file && file.sourceUri && file.sourceUri.length && file.destUri && file.destUri.length) { try { var serviceURL = this._prepareServiceURL(this.fileServiceURL, file.destUri), - xhr = new XMLHttpRequest(); + xhr = new XMLHttpRequest(); // xhr.open("PUT", serviceURL, false); xhr.setRequestHeader("sourceURI", file.sourceUri); - // + // if(file.overwriteDestination && file.overwriteDestination === true) { xhr.setRequestHeader("overwrite-destination", "true"); } - // + // xhr.send(); - // + // if (xhr.readyState === 4) { retValue.status = xhr.status; retValue.success = true; @@ -550,9 +550,9 @@ exports.CoreIoApi = Montage.create(Component, { retValue.success = false; } } - // + // return retValue; - } + } }, //////////////////////////////////////////////////////////////////// // Moves a file from one location to another @@ -571,24 +571,24 @@ exports.CoreIoApi = Montage.create(Component, { // 404 - the file specified in sourceUri does not exist // 500 - unknown server error occurred moveFile: { - enumerable: false, - value: function(file) { + enumerable: false, + value: function(file) { var retValue = { success:null, status:null }; if(file && file.sourceUri && file.sourceUri.length && file.destUri && file.destUri.length) { try { var serviceURL = this._prepareServiceURL(this.fileServiceURL, file.destUri), - xhr = new XMLHttpRequest(); + xhr = new XMLHttpRequest(); // xhr.open("PUT", serviceURL, false); xhr.setRequestHeader("sourceURI", file.sourceUri); xhr.setRequestHeader("delete-source", "true"); - // + // if(file.overwriteDestination && file.overwriteDestination === true) { xhr.setRequestHeader("overwrite-destination", "true"); } - // + // xhr.send(); - // + // if (xhr.readyState === 4) { retValue.status = xhr.status; retValue.success = true; @@ -599,9 +599,9 @@ exports.CoreIoApi = Montage.create(Component, { retValue.success = false; } } - // + // return retValue; - } + } }, //////////////////////////////////////////////////////////////////// // Deletes an existing file @@ -617,17 +617,17 @@ exports.CoreIoApi = Montage.create(Component, { // 404 - the file does not exist // 500 - unknown server error occurred deleteFile: { - enumerable: false, - value: function(file) { + enumerable: false, + value: function(file) { var retValue = { success:null, status:null }; if(file && file.uri && file.uri.length) { try { var serviceURL = this._prepareServiceURL(this.fileServiceURL, file.uri), - xhr = new XMLHttpRequest(); + xhr = new XMLHttpRequest(); // xhr.open("DELETE", serviceURL, false); xhr.send(); - // + // if (xhr.readyState === 4) { retValue.status = xhr.status; retValue.success = true; @@ -638,9 +638,9 @@ exports.CoreIoApi = Montage.create(Component, { retValue.success = false; } } - // + // return retValue; - } + } }, //////////////////////////////////////////////////////////////////// // Reads an existing file @@ -657,19 +657,19 @@ exports.CoreIoApi = Montage.create(Component, { // 404 - the file does not exist // 500 - unknown server error occurred readFile: { - enumerable: false, - value: function(file) { - // + enumerable: false, + value: function(file) { + // var retValue = { success:null, content:null, status:null}; // if(file && file.uri && file.uri.length) { try { var serviceURL = this._prepareServiceURL(this.fileServiceURL, file.uri), - xhr = new XMLHttpRequest(); + xhr = new XMLHttpRequest(); // xhr.open("GET", serviceURL, false); xhr.send(); - // + // if (xhr.readyState === 4) { retValue.status = xhr.status; if(xhr.status == 200) { @@ -683,16 +683,16 @@ exports.CoreIoApi = Montage.create(Component, { retValue.success = false; } } - // + // return retValue; - } + } }, //////////////////////////////////////////////////////////////////// // Reads an external file (cross-domain) // Parameters: // the file parameter must contain the following properties // url: string value containing the full file path/URL i.e. "http://google.com/motorola.html" - // binary parameter is optional if the content is to be binary + // binary parameter is optional if the content is to be binary // Return values: // returns an object with two properties // success: boolean indicating if the call succeeded or failed @@ -702,21 +702,21 @@ exports.CoreIoApi = Montage.create(Component, { // 404 - the file does not exist // 500 - unknown server error occurred readExternalFile: { - enumerable: false, - value: function(file) { - // + enumerable: false, + value: function(file) { + // var retValue = {success:null, content:null, status:null}; // if(file && file.url && file.url.length) { try { - var serviceURL = this._prepareServiceURL(this.webServiceURL, ''), - xhr = new XMLHttpRequest(); + var serviceURL = this._prepareServiceURL(this.webServiceURL, ''), + xhr = new XMLHttpRequest(); // xhr.open("GET", serviceURL+"?url="+file.url, false); if (file.binary) xhr.setRequestHeader("return-type", "binary"); xhr.setRequestHeader("Content-Type", "text/plain"); xhr.send(); - // + // if (xhr.readyState === 4) { retValue.status = xhr.status; if(xhr.status == 200) { @@ -730,9 +730,9 @@ exports.CoreIoApi = Montage.create(Component, { retValue.success = false; } } - // + // return retValue; - } + } }, //////////////////////////////////////////////////////////////////// // Create a new directory/folder @@ -748,17 +748,17 @@ exports.CoreIoApi = Montage.create(Component, { // 400 - the directory was unable to be created // 500 - unknown server error occurred createDirectory: { - enumerable: false, - value: function(dir) { + enumerable: false, + value: function(dir) { var retValue = { success:null, status:null }; if(dir && dir.uri && dir.uri.length) { try { var serviceURL = this._prepareServiceURL(this.directoryServiceURL, dir.uri), - xhr = new XMLHttpRequest(); + xhr = new XMLHttpRequest(); // xhr.open("POST", serviceURL, false); xhr.send(); - // + // if (xhr.readyState === 4) { retValue.status = xhr.status; retValue.success = true; @@ -769,9 +769,9 @@ exports.CoreIoApi = Montage.create(Component, { retValue.success = false; } } - // + // return retValue; - } + } }, //////////////////////////////////////////////////////////////////// // Delete a directory/folder @@ -787,17 +787,17 @@ exports.CoreIoApi = Montage.create(Component, { // 404 - the directory does not exist // 500 - unknown server error occurred deleteDirectory: { - enumerable: false, - value: function(dir) { + enumerable: false, + value: function(dir) { var retValue = { success:null, status:null }; if(dir && dir.uri && dir.uri.length) { try { var serviceURL = this._prepareServiceURL(this.directoryServiceURL, dir.uri), - xhr = new XMLHttpRequest(); + xhr = new XMLHttpRequest(); // xhr.open("DELETE", serviceURL, false); xhr.send(); - // + // if (xhr.readyState === 4) { retValue.status = xhr.status; retValue.success = true; @@ -808,9 +808,9 @@ exports.CoreIoApi = Montage.create(Component, { retValue.success = false; } } - // + // return retValue; - } + } }, //////////////////////////////////////////////////////////////////// // List the contents of a directory/folder @@ -830,16 +830,16 @@ exports.CoreIoApi = Montage.create(Component, { // 404 - the directory does not exist // 500 - unknown server error occurred getDirectoryContents: { - enumerable: false, - value: function(dir) { + enumerable: false, + value: function(dir) { var retValue = { success:null, content:null, status:null }; if(!!dir && (typeof dir.uri !== "undefined") && (dir.uri !== null) ) { try { var serviceURL = this._prepareServiceURL(this.directoryServiceURL, dir.uri), - xhr = new XMLHttpRequest(); + xhr = new XMLHttpRequest(); // xhr.open("GET", serviceURL, false); - // + // if(dir.recursive) { xhr.setRequestHeader("recursive", dir.recursive.toString()); } @@ -848,15 +848,15 @@ exports.CoreIoApi = Montage.create(Component, { if (dir.fileFilters) { xhr.setRequestHeader("file-filters", dir.fileFilters.toString()); } - // + // // if(dir.returnType) { xhr.setRequestHeader("return-type", dir.returnType.toString()); } - // + // xhr.send(); - // + // if (xhr.readyState === 4) { retValue.status = xhr.status; if(xhr.status == 200) { @@ -870,9 +870,9 @@ exports.CoreIoApi = Montage.create(Component, { retValue.success = false; } } - // + // return retValue; - } + } }, //////////////////////////////////////////////////////////////////// // Check if a directory/folder exists @@ -888,19 +888,19 @@ exports.CoreIoApi = Montage.create(Component, { // 404 - the directory does not exist // 500 - unknown server error occurred directoryExists: { - enumerable: false, - value: function(dir) { + enumerable: false, + value: function(dir) { var retValue = { success:null, content:null, status:null }; if(dir && dir.uri && dir.uri.length) { try { - var serviceURL = this._prepareServiceURL(this.directoryServiceURL, dir.uri), - xhr = new XMLHttpRequest(); + var serviceURL = this._prepareServiceURL(this.directoryServiceURL, dir.uri), + xhr = new XMLHttpRequest(); // xhr.open("GET", serviceURL, false); xhr.setRequestHeader("check-existence-only", "true"); - // + // xhr.send(); - // + // if (xhr.readyState === 4) { retValue.status = xhr.status; retValue.success = true; @@ -911,9 +911,9 @@ exports.CoreIoApi = Montage.create(Component, { retValue.success = false; } } - // + // return retValue; - } + } }, //////////////////////////////////////////////////////////////////// // copies an existing directory/folder to a new location @@ -931,10 +931,10 @@ exports.CoreIoApi = Montage.create(Component, { // 404 - the source directory does not exist // 500 - unknown server error occurred copyDirectory: { - enumerable: false, - value: function(dir) { + enumerable: false, + value: function(dir) { return this._copyMoveDirHelper(dir.sourceUri, dir.destUri, "copy"); - } + } }, //////////////////////////////////////////////////////////////////// // Moves an existing directory/folder to a new location @@ -952,10 +952,10 @@ exports.CoreIoApi = Montage.create(Component, { // 404 - the source directory does not exist // 500 - unknown server error occurred moveDirectory: { - enumerable: false, - value: function(dir) { + enumerable: false, + value: function(dir) { return this._copyMoveDirHelper(dir.sourceUri, dir.destUri, "move"); - } + } }, //////////////////////////////////////////////////////////////////// // Moves an existing directory/folder to a new location @@ -973,28 +973,28 @@ exports.CoreIoApi = Montage.create(Component, { // 404 - the source directory does not exist // 500 - unknown server error occurred renameDirectory: { - enumerable: false, - value: function(dir) { + enumerable: false, + value: function(dir) { return this._copyMoveDirHelper(dir.sourceUri, dir.sourceUri + "/" + dir.newDirectoryName, "move"); - } + } }, - //////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////// //Helper that is used by copyDirectory, moveDirectory, renameDirectory _copyMoveDirHelper: { - enumerable: false, - value: function(sourceDir, destDir, operation) { - var retValue = {}; + enumerable: false, + value: function(sourceDir, destDir, operation) { + var retValue = {}; if(sourceDir && sourceDir.length && destDir && destDir.length && operation && operation.length) { try { var serviceURL = this._prepareServiceURL(this.directoryServiceURL, destDir), - xhr = new XMLHttpRequest(); + xhr = new XMLHttpRequest(); // xhr.open("PUT", serviceURL, false); xhr.setRequestHeader("sourceURI", sourceDir); xhr.setRequestHeader("operation", operation); - // + // xhr.send(); - // + // if (xhr.readyState === 4) { retValue.status = xhr.status; retValue.success = true; @@ -1005,9 +1005,9 @@ exports.CoreIoApi = Montage.create(Component, { retValue.success = false; } } - // + // return retValue; - } + } }, //////////////////////////////////////////////////////////////////// // Checks if the file has been modified since it was last queried @@ -1136,31 +1136,31 @@ exports.CoreIoApi = Montage.create(Component, { }, //////////////////////////////////////////////////////////////////// // - getCloudStatus: { + 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.response = JSON.parse(xhr.response); - retValue.success = true; - } - } + 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.response = JSON.parse(xhr.response); + retValue.success = true; + } + } catch(error) { - xhr = null; - retValue.success = false; + xhr = null; + retValue.success = false; } - // + // return retValue; } }, @@ -1185,7 +1185,7 @@ exports.CoreIoApi = Montage.create(Component, { return status; } } - //////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////// }); //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// diff --git a/js/io/system/fileio.js b/js/io/system/fileio.js index d4de74f9..50b86248 100755 --- a/js/io/system/fileio.js +++ b/js/io/system/fileio.js @@ -32,208 +32,208 @@ POSSIBILITY OF SUCH DAMAGE. //////////////////////////////////////////////////////////////////////// NOTES: - For newFile, only the 'uri' is required, if contents is empty, such - empty file will be created. 'contents' should be a string to be saved - as the file. 'contentType' is the mime type of the file. - - Core API reference in NINJA: this.application.ninja.coreIoApi - + For newFile, only the 'uri' is required, if contents is empty, such + empty file will be created. 'contents' should be a string to be saved + as the file. 'contentType' is the mime type of the file. + + Core API reference in NINJA: this.application.ninja.coreIoApi + //////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// */ // -var Montage = require("montage/core/core").Montage, - Component = require("montage/ui/component").Component; +var Montage = require("montage/core/core").Montage, + Component = require("montage/ui/component").Component; //////////////////////////////////////////////////////////////////////// //Exporting as File I/O exports.FileIo = Montage.create(Component, { - //////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////// //Creating new file newFile: { - enumerable: true, - value: function(file) { - //Checking for API to be available - if (!this.application.ninja.coreIoApi.cloudAvailable()) { - //API not available, no IO action taken - return null; - } - //Peforming check for file to exist - var check = this.application.ninja.coreIoApi.fileExists({uri: file.uri}), status, create; - //Upon successful check, handling results - if (check.success) { - //Handling status of check - switch (check.status) { - case 204: - //Storing status to be returned (for UI handling) - status = check.status; - break; - case 404: - //File does not exists, ready to be created - create = this.application.ninja.coreIoApi.createFile(file); - status = create.status; - break; - default: - //Unknown Error - status = 500; - break; - } - } else { - //Unknown Error - status = 500; - } - //Returning resulting code - return status; - // 204: File exists (not created) | 400: File exists | 404: File does not exists - // 201: File succesfully created | 500: Unknown - } + enumerable: true, + value: function(file) { + //Checking for API to be available + if (!this.application.ninja.coreIoApi.cloudAvailable()) { + //API not available, no IO action taken + return null; + } + //Peforming check for file to exist + var check = this.application.ninja.coreIoApi.fileExists({uri: file.uri}), status, create; + //Upon successful check, handling results + if (check.success) { + //Handling status of check + switch (check.status) { + case 204: + //Storing status to be returned (for UI handling) + status = check.status; + break; + case 404: + //File does not exists, ready to be created + create = this.application.ninja.coreIoApi.createFile(file); + status = create.status; + break; + default: + //Unknown Error + status = 500; + break; + } + } else { + //Unknown Error + status = 500; + } + //Returning resulting code + return status; + // 204: File exists (not created) | 400: File exists | 404: File does not exists + // 201: File succesfully created | 500: Unknown + } }, //////////////////////////////////////////////////////////////////// //Reading contents from file readFile: { - enumerable: true, - value: function(file) { - //Checking for API to be available - if (!this.application.ninja.coreIoApi.cloudAvailable()) { - //API not available, no IO action taken - return null; - } - //Peforming check for file to exist - var check = this.application.n