mirror of
https://github.com/JanGross/quicknotes.git
synced 2025-12-01 07:37:18 +01:00
Add confirmation dialog to cancel. Part of issue #27
This commit is contained in:
52
js/script.js
52
js/script.js
@@ -161,6 +161,9 @@ Notes.prototype = {
|
|||||||
// 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) {
|
var View = function (notes) {
|
||||||
this._notes = notes;
|
this._notes = notes;
|
||||||
|
|
||||||
|
this._editor = undefined;
|
||||||
|
this._changed = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
View.prototype = {
|
View.prototype = {
|
||||||
@@ -184,6 +187,7 @@ View.prototype = {
|
|||||||
return digits[1] + '#' + rgb.toString(16).toUpperCase();
|
return digits[1] + '#' + rgb.toString(16).toUpperCase();
|
||||||
},
|
},
|
||||||
editNote: function (id) {
|
editNote: function (id) {
|
||||||
|
var self = this;
|
||||||
var modal = $('#modal-note-div');
|
var modal = $('#modal-note-div');
|
||||||
var modaltitle = $('#modal-note-div #title-editable');
|
var modaltitle = $('#modal-note-div #title-editable');
|
||||||
var modalcontent = $('#modal-note-div #content-editable');
|
var modalcontent = $('#modal-note-div #content-editable');
|
||||||
@@ -237,6 +241,12 @@ View.prototype = {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
editor.subscribe('editableInput', function(event, editorElement) {
|
||||||
|
self._changed = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
this._editor = editor;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
var shareSelect = $('.note-share-select');
|
var shareSelect = $('.note-share-select');
|
||||||
shareSelect.select2({
|
shareSelect.select2({
|
||||||
@@ -350,15 +360,21 @@ View.prototype = {
|
|||||||
modalcontent.html("");
|
modalcontent.html("");
|
||||||
modaltags.html("");
|
modaltags.html("");
|
||||||
|
|
||||||
|
self._editor.destroy();
|
||||||
|
self._changed = false;
|
||||||
|
|
||||||
self.render();
|
self.render();
|
||||||
}).fail(function () {
|
}).fail(function () {
|
||||||
alert('DOh!. Could not update note!.');
|
alert('DOh!. Could not update note!.');
|
||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
cancelEdit: function () {
|
cancelEdit: function () {
|
||||||
|
var self = this;
|
||||||
var modal = $('#modal-note-div');
|
var modal = $('#modal-note-div');
|
||||||
var modaltitle = $('#modal-note-div #title-editable');
|
var modaltitle = $('#modal-note-div #title-editable');
|
||||||
var modalcontent = $('#modal-note-dive #content-editable');
|
var modalcontent = $('#modal-note-dive #content-editable');
|
||||||
|
var modaltags = $('#modal-note-div .note-tags');
|
||||||
var modalcolortools = $("#modal-note-div .circle-toolbar");
|
var modalcolortools = $("#modal-note-div .circle-toolbar");
|
||||||
var modalnote = $("#modal-note-div .quicknote");
|
var modalnote = $("#modal-note-div .quicknote");
|
||||||
|
|
||||||
@@ -385,12 +401,18 @@ View.prototype = {
|
|||||||
modalnote.data('id', -1);
|
modalnote.data('id', -1);
|
||||||
modaltitle.html("");
|
modaltitle.html("");
|
||||||
modalcontent.html("");
|
modalcontent.html("");
|
||||||
|
modaltags.html("");
|
||||||
|
|
||||||
$.each(modalcolortools, function(i, colortool) {
|
$.each(modalcolortools, function(i, colortool) {
|
||||||
$(colortool).removeClass('icon-checkmark');
|
$(colortool).removeClass('icon-checkmark');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
self._editor.destroy();
|
||||||
|
self._changed = false;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this._changed = false;
|
||||||
},
|
},
|
||||||
renderContent: function () {
|
renderContent: function () {
|
||||||
// Remove all event handlers to prevent double events.
|
// Remove all event handlers to prevent double events.
|
||||||
@@ -451,7 +473,20 @@ View.prototype = {
|
|||||||
// Cancel when click outside the modal.
|
// Cancel when click outside the modal.
|
||||||
$('#app-content').on('click', '.modal-note-background', function (event) {
|
$('#app-content').on('click', '.modal-note-background', function (event) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
self.cancelEdit();
|
if (!self._changed) {
|
||||||
|
self.cancelEdit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
OC.dialogs.confirm(
|
||||||
|
t('facerecognition', 'Do you want to discard the changes?'),
|
||||||
|
t('facerecognition', 'Unsaved changes'),
|
||||||
|
function(result) {
|
||||||
|
if (result) {
|
||||||
|
self.cancelEdit();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
true
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle hotkeys
|
// Handle hotkeys
|
||||||
@@ -459,7 +494,20 @@ View.prototype = {
|
|||||||
$(document).on("keyup", function(event) {
|
$(document).on("keyup", function(event) {
|
||||||
if (event.keyCode == 27) {
|
if (event.keyCode == 27) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
self.cancelEdit();
|
if (!self._changed) {
|
||||||
|
self.cancelEdit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
OC.dialogs.confirm(
|
||||||
|
t('facerecognition', 'Do you want to discard the changes?'),
|
||||||
|
t('facerecognition', 'Unsaved changes'),
|
||||||
|
function(result) {
|
||||||
|
if (result) {
|
||||||
|
self.cancelEdit();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
true
|
||||||
|
);
|
||||||
}
|
}
|
||||||
else if (event.keyCode == 13 && event.altKey) {
|
else if (event.keyCode == 13 && event.altKey) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|||||||
Reference in New Issue
Block a user