From b58c90249be5050d02cfc1d7fc9cca58edc5af16 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 22 Dec 2015 11:56:52 +0100 Subject: [PATCH] js cleanup: remove settings related code from bookmarks.js --- js/app.js | 12 +++++- js/bookmarks.js | 24 ------------ js/settings.js | 63 -------------------------------- js/settingsView.js | 91 ++++++++++++++++++++++++++++++++++++++++++++++ templates/main.php | 2 +- 5 files changed, 103 insertions(+), 89 deletions(-) delete mode 100644 js/settings.js create mode 100644 js/settingsView.js diff --git a/js/app.js b/js/app.js index 9c5ea23b..f54a35c0 100644 --- a/js/app.js +++ b/js/app.js @@ -22,7 +22,7 @@ } /** - * @namespace OCA.Files.App + * @namespace OCA.Bookmarks.App */ OCA.Bookmarks.App = { @@ -56,6 +56,11 @@ */ tagFilterView: null, + /** + * @member OCA.Bookmarks.SettinsView + */ + settingsView: null, + /** * Initializes the bookmarks app */ @@ -78,6 +83,11 @@ id: 'tagitManager' }); + this.settingsView = new OCA.Bookmarks.SettingsView({ + el: '#app-settings', + id: 'appSettings' + }); + this.allTagsCollection.fetch(); console.warn('INiT DONE'); } diff --git a/js/bookmarks.js b/js/bookmarks.js index 703218e9..1753ffc4 100644 --- a/js/bookmarks.js +++ b/js/bookmarks.js @@ -6,15 +6,7 @@ var ajaxCallCount = 0; $(document).ready(function () { watchUrlField(); - $('#bm_import').change(attachSettingEvent); $('#add_url').on('keydown keyup change click', watchUrlField); - $('#app-settings').on('click keydown', toggleSettings); - $('#bm_export').click(exportBm); - $('#emptycontent-setting').click(function () { - if (!$('#app-settings').hasClass('open')) { - $('#app-settings').click(); - } - }); $('.bookmarks_list').scroll(updateOnBottom).empty(); $('.navigationAllBookmarks').click(resetTagFilter); @@ -57,12 +49,6 @@ function updateLoadingAnimation() { } } -function watchClickInSetting(e) { - if ($('#app-settings').find($(e.target)).length === 0) { - toggleSettings(); - } -} - function checkURL(url) { if (url.substring(0, 3) === "htt") { return url; @@ -70,16 +56,6 @@ function checkURL(url) { return "http://" + url; } -function toggleSettings() { - if ($('#app-settings').hasClass('open')) { //Close - $('#app-settings').switchClass("open", ""); - $('body').unbind('click', watchClickInSetting); - } - else { - $('#app-settings').switchClass("", "open"); - $('body').bind('click', watchClickInSetting); - } -} function addFilterTag(event) { event.preventDefault(); $('#tag_filter input').tagit('createTag', $(this).text()); diff --git a/js/settings.js b/js/settings.js deleted file mode 100644 index 226c84fe..00000000 --- a/js/settings.js +++ /dev/null @@ -1,63 +0,0 @@ -function attachSettingEvent(event) { - event.preventDefault(); - fileUpload($(this).closest('form'), $('#upload')); -} - -function exportBm() { - window.location = $(this).attr('href'); -} - -function fileUpload(form, resultDiv) { - - var uploadEventHandler = function () { - var data = {}; - try { - data = $.parseJSON(iframe.contents().text()); - } catch (e) { - } - if (!data) { - resultDiv.text(t('bookmark', 'Import error')); - return; - } - if (data.status == 'error') { - var list = $("").addClass('setting_error_list'); - console.log(data); - $.each(data.data, function (index, item) { - list.append($("
  • ").text(item)); - }); - resultDiv.html(list); - } else { - resultDiv.text(t('bookmark', 'Import completed successfully.')); - getBookmarks(); - } - }; - - // Create the iframe... - var iframe; - if ($('#upload_iframe').length === 1) - iframe = $('#upload_iframe'); - else { - iframe = $('').attr({ - id: 'upload_iframe', - name: 'upload_iframe', - width: '0', - height: '0', - border: '0', - style: 'display:none' - }).bind('load', uploadEventHandler); - form.append(iframe); - } - - // Set properties of form... - form.attr({ - target: 'upload_iframe', - method: 'post', - enctype: 'multipart/form-data', - encoding: 'multipart/form-data' - }); - - // Submit the form... - form.submit(); - - resultDiv.text(t('bookmark', 'Uploading...')); -} \ No newline at end of file diff --git a/js/settingsView.js b/js/settingsView.js new file mode 100644 index 00000000..59f4fd94 --- /dev/null +++ b/js/settingsView.js @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2015 + * + * This file is licensed under the Affero General Public License version 3 + * or later. + * + * See the COPYING-README file. + * + */ + +(function() { + + var SettingsView = OC.Backbone.View.extend({ + + initialize: function() { + view = this; + + $('#firstrun_setting').click(function () { + if (!view.$el.hasClass('open')) { + view.$el.find('.settings-button').click(); + } + }); + + $('#bm_import').change(function(event){ + event.preventDefault(); + view.import(view, $(this).closest('form')); + }); + + $('#bm_export').on('click', view.export); + }, + + export: function() { + window.location = $(this).attr('href'); + }, + + import: function(view, $form) { + var iframe; + if ($('#upload_iframe').length === 1) + iframe = $('#upload_iframe'); + else { + iframe = $('').attr({ + id: 'upload_iframe', + name: 'upload_iframe', + width: '0', + height: '0', + border: '0', + class: 'hidden' + }).on('load', view.importHandler); + $form.append(iframe); + } + + $form.attr({ + target: 'upload_iframe', + method: 'post', + enctype: 'multipart/form-data', + encoding: 'multipart/form-data' + }); + + $form.submit(); + }, + + importHandler: function () { + var $iframe = $(this); + var data = {}; + try { + data = $.parseJSON($iframe.contents().text()); + } catch (e) { + } + if (!data) { + OC.Notification.showTemporary(t('bookmark', 'Import error')); + return; + } + if (data.status == 'error') { + var list = $("").addClass('setting_error_list'); + console.warn(data); + $.each(data.data, function (index, item) { + list.append($("
  • ").text(item)); + }); + OC.Notification.showTemporary(list, {isHTML: true}); + } else { + OC.Notification.showTemporary(t('bookmark', 'Import completed successfully.')); + //FIXME resolve getBookmarks(), empty bookmarkslist first + getBookmarks(); + } + } + + }); + + OCA.Bookmarks = OCA.Bookmarks || {}; + OCA.Bookmarks.SettingsView = SettingsView; +})(); diff --git a/templates/main.php b/templates/main.php index 25e328e9..be7bb9be 100644 --- a/templates/main.php +++ b/templates/main.php @@ -6,9 +6,9 @@ script('bookmarks', 'tagModel'); script('bookmarks', 'tagCollection'); script('bookmarks', 'tagListView'); script('bookmarks', 'tagFilterView'); +script('bookmarks', 'settingsView'); script('bookmarks', 'app'); -script('bookmarks', 'settings'); script('bookmarks', 'bookmarks'); style('bookmarks', 'bookmarks');