2 /*global tizen, $, app, Ui, Model, Helpers, Config, Clipboard*/
6 (function () { // strict mode wrapper
10 * Creates a new application object
15 App = function App() {
22 requires: ['js/app.config.js', 'js/app.model.js', 'js/app.ui.js', 'js/app.ui.templateManager.js', 'js/app.systemIO.js', 'js/app.helpers.js', 'js/app.clipboard.js'],
57 currentDirHandle: null,
67 init: function App_init() {
68 this.config = new Config();
69 this.model = new Model();
71 this.helpers = new Helpers();
72 this.clipboard = new Clipboard();
81 initUi: function App_initUi() {
82 this.ui.init(this.model.getInternalStorages());
88 addEvents: function App_addEvents() {
90 document.addEventListener('webkitvisibilitychange', function () { self.refreshCurrentPage(); });
91 // workaround: page refresh for on/off keyboard
92 window.addEventListener('softkeyboardchange',function () {
93 $.mobile.activePage.page('refresh');
98 * Displays media storages
100 displayStorages: function App_displayStorages() {
101 this.currentPath = '';
102 this.ui.scrollContentTo(0);
103 this.ui.displayStorages(this.model.getInternalStorages());
107 * Displays specified folder
108 * @param {string} path
109 * @param {bool} [refresh=false]
111 displayFolder: function App_displayFolder(path, refresh) {
114 refresh = refresh || false;
116 // get folder data and push into rendering method
117 this.model.getFolderData(path, function (dir, nodes) {
120 // update current path
121 self.currentPath = path;
123 // update current dir handle
124 self.currentDirHandle = dir;
127 if (refresh === undefined) {
128 self.ui.scrollContentTo(0);
130 self.ui.displayFolder(path, nodes, refresh);
135 * Opens specified file
136 * @params {string} uri File URI
138 openFile: function App_openFile(uri, fullUri) {
139 var ext = this.helpers.getFileExtension(uri),
140 mime = this.helpers.resolveMimeType(ext);
143 this.model.openFile(fullUri, mime);
145 console.error('Unsupported mime type for extension ' + ext);
150 * Displays parent location
152 goLevelUp: function App_goLevelUp() {
153 // split current path and get proper path for parent location
154 var newPath = this.currentPath.split('/').slice(0, -1).join('/');
156 if (newPath !== '') {
157 this.displayFolder(newPath);
159 this.displayStorages();
164 * creates new dir in currently viewed dir
165 * @param {string} dirName
167 createDir: function App_createDir(dirName) {
169 if (this.currentDirPath !== '') {
171 this.currentDirHandle.createDirectory(dirName);
175 this.refreshCurrentPage();
177 alert("You can't create new nodes in the main view");
182 * Triggers refresh current page
184 refreshCurrentPage: function App_refreshCurrentPage() {
185 if (this.currentPath !== '') {
186 this.displayFolder(this.currentPath, true);
188 this.displayStorages();
193 * Deletes nodes with specified paths
194 * @param {string[]} nodes nodePaths
196 deleteNodes: function App_deleteNodes(nodes) {
197 this.model.deleteNodes(nodes, this.currentDirHandle, this.ui.removeNodeFromList.bind(this.ui));
201 * @param {string[]} paths filepaths
202 * @param {number} mode clipboard mode
204 saveToClipboard: function App_saveToClipboard(paths, mode) {
205 var clipboardLength = this.clipboard.add(paths);
207 if (clipboardLength > 0) {
208 this.clipboard.setMode(mode);
209 alert('Data saved in clipboard');
210 this.ui.clearTabbars();
212 alert('Error occured. Data has not been saved in clipboard');
215 this.ui.refreshPasteActionBtn(this.clipboard.isEmpty());
219 * Paste nodes from clipboard to current dir
221 pasteClipboard: function App_pasteClipboard() {
222 var clipboardData = this.clipboard.get();
224 if (clipboardData.length === 0) {
225 alert('Clipboard is empty');
229 if (this.clipboard.getMode() === this.clipboard.COPY_MODE_ID) {
230 this.model.copyNodes(this.currentDirHandle, clipboardData, this.currentPath, this.onPasteClipboardSuccess.bind(this));
232 this.model.moveNodes(this.currentDirHandle, clipboardData, this.currentPath, this.onPasteClipboardSuccess.bind(this));
235 this.ui.refreshPasteActionBtn(this.clipboard.isEmpty());
241 * Handler for paste clipboard success
243 onPasteClipboardSuccess: function App_onPasteClipboardSuccess() {
244 this.clipboard.clear();
245 this.refreshCurrentPage();
251 exit: function App_exit() {
252 tizen.application.getCurrentApplication().exit();