Skip to content

Commit beae73d

Browse files
author
minjk-bl
committed
Confirm to save changes before clear note
1 parent 7dd7679 commit beae73d

File tree

1 file changed

+84
-5
lines changed

1 file changed

+84
-5
lines changed

js/board/BoardFrame.js

Lines changed: 84 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ define([
9090
let menu = $(this).data('menu');
9191
switch (menu) {
9292
case 'new':
93-
that.createNewNote();
93+
that.createNewNoteWithChecking();
9494
break;
9595
case 'open':
9696
that.openNote();
@@ -111,7 +111,7 @@ define([
111111
that.exportCode();
112112
break;
113113
case 'clear':
114-
that.clearBoard();
114+
that.clearBoardWithChecking();
115115
break;
116116
}
117117
});
@@ -429,9 +429,51 @@ define([
429429
//========================================================================
430430
// Note control
431431
//========================================================================
432-
createNewNote() {
433-
// TODO: alert before closing
432+
/**
433+
* Check if note has changes to save
434+
*/
435+
checkNote() {
436+
if (this.blockList.length > 0) {
437+
return true;
438+
}
439+
return false;
440+
}
441+
createNewNoteWithChecking() {
442+
// alert before closing
443+
let that = this;
444+
if (this.checkNote()) {
445+
// render update modal
446+
com_util.renderModal({
447+
title: 'Save changes',
448+
message: 'Do you want to save changes?',
449+
buttons: ['Cancel', "No", 'Save'],
450+
defaultButtonIdx: 0,
451+
buttonClass: ['cancel', '', 'activated'],
452+
finish: function(clickedBtnIdx) {
453+
switch (clickedBtnIdx) {
454+
case 0:
455+
// cancel - do nothing
456+
return;
457+
case 1:
458+
// don't save
459+
that.createNewNote();
460+
break;
461+
case 2:
462+
// save
463+
that.saveAsNote(function() {
464+
that.createNewNote();
465+
});
466+
break;
467+
}
468+
}
469+
});
434470

471+
return;
472+
}
473+
474+
this.createNewNote();
475+
}
476+
createNewNote() {
435477
// clear board before create new note
436478
this.clearBoard();
437479

@@ -502,7 +544,7 @@ define([
502544

503545
this.saveAsNote();
504546
}
505-
saveAsNote() {
547+
saveAsNote(callback) {
506548
let that = this;
507549
// save file navigation
508550
let fileNavi = new FileNavigation({
@@ -525,6 +567,8 @@ define([
525567
that.tmpState.boardTitle = boardTitle;
526568
that.tmpState.boardPath = boardPath;
527569
$('#vp_boardTitle').val(boardTitle);
570+
571+
callback();
528572
}
529573
});
530574
fileNavi.open();
@@ -625,6 +669,41 @@ define([
625669
// // reloadBlockList
626670
// this.reloadBlockList();
627671
// }
672+
clearBoardWithChecking() {
673+
// alert before closing
674+
let that = this;
675+
if (this.checkNote()) {
676+
// render update modal
677+
com_util.renderModal({
678+
title: 'Save changes',
679+
message: 'Do you want to save changes?',
680+
buttons: ['Cancel', "No", 'Save'],
681+
defaultButtonIdx: 0,
682+
buttonClass: ['cancel', '', 'activated'],
683+
finish: function(clickedBtnIdx) {
684+
switch (clickedBtnIdx) {
685+
case 0:
686+
// cancel - do nothing
687+
return;
688+
case 1:
689+
// don't save
690+
that.clearBoard();
691+
break;
692+
case 2:
693+
// save
694+
that.saveAsNote(function() {
695+
that.clearBoard();
696+
});
697+
break;
698+
}
699+
}
700+
});
701+
702+
return;
703+
}
704+
705+
this.clearBoard();
706+
}
628707
clearBoard() {
629708
// TODO: alert before clearing
630709
let that = this;

0 commit comments

Comments
 (0)