Skip to content

Commit 2e8c60d

Browse files
committed
Add save button, remove autosave, check saved when click close button
1 parent a221796 commit 2e8c60d

File tree

13 files changed

+230
-155
lines changed

13 files changed

+230
-155
lines changed

js/mindmap.js

+27-9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ var FilesMindMap = {
66
this.registerFileActions();
77
},
88

9+
showMessage: function(msg, delay, t) {
10+
var self = this;
11+
delay = delay || 3000;
12+
var id = OC.Notification.show(msg, t);
13+
setTimeout(function(){
14+
self.hideMessage(id);
15+
}, delay);
16+
return id;
17+
},
18+
19+
hideMessage: function(id, t) {
20+
OC.Notification.hide(id, t);
21+
},
22+
923
hide: function() {
1024
$('#mmframe').remove();
1125
if ($('#isPublic').val() && $('#filesApp').val()){
@@ -37,7 +51,9 @@ var FilesMindMap = {
3751
var $iframe;
3852
var shown = true;
3953
var viewer = OC.generateUrl('/apps/files_mindmap/');
40-
$iframe = $('<iframe id="mmframe" style="width:100%;height:100%;display:block;position:absolute;top:0;z-index:1041;" src="'+viewer+'" sandbox="allow-scripts allow-same-origin allow-popups allow-modals allow-top-navigation" allowfullscreen="true"/>');
54+
$iframe = $('<iframe id="mmframe" style="width:100%;height:100%;display:block;position:absolute;top:0;' +
55+
'z-index:1041;" src="'+viewer+'" sandbox="allow-scripts allow-same-origin allow-popups allow-modals ' +
56+
'allow-top-navigation" allowfullscreen="true"/>');
4157

4258
if (!$('#mimetype').val()) {
4359
FileList.setViewerMode(true);
@@ -67,16 +83,16 @@ var FilesMindMap = {
6783
OC.Apps.hideAppSidebar();
6884

6985
iframe.save = function() {
70-
alert('save');
86+
window.alert('save');
7187
};
7288

73-
iframe.find('#close-button').click(function() {
74-
self.hide();
75-
});
89+
// iframe.find('#close-button').click(function() {
90+
// self.hide();
91+
// });
7692

7793
// Go back on ESC
7894
$(document).keyup(function(e) {
79-
if (shown && e.keyCode == 27) {
95+
if (shown && e.keyCode === 27) {
8096
shown = false;
8197
self.hide();
8298
}
@@ -88,7 +104,7 @@ var FilesMindMap = {
88104
}
89105

90106
if(!$('html').hasClass('ie8')) {
91-
$(window).one('popstate', function (e) {
107+
$(window).one('popstate', function () {
92108
self.hide();
93109
});
94110
}
@@ -141,10 +157,12 @@ var FilesMindMap = {
141157
url = OC.generateUrl('/apps/files_mindmap/public/{token}', {token: sharingToken});
142158
} else if ($('#isPublic').val()) {
143159
sharingToken = $('#sharingToken').val();
144-
url = OC.generateUrl('/apps/files_mindmap/public/{token}?dir={dir}&filename={filename}', { token: sharingToken, filename: filename, dir: dir})
160+
url = OC.generateUrl('/apps/files_mindmap/public/{token}?dir={dir}&filename={filename}',
161+
{ token: sharingToken, filename: filename, dir: dir});
145162
//url = this._currentContext.fileList.getDownloadUrl(filename, dir);
146163
} else {
147-
url = OC.generateUrl('/apps/files_mindmap/ajax/loadfile?filename={filename}&dir={dir}', {filename: filename, dir: dir});
164+
url = OC.generateUrl('/apps/files_mindmap/ajax/loadfile?filename={filename}&dir={dir}',
165+
{filename: filename, dir: dir});
148166
}
149167
$.get(url).done(function(data) {
150168
OCA.FilesMindMap._file.writeable = data.writeable;

js/viewer.js

+46-25
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ redirectIfNotDisplayedInFrame();
3838
self.initHotkey();
3939
self.bindEvent();
4040
self.loadData();
41-
self.startSaveTimer();
42-
minder.on('contentchange', function(e) {
41+
//self.startSaveTimer();
42+
minder.on('contentchange', function() {
4343
self._changed = true;
4444
});
4545
};
@@ -54,7 +54,7 @@ redirectIfNotDisplayedInFrame();
5454
initHotkey: function() {
5555
var self = this;
5656
$(document).keydown(function(e) {
57-
if((e.ctrlKey || e.metaKey) && e.which == 83){
57+
if((e.ctrlKey || e.metaKey) && e.which === 83){
5858
self.save();
5959
e.preventDefault();
6060
return false;
@@ -78,44 +78,64 @@ redirectIfNotDisplayedInFrame();
7878
$('#export-text').click(function(){
7979
self.exportText();
8080
});
81-
},
82-
startSaveTimer: function() {
83-
var self = this;
84-
self.stopSaveTimer();
85-
self._saveTimer = setInterval(function(){
81+
$('#save-button').click(function() {
8682
self.save();
87-
}, 10000);
83+
});
84+
$('#close-button').click(function() {
85+
self.close();
86+
return false;
87+
});
8888
},
89-
stopSaveTimer: function() {
89+
close: function() {
9090
var self = this;
91-
if (self._saveTimer != null) {
92-
clearInterval(self._saveTimer);
91+
if (this._changed) {
92+
window.parent.OC.dialogs.confirm(t('The file has not been saved. Is it saved?'),
93+
t('Unsaved file'), function(result){
94+
if (result) {
95+
self.save(function(){
96+
window.parent.OCA.FilesMindMap.hide();
97+
});
98+
} else {
99+
window.parent.OCA.FilesMindMap.hide();
100+
}
101+
},true);
102+
} else {
103+
window.parent.OCA.FilesMindMap.hide();
93104
}
94105
},
95-
setStatusMessage: function(msg) {
96-
$('#status-message').html(msg);
97-
this.clearStatusMessage();
106+
showMessage: function(msg, delay) {
107+
return window.parent.OCA.FilesMindMap.showMessage(msg, delay);
108+
},
109+
hideMessage: function(id) {
110+
return window.parent.OCA.FilesMindMap.hideMessage(id);
98111
},
99-
clearStatusMessage: function() {
112+
setStatusMessage: function(msg) {
100113
var self = this;
101-
if (self._clearStatusMessageTimer != null) {
102-
clearTimeout(self._clearStatusMessageTimer);
114+
if (this._clearStatusMessageTimer !== null) {
115+
this.hideMessage(this._clearStatusMessageTimer);
103116
}
104-
self._clearStatusMessageTimer = setTimeout(function(){
105-
$('#status-message').html('');
117+
this._clearStatusMessageTimer = this.showMessage(msg);
118+
setTimeout(function(){
119+
self.hideMessage(self._clearStatusMessageTimer);
106120
self._clearStatusMessageTimer = null;
107121
}, 3000);
108122
},
109-
save: function() {
123+
save: function(callback) {
110124
var self = this;
111125
if (self._changed) {
112126
self.setStatusMessage(t('Saving...'));
113127
var data = JSON.stringify(minder.exportJson());
114128
window.parent.OCA.FilesMindMap.save(data, function(msg){
115129
self.setStatusMessage(msg);
116130
self._changed = false;
131+
if (undefined !== callback) {
132+
callback(true, msg);
133+
}
117134
}, function(msg){
118135
self.setStatusMessage(msg);
136+
if (undefined !== callback) {
137+
callback(false, msg);
138+
}
119139
});
120140
}
121141
},
@@ -140,7 +160,8 @@ redirectIfNotDisplayedInFrame();
140160
try {
141161
obj = JSON.parse(data);
142162
} catch (e){
143-
alert(t('This file is not a valid mind map file and may cause file corruption if you continue editing.'));
163+
window.alert(t('This file is not a valid mind map file and may cause file ' +
164+
'corruption if you continue editing.'));
144165
}
145166
}
146167
minder.importJson(obj);
@@ -152,7 +173,7 @@ redirectIfNotDisplayedInFrame();
152173
self._changed = false;
153174
}, function(msg){
154175
self._loadStatus = false;
155-
alert(t('Load file fail!') + msg);
176+
window.alert(t('Load file fail!') + msg);
156177
window.parent.OCA.FilesMindMap.hide();
157178
});
158179
},
@@ -172,7 +193,7 @@ redirectIfNotDisplayedInFrame();
172193
obj.dataset.downloadurl = url;
173194
document.body.appendChild(obj);
174195
obj.click();
175-
document.body.removeChild(obj)
196+
document.body.removeChild(obj);
176197
},
177198

178199
exportPNG: function () {
@@ -230,4 +251,4 @@ redirectIfNotDisplayedInFrame();
230251
window.MindMap = MindMap;
231252
})();
232253

233-
MindMap.init();
254+
window.MindMap.init();

l10n/de.js

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
OC.L10N.register(
2-
"files_mindmap",
3-
{
2+
"files_mindmap", {
43
"New mind map file": "Neue Mindmap-Datei",
54
"New mind map.km": "Neue Mindmap.km",
65
"Main Topic": "Zentrales Thema",
@@ -12,14 +11,17 @@ OC.L10N.register(
1211
"Export": "Export",
1312
"Export to PNG": "Export nach PNG",
1413
"Export to SVG": "Export nach SVG",
15-
"You are not permission to write this file":"You are not permission to write this file",
16-
"File not found":"File not found",
17-
"The file is locked.":"The file is locked.",
18-
"Share not found":"Share not found",
19-
"You are not authorized to open this share":"You are not authorized to open this share",
20-
"Could not write to file.":"Could not write to file.",
21-
"Export to Markdown":"Export to Markdown",
22-
"Export to Text":"Export to Text",
23-
"Export to PDF":"Export to PDF"
24-
},"nplurals=1; plural=0;"
14+
"You are not permission to write this file": "You are not permission to write this file",
15+
"File not found": "File not found",
16+
"The file is locked.": "The file is locked.",
17+
"Share not found": "Share not found",
18+
"You are not authorized to open this share": "You are not authorized to open this share",
19+
"Could not write to file.": "Could not write to file.",
20+
"Export to Markdown": "Export to Markdown",
21+
"Export to Text": "Export to Text",
22+
"Export to PDF": "Export to PDF",
23+
"Save": "Save",
24+
"The file has not been saved. Is it saved?": "The file has not been saved. Is it saved?",
25+
"Unsaved file": "Unsaved file"
26+
}, "nplurals=1; plural=0;"
2527
);

l10n/de.json

+14-10
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@
1111
"Export": "Export",
1212
"Export to PNG": "Export nach PNG",
1313
"Export to SVG": "Export nach SVG",
14-
"You are not permission to write this file":"You are not permission to write this file",
15-
"File not found":"File not found",
16-
"The file is locked.":"The file is locked.",
17-
"Share not found":"Share not found",
18-
"You are not authorized to open this share":"You are not authorized to open this share",
19-
"Could not write to file.":"Could not write to file.",
20-
"Export to Markdown":"Export to Markdown",
21-
"Export to Text":"Export to Text",
22-
"Export to PDF":"Export to PDF"
23-
},"pluralForm" :"nplurals=1; plural=0;"
14+
"You are not permission to write this file": "You are not permission to write this file",
15+
"File not found": "File not found",
16+
"The file is locked.": "The file is locked.",
17+
"Share not found": "Share not found",
18+
"You are not authorized to open this share": "You are not authorized to open this share",
19+
"Could not write to file.": "Could not write to file.",
20+
"Export to Markdown": "Export to Markdown",
21+
"Export to Text": "Export to Text",
22+
"Export to PDF": "Export to PDF",
23+
"Save": "Save",
24+
"The file has not been saved. Is it saved?": "The file has not been saved. Is it saved?",
25+
"Unsaved file": "Unsaved file"
26+
},
27+
"pluralForm": "nplurals=1; plural=0;"
2428
}

l10n/fr.js

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
OC.L10N.register(
2-
"files_mindmap",
3-
{
2+
"files_mindmap", {
43
"New mind map file": "Nouvelle mindmap",
54
"New mind map.km": "Nouvelle Mindmap.km",
65
"Main Topic": "Sujet principal",
@@ -12,14 +11,17 @@ OC.L10N.register(
1211
"Export": "Exporter",
1312
"Export to PNG": "Exporter en PNG",
1413
"Export to SVG": "Exporter en SVG",
15-
"You are not permission to write this file":"You are not permission to write this file",
16-
"File not found":"File not found",
17-
"The file is locked.":"The file is locked.",
18-
"Share not found":"Share not found",
19-
"You are not authorized to open this share":"You are not authorized to open this share",
20-
"Could not write to file.":"Could not write to file.",
21-
"Export to Markdown":"Export to Markdown",
22-
"Export to Text":"Export to Text",
23-
"Export to PDF":"Export to PDF"
24-
},"nplurals=1; plural=0;"
14+
"You are not permission to write this file": "You are not permission to write this file",
15+
"File not found": "File not found",
16+
"The file is locked.": "The file is locked.",
17+
"Share not found": "Share not found",
18+
"You are not authorized to open this share": "You are not authorized to open this share",
19+
"Could not write to file.": "Could not write to file.",
20+
"Export to Markdown": "Export to Markdown",
21+
"Export to Text": "Export to Text",
22+
"Export to PDF": "Export to PDF",
23+
"Save": "Save",
24+
"The file has not been saved. Is it saved?": "The file has not been saved. Is it saved?",
25+
"Unsaved file": "Unsaved file"
26+
}, "nplurals=1; plural=0;"
2527
);

l10n/fr.json

+26-22
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
{
2-
"translations": {
3-
"New mind map file": "Nouvelle mindmap",
4-
"New mind map.km": "Nouvelle Mindmap.km",
5-
"Main Topic": "Sujet principal",
6-
"Saving...": "Sauvegarde ...",
7-
"This file is not a valid mind map file and may cause file corruption if you continue editing.": "Ce fichier n'est pas une carte valide, vous pourriez l'endommager en continuant.",
8-
"Load file fail!": "Chargement du fichier échoué",
9-
"File Saved": "Fichier Sauvegardé",
10-
"Save failed": "Sauvegarde échouée",
11-
"Export": "Exporter",
12-
"Export to PNG": "Exporter en PNG",
13-
"Export to SVG": "Exporter en SVG",
14-
"You are not permission to write this file":"You are not permission to write this file",
15-
"File not found":"File not found",
16-
"The file is locked.":"The file is locked.",
17-
"Share not found":"Share not found",
18-
"You are not authorized to open this share":"You are not authorized to open this share",
19-
"Could not write to file.":"Could not write to file.",
20-
"Export to Markdown":"Export to Markdown",
21-
"Export to Text":"Export to Text",
22-
"Export to PDF":"Export to PDF"
23-
},"nplurals=1; plural=0;"
2+
"translations": {
3+
"New mind map file": "Nouvelle mindmap",
4+
"New mind map.km": "Nouvelle Mindmap.km",
5+
"Main Topic": "Sujet principal",
6+
"Saving...": "Sauvegarde ...",
7+
"This file is not a valid mind map file and may cause file corruption if you continue editing.": "Ce fichier n'est pas une carte valide, vous pourriez l'endommager en continuant.",
8+
"Load file fail!": "Chargement du fichier échoué",
9+
"File Saved": "Fichier Sauvegardé",
10+
"Save failed": "Sauvegarde échouée",
11+
"Export": "Exporter",
12+
"Export to PNG": "Exporter en PNG",
13+
"Export to SVG": "Exporter en SVG",
14+
"You are not permission to write this file": "You are not permission to write this file",
15+
"File not found": "File not found",
16+
"The file is locked.": "The file is locked.",
17+
"Share not found": "Share not found",
18+
"You are not authorized to open this share": "You are not authorized to open this share",
19+
"Could not write to file.": "Could not write to file.",
20+
"Export to Markdown": "Export to Markdown",
21+
"Export to Text": "Export to Text",
22+
"Export to PDF": "Export to PDF",
23+
"Save": "Save",
24+
"The file has not been saved. Is it saved?": "The file has not been saved. Is it saved?",
25+
"Unsaved file": "Unsaved file"
26+
},
27+
"nplurals=1; plural=0;"
2428
}

0 commit comments

Comments
 (0)