diff options
| author | chm@openerp.com <> | 2014-03-31 14:09:06 +0200 |
|---|---|---|
| committer | chm@openerp.com <> | 2014-03-31 14:09:06 +0200 |
| commit | 655142b04b32d48d29540552a7ebd9f20ef38856 (patch) | |
| tree | 34945aa2cda1c6b35fd71ab2f16c840f817c4b41 /addons/website/static/src/js/website.editor.js | |
| parent | 1c4b7e9f6fe774b669c47292e8d2e50538990bc1 (diff) | |
[IMP] website: media editor: add search result for images
bzr revid: chm@openerp.com-20140331120906-0qqa40xbvek27z4j
Diffstat (limited to 'addons/website/static/src/js/website.editor.js')
| -rw-r--r-- | addons/website/static/src/js/website.editor.js | 25 |
1 files changed, 19 insertions, 6 deletions
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]; |
