Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ODOO-414][ADD] Added new view description to control panel area #20

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion addons/web/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ def generate_views(action):
# providing at least one view mode is a requirement, not an option
view_modes = action['view_mode'].split(',')

# BLUE STINGRAY / METRIC WISE CUSTOM
# make sure the view_description is instantiated
view_description = action['view_description'] or False

if len(view_modes) > 1:
if view_id:
raise ValueError('Non-db action dictionaries should provide '
Expand All @@ -291,7 +295,7 @@ def generate_views(action):
view_modes, view_id, action))
action['views'] = [(False, mode) for mode in view_modes]
return
action['views'] = [(view_id, view_modes[0])]
action['views'] = [(view_id, view_modes[0], view_description)]

def fix_view_modes(action):
""" For historical reasons, Odoo has weird dealings in relation to
Expand Down
14 changes: 14 additions & 0 deletions addons/web/static/src/legacy/js/chrome/abstract_action.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ const AbstractAction = Widget.extend(ActionMixin, {
*/
withSearchBar: false,

/**
* BLUE STINGRAY / METRIC WISE CUSTOM
* A client action might want to see the view description displayed in its
* control panel, or it choose not to use it.
*
* It also only makes sense if hasControlPanel is set to true.
*
* @type boolean
*/
withViewDescription: false,

/**
* This parameter can be set to customize the available sub menus in the
* controlpanel (Filters/Group By/Favorites). This is basically a list of
Expand All @@ -74,6 +85,7 @@ const AbstractAction = Widget.extend(ActionMixin, {
init: function (parent, action, options) {
this._super(parent);
this._title = action.display_name || action.name;
this._viewDescription = action.view_description;

this.searchModelConfig = {
context: Object.assign({}, action.context),
Expand All @@ -86,6 +98,7 @@ const AbstractAction = Widget.extend(ActionMixin, {
this.extensions.ControlPanel = {
actionId: action.id,
withSearchBar: this.withSearchBar,
withViewDescription: this.withViewDescription,
};

this.viewId = action.search_view_id && action.search_view_id[0];
Expand All @@ -95,6 +108,7 @@ const AbstractAction = Widget.extend(ActionMixin, {
breadcrumbs: options && options.breadcrumbs,
withSearchBar: this.withSearchBar,
searchMenuTypes: this.searchMenuTypes,
withViewDescription: this.withViewDescription,
};
}
},
Expand Down
32 changes: 32 additions & 0 deletions addons/web/static/src/legacy/js/chrome/action_mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ odoo.define('web.ActionMixin', function (require) {
*/
_title: '',

/**
* BLUE STINGRAY / METRIC WISE CUSTOM
* String containing the view description of the client action
*
* @see _setViewDescription
*/
_viewDescription: '',

/**
* @override
*/
Expand Down Expand Up @@ -154,6 +162,17 @@ odoo.define('web.ActionMixin', function (require) {
return this._title;
},

/**
* BLUE STINGRAY / METRIC WISE CUSTOM
* Returns a view_description that may be displayed in center of the
* control panel area.
*
* @returns {string}
*/
getViewDescription: function () {
return this._viewDescription;
},

/**
* Renders the buttons to append, in most cases, to the control panel (in
* the bottom left corner). When the action is rendered in a dialog, those
Expand Down Expand Up @@ -187,6 +206,11 @@ odoo.define('web.ActionMixin', function (require) {
this.controlPanelProps.title = this.getTitle();
delete props.title;
}
if ('view_description' in props) {
this._setViewDescription(props.view_description);
this.controlPanelProps.view_description = this.getViewDescription();
delete props.view_description;
}
if ('cp_content' in props) {
// cp_content has been updated: refresh it.
this.controlPanelProps.cp_content = Object.assign({},
Expand All @@ -212,6 +236,14 @@ odoo.define('web.ActionMixin', function (require) {
this._title = title;
},

/**
* @private
* @param {string} view_description
*/
_setViewDescription: function (view_description) {
this._viewDescription = view_description;
},

//---------------------------------------------------------------------
// Handlers
//---------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ odoo.define('web.ControlPanel', function (require) {
actionMenus: { validate: s => typeof s === 'object' || s === null, optional: 1 },
title: { type: String, optional: 1 },
view: { type: Object, optional: 1 },
view_description: { type: String, optional: 1 },
views: Array,
withBreadcrumbs: Boolean,
withSearchBar: Boolean,
Expand Down
1 change: 1 addition & 0 deletions addons/web/static/src/legacy/js/views/abstract_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ var AbstractView = Factory.extend({
fields,
searchMenuTypes: params.searchMenuTypes,
view: this.fieldsView,
view_description: params.action.view_description || "",
views: params.action.views && params.action.views.filter(
v => v.multiRecord === this.multi_record
),
Expand Down
7 changes: 7 additions & 0 deletions addons/web/static/src/legacy/xml/base.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
</li>
</ol>
</div>
<div class="o_cp_top_center" t-if="props.withSearchBar">
<div t-if="props.withBreadcrumbs" class="breadcrumb" role="navigation">
<div>
<p t-esc="props.view_description"/>
</div>
</div>
</div>
<div class="o_cp_top_right">
<div class="o_cp_searchview"
role="search"
Expand Down
5 changes: 4 additions & 1 deletion addons/web/static/src/search/control_panel/control_panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class ControlPanel extends Component {
const transferredSlotNames = [
"control-panel-top-left",
"control-panel-top-right",
"control-panel-top-center",
"control-panel-bottom-left",
"control-panel-bottom-right",
];
Expand All @@ -66,13 +67,15 @@ export class ControlPanel extends Component {
const display = Object.assign(
{
"top-left": true,
"top-center":true,
"top-right": true,
"bottom-left": true,
"bottom-right": true,
},
this.props.display || this.env.searchModel.display.controlPanel
);
display.top = display["top-left"] || display["top-right"];
display.top = display["top-left"] || display["top-center"] ||
display["top-right"];
display.bottom = display["bottom-left"] || display["bottom-right"];
return display;
}
Expand Down
11 changes: 11 additions & 0 deletions addons/web/static/src/search/control_panel/control_panel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@
}
}

.o_cp_top_center {
padding-right: 20em;
font-size: 10px;
}

@media only screen and (max-width: 1026px) {
.o_cp_top_center {
display: none;
}
}

.o_cp_top_right {
min-height: $o-cp-breadcrumb-height;
}
Expand Down
9 changes: 8 additions & 1 deletion addons/web/static/src/search/control_panel/control_panel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
<t t-call="web.Breadcrumbs" />
</t>
</div>
<div t-if="display['top-center']" class="o_cp_top_center">
<t t-slot="control-panel-top-center">
<t t-set="view_description" t-value="window.sessionStorage.current_action.split(':')[9].slice(1, window.sessionStorage.current_action.split(':')[9].search(','))"/>
<t t-if="view_description">
<p t-esc="view_description.slice(0,-1)" style="font-size: 18px;"/>
</t>
</t>
</div>
<div t-if="display['top-right']" class="o_cp_top_right">
<t t-slot="control-panel-top-right">
<SearchBar/>
Expand Down Expand Up @@ -64,5 +72,4 @@
</li>
</ol>
</t>

</templates>
7 changes: 7 additions & 0 deletions addons/web/static/src/webclient/actions/action_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ function makeActionManager(env) {
return {
jsId: controller.jsId,
name: controller.title || controller.action.name || env._t("Undefined"),
view_description: controller.action.view_description || env._t("Undefined"),
};
});
}
Expand Down Expand Up @@ -297,6 +298,12 @@ function makeActionManager(env) {
const storedAction = browser.sessionStorage.getItem("current_action");
const lastAction = JSON.parse(storedAction || "{}");
if (lastAction.res_model === state.model) {
if (lastAction.context) {
// If this method is called because of a company switch, the
// stored allowed_company_ids is incorrect.
// (Fix will be improved in master)
delete lastAction.context.allowed_company_ids;
}
actionRequest = lastAction;
options.viewType = state.view_type;
}
Expand Down
6 changes: 4 additions & 2 deletions odoo/addons/base/models/ir_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class IrActions(models.Model):
('report', 'Report')],
required=True, default='action')
binding_view_types = fields.Char(default='list,form')
# BLUE STINGRAY / METRIC WISE CUSTOM
view_description = fields.Char(string='View Description')

def _compute_xml_id(self):
res = self.get_external_id()
Expand Down Expand Up @@ -165,7 +167,7 @@ def _get_readable_fields(self):
"""
return {
"binding_model_id", "binding_type", "binding_view_types",
"display_name", "help", "id", "name", "type", "xml_id",
"display_name", "help", "id", "name", "type", "xml_id", "view_description",
}


Expand Down Expand Up @@ -293,7 +295,7 @@ def _get_readable_fields(self):
return super()._get_readable_fields() | {
"context", "domain", "filter", "groups_id", "limit", "res_id",
"res_model", "search_view", "search_view_id", "target", "view_id",
"view_mode", "views",
"view_description", "view_mode", "views",
# `flags` is not a real field of ir.actions.act_window but is used
# to give the parameters to generate the action
"flags"
Expand Down
3 changes: 2 additions & 1 deletion odoo/addons/base/views/ir_actions_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
<field name="name"/>
<field name="xml_id" string="External ID"/>
<field name="res_model" string="Object"/>
<field name="view_description"/>
</group>
<group name="action_details">
<field name="usage"/>
Expand Down Expand Up @@ -420,7 +421,7 @@ env['res.partner'].create({'name': partner_name})
<header>
<button name="action_launch"
states="open" string="Launch"
type="object" icon="fa-cogs" class="oe_highlight"
type="object" icon="fa-cogs" class="oe_highlight"
help="Launch Configuration Wizard"/>
<button name="action_open" states="done"
string="Set as Todo" type="object"
Expand Down