2 /*global tizen, SystemIO, $ */
12 (function () { // strict mode wrapper
27 * API module initialisation
29 init: function Model_init() {
30 this.systemIO = new SystemIO();
34 * @returns {FileSystemStorage[]} storages
36 getInternalStorages: function Model_getInternalStorages() {
42 * @param {function} onSuccess callback
44 loadInternalStorages: function Model_loadInternalStorages(onSuccess) {
47 this.systemIO.getStorages('INTERNAL', function (storages) {
48 self.storages = storages;
49 if (typeof onSuccess === 'function') {
57 * @param {string} path Node path
58 * @param {function} onSuccess Success callback
59 * @param {function} onError Error callback
61 getFolderData: function Model_getFolderData(path, onSuccess, onError) {
63 var onOpenSuccess = function (dir) {
66 onSuccess(dir, files);
69 console.error('Model_getFolderData listFiles error', e);
73 onOpenError = function (e) {
74 console.error('Model_getFolderData openDir error', e);
77 this.systemIO.openDir(path, onOpenSuccess, onOpenError);
81 * Launch a service associated with 'ext' to launch the 'uri'
84 * @returns {ApplicationSevice}
86 openFile: function Model_openFile(fullUri, mime) {
87 var serviceReplyCB = {
88 onsuccess: function (reply) {
90 for (num = 0; num < reply.data.length; num += 1) {
93 onfailure: function () {
94 console.error('Launch service failed');
99 tizen.application.launchAppControl(new tizen.ApplicationControl(
100 'http://tizen.org/appcontrol/operation/view',
107 alert('launch sevice failed. reason :' + e.message);
112 console.error('openFile error:', e);
117 * @param {File[]} nodes Collection of node objects
118 * @param {File} dir Directory handle
119 * @param {function} onSuccess
120 * @param {function} onError
122 deleteNodes: function Model_deleteNodes(nodes, dir, onSuccess, onError) {
123 var len = nodes.length,
124 onDeleteNodeSuccess = function (nodeId, isDir) {
125 if (typeof onSuccess === 'function') {
129 onDeleteNodeError = function (e) {
130 console.error('Folder delete error', e);
131 if (typeof onError === 'function') {
137 for (i = 0; i < len; i = i + 1) {
138 if (nodes[i].folder) {
142 onDeleteNodeSuccess.bind(this, nodes[i].id, true),
148 onDeleteNodeSuccess.bind(this, nodes[i].id, false),
156 * Copy specified files to destination path
157 * Overwrites existing files
159 * @param {File} dir Directory handle
160 * @param {string[]} paths Array with absolute virtual file paths
161 * @param {string} destinationPath
162 * @param {function} onSuccess callback
164 copyNodes: function Model_copyNodes(dir, paths, destinationPath, onSuccess) {
165 var len = paths.length,
167 onCopyNodeSuccess = function () {
169 if (copied === len) {
173 onCopyNodeFailure = function () {
174 alert('Copying error');
180 this.systemIO.getFilesList(dir, function (filesList) {
181 for (i = 0; i < len; i = i + 1) {
182 if (destinationPath.indexOf(paths[i]) !== -1) {
183 alert('Copying error');
188 for (i = 0; i < len; i = i + 1) {
190 sourceName = paths[i].split('/').pop();
192 if ($.inArray(sourceName, filesList) !== -1) {
193 decision = confirm('A file with (' + sourceName + ') name already exists.\nDo you want to overwrite it?');
198 dir.copyTo(paths[i], destinationPath + '/' + sourceName, true, onCopyNodeSuccess, onCopyNodeFailure);
208 * Move specified files to destination path
209 * Overwrites existing files
211 * @param {File} dir Directory handle
212 * @param {string[]} paths Array with absolute virtual file paths
213 * @param {string} destinationPath
214 * @param {function} onSuccess callback
216 moveNodes: function Model_moveNodes(dir, paths, destinationPath, onSuccess) {
217 var len = paths.length,
219 onMoveNodeSuccess = function () {
225 onMoveNodeFailure = function () {
226 alert('Moving error');
232 this.systemIO.getFilesList(dir, function (filesList) {
233 for (i = 0; i < len; i = i + 1) {
234 if (destinationPath.indexOf(paths[i]) !== -1) {
235 alert('Moving error');
240 for (i = 0; i < len; i = i + 1) {
242 sourceName = paths[i].split('/').pop();
244 if ($.inArray(sourceName, filesList) !== -1) {
245 decision = confirm('A file with (' + sourceName + ') name already exists.\nDo you want to overwrite it?');
249 dir.moveTo(paths[i], destinationPath + '/' + sourceName, true, onMoveNodeSuccess, onMoveNodeFailure);