[IMP] website,website_livechat,website_slides: add "new content" buttons

Those allow the user to quickly create a new channel or new slides.

PR: #27110
task-1885419
This commit is contained in:
Sébastien Theys
2018-09-25 16:23:08 +02:00
parent 2ab6ce80d6
commit e4aa8ec6d1
8 changed files with 189 additions and 0 deletions
@@ -147,6 +147,18 @@
<p>New Product</p>
</a>
</div>
<div groups="base.group_system" name="module_website_slides" t-att-data-module-id="env.ref('base.module_website_slides').id" t-att-data-module-shortdesc="env.ref('base.module_website_slides').shortdesc" class="col-md-4 mb8 o_new_content_element">
<a href="#" data-action="new_slide">
<i class="fa fa-youtube-play"/>
<p>New Slide</p>
</a>
</div>
<div groups="base.group_system" name="module_website_livechat" t-att-data-module-id="env.ref('base.module_website_livechat').id" t-att-data-module-shortdesc="env.ref('base.module_website_livechat').shortdesc" class="col-md-4 mb8 o_new_content_element">
<a href="#" data-action="new_channel">
<i class="fa fa-hashtag"/>
<p>New Channel</p>
</a>
</div>
</div>
</div>
</div>
@@ -0,0 +1,52 @@
odoo.define('website_livechat.editor', function (require) {
'use strict';
var core = require('web.core');
var wUtils = require('website.utils');
var WebsiteNewMenu = require('website.newMenu');
var weContext = require('web_editor.context');
var _t = core._t;
WebsiteNewMenu.include({
actions: _.extend({}, WebsiteNewMenu.prototype.actions || {}, {
new_channel: '_createNewChannel',
}),
//--------------------------------------------------------------------------
// Actions
//--------------------------------------------------------------------------
/**
* Asks the user information about a new channel to create, then creates it
* and redirects the user to this new channel.
*
* @private
* @returns {Deferred} Unresolved if there is a redirection
*/
_createNewChannel: function () {
var self = this;
return wUtils.prompt({
window_title: _t("New Channel"),
input: _t("Name"),
}).then(function (name) {
if (!name) {
return;
}
return self._rpc({
model: 'im_livechat.channel',
method: 'create_and_get_website_url',
context: weContext.get(),
args: [[]],
kwargs: {
name: name,
},
}).then(function (url) {
window.location.href = url;
return $.Deferred();
});
});
},
});
});
@@ -37,6 +37,13 @@
<link rel="stylesheet" type="text/scss" href="/im_livechat/static/src/scss/im_livechat.scss"/>
</xpath>
</template>
<template id="assets_editor_inherit_website_livechat" inherit_id="website.assets_editor" name="website_livechat Assets Editor">
<xpath expr="." position="inside">
<script type="text/javascript" src="/website_livechat/static/src/js/website_livechat.editor.js"></script>
</xpath>
</template>
<template id="loader" inherit_id="website.layout" name="Livechat : include loader on Website">
<xpath expr="//div[@id='wrapwrap']" position="after">
<t t-if="website and website.channel_id">
@@ -189,5 +196,15 @@
</t>
</template>
<!-- User Navbar -->
<template id="user_navbar_inherit_website_livecaht" inherit_id="website.user_navbar">
<xpath expr="//div[@id='o_new_content_menu_choices']//div[@name='module_website_livechat']" position="attributes">
<attribute name="name"/>
<attribute name="t-att-data-module-id"/>
<attribute name="t-att-data-module-shortdesc"/>
<attribute name="groups">im_livechat.im_livechat_group_manager</attribute>
</xpath>
</template>
</data>
</odoo>
+5
View File
@@ -182,6 +182,11 @@ class Channel(models.Model):
subtype = 'mail.mt_note'
return super(Channel, self).message_post(parent_id=parent_id, subtype=subtype, **kwargs)
def list_all(self):
return {
'channels': [{'id': channel.id, 'name': channel.name, 'website_url': channel.website_url} for channel in self.search([])]
}
class Category(models.Model):
""" Channel contain various categories to manage its slides """
@@ -378,4 +378,10 @@ $('.oe_slide_js_upload').on('click', function () {
var channel_id = $(this).attr('channel_id');
slides.page_widgets['upload_dialog'] = new SlideDialog(this, channel_id).appendTo(document.body);
});
// automatically open the upload dialog if requested from query string
if ($.deparam.querystring().enable_slide_upload !== undefined) {
$('.oe_slide_js_upload').click();
}
});
@@ -0,0 +1,66 @@
odoo.define('website_slides.editor', function (require) {
"use strict";
var core = require('web.core');
var Dialog = require('web.Dialog');
var QWeb = core.qweb;
var WebsiteNewMenu = require('website.newMenu');
var weContext = require('web_editor.context');
var _t = core._t;
WebsiteNewMenu.include({
actions: _.extend({}, WebsiteNewMenu.prototype.actions || {}, {
new_slide: '_createNewSlide',
}),
xmlDependencies: WebsiteNewMenu.prototype.xmlDependencies.concat(
['/website_slides/static/src/xml/website_slides.xml']
),
//--------------------------------------------------------------------------
// Actions
//--------------------------------------------------------------------------
/**
* Asks the user information about in which channel to create a new slide,
* and redirects the user to this channel with the "new slide" popup open.
*
* @private
* @returns {Deferred} Unresolved if there is a redirection
*/
_createNewSlide: function () {
var self = this;
return this._rpc({
model: 'slide.channel',
method: 'list_all',
context: weContext.get(),
args: [[]],
}).then(function (data) {
var def = $.Deferred();
new Dialog(self, {
title: _t("New slide"),
subtitle: _t("On which channel do you want to add a slide?"),
size: 'medium',
$content: QWeb.render('website.slide.create', data),
buttons: [{
text: _t("Select"),
classes: 'btn-primary',
click: function () {
var channel_url = this.$("option:selected").val();
if (channel_url) {
window.location.href = channel_url + '?enable_slide_upload';
} else {
def.reject();
}
}
}, {
text: _t("Cancel"), close: true
},]
}).open()
.on('closed', def.resolve.bind(def));
return def;
});
},
});
});
@@ -75,4 +75,19 @@
</div>
</t>
<t t-name="website.slide.create">
<form>
<div class="form-group row">
<label class="col-form-label col-md-3" for="slide_channel_id">Channel</label>
<div class="col-md-9">
<select class="form-control" id="slide_channel_id" required="">
<t t-foreach="channels" t-as="channel">
<option t-att-value="channel.website_url"><t t-esc="channel.name"/></option>
</t>
</select>
</div>
</div>
</form>
</t>
</templates>
@@ -12,6 +12,12 @@
</xpath>
</template>
<template id="assets_editor_inherit_website_slides" inherit_id="website.assets_editor" name="website_slides Assets Editor">
<xpath expr="." position="inside">
<script type="text/javascript" src="/website_slides/static/src/js/website_slides.editor.js"/>
</xpath>
</template>
<!-- Tools template: share on social networkds -->
<template id='slides_share' name="Slides Media Share">
<div>
@@ -724,5 +730,15 @@
</div>
</template>
<!-- User Navbar -->
<template id="user_navbar_inherit_website_slides" inherit_id="website.user_navbar">
<xpath expr="//div[@id='o_new_content_menu_choices']//div[@name='module_website_slides']" position="attributes">
<attribute name="name"/>
<attribute name="t-att-data-module-id"/>
<attribute name="t-att-data-module-shortdesc"/>
<attribute name="groups">website.group_website_designer</attribute>
</xpath>
</template>
</data>
</odoo>