2 /*global tizen, SystemIO, $ */
12 (function () { // strict mode wrapper
17 * file open unlock flag
20 openFileUnLocked: true,
30 storages: [{label: 'root', type: 'INTERNAL'}],
33 * API module initialisation
35 init: function Model_init() {
36 this.systemIO = new SystemIO();
40 * @returns {FileSystemStorage[]} storages
42 getInternalStorages: function Model_getInternalStorages() {
48 * @param {function} onSuccess callback
50 loadInternalStorages: function Model_loadInternalStorages(onSuccess) {
53 this.systemIO.getStorages('INTERNAL', function (storages) {
54 self.storages = storages;
55 if (typeof onSuccess === 'function') {
63 * @param {string} path Node path
64 * @param {function} onSuccess Success callback
65 * @param {function} onError Error callback
67 getFolderData: function Model_getFolderData(path, onSuccess, onError) {
69 var onOpenSuccess = function (dir) {
72 onSuccess(dir, files);
75 console.error('Model_getFolderData listFiles error', e);
79 onOpenError = function (e) {
80 console.error('Model_getFolderData openDir error', e);
83 this.systemIO.openDir(path, onOpenSuccess, onOpenError);
87 * Launch a service to open the file
88 * @param {string} fullUri ext
89 * @param {string} mime uri
91 openFile: function Model_openFile(fullUri, mime) {
92 if (this.openFileUnLocked) {
93 var self = this, serviceReplyCB = {
94 onsuccess: function (reply) {
95 self.openFileUnLocked = true;
97 onfailure: function () {
98 self.openFileUnLocked = true;
99 console.error('Launch service failed');
102 this.openFileUnLocked = false;
104 tizen.application.launchAppControl(new tizen.ApplicationControl(
105 'http://tizen.org/appcontrol/operation/view',
111 setTimeout(function () {
112 self.openFileUnLocked = true;
116 self.openFileUnLocked = true;
117 console.error('launch sevice failed. reason :' + e.message);
122 self.openFileUnLocked = true;
123 console.error('openFile error:', e);
129 * @param {File[]} nodes Collection of node objects
130 * @param {File} dir Directory handle
131 * @param {function} onSuccess
132 * @param {function} onError
134 deleteNodes: function Model_deleteNodes(nodes, dir, onSuccess, onError) {
135 var len = nodes.length,
136 onDeleteNodeSuccess = function (nodeId, isDir) {
137 if (typeof onSuccess === 'function') {
141 onDeleteNodeError = function (e) {
142 console.error('Folder delete error', e);
143 if (typeof onError === 'function') {
149 for (i = 0; i < len; i = i + 1) {
150 if (nodes[i].folder) {
154 onDeleteNodeSuccess.bind(this, nodes[i].id, true),
160 onDeleteNodeSuccess.bind(this, nodes[i].id, false),
168 * Copy specified files to destination path
169 * Overwrites existing files
171 * @param {File} dir Directory handle
172 * @param {string[]} paths Array with absolute virtual file paths
173 * @param {string} destinationPath
174 * @param {function} onSuccess callback
176 copyNodes: function Model_copyNodes(dir, paths, destinationPath, onSuccess) {
177 var len = paths.length,
179 onCopyNodeSuccess = function () {
181 if (copied === len) {
185 onCopyNodeFailure = function () {
186 alert('Copying error');
192 this.systemIO.getFilesList(dir, function (filesList) {
193 for (i = 0; i < len; i = i + 1) {
194 if (destinationPath.indexOf(paths[i]) !== -1) {
195 alert('Copying error');
200 for (i = 0; i < len; i = i + 1) {
202 sourceName = paths[i].split('/').pop();
203 sourceName = app.helpers.getCopyFileName(sourceName, filesList);
206 dir.copyTo(paths[i], destinationPath + '/' + sourceName, true, onCopyNodeSuccess, onCopyNodeFailure);
215 * Move specified files to destination path
216 * Overwrites existing files
218 * @param {File} dir Directory handle
219 * @param {string[]} paths Array with absolute virtual file paths
220 * @param {string} destinationPath
221 * @param {function} onSuccess callback
223 moveNodes: function Model_moveNodes(dir, paths, destinationPath, onSuccess) {
224 var len = paths.length,
226 onMoveNodeSuccess = function () {
232 onMoveNodeFailure = function () {
233 alert('Moving error');
239 this.systemIO.getFilesList(dir, function (filesList) {
240 for (i = 0; i < len; i = i + 1) {
241 if (destinationPath.indexOf(paths[i]) !== -1) {
242 alert('Moving error');
247 for (i = 0; i < len; i = i + 1) {
249 sourceName = paths[i].split('/').pop();
251 if ($.inArray(sourceName, filesList) !== -1) {
252 decision = confirm('A file with (' + sourceName + ') name already exists.\nDo you want to overwrite it?');
256 dir.moveTo(paths[i], destinationPath + '/' + sourceName, true, onMoveNodeSuccess, onMoveNodeFailure);