aboutsummaryrefslogtreecommitdiff
path: root/js/io/system/ninjalibrary.js
diff options
context:
space:
mode:
authorJonathan Duran2012-05-31 08:54:48 -0700
committerJonathan Duran2012-05-31 08:54:48 -0700
commitf297093b5bfa62c9832829751a12f0e556bb5cc0 (patch)
tree6e04cdf142cb1b36e2197970c9dc2141017a2be7 /js/io/system/ninjalibrary.js
parent9253e2ce98d748edd8c3929f113a597923960387 (diff)
parentd49c909cff7f0c5e5d0b127ad84a2fefc6677dc6 (diff)
downloadninja-f297093b5bfa62c9832829751a12f0e556bb5cc0.tar.gz
Merge branch 'refs/heads/NINJAmaster' into TimelineUber
Conflicts: js/panels/Timeline/Layer.reel/Layer.js js/panels/Timeline/TimelinePanel.reel/TimelinePanel.js js/panels/properties.reel/properties.js Signed-off-by: Jonathan Duran <jduran@motorola.com>
Diffstat (limited to 'js/io/system/ninjalibrary.js')
-rw-r--r--js/io/system/ninjalibrary.js137
1 files changed, 59 insertions, 78 deletions
diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js
index f4915a91..12af5988 100644
--- a/js/io/system/ninjalibrary.js
+++ b/js/io/system/ninjalibrary.js
@@ -4,12 +4,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
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 6
7/* /////////////////////////////////////////////////////////////////////
8//////////////////////////////////////////////////////////////////////// 7////////////////////////////////////////////////////////////////////////
9NOTES:
10
11////////////////////////////////////////////////////////////////////////
12///////////////////////////////////////////////////////////////////// */
13// 8//
14var Montage = require("montage/core/core").Montage; 9var Montage = require("montage/core/core").Montage;
15//////////////////////////////////////////////////////////////////////// 10////////////////////////////////////////////////////////////////////////
@@ -18,96 +13,80 @@ exports.NinjaLibrary = Montage.create(Object.prototype, {
18 //////////////////////////////////////////////////////////////////// 13 ////////////////////////////////////////////////////////////////////
19 // 14 //
20 _chromeApi: { 15 _chromeApi: {
21 enumerable: false,
22 value: null 16 value: null
23 }, 17 },
24 //////////////////////////////////////////////////////////////////// 18 ////////////////////////////////////////////////////////////////////
25 // 19 //
26 chromeApi: { 20 chromeApi: {
27 enumerable: false, 21 get: function() {return this._chromeApi;},
28 get: function() { 22 set: function(value) {this._chromeApi = value;}
29 return this._chromeApi;
30 },
31 set: function(value) {
32 this._chromeApi = value;
33 }
34 }, 23 },
35 //////////////////////////////////////////////////////////////////// 24 ////////////////////////////////////////////////////////////////////
36 // 25 //
37 _coreApi: { 26 _coreApi: {
38 enumerable: false,
39 value: null 27 value: null
40 }, 28 },
41 //////////////////////////////////////////////////////////////////// 29 ////////////////////////////////////////////////////////////////////
42 // 30 //
43 coreApi: { 31 coreApi: {
44 enumerable: false, 32 get: function() {return this._coreApi;},
45 get: function() { 33 set: function(value) {this._coreApi = value;}
46 return this._coreApi;
47 },
48 set: function(value) {
49 this._coreApi = value;
50 }
51 }, 34 },
52 //////////////////////////////////////////////////////////////////// 35 ////////////////////////////////////////////////////////////////////
53 // 36 //
54 _libs: { 37 _libs: {
55 enumerable: false,
56 value: null 38 value: null
57 }, 39 },
58 //////////////////////////////////////////////////////////////////// 40 ////////////////////////////////////////////////////////////////////
59 // 41 //
60 libs: { 42 libs: {
61 enumerable: false, 43 get: function() {return this._libs;},
62 get: function() { 44 set: function(value) {this._libs = value;}
63 return this._libs;
64 },
65 set: function(value) {
66 this._libs = value;
67 }
68 }, 45 },
69 //////////////////////////////////////////////////////////////////// 46 ////////////////////////////////////////////////////////////////////
70 // 47 //
71 _libsToSync: { 48 _libsToSync: {
72 enumerable: false,
73 value: 0 49 value: 0
74 }, 50 },
75 //////////////////////////////////////////////////////////////////// 51 ////////////////////////////////////////////////////////////////////
76 // 52 //
77 _syncedLibs: { 53 _syncedLibs: {
78 enumerable: false,
79 value: 0 54 value: 0
80 }, 55 },
81 //////////////////////////////////////////////////////////////////// 56 ////////////////////////////////////////////////////////////////////
82 // 57 //
83 copyLibToCloud: { 58 copyLibToCloud: {
84 enumerable: false,
85 value: function (path, libName, callback) { 59 value: function (path, libName, callback) {
86 // 60 //Checking for library to exists
87 if(this.coreApi.directoryExists({uri: path+libName}).status === 404) { 61 if(this.coreApi.directoryExists({uri: path+libName}).status === 404) {
62 //Getting contents to begin copying
88 this.chromeApi.directoryContents(this.chromeApi.fileSystem.root, function (contents) { 63 this.chromeApi.directoryContents(this.chromeApi.fileSystem.root, function (contents) {
89 for (var i in contents) { 64 for (var i in contents) {
90 if (libName === contents[i].name) { 65 if (libName === contents[i].name) {
91 //Getting contents of library to be copied 66 //Getting contents of library to be copied
92 this.chromeApi.directoryContents(contents[i], function (lib) { 67 this.chromeApi.directoryContents(contents[i], function (lib) {
93 //Creating directory structure from subfolders 68 //Copying to cloud, adding blocking if no callback specified
94 this.copyDirectoryToCloud(path, contents[i], path, callback); 69 if (!callback) {
70 //TODO: Add blocking logic here
71 this.copyDirectoryToCloud(path, contents[i], path);
72 } else {
73 this.copyDirectoryToCloud(path, contents[i], path, callback);
74 }
95 }.bind(this)); 75 }.bind(this));
96 break; 76 break;
97 } 77 }
98 } 78 }
99 }.bind(this)); 79 }.bind(this));
100 } else { 80 } else {
101 //Error 81 //TODO: Add error handling
102 } 82 }
103 } 83 }
104 }, 84 },
105 //////////////////////////////////////////////////////////////////// 85 ////////////////////////////////////////////////////////////////////
106 // 86 //
107 copyDirectoryToCloud: { 87 copyDirectoryToCloud: {
108 enumerable: true,
109 value: function(root, folder, fileRoot, callback) { 88 value: function(root, folder, fileRoot, callback) {
110 // 89 //Setting up directory name
111 if (folder.name) { 90 if (folder.name) {
112 var dir; 91 var dir;
113 if (root) { 92 if (root) {
@@ -115,23 +94,26 @@ exports.NinjaLibrary = Montage.create(Object.prototype, {
115 } else { 94 } else {
116 dir = folder.name; 95 dir = folder.name;
117 } 96 }
118 // 97 //Creating directory
119 if (!this.coreApi.createDirectory({uri: dir.replace(/\/\//gi, '/')})) { 98 if (!this.coreApi.createDirectory({uri: dir.replace(/\/\//gi, '/')})) {
120 //Error occured while creating folders 99 //Error occured while creating folders
121 return; 100 return; //TODO: Add error handling
122 } 101 }
123 } 102 }
124 // 103 //Checking for directory
125 if (folder.isDirectory) { 104 if (folder.isDirectory) {
105 //Using Chrome API to get directory contents
126 this.chromeApi.directoryContents(folder, function (contents) { 106 this.chromeApi.directoryContents(folder, function (contents) {
107 //Looping through children of directory to copy
127 for (var i in contents) { 108 for (var i in contents) {
109 //Checking for file or directory
128 if (contents[i].isDirectory) { 110 if (contents[i].isDirectory) {
111 //Recursive call if directory
129 this.copyDirectoryToCloud(dir, contents[i], fileRoot); 112 this.copyDirectoryToCloud(dir, contents[i], fileRoot);
130 } else if (contents[i].isFile){ 113 } else if (contents[i].isFile){
131 //File to copy 114 //Copying file
132 this.chromeApi.fileContent(contents[i].fullPath, function (result) { 115 this.chromeApi.fileContent(contents[i].fullPath, function (result) {
133 // 116 //Using binary when copying files to allow images and such to work
134 //this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: blob.getBlob(result.data.type), contentType: result.data.type});
135 this.coreApi.createFile({uri: (fileRoot+result.file.fullPath).replace(/\/\//gi, '/'), contents: result.content}); 117 this.coreApi.createFile({uri: (fileRoot+result.file.fullPath).replace(/\/\//gi, '/'), contents: result.content});
136 }.bind(this)); 118 }.bind(this));
137 } 119 }
@@ -145,34 +127,31 @@ exports.NinjaLibrary = Montage.create(Object.prototype, {
145 //////////////////////////////////////////////////////////////////// 127 ////////////////////////////////////////////////////////////////////
146 // 128 //
147 synchronize: { 129 synchronize: {
148 enumerable: true,
149 value: function(chromeLibs, chrome) { 130 value: function(chromeLibs, chrome) {
150 //TODO: Remove 131 //TODO: Remove
151 window.wipeLibrary = this.deleteLibraries.bind(this); 132 window.wipeLibrary = this.deleteLibraries.bind(this);
152 // 133 //Getting instance of browser file API
153 this.chromeApi = chrome; 134 this.chromeApi = chrome;
154 // 135 //Local variables
155// debugger;
156 var i, l, libs, libjson, xhr = new XMLHttpRequest(), tocopylibs = []; 136 var i, l, libs, libjson, xhr = new XMLHttpRequest(), tocopylibs = [];
157 //Getting known json list of libraries to copy to chrome 137 //Getting known json list of libraries to copy to chrome (will be on a CDN later)
158 xhr.open("GET", '/js/io/system/ninjalibrary.json', false); 138 xhr.open("GET", '/js/io/system