From 1d54874c13e974317bf211ea5af7c1b7d130dbcd Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Tue, 9 Aug 2016 10:58:17 +0200 Subject: [PATCH] [IMP] website: propose edition of company data in frontend When clicking on the logo or the company adress in the website edit mode, the user can now choose to be redirected to the form view of the company so that it can edit the data. --- .../static/src/js/website.snippets.editor.js | 37 +++++++++++++++++++ addons/website/views/snippets.xml | 4 ++ 2 files changed, 41 insertions(+) diff --git a/addons/website/static/src/js/website.snippets.editor.js b/addons/website/static/src/js/website.snippets.editor.js index 0a735f34263..bc2dbf3b658 100644 --- a/addons/website/static/src/js/website.snippets.editor.js +++ b/addons/website/static/src/js/website.snippets.editor.js @@ -1,8 +1,10 @@ odoo.define('website.snippets.editor', function (require) { 'use strict'; +var ajax = require("web.ajax"); var core = require("web.core"); var Dialog = require("web.Dialog"); +var Model = require("web.Model"); var editor = require("web_editor.editor"); var options = require('web_editor.snippets.options'); var snippet_editor = require('web_editor.snippet.editor'); @@ -51,6 +53,41 @@ options.registry.menu_data = options.Class.extend({ }, }); +options.registry.company_data = options.Class.extend({ + start: function () { + this._super.apply(this, arguments); + + var proto = options.registry.company_data.prototype; + + if (proto.__link_deferred === undefined) { + proto.__link_deferred = $.Deferred(); + return ajax.jsonRpc("/web/session/get_session_info", "call").then(function (session) { + return (new Model("res.users")).get_func("read")(session.uid, ["company_id"]).then(function (res) { + proto.__link_deferred.resolve( + "/web#action=base.action_res_company_form&view_type=form&id=" + (res && res[0] && res[0].company_id[0] || 1) + ); + }); + }); + } + }, + + on_focus: function () { + this._super.apply(this, arguments); + + var proto = options.registry.company_data.prototype; + + Dialog.confirm(null, _t("Do you want to edit the company data ?"), { + confirm_callback: function () { + editor.editor_bar.save_without_reload().then(function () { + proto.__link_deferred.then(function (link) { + window.location.href = link; + }); + }); + }, + }); + }, +}); + options.registry.slider = options.Class.extend({ drop_and_build_snippet: function () { this.id = "myCarousel" + new Date().getTime(); diff --git a/addons/website/views/snippets.xml b/addons/website/views/snippets.xml index e7260203d2f..e987acad8cb 100644 --- a/addons/website/views/snippets.xml +++ b/addons/website/views/snippets.xml @@ -937,5 +937,9 @@
+ +