From f33bfef15ff7d7e95e8067f5792023c5659629b5 Mon Sep 17 00:00:00 2001 From: benweet Date: Mon, 12 Aug 2013 01:10:37 +0100 Subject: [PATCH] Upgrade to Bootstrap 3 --- js/extensions/documentPanel.js | 118 +++++++++++++++++++++++++++++++++ js/folderList.js | 15 +++++ 2 files changed, 133 insertions(+) create mode 100644 js/extensions/documentPanel.js create mode 100644 js/folderList.js diff --git a/js/extensions/documentPanel.js b/js/extensions/documentPanel.js new file mode 100644 index 00000000..4f247855 --- /dev/null +++ b/js/extensions/documentPanel.js @@ -0,0 +1,118 @@ +define([ + "jquery", + "underscore", + "utils", + "classes/Extension", + "folderList", + "fileSystem", +], function($, _, utils, Extension, folderList, fileSystem) { + + var documentPanel = new Extension("documentPanel", 'Document Panel'); + + var fileMgr = undefined; + documentPanel.onFileMgrCreated = function(fileMgrParameter) { + fileMgr = fileMgrParameter; + }; + + var folderEltTmpl = [ + '', + '
<%= _.size(folderDesc.fileList) %>
', + ' <%= folderDesc.name %>
', + '' + ].join(''); + var documentEltTmpl = [ + '" data-file-index="<%= fileDesc.fileIndex %>">', + '<%= fileDesc.composeTitle() %>', + ].join(''); + + var panelElt = undefined; + var documentListElt = undefined; + var refreshPanel = function() { + + // List orphan documents + var orphanDocumentList = _.filter(fileSystem, function(fileDesc) { + return fileDesc.folder === undefined; + }); + + // Add orphan documents + var documentListHtml = _.chain(orphanDocumentList).sortBy(function(fileDesc) { + return fileDesc.title.toLowerCase(); + }).reduce(function(result, fileDesc) { + return result + '
  • ' + _.template(documentEltTmpl, { + fileDesc: fileDesc, + }) + '
  • '; + }, '').value(); + documentListHtml = ''; + + // Build directories + _.chain(folderList).sortBy(function(folderDesc) { + return folderDesc.name.toLowerCase(); + }).each(function(folderDesc) { + var fileListHtml = _.chain(folderDesc.fileList).sortBy(function(fileDesc) { + return fileDesc.title.toLowerCase(); + }).reduce(function(result, fileDesc) { + return result + _.template(documentEltTmpl, { + fileDesc: fileDesc, + }); + }, '').value(); + documentListHtml += _.template(folderEltTmpl, { + folderDesc: folderDesc, + fileListHtml: fileListHtml, + id: folderDesc.folderIndex.replace('.', '') + }); + }); + + documentListElt.innerHTML = documentListHtml; + + // Add click listeners + _.each(documentListElt.querySelectorAll('.file'), function(fileElt) { + fileElt = $(fileElt); + fileElt.click(function(e) { + var fileDesc = fileSystem[fileElt.data('fileIndex')]; + if(fileDesc && fileDesc !== selectedFileDesc) { + fileMgr.selectFile(fileDesc); + } + }); + }); + + }; + + documentPanel.onFileSelected = function(fileDesc) { + selectedFileDesc = fileDesc; + refreshPanel(); + }; + + documentPanel.onFileCreated = refreshPanel; + documentPanel.onFileDeleted = refreshPanel; + documentPanel.onTitleChanged = refreshPanel; + documentPanel.onSyncExportSuccess = refreshPanel; + documentPanel.onSyncRemoved = refreshPanel; + documentPanel.onNewPublishSuccess = refreshPanel; + documentPanel.onPublishRemoved = refreshPanel; + documentPanel.onFoldersChanged = refreshPanel; + + // Filter for search input in file selector + function filterFileSelector(filter) { + var liList = $(".file-selector > li"); + liList.show(); + if(filter) { + var words = filter.toLowerCase().split(/\s+/); + liList.each(function() { + var fileTitle = $(this).text().toLowerCase(); + if(_.some(words, function(word) { + return fileTitle.indexOf(word) === -1; + })) { + $(this).hide(); + } + }); + } + } + + documentPanel.onReady = function() { + panelElt = document.querySelector('.document-panel'); + documentListElt = panelElt.querySelector('.list-group'); + }; + + return documentPanel; + +}); \ No newline at end of file diff --git a/js/folderList.js b/js/folderList.js new file mode 100644 index 00000000..59d352c1 --- /dev/null +++ b/js/folderList.js @@ -0,0 +1,15 @@ +define([ + "underscore", + "utils", + "classes/FolderDescriptor", + "storage", +], function(_, utils, FolderDescriptor) { + var folderList = {}; + + // Retrieve folder descriptors from localStorage + _.each(utils.retrieveIndexArray("folder.list"), function(folderIndex) { + folderList[folderIndex] = new FolderDescriptor(folderIndex); + }); + + return folderList; +}); \ No newline at end of file