diff --git a/addons/website/__openerp__.py b/addons/website/__openerp__.py index 14e8aaa3564..aa0f5dbf64f 100644 --- a/addons/website/__openerp__.py +++ b/addons/website/__openerp__.py @@ -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'], } diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py index 420366862bd..bd3f7285126 100644 --- a/addons/website/controllers/main.py +++ b/addons/website/controllers/main.py @@ -12,6 +12,8 @@ from openerp.addons.web.http import request import werkzeug import werkzeug.exceptions import werkzeug.wrappers +import hashlib +import os logger = logging.getLogger(__name__) @@ -154,6 +156,47 @@ class Website(openerp.addons.web.controllers.main.Home): return response + @http.route('/website/image', type='http', auth="public") + def image(self, model, id, field, **kw): + last_update = '__last_update' + Model = request.registry[model] + headers = [('Content-Type', 'image/png')] + etag = request.httprequest.headers.get('If-None-Match') + hashed_session = hashlib.md5(request.session_id).hexdigest() + retag = hashed_session + try: + if etag: + date = Model.read(request.cr, request.uid, [id], [last_update], request.context)[0].get(last_update) + if hashlib.md5(date).hexdigest() == etag: + return werkzeug.wrappers.Response(status=304) + + res = Model.read(request.cr, request.uid, [id], [last_update, field], request.context)[0] + retag = hashlib.md5(res.get(last_update)).hexdigest() + image_base64 = res.get(field) + + if kw.get('resize'): + resize = kw.get('resize').split(',') + if len(resize) == 2 and int(resize[0]) and int(resize[1]): + width = int(resize[0]) + height = int(resize[1]) + # resize maximum 500*500 + if width > 500: width = 500 + if height > 500: height = 500 + image_base64 = openerp.tools.image_resize_image(base64_source=image_base64, size=(width, height), encoding='base64', filetype='PNG') + + image_data = base64.b64decode(image_base64) + except Exception: + image_data = open(os.path.join(http.addons_manifest['web']['addons_path'], 'web', 'static', 'src', 'img', 'placeholder.png'), 'rb').read() + + headers.append(('ETag', retag)) + headers.append(('Content-Length', len(image_data))) + try: + ncache = int(kw.get('cache')) + headers.append(('Cache-Control', 'no-cache' if ncache == 0 else 'max-age=%s' % (ncache))) + except: + pass + return request.make_response(image_data, headers) + @http.route(['/website/publish/'], type='http', auth="public") def publish(self, **post): _id = int(post['id']) diff --git a/addons/website/static/src/js/website.js b/addons/website/static/src/js/website.js index c83cc5cc1be..2c589a49de5 100644 --- a/addons/website/static/src/js/website.js +++ b/addons/website/static/src/js/website.js @@ -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('
').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 () { }); }); -}; diff --git a/addons/website/static/src/js/website_bootstrap.js b/addons/website/static/src/js/website_bootstrap.js deleted file mode 100644 index d08f6270fc9..00000000000 --- a/addons/website/static/src/js/website_bootstrap.js +++ /dev/null @@ -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()); - }); -}); diff --git a/addons/website/views/views.xml b/addons/website/views/views.xml index 12267889b62..509f0180f5d 100644 --- a/addons/website/views/views.xml +++ b/addons/website/views/views.xml @@ -20,10 +20,13 @@ + + + + +