mirror of
https://github.com/JanGross/quicknotes.git
synced 2025-12-01 07:37:18 +01:00
Take tags from notes controller
This commit is contained in:
55
js/script.js
55
js/script.js
@@ -111,6 +111,16 @@ Notes.prototype = {
|
|||||||
});
|
});
|
||||||
return Ccolors;
|
return Ccolors;
|
||||||
},
|
},
|
||||||
|
getTags: function () {
|
||||||
|
var tags = [];
|
||||||
|
$.each(this._notes, function(index, note) {
|
||||||
|
$.each(note.tags, function(index, tag) {
|
||||||
|
if (tags.findIndex(item => item.id == tag.id) === -1)
|
||||||
|
tags.push(tag);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return tags;
|
||||||
|
},
|
||||||
loadAll: function () {
|
loadAll: function () {
|
||||||
var deferred = $.Deferred();
|
var deferred = $.Deferred();
|
||||||
var self = this;
|
var self = this;
|
||||||
@@ -147,38 +157,10 @@ Notes.prototype = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// this notes object holds all our tags
|
|
||||||
var Tags = function (baseUrl) {
|
|
||||||
this._baseUrl = baseUrl;
|
|
||||||
this._tags = [];
|
|
||||||
this._loaded = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
Tags.prototype = {
|
|
||||||
loadAll: function () {
|
|
||||||
var deferred = $.Deferred();
|
|
||||||
var self = this;
|
|
||||||
$.get(this._baseUrl).done(function (tags) {
|
|
||||||
self._tags = tags.reverse();
|
|
||||||
self._loaded = true;
|
|
||||||
deferred.resolve();
|
|
||||||
}).fail(function () {
|
|
||||||
deferred.reject();
|
|
||||||
});
|
|
||||||
return deferred.promise();
|
|
||||||
},
|
|
||||||
isLoaded: function () {
|
|
||||||
return this._loaded;
|
|
||||||
},
|
|
||||||
getAll: function () {
|
|
||||||
return this._tags;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// this will be the view that is used to update the html
|
// this will be the view that is used to update the html
|
||||||
var View = function (notes, tags) {
|
var View = function (notes) {
|
||||||
this._notes = notes;
|
this._notes = notes;
|
||||||
this._tags = tags;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
View.prototype = {
|
View.prototype = {
|
||||||
@@ -631,7 +613,7 @@ View.prototype = {
|
|||||||
var id = $("#modal-note-div .quicknote").data('id');
|
var id = $("#modal-note-div .quicknote").data('id');
|
||||||
self._notes.load(id);
|
self._notes.load(id);
|
||||||
QnDialogs.tags(
|
QnDialogs.tags(
|
||||||
self._tags.getAll(),
|
self._notes.getTags(),
|
||||||
self._notes.getActive().tags,
|
self._notes.getActive().tags,
|
||||||
function(result, newTags) {
|
function(result, newTags) {
|
||||||
if (result === true) {
|
if (result === true) {
|
||||||
@@ -666,7 +648,7 @@ View.prototype = {
|
|||||||
var html = Handlebars.templates['navigation']({
|
var html = Handlebars.templates['navigation']({
|
||||||
colors: this._notes.getColors(),
|
colors: this._notes.getColors(),
|
||||||
notes: this._notes.getAll(),
|
notes: this._notes.getAll(),
|
||||||
tags: this._tags.getAll(),
|
tags: this._notes.getTags(),
|
||||||
newNoteTxt: t('quicknotes', 'New note'),
|
newNoteTxt: t('quicknotes', 'New note'),
|
||||||
allNotesTxt: t('quicknotes', 'All notes'),
|
allNotesTxt: t('quicknotes', 'All notes'),
|
||||||
colorsTxt: t('quicknotes', 'Colors'),
|
colorsTxt: t('quicknotes', 'Colors'),
|
||||||
@@ -843,9 +825,7 @@ new OCA.Search(search, function() {
|
|||||||
* Create modules
|
* Create modules
|
||||||
*/
|
*/
|
||||||
var notes = new Notes(OC.generateUrl('/apps/quicknotes/notes'));
|
var notes = new Notes(OC.generateUrl('/apps/quicknotes/notes'));
|
||||||
var tags = new Tags(OC.generateUrl('/apps/quicknotes/tags'));
|
var view = new View(notes);
|
||||||
|
|
||||||
var view = new View(notes, tags);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Render initial loading view
|
* Render initial loading view
|
||||||
@@ -856,12 +836,7 @@ view.renderContent();
|
|||||||
* Loading notes and render final view.
|
* Loading notes and render final view.
|
||||||
*/
|
*/
|
||||||
notes.loadAll().done(function () {
|
notes.loadAll().done(function () {
|
||||||
tags.loadAll().done(function () {
|
view.render();
|
||||||
view.render();
|
|
||||||
}).fail(function () {
|
|
||||||
alert('Could not load tags');
|
|
||||||
});
|
|
||||||
// FIXME: So ugly...
|
|
||||||
}).fail(function () {
|
}).fail(function () {
|
||||||
alert('Could not load notes');
|
alert('Could not load notes');
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user