Skip to content

Commit

Permalink
Missing "Not Saved" warning
Browse files Browse the repository at this point in the history
  • Loading branch information
gevorgmansuryan committed Jul 2, 2024
1 parent 3f6ea32 commit b8d5ae3
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
17 changes: 17 additions & 0 deletions resources/js/humhub.mail.ConversationView.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ humhub.module('mail.ConversationView', function (module, require, $) {
this.setActiveMessageId(Widget.instance('#inbox').getFirstMessageId());
}

window.onbeforeunload = function() {
return this.onbeforeunloadCheck();
}

this.reload();

this.$.on('mouseenter', '.mail-conversation-entry', function () {
Expand All @@ -31,6 +35,15 @@ humhub.module('mail.ConversationView', function (module, require, $) {
});
};

ConversationView.prototype.onbeforeunloadCheck = function () {
var replyRichtext = this.getReplyRichtext();
if (replyRichtext && $(replyRichtext.$[0]).closest('form').find('textarea').val().trim().length) {
return confirm(module.text('warn.onBeforeUnload'));
}

return true;
};

ConversationView.prototype.loader = function (load) {
if (load !== false) {
loader.set(this.$);
Expand Down Expand Up @@ -172,6 +185,10 @@ humhub.module('mail.ConversationView', function (module, require, $) {
};

ConversationView.prototype.loadMessage = function (evt) {
if (!this.onbeforeunloadCheck()) {
return false;
}

var messageId = object.isNumber(evt) ? evt : evt.$trigger.data('message-id');
var that = this;
this.loader();
Expand Down
23 changes: 20 additions & 3 deletions resources/js/humhub.mail.messenger.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ humhub.module('mail.ConversationView', function (module, require, $) {
this.setActiveMessageId(Widget.instance('#inbox').getFirstMessageId());
}

window.onbeforeunload = function() {
return this.onbeforeunloadCheck();
}

this.reload();

this.$.on('mouseenter', '.mail-conversation-entry', function () {
Expand All @@ -31,6 +35,15 @@ humhub.module('mail.ConversationView', function (module, require, $) {
});
};

ConversationView.prototype.onbeforeunloadCheck = function () {
var replyRichtext = this.getReplyRichtext();
if (replyRichtext && $(replyRichtext.$[0]).closest('form').find('textarea').val().trim().length) {
return confirm(module.text('warn.onBeforeUnload'));
}

return true;
};

ConversationView.prototype.loader = function (load) {
if (load !== false) {
loader.set(this.$);
Expand Down Expand Up @@ -172,6 +185,10 @@ humhub.module('mail.ConversationView', function (module, require, $) {
};

ConversationView.prototype.loadMessage = function (evt) {
if (!this.onbeforeunloadCheck()) {
return false;
}

var messageId = object.isNumber(evt) ? evt : evt.$trigger.data('message-id');
var that = this;
this.loader();
Expand Down Expand Up @@ -415,7 +432,7 @@ humhub.module('mail.ConversationView', function (module, require, $) {

module.export = ConversationView;
});


humhub.module('mail.ConversationEntry', function (module, require, $) {

var Widget = require('ui.widget').Widget;
Expand All @@ -439,7 +456,7 @@ humhub.module('mail.ConversationEntry', function (module, require, $) {
};

module.export = ConversationEntry;
});
});
humhub.module('mail.inbox', function (module, require, $) {
var Widget = require('ui.widget').Widget;
var Filter = require('ui.filter').Filter;
Expand Down Expand Up @@ -703,7 +720,7 @@ humhub.module('mail.inbox', function (module, require, $) {
toggleInbox: toggleInbox
});
});


humhub.module('mail.conversation', function (module, require, $) {
var Widget = require('ui.widget').Widget;
var modal = require('ui.modal');
Expand Down
Loading

0 comments on commit b8d5ae3

Please sign in to comment.