2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 /*jslint devel: true*/
18 /*global tizen, $, app, Ui, Model, Helpers, Config, Clipboard*/
22 (function () { // strict mode wrapper
26 * Creates a new application object
31 App = function App() {
42 'js/app.ui.templateManager.js',
43 'js/app.ui.templateManager.modifiers.js',
82 currentDirHandle: null,
92 init: function App_init() {
93 this.config = new Config();
94 this.model = new Model();
96 this.helpers = new Helpers();
97 this.clipboard = new Clipboard();
105 initUi: function App_initUi() {
106 this.ui.init(this.model.getInternalStorages());
110 * Displays media storages
112 displayStorages: function App_displayStorages() {
113 this.currentPath = '';
114 if (!this.ui.editMode) {
115 this.ui.scrollContentTo(0);
117 this.ui.displayStorages(this.model.getInternalStorages());
121 * Displays specified folder
122 * @param {string} path
123 * @param {bool} [refresh=false]
125 displayFolder: function App_displayFolder(path, refresh) {
128 refresh = refresh || false;
130 // get folder data and push into rendering method
131 this.model.getFolderData(path, function (dir, nodes) {
134 // update current path
135 self.currentPath = path;
137 // update current dir handle
138 self.currentDirHandle = dir;
141 if (refresh === undefined) {
142 self.ui.scrollContentTo(0);
144 self.ui.displayFolder(path, nodes, refresh);
149 * Opens specified file
150 * @params {string} uri File URI
152 openFile: function App_openFile(uri, fullUri) {
153 tizen.filesystem.resolve(
156 this.model.openFile(fullUri);
159 // file doesn't exists
160 this.ui.alertPopup('File does no longer exist',
161 this.refreshCurrentPage.bind(this, true));
167 * Displays parent location
169 goLevelUp: function App_goLevelUp() {
170 // split current path and get proper path for parent location
171 var newPath = this.currentPath.split('/').slice(0, -1).join('/');
173 if (newPath !== '') {
174 this.displayFolder(newPath);
176 this.displayStorages();
181 * creates new dir in currently viewed dir
182 * @param {string} dirName
183 * @return {boolean} return status
185 createDir: function App_createDir(dirName, callback) {
187 if (this.currentDirPath !== '') {
189 this.currentDirHandle.createDirectory(dirName);
192 app.ui.alertPopup(e.message, callback);
194 this.refreshCurrentPage();
198 'You can\'t create new nodes in the main view'
205 * Triggers refresh current page
207 refreshCurrentPage: function App_refreshCurrentPage(refresh) {
208 refresh = refresh || false;
209 if (this.currentPath === 'root') {
210 this.ui.toggleInfoPopup();
213 if (this.currentPath !== '') {
214 app.model.isStorageExists(this.currentPath,
215 app.displayFolder.bind(app, app.model.currentPath, refresh),
217 app.ui.popupHardClose();
218 app.displayStorages();
223 app.model.currentPath +
224 '" does no longer exist'
231 this.displayStorages();
236 * Deletes nodes with specified paths
237 * @param {string[]} nodes nodePaths
239 deleteNodes: function App_deleteNodes(nodes) {
240 this.model.deleteNodes(
242 this.currentDirHandle,
243 this.ui.removeNodeFromList.bind(this.ui)
248 * @param {string[]} paths filepaths
249 * @param {number} mode clipboard mode
251 saveToClipboard: function App_saveToClipboard(paths, mode) {
252 var clipboardLength = this.clipboard.add(paths);
254 if (clipboardLength > 0) {
255 this.clipboard.setMode(mode);
256 app.ui.alertPopup('Data saved in clipboard');
257 this.ui.clearTabbars();
260 'Error occured. Data has not been saved in clipboard'
264 this.ui.refreshPasteActionBtn(this.clipboard.isEmpty());
268 * Paste nodes from clipboard to current dir
270 pasteClipboard: function App_pasteClipboard() {
271 var clipboardData = this.clipboard.get();
273 if (clipboardData.length === 0) {
274 app.ui.alertPopup('Clipboard is empty');
278 if (this.clipboard.getMode() === this.clipboard.COPY_MODE_ID) {
279 this.model.copyNodes(
280 this.currentDirHandle,
283 this.onPasteClipboardSuccess.bind(this)
286 this.model.moveNodes(
287 this.currentDirHandle,
290 this.onPasteClipboardSuccess.bind(this)
294 this.ui.refreshPasteActionBtn(this.clipboard.isEmpty());
299 emptyClipboard: function App_emptyClipboard() {
300 return this.clipboard.get().length === 0;
304 * Handler for paste clipboard success
306 onPasteClipboardSuccess: function App_onPasteClipboardSuccess() {
307 this.clipboard.clear();
308 this.refreshCurrentPage();
314 exit: function App_exit() {
315 tizen.application.getCurrentApplication().exit();