define([ 'jquery', '/common/toolbar3.js', 'json.sortify', '/common/common-util.js', '/common/common-hash.js', '/common/common-ui-elements.js', '/common/common-interface.js', '/common/common-constants.js', '/common/common-feedback.js', '/bower_components/nthen/index.js', '/common/sframe-common.js', '/common/common-realtime.js', '/common/hyperscript.js', '/common/userObject.js', '/customize/application_config.js', '/bower_components/chainpad-listmap/chainpad-listmap.js', '/customize/messages.js', 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', 'less!/customize/src/less2/main.less', ], function ( $, Toolbar, JSONSortify, Util, Hash, UIElements, UI, Constants, Feedback, nThen, SFCommon, CommonRealtime, h, FO, AppConfig, Listmap, Messages) { var APP = window.APP = { editable: false, mobile: function () { return $('body').width() <= 600; }, // Menu and content area are not inline-block anymore for mobiles isMac: navigator.platform === "MacIntel" }; var stringify = function (obj) { return JSONSortify(obj); }; var E_OVER_LIMIT = 'E_OVER_LIMIT'; var SEARCH = "search"; var SEARCH_NAME = Messages.fm_searchName; var ROOT = "root"; var ROOT_NAME = Messages.fm_rootName; var FILES_DATA = Constants.storageKey; var FILES_DATA_NAME = Messages.fm_filesDataName; var TEMPLATE = "template"; var TEMPLATE_NAME = Messages.fm_templateName; var TRASH = "trash"; var TRASH_NAME = Messages.fm_trashName; var RECENT = "recent"; var RECENT_NAME = Messages.fm_recentPadsName; var OWNED = "owned"; var OWNED_NAME = Messages.fm_ownedPadsName; var LS_LAST = "app-drive-lastOpened"; var LS_OPENED = "app-drive-openedFolders"; var LS_VIEWMODE = "app-drive-viewMode"; var LS_SEARCHCURSOR = "app-drive-searchCursor"; var FOLDER_CONTENT_ID = "cp-app-drive-content-folder"; var config = {}; var DEBUG = config.DEBUG = true; var debug = config.debug = DEBUG ? function () { console.log.apply(console, arguments); } : function () { return; }; var logError = config.logError = function () { console.error.apply(console, arguments); }; var log = config.log = UI.log; var localStore = window.cryptpadStore; APP.store = {}; var getLastOpenedFolder = function () { var path; try { path = APP.store[LS_LAST] ? JSON.parse(APP.store[LS_LAST]) : [ROOT]; } catch (e) { path = [ROOT]; } return path; }; var setLastOpenedFolder = function (path) { if (path[0] === SEARCH) { return; } APP.store[LS_LAST] = JSON.stringify(path); localStore.put(LS_LAST, JSON.stringify(path)); }; var wasFolderOpened = function (path) { var stored = JSON.parse(APP.store[LS_OPENED] || '[]'); return stored.indexOf(JSON.stringify(path)) !== -1; }; var setFolderOpened = function (path, opened) { var s = JSON.stringify(path); var stored = JSON.parse(APP.store[LS_OPENED] || '[]'); if (opened && stored.indexOf(s) === -1) { stored.push(s); } if (!opened) { var idx = stored.indexOf(s); if (idx !== -1) { stored.splice(idx, 1); } } APP.store[LS_OPENED] = JSON.stringify(stored); localStore.put(LS_OPENED, JSON.stringify(stored)); }; var getViewModeClass = function () { var mode = APP.store[LS_VIEWMODE]; if (mode === 'list') { return 'cp-app-drive-content-list'; } return 'cp-app-drive-content-grid'; }; var getViewMode = function () { return APP.store[LS_VIEWMODE] || 'grid'; }; var setViewMode = function (mode) { if (typeof(mode) !== "string") { logError("Incorrect view mode: ", mode); return; } APP.store[LS_VIEWMODE] = mode; localStore.put(LS_VIEWMODE, mode); }; var setSearchCursor = function () { var $input = $('#cp-app-drive-tree-search-input'); APP.store[LS_SEARCHCURSOR] = $input[0].selectionStart; localStore.put(LS_SEARCHCURSOR, $input[0].selectionStart); }; var getSearchCursor = function () { return APP.store[LS_SEARCHCURSOR] || 0; }; var setEditable = function (state) { APP.editable = state; if (!state) { APP.$content.addClass('cp-app-drive-readonly'); $('[draggable="true"]').attr('draggable', false); } else { APP.$content.removeClass('cp-app-drive-readonly'); $('[draggable="false"]').attr('draggable', true); } }; // Icons var faFolder = 'fa-folder'; var faFolderOpen = 'fa-folder-open'; var faReadOnly = 'fa-eye'; var faRename = 'fa-pencil'; var faTrash = 'fa-trash'; var faDelete = 'fa-eraser'; var faProperties = 'fa-database'; var faTags = 'fa-hashtag'; var faEmpty = 'fa-trash-o'; var faRestore = 'fa-repeat'; var faShowParent = 'fa-location-arrow'; var $folderIcon = $('', { "class": faFolder + " fa cp-app-drive-icon-folder cp-app-drive-content-icon" }); //var $folderIcon = $('', {src: "/customize/images/icons/folder.svg", "class": "folder icon"}); var $folderEmptyIcon = $folderIcon.clone(); var $folderOpenedIcon = $('', {"class": faFolderOpen + " fa cp-app-drive-icon-folder"}); //var $folderOpenedIcon = $('', {src: "/customize/images/icons/folderOpen.svg", "class": "folder icon"}); var $folderOpenedEmptyIcon = $folderOpenedIcon.clone(); //var $upIcon = $('', {"class": "fa fa-arrow-circle-up"}); var $unsortedIcon = $('', {"class": "fa fa-files-o"}); var $templateIcon = $('', {"class": "fa fa-cubes"}); var $recentIcon = $('', {"class": "fa fa-clock-o"}); var $trashIcon = $('', {"class": "fa " + faTrash}); var $trashEmptyIcon = $('', {"class": "fa fa-trash-o"}); //var $collapseIcon = $('', {"class": "fa fa-minus-square-o cp-app-drive-icon-expcol"}); var $expandIcon = $('', {"class": "fa fa-plus-square-o cp-app-drive-icon-expcol"}); var $emptyTrashIcon = $('