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();
89 initUi: function App_initUi() {
90 this.ui.init(this.model.getInternalStorages());
94 * Displays media storages
96 displayStorages: function App_displayStorages() {
97 this.currentPath = '';
98 if (!this.ui.editMode) {
99 this.ui.scrollContentTo(0);
101 this.ui.displayStorages(this.model.getInternalStorages());
105 * Displays specified folder
106 * @param {string} path
107 * @param {bool} [refresh=false]
109 displayFolder: function App_displayFolder(path, refresh) {
112 refresh = refresh || false;
114 // get folder data and push into rendering method
115 this.model.getFolderData(path, function (dir, nodes) {
118 // update current path
119 self.currentPath = path;
121 // update current dir handle
122 self.currentDirHandle = dir;
125 if (refresh === undefined) {
126 self.ui.scrollContentTo(0);
128 self.ui.displayFolder(path, nodes, refresh);
133 * Opens specified file
134 * @params {string} uri File URI
136 openFile: function App_openFile(uri, fullUri) {
137 var ext = this.helpers.getFileExtension(uri),
138 mime = this.helpers.resolveMimeType(ext);
141 this.model.openFile(fullUri, mime);
143 console.error('Unsupported mime type for extension ' + ext);
148 * Displays parent location
150 goLevelUp: function App_goLevelUp() {
151 // split current path and get proper path for parent location
152 var newPath = this.currentPath.split('/').slice(0, -1).join('/');
154 if (newPath !== '') {
155 this.displayFolder(newPath);
157 this.displayStorages();
162 * creates new dir in currently viewed dir
163 * @param {string} dirName
164 * @return {boolean} return status
166 createDir: function App_createDir(dirName, callback) {
168 if (this.currentDirPath !== '') {
170 this.currentDirHandle.createDirectory(dirName);
173 app.ui.alertPopup(e.message, callback);
175 this.refreshCurrentPage();
178 app.ui.alertPopup("You can't create new nodes in the main view");
184 * Triggers refresh current page
186 refreshCurrentPage: function App_refreshCurrentPage(refresh) {
187 refresh = refresh || false;
188 if (this.currentPath === 'root') {
191 if (this.currentPath !== '') {
192 app.model.isStorageExists(this.currentPath,
193 app.displayFolder.bind(app, app.model.currentPath, refresh),
195 $.mobile.popup.active && $.mobile.popup.active.close();
196 app.displayStorages();
200 'Path "' + app.model.currentPath + '" does no longer exist'
207 this.displayStorages();
212 * Deletes nodes with specified paths
213 * @param {string[]} nodes nodePaths
215 deleteNodes: function App_deleteNodes(nodes) {
216 this.model.deleteNodes(nodes, this.currentDirHandle, this.ui.removeNodeFromList.bind(this.ui));
220 * @param {string[]} paths filepaths
221 * @param {number} mode clipboard mode
223 saveToClipboard: function App_saveToClipboard(paths, mode) {
224 var clipboardLength = this.clipboard.add(paths);
226 if (clipboardLength > 0) {
227 this.clipboard.setMode(mode);
228 app.ui.alertPopup('Data saved in clipboard');
229 this.ui.clearTabbars();
231 app.ui.alertPopup('Error occured. Data has not been saved in clipboard');
234 this.ui.refreshPasteActionBtn(this.clipboard.isEmpty());
238 * Paste nodes from clipboard to current dir
240 pasteClipboard: function App_pasteClipboard() {
241 var clipboardData = this.clipboard.get();
243 if (clipboardData.length === 0) {
244 app.ui.alertPopup('Clipboard is empty');
248 if (this.clipboard.getMode() === this.clipboard.COPY_MODE_ID) {
249 this.model.copyNodes(this.currentDirHandle, clipboardData, this.currentPath, this.onPasteClipboardSuccess.bind(this));
251 this.model.moveNodes(this.currentDirHandle, clipboardData, this.currentPath, this.onPasteClipboardSuccess.bind(this));
254 this.ui.refreshPasteActionBtn(this.clipboard.isEmpty());
259 emptyClipboard: function App_emptyClipboard() {
260 return this.clipboard.get().length === 0;
264 * Handler for paste clipboard success
266 onPasteClipboardSuccess: function App_onPasteClipboardSuccess() {
267 this.clipboard.clear();
268 this.refreshCurrentPage();
274 exit: function App_exit() {
275 tizen.application.getCurrentApplication().exit();