--- /dev/null
+Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
+Except as noted, this software is licensed under Flora License, Version 1.
+Please, see the LICENSE.Flora file for Flora License terms and conditions.
+
<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:tizen="http://tizen.org/ns/widgets" id="http://sample-web-application.tizen.org/file-manager" version="2.1.0" viewmodes="maximized">
- <tizen:application id="DncjwaRfgh" required_version="1.0"/>
+ <tizen:application id="km8AETYhee.FileManager" package="km8AETYhee" required_version="2.1"/>
<icon src="icon.png"/>
<name>FileManager</name>
- <tizen:privilege name="http://tizen.org/privilege/tizen"/>
<tizen:privilege name="http://tizen.org/privilege/content.read"/>
<tizen:privilege name="http://tizen.org/privilege/content.write"/>
<tizen:privilege name="http://tizen.org/privilege/systeminfo"/>
<tizen:privilege name="http://tizen.org/privilege/application.read"/>
<tizen:privilege name="http://tizen.org/privilege/filesystem.read"/>
<tizen:privilege name="http://tizen.org/privilege/filesystem.write"/>
- <tizen:setting screen-orientation="portrait" context-menu="disable" background-support="enable" encryption="disable" nodisplay="false"/>
+ <tizen:setting screen-orientation="portrait" context-menu="disable" background-support="enable" encryption="disable" install-location="auto"/>
</widget>
#mainTitle {
width: 260px;
+ text-transform: uppercase;
}
#fileList > li {
height: 100%;
}
+#homeBtn,
+#levelUpBtn {
+ top:20px;
+}
+
.ui-li-1line-bigicon1.ui-li.ui-li-static.ui-body-s.ui-li-has-thumb {
padding-left: 0.7rem;
padding-right: 0rem;
.ui-tabbar a {
color: #999 !important;
+}
+
+#newFolderName {
+ margin:0.4em;
+}
+
+.ui-header.ui-bar-s > .ui-btn {
+ width: 2rem;
+}
+/** workaround to prevent hiding footer caused by broken softkeyboardupdate event**/
+[data-role="footer"] {
+ display: block !important;
+}
+
+.ui-ctxpopup .horizontal a.ui-link {
+ display: block;
+}
+
+.ui-footer .ui-btn-text {
+ text-transform: uppercase;
}
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
+ <meta name="viewport" content="width=360,user-scalable=no">
<meta charset="utf-8"/>
<meta name="description" content="file manager"/>
- <title>file manager</title>
- <script src="/usr/share/tizen-web-ui-fw/latest/js/jquery.js"></script>
- <script src="/usr/share/tizen-web-ui-fw/latest/js/tizen-web-ui-fw-libs.js"></script>
- <script src="/usr/share/tizen-web-ui-fw/latest/js/tizen-web-ui-fw.js" data-framework-theme="tizen-white" data-framework-viewport-scale="false"></script>
+ <title>File Manager</title>
+ <script src="/usr/share/tizen-web-ui-fw/latest/js/jquery.min.js"></script>
+ <script src="/usr/share/tizen-web-ui-fw/latest/js/tizen-web-ui-fw-libs.min.js"></script>
+ <script src="/usr/share/tizen-web-ui-fw/latest/js/tizen-web-ui-fw.min.js" data-framework-theme="tizen-white" data-framework-viewport-scale="false"></script>
<script type="text/javascript" src="./js/main.js"></script>
<link rel="stylesheet" type="text/css" href="./css/style.css"/>
</head>
+
<body>
<div data-role="page" data-footer-Exist="false" id="main"></div>
</body>
-/*jslint browser: true, devel: true */
+/*jslint devel: true*/
/*global $*/
/**
/**
* Add new path to clipboard
- * @param {array} full path
+ * @param {array} paths array of full paths
* @returns {number} current length of clipboard objects
*/
add: function Clipboard_add(paths) {
this.clear();
for (i = 0; i < len; i += 1) {
if (this.has(paths[i]) === false) {
- console.log('Adding file ' + paths[i] + ' to clipboard');
this.data.push(paths[i]);
}
}
/**
* Checks if specified path is already in clipboard
- * @param {string} full path
+ * @param {string} path full path
* @returns {boolean}
*/
has: function Clipboard_has(path) {
- console.log('Clipboard_has', path);
return $.inArray(path, this.data) === -1 ? false : true;
},
/**
- * Clears all clipboard data and reset clipboard mode
+ * Clears all clipboard data and resets clipboard mode
*/
clear: function Clipboard_clear() {
- console.log('Clipboard_clear');
this.data = [];
this.mode = this.INACTIVE_MODE;
},
-/*jslint devel: true */
-
/**
* @class Config
*/
-/*jslint devel: true */
+/*jslint devel: true*/
/*global $ */
/**
/**
* @param {string} fileName
+ * @returns {string} file name without extension
+ */
+ getFileName: function Helpers_getFileName(fileName) {
+ var fileNameLen = fileName.indexOf('.');
+ if (fileNameLen !== -1) {
+ fileName = fileName.slice(0, fileNameLen);
+ }
+ return fileName;
+ },
+
+ /**
+ * @param {string} fileName
* @returns {string} extension for specified file name
*/
getFileExtension: function Helpers_getFileExtension(fileName) {
- console.log('Helpers_getFileExtension', fileName);
var splittedFileName = fileName.split('.'),
ext = '';
* @return {string}
*/
resolveFileIcon: function Helpers_resolveFileIcon(ext) {
- console.log('Helpers_resolveFileIcon', ext);
+
+ ext = ext.toLowerCase();
+
switch (ext) {
case '.jpg':
return 'img.png';
return 'pdf.png';
case '.mp3':
return 'music.png';
+ case '.avi':
+ return 'video.png';
case '.mp4':
return 'video.png';
case '.ppt':
* @returns {string}
*/
resolveMimeType: function Helpers_resolveMimeType(ext) {
- console.log('Helpers_resolveMimeType', ext);
var mime = '';
+ ext = ext.toLowerCase();
+
if (ext === '.jpg' || ext === '.png' || ext === '.gif') {
mime = 'image/*';
- } else if (ext === '.mp4' || ext === '.ogv') {
+ } else if (ext === '.mp4' || ext === '.ogv' || ext === '.avi') {
mime = 'video/*';
} else if (ext === '.mp3') {
- mime = 'audio/*';
+ mime = 'audio/mp3';
} else if (ext === '.txt' || ext === '.doc' || ext === '.html' || ext === '.ppt' || ext === '.xls' || ext === '.pdf') {
mime = 'text/*';
}
* @returns {string}
*/
getThumbnailURI: function Helpers_getThumbnailURI(fileName, node) {
- console.log('Helpers_getThumbnailURI', fileName, node);
var ext = this.getFileExtension(fileName),
thumbnailURI = '';
if (!node.thumbnailURIs) {
- console.log('getFileListItem: get icon');
thumbnailURI = 'images/' + this.resolveFileIcon(ext);
} else if (node.thumbnailURIs[0] && $.inArray(ext, ['.mp4', '.jpg', '.png', '.gif'])) {
thumbnailURI = node.thumbnailURIs[0];
}
return thumbnailURI;
+ },
+
+ /**
+ * File name automatic number increase for copy files
+ */
+ getCopyFileName: function (sourceName, filesList) {
+ var ext = this.getFileExtension(sourceName),
+ fileName = this.getFileName(sourceName),
+ copyFileName = sourceName, i = 1;
+ while ($.inArray(copyFileName, filesList) !== -1) {
+ i+=1;
+ copyFileName = fileName+'('+i+')'+ext;
+ }
+ return copyFileName;
}
};
-}());
\ No newline at end of file
+}());
+
+(function($) {
+ 'use strict';
+
+ function height(t, el) {
+ return t.height() > el.height();
+ }
+ function width(t, el) {
+ return t.width() > el.width();
+ }
+
+ $.fn.ellipsis = function ()
+ {
+ return this.each(function () {
+ var el, text, multiline, t, func;
+ el = $(this);
+ if(el.css("overflow") === "hidden") {
+ text = el.html();
+ multiline = el.hasClass('multiline');
+ t = $(this.cloneNode(true))
+ .hide()
+ .css('position', 'absolute')
+ .css('overflow', 'visible')
+ .width(multiline ? el.width() : 'auto')
+ .height(multiline ? 'auto' : el.height())
+ ;
+
+ el.after(t);
+
+ func = multiline ? height : width;
+
+ while (text.length > 0 && func(t, el)) {
+ text = text.substr(0, text.length - 1);
+ t.html(text + "...");
+ }
+
+ el.html(t.html());
+ t.remove();
+ }
+ });
+ };
+}(jQuery));
-/*jslint devel: true */
+/*jslint devel: true*/
/*global tizen, $, app, Ui, Model, Helpers, Config, Clipboard*/
var App = null;
* Initialization
*/
init: function App_init() {
- console.log('App_init');
this.config = new Config();
this.model = new Model();
this.ui = new Ui();
this.helpers = new Helpers();
this.clipboard = new Clipboard();
- this.model.loadInternalStorages(this.initUi.bind(this));
+ this.initUi();
this.addEvents();
},
* UI initialization
*/
initUi: function App_initUi() {
- console.log('App_initUi');
this.ui.init(this.model.getInternalStorages());
},
* Add pages events
*/
addEvents: function App_addEvents() {
- console.log('App_addEvents');
var self = this;
- document.addEventListener('webkitvisibilitychange', function() { self.refreshCurrentPage(); } );
+ document.addEventListener('webkitvisibilitychange', function () { self.refreshCurrentPage(); });
+ // workaround: page refresh for on/off keyboard
+ window.addEventListener('softkeyboardchange',function () {
+ $.mobile.activePage.page('refresh');
+ });
},
/**
* Displays media storages
*/
displayStorages: function App_displayStorages() {
+ this.currentPath = '';
+ 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) {
- console.log('App_displayFolder', path);
+ 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
- console.log('App_displayFolder success', dir, nodes);
// update current path
self.currentPath = path;
self.currentDirHandle = dir;
// display folder UI
- self.ui.displayFolder(path, nodes);
+ if (refresh === undefined) {
+ self.ui.scrollContentTo(0);
+ }
+ self.ui.displayFolder(path, nodes, refresh);
});
},
* @params {string} uri File URI
*/
openFile: function App_openFile(uri, fullUri) {
- console.log('App_openFile', uri);
var ext = this.helpers.getFileExtension(uri),
mime = this.helpers.resolveMimeType(ext);
if (mime !== '') {
this.model.openFile(fullUri, mime);
} else {
- console.error('Unsupported mime type', mime);
+ console.error('Unsupported mime type for extension ' + ext);
}
},
* @param {string} dirName
*/
createDir: function App_createDir(dirName) {
- console.log('App_createDir', dirName);
if (this.currentDirPath !== '') {
try {
this.currentDirHandle.createDirectory(dirName);
} catch (e) {
- console.error('App_createDir error', e);
+ alert(e.message);
}
this.refreshCurrentPage();
} else {
- alert("you can't create new nodes in main view");
+ alert("You can't create new nodes in the main view");
}
},
* Triggers refresh current page
*/
refreshCurrentPage: function App_refreshCurrentPage() {
- console.log('App_refreshCurrentPage');
if (this.currentPath !== '') {
- this.displayFolder(this.currentPath);
+ this.displayFolder(this.currentPath, true);
} else {
this.displayStorages();
}
/**
* Deletes nodes with specified paths
- * @param {string[]} nodePaths
+ * @param {string[]} nodes nodePaths
*/
deleteNodes: function App_deleteNodes(nodes) {
- console.log('App_deleteNodes', nodes);
this.model.deleteNodes(nodes, this.currentDirHandle, this.ui.removeNodeFromList.bind(this.ui));
},
/**
- * @param {string[]} filepaths
- * @param {number} clipboard mode
+ * @param {string[]} paths filepaths
+ * @param {number} mode clipboard mode
*/
saveToClipboard: function App_saveToClipboard(paths, mode) {
- this.clipboard.add(paths);
- this.clipboard.setMode(mode);
+ var clipboardLength = this.clipboard.add(paths);
+
+ if (clipboardLength > 0) {
+ this.clipboard.setMode(mode);
+ alert('Data saved in clipboard');
+ } else {
+ alert('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() {
- console.log('App_pasteClipboard');
var clipboardData = this.clipboard.get();
if (clipboardData.length === 0) {
}
this.ui.refreshPasteActionBtn(this.clipboard.isEmpty());
+
+ return true;
},
/**
* Handler for paste clipboard success
*/
onPasteClipboardSuccess: function App_onPasteClipboardSuccess() {
- console.log('App_onPasteClipboardSuccess');
this.clipboard.clear();
this.refreshCurrentPage();
},
-/*jslint devel: true */
-/*global tizen, SystemIO */
+/*jslint devel: true*/
+/*global tizen, SystemIO, $ */
/**
* @class Model
Model.prototype = {
/**
- * @type SystemIO
+ * file open unlock flag
+ * @type {boolean}
*/
- systemIO: null,
+ openFileUnLocked: true,
/**
- * @type Array
+ * @type SystemIO
*/
- storages: [],
+ systemIO: null,
/**
- * @type MediaSource
+ * @type Array
*/
- mediaSource: null,
+ storages: [{label: 'root', type: 'INTERNAL'}],
/**
* API module initialisation
*/
init: function Model_init() {
- console.log('Model_init');
this.systemIO = new SystemIO();
- //this.mediaSource = tizen.mediacontent.getLocalMediaSource();
},
/**
* @returns {FileSystemStorage[]} storages
*/
getInternalStorages: function Model_getInternalStorages() {
- console.log('Model_getInternalStorages');
return this.storages;
},
/**
* Saves storages
- * @param {function} callback
+ * @param {function} onSuccess callback
*/
loadInternalStorages: function Model_loadInternalStorages(onSuccess) {
- console.log('Model_loadInternalStorages', onSuccess);
var self = this;
this.systemIO.getStorages('INTERNAL', function (storages) {
self.storages = storages;
if (typeof onSuccess === 'function') {
- console.log('Storages loaded successfully');
onSuccess();
}
- });
+ }, 'internal0');
},
/**
* Returns folder data
- * @param {string} node Node path
+ * @param {string} path Node path
* @param {function} onSuccess Success callback
+ * @param {function} onError Error callback
*/
getFolderData: function Model_getFolderData(path, onSuccess, onError) {
- console.log('Model_getFolderData', path);
var onOpenSuccess = function (dir) {
dir.listFiles(
function (files) {
- console.log('Model_getFolderData listFiles success', files);
onSuccess(dir, files);
},
function (e) {
},
/**
- * Launch a service associated with 'ext' to launch the 'uri'
- * @param {string} ext
- * @param {string} uri
- * @returns {ApplicationSevice}
+ * Launch a service to open the file
+ * @param {string} fullUri ext
+ * @param {string} mime uri
*/
openFile: function Model_openFile(fullUri, mime) {
- var serviceReplyCB = {
- onsuccess: function (reply) {
- var num = 0;
- for (num = 0; num < reply.data.length; num += 1) {
- console.log('reply.data[' + num + '].key = ' + reply.data[num].key);
- console.log('reply.data[' + num + '].value = ' + reply.data[num].value);
+ if (this.openFileUnLocked) {
+ var self = this, serviceReplyCB = {
+ onsuccess: function (reply) {
+ self.openFileUnLocked = true;
+ },
+ onfailure: function () {
+ self.openFileUnLocked = true;
+ console.error('Launch service failed');
}
- },
- onfailure: function () {
- console.log('Launch service failed');
+ };
+ this.openFileUnLocked = false;
+ try {
+ tizen.application.launchAppControl(new tizen.ApplicationControl(
+ 'http://tizen.org/appcontrol/operation/view',
+ fullUri,
+ mime
+ ),
+ null,
+ function () {
+ setTimeout(function () {
+ self.openFileUnLocked = true;
+ }, 500);
+ },
+ function (e) {
+ self.openFileUnLocked = true;
+ alert('launch sevice failed. reason :' + e.message);
+ },
+ serviceReplyCB
+ );
+ } catch (e) {
+ self.openFileUnLocked = true;
+ console.error('openFile error:', e);
}
- };
-
- try {
- tizen.application.launchAppControl(new tizen.ApplicationControl(
- 'http://tizen.org/appcontrol/operation/view',
- fullUri,
- mime
- ),
- null,
- function () { },
- function (e) {
- alert('launch sevice failed. reason :' + e.message);
- },
- serviceReplyCB
- );
- } catch (e) {
- console.error('openFile error:', e);
}
},
* @param {function} onError
*/
deleteNodes: function Model_deleteNodes(nodes, dir, onSuccess, onError) {
- console.log('Model_deleteNodes', nodes, dir);
var len = nodes.length,
onDeleteNodeSuccess = function (nodeId, isDir) {
- console.log((isDir ? 'Folder' : 'File') + nodeId + ' deleted successfully');
if (typeof onSuccess === 'function') {
onSuccess(nodeId);
}
},
onDeleteNodeError = function (e) {
- console.log('Folder delete error', e);
+ console.error('Folder delete error', e);
if (typeof onError === 'function') {
onError();
}
* @param {function} onSuccess callback
*/
copyNodes: function Model_copyNodes(dir, paths, destinationPath, onSuccess) {
- console.log('Model_copyNodes', dir, paths, destinationPath);
var len = paths.length,
copied = 0,
onCopyNodeSuccess = function () {
onSuccess();
}
},
- i;
+ onCopyNodeFailure = function () {
+ alert('Copying error');
+ },
+ i,
+ sourceName,
+ decision;
- for (i = 0; i < len; i = i + 1) {
- dir.copyTo(paths[i], destinationPath, true, onCopyNodeSuccess);
- }
+ this.systemIO.getFilesList(dir, function (filesList) {
+ for (i = 0; i < len; i = i + 1) {
+ if (destinationPath.indexOf(paths[i]) !== -1) {
+ alert('Copying error');
+ return;
+ }
+ }
+
+ for (i = 0; i < len; i = i + 1) {
+ decision = true;
+ sourceName = paths[i].split('/').pop();
+ sourceName = app.helpers.getCopyFileName(sourceName, filesList);
+
+ try {
+ dir.copyTo(paths[i], destinationPath + '/' + sourceName, true, onCopyNodeSuccess, onCopyNodeFailure);
+ } catch (e) {
+ console.error(e);
+ }
+ }
+ });
},
/**
* @param {function} onSuccess callback
*/
moveNodes: function Model_moveNodes(dir, paths, destinationPath, onSuccess) {
- console.log('Model_moveNodes', dir, paths, destinationPath);
var len = paths.length,
moved = 0,
onMoveNodeSuccess = function () {
onSuccess();
}
},
- i;
+ onMoveNodeFailure = function () {
+ alert('Moving error');
+ },
+ i,
+ sourceName,
+ decision;
- for (i = 0; i < len; i = i + 1) {
- dir.moveTo(paths[i], destinationPath, true, onMoveNodeSuccess);
- }
+ this.systemIO.getFilesList(dir, function (filesList) {
+ for (i = 0; i < len; i = i + 1) {
+ if (destinationPath.indexOf(paths[i]) !== -1) {
+ alert('Moving error');
+ return;
+ }
+ }
+
+ for (i = 0; i < len; i = i + 1) {
+ decision = true;
+ sourceName = paths[i].split('/').pop();
+
+ if ($.inArray(sourceName, filesList) !== -1) {
+ decision = confirm('A file with (' + sourceName + ') name already exists.\nDo you want to overwrite it?');
+ }
+
+ if (decision) {
+ dir.moveTo(paths[i], destinationPath + '/' + sourceName, true, onMoveNodeSuccess, onMoveNodeFailure);
+ }
+ }
+ });
}
};
}());
-/*jslint devel: true */
+/*jslint devel: true*/
/*global tizen, localStorage */
/**
* @param {string} fileName
*/
createFile: function SystemIO_createFile(directoryHandle, fileName) {
- console.log('SystemIO_createFile', directoryHandle, fileName);
try {
return directoryHandle.createFile(fileName);
} catch (e) {
- console.error('SystemIO_createFile error:', e);
+ console.error('SystemIO_createFile error:' + e.message);
return false;
}
},
/**
* Writes content to file stream
*
- * @param {File} file handler
- * @param {string} file content
- * @param {function} on success callback
+ * @param {File} fileHandle file handler
+ * @param {string} fileContent file content
+ * @param {function} onSuccess on success callback
+ * @param {function} onError on error callback
* @param {string} content encoding
*/
writeFile: function SystemIO_writeFile(fileHandle, fileContent, onSuccess, onError, contentEncoding) {
- console.log('SystemIO_writeFile', fileHandle, fileContent.length, contentEncoding);
onError = onError || function () {};
fileHandle.openStream('w', function (fileStream) {
- console.log('SystemIO_writeFile:_onOpenStreamSuccess', fileStream);
if (contentEncoding === 'base64') {
fileStream.writeBase64(fileContent);
} else {
* @param {string} mode
*/
openDir: function SystemIO_openDir(directoryPath, onSuccess, onError, openMode) {
- console.log('SystemIO_openDir', directoryPath, openMode);
openMode = openMode || 'rw';
onSuccess = onSuccess || function () {};
try {
tizen.filesystem.resolve(directoryPath, onSuccess, onError, openMode);
} catch (e) {
- console.log('SystemIO_openDir error:' + e.message);
}
},
* @returns {array}
*/
getPathData: function SystemIO_getPathData(filePath) {
- console.log('SystemIO_getPathData', filePath);
var path = {
originalPath: filePath,
fileName: '',
* @param {string} file encoding
*/
saveFileContent: function SystemIO_saveFileContent(filePath, fileContent, onSaveSuccess, fileEncoding) {
- console.log('SystemIO_saveFileContent', filePath, fileContent.length, fileEncoding);
var pathData = this.getPathData(filePath),
self = this,
fileHandle;
function onOpenDirSuccess(dir) {
- console.log('SystemIO_saveFileContent:_onOpenDirSuccess', dir);
// create new file
fileHandle = self.createFile(dir, pathData.fileName);
if (fileHandle !== false) {
* @param {function} success callback
*/
deleteNode: function SystemIO_deleteNode(nodePath, onSuccess) {
- console.log('SystemIO_deleteNode', nodePath);
var pathData = this.getPathData(nodePath),
self = this;
function onDeleteSuccess() {
- console.log('SystemIO_deleteNode:_onDeleteSuccess');
onSuccess();
}
function onDeleteError(e) {
- console.log('SystemIO_deleteNode:_onDeleteError', e);
+ console.error('SystemIO_deleteNode:_onDeleteError', e);
}
function onOpenDirSuccess(dir) {
- console.log('SystemIO_deleteNode:_onOpenDirSuccess', dir);
var onListFiles = function (files) {
- console.log('SystemIO_deleteNode:_onListFiles', files);
if (files.length > 0) {
// file exists;
if (files[0].isDirectory) {
* @param {function} delete error callback
*/
deleteFile: function SystemIO_deleteFile(dir, filePath, onDeleteSuccess, onDeleteError) {
- console.log('SystemIO_deleteFile', filePath);
try {
dir.deleteFile(filePath, onDeleteSuccess, onDeleteError);
} catch (e) {
- console.error('SystemIO_deleteFile error:' + e.message);
+ console.error('SystemIO_deleteFile error: ' + e.message);
return false;
}
},
* Deletes specified directory
*
* @param {File} dir
- * @param {string} dir path
- * @param {function} delete success callback
- * @param {function} delete error callback
+ * @param {string} dirPath dir path
+ * @param {function} onDeleteSuccess delete success callback
+ * @param {function} onDeleteError delete error callback
* @returns {boolean}
*/
deleteDir: function SystemIO_deleteDir(dir, dirPath, onDeleteSuccess, onDeleteError) {
- console.log('SystemIO_deleteDir', dir, dirPath);
try {
dir.deleteDirectory(dirPath, false, onDeleteSuccess, onDeleteError);
} catch (e) {
},
/**
- * @param {string} storage type
+ * @param {string} type storage type
+ * @param {function} onSuccess on success callback
+ * @param {string} excluded Excluded storage
*/
- getStorages: function SystemIO_getStorages(type, onSuccess) {
- console.log('SystemIO_getStorages', type);
+ getStorages: function SystemIO_getStorages(type, onSuccess, excluded) {
try {
tizen.filesystem.listStorages(function (storages) {
- console.log('...listStorages success', storages);
var tmp = [],
len = storages.length,
i;
if (type !== undefined) {
for (i = 0; i < len; i += 1) {
- if (storages[i].type === 0 || storages[i].type === type) {
- tmp.push(storages[i]);
+ if (storages[i].label !== excluded) {
+ if (storages[i].type === 0 || storages[i].type === type) {
+ tmp.push(storages[i]);
+ }
}
}
} else {
}
});
} catch (e) {
- console.error('SystemIO_getStorages error:', e);
+ console.error('SystemIO_getStorages error:' + e.message);
+ }
+ },
+
+ getFilesList: function SystemIO_getFilesList(dir, onSuccess) {
+ try {
+ dir.listFiles(
+ function (files) {
+ var tmp = [],
+ len = files.length,
+ i;
+
+ for (i = 0; i < len; i += 1) {
+ tmp.push(files[i].name);
+ }
+
+ if (typeof onSuccess === 'function') {
+ onSuccess(tmp);
+ }
+ },
+ function (e) {
+ console.error('SystemIO_getFilesList dir.listFiles() error:', e);
+ }
+ );
+ } catch (e) {
+ console.error('SystemIO_getFilesList error:', e.message);
}
}
};
'use strict';
Ui.prototype = {
/**
+ * root mode
+ * @type {boolean}
+ */
+ root: true,
+
+ /**
* UI edit mode
* @type {boolean}
*/
EDIT_TABBAR_COPY_ACTION: 2,
EDIT_TABBAR_CANCEL_ACTION: 3,
+ currentHeaderHeight: null,
+ currentScrollPosition: null,
+
/**
* UI Initialization
*/
init: function Ui_init(storages) {
- console.log('Ui_init', storages);
this.templateManager = new TemplateManager();
this.helpers = new Helpers();
// Disable text selection
},
initDom: function Ui_initDom(storages) {
- console.log('Ui_initDom', storages);
var self = this;
this.templateManager.loadToCache(['main', 'fileRow', 'folderRow', 'levelUpRow', 'emptyFolder'], function () {
* Add UI events
*/
addEvents: function Ui_addEvents() {
- console.log('Ui_addEvents');
var self = this;
// touch events for all nodes
$('ul#fileList')
});
// level up
- $('#levelUpBtn').on('tap', app.goLevelUp.bind(app));
+ $('#levelUpBtn').on('tap', function () {
+ if (self.editMode === true) {
+ self.handleCancelEditAction();
+ }
+ app.goLevelUp();
+ });
$('#homeBtn').on('tap', app.displayStorages.bind(app));
}
});
- $('#cancelNewFolder').on('tap', function () {
- $('#addFolderPopup').popup('close');
- $('#morePopup').popupwindow('close');
- });
-
- $('#saveNewFolder').on('tap', function () {
+ $('#saveNewFolder').on('click', function () {
var folderName = $('#newFolderName').val().trim();
- $('#addFolderPopup').popup('close');
- $('#morePopup').popupwindow('close');
-
- if (folderName !== '') {
- app.createDir(folderName);
+ if (folderName === '') {
+ alert("Empty folder name");
+ } else if (folderName.match(/[\*\.\/\\\?\"\'\:<>|]/)) {
+ alert("The following special characters are not allowed: *./\\?:<>|'\"");
} else {
- alert("Wrong name of folder");
+ app.createDir(folderName);
}
});
}, 700);
});
+ /* workaround for UIFW & webkit scroll*/
+ //$('.ui-page').css('min-height', 0);
},
/**
* @param {boolean} toggleCheckbox
*/
handleNodeClick: function Ui_handleNodeClick(node, toggleCheckbox) {
- console.log('Ui_handleNodeClick', node);
- if (this.editMode === true) {
+ if (this.root) {
+ app.model.loadInternalStorages(function(){app.displayStorages()});
+ this.root = false;
+ } else if (this.editMode === true) {
//if edit mode is on toggle checkbox state
if (toggleCheckbox === true) {
this.toggleCheckBoxState(node); // select the checkbox
}
this.refreshSelectAllStatus();
-
- if ($('ul#fileList input:checkbox:checked').length > 0) {
- this.enableControlBarButtons($('.editTabbar'), [this.EDIT_TABBAR_DELETE_ACTION, this.EDIT_TABBAR_COPY_ACTION, this.EDIT_TABBAR_MOVE_ACTION]);
- } else {
- this.disableControlBarButtons($('.editTabbar'), [this.EDIT_TABBAR_DELETE_ACTION, this.EDIT_TABBAR_COPY_ACTION, this.EDIT_TABBAR_MOVE_ACTION]);
- }
+ this.refreshEditMenu();
} else if (node.hasClass('folder')) {
// otherwise display folder
app.displayFolder(node.attr('uri'));
* Handler for edit action
*/
handleEditAction: function Ui_handleEditAction() {
- console.log('Ui_handleEditAction');
this.editMode = true;
$('.standardTabbar').hide();
$('div.editTabbar').show();
* Handler for cancel edit action
*/
handleCancelEditAction: function Ui_handleCancelEditAction() {
- console.log('Ui_handleCancelEditAction');
+ this.editMode = false;
$('div.editTabbar').hide();
$('.standardTabbar').show();
this.hideEditCheckBoxes();
* Handler for delete action
*/
handleDeleteAction: function Ui_handleDeleteAction() {
- console.log('Ui_handleDeleteAction');
var nodesToDelete = [],
$rowElement;
if (nodesToDelete.length > 0 && confirm('Selected nodes will be deleted. Are you sure?')) {
app.deleteNodes(nodesToDelete);
+ this.scrollContentTo(0);
+ $('ul#fileList input:checkbox:checked').remove();
+ this.refreshEditMenu();
}
},
* Handler for copy action
*/
handleCopyAction: function Ui_handleCopyAction() {
- console.log('Ui_handleCopyAction');
var paths = [];
if (this.editMode === true) {
$('ul#fileList input:checkbox:checked').each(function (index) {
* Handler for move action
*/
handleMoveAction: function Ui_handleMoveAction() {
- console.log('Ui_handleMoveAction');
var paths = [];
if (this.editMode === true) {
$('ul#fileList input:checkbox:checked').each(function (index) {
* Handler for paste action
*/
handlePasteAction: function Ui_handlePasteAction() {
- console.log('Ui_handlePasteAction');
+ },
+
+ /**
+ * Scrolls content to the specified position
+ */
+ scrollContentTo: function scrollContentTo(value) {
+ $('#main [data-role="content"]').scrollview('scrollTo', 0, value);
},
/**
* @param {FileSystemStorage[]} nodes Storage elements
*/
displayStorages: function Ui_displayStorages(nodes) {
- console.log('Ui_displayStorages', nodes, nodes.length);
var len = nodes.length,
listElements = [],
nodeName,
listTemplate = '',
i;
-
this.updateNavbar('');
for (i = 0; i < len; i = i + 1) {
listTemplate = listElements.join('');
$(listTemplate).appendTo('#fileList');
// reset scrollview position
- $('#main .ui-scrollview-view').css('-webkit-transform','none');
- $('#fileList')
- .trigger("refresh");
+ //$('#main .ui-scrollview-view').css('-webkit-transform', 'none');
+ $('#fileList').listview("refresh");
this.resetDefaultCheckBoxLabelEvents();
this.hideSelectAllArea();
},
/**
+ * File comparison function using their names (case insensitive)
+ *
+ * @param {File} x
+ * @param {File} y
+ * @returns {Number}
+ */
+ fileComparison: function fileComparison(x, y) {
+ var a = x.name.toLowerCase(),
+ b = y.name.toLowerCase();
+
+ if (a < b) {
+ return -1;
+ }
+ if (a > b) {
+ return 1;
+ }
+ return 0;
+ },
+
+ /**
* renders node list for folder
+ * @param {string} folderName
* @param {File[]} nodes
+ * @param {bool} [refresh=false]
*/
- displayFolder: function Ui_displayFolder(folderName, nodes) {
- console.log('Ui_displayFolder', nodes, nodes.length);
+ displayFolder: function Ui_displayFolder(folderName, nodes, refresh) {
var len = nodes.length,
listElements = [this.templateManager.get('levelUpRow')],
nodeName,
+ checkedRows = [],
i;
+ refresh = refresh || false;
+
// update title
this.updateTitle(folderName);
// update navbar
this.updateNavbar(folderName);
+ nodes.sort(this.fileComparison);
+
// render nodes
for (i = 0; i < len; i = i + 1) {
nodeName = nodes[i].name.trim();
- console.log('node:', nodeName);
if (nodeName !== '') {
if (nodes[i].isDirectory) {
// folder
listElements.push(this.templateManager.get('emptyFolder'));
}
+ // scroll to top of list
+ this.scrollContentTo(0);
+
$('#levelUpBtn').removeClass('vhidden');
$('#homeBtn').removeClass('vhidden');
$('#editActionBtn').removeClass('vhidden');
$('#moreActionBtn').removeClass('vhidden');
- this.hideSelectAllArea();
+
+ if (refresh === true && this.editMode === true) {
+ $.each($('#fileList .ui-checkbox input:checked'), function () {
+ checkedRows.push($(this).closest('li').attr('id'));
+ });
+ }
// update file list
$('#fileList').html(listElements.join(''))
.trigger('refresh')
.trigger('create');
+ // fixing ellisis for Bengali language
+ $(".ui-li-text-main.nodename").ellipsis();
+ $("#mainTitle").ellipsis();
+ $("#navbar").ellipsis();
+
+ if (this.editMode === true) {
+ $('.selectAll').show();
+ $('ul#fileList > li').css('paddingLeft', '2rem');
+ $('.my-ui-checkbox').removeClass('hidden');
+
+ if (refresh === true) {
+ // restore checked checkboxes
+ for (i = 0; i < checkedRows.length; i += 1) {
+ $('#' + checkedRows[i] + ' input:checkbox')
+ .attr('checked', 'checked')
+ .data('checkboxradio').refresh();
+ }
+ }
+ } else {
+ $('.selectAll').hide();
+ $('ul#fileList > li').css('paddingLeft', '0');
+ $('.my-ui-checkbox').addClass('hidden');
+ }
},
/**
* @param {jQuery} listElement
*/
toggleCheckBoxState: function Ui_toggleCheckBoxState(listElement) {
- console.log('Ui_toggleCheckBoxState', listElement);
- var checkboxInput = null,
- checkboxesInputChecked = null,
- editTabbar = null;
+
+ var checkboxInput = null;
checkboxInput = listElement.find('form > div.ui-checkbox input');
checkboxInput
* Shows item checkboxes and topbar with select all option
*/
showEditCheckBoxes: function Ui_showEditCheckBoxes() {
- console.log('Ui_showEditCheckBoxes');
var self = this;
this.showSelectAllArea();
* All checkboxes are auto uncheked
*/
hideEditCheckBoxes: function Ui_hideEditCheckBoxes() {
- console.log('Ui_hideEditCheckBoxes');
var self = this;
this.hideSelectAllArea(); // hide select all option topbar
$('ul#fileList > li').animate({paddingLeft: '0'}, 200, 'swing', function () {
- self.editMode = false;
$('.my-ui-checkbox').addClass('hidden');
$.mobile.activePage.page('refresh');
});
// uncheck all checkboxes
$('ul#fileList input[type=checkbox]').each(function (index) {
+ var checkboxradio = $(this).data('checkboxradio');
+
$(this).attr('checked', false);
- //$(this).data('checkboxradio').refresh(); // element undefined
+
+ if (checkboxradio) {
+ checkboxradio.refresh();
+ }
});
//uncheck select all input
},
/**
+ * Save current header and content height
+ */
+ saveHeights: function Ui_saveHeights() {
+ this.currentHeaderHeight = $('#main div[data-role="header"]').height();
+ this.currentScrollPosition = $('#main div[data-role="content"]').scrollview('getScrollPosition').y;
+ },
+
+ /**
+ * Changes content scroll position after showing/hiding selectAllArea
+ */
+ changeContentScrollPosition: function Ui_changeContentScrollPosition() {
+ var diff;
+ if (this.currentScrollPosition !== 0) {
+ diff = $('#main div[data-role="header"]').height() - this.currentHeaderHeight;
+ $('#main div[data-role="content"]').scrollview('scrollTo', 0, -(this.currentScrollPosition + diff));
+ }
+ },
+
+ /**
* Shows topbar with select all option
*/
showSelectAllArea: function Ui_showSelectAllArea() {
- console.log('showSelectAllArea');
+ this.saveHeights();
$('.selectAll').show();
$.mobile.activePage.page('refresh');
+ this.changeContentScrollPosition();
},
/**
* Hides topbar with select all option
*/
hideSelectAllArea: function Ui_hideSelectAllArea() {
- console.log('hideSelectAllArea');
+ this.saveHeights();
$('.selectAll').hide();
$.mobile.activePage.page('refresh');
+ this.changeContentScrollPosition();
},
/**
* Enable specified options for tabbar
* @param {object} tabbar
- * @param {array} options to enable
+ * @param {array} enableOptions options to enable
*/
enableControlBarButtons: function Ui_enableControlBarButtons(tabbar, enableOptions) {
- console.log('Ui_enableControlBarButtons', tabbar, enableOptions);
var i = 0,
len = enableOptions.length;
/**
* Disable specified options for tabbar
- * @param {object} controlbar
- * @param {array} options to enable
+ * @param {object} tabbar controlbar
+ * @param {array} disableOptions options to enable
*/
disableControlBarButtons: function Ui_disableControlBarButtons(tabbar, disableOptions) {
- console.log('Ui_disableControlBarButtons', tabbar, disableOptions);
var i = 0,
len = disableOptions.length;
* @param {string} path
*/
updateTitle: function Ui_updateTitle(path) {
- console.log('Ui_updateTitle', path);
var regexp = new RegExp('([^\/])+$', 'g'),
match = path.match(regexp),
lastDir = match[0] || '(dir)';
* @param {string} path
*/
updateNavbar: function Ui_updateNavbar(path) {
- console.log('Ui_updateNavbar', path);
var html = ['<span uri="home">Media</span>'],
splitted,
len,
},
handleSelectAllChange: function Ui_handleSelectAllChange() {
- console.log('Ui_handleSelectAllChange');
var $selectAllInput = $('.ui-header .selectAll .ui-checkbox input');
$selectAllInput.data('checkboxradio').refresh();
if ($selectAllInput.is(':checked')) {
- this.enableControlBarButtons($('.editTabbar'), [this.EDIT_TABBAR_DELETE_ACTION, this.EDIT_TABBAR_COPY_ACTION, this.EDIT_TABBAR_MOVE_ACTION]);
-
// check all checkboxes
$('ul#fileList input[type=checkbox]').each(function (index) {
$(this).attr('checked', true);
$(this).data('checkboxradio').refresh();
});
- } else {
- this.disableControlBarButtons($('.editTabbar'), [this.EDIT_TABBAR_DELETE_ACTION, this.EDIT_TABBAR_COPY_ACTION, this.EDIT_TABBAR_MOVE_ACTION]);
+ this.enableControlBarButtons($('.editTabbar'), [this.EDIT_TABBAR_DELETE_ACTION, this.EDIT_TABBAR_COPY_ACTION, this.EDIT_TABBAR_MOVE_ACTION]);
+ } else {
$('ul#fileList input[type=checkbox]').each(function (index) {
$(this).attr('checked', false);
$(this).data('checkboxradio').refresh();
});
+
+ this.disableControlBarButtons($('.editTabbar'), [this.EDIT_TABBAR_DELETE_ACTION, this.EDIT_TABBAR_COPY_ACTION, this.EDIT_TABBAR_MOVE_ACTION]);
}
},
*
*/
refreshSelectAllStatus: function Ui_refreshSelectAllStatus() {
- console.log('Ui_refreshSelectAllStatus');
var $selectAllInput = $('.ui-header .selectAll .ui-checkbox input');
// update status of select all checkbox
if ($('ul#fileList input:checkbox:not(:checked)').length === 0) {
},
/**
+ * Refresh activity of edit menu
+ */
+ refreshEditMenu: function () {
+ if ($('ul#fileList input:checkbox:checked').length > 0) {
+ this.enableControlBarButtons($('.editTabbar'),
+ [this.EDIT_TABBAR_DELETE_ACTION, this.EDIT_TABBAR_COPY_ACTION, this.EDIT_TABBAR_MOVE_ACTION]);
+ } else {
+ this.disableControlBarButtons($('.editTabbar'),
+ [this.EDIT_TABBAR_DELETE_ACTION, this.EDIT_TABBAR_COPY_ACTION, this.EDIT_TABBAR_MOVE_ACTION]);
+ }
+ },
+
+ /**
* Unbinds default events for checkbox labels
*/
resetDefaultCheckBoxLabelEvents: function Ui_resetDefaultCheckBoxLabelEvents() {
- console.log('Ui_resetDefaultCheckBoxLabelEvents');
$('div.ui-checkbox > label')
.unbind('vmousedown')
.unbind('vmouseup')
/**
* Remove html node element from list
- * @param {string} node id
+ * @param {string} nodeId node id
*/
removeNodeFromList: function Ui_removeNodeFromList(nodeId) {
- console.log('Ui_removeNodeFromList', nodeId);
$('ul#fileList > li#' + nodeId).remove();
+
+ // hide select All checkbox if removed all elements;
+ if ($('ul#fileList > li.node').length === 0) {
+ this.hideSelectAllArea();
+ }
},
/**
* Enable/Disable
*/
refreshPasteActionBtn: function Ui_refreshPasteActionBtn(clipboardEmpty) {
- console.log('Ui_refreshPasteActionBtn', clipboardEmpty);
if (clipboardEmpty === true) {
$('#pasteActionBtnRow').addClass('hidden');
} else {
-/*jslint devel: true*/
-/*global $, app */
+/*global tizen, $, app */
/**
* @class TemplateManager
*/
* UI module initialisation
*/
init: function init() {
-
},
/**
* Returns template html (from cache)
+ * @param {string} tplName
+ * @param {string} tplParams
*/
get: function TemplateManager_get(tplName, tplParams) {
- console.log('TemplateManager_get:' + tplName);
-
if (this.cache[tplName] !== undefined) {
return this.getCompleted(this.cache[tplName], tplParams);
}
/**
* Load templates to cache
+ * @param {string} tplNames
+ * @param {function} onSuccess
*/
loadToCache: function TemplateManager_loadToCache(tplNames, onSuccess) {
var self = this,
// save to cache
self.cache[fileName] = data;
- console.log('Cached template: ' + fileName);
// if all templates are cached launch callback
if (cachedTemplates >= tplNames.length && typeof onSuccess === 'function') {
}
},
error: function (jqXHR, textStatus, errorThrown) {
- alert(errorThrown);
+ console.error('templateManagerError: ' + errorThrown);
}
});
} else {
/**
* Returns template completed by specified params
+ * @param {string} tplHtml
+ * @param {string} tplParams
*/
getCompleted: function TemplateManager_getCompleted(tplHtml, tplParams) {
var tplParam, replaceRegExp;
* limitations under the License.
*/
-/*jslint devel: true */
+/*jslint devel: true*/
/*global $, tizen, App */
/**
var self = this;
$.getScript('js/app.js')
.done(function () {
- console.log('Loaded app.js');
// once the app is loaded, create the app object
// and load the libraries
app = new App();
$.getScript(filename)
.done(function () {
loadedLibs += 1;
- console.log('Loaded subscript: ' + filename + ' : ' + loadedLibs);
if (loadedLibs >= app.requires.length) {
// All dependencies are loaded - initialise the app
app.init();
<div data-role="content">
<ul id="fileList" data-role="listview"></ul>
+ <div data-role="popup" class="center_title_2btn" id="addFolderPopup">
+ <div class="ui-popup-title">
+ <h1>Add new folder<h1>
+ </div>
+ <div class="ui-popup-text">
+ <input id="newFolderName" type="text" value="New folder" class="newFolder" />
+ </div>
+ <div class="ui-popup-button-bg">
+ <a data-role="button" id="saveNewFolder" data-rel="back" data-inline="true">Save</a>
+ <a data-role="button" id="cancelNewFolder" id="btn_textbox_popup_cancel" data-rel="back" data-inline="true">Cancel</a>
+ </div>
+ </div>
</div>
<div data-role="footer" data-position="fixed">
</tr>
</table>
</div>
- <div class="horizontal" id="addFolderPopup" data-role="popup" data-style="center_title_2btn" data-corners="true" >
- <p data-role="title">Add new folder</p>
- <p data-role="text">
- <input id="newFolderName" type="text" value="New folder" class="newFolder" />
- </p>
- <p data-role="text">
- <input type="button" id="saveNewFolder" value="Save" data-inline="true" />
- <input type="button" id="cancelNewFolder" value="Cancel" data-inline="true" />
- </p>
- </div>
</div>
</div>
</div>
\ No newline at end of file