Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v.17] Fix missing not saved warning #400

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Changelog
- Fix #389: Fix notification about participant joining
- Fix #396: Don't override global styles
- Enh #397: Use PHP CS Fixer
- Fix #400: Fixed missing `not saved` warning

3.2.1 (April 15, 2024)
----------------------
Expand Down
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
2 changes: 1 addition & 1 deletion resources/js/humhub.mail.messenger.bundle.min.js

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions widgets/ConversationView.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace humhub\modules\mail\widgets;

use Yii;
use humhub\widgets\JsWidget;
use humhub\modules\mail\helpers\Url;

Expand All @@ -33,6 +34,19 @@ class ConversationView extends JsWidget
*/
public $messageId;

public function init()
{
parent::init();

$this->view->registerJsConfig([
'mail.ConversationView' => [
'text' => [
'warn.onBeforeUnload' => Yii::t('base', 'Unsaved changes will be lost. Do you want to proceed?'),
gevorgmansuryan marked this conversation as resolved.
Show resolved Hide resolved
],
],
]);
}

public function getData()
{
return [
Expand Down
Loading