diff options
Diffstat (limited to 'js/io/system/ninjalibrary.js')
-rw-r--r-- | js/io/system/ninjalibrary.js | 77 |
1 files changed, 74 insertions, 3 deletions
diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js index fa2e7d1f..0ab19401 100644 --- a/js/io/system/ninjalibrary.js +++ b/js/io/system/ninjalibrary.js | |||
@@ -8,8 +8,6 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
8 | //////////////////////////////////////////////////////////////////////// | 8 | //////////////////////////////////////////////////////////////////////// |
9 | NOTES: | 9 | NOTES: |
10 | 10 | ||
11 | Core API reference in NINJA: this.application.ninja.coreIoApi | ||
12 | |||
13 | //////////////////////////////////////////////////////////////////////// | 11 | //////////////////////////////////////////////////////////////////////// |
14 | ///////////////////////////////////////////////////////////////////// */ | 12 | ///////////////////////////////////////////////////////////////////// */ |
15 | // | 13 | // |
@@ -36,6 +34,23 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { | |||
36 | }, | 34 | }, |
37 | //////////////////////////////////////////////////////////////////// | 35 | //////////////////////////////////////////////////////////////////// |
38 | // | 36 | // |
37 | _coreApi: { | ||
38 | enumerable: false, | ||
39 | value: null | ||
40 | }, | ||
41 | //////////////////////////////////////////////////////////////////// | ||
42 | // | ||
43 | coreApi: { | ||
44 | enumerable: false, | ||
45 | get: function() { | ||
46 | return this._coreApi; | ||
47 | }, | ||
48 | set: function(value) { | ||
49 | this._coreApi = value; | ||
50 | } | ||
51 | }, | ||
52 | //////////////////////////////////////////////////////////////////// | ||
53 | // | ||
39 | _libsToSync: { | 54 | _libsToSync: { |
40 | enumerable: false, | 55 | enumerable: false, |
41 | value: 0 | 56 | value: 0 |
@@ -46,6 +61,62 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { | |||
46 | enumerable: false, | 61 | enumerable: false, |
47 | value: 0 | 62 | value: 0 |
48 | }, | 63 | }, |
64 | //////////////////////////////////////////////////////////////////// | ||
65 | // | ||
66 | copyLibToCloud: { | ||
67 | enumerable: false, | ||
68 | value: function (path, libName) { | ||
69 | // | ||
70 | if(this.coreApi.directoryExists({uri: '/'+path+'/'+libName+'/'}).status === 404) { | ||
71 | this.chromeApi.directoryContents(this.chromeApi.fileSystem.root, function (contents) { | ||
72 | for (var i in contents) { | ||
73 | if (libName === contents[i].name) { | ||
74 | //Getting contents of library to be copied | ||
75 | this.chromeApi.directoryContents(contents[i], function (lib) { | ||
76 | //Creating directory structure from subfolders | ||
77 | this.copyDirectoryToCloud(path, contents[i], function (status) {console.log(status)}); | ||
78 | }.bind(this)); | ||
79 | break; | ||
80 | } | ||
81 | } | ||
82 | }.bind(this)); | ||
83 | } else { | ||
84 | //Error | ||
85 | } | ||
86 | } | ||
87 | }, | ||
88 | //////////////////////////////////////////////////////////////////// | ||
89 | // | ||
90 | copyDirectoryToCloud: { | ||
91 | enumerable: true, | ||
92 | value: function(root, folder, callback) { | ||
93 | if (folder.name) { | ||
94 | var dir; | ||
95 | if (root) { | ||
96 | dir = root+'/'+folder.name; | ||
97 | } else { | ||
98 | dir = folder.name; | ||
99 | } | ||
100 | // | ||
101 | if (!this.coreApi.createDirectory({uri: '/'+dir+'/'})) { | ||
102 | //Error occured while creating folders | ||
103 | return; | ||
104 | } | ||
105 | } | ||
106 | // | ||
107 | if (folder.isDirectory) { | ||
108 | this.chromeApi.directoryContents(folder, function (contents) { | ||
109 | for (var i in contents) { | ||
110 | if (contents[i].isDirectory) { | ||
111 | this.copyDirectoryToCloud(dir, contents[i]); | ||
112 | } else if (contents[i].isFile){ | ||
113 | //File to copy | ||
114 | } | ||
115 | } | ||
116 | }.bind(this)); | ||
117 | } | ||
118 | } | ||
119 | }, | ||
49 | //////////////////////////////////////////////////////////////////// | 120 | //////////////////////////////////////////////////////////////////// |
50 | // | 121 | // |
51 | synchronize: { | 122 | synchronize: { |
@@ -81,7 +152,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { | |||
81 | } | 152 | } |
82 | } else { | 153 | } else { |
83 | //TODO: Remove, currently manually removing copied libraries | 154 | //TODO: Remove, currently manually removing copied libraries |
84 | this.chromeApi.directoryDelete(chromeLibs[i]); | 155 | //this.chromeApi.directoryDelete(chromeLibs[i]); |
85 | } | 156 | } |
86 | } | 157 | } |
87 | 158 | ||