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
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

3.2.3 (Unreleased)
--------------------
- Fix #400: Fixed missing `not saved` warning

3.2.2 (July 9, 2024)
--------------------
- Enh #382: Implement provider for meta searching
Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"version": "3.2.2",
"humhub": {
"minVersion": "1.16"
"minVersion": "1.16.2"
},
"homepage": "https://github.com/humhub/mail",
"authors": [
Expand Down
13 changes: 13 additions & 0 deletions resources/js/humhub.mail.ConversationView.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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 client.confirmUnload(module.text('warn.onBeforeUnload'));
}

return true;
};

ConversationView.prototype.loader = function (load) {
if (load !== false) {
loader.set(this.$);
Expand Down Expand Up @@ -172,6 +181,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
19 changes: 16 additions & 3 deletions resources/js/humhub.mail.messenger.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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 client.confirmUnload(module.text('warn.onBeforeUnload'));
}

return true;
};

ConversationView.prototype.loader = function (load) {
if (load !== false) {
loader.set(this.$);
Expand Down Expand Up @@ -172,6 +181,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 +428,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 +452,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 +716,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