From 3a754133dbc138390503341fd2e9beba3e43aa4b Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Fri, 27 Jan 2012 12:05:17 -0800 Subject: Merged old FileIO --- js/io/system/fileio.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 js/io/system/fileio.js (limited to 'js/io/system/fileio.js') diff --git a/js/io/system/fileio.js b/js/io/system/fileio.js old mode 100644 new mode 100755 -- cgit v1.2.3 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/fileio.js | 169 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 131 insertions(+), 38 deletions(-) (limited to 'js/io/system/fileio.js') diff --git a/js/io/system/fileio.js b/js/io/system/fileio.js index 1d76a91b..b3158a68 100755 --- a/js/io/system/fileio.js +++ b/js/io/system/fileio.js @@ -3,22 +3,139 @@ This file contains proprietary software owned by Motorola Mobility, Inc.
No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ +/* ///////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +NOTES: -//Required modules -var Serializer = require("montage/core/serializer").Serializer; + 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. + +//////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////// */ +// +var Montage = require("montage/core/core").Montage, + CoreIoApi = require("js/io/system/coreioapi").CoreIoApi; +//////////////////////////////////////////////////////////////////////// //Exporting as File I/O -exports.FileIo = (require("montage/core/core").Montage).create(Object.prototype, { - /* -create: { - enumerable: true, - value: function (type) { - // - } - }, -*/ +exports.FileIo = Montage.create(Object.prototype, { //////////////////////////////////////////////////////////////////// - // - open: { + //newFile Object (*required): {uri*, contents, contentType} + //Return codes + // 204: File exists | 400: File exists | 404: File does not exists + // 201: File succesfully created | 500: Unknown | undefined: Unknown + newFile: { + enumerable: true, + value: function(file) { + //Checking for API to be available + if (!CoreIoApi.isIoServiceActive()) { + //API not available, no IO action taken + return null; + } + //Peforming check for file to exist + var check = CoreIoApi.fileExists(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 = CoreIoApi.createFile(file); + //Storing status to be returned (for UI handling) + if (create.success) { + status = check.status; + } + break; + default: + //Unknown Error + break; + } + } else { + //Unknown Error + } + //Returning resulting code + return status; + } + }, + readFile: { + enumerable: true, + value: function() { + // + } + }, + saveFile: { + enumerable: true, + value: function() { + // + } + }, + copyFile: { + enumerable: true, + value: function() { + // + } + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + /* +open: { enumerable: true, value: function(doc, type, uri, server) { // @@ -70,32 +187,7 @@ create: { enumerable: true, value: function(type, id, components) { - /* - - GETS HTML IN LOADED DOCUMENT - document.getElementById('userDocument').contentDocument.documentElement.outerHTML - - GETS HTML IN AND OR ANYTHING INSIDE - document.getElementById('userDocument').contentDocument.documentElement.innerHTML - - THE ABOVE METHOD SEEMS TO BE BETTER JUST IN CASE PEOPLE REMOVE THE BODY TAG SINCE NOT REQUIRED IN HTML5 - - GETS HTML IN ONLY - document.getElementById('userDocument').contentDocument.body.innerHTML - HACK TO GET THE STYLES OF THE ELEMENTS ADDED WHILE DRAWING - document.getElementById('userDocument').contentDocument.styleSheets[document.getElementById('userDocument').contentDocument.styleSheets.length-1] - - CSS SEEMS TO BE RESERVED WHEN APPENDED, MEANING 0 IN THE ARRAY IS ACTUALLY THE LAST DEFINED STYLE IN THE CSS - - //GETS CSS RULES APPLIED TO ALL OBJECTS CREATED BY THE APP - document.getElementById('userDocument').contentDocument.styleSheets[document.getElementById('userDocument').contentDocument.styleSheets.length-1].cssRules - - document.getElementById('userDocument').contentDocument.getElementById('userHead').innerHTML - document.getElementById('userDocument').contentDocument.getElementById('UserContent').innerHTML - this.getCssFromRules(document.getElementById('userDocument').contentDocument.styleSheets[document.getElementById('userDocument').contentDocument.styleSheets.length-1].cssRules) - - */ // var contents, counter = 0; @@ -215,6 +307,7 @@ create: { return css; } } +*/ -- 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/fileio.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'js/io/system/fileio.js') diff --git a/js/io/system/fileio.js b/js/io/system/fileio.js index b3158a68..38ab05e8 100755 --- a/js/io/system/fileio.js +++ b/js/io/system/fileio.js @@ -28,7 +28,7 @@ exports.FileIo = Montage.create(Object.prototype, { enumerable: true, value: function(file) { //Checking for API to be available - if (!CoreIoApi.isIoServiceActive()) { + if (!CoreIoApi.cloudAvailable()) { //API not available, no IO action taken return null; } @@ -78,6 +78,12 @@ exports.FileIo = Montage.create(Object.prototype, { value: function() { // } + }, + infoFile: { + enumerable: true, + value: function() { + // + } } -- cgit v1.2.3 From d74910a897f2db920f6f67d922532d245074c8f7 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Wed, 1 Feb 2012 11:51:24 -0800 Subject: Fixing coreIO API referencing --- js/io/system/fileio.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'js/io/system/fileio.js') 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: empty file will be created. 'contents' should be a string to be saved as the file. 'contentType' is the mime type of the file. + coreIoApi: this.application.ninja.coreIoApi + //////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// */ // -var Montage = require("montage/core/core").Montage, - CoreIoApi = require("js/io/system/coreioapi").CoreIoApi; +var Montage = require("montage/core/core").Montage; //////////////////////////////////////////////////////////////////////// //Exporting as File I/O exports.FileIo = Montage.create(Object.prototype, { @@ -28,12 +29,12 @@ exports.FileIo = Montage.create(Object.prototype, { enumerable: true, value: function(file) { //Checking for API to be available - if (!CoreIoApi.cloudAvailable()) { + if (!this.application.ninja.coreIoApi.cloudAvailable()) { //API not available, no IO action taken return null; } //Peforming check for file to exist - var check = CoreIoApi.fileExists(file.uri), status, create; + var check = this.application.ninja.coreIoApi.fileExists(file.uri), status, create; //Upon successful check, handling results if (check.success) { //Handling status of check @@ -44,7 +45,7 @@ exports.FileIo = Montage.create(Object.prototype, { break; case 404: //File does not exists, ready to be created - create = CoreIoApi.createFile(file); + create = this.application.ninja.coreIoApi.createFile(file); //Storing status to be returned (for UI handling) if (create.success) { status = check.status; -- cgit v1.2.3 From 42122c5c708769e11b626654bf3d989b6b0eddad Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Wed, 1 Feb 2012 13:34:53 -0800 Subject: Updating after merge with other FileIO branch --- js/io/system/fileio.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'js/io/system/fileio.js') diff --git a/js/io/system/fileio.js b/js/io/system/fileio.js index ac5812e9..f40aa96b 100755 --- a/js/io/system/fileio.js +++ b/js/io/system/fileio.js @@ -11,7 +11,7 @@ NOTES: empty file will be created. 'contents' should be a string to be saved as the file. 'contentType' is the mime type of the file. - coreIoApi: this.application.ninja.coreIoApi + Core API reference in NINJA: this.application.ninja.coreIoApi //////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// */ @@ -65,24 +65,44 @@ exports.FileIo = Montage.create(Object.prototype, { readFile: { enumerable: true, value: function() { + //Checking for API to be available + if (!this.application.ninja.coreIoApi.cloudAvailable()) { + //API not available, no IO action taken + return null; + } // } }, saveFile: { enumerable: true, value: function() { + //Checking for API to be available + if (!this.application.ninja.coreIoApi.cloudAvailable()) { + //API not available, no IO action taken + return null; + } // } }, copyFile: { enumerable: true, value: function() { + //Checking for API to be available + if (!this.application.ninja.coreIoApi.cloudAvailable()) { + //API not available, no IO action taken + return null; + } // } }, infoFile: { enumerable: true, value: function() { + //Checking for API to be available + if (!this.application.ninja.coreIoApi.cloudAvailable()) { + //API not available, no IO action taken + return null; + } // } } -- cgit v1.2.3 From 8e06b63e5eab5558823f4923e20a832c8b36cbe2 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Thu, 2 Feb 2012 23:55:33 -0800 Subject: Chrome FileSystem API Testing Doing benchmark testing of the native HTML5 FileSystem API available in Chrome. Need to run testing of local XHR requests and also getting files from packaged app. --- js/io/system/fileio.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'js/io/system/fileio.js') diff --git a/js/io/system/fileio.js b/js/io/system/fileio.js index f40aa96b..4ab98606 100755 --- a/js/io/system/fileio.js +++ b/js/io/system/fileio.js @@ -3,6 +3,7 @@ This file contains proprietary software owned by Motorola Mobility, Inc.
No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ + /* ///////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// NOTES: @@ -62,6 +63,8 @@ exports.FileIo = Montage.create(Object.prototype, { return status; } }, + //////////////////////////////////////////////////////////////////// + // readFile: { enumerable: true, value: function() { @@ -73,6 +76,8 @@ exports.FileIo = Montage.create(Object.prototype, { // } }, + //////////////////////////////////////////////////////////////////// + // saveFile: { enumerable: true, value: function() { @@ -84,6 +89,8 @@ exports.FileIo = Montage.create(Object.prototype, { // } }, + //////////////////////////////////////////////////////////////////// + // copyFile: { enumerable: true, value: function() { @@ -95,6 +102,8 @@ exports.FileIo = Montage.create(Object.prototype, { // } }, + //////////////////////////////////////////////////////////////////// + // infoFile: { enumerable: true, value: function() { @@ -106,7 +115,8 @@ exports.FileIo = Montage.create(Object.prototype, { // } } - + //////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////// @@ -339,8 +349,7 @@ open: { - //////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////// + }); //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// \ No newline at end of file -- cgit v1.2.3 From 23d958580a785ae265bb0a78f238093cc93cee85 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Sat, 4 Feb 2012 22:32:18 -0800 Subject: Setting up Chrome File System API class Chrome file system API will be used to copy over files from the sandboxed app into the sandboxed file system directory (in Chrome) to then be used by the core API and the cloud. --- js/io/system/fileio.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/io/system/fileio.js') diff --git a/js/io/system/fileio.js b/js/io/system/fileio.js index 4ab98606..355812da 100755 --- a/js/io/system/fileio.js +++ b/js/io/system/fileio.js @@ -17,7 +17,7 @@ NOTES: //////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// */ // -var Montage = require("montage/core/core").Montage; +var Montage = require("montage/core/core").Montage; //////////////////////////////////////////////////////////////////////// //Exporting as File I/O exports.FileIo = Montage.create(Object.prototype, { -- cgit v1.2.3 From 8c530e9291721083ba11746fc5b3da66dc692120 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Sun, 5 Feb 2012 10:42:58 -0800 Subject: Setting up IO Ninja Library This class will be used to copy locally the library needed for Ninja's IO. --- js/io/system/fileio.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'js/io/system/fileio.js') diff --git a/js/io/system/fileio.js b/js/io/system/fileio.js index 355812da..2c49e849 100755 --- a/js/io/system/fileio.js +++ b/js/io/system/fileio.js @@ -91,6 +91,19 @@ exports.FileIo = Montage.create(Object.prototype, { }, //////////////////////////////////////////////////////////////////// // + deleteFile: { + enumerable: true, + value: function() { + //Checking for API to be available + if (!this.application.ninja.coreIoApi.cloudAvailable()) { + //API not available, no IO action taken + return null; + } + // + } + }, + //////////////////////////////////////////////////////////////////// + // copyFile: { enumerable: true, value: function() { -- cgit v1.2.3 From 9140a5bb6e7ecc24e6b4e540308042e10165e604 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Thu, 9 Feb 2012 11:07:10 -0800 Subject: New File Adding new file functionality, awaiting UI to implement correct file path for templates to hook into mediator. --- js/io/system/fileio.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'js/io/system/fileio.js') diff --git a/js/io/system/fileio.js b/js/io/system/fileio.js index 2c49e849..7bf4d41f 100755 --- a/js/io/system/fileio.js +++ b/js/io/system/fileio.js @@ -17,15 +17,13 @@ NOTES: //////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// */ // -var Montage = require("montage/core/core").Montage; +var Montage = require("montage/core/core").Montage, + Component = require("montage/ui/component").Component; //////////////////////////////////////////////////////////////////////// //Exporting as File I/O -exports.FileIo = Montage.create(Object.prototype, { +exports.FileIo = Montage.create(Component, { //////////////////////////////////////////////////////////////////// //newFile Object (*required): {uri*, contents, contentType} - //Return codes - // 204: File exists | 400: File exists | 404: File does not exists - // 201: File succesfully created | 500: Unknown | undefined: Unknown newFile: { enumerable: true, value: function(file) { @@ -35,7 +33,7 @@ exports.FileIo = Montage.create(Object.prototype, { return null; } //Peforming check for file to exist - var check = this.application.ninja.coreIoApi.fileExists(file.uri), status, create; + var check = this.application.ninja.coreIoApi.fileExists({uri: file.uri}), status, create; //Upon successful check, handling results if (check.success) { //Handling status of check @@ -47,10 +45,7 @@ exports.FileIo = Montage.create(Object.prototype, { case 404: //File does not exists, ready to be created create = this.application.ninja.coreIoApi.createFile(file); - //Storing status to be returned (for UI handling) - if (create.success) { - status = check.status; - } + status = create.status; break; default: //Unknown Error @@ -61,6 +56,8 @@ exports.FileIo = Montage.create(Object.prototype, { } //Returning resulting code return status; + // 204: File exists | 400: File exists | 404: File does not exists + // 201: File succesfully created | 500: Unknown | undefined: Unknown } }, //////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From 74efc1238f51e9c0ffdeffe2a349f66011ef9f17 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Thu, 9 Feb 2012 15:02:16 -0800 Subject: File Open Adding file open functionality. --- js/io/system/fileio.js | 68 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 3 deletions(-) (limited to 'js/io/system/fileio.js') diff --git a/js/io/system/fileio.js b/js/io/system/fileio.js index 7bf4d41f..045fa2fd 100755 --- a/js/io/system/fileio.js +++ b/js/io/system/fileio.js @@ -64,13 +64,40 @@ exports.FileIo = Montage.create(Component, { // readFile: { enumerable: true, - value: function() { + 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, result; + //Upon successful check, handling results + if (check.success) { + //Handling status of check + switch (check.status) { + case 204: + //File exists + result = {}; + result.content = this.application.ninja.coreIoApi.readFile(file).content; + result.details = this.infoFile(file); + status = check.status; + break; + case 404: + //File does not exists, ready to be created + status = check.status; + break; + default: + //Unknown Error + status = 500; + break; + } + } else { + //Unknown Error + status = 500; + } + //Returning resulting code + return {status: status, file: result}; } }, //////////////////////////////////////////////////////////////////// @@ -116,14 +143,49 @@ exports.FileIo = Montage.create(Component, { // infoFile: { enumerable: true, - value: function() { + value: function(file) { //Checking for API to be available if (!this.application.ninja.coreIoApi.cloudAvailable()) { //API not available, no IO action taken return null; } // + var check = this.application.ninja.coreIoApi.fileExists({uri: file.uri}), details; + // + if (check.success) { + //Handling status of check + switch (check.status) { + case 204: + //File exists + details = JSON.parse(this.application.ninja.coreIoApi.isFileWritable(file).content); + details.uri = file.uri; + details.name = this.getFileNameFromPath(file.uri); + details.extension = details.name.split('.')[details.name.split('.').length-1]; + break; + case 404: + //File does not exists, ready to be created + + break; + default: + //Unknown Error + + break; + } + } else { + //Unknown Error + + } + return details; } + }, + //////////////////////////////////////////////////////////////////// + // + getFileNameFromPath : { + value: function(path) { + path = path.replace(/[/\\]$/g,""); + path = path.replace(/\\/g,"/"); + return path.substr(path.lastIndexOf('/') + 1); + } } //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From b1fc4f84d92efeaa33ec239b662235c9e8218d0c Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Sun, 12 Feb 2012 16:50:33 -0800 Subject: File Save (HTML only) Added the ability to save an HTML file from design view, need to add CSS detection and saving (of styles in