[WIP] unwebclientification of the Editorbar
bzr revid: fme@openerp.com-20130814171532-36trhgx2vso7yrr3
This commit is contained in:
parent
6581346ef1
commit
c94c7c4226
|
@ -15,13 +15,5 @@ OpenERP Website CMS
|
|||
'views/views.xml',
|
||||
'views/res_config.xml',
|
||||
'website_data.xml',
|
||||
],
|
||||
'js': [
|
||||
'static/lib/bootstrap/js/bootstrap.js',
|
||||
'static/src/js/website.js',
|
||||
],
|
||||
'css': [
|
||||
'static/src/css/editor.css',
|
||||
],
|
||||
'qweb': ['static/src/xml/*.xml'],
|
||||
}
|
||||
|
|
|
@ -1,20 +1,36 @@
|
|||
openerp.website = function(instance) {
|
||||
// Ugly. I'll clean this monday
|
||||
$(function () { if ($('html').attr('data-editable') !== '1') return;
|
||||
|
||||
instance.web.ActionManager.include({
|
||||
// Temporary fix until un-webclientization of the editorbar
|
||||
ir_actions_client: function (action) {
|
||||
if (instance.web.client_actions.get_object(action.tag)) {
|
||||
return this._super.apply(this, arguments);
|
||||
} else {
|
||||
console.warn("Action '%s' not found in registry", action.tag);
|
||||
return $.when();
|
||||
}
|
||||
}
|
||||
});
|
||||
// TODO fme: put everything in openerp.website scope and load templates on
|
||||
// next tick or document ready
|
||||
// Also check with xmo if jquery.keypress.js is still needed.
|
||||
|
||||
var _lt = instance.web._lt;
|
||||
var QWeb = instance.web.qweb;
|
||||
instance.website.EditorBar = instance.web.Widget.extend({
|
||||
var doc_ready = $.Deferred();
|
||||
$(doc_ready.resolve);
|
||||
|
||||
var templates = [
|
||||
'/website/static/src/xml/website.xml'
|
||||
];
|
||||
|
||||
function loadTemplates(templates) {
|
||||
var def = $.Deferred();
|
||||
var count = templates.length;
|
||||
templates.forEach(function(t) {
|
||||
openerp.qweb.add_template(t, function(err) {
|
||||
if (err) {
|
||||
def.reject();
|
||||
} else {
|
||||
count--;
|
||||
if (count < 1) {
|
||||
def.resolve();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
return def;
|
||||
}
|
||||
|
||||
var EditorBar = openerp.Widget.extend({
|
||||
template: 'Website.EditorBar',
|
||||
events: {
|
||||
'click button[data-action=edit]': 'edit',
|
||||
|
@ -23,17 +39,13 @@ instance.website.EditorBar = instance.web.Widget.extend({
|
|||
'click button[data-action=snippet]': 'snippet',
|
||||
},
|
||||
container: 'body',
|
||||
init: function () {
|
||||
this._super.apply(this, arguments);
|
||||
this.saving_mutex = new $.Mutex();
|
||||
},
|
||||
customize_setup: function() {
|
||||
var self = this;
|
||||
var view_name = $('html').data('view-xmlid');
|
||||
var menu = $('#customize-menu');
|
||||
this.$('#customize-menu-button').click(function(event) {
|
||||
menu.empty();
|
||||
self.rpc('/website/customize_template_get', { 'xml_id': view_name }).then(
|
||||
openerp.jsonRpc('/website/customize_template_get', 'call', { 'xml_id': view_name }).then(
|
||||
function(result) {
|
||||
_.each(result, function (item) {
|
||||
if (item.header) {
|
||||
|
@ -48,7 +60,7 @@ instance.website.EditorBar = instance.web.Widget.extend({
|
|||
});
|
||||
menu.on('click', 'a', function (event) {
|
||||
var view_id = $(event.target).data('view-id');
|
||||
self.rpc('/website/customize_template_toggle', {
|
||||
openerp.jsonRpc('/website/customize_template_toggle', 'call', {
|
||||
'view_id': view_id
|
||||
}).then( function(result) {
|
||||
window.location.reload();
|
||||
|
@ -58,6 +70,8 @@ instance.website.EditorBar = instance.web.Widget.extend({
|
|||
start: function() {
|
||||
var self = this;
|
||||
|
||||
this.saving_mutex = new openerp.Mutex();
|
||||
|
||||
this.$('#website-top-edit').hide();
|
||||
this.$('#website-top-view').show();
|
||||
|
||||
|
@ -73,7 +87,7 @@ instance.website.EditorBar = instance.web.Widget.extend({
|
|||
|
||||
self.snippet_start();
|
||||
|
||||
this.rte = new instance.website.RTE(this);
|
||||
this.rte = new RTE(this);
|
||||
this.rte.on('change', this, this.proxy('rte_changed'));
|
||||
|
||||
return $.when(
|
||||
|
@ -156,7 +170,11 @@ instance.website.EditorBar = instance.web.Widget.extend({
|
|||
.prop('contentEditable', false);
|
||||
html = $w.wrap('<div>').parent().html();
|
||||
}
|
||||
return (new instance.web.DataSet(this, 'ir.ui.view')).call('save', [data.oeModel, data.oeId, data.oeField, html, xpath]);
|
||||
return openerp.jsonRpc('/web/dataset/call', 'call', {
|
||||
model: 'ir.ui.view',
|
||||
method: 'save',
|
||||
args: [data.oeModel, data.oeId, data.oeField, html, xpath]
|
||||
});
|
||||
},
|
||||
cancel: function () {
|
||||
window.location.reload();
|
||||
|
@ -194,7 +212,7 @@ instance.website.EditorBar = instance.web.Widget.extend({
|
|||
},
|
||||
});
|
||||
|
||||
instance.website.RTE = instance.web.Widget.extend({
|
||||
var RTE = openerp.Widget.extend({
|
||||
tagName: 'li',
|
||||
id: 'oe_rte_toolbar',
|
||||
className: 'oe_right oe_rte_toolbar',
|
||||
|
@ -297,7 +315,12 @@ instance.website.RTE = instance.web.Widget.extend({
|
|||
}
|
||||
});
|
||||
|
||||
$(function(){
|
||||
$.when(doc_ready, loadTemplates(templates)).then(function() {
|
||||
var editor = new EditorBar();
|
||||
editor.prependTo($('body'));
|
||||
$('body').css('padding-top', '50px'); // Not working properly: editor.$el.outerHeight());
|
||||
|
||||
// TODO: Create an openerp.Widget out of this
|
||||
|
||||
function make_static(){
|
||||
$('.oe_snippet_demo').removeClass('oe_new');
|
||||
|
@ -382,6 +405,10 @@ $(function(){
|
|||
}
|
||||
});
|
||||
|
||||
});
|
||||
// }()); I'll clean this monday
|
||||
|
||||
|
||||
$(function () {
|
||||
$(document).on('click', '.js_publish, .js_unpublish', function (e) {
|
||||
e.preventDefault();
|
||||
|
@ -401,4 +428,3 @@ $(function () {
|
|||
});
|
||||
});
|
||||
|
||||
};
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
$(function() {
|
||||
// Init headless webclient
|
||||
// TODO: Webclient research : use iframe embedding mode
|
||||
// Meanwhile, let's HACK !!!
|
||||
var s = new openerp.init(['web', 'website']);
|
||||
s.web.WebClient.bind_hashchange = s.web.WebClient.show_common = s.web.blockUI = s.web.unblockUI = function() {};
|
||||
s.web.WebClient.include({ do_push_state: function() {} });
|
||||
var wc = new s.web.WebClient();
|
||||
wc.start();
|
||||
var instance = openerp.instances[wc.session.name];
|
||||
// Another hack since we have no callback when webclient has loaded modules.
|
||||
instance.web.qweb.add_template('/website/static/src/xml/website.xml');
|
||||
|
||||
$(function() {
|
||||
var editor = new instance.website.EditorBar(instance.webclient);
|
||||
editor.prependTo($('body'));
|
||||
$('body').css('padding-top', '50px'); // Not working properly: editor.$el.outerHeight());
|
||||
});
|
||||
});
|
|
@ -20,10 +20,13 @@
|
|||
|
||||
<template id="layout">
|
||||
<!DOCTYPE html>
|
||||
<html t-att-data-view-xmlid="__stack__[0]">
|
||||
<html t-att-data-view-xmlid="__stack__[0]" t-att-data-editable="'1' if editable else '0'">
|
||||
<head>
|
||||
<title><t t-esc="title or res_company.name"/></title>
|
||||
<script type="text/javascript" src="/web/static/lib/underscore/underscore.js"></script>
|
||||
<script type="text/javascript" src="/web/static/lib/underscore.string/lib/underscore.string.js"></script>
|
||||
<script type="text/javascript" src="/web/static/lib/jquery/jquery.js"></script>
|
||||
<script type="text/javascript" src="/website/static/lib/bootstrap/js/bootstrap.js"></script>
|
||||
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/ckeditor/4.2/ckeditor.js"></script>
|
||||
<script type="text/javascript" src="/website/static/lib/ckeditor.sharedspace/plugin.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
@ -34,11 +37,15 @@
|
|||
</script>
|
||||
|
||||
<t t-if="editable">
|
||||
<t t-raw="css"/>
|
||||
<t t-raw="script"/>
|
||||
<link rel='stylesheet' href='/website/static/src/css/snippets.css'/>
|
||||
<script type="text/javascript" src="/website/static/src/js/website_bootstrap.js"></script>
|
||||
<link rel='stylesheet' href='/website/static/src/css/editor.css'/>
|
||||
|
||||
<script type="text/javascript" src="/web/static/lib/jquery.ui/js/jquery-ui-1.9.1.custom.js"></script>
|
||||
<script type="text/javascript" src="/web/static/lib/qweb/qweb2.js"></script>
|
||||
<script type="text/javascript" src="/web/static/src/js/openerpframework.js"></script>
|
||||
</t>
|
||||
|
||||
<script type="text/javascript" src="/website/static/src/js/website.js"></script>
|
||||
<t t-raw="head or ''"/>
|
||||
<t t-call="website.theme"/>
|
||||
|
||||
|
|
|
@ -46,11 +46,16 @@ class website(osv.osv):
|
|||
|
||||
def get_rendering_context(self, additional_values=None):
|
||||
debug = 'debug' in request.params
|
||||
is_logged = True
|
||||
try:
|
||||
request.session.check_security()
|
||||
except: # TODO fme: check correct exception
|
||||
is_logged = False
|
||||
is_public_user = request.uid == self.get_public_user().id
|
||||
values = {
|
||||
'debug': debug,
|
||||
'is_public_user': is_public_user,
|
||||
'editable': not is_public_user,
|
||||
'editable': is_logged and not is_public_user,
|
||||
'request': request,
|
||||
'registry': request.registry,
|
||||
'cr': request.cr,
|
||||
|
@ -59,11 +64,6 @@ class website(osv.osv):
|
|||
'res_company': request.registry['res.company'].browse(request.cr, openerp.SUPERUSER_ID, 1),
|
||||
'json': simplejson,
|
||||
}
|
||||
if values['editable']:
|
||||
values.update({
|
||||
'script': "\n".join(['<script type="text/javascript" src="%s"></script>' % i for i in main.manifest_list('js', db=request.db, debug=debug)]),
|
||||
'css': "\n".join('<link rel="stylesheet" href="%s">' % i for i in main.manifest_list('css', db=request.db, debug=debug))
|
||||
})
|
||||
if additional_values:
|
||||
values.update(additional_values)
|
||||
return values
|
||||
|
|
Loading…
Reference in New Issue