diff --git a/muk_web_utils/__init__.py b/muk_web_utils/__init__.py index 9bc0a69..3a0a7c9 100644 --- a/muk_web_utils/__init__.py +++ b/muk_web_utils/__init__.py @@ -16,3 +16,5 @@ # along with this program. If not, see . # ################################################################################### + +from . import models \ No newline at end of file diff --git a/muk_web_utils/__manifest__.py b/muk_web_utils/__manifest__.py index fc55344..2fd0830 100644 --- a/muk_web_utils/__manifest__.py +++ b/muk_web_utils/__manifest__.py @@ -20,7 +20,7 @@ { "name": "MuK Web Utils", "summary": """Utility Features""", - "version": "12.0.2.0.19", + "version": "12.0.2.1.0", "category": "Extra Tools", "license": "AGPL-3", "author": "MuK IT", diff --git a/muk_web_utils/doc/changelog.rst b/muk_web_utils/doc/changelog.rst index f2ae21c..c659e2d 100644 --- a/muk_web_utils/doc/changelog.rst +++ b/muk_web_utils/doc/changelog.rst @@ -1,3 +1,8 @@ +`2.1.0` +------- + +- Automatic labels on settings + `2.0.0` ------- diff --git a/muk_web_utils/models/__init__.py b/muk_web_utils/models/__init__.py new file mode 100644 index 0000000..af61df3 --- /dev/null +++ b/muk_web_utils/models/__init__.py @@ -0,0 +1,21 @@ +################################################################################### +# +# Copyright (C) 2018 MuK IT GmbH +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +################################################################################### + +from . import res_config_settings + diff --git a/muk_web_utils/models/res_config_settings.py b/muk_web_utils/models/res_config_settings.py new file mode 100644 index 0000000..f42a83b --- /dev/null +++ b/muk_web_utils/models/res_config_settings.py @@ -0,0 +1,51 @@ +################################################################################### +# +# Copyright (C) 2017 MuK IT GmbH +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +################################################################################### + +import re +import json +import logging + +from lxml import etree + +from odoo import api, fields, models + +_logger = logging.getLogger(__name__) + +class ResConfigSettings(models.TransientModel): + + _inherit = 'res.config.settings' + + #---------------------------------------------------------- + # Functions + #---------------------------------------------------------- + + @api.model + def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): + ret_val = super(ResConfigSettings, self).fields_view_get( + view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu) + modules = self.env['ir.module.module'].sudo().search([]).mapped('name') + print(modules) + document = etree.XML(ret_val['arch']) + for field in ret_val['fields']: + if field.startswith("module_") and field[len("module_"):] not in modules: + for node in document.xpath("//field[@name='%s']" % field): + if node.get("widget") != 'upgrade_boolean': + node.set("widget", "module_boolean") + ret_val['arch'] = etree.tostring(document, encoding='unicode') + return ret_val \ No newline at end of file diff --git a/muk_web_utils/static/src/img/module.png b/muk_web_utils/static/src/img/module.png new file mode 100644 index 0000000..74ca4c7 Binary files /dev/null and b/muk_web_utils/static/src/img/module.png differ diff --git a/muk_web_utils/static/src/js/fields/module.js b/muk_web_utils/static/src/js/fields/module.js new file mode 100644 index 0000000..a79d571 --- /dev/null +++ b/muk_web_utils/static/src/js/fields/module.js @@ -0,0 +1,93 @@ +/********************************************************************************** +* +* Copyright (C) 2017 MuK IT GmbH +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +* +**********************************************************************************/ + +odoo.define('muk_web_utils.ModuleBoolean', function (require) { +"use strict"; + +var core = require('web.core'); +var fields = require('web.basic_fields'); +var registry = require('web.field_registry'); +var framework = require('web.framework'); + +var Dialog = require('web.Dialog'); +var AbstractField = require('web.AbstractField'); + +var _t = core._t; +var QWeb = core.qweb; + +var ModuleBoolean = fields.FieldBoolean.extend({ + supportedFieldTypes: [], + events: _.extend({}, AbstractField.prototype.events, { + 'click input': '_onInputClicked', + }), + renderWithLabel: function ($label) { + this.$label = $label; + this._render(); + }, + _openDialog: function () { + var buttons = [{ + text: _t("Download"), + classes: 'btn-primary', + close: true, + click: this._confirmRedirect.bind(this), + }, { + text: _t("Cancel"), + close: true, + }]; + return new Dialog(this, { + size: 'medium', + buttons: buttons, + $content: $('
', { + html: $(QWeb.render('muk_web_utils.MissingModuleDialog')), + }), + title: _t("Missing Module"), + }).open(); + }, + _confirmRedirect: function () { + if(this.nodeOptions.url) { + framework.redirect(this.nodeOptions.url); + } else { + var module = this.name.replace("module_", ""); + framework.redirect("https://apps.odoo.com/apps/modules/browse?search=" + module); + } + }, + _render: function () { + this._super.apply(this, arguments); + var $element = this.$label || this.$el; + $element.append(' ').append($("", { + 'text': _t("Store"), + 'class': "badge badge-primary oe_inline mk_module_label" + })); + }, + _onInputClicked: function (event) { + if ($(event.currentTarget).prop("checked")) { + var dialog = this._openDialog(); + dialog.on('closed', this, this._resetValue.bind(this)); + } + }, + _resetValue: function () { + this.$input.prop("checked", false).change(); + }, +}); + +registry.add('module_boolean', ModuleBoolean); + +return ModuleBoolean; + +}); \ No newline at end of file diff --git a/muk_web_utils/static/src/js/views/form/renderer.js b/muk_web_utils/static/src/js/views/form/renderer.js new file mode 100644 index 0000000..7236c80 --- /dev/null +++ b/muk_web_utils/static/src/js/views/form/renderer.js @@ -0,0 +1,44 @@ +/********************************************************************************** +* +* Copyright (C) 2017 MuK IT GmbH +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +* +**********************************************************************************/ + +odoo.define('muk_web_utils.FormRenderer', function (require) { +"use strict"; + +var core = require('web.core'); + +var FormRenderer = require('web.FormRenderer'); + +var _t = core._t; +var QWeb = core.qweb; + +FormRenderer.include({ + _updateView: function ($newContent) { + this._super.apply(this, arguments); + _.each(this.allFieldWidgets[this.state.id], function (widget) { + if (widget.attrs.widget === 'module_boolean') { + var inputID = this.idsForLabels[widget.name]; + var $widgets = this.$('.o_field_widget[name=' + widget.name + ']'); + var $label = inputID ? this.$('.o_form_label[for=' + inputID + ']') : $(); + widget.renderWithLabel($label.eq($widgets.index(widget.$el))); + } + }, this); + } +}); + +}); \ No newline at end of file diff --git a/muk_web_utils/static/src/scss/module.scss b/muk_web_utils/static/src/scss/module.scss new file mode 100644 index 0000000..cde97f4 --- /dev/null +++ b/muk_web_utils/static/src/scss/module.scss @@ -0,0 +1,30 @@ +/********************************************************************************** +* +* Copyright (C) 2017 MuK IT GmbH +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +* +**********************************************************************************/ + +.o_settings_container { + .o_setting_box { + .o_setting_left_pane { + .mk_module_label { + position: absolute; + top: 0px; + right: 40px; + } + } + } +} \ No newline at end of file diff --git a/muk_web_utils/static/src/xml/module.xml b/muk_web_utils/static/src/xml/module.xml new file mode 100644 index 0000000..b163902 --- /dev/null +++ b/muk_web_utils/static/src/xml/module.xml @@ -0,0 +1,34 @@ + + + + + + + +
+
+ Missing Module +
+
+

The module could not be found on the server.

+

Click on the download button to be redirected to the store and download the corresponding module.

+
+
+
+ +
\ No newline at end of file diff --git a/muk_web_utils/static/src/xml/switch.xml b/muk_web_utils/static/src/xml/switch.xml index 67e7054..1341ab2 100644 --- a/muk_web_utils/static/src/xml/switch.xml +++ b/muk_web_utils/static/src/xml/switch.xml @@ -1,38 +1,22 @@ + diff --git a/muk_web_utils/template/assets.xml b/muk_web_utils/template/assets.xml index a1a16b6..09d7c71 100644 --- a/muk_web_utils/template/assets.xml +++ b/muk_web_utils/template/assets.xml @@ -23,8 +23,11 @@ + + +