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