summaryrefslogtreecommitdiff
path: root/addons/website/static/src
diff options
context:
space:
mode:
authorFabien Meghazi <fme@openerp.com>2013-11-13 18:14:38 +0100
committerFabien Meghazi <fme@openerp.com>2013-11-13 18:14:38 +0100
commit7598bcdb98795d7e95a6a7b3eacdf018766f1328 (patch)
tree2e18cfd788a9ed9e679a0dabf26edcb70908c3e1 /addons/website/static/src
parent70d9e5a8aa00014840de5493cbeb22389cbcf7e9 (diff)
[ADD] Content menu links splitted per modules
TODO: website.prompt() should be finished for Add a blog post link Added @id=editable_scripts_hook in layout template so modules can easly add *.editor.js files bzr revid: fme@openerp.com-20131113171438-3l0wo08ta5vsulq3
Diffstat (limited to 'addons/website/static/src')
-rw-r--r--addons/website/static/src/js/website.editor.js17
-rw-r--r--addons/website/static/src/js/website.js36
-rw-r--r--addons/website/static/src/xml/website.xml35
3 files changed, 82 insertions, 6 deletions
diff --git a/addons/website/static/src/js/website.editor.js b/addons/website/static/src/js/website.editor.js
index 5915ee5b359..a617f712976 100644
--- a/addons/website/static/src/js/website.editor.js
+++ b/addons/website/static/src/js/website.editor.js
@@ -12,6 +12,16 @@
website.ready().then(website.init_editor);
}
+ $(document).on('click', 'a.js_link2post', function (ev) {
+ ev.preventDefault();
+ var form = document.createElement('form');
+ form.action = this.pathname; // restrict to same origin
+ form.method = 'POST';
+ // TODO: support this.search as form input fields
+ $(this).append(form);
+ form.submit();
+ });
+
$(document).on('hide.bs.dropdown', '.dropdown', function (ev) {
// Prevent dropdown closing when a contenteditable children is focused
if (ev.originalEvent
@@ -383,6 +393,7 @@
'click button[data-action=edit]': 'edit',
'click button[data-action=save]': 'save',
'click button[data-action=cancel]': 'cancel',
+ 'click a[data-action=new_page]': 'new_page',
},
container: 'body',
customize_setup: function() {
@@ -531,6 +542,12 @@
cancel: function () {
website.reload();
},
+ new_page: function (ev) {
+ ev.preventDefault();
+ website.prompt('Create a new page', 'Page name').then(function (val) {
+ document.location = '/pagenew/' + encodeURI(val);
+ });
+ },
});
var blocks_selector = _.keys(CKEDITOR.dtd.$block).join(',');
diff --git a/addons/website/static/src/js/website.js b/addons/website/static/src/js/website.js
index 0d166b9b549..6919af78b42 100644
--- a/addons/website/static/src/js/website.js
+++ b/addons/website/static/src/js/website.js
@@ -132,6 +132,42 @@
$error.modal('show');
};
+ website.prompt = function (window_title, field_name, field_type, on_init) {
+ // A bootstraped version of javascript prompt albeit asynchronous
+ // Built to handle only one field, for anything more complex, use editor.Dialog class
+ // TODO: use option dict for parameters
+ field_type = field_type || 'input';
+ on_init = on_init || function() {};
+ var def = $.Deferred();
+ var dialog = $(openerp.qweb.render('website.prompt', {
+ field_type: field_type,
+ field_name: field_name,
+ window_title: window_title,
+ })).appendTo("body");
+ var input = dialog.find(field_type).first();
+ var init = on_init(input);
+ $.when(init).then(function () {
+ dialog.modal('show');
+ input.focus();
+ dialog.on('click', '.btn-primary', function () {
+ def.resolve(input.val(), input);
+ dialog.remove();
+ });
+ });
+ dialog.on('hidden.bs.modal', function () {
+ def.reject();
+ dialog.remove();
+ });
+ if (input.is('input[type="text"]')) {
+ input.keypress(function (e) {
+ if (e.which == 13) {
+ dialog.find('.btn-primary').trigger('click');
+ }
+ });
+ }
+ return def;
+ };
+
dom_ready.then(function () {
/* ----- BOOTSTRAP STUFF ---- */
diff --git a/addons/website/static/src/xml/website.xml b/addons/website/static/src/xml/website.xml
index 8ce2b155d7a..e24d93bf257 100644
--- a/addons/website/static/src/xml/website.xml
+++ b/addons/website/static/src/xml/website.xml
@@ -24,14 +24,10 @@
<li><a data-action="promote-current-page" href="#"><span title="Promote page on the web">Promote</span></a></li>
<li class="dropdown js_hide_on_translate">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Content <span class="caret"></span></a>
- <ul class="dropdown-menu" role="menu">
+ <ul class="dropdown-menu oe_content_menu" role="menu">
<li><a data-action="edit-structure" href="#"><span title="Edit Top Menu">Edit Menu</span></a></li>
<li class="divider"> </li>
- <li><a href="">New Page</a></li> <!-- Todo: Implement with inheritancy in each module-->
- <li><a href="">New Blog Post</a></li>
- <li><a href="">New Event</a></li>
- <li><a href="">New Job Offer</a></li>
- <li><a href="">New Product</a></li>
+ <li><a href="#" data-action="new_page">New Page</a></li>
</ul>
</li>
<li class="dropdown js_hide_on_translate">
@@ -100,4 +96,31 @@
</div>
</div>
</t>
+
+ <t t-name="website.prompt">
+ <div class="modal" tabindex="-1" role="dialog" aria-hidden="true">
+ <div class="modal-dialog">
+ <div class="modal-content">
+ <div class="modal-header">
+ <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
+ <h3 class="modal-title"><t t-esc="window_title"/></h3>
+ </div>
+ <div class="modal-body">
+ <h4 class="list-group-item-heading">
+ <label for="page-name" class="control-label">
+ <t t-esc="field_name"/>
+ </label>
+ </h4>
+ <!-- TODO: support other types -->
+ <input type="text" class="form-control" required="required" t-att-placeholder="field_name"/>
+ </div>
+ <div class="modal-footer">
+ <button type="button" class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
+ <button type="button" class="btn btn-primary">Ok</button>
+ </div>
+ </div>
+ </div>
+ </div>
+ </t>
+
</templates>