1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
odoo.define('wysiwyg.widgets.Dialog', function (require) {
'use strict';
var config = require('web.config');
var core = require('web.core');
var Dialog = require('web.Dialog');
var _t = core._t;
/**
* Extend Dialog class to handle save/cancel of edition components.
*/
var SummernoteDialog = Dialog.extend({
/**
* @constructor
*/
init: function (parent, options) {
this.options = options || {};
if (config.device.isMobile) {
options.fullscreen = true;
}
this._super(parent, _.extend({}, {
buttons: [{
text: this.options.save_text || _t("Save"),
classes: 'btn-primary',
click: this.save,
},
{
text: _t("Discard"),
close: true,
}
]
}, this.options));
this.destroyAction = 'cancel';
var self = this;
this.opened(function () {
self.$('input:visible:first').focus();
self.$el.closest('.modal').addClass('o_web_editor_dialog');
self.$el.closest('.modal').on('hidden.bs.modal', self.options.onClose);
});
this.on('closed', this, function () {
self._toggleFullScreen();
this.trigger(this.destroyAction, this.final_data || null);
});
},
/**
* Only use on config.device.isMobile, it's used by mass mailing to allow the dialog opening on fullscreen
* @private
*/
_toggleFullScreen: function() {
if (config.device.isMobile && !this.hasFullScreen) {
$('#iframe_target[isMobile="true"] #web_editor-top-edit .o_fullscreen').click();
}
},
//--------------------------------------------------------------------------
// Public
//--------------------------------------------------------------------------
/**
* Called when the dialog is saved. Set the destroy action type to "save"
* and should set the final_data variable correctly before closing.
*/
save: function () {
this.destroyAction = "save";
this.close();
},
/**
* @override
* @returns {*}
*/
open: function() {
this.hasFullScreen = $(window.top.document.body).hasClass('o_field_widgetTextHtml_fullscreen');
this._toggleFullScreen();
return this._super.apply(this, arguments);
},
});
return SummernoteDialog;
});
|