[IMP] website: media editor: add search result for images
bzr revid: chm@openerp.com-20140331120906-0qqa40xbvek27z4j
This commit is contained in:
@@ -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];
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -194,7 +194,7 @@
|
||||
<div class="col-sm-2 existing-attachment-cell"
|
||||
t-foreach="row" t-as="attachment">
|
||||
<i class="fa fa-times existing-attachment-remove" t-att-data-id="attachment.id"/>
|
||||
<img t-att-src="attachment.website_url" t-att-alt="attachment.name" class="img img-responsive"/>
|
||||
<img t-att-src="attachment.website_url" t-att-alt="attachment.name" t-att-title="attachment.name" class="img img-responsive"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user