2017-06-12 04:04:07 +08:00
|
|
|
let tags = {
|
|
|
|
1: "<b>",
|
|
|
|
2: "</b>",
|
|
|
|
3: "<i>",
|
|
|
|
4: "</i>",
|
|
|
|
5: "<u>",
|
|
|
|
6: "</u>",
|
|
|
|
9: "<s>",
|
|
|
|
10: "</s>"
|
|
|
|
};
|
|
|
|
|
2017-06-12 09:04:04 +08:00
|
|
|
let noteChangeDisabled = false;
|
|
|
|
|
2017-06-12 04:04:07 +08:00
|
|
|
function noteChanged() {
|
2017-06-12 09:04:04 +08:00
|
|
|
if (noteChangeDisabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-12 04:04:07 +08:00
|
|
|
let note = globalNote;
|
|
|
|
|
|
|
|
let contents = $('#noteDetail').summernote('code');
|
|
|
|
|
|
|
|
let title = $('#noteTitle').val();
|
|
|
|
|
|
|
|
$("#tree").fancytree('getNodeByKey', note.detail.note_id).setTitle(title);
|
|
|
|
|
|
|
|
html2notecase(contents, note);
|
|
|
|
|
|
|
|
note.detail.note_title = title;
|
|
|
|
|
2017-08-16 09:29:12 +08:00
|
|
|
const note_id = note.detail.is_clone ? note.detail.note_clone_id : note.detail.note_id;
|
|
|
|
|
2017-06-12 04:04:07 +08:00
|
|
|
$.ajax({
|
2017-08-16 09:29:12 +08:00
|
|
|
url: baseUrl + 'notes/' + note_id,
|
2017-06-12 04:04:07 +08:00
|
|
|
type: 'PUT',
|
|
|
|
data: JSON.stringify(note),
|
|
|
|
contentType: "application/json",
|
|
|
|
success: function(result) {
|
|
|
|
message("Saved!");
|
2017-08-14 09:42:10 +08:00
|
|
|
},
|
|
|
|
error: function(result) {
|
|
|
|
error("Error saving the note!");
|
2017-06-12 04:04:07 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
$("#noteTitle").on('input', function() {
|
|
|
|
noteChanged();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#noteDetail').summernote({
|
|
|
|
airMode: true,
|
2017-06-12 09:04:04 +08:00
|
|
|
height: 300,
|
2017-06-12 04:04:07 +08:00
|
|
|
callbacks: {
|
|
|
|
onChange: noteChanged
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
var globalNote;
|
|
|
|
|
|
|
|
function setParent(noteId, newParentKey, successCallback) {
|
|
|
|
let newNoteName = "new note";
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: baseUrl + 'notes/' + nodeId + '/setParent/' + newParentKey,
|
|
|
|
type: 'PUT',
|
|
|
|
contentType: "application/json",
|
|
|
|
success: function(result) {
|
|
|
|
successCallback();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-06-12 09:04:04 +08:00
|
|
|
function createNewTopLevelNote() {
|
|
|
|
let rootNode = $("#tree").fancytree("getRootNode");
|
|
|
|
|
|
|
|
createNote(rootNode, "root", "into");
|
|
|
|
}
|
|
|
|
|
2017-06-14 10:36:56 +08:00
|
|
|
let newNoteCreated = false;
|
|
|
|
|
2017-06-12 04:04:07 +08:00
|
|
|
function createNote(node, parentKey, target) {
|
|
|
|
let newNoteName = "new note";
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: baseUrl + 'notes/' + parentKey + '/children' ,
|
|
|
|
type: 'POST',
|
|
|
|
data: JSON.stringify({
|
|
|
|
note_title: newNoteName,
|
|
|
|
target: target,
|
|
|
|
target_note_id: node.key
|
|
|
|
}),
|
|
|
|
contentType: "application/json",
|
|
|
|
success: function(result) {
|
|
|
|
let newNode = {
|
|
|
|
"title": newNoteName,
|
|
|
|
"key": result.note_id,
|
|
|
|
"note_id": result.note_id
|
|
|
|
};
|
|
|
|
|
2017-06-14 10:36:56 +08:00
|
|
|
newNoteCreated = true;
|
|
|
|
|
2017-06-12 04:04:07 +08:00
|
|
|
if (target == 'after') {
|
|
|
|
node.appendSibling(newNode).setActive(true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
node.addChildren(newNode).setActive(true);
|
|
|
|
|
|
|
|
node.folder = true;
|
|
|
|
node.renderTitle();
|
|
|
|
}
|
|
|
|
|
|
|
|
message("Created!");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadNote(noteId) {
|
|
|
|
$.get(baseUrl + 'notes/' + noteId).then(function(note) {
|
|
|
|
globalNote = note;
|
|
|
|
|
|
|
|
$("#noteTitle").val(note.detail.note_title);
|
|
|
|
|
2017-06-14 10:36:56 +08:00
|
|
|
if (newNoteCreated) {
|
|
|
|
newNoteCreated = false;
|
|
|
|
|
|
|
|
$("#noteTitle").focus().select();
|
|
|
|
}
|
|
|
|
|
2017-06-12 04:04:07 +08:00
|
|
|
let noteText = notecase2html(note);
|
|
|
|
|
2017-06-12 09:04:04 +08:00
|
|
|
noteChangeDisabled = true;
|
|
|
|
|
2017-06-12 04:04:07 +08:00
|
|
|
$('#noteDetail').summernote('code', noteText);
|
2017-06-12 09:04:04 +08:00
|
|
|
|
2017-08-16 10:32:30 +08:00
|
|
|
$(window).resize(); // to trigger resizing of editor
|
|
|
|
|
2017-06-12 09:04:04 +08:00
|
|
|
noteChangeDisabled = false;
|
2017-06-12 04:04:07 +08:00
|
|
|
});
|
|
|
|
}
|