X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=project%2Fjs%2Fapp.js;h=296356f786728ac0cc74245ce011184a6d7c5fbf;hb=3610a7e902a7d3a18d5762295f8899dcd9e4f5c3;hp=297023b928fc2ef2568101d8c80fb651d30575fe;hpb=9c94ce2ec0be8f9f170d039b06cd01858a83db8b;p=apps%2Fweb%2Fsample%2FFileManager.git diff --git a/project/js/app.js b/project/js/app.js index 297023b..296356f 100644 --- a/project/js/app.js +++ b/project/js/app.js @@ -1,278 +1,318 @@ +/* + * Copyright 2013 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /*jslint devel: true*/ /*global tizen, $, app, Ui, Model, Helpers, Config, Clipboard*/ var App = null; (function () { // strict mode wrapper - 'use strict'; - - /** - * Creates a new application object - * - * @class Application - * @constructor - */ - App = function App() { - }; - - App.prototype = { - /** - * @type Array - */ - requires: [ - 'js/app.config.js', - 'js/app.model.js', - 'js/app.ui.js', - 'js/app.ui.templateManager.js', - 'js/app.ui.templateManager.modifiers.js', - 'js/app.systemIO.js', - 'js/app.helpers.js', - 'js/app.clipboard.js' - ], - - /** - * @type Model - */ - model: null, - - /** - * @type Ui - */ - ui: null, - - /** - * @type Config - */ - config: null, - - /** - * @type SystemIO - */ - systemIO: null, - - /** - * @type Helpers - */ - helpers: null, - - /** - * @type {string} - */ - currentPath: 'root', - - /** - * - */ - currentDirHandle: null, - - /** - * @type {Clipboard} - */ - clipboard: null, - - /** - * Initialization - */ - init: function App_init() { - this.config = new Config(); - this.model = new Model(); - this.ui = new Ui(); - this.helpers = new Helpers(); - this.clipboard = new Clipboard(); - - this.initUi(); - }, - - /** - * UI initialization - */ - initUi: function App_initUi() { - this.ui.init(this.model.getInternalStorages()); - }, - - /** - * Displays media storages - */ - displayStorages: function App_displayStorages() { - this.currentPath = ''; - if (!this.ui.editMode) { - this.ui.scrollContentTo(0); - } - this.ui.displayStorages(this.model.getInternalStorages()); - }, - - /** - * Displays specified folder - * @param {string} path - * @param {bool} [refresh=false] - */ - displayFolder: function App_displayFolder(path, refresh) { - var self = this; - - refresh = refresh || false; - - // get folder data and push into rendering method - this.model.getFolderData(path, function (dir, nodes) { - // on success - - // update current path - self.currentPath = path; - - // update current dir handle - self.currentDirHandle = dir; - - // display folder UI - if (refresh === undefined) { - self.ui.scrollContentTo(0); - } - self.ui.displayFolder(path, nodes, refresh); - }); - }, - - /** - * Opens specified file - * @params {string} uri File URI - */ - openFile: function App_openFile(uri, fullUri) { - var ext = this.helpers.getFileExtension(uri), - mime = this.helpers.resolveMimeType(ext); - - if (mime !== '') { - this.model.openFile(fullUri, mime); - } else { - console.error('Unsupported mime type for extension ' + ext); - } - }, - - /** - * Displays parent location - */ - goLevelUp: function App_goLevelUp() { - // split current path and get proper path for parent location - var newPath = this.currentPath.split('/').slice(0, -1).join('/'); - - if (newPath !== '') { - this.displayFolder(newPath); - } else { - this.displayStorages(); - } - }, - - /** - * creates new dir in currently viewed dir - * @param {string} dirName - * @return {boolean} return status - */ - createDir: function App_createDir(dirName, callback) { - var status = true; - if (this.currentDirPath !== '') { - try { - this.currentDirHandle.createDirectory(dirName); - } catch (e) { - status = false; - app.ui.alertPopup(e.message, callback); - } - this.refreshCurrentPage(); - } else { - status = false; - app.ui.alertPopup("You can't create new nodes in the main view"); - } - return status; - }, - - /** - * Triggers refresh current page - */ - refreshCurrentPage: function App_refreshCurrentPage(refresh) { - refresh = refresh || false; - if (this.currentPath === 'root') { - return; - } - if (this.currentPath !== '') { - app.model.isStorageExists(this.currentPath, - app.displayFolder.bind(app, app.model.currentPath, refresh), - function () { - $.mobile.popup.active && $.mobile.popup.active.close(); - app.displayStorages(); - setTimeout( - function(){ - app.ui.alertPopup( - 'Path "' + app.model.currentPath + '" does no longer exist' - ); - }, - 200 - ); - }); - } else { - this.displayStorages(); - } - }, - - /** - * Deletes nodes with specified paths - * @param {string[]} nodes nodePaths - */ - deleteNodes: function App_deleteNodes(nodes) { - this.model.deleteNodes(nodes, this.currentDirHandle, this.ui.removeNodeFromList.bind(this.ui)); - }, - - /** - * @param {string[]} paths filepaths - * @param {number} mode clipboard mode - */ - saveToClipboard: function App_saveToClipboard(paths, mode) { - var clipboardLength = this.clipboard.add(paths); - - if (clipboardLength > 0) { - this.clipboard.setMode(mode); - app.ui.alertPopup('Data saved in clipboard'); - this.ui.clearTabbars(); - } else { - app.ui.alertPopup('Error occured. Data has not been saved in clipboard'); - } - - this.ui.refreshPasteActionBtn(this.clipboard.isEmpty()); - }, - - /** - * Paste nodes from clipboard to current dir - */ - pasteClipboard: function App_pasteClipboard() { - var clipboardData = this.clipboard.get(); - - if (clipboardData.length === 0) { - app.ui.alertPopup('Clipboard is empty'); - return false; - } - - if (this.clipboard.getMode() === this.clipboard.COPY_MODE_ID) { - this.model.copyNodes(this.currentDirHandle, clipboardData, this.currentPath, this.onPasteClipboardSuccess.bind(this)); - } else { - this.model.moveNodes(this.currentDirHandle, clipboardData, this.currentPath, this.onPasteClipboardSuccess.bind(this)); - } - - this.ui.refreshPasteActionBtn(this.clipboard.isEmpty()); - - return true; - }, - - emptyClipboard: function App_emptyClipboard() { - return this.clipboard.get().length === 0; - }, - - /** - * Handler for paste clipboard success - */ - onPasteClipboardSuccess: function App_onPasteClipboardSuccess() { - this.clipboard.clear(); - this.refreshCurrentPage(); - }, - - /** - * App exit - */ - exit: function App_exit() { - tizen.application.getCurrentApplication().exit(); - } - }; + 'use strict'; + + /** + * Creates a new application object + * + * @class Application + * @constructor + */ + App = function App() { + }; + + App.prototype = { + /** + * @type Array + */ + requires: [ + 'js/app.config.js', + 'js/app.model.js', + 'js/app.ui.js', + 'js/app.ui.templateManager.js', + 'js/app.ui.templateManager.modifiers.js', + 'js/app.systemIO.js', + 'js/app.helpers.js', + 'js/app.clipboard.js' + ], + + /** + * @type Model + */ + model: null, + + /** + * @type Ui + */ + ui: null, + + /** + * @type Config + */ + config: null, + + /** + * @type SystemIO + */ + systemIO: null, + + /** + * @type Helpers + */ + helpers: null, + + /** + * @type {string} + */ + currentPath: 'root', + + /** + * + */ + currentDirHandle: null, + + /** + * @type {Clipboard} + */ + clipboard: null, + + /** + * Initialization + */ + init: function App_init() { + this.config = new Config(); + this.model = new Model(); + this.ui = new Ui(); + this.helpers = new Helpers(); + this.clipboard = new Clipboard(); + + this.initUi(); + }, + + /** + * UI initialization + */ + initUi: function App_initUi() { + this.ui.init(this.model.getInternalStorages()); + }, + + /** + * Displays media storages + */ + displayStorages: function App_displayStorages() { + this.currentPath = ''; + if (!this.ui.editMode) { + this.ui.scrollContentTo(0); + } + this.ui.displayStorages(this.model.getInternalStorages()); + }, + + /** + * Displays specified folder + * @param {string} path + * @param {bool} [refresh=false] + */ + displayFolder: function App_displayFolder(path, refresh) { + var self = this; + + refresh = refresh || false; + + // get folder data and push into rendering method + this.model.getFolderData(path, function (dir, nodes) { + // on success + + // update current path + self.currentPath = path; + + // update current dir handle + self.currentDirHandle = dir; + + // display folder UI + if (refresh === undefined) { + self.ui.scrollContentTo(0); + } + self.ui.displayFolder(path, nodes, refresh); + }); + }, + + /** + * Opens specified file + * @params {string} uri File URI + */ + openFile: function App_openFile(uri, fullUri) { + tizen.filesystem.resolve( + fullUri, + function (file) { + this.model.openFile(fullUri); + }.bind(this), + function () { + // file doesn't exists + this.ui.alertPopup('File does no longer exist', + this.refreshCurrentPage.bind(this, true)); + }.bind(this) + ); + }, + + /** + * Displays parent location + */ + goLevelUp: function App_goLevelUp() { + // split current path and get proper path for parent location + var newPath = this.currentPath.split('/').slice(0, -1).join('/'); + + if (newPath !== '') { + this.displayFolder(newPath); + } else { + this.displayStorages(); + } + }, + + /** + * creates new dir in currently viewed dir + * @param {string} dirName + * @return {boolean} return status + */ + createDir: function App_createDir(dirName, callback) { + var status = true; + if (this.currentDirPath !== '') { + try { + this.currentDirHandle.createDirectory(dirName); + } catch (e) { + status = false; + app.ui.alertPopup(e.message, callback); + } + this.refreshCurrentPage(); + } else { + status = false; + app.ui.alertPopup( + 'You can\'t create new nodes in the main view' + ); + } + return status; + }, + + /** + * Triggers refresh current page + */ + refreshCurrentPage: function App_refreshCurrentPage(refresh) { + refresh = refresh || false; + if (this.currentPath === 'root') { + this.ui.toggleInfoPopup(); + return; + } + if (this.currentPath !== '') { + app.model.isStorageExists(this.currentPath, + app.displayFolder.bind(app, app.model.currentPath, refresh), + function () { + app.ui.popupHardClose(); + app.displayStorages(); + setTimeout( + function () { + app.ui.alertPopup( + 'Path "' + + app.model.currentPath + + '" does no longer exist' + ); + }, + 200 + ); + }); + } else { + this.displayStorages(); + } + }, + + /** + * Deletes nodes with specified paths + * @param {string[]} nodes nodePaths + */ + deleteNodes: function App_deleteNodes(nodes) { + this.model.deleteNodes( + nodes, + this.currentDirHandle, + this.ui.removeNodeFromList.bind(this.ui) + ); + }, + + /** + * @param {string[]} paths filepaths + * @param {number} mode clipboard mode + */ + saveToClipboard: function App_saveToClipboard(paths, mode) { + var clipboardLength = this.clipboard.add(paths); + + if (clipboardLength > 0) { + this.clipboard.setMode(mode); + app.ui.alertPopup('Data saved in clipboard'); + this.ui.clearTabbars(); + } else { + app.ui.alertPopup( + 'Error occured. Data has not been saved in clipboard' + ); + } + + this.ui.refreshPasteActionBtn(this.clipboard.isEmpty()); + }, + + /** + * Paste nodes from clipboard to current dir + */ + pasteClipboard: function App_pasteClipboard() { + var clipboardData = this.clipboard.get(); + + if (clipboardData.length === 0) { + app.ui.alertPopup('Clipboard is empty'); + return false; + } + + if (this.clipboard.getMode() === this.clipboard.COPY_MODE_ID) { + this.model.copyNodes( + this.currentDirHandle, + clipboardData, + this.currentPath, + this.onPasteClipboardSuccess.bind(this) + ); + } else { + this.model.moveNodes( + this.currentDirHandle, + clipboardData, + this.currentPath, + this.onPasteClipboardSuccess.bind(this) + ); + } + + this.ui.refreshPasteActionBtn(this.clipboard.isEmpty()); + + return true; + }, + + emptyClipboard: function App_emptyClipboard() { + return this.clipboard.get().length === 0; + }, + + /** + * Handler for paste clipboard success + */ + onPasteClipboardSuccess: function App_onPasteClipboardSuccess() { + this.clipboard.clear(); + this.refreshCurrentPage(); + }, + + /** + * App exit + */ + exit: function App_exit() { + tizen.application.getCurrentApplication().exit(); + } + }; }());