2 /*global tizen, $, app, Ui, Model, Helpers, Config, Clipboard*/
6 (function () { // strict mode wrapper
10 * Creates a new application object
15 App = function App() {
26 'js/app.ui.templateManager.js',
27 'js/app.ui.templateManager.modifiers.js',
66 currentDirHandle: null,
76 init: function App_init() {
77 this.config = new Config();
78 this.model = new Model();
80 this.helpers = new Helpers();
81 this.clipboard = new Clipboard();
90 initUi: function App_initUi() {
91 this.ui.init(this.model.getInternalStorages());
97 addEvents: function App_addEvents() {
99 document.addEventListener('webkitvisibilitychange', function () {
100 self.refreshCurrentPage();
102 // workaround: page refresh for on/off keyboard
103 window.addEventListener('softkeyboardchange', function () {
104 $.mobile.activePage.page('refresh');
109 * Displays media storages
111 displayStorages: function App_displayStorages() {
112 this.currentPath = '';
113 if (!this.ui.editMode) {
114 this.ui.scrollContentTo(0);
116 this.ui.displayStorages(this.model.getInternalStorages());
120 * Displays specified folder
121 * @param {string} path
122 * @param {bool} [refresh=false]
124 displayFolder: function App_displayFolder(path, refresh) {
127 refresh = refresh || false;
129 // get folder data and push into rendering method
130 this.model.getFolderData(path, function (dir, nodes) {
133 // update current path
134 self.currentPath = path;
136 // update current dir handle
137 self.currentDirHandle = dir;
140 if (refresh === undefined) {
141 self.ui.scrollContentTo(0);
143 self.ui.displayFolder(path, nodes, refresh);
148 * Opens specified file
149 * @params {string} uri File URI
151 openFile: function App_openFile(uri, fullUri) {
152 var ext = this.helpers.getFileExtension(uri),
153 mime = this.helpers.resolveMimeType(ext);
156 this.model.openFile(fullUri, mime);
158 console.error('Unsupported mime type for extension ' + ext);
163 * Displays parent location
165 goLevelUp: function App_goLevelUp() {
166 // split current path and get proper path for parent location
167 var newPath = this.currentPath.split('/').slice(0, -1).join('/');
169 if (newPath !== '') {
170 this.displayFolder(newPath);
172 this.displayStorages();
177 * creates new dir in currently viewed dir
178 * @param {string} dirName
179 * @return {boolean} return status
181 createDir: function App_createDir(dirName) {
183 if (this.currentDirPath !== '') {
185 this.currentDirHandle.createDirectory(dirName);
188 app.ui.alertPopup(e.message);
190 this.refreshCurrentPage();
193 app.ui.alertPopup("You can't create new nodes in the main view");
199 * Triggers refresh current page
201 refreshCurrentPage: function App_refreshCurrentPage() {
202 if (this.currentPath !== '') {
203 this.displayFolder(this.currentPath, true);
205 this.displayStorages();
210 * Deletes nodes with specified paths
211 * @param {string[]} nodes nodePaths
213 deleteNodes: function App_deleteNodes(nodes) {
214 this.model.deleteNodes(nodes, this.currentDirHandle, this.ui.removeNodeFromList.bind(this.ui));
218 * @param {string[]} paths filepaths
219 * @param {number} mode clipboard mode
221 saveToClipboard: function App_saveToClipboard(paths, mode) {
222 var clipboardLength = this.clipboard.add(paths);
224 if (clipboardLength > 0) {
225 this.clipboard.setMode(mode);
226 app.ui.alertPopup('Data saved in clipboard');
227 this.ui.clearTabbars();
229 app.ui.alertPopup('Error occured. Data has not been saved in clipboard');
232 this.ui.refreshPasteActionBtn(this.clipboard.isEmpty());
236 * Paste nodes from clipboard to current dir
238 pasteClipboard: function App_pasteClipboard() {
239 var clipboardData = this.clipboard.get();
241 if (clipboardData.length === 0) {
242 app.ui.alertPopup('Clipboard is empty');
246 if (this.clipboard.getMode() === this.clipboard.COPY_MODE_ID) {
247 this.model.copyNodes(this.currentDirHandle, clipboardData, this.currentPath, this.onPasteClipboardSuccess.bind(this));
249 this.model.moveNodes(this.currentDirHandle, clipboardData, this.currentPath, this.onPasteClipboardSuccess.bind(this));
252 this.ui.refreshPasteActionBtn(this.clipboard.isEmpty());
257 emptyClipboard: function App_emptyClipboard() {
258 return this.clipboard.get().length === 0;
262 * Handler for paste clipboard success
264 onPasteClipboardSuccess: function App_onPasteClipboardSuccess() {
265 this.clipboard.clear();
266 this.refreshCurrentPage();
272 exit: function App_exit() {
273 tizen.application.getCurrentApplication().exit();