diff --git a/addons/website/static/src/js/website.editor.js b/addons/website/static/src/js/website.editor.js index fb8b5366a54..d4444eb8852 100644 --- a/addons/website/static/src/js/website.editor.js +++ b/addons/website/static/src/js/website.editor.js @@ -1385,9 +1385,14 @@ return this._super(); }, + searchTimer: null, search: function () { + var self = this; var needle = this.$("input#icon-search").val(); - this.active.search(needle || ""); + clearTimeout(this.searchTimer); + this.searchTimer = setTimeout(function () { + self.active.search(needle || ""); + },250); } }); @@ -1470,6 +1475,13 @@ this.trigger('cancel'); }, + search: function (needle) { + var self = this; + this.fetch_existing(needle).then(function () { + self.selected_existing(self.$('input.url').val()); + }); + }, + set_image: function (url, error) { var self = this; this.$('input.url').val(error ? null : url || ''); @@ -1483,7 +1495,6 @@ var $form = this.$('form[action="/website/attach"]'); if (!$form.find('input[name="upload"]').val().length) { var url = $form.find('input[name="url"]').val(); - console.log(url); if (this.selected_existing(url).size()) { event.preventDefault(); return false; @@ -1515,14 +1526,18 @@ this.set_image(url, error); }, - fetch_existing: function () { + fetch_existing: function (needle) { + var domain = [['res_model', '=', 'ir.ui.view']]; + if (needle && needle.length) { + domain.push('|', ['datas_fname', 'ilike', needle], ['name', 'ilike', needle]); + } return openerp.jsonRpc('/web/dataset/call_kw', 'call', { model: 'ir.attachment', method: 'search_read', args: [], kwargs: { fields: ['name', 'website_url'], - domain: [['res_model', '=', 'ir.ui.view']], + domain: domain, order: 'id desc', context: website.get_context(), } @@ -1552,7 +1567,6 @@ this.$('.pager') .find('li.previous').toggleClass('disabled', (from === 0)).end() .find('li.next').toggleClass('disabled', (from + per_screen >= records.length)); - }, select_existing: function (e) { var link = $(e.currentTarget).attr('src'); @@ -1835,7 +1849,6 @@ } else if (needle.indexOf("player.vimeo.") != -1 || needle.indexOf("//vimeo.") != -1) { video_type = "vimeo"; video_id = needle.match(/vimeo\.[a-z]+\/(video\/)?([^?&]+)/i)[2]; - console.log(video_id); } else if (needle.indexOf(".dailymotion.") != -1) { video_type = "dailymotion"; video_id = needle.match(/dailymotion\.[a-z]+\/(embed\/)?(video\/)?([^\/?&]+)/i)[3]; diff --git a/addons/website/static/src/js/website.snippets.editor.js b/addons/website/static/src/js/website.snippets.editor.js index eb2d2c29654..c52a7b6fb04 100644 --- a/addons/website/static/src/js/website.snippets.editor.js +++ b/addons/website/static/src/js/website.snippets.editor.js @@ -1436,16 +1436,10 @@ start: function () { var self = this; this._super(); - website.snippet.start_animation(true, this.$target); - this.$el.find(".edition").click(function (event) { - event.preventDefault(); - event.stopPropagation(); - self.element = new CKEDITOR.dom.element(self.$target[0]); - new website.editor.MediaDialog(self, self.element).appendTo(document.body); - }); this.$el.find(".clear-style").click(function (event) { self.$target.removeClass("fa-spin").attr("style", null); + self.$target.transfo({ hide: true }); }); this.$target.transfo({ @@ -1486,6 +1480,22 @@ }, }); + website.snippet.options.media = website.snippet.Option.extend({ + start: function () { + var self = this; + this._super(); + + website.snippet.start_animation(true, this.$target); + + this.$el.find(".edition").click(function (event) { + event.preventDefault(); + event.stopPropagation(); + self.element = new CKEDITOR.dom.element(self.$target[0]); + new website.editor.MediaDialog(self, self.element).appendTo(document.body); + }); + }, + }); + website.snippet.Editor = openerp.Class.extend({ init: function (BuildingBlock, dom) { diff --git a/addons/website/static/src/xml/website.editor.xml b/addons/website/static/src/xml/website.editor.xml index 89b184a2c4e..8e6f9766ecf 100644 --- a/addons/website/static/src/xml/website.editor.xml +++ b/addons/website/static/src/xml/website.editor.xml @@ -194,7 +194,7 @@