aboutsummaryrefslogtreecommitdiff
path: root/js/io/system
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-01-30 14:35:11 -0800
committerJose Antonio Marquez2012-01-30 14:35:11 -0800
commit2f61dfca4466661e1ea23888675a86b601b58c63 (patch)
treea86bf1b6d3f98776f0b329f2f8f0a3cc2e2dc71c /js/io/system
parent4d5f9c451524829f55ddf26642cb9fc28228b6ce (diff)
downloadninja-2f61dfca4466661e1ea23888675a86b601b58c63.tar.gz
Setting up new file
Adding base functionality to creating files.
Diffstat (limited to 'js/io/system')
-rwxr-xr-xjs/io/system/coreioapi.js64
-rwxr-xr-xjs/io/system/fileio.js169
2 files changed, 175 insertions, 58 deletions
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
7/* ///////////////////////////////////////////////////////////////////// 7/* /////////////////////////////////////////////////////////////////////
8//////////////////////////////////////////////////////////////////////// 8////////////////////////////////////////////////////////////////////////
9NOTES: 9NOTES:
10These methods should only be access through the file and project IO classes.
11//////////////////////////////////////////////////////////////////////// 10////////////////////////////////////////////////////////////////////////
12///////////////////////////////////////////////////////////////////// */ 11///////////////////////////////////////////////////////////////////// */
13var Montage = require("montage/core/core").Montage, 12var Montage = require("montage/core/core").Montage,
@@ -20,22 +19,29 @@ exports.CoreIoApi = Montage.create(Component, {
20 deserializedFromTemplate: { 19 deserializedFromTemplate: {
21 enumerable: false, 20 enumerable: false,
22 value: function () { 21 value: function () {
23 //////////////////////////////////////////////////////////// 22 //Checking for local storage of URL for IO
24 23 if (window.localStorage['ioRootUrl']) {
25 //TODO: Add logic for getting rooUrl from local storage 24 //Getting URL from local storage
26 25 this.rootUrl = window.localStorage['ioRootUrl'];
27 //////////////////////////////////////////////////////////// 26 //Checks for IO API to be active
28 27 this.ioServiceDetected = this.isIoServiceActive();
29 28 //
30 29 console.log('FileIO: localStorage URL detected | IO Service Detected: '+ this.ioServiceDetected);
31 //Checking for status of I/O API 30 //
32 this.ioDetected = this.isActive(); 31 } else {
33 //TODO: Add welcome screen logic, probably externally 32 //TODO: Remove, automatically prompt user on welcome
33 this.rootUrl = 'http://localhost:16380';
34 //TODO: Changed to false, welcome screen prompts user
35 this.ioServiceDetected = this.isIoServiceActive();
36 //
37 console.log('FileIO: localStorage URL NOT detected | IO Service Detected: '+ this.ioServiceDetected);
38 //
39 }
34 } 40 }
35 }, 41 },
36 //////////////////////////////////////////////////////////////////// 42 ////////////////////////////////////////////////////////////////////
37 //Method to check status of I/O API, will return false if not active 43 //Method to check status of I/O API, will return false if not active
38 isActive: { 44 isIoServiceActive: {
39 enumerable: false, 45 enumerable: false,
40 value: function () { 46 value: function () {
41 //Doing a directory root check, a 200 status means running 47 //Doing a directory root check, a 200 status means running
@@ -47,27 +53,27 @@ exports.CoreIoApi = Montage.create(Component, {
47 } 53 }
48 }, 54 },
49 //////////////////////////////////////////////////////////////////// 55 ////////////////////////////////////////////////////////////////////
50 //Root API URL 56 //
51 _ioDetected: { 57 _ioServiceDetected: {
52 enumerable: false, 58 enumerable: false,
53 value: false 59 value: false
54 }, 60 },
55 //////////////////////////////////////////////////////////////////// 61 ////////////////////////////////////////////////////////////////////
56 // 62 //Checking for service availability on boot
57 ioDetected: { 63 ioServiceDetected: {
58 enumerable: false, 64 enumerable: false,
59 get: function() { 65 get: function() {
60 return this._ioDetected; 66 return this._ioServiceDetected;
61 }, 67 },
62 set: function(value) { 68 set: function(value) {
63 this._ioDetected = value; 69 this._ioServiceDetected = value;
64 } 70 }
65 }, 71 },
66 //////////////////////////////////////////////////////////////////// 72 ////////////////////////////////////////////////////////////////////
67 //Root API URL 73 //Root API URL
68 _rootUrl: { 74 _rootUrl: {
69 enumerable: false, 75 enumerable: false,
70 value: 'http://localhost:16380' 76 value: null
71 }, 77 },
72 //////////////////////////////////////////////////////////////////// 78 ////////////////////////////////////////////////////////////////////
73 // 79 //
@@ -78,6 +84,24 @@ exports.CoreIoApi = Montage.create(Component, {
78 }, 84 },
79 set: function(value) { 85 set: function(value) {
80 this._rootUrl = value; 86 this._rootUrl = value;
87 window.localStorage["ioRootUrl"] = value;
88 }
89 },
90 ////////////////////////////////////////////////////////////////////
91 //API service URL
92 _apiServiceURL: {
93 enumerable: false,
94 value: '/'
95 },
96 ////////////////////////////////////////////////////////////////////
97 //
98 apiServiceURL: {
99 enumerable: false,
100 get: function() {
101 return this.rootUrl+this._apiServiceURL;
102 },
103 set: function(value) {
104 this._apiServiceURL = value;
81 } 105 }
82 }, 106 },
83 //////////////////////////////////////////////////////////////////// 107 ////////////////////////////////////////////////////////////////////
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.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> 3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. 4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */ 5</copyright> */
6/* /////////////////////////////////////////////////////////////////////
7////////////////////////////////////////////////////////////////////////
8NOTES:
6 9
7//Required modules 10 For newFile, only the 'uri' is required, if contents is empty, such
8var Serializer = require("montage/core/serializer").Serializer; 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.
13
14////////////////////////////////////////////////////////////////////////
15///////////////////////////////////////////////////////////////////// */
16//
17var Montage = require("montage/core/core").Montage,
18 CoreIoApi = require("js/io/system/coreioapi").CoreIoApi;
19////////////////////////////////////////////////////////////////////////
9//Exporting as File I/O 20//Exporting as File I/O
10exports.FileIo = (require("montage/core/core").Montage).create(Object.prototype, { 21exports.FileIo = Montage.create(Object.prototype, {
11 /*
12create: {
13 enumerable: true,
14 value: function (type) {
15 //
16 }
17 },
18*/
19 //////////////////////////////////////////////////////////////////// 22 ////////////////////////////////////////////////////////////////////
20 // 23 //newFile Object (*required): {uri*, contents, contentType}
21 open: { 24 //Return codes
25 // 204: File exists | 400: File exists | 404: File does not exists
26 // 201: File succesfully created | 500: Unknown | undefined: Unknown
27 newFile: {
28 enumerable: true,
29 value: function(file) {
30 //Checking for API to be available
31 if (!CoreIoApi.isIoServiceActive()) {
32 //API not available, no IO action taken
33 return null;
34 }
35 //Peforming check for file to exist
36 var check = CoreIoApi.fileExists(file.uri), status, create;
37 //Upon successful check, handling results
38 if (check.success) {
39 //Handling status of check
40 switch (check.status) {
41 case 204:
42 //Storing status to be returned (for UI handling)
43 status = check.status;
44 break;
45 case 404:
46 //File does not exists, ready to be created
47 create = CoreIoApi.createFile(file);
48 //Storing status to be returned (for UI handling)
49 if (create.success) {
50 status = check.status;
51 }
52 break;
53 default:
54 //Unknown Error
55 break;
56 }
57 } else {
58 //Unknown Error
59 }
60 //Returning resulting code
61 return status;
62 }
63 },
64 readFile: {
65 enumerable: true,
66 value: function() {
67 //
68 }
69 },
70 saveFile: {
71 enumerable: true,
72 value: function() {
73 //
74 }
75 },
76 copyFile: {
77 enumerable: true,
78 value: function() {
79 //
80 }
81 }
82
83
84
85
86
87
88
89
90
91
92
93
94
95