diff --git a/muk_web_fields_lobject/__init__.py b/muk_web_fields_lobject/__init__.py new file mode 100644 index 0000000..fe23305 --- /dev/null +++ b/muk_web_fields_lobject/__init__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- + +################################################################################### +# +# 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 . +# +################################################################################### diff --git a/muk_web_fields_lobject/__manifest__.py b/muk_web_fields_lobject/__manifest__.py new file mode 100644 index 0000000..ee0f2bf --- /dev/null +++ b/muk_web_fields_lobject/__manifest__.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- + +################################################################################### +# +# 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 . +# +################################################################################### + +{ + "name": "MuK Large Objects Field Widget", + "summary": """PGSQL Large Objects Field Widget""", + "version": '11.0.1.0.0', + "category": 'Extra Tools', + "license": "AGPL-3", + "website": "http://www.mukit.at", + "author": "MuK IT", + "contributors": [ + "Mathias Markl ", + ], + "depends": [ + "web", + "muk_fields_lobject", + ], + "data": [ + "template/assets.xml" + ], + "demo": [ + ], + "qweb": [ + "static/src/xml/*.xml", + ], + "images": [ + 'static/description/banner.png' + ], + "external_dependencies": { + "python": [], + "bin": [], + }, + "auto_install": True, + "application": False, + "installable": True, +} diff --git a/muk_web_fields_lobject/doc/changelog.rst b/muk_web_fields_lobject/doc/changelog.rst new file mode 100644 index 0000000..9ee2b48 --- /dev/null +++ b/muk_web_fields_lobject/doc/changelog.rst @@ -0,0 +1,4 @@ +`1.0.0` +------- + +- Init version diff --git a/muk_web_fields_lobject/doc/index.rst b/muk_web_fields_lobject/doc/index.rst new file mode 100644 index 0000000..94de82b --- /dev/null +++ b/muk_web_fields_lobject/doc/index.rst @@ -0,0 +1,47 @@ +============================== +MuK Large Objects Field Widget +============================== + +This module allows the LargeObject Field to be used in different views. It is +installed automatically with the MuK Large Objects module. + +Installation +============ + +To install this module, you need to: + +Download the module and add it to your Odoo addons folder. Afterward, log on to +your Odoo server and go to the Apps menu. Trigger the debug modus and update the +list by clicking on the "Update Apps List" link. Now install the module by +clicking on the install button. + +Configuration +============= + +No additional configuration is needed to use this module. + +Usage +============= + +This module has no direct visible effect on the system. It allows LargeObejct +fields to display in XML views. + +Credits +======= + +Contributors +------------ + +* Mathias Markl + +Author & Maintainer +------------------- + +This module is maintained by the `MuK IT GmbH `_. + +MuK IT is an Austrian company specialized in customizing and extending Odoo. +We develop custom solutions for your individual needs to help you focus on +your strength and expertise to grow your business. + +If you want to get in touch please contact us via mail +(sale@mukit.at) or visit our website (https://mukit.at). diff --git a/muk_web_fields_lobject/i18n/de.po b/muk_web_fields_lobject/i18n/de.po new file mode 100644 index 0000000..4737d85 --- /dev/null +++ b/muk_web_fields_lobject/i18n/de.po @@ -0,0 +1,75 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * muk_web_fields_lobject +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-04-25 16:17+0000\n" +"PO-Revision-Date: 2018-04-25 18:19+0200\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"Language: de\n" +"X-Generator: Poedit 2.0.6\n" + +#. module: muk_web_fields_lobject +#. openerp-web +#: code:addons/muk_web_fields_lobject/static/src/xml/lobject.xml:33 +#, python-format +msgid "Clear" +msgstr "Löschen" + +#. module: muk_web_fields_lobject +#. openerp-web +#: code:addons/muk_web_fields_lobject/static/src/js/lobject.js:92 +#, python-format +msgid "File Upload" +msgstr "File Hochladen" + +#. module: muk_web_fields_lobject +#. openerp-web +#: code:addons/muk_web_fields_lobject/static/src/js/lobject.js:72 +#, python-format +msgid "File upload" +msgstr "File Hochladen" + +#. module: muk_web_fields_lobject +#. openerp-web +#: code:addons/muk_web_fields_lobject/static/src/xml/lobject.xml:31 +#: code:addons/muk_web_fields_lobject/static/src/xml/lobject.xml:32 +#, python-format +msgid "Select" +msgstr "Auswählen" + +#. module: muk_web_fields_lobject +#. openerp-web +#: code:addons/muk_web_fields_lobject/static/src/js/lobject.js:71 +#, python-format +msgid "The selected file exceed the maximum file size of %s." +msgstr "Die ausgewählte Datei überschreitet die maximale Dateigröße von %s." + +#. module: muk_web_fields_lobject +#. openerp-web +#: code:addons/muk_web_fields_lobject/static/src/js/lobject.js:92 +#, python-format +msgid "There was a problem while uploading your file" +msgstr "Es gab ein Problem beim Hochladen Ihrer Datei" + +#. module: muk_web_fields_lobject +#. openerp-web +#: code:addons/muk_web_fields_lobject/static/src/xml/lobject.xml:31 +#, python-format +msgid "Upload your file" +msgstr "Laden Sie Ihre Datei hoch" + +#. module: muk_web_fields_lobject +#. openerp-web +#: code:addons/muk_web_fields_lobject/static/src/xml/lobject.xml:34 +#, python-format +msgid "Uploading..." +msgstr "Hochladen...." diff --git a/muk_web_fields_lobject/i18n/muk_web_fields_lobject.pot b/muk_web_fields_lobject/i18n/muk_web_fields_lobject.pot new file mode 100644 index 0000000..3bbf38f --- /dev/null +++ b/muk_web_fields_lobject/i18n/muk_web_fields_lobject.pot @@ -0,0 +1,74 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * muk_web_fields_lobject +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-04-25 16:16+0000\n" +"PO-Revision-Date: 2018-04-25 16:16+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: muk_web_fields_lobject +#. openerp-web +#: code:addons/muk_web_fields_lobject/static/src/xml/lobject.xml:33 +#, python-format +msgid "Clear" +msgstr "" + +#. module: muk_web_fields_lobject +#. openerp-web +#: code:addons/muk_web_fields_lobject/static/src/js/lobject.js:92 +#, python-format +msgid "File Upload" +msgstr "" + +#. module: muk_web_fields_lobject +#. openerp-web +#: code:addons/muk_web_fields_lobject/static/src/js/lobject.js:72 +#, python-format +msgid "File Upload" +msgstr "" + +#. module: muk_web_fields_lobject +#. openerp-web +#: code:addons/muk_web_fields_lobject/static/src/xml/lobject.xml:31 +#: code:addons/muk_web_fields_lobject/static/src/xml/lobject.xml:32 +#, python-format +msgid "Select" +msgstr "" + +#. module: muk_web_fields_lobject +#. openerp-web +#: code:addons/muk_web_fields_lobject/static/src/js/lobject.js:71 +#, python-format +msgid "The selected file exceed the maximum file size of %s." +msgstr "" + +#. module: muk_web_fields_lobject +#. openerp-web +#: code:addons/muk_web_fields_lobject/static/src/js/lobject.js:92 +#, python-format +msgid "There was a problem while uploading your file" +msgstr "" + +#. module: muk_web_fields_lobject +#. openerp-web +#: code:addons/muk_web_fields_lobject/static/src/xml/lobject.xml:31 +#, python-format +msgid "Upload your file" +msgstr "" + +#. module: muk_web_fields_lobject +#. openerp-web +#: code:addons/muk_web_fields_lobject/static/src/xml/lobject.xml:34 +#, python-format +msgid "Uploading..." +msgstr "" + diff --git a/muk_web_fields_lobject/static/description/banner.png b/muk_web_fields_lobject/static/description/banner.png new file mode 100644 index 0000000..97a5f8b Binary files /dev/null and b/muk_web_fields_lobject/static/description/banner.png differ diff --git a/muk_web_fields_lobject/static/description/icon.png b/muk_web_fields_lobject/static/description/icon.png new file mode 100644 index 0000000..ca01c46 Binary files /dev/null and b/muk_web_fields_lobject/static/description/icon.png differ diff --git a/muk_web_fields_lobject/static/description/index.html b/muk_web_fields_lobject/static/description/index.html new file mode 100644 index 0000000..1a5e032 --- /dev/null +++ b/muk_web_fields_lobject/static/description/index.html @@ -0,0 +1,51 @@ +
+
+

MuK PGSQL Large Objects

+

PGSQL Large Objects Support

+

MuK IT GmbH - + www.mukit.at

+
+
+ +
+
+
+

Overview

+
+

This module allows the LargeObject Field to be used in different views. It is +installed automatically with the MuK Large Objects module. It has no direct visible effect on the system, but allows LargeObejct +fields to display in XML views.

+
+
+		    	
+<record id="view_lobject" model="ir.ui.view">
+    <field name="name">lobject.form</field>
+    <field name="model">lobject</field>
+    <field name="arch" type="xml">
+        <form string="LargeObjectModel">
+            <group>
+	            <field name="content_fname" />
+	            <field name="content" filename="content_fname" />
+            </group>
+        </form>
+    </field>
+</record> 
+		    	
+			
+
+
+
+ +
+

Help and Support

+ + +
\ No newline at end of file diff --git a/muk_web_fields_lobject/static/description/logo.png b/muk_web_fields_lobject/static/description/logo.png new file mode 100644 index 0000000..9427ce3 Binary files /dev/null and b/muk_web_fields_lobject/static/description/logo.png differ diff --git a/muk_web_fields_lobject/static/src/js/field_utils.js b/muk_web_fields_lobject/static/src/js/field_utils.js new file mode 100644 index 0000000..664aa38 --- /dev/null +++ b/muk_web_fields_lobject/static/src/js/field_utils.js @@ -0,0 +1,48 @@ +/********************************************************************************** +* +* 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_fields_lobject.field_utils', function(require) { +"use strict"; + +var core = require('web.core'); +var utils = require('web.utils'); +var field_utils = require('web.field_utils'); + +var _t = core._t; +var QWeb = core.qweb; + +function lobjectToBinsize(value) { + if (!utils.is_bin_size(value)) { + return utils.human_size(value.length); + } + return value; +} + +function formatLargeObject(value, field, options) { + if (!value) { + return ''; + } + return lobjectToBinsize(value); +} + +field_utils.format.lobject = formatLargeObject; +field_utils.parse.lobject = _.identity; + + +}); diff --git a/muk_web_fields_lobject/static/src/js/lobject.js b/muk_web_fields_lobject/static/src/js/lobject.js new file mode 100644 index 0000000..1eeae46 --- /dev/null +++ b/muk_web_fields_lobject/static/src/js/lobject.js @@ -0,0 +1,208 @@ +/********************************************************************************** +* +* 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_fields_lobject.lobject', function(require) { +"use strict"; + +var core = require('web.core'); +var utils = require('web.utils'); +var session = require('web.session'); +var framework = require('web.framework'); +var crash_manager = require('web.crash_manager'); +var registry = require('web.field_registry'); +var field_utils = require('web.field_utils'); + +var AbstractField = require('web.AbstractField'); + +var _t = core._t; +var QWeb = core.qweb; + +var AbstractFieldLargeObject = AbstractField.extend({ + events: _.extend({}, AbstractField.prototype.events, { + 'change .o_input_file': 'on_file_change', + 'click .o_select_file_button': function () { + this.$('.o_input_file').click(); + }, + 'click .o_clear_file_button': 'on_clear', + }), + init: function (parent, name, record) { + this._super.apply(this, arguments); + this.fields = record.fields; + this.useFileAPI = !!window.FileReader; + this.max_upload_size = 25 * 1024 * 1024; + if (!this.useFileAPI) { + var self = this; + this.fileupload_id = _.uniqueId('o_fileupload'); + $(window).on(this.fileupload_id, function () { + var args = [].slice.call(arguments).slice(1); + self.on_file_uploaded.apply(self, args); + }); + } + }, + destroy: function () { + if (this.fileupload_id) { + $(window).off(this.fileupload_id); + } + this._super.apply(this, arguments); + }, + on_file_change: function (e) { + var self = this; + var file_node = e.target; + if ((this.useFileAPI && file_node.files.length) || (!this.useFileAPI && $(file_node).val() !== '')) { + if (this.useFileAPI) { + var file = file_node.files[0]; + if (file.size > this.max_upload_size) { + var msg = _t("The selected file exceed the maximum file size of %s."); + this.do_warn(_t("File Upload"), _.str.sprintf(msg, utils.human_size(this.max_upload_size))); + return false; + } + var filereader = new FileReader(); + filereader.readAsDataURL(file); + filereader.onloadend = function (upload) { + var data = upload.target.result; + data = data.split(',')[1]; + self.on_file_uploaded(file.size, file.name, file.type, data); + }; + } else { + this.$('form.o_form_binary_form input[name=session_id]').val(this.getSession().session_id); + this.$('form.o_form_binary_form').submit(); + } + this.$('.o_form_binary_progress').show(); + this.$('button').hide(); + } + }, + on_file_uploaded: function (size, name) { + if (size === false) { + this.do_warn(_t("File Upload"), _t("There was a problem while uploading your file")); + console.warn("Error while uploading file : ", name); + } else { + this.on_file_uploaded_and_valid.apply(this, arguments); + } + this.$('.o_form_binary_progress').hide(); + this.$('button').show(); + }, + on_file_uploaded_and_valid: function (size, name, content_type, file_base64) { + this.set_filename(name); + this._setValue(file_base64); + this._render(); + }, + set_filename: function (value) { + var filename = this.attrs.filename; + if (filename && filename in this.fields) { + var changes = {}; + changes[filename] = value; + this.trigger_up('field_changed', { + dataPointID: this.dataPointID, + changes: changes, + viewType: this.viewType, + }); + } + }, + on_clear: function () { + this.set_filename(''); + this._setValue(false); + this._render(); + }, +}); + +var FieldLargeObject = AbstractFieldLargeObject.extend({ + template: 'FieldLObjectFile', + events: _.extend({}, AbstractFieldLargeObject.prototype.events, { + 'click': function (event) { + if (this.mode === 'readonly' && this.value && this.recordData.id) { + this.on_save_as(event); + } + }, + 'click .o_input': function () { + this.$('.o_input_file').click(); + }, + }), + supportedFieldTypes: ['lobject'], + init: function () { + this._super.apply(this, arguments); + this.filename_value = this.recordData[this.attrs.filename]; + }, + _renderReadonly: function () { + this.do_toggle(!!this.value); + if (this.value) { + this.$el.empty().append($("").addClass('fa fa-download')); + if (this.recordData.id) { + this.$el.css('cursor', 'pointer'); + } else { + this.$el.css('cursor', 'not-allowed'); + } + if (this.filename_value) { + this.$el.append(" " + this.filename_value); + } + } + if (!this.res_id) { + this.$el.css('cursor', 'not-allowed'); + } else { + this.$el.css('cursor', 'pointer'); + } + }, + _renderEdit: function () { + if (this.value) { + this.$el.children().removeClass('o_hidden'); + this.$('.o_select_file_button').first().addClass('o_hidden'); + this.$('.o_input').eq(0).val(this.filename_value || this.value); + } else { + this.$el.children().addClass('o_hidden'); + this.$('.o_select_file_button').first().removeClass('o_hidden'); + } + }, + set_filename: function (value) { + this._super.apply(this, arguments); + this.filename_value = value; + this.$('.o_save_file_button').prop('disabled', true); + }, + on_save_as: function (ev) { + if (!this.value) { + this._super.apply(this, arguments); + } else if (this.res_id) { + framework.blockUI(); + var c = crash_manager; + var filename_fieldname = this.attrs.filename; + this.getSession().get_file({ + 'url': '/web/lobject', + 'data': { + 'model': this.model, + 'id': this.res_id, + 'field': this.name, + 'filename_field': filename_fieldname, + 'filename': this.recordData[filename_fieldname] || null, + 'download': true, + 'data': utils.is_bin_size(this.value) ? null : this.value, + }, + 'complete': framework.unblockUI, + 'error': c.rpc_error.bind(c), + }); + ev.stopPropagation(); + } + }, +}); + +registry.add('lobject', FieldLargeObject); + +return { + AbstractFieldLargeObject: AbstractFieldLargeObject, + FieldLargeObject: FieldLargeObject +}; + +}); diff --git a/muk_web_fields_lobject/static/src/xml/lobject.xml b/muk_web_fields_lobject/static/src/xml/lobject.xml new file mode 100644 index 0000000..11f6d5d --- /dev/null +++ b/muk_web_fields_lobject/static/src/xml/lobject.xml @@ -0,0 +1,41 @@ + + + + + + + + +
+ + +
+
+ +
\ No newline at end of file diff --git a/muk_web_fields_lobject/template/assets.xml b/muk_web_fields_lobject/template/assets.xml new file mode 100644 index 0000000..1afc647 --- /dev/null +++ b/muk_web_fields_lobject/template/assets.xml @@ -0,0 +1,29 @@ + + + + + + +