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
82
83
84
85
86
87
88
89
90
91
92
|
odoo.define("website.ace", function (require) {
"use strict";
var AceEditor = require('web_editor.ace');
/**
* Extends the default view editor so that the URL hash is updated with view ID
*/
var WebsiteAceEditor = AceEditor.extend({
hash: '#advanced-view-editor',
//--------------------------------------------------------------------------
// Public
//--------------------------------------------------------------------------
/**
* @override
*/
do_hide: function () {
this._super.apply(this, arguments);
window.location.hash = "";
},
//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
/**
* @override
*/
_displayResource: function () {
this._super.apply(this, arguments);
this._updateHash();
},
/**
* @override
*/
_saveResources: function () {
return this._super.apply(this, arguments).then((function () {
var defs = [];
if (this.currentType === 'xml') {
// When saving a view, the view ID might change. Thus, the
// active ID in the URL will be incorrect. After the save
// reload, that URL ID won't be found and JS will crash.
// We need to find the new ID (either because the view became
// specific or because its parent was edited too and the view
// got copy/unlink).
var selectedView = _.findWhere(this.views, {id: this._getSelectedResource()});
var context;
this.trigger_up('context_get', {
callback: function (ctx) {
context = ctx;
},
});
defs.push(this._rpc({
model: 'ir.ui.view',
method: 'search_read',
fields: ['id'],
domain: [['key', '=', selectedView.key], ['website_id', '=', context.website_id]],
}).then((function (view) {
if (view[0]) {
this._updateHash(view[0].id);
}
}).bind(this)));
}
return Promise.all(defs).then((function () {
window.location.reload();
return new Promise(function () {});
}));
}).bind(this));
},
/**
* @override
*/
_resetResource: function () {
return this._super.apply(this, arguments).then((function () {
window.location.reload();
return new Promise(function () {});
}).bind(this));
},
/**
* Adds the current resource ID in the URL.
*
* @private
*/
_updateHash: function (resID) {
window.location.hash = this.hash + "?res=" + (resID || this._getSelectedResource());
},
});
return WebsiteAceEditor;
});
|