mirror of
https://github.com/owncloud/bookmarks.git
synced 2025-02-19 16:54:27 +01:00
js cleanup: initialize stuff in new OCA.Bookmarks.App, replace first init runs and functions in bookmarks.js
This commit is contained in:
parent
1f8ee4d068
commit
0adbc2b1cf
@ -75,7 +75,7 @@ class TagsController extends ApiController {
|
||||
|
||||
$tags = Bookmarks::analyzeTagRequest($tag);
|
||||
$qtags = Bookmarks::findTags($this->userId, $this->db, $tags);
|
||||
return new JSONResponse(array('data' => $qtags, 'status' => 'success'));
|
||||
return new JSONResponse($qtags);
|
||||
}
|
||||
|
||||
}
|
||||
|
93
js/app.js
Normal file
93
js/app.js
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2015
|
||||
*
|
||||
* @author Arthur Schiwon
|
||||
* @copyright 2015 Arthur Schiwon <blizzz@owncloud.com>
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3
|
||||
* or later.
|
||||
*
|
||||
* See the COPYING-README file.
|
||||
*
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
if (!OCA.Bookmarks) {
|
||||
/**
|
||||
* Namespace for the bookmarks app
|
||||
* @namespace OCA.Bookmarks
|
||||
*/
|
||||
OCA.Bookmarks = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* @namespace OCA.Files.App
|
||||
*/
|
||||
OCA.Bookmarks.App = {
|
||||
|
||||
/**
|
||||
* @member OCA.Bookmarks.TagCollection
|
||||
*/
|
||||
allTagsCollection: null,
|
||||
|
||||
/**
|
||||
* @member OCA.Bookmarks.TagCollection
|
||||
*/
|
||||
availableTagsCollection: null,
|
||||
|
||||
/**
|
||||
* @member OCA.Bookmarks.TagCollection
|
||||
*/
|
||||
selectedTagsCollection: null,
|
||||
|
||||
/**
|
||||
* @member OCA.Bookmarks.TagListView
|
||||
*/
|
||||
availableTagsList: null,
|
||||
|
||||
/**
|
||||
* @member OCA.Bookmarks.TagListView
|
||||
*/
|
||||
selectedTagsList: null,
|
||||
|
||||
/**
|
||||
* @member OCA.Bookmarks.TagFilterView
|
||||
*/
|
||||
tagFilterView: null,
|
||||
|
||||
/**
|
||||
* Initializes the bookmarks app
|
||||
*/
|
||||
initialize: function() {
|
||||
this.allTagsCollection = new OCA.Bookmarks.TagCollection();
|
||||
this.availableTagsCollection = new OCA.Bookmarks.TagCollection();
|
||||
this.selectedTagsCollection = new OCA.Bookmarks.TagCollection();
|
||||
|
||||
this.availableTagsList = new OCA.Bookmarks.TagListView({
|
||||
model: this.availableTagsCollection,
|
||||
id: 'availableTagsList'
|
||||
});
|
||||
this.selectedTagsList = new OCA.Bookmarks.TagListView({
|
||||
model: this.selectedTagsCollection,
|
||||
id: 'selectedTagsList'
|
||||
});
|
||||
|
||||
this.tagFilterView = new OCA.Bookmarks.TagFilterView({
|
||||
collection: this.allTagsCollection,
|
||||
id: 'tagitManager'
|
||||
});
|
||||
|
||||
this.allTagsCollection.fetch();
|
||||
console.warn('INiT DONE');
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
$(document).ready(function() {
|
||||
// wait for other apps/extensions to register their event handlers and file actions
|
||||
// in the "ready" clause
|
||||
_.defer(function() {
|
||||
OCA.Bookmarks.App.initialize();
|
||||
});
|
||||
});
|
@ -2,29 +2,9 @@ var bookmarksPage = 0;
|
||||
var bookmarksLoading = false;
|
||||
var dialog;
|
||||
var bookmarksSorting = 'bookmarks_sorting_recent';
|
||||
var fullTags = [];
|
||||
var ajaxCallCount = 0;
|
||||
|
||||
var allTagsCollection;
|
||||
var availableTagsCollection;
|
||||
var selectedTagsCollection;
|
||||
var availableTagsList;
|
||||
var selectedTagsList;
|
||||
|
||||
$(document).ready(function () {
|
||||
allTagsCollection = new OCA.Bookmarks.TagCollection();
|
||||
availableTagsCollection = new OCA.Bookmarks.TagCollection();
|
||||
selectedTagsCollection = new OCA.Bookmarks.TagCollection();
|
||||
availableTagsList = new OCA.Bookmarks.TagListView({
|
||||
model: availableTagsCollection,
|
||||
id: 'availableTagsList'
|
||||
});
|
||||
selectedTagsList = new OCA.Bookmarks.TagListView({
|
||||
model: selectedTagsCollection,
|
||||
id: 'selectedTagsList'
|
||||
});
|
||||
|
||||
getTags();
|
||||
watchUrlField();
|
||||
$('#bm_import').change(attachSettingEvent);
|
||||
$('#add_url').on('keydown keyup change click', watchUrlField);
|
||||
@ -36,28 +16,11 @@ $(document).ready(function () {
|
||||
}
|
||||
});
|
||||
$('.bookmarks_list').scroll(updateOnBottom).empty();
|
||||
$('#tag_filter input').tagit({
|
||||
allowSpaces: true,
|
||||
availableTags: fullTags,
|
||||
onTagFinishRemoved: filterTagsChanged,
|
||||
placeholderText: t('bookmarks', 'Filter by tag')
|
||||
}).tagit('option', 'onTagAdded', filterTagsChanged);
|
||||
$('.navigationAllBookmarks').click(resetTagFilter);
|
||||
|
||||
getBookmarks();
|
||||
});
|
||||
|
||||
function getTags() {
|
||||
jQuery.ajax({
|
||||
url: 'tag',
|
||||
success: function (result) {
|
||||
fullTags = result;
|
||||
console.warn(fullTags);
|
||||
},
|
||||
async: false
|
||||
});
|
||||
}
|
||||
|
||||
var formatString = (function () {
|
||||
var replacer = function (context) {
|
||||
return function (s, name) {
|
||||
@ -178,8 +141,8 @@ function getBookmarks() {
|
||||
data: {tag: $('#bookmarkFilterTag').val(), page: bookmarksPage, sort: bookmarksSorting},
|
||||
success: function (tags) {
|
||||
$('.tag_list').empty();
|
||||
for (var i in tags.data) {
|
||||
updateTagsList(tags.data[i]);
|
||||
for (var i in tags) {
|
||||
updateTagsList(tags[i]);
|
||||
}
|
||||
$('.tag_list .tag_edit').click(renameTag);
|
||||
$('.tag_list .tag_delete').click(deleteTag);
|
||||
@ -318,7 +281,7 @@ function editBookmark() {
|
||||
var rec_form = record.next().find('form');
|
||||
rec_form.find('.bookmark_form_tags ul').tagit({
|
||||
allowSpaces: true,
|
||||
availableTags: fullTags,
|
||||
availableTags: OCA.Bookmarks.App.allTagsCollection.getLabels(),
|
||||
placeholderText: t('bookmarks', 'Tags')
|
||||
});
|
||||
|
||||
|
@ -12,7 +12,15 @@
|
||||
|
||||
var TagCollection = OC.Backbone.Collection.extend({
|
||||
model: OCA.Bookmarks.TagModel,
|
||||
url: 'tag'
|
||||
url: 'relatedTags',
|
||||
|
||||
getLabels: function () {
|
||||
var labels = [];
|
||||
_.each(this.models, function(model) {
|
||||
this.push(model.get('tag'));
|
||||
}, labels);
|
||||
return labels;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
38
js/tagFilterView.js
Normal file
38
js/tagFilterView.js
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2015
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3
|
||||
* or later.
|
||||
*
|
||||
* See the COPYING-README file.
|
||||
*
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
var TagFilterView = OC.Backbone.View.extend({
|
||||
|
||||
initialize: function(options) {
|
||||
var view = this;
|
||||
|
||||
this.collection.on('add remove', function() { view.render() });
|
||||
|
||||
$('#tag_filter input').tagit({
|
||||
allowSpaces: true
|
||||
});
|
||||
},
|
||||
|
||||
render: function() {
|
||||
console.warn('RUNNING');
|
||||
$('#tag_filter input').tagit({
|
||||
allowSpaces: true,
|
||||
availableTags: this.collection.getLabels(),
|
||||
onTagFinishRemoved: filterTagsChanged,
|
||||
placeholderText: t('bookmarks', 'Filter by tag')
|
||||
}).tagit('option', 'onTagAdded', filterTagsChanged);
|
||||
}
|
||||
});
|
||||
|
||||
OCA.Bookmarks = OCA.Bookmarks || {};
|
||||
OCA.Bookmarks.TagFilterView = TagFilterView;
|
||||
})();
|
@ -11,20 +11,7 @@
|
||||
(function() {
|
||||
|
||||
var TagModel = OC.Backbone.Model.extend({
|
||||
idAttribute: 'id',
|
||||
defaults: {
|
||||
label: '',
|
||||
numberOfBookmarks: 0
|
||||
},
|
||||
|
||||
setLabel: function(label) {
|
||||
this.set({label: label});
|
||||
},
|
||||
|
||||
setNumberOfBookmarks: function(nob) {
|
||||
this.set({numberOfBookmarks: nob});
|
||||
}
|
||||
|
||||
idAttribute: 'id'
|
||||
});
|
||||
|
||||
OCA.Bookmarks = OCA.Bookmarks || {};
|
||||
|
@ -1,13 +1,17 @@
|
||||
<?php
|
||||
script('bookmarks', '3rdparty/tag-it');
|
||||
script('bookmarks', '3rdparty/js_tpl');
|
||||
|
||||
script('bookmarks', 'tagModel');
|
||||
script('bookmarks', 'tagCollection');
|
||||
script('bookmarks', 'tagListView');
|
||||
script('bookmarks', 'tagFilterView');
|
||||
script('bookmarks', 'app');
|
||||
|
||||
script('bookmarks', 'settings');
|
||||
script('bookmarks', 'bookmarks');
|
||||
style('bookmarks', 'bookmarks');
|
||||
|
||||
script('bookmarks', '3rdparty/tag-it');
|
||||
script('bookmarks', '3rdparty/js_tpl');
|
||||
style('bookmarks', '3rdparty/jquery.tagit');
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user