mirror of
https://github.com/JanGross/quicknotes.git
synced 2025-11-30 23:37:16 +01:00
Show an spinner while loading notes.
Misc fixes..
This commit is contained in:
68
js/script.js
68
js/script.js
@@ -5,7 +5,7 @@
|
|||||||
* later. See the COPYING file.
|
* later. See the COPYING file.
|
||||||
*
|
*
|
||||||
* @author Matias De lellis <mati86dl@gmail.com>
|
* @author Matias De lellis <mati86dl@gmail.com>
|
||||||
* @copyright Matias De lellis 2016-2018
|
* @copyright Matias De lellis 2016-2019
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function (OC, window, $, undefined) {
|
(function (OC, window, $, undefined) {
|
||||||
@@ -18,6 +18,7 @@ var Notes = function (baseUrl) {
|
|||||||
this._baseUrl = baseUrl;
|
this._baseUrl = baseUrl;
|
||||||
this._notes = [];
|
this._notes = [];
|
||||||
this._activeNote = undefined;
|
this._activeNote = undefined;
|
||||||
|
this._loaded = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
Notes.prototype = {
|
Notes.prototype = {
|
||||||
@@ -115,12 +116,16 @@ Notes.prototype = {
|
|||||||
$.get(this._baseUrl).done(function (notes) {
|
$.get(this._baseUrl).done(function (notes) {
|
||||||
self._activeNote = undefined;
|
self._activeNote = undefined;
|
||||||
self._notes = notes.reverse();
|
self._notes = notes.reverse();
|
||||||
|
self._loaded = true;
|
||||||
deferred.resolve();
|
deferred.resolve();
|
||||||
}).fail(function () {
|
}).fail(function () {
|
||||||
deferred.reject();
|
deferred.reject();
|
||||||
});
|
});
|
||||||
return deferred.promise();
|
return deferred.promise();
|
||||||
},
|
},
|
||||||
|
isLoaded: function () {
|
||||||
|
return this._loaded;
|
||||||
|
},
|
||||||
updateActive: function (title, content, color) {
|
updateActive: function (title, content, color) {
|
||||||
var note = this.getActive();
|
var note = this.getActive();
|
||||||
note.title = title;
|
note.title = title;
|
||||||
@@ -286,11 +291,18 @@ View.prototype = {
|
|||||||
return digits[1] + '#' + rgb.toString(16).toUpperCase();
|
return digits[1] + '#' + rgb.toString(16).toUpperCase();
|
||||||
},
|
},
|
||||||
renderContent: function () {
|
renderContent: function () {
|
||||||
|
// Remove all event handlers to prevent double events.
|
||||||
|
$("#app-content").off();
|
||||||
|
|
||||||
var html = Handlebars.templates['notes']({
|
var html = Handlebars.templates['notes']({
|
||||||
|
loaded: this._notes.isLoaded(),
|
||||||
notes: this._notes.getAll(),
|
notes: this._notes.getAll(),
|
||||||
cancelTxt: t('quicknotes', 'Cancel'),
|
cancelTxt: t('quicknotes', 'Cancel'),
|
||||||
saveTxt: t('quicknotes', 'Save'),
|
saveTxt: t('quicknotes', 'Save'),
|
||||||
emptyTxt: t('quicknotes', 'Nothing here. Take your quick notes.'),
|
loadingMsg: t('quicknotes', 'Looking for your notes'),
|
||||||
|
loadingIcon: OC.imagePath('core', 'loading.gif'),
|
||||||
|
emptyMsg: t('quicknotes', 'Nothing here. Take your first quick notes'),
|
||||||
|
emptyIcon: OC.imagePath('quicknotes', 'app'),
|
||||||
});
|
});
|
||||||
$('#div-content').html(html);
|
$('#div-content').html(html);
|
||||||
|
|
||||||
@@ -321,7 +333,7 @@ View.prototype = {
|
|||||||
|
|
||||||
// Open notes when clicking them.
|
// Open notes when clicking them.
|
||||||
$("#app-content").on("click", ".quicknote", function (event) {
|
$("#app-content").on("click", ".quicknote", function (event) {
|
||||||
event.stopPropagation(); // Not work so need fix on next binding..
|
event.stopPropagation();
|
||||||
|
|
||||||
if($(this).hasClass('shared')) return; //shares don't allow editing
|
if($(this).hasClass('shared')) return; //shares don't allow editing
|
||||||
var modalnote = $("#modal-note-editable .quicknote");
|
var modalnote = $("#modal-note-editable .quicknote");
|
||||||
@@ -334,12 +346,8 @@ View.prototype = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Cancel when click outside the modal.
|
// Cancel when click outside the modal.
|
||||||
$(".modal-note-background").click(function (event) {
|
$('#app-content').on('click', '.modal-note-background', function (event) {
|
||||||
/* stopPropagation() not work with .on() binings. */
|
|
||||||
if (!$(event.target).is(".modal-note-background")) {
|
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
return;
|
|
||||||
}
|
|
||||||
self.cancelEdit();
|
self.cancelEdit();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -353,11 +361,11 @@ View.prototype = {
|
|||||||
// Remove note icon
|
// Remove note icon
|
||||||
var self = this;
|
var self = this;
|
||||||
$('#app-content').on("click", ".icon-delete-note", function (event) {
|
$('#app-content').on("click", ".icon-delete-note", function (event) {
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
var note = $(this).parent().parent();
|
var note = $(this).parent().parent();
|
||||||
var id = parseInt(note.data('id'), 10);
|
var id = parseInt(note.data('id'), 10);
|
||||||
|
|
||||||
event.stopPropagation();
|
|
||||||
|
|
||||||
self._notes.load(id);
|
self._notes.load(id);
|
||||||
OC.dialogs.confirm(
|
OC.dialogs.confirm(
|
||||||
t('quicknotes', 'Are you sure you want to delete the note?'),
|
t('quicknotes', 'Are you sure you want to delete the note?'),
|
||||||
@@ -475,6 +483,7 @@ View.prototype = {
|
|||||||
|
|
||||||
// handle cancel editing notes.
|
// handle cancel editing notes.
|
||||||
$('#modal-note-div #cancel-button').click(function (event) {
|
$('#modal-note-div #cancel-button').click(function (event) {
|
||||||
|
event.stopPropagation();
|
||||||
self.cancelEdit();
|
self.cancelEdit();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -594,32 +603,6 @@ View.prototype = {
|
|||||||
$(this).toggleClass("open");
|
$(this).toggleClass("open");
|
||||||
});
|
});
|
||||||
|
|
||||||
// show app menu
|
|
||||||
$('#app-navigation .app-navigation-entry-utils-menu-button').click(function () {
|
|
||||||
var entry = $(this).closest('.note');
|
|
||||||
entry.find('.app-navigation-entry-menu').toggleClass('open');
|
|
||||||
});
|
|
||||||
|
|
||||||
// delete a note
|
|
||||||
$('#app-navigation .note .delete').click(function () {
|
|
||||||
var entry = $(this).closest('.note');
|
|
||||||
entry.find('.app-navigation-entry-menu').removeClass('open');
|
|
||||||
OC.dialogs.confirm(
|
|
||||||
t('quicknotes', 'Are you sure you want to delete the note?'),
|
|
||||||
t('quicknotes', 'Delete note'),
|
|
||||||
function(result) {
|
|
||||||
if (result) {
|
|
||||||
self._notes.removeActive().done(function () {
|
|
||||||
self.render();
|
|
||||||
}).fail(function () {
|
|
||||||
alert('Could not delete note, not found');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
true
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
// show a note
|
// show a note
|
||||||
$('#app-navigation .note > a').click(function (event) {
|
$('#app-navigation .note > a').click(function (event) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
@@ -683,8 +666,21 @@ new OCA.Search(search, function() {
|
|||||||
search('');
|
search('');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create modules
|
||||||
|
*/
|
||||||
var notes = new Notes(OC.generateUrl('/apps/quicknotes/notes'));
|
var notes = new Notes(OC.generateUrl('/apps/quicknotes/notes'));
|
||||||
var view = new View(notes);
|
var view = new View(notes);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Render loading view
|
||||||
|
*/
|
||||||
|
view.renderContent();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Loading notes and render view.
|
||||||
|
*/
|
||||||
notes.loadAll().done(function () {
|
notes.loadAll().done(function () {
|
||||||
view.render();
|
view.render();
|
||||||
}).fail(function () {
|
}).fail(function () {
|
||||||
|
|||||||
@@ -74,9 +74,19 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{{else if loaded}}
|
||||||
|
<div class="emptycontent">
|
||||||
|
<div class="icon-edit svg"></div>
|
||||||
|
<h2>
|
||||||
|
{{ emptyMsg }}
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
{{else}}
|
{{else}}
|
||||||
<div class="emptycontent">
|
<div class="emptycontent">
|
||||||
<div class="icon-folder"></div>
|
<div class="icon-edit svg"></div>
|
||||||
{{ emptyMsg }}
|
<h2>
|
||||||
</div>
|
{{loadingMsg}}
|
||||||
|
</h2>
|
||||||
|
<img class="loadingimport" src="{{loadingIcon}}"/>
|
||||||
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|||||||
Reference in New Issue
Block a user