1
0
mirror of https://github.com/owncloud/bookmarks.git synced 2024-12-01 05:24:11 +01:00

js cleanup: remove settings related code from bookmarks.js

This commit is contained in:
Arthur Schiwon 2015-12-22 11:56:52 +01:00
parent 0adbc2b1cf
commit b58c90249b
5 changed files with 103 additions and 89 deletions

View File

@ -22,7 +22,7 @@
} }
/** /**
* @namespace OCA.Files.App * @namespace OCA.Bookmarks.App
*/ */
OCA.Bookmarks.App = { OCA.Bookmarks.App = {
@ -56,6 +56,11 @@
*/ */
tagFilterView: null, tagFilterView: null,
/**
* @member OCA.Bookmarks.SettinsView
*/
settingsView: null,
/** /**
* Initializes the bookmarks app * Initializes the bookmarks app
*/ */
@ -78,6 +83,11 @@
id: 'tagitManager' id: 'tagitManager'
}); });
this.settingsView = new OCA.Bookmarks.SettingsView({
el: '#app-settings',
id: 'appSettings'
});
this.allTagsCollection.fetch(); this.allTagsCollection.fetch();
console.warn('INiT DONE'); console.warn('INiT DONE');
} }

View File

@ -6,15 +6,7 @@ var ajaxCallCount = 0;
$(document).ready(function () { $(document).ready(function () {
watchUrlField(); watchUrlField();
$('#bm_import').change(attachSettingEvent);
$('#add_url').on('keydown keyup change click', watchUrlField); $('#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(); $('.bookmarks_list').scroll(updateOnBottom).empty();
$('.navigationAllBookmarks').click(resetTagFilter); $('.navigationAllBookmarks').click(resetTagFilter);
@ -57,12 +49,6 @@ function updateLoadingAnimation() {
} }
} }
function watchClickInSetting(e) {
if ($('#app-settings').find($(e.target)).length === 0) {
toggleSettings();
}
}
function checkURL(url) { function checkURL(url) {
if (url.substring(0, 3) === "htt") { if (url.substring(0, 3) === "htt") {
return url; return url;
@ -70,16 +56,6 @@ function checkURL(url) {
return "http://" + 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) { function addFilterTag(event) {
event.preventDefault(); event.preventDefault();
$('#tag_filter input').tagit('createTag', $(this).text()); $('#tag_filter input').tagit('createTag', $(this).text());

View File

@ -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 = $("<ul></ul>").addClass('setting_error_list');
console.log(data);
$.each(data.data, function (index, item) {
list.append($("<li></li>").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 = $('<iframe></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...'));
}

91
js/settingsView.js Normal file
View File

@ -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 = $('<iframe></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 = $("<ul></ul>").addClass('setting_error_list');
console.warn(data);
$.each(data.data, function (index, item) {
list.append($("<li></li>").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;
})();

View File

@ -6,9 +6,9 @@ script('bookmarks', 'tagModel');
script('bookmarks', 'tagCollection'); script('bookmarks', 'tagCollection');
script('bookmarks', 'tagListView'); script('bookmarks', 'tagListView');
script('bookmarks', 'tagFilterView'); script('bookmarks', 'tagFilterView');
script('bookmarks', 'settingsView');
script('bookmarks', 'app'); script('bookmarks', 'app');
script('bookmarks', 'settings');
script('bookmarks', 'bookmarks'); script('bookmarks', 'bookmarks');
style('bookmarks', 'bookmarks'); style('bookmarks', 'bookmarks');