[REV] tabification of link and image dialogs

bzr revid: xmo@openerp.com-20130913084013-19zu9k9voxplwwhp
This commit is contained in:
Xavier Morel 2013-09-13 10:40:13 +02:00
parent 410e562893
commit a793a8ff16
4 changed files with 95 additions and 120 deletions

View File

@ -83,10 +83,6 @@
}
/* ---- EDITOR BAR ---- */
.modal .tab-content {
padding-top: 5px;
}
table.editorbar-panel {
cursor: pointer;
width: 100%;
@ -95,10 +91,6 @@ table.editorbar-panel td.selected {
background-color: #b1c9d9;
}
.modal .image-preview-container, .modal .image-preview {
margin-bottom: 0.5em;
}
/* ---- RTE ---- */
.oe_editable .btn {
-webkit-user-select: auto;

View File

@ -74,18 +74,12 @@
/* ---- EDITOR BAR ---- */
.modal .tab-content
padding-top: 5px
table.editorbar-panel
cursor: pointer
width: 100%
td.selected
background-color: #b1c9d9
.modal .image-preview-container, .modal .image-preview
margin-bottom: 0.5em
/* ---- RTE ---- */
// bootstrap makes .btn elements unselectable -> RTE double-click can't know

View File

@ -399,11 +399,15 @@
website.editor.LinkDialog = website.editor.Dialog.extend({
template: 'website.editor.dialog.link',
events: _.extend({}, website.editor.Dialog.prototype.events, {
'change .url-source': function (e) { this.changed($(e.target)); },
'click div.existing a': 'select_page',
}),
init: function (editor) {
this._super(editor);
// url -> name mapping for existing pages
this.pages = Object.create(null);
// name -> url mapping for the same
this.pages_by_name = Object.create(null);
},
start: function () {
var element;
@ -462,24 +466,24 @@
},
save: function () {
var self = this, _super = this._super.bind(this);
var $active_tab = this.$('.tab-pane.active');
var $e = $active_tab.find('.url-source');
var $e = this.$('.url-source').filter(function () { return !!this.value; });
var val = $e.val(), done = $.when();
if ($active_tab.is('#link-email')) {
if ($e.hasClass('email-address')) {
this.make_link('mailto:' + val, false, val);
} else if ($active_tab.is('#link-existing')) {
self.make_link(val, false, this.pages[val]);
} else if ($active_tab.is('#link-new')) {
// Create the page, get the URL back
done = $.get(_.str.sprintf(
'/pagenew/%s?noredirect', encodeURIComponent(val)))
.then(function (response) {
val = response;
});
} else if ($e.hasClass('pages')) {
// ``val`` is the *name* of the page
var url = this.pages_by_name[val];
if (!url) {
// Create the page, get the URL back
done = $.get(_.str.sprintf(
'/pagenew/%s?noredirect', encodeURIComponent(val)))
.then(function (response) {
url = response;
});
}
done.then(function () {
self.make_link(val, false);
self.make_link(url, false, val);
});
} else {
this.make_link(val, this.$('input.window-new').prop('checked'));
@ -493,19 +497,36 @@
var match, $control;
if (match = /(mailto):(.+)/.exec(href)) {
$control = this.$('#link-email input').val(match[2]);
$control = this.$('input.email-address').val(match[2]);
} else if(href in this.pages) {
$control = this.$('#link-existing select').val(href);
} else {
$control = this.$('#link-external input:first').val(href);
$control = this.$('input.pages').val(this.pages[href]);
}
if (!$control) {
$control = this.$('input.url').val(href);
}
var tab_name = $control.closest('.tab-pane').attr('id');
this.$('.nav a[href="#' + tab_name + '"]').tab('show');
this.changed($control);
this.$('input.window-new').prop(
'checked', this.element.getAttribute('target') === '_blank');
},
changed: function ($e) {
$e.closest('li.list-group-item').addClass('active')
.siblings().removeClass('active');
this.$('.url-source').not($e).val('');
},
/**
* Selected an existing page in dropdown
*/
select_page: function (e) {
e.preventDefault();
e.stopPropagation();
var $target = $(e.target);
this.$('input.pages').val($target.text()).change();
// No #dropdown('close'), and using #dropdown('toggle') sur
// #closest('.dropdown') makes the dropdown not work correctly
$target.closest('.open').removeClass('open');
},
/**
* CKEDITOR.plugins.link.getSelectedLink ignores the editor's root,
* if the editor is set directly on a link it will thus not work.
@ -535,43 +556,32 @@
},
fill_pages: function (results) {
var self = this;
var pages = this.$('#link-existing-select')[0];
var $pages = this.$('div.existing ul').empty();
_(results).each(function (result) {
self.pages[result.url] = result.name;
pages.options[pages.options.length] =
new Option(result.name, result.url);
self.pages_by_name[result.name] = result.url;
var $link = $('<a>').attr('href', result.url).text(result.name);
$('<li>').append($link).appendTo($pages);
});
},
});
website.editor.ImageDialog = website.editor.Dialog.extend({
template: 'website.editor.dialog.image',
events: _.extend({}, website.editor.Dialog.prototype.events, {
'change .url-source': function (e) { this.changed($(e.target)); },
'click button.filepicker': function () {
this.$('input[type=file]').click();
},
'change input[type=file]': 'file_selection',
'change input.url': 'preview_image',
'change select.image-style': 'preview_image',
'click .existing-attachments a': 'select_existing',
}),
start: function () {
var selection = this.editor.getSelection();
var el = selection && selection.getSelectedElement();
this.element = null;
var $select = this.$('.image-style');
var $options = $select.children();
this.image_styles = $options.map(function () { return this.value; }).get();
if (el && el.is('img')) {
this.element = el;
_(this.image_styles).each(function (style) {
if (el.hasClass(style)) {
$select.val(style);
}
});
// set_image should follow setup of image style
this.set_image(el.getAttribute('src'));
}
@ -581,7 +591,6 @@
},
save: function () {
var url = this.$('input.url').val();
var style = this.$('.image-style').val();
var element, editor = this.editor;
if (!(element = this.element)) {
element = editor.document.createElement('img');
@ -595,10 +604,7 @@
}, 0);
}
element.setAttribute('src', url);
$(element.$).removeClass(this.image_styles.join(' '));
if (style) { element.addClass(style); }
return this._super();
this._super();
},
/**
@ -636,10 +642,7 @@
var image = this.$('input.url').val();
if (!image) { return; }
this.$('img.image-preview')
.attr('src', image)
.removeClass(this.image_styles.join(' '))
.addClass(this.$('select.image-style').val());
this.$('img.image-preview').attr('src', image);
},
fetch_existing: function () {

View File

@ -35,87 +35,73 @@
<t t-call="website.editor.dialog">
<t t-set="title">Link to</t>
<form>
<ul class="nav nav-pills nav-justified">
<li class="active">
<a href="#link-existing" data-toggle="pill">Your website</a>
<ul class="list-group form-group">
<li class="list-group-item active">
<h3 class="list-group-item-heading">Page on your website</h3>
<div class="input-group">
<input type="text" class="form-control pages url-source"
placeholder="Create new page"/>
<div class="input-group-btn existing dropdown">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">Existing page <span class="caret"></span></button>
<ul class="dropdown-menu pull-right"/>
</div>
</div>
</li>
<li><a href="#link-new" data-toggle="pill">New page</a></li>
<li><a href="#link-external" data-toggle="pill">External Page</a></li>
<li><a href="#link-email" data-toggle="pill">Email Address</a></li>
</ul>
<div class="tab-content">
<div id="link-existing" class="tab-pane active form-group">
<select id="link-existing-select"
class="form-control url-source">
<option disabled="disabled">Select existing page:</option>
</select>
</div>
<div id="link-new" class="tab-pane form-group">
<input type="text" class="form-control pages url-source"
placeholder="Enter the name of the new page"/>
</div>
<div id="link-external" class="tab-pane">
<input type="text" class="form-control url url-source"
placeholder="example: http://openerp.com"/>
<li class="list-group-item">
<div class="pull-right">
<label>
<input type="checkbox" class="window-new"/>
Open in new window
</label>
</div>
</div>
<div id="link-email" class="tab-pane">
<h3 class="list-group-item-heading">External Page</h3>
<input type="text" class="form-control url url-source"
placeholder="http://openerp.com"/>
</li>
<li class="list-group-item">
<h3 class="list-group-item-heading">Email Address</h3>
<input type="email" class="form-control email-address url-source"
placeholder="example: you@yourwebsite.com"/>
</div>
</div>
placeholder="you@yourwebsite.com"/>
</li>
</ul>
</form>
</t>
</t>
<t t-name="website.editor.dialog.image">
<t t-call="website.editor.dialog">
<t t-set="title">Image:</t>
<div>
<div class="image-preview-container">
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAC0lEQVQIHWP4zwAAAgEBAMVfG14AAAAASUVORK5CYII%3D"
class="pull-right img-rounded image-preview"
width="100%"/>
<select class="form-control image-style">
<option value="">No styling</option>
<option value="img-rounded">Rounded corners</option>
<option value="img-thumbnail">Box</option>
<option value="img-circle">Circle</option>
</select>
</div>
<div class="row">
<form method="POST" action="/website/attach"
enctype="multipart/form-data"
target="fileframe">
<ul class="nav nav-pills nav-justified">
<li class="active"><a href="#image-upload" data-toggle="pill">
Upload
</a></li>
<li><a href="#image-existing" data-toggle="pill">Your images</a></li>
<li><a href="#image-external" data-toggle="pill">External Image</a></li>
</ul>
<div class="tab-content">
<div id="image-upload" class="tab-pane active form-group text-center">
<input type="file" name="upload" style="position: absolute; opacity: 0; width: 1px; height: 1px;"/>
<button type="button" class="btn btn-primary btn-lg filepicker">
Upload an image from your computer
</button>
</div>
<div id="image-existing" class="tab-pane well">
<div class="existing-attachments"/>
</div>
<div id="image-external" class="tab-pane well form-group">
<input type="text" class="form-control url"
placeholder="e.g. http://goo.gl/EDC325"/>
</div>
target="fileframe"
class="col-sm-8">
<div class="well">
<!-- a href="#" class="pull-left">Find image</a -->
<h3 class="list-group-item-heading">Image URL</h3>
<input type="text" class="form-control url"
placeholder="http://openerp.com"/>
</div>
<div class="text-center">
<p class="">— or —</p>
<input type="file" name="upload" style="position: absolute; opacity: 0; width: 1px; height: 1px;"/>
<button type="button" class="btn btn-primary btn-lg filepicker">
Upload an image from your computer
</button>
</div>
<p class="text-center">— or —</p>
<div class="well">
<h3 class="list-group-item-heading">Pick an existing attachment</h3>
<div class="existing-attachments"/>
</div>
<input type="hidden" name="func"/>
</form>
<iframe src="about:blank" name="fileframe" class="hidden"/>
<div class="col-sm-4">
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAC0lEQVQIHWP4zwAAAgEBAMVfG14AAAAASUVORK5CYII%3D"
class="pull-right img-rounded image-preview"
width="100%"/>
</div>
</div>
<iframe src="about:blank" name="fileframe" class="hidden"/>
</t>
</t>
<t t-name="website.editor.dialog.image.existing">