[ADD] separate attachment dialog selector

bzr revid: xmo@openerp.com-20130913114143-v799fvf08rpiox3r
This commit is contained in:
Xavier Morel
2013-09-13 13:41:43 +02:00
parent e2676729b0
commit f16b61cbe6
4 changed files with 87 additions and 8 deletions
+20 -1
View File
@@ -1,4 +1,4 @@
@charset "utf-8";
@charset "UTF-8";
/* ---- CKEditor Minimal Reset ---- */
.navbar.navbar-inverse .cke_chrome {
border: none;
@@ -100,6 +100,25 @@ table.editorbar-panel td.selected {
user-select: auto;
}
.modal .existing-attachments a.thumbnail {
position: relative;
}
.modal .existing-attachments a.thumbnail.selected:before {
text-decoration: none;
font-size: 150%;
background-color: rgba(0, 0, 0, 0.3);
color: #21dc0f;
content: "✔";
height: 2em;
width: 2em;
text-align: center;
padding: 5px;
border-radius: 4px 0;
position: absolute;
top: 0;
left: 0;
}
/* ---- SNIPPET EDITOR ---- */
#oe_snippets {
position: fixed;
+21
View File
@@ -91,6 +91,27 @@ table.editorbar-panel
-o-user-select: auto
user-select: auto
.modal .existing-attachments a.thumbnail
position: relative
&.selected:before
text-decoration: none
font-size: 150%
background-color: rgba(0, 0, 0, 0.3)
color: #21dc0f
content: "✔"
height: 2em
width: 2em
text-align: center
padding: 5px
border-radius: 4px 0
position: absolute
top: 0
left: 0
/* ---- SNIPPET EDITOR ---- */
#oe_snippets
+37 -6
View File
@@ -589,7 +589,7 @@
},
'change input[type=file]': 'file_selection',
'change input.url': 'preview_image',
'click .existing-attachments a': 'select_existing',
'click a[href=#existing]': 'browse_existing',
}),
start: function () {
var selection = this.editor.getSelection();
@@ -600,9 +600,7 @@
this.set_image(el.getAttribute('src'));
}
return $.when(
this._super(),
this.fetch_existing().then(this.proxy('fetched_existing')));
return this._super();
},
save: function () {
var url = this.$('input.url').val();
@@ -660,6 +658,29 @@
this.$('img.image-preview').attr('src', image);
},
browse_existing: function (e) {
e.preventDefault();
new website.editor.ExistingImageDialog(this).appendTo(document.body);
},
});
website.editor.ExistingImageDialog = website.editor.Dialog.extend({
template: 'website.editor.dialog.image.existing',
events: _.extend({}, website.editor.Dialog.prototype.events, {
'click .existing-attachments a': 'select_existing',
}),
init: function (parent) {
this.image = null;
this.parent = parent;
this._super(parent.editor);
},
start: function () {
return $.when(
this._super(),
this.fetch_existing().then(this.proxy('fetched_existing')));
},
fetch_existing: function () {
// FIXME: lazy load attachments?
return openerp.jsonRpc('/web/dataset/call_kw', 'call', {
@@ -681,11 +702,21 @@
.values()
.value();
this.$('.existing-attachments').replaceWith(
openerp.qweb.render('website.editor.dialog.image.existing', {rows: rows}));
openerp.qweb.render(
'website.editor.dialog.image.existing.content', {rows: rows}));
},
select_existing: function (e) {
e.preventDefault();
this.set_image(e.currentTarget.getAttribute('href'));
this.$('a.thumbnail.selected').removeClass('selected');
$(e.currentTarget).addClass('selected');
},
save: function () {
var link = this.$('a.thumbnail.selected').attr('href');
if (link) {
this.parent.set_image(link);
}
this._super();
},
});
@@ -103,7 +103,7 @@
<p class="">— or —</p>
</div>
<div class="well">
<!-- a href="#" class="pull-left">Find image</a -->
<a href="#existing" class="pull-right">Browse your images</a>
<h3 class="list-group-item-heading">Image URL</h3>
<input type="text" class="form-control url"
placeholder="http://openerp.com"/>
@@ -120,6 +120,14 @@
</t>
</t>
<t t-name="website.editor.dialog.image.existing">
<t t-call="website.editor.dialog">
<t t-set="title">Pick an existing attachment:</t>
<div class="well">
<div class="existing-attachments"/>
</div>
</t>
</t>
<t t-name="website.editor.dialog.image.existing.content">
<div class="existing-attachments">
<div class="row" t-foreach="rows" t-as="row">
<div class="col-md-4" t-foreach="row" t-as="attachment">