summaryrefslogtreecommitdiff
path: root/addons/website/static/src/js/utils.js
diff options
context:
space:
mode:
authorAndrea Ulliana <aul@odoo.com>2019-01-03 08:40:45 +0000
committerqsm-odoo <qsm@odoo.com>2019-01-09 16:16:01 +0000
commit59cc261448b67c424051a623c5c8d76ddd20aa71 (patch)
treebd09682296a5193ab9e41a1f6d4750d76adc0aa3 /addons/website/static/src/js/utils.js
parent2ee21d9938c14a47e33b36446a03f284cfa67ffe (diff)
[IMP] website, *: allow creating anchor links
* portal, web_editor Anchor Link: - Some visual improvements of the link dialog. - New 'Page Anchor' field. - System by default: top and bottom. - Shows existing anchors. Creation of the anchor: - New option 'Anchor Name' to be able to create an anchor. task-1913458 closes odoo/odoo#29150
Diffstat (limited to 'addons/website/static/src/js/utils.js')
-rw-r--r--addons/website/static/src/js/utils.js54
1 files changed, 42 insertions, 12 deletions
diff --git a/addons/website/static/src/js/utils.js b/addons/website/static/src/js/utils.js
index 63c44f67d78..9cf511fe160 100644
--- a/addons/website/static/src/js/utils.js
+++ b/addons/website/static/src/js/utils.js
@@ -7,6 +7,26 @@ var core = require('web.core');
var qweb = core.qweb;
/**
+ * Allows to load anchors from a page.
+ *
+ * @param {string} url
+ * @returns {Deferred<string[]>}
+ */
+function loadAnchors(url) {
+ var def;
+ if (url !== window.location.pathname && url[0] !== '#') {
+ def = $.get(window.location.origin + url);
+ } else {
+ def = $.when(document.body.outerHTML);
+ }
+ return def.then(function (response) {
+ return _.map($(response).find('[id][data-anchor=true]'), function (el) {
+ return '#' + el.id;
+ });
+ });
+}
+
+/**
* Allows the given input to propose existing website URLs.
*
* @param {ServicesMixin|Widget} self - an element capable to trigger an RPC
@@ -15,19 +35,28 @@ var qweb = core.qweb;
function autocompleteWithPages(self, $input) {
$input.autocomplete({
source: function (request, response) {
- return self._rpc({
- model: 'website',
- method: 'search_pages',
- args: [null, request.term],
- kwargs: {
- limit: 15,
- },
- }).then(function (exists) {
- var rs = _.map(exists, function (r) {
- return r.loc;
+ if (request.term[0] === '#') {
+ loadAnchors(request.term).then(function (anchors) {
+ response(anchors);
});
- response(rs);
- });
+ } else {
+ return self._rpc({
+ model: 'website',
+ method: 'search_pages',
+ args: [null, request.term],
+ kwargs: {
+ limit: 15,
+ },
+ }).then(function (exists) {
+ var rs = _.map(exists, function (r) {
+ return r.loc;
+ });
+ response(rs.sort());
+ });
+ }
+ },
+ close: function () {
+ self.trigger_up('website_url_chosen');
},
});
}
@@ -137,6 +166,7 @@ function prompt(options, _qweb) {
}
return {
+ loadAnchors: loadAnchors,
autocompleteWithPages: autocompleteWithPages,
prompt: prompt,
};