diff --git a/cmis_web/__init__.py b/cmis_web/__init__.py index 872b1862..6a7770d5 100644 --- a/cmis_web/__init__.py +++ b/cmis_web/__init__.py @@ -1,2 +1 @@ -# Copyright 2016 ACSONE SA/NV () -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from . import mixins diff --git a/cmis_web/i18n/fr.po b/cmis_web/i18n/fr.po index e54acefb..397ced3e 100644 --- a/cmis_web/i18n/fr.po +++ b/cmis_web/i18n/fr.po @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 13.0+e\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-05-10 09:22+0000\n" -"PO-Revision-Date: 2023-05-10 09:22+0000\n" +"POT-Creation-Date: 2023-12-01 08:20+0000\n" +"PO-Revision-Date: 2023-12-01 08:20+0000\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -88,6 +88,11 @@ msgstr "Ajouter un document" msgid "Alfresco Error" msgstr "Erreur Alfresco" +#. module: cmis_web +#: model:ir.model,name:cmis_web.model_cmis_document_link_src_folder_mixin +msgid "Allow to search files to link on parent record folders cmis" +msgstr "" + #. module: cmis_web #. openerp-web #: code:addons/cmis_web/static/src/xml/form_widgets.xml:0 @@ -169,6 +174,11 @@ msgstr "Cliquez ici pour voir les détails techniques" msgid "Close" msgstr "Fermer" +#. module: cmis_web +#: model:ir.model.fields,field_description:cmis_web.field_cmis_document_link_src_folder_mixin__cmis_document_link_src_folders +msgid "Cmis Document Link Src Folders" +msgstr "" + #. module: cmis_web #. openerp-web #: code:addons/cmis_web/static/src/js/form_widgets.js:0 @@ -266,6 +276,7 @@ msgstr "Veuillez d'abord enregistrer votre objet une première fois." #. openerp-web #: code:addons/cmis_web/static/src/xml/form_widgets.xml:0 #: code:addons/cmis_web/static/src/xml/form_widgets.xml:0 +#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0 #, python-format msgid "Created" msgstr "Date de création" @@ -303,10 +314,16 @@ msgstr "Supprimer" #: code:addons/cmis_web/static/src/xml/form_widgets.xml:0 #: code:addons/cmis_web/static/src/xml/form_widgets.xml:0 #: code:addons/cmis_web/static/src/xml/form_widgets.xml:0 +#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0 #, python-format msgid "Description" msgstr "" +#. module: cmis_web +#: model:ir.model.fields,field_description:cmis_web.field_cmis_document_link_src_folder_mixin__display_name +msgid "Display Name" +msgstr "" + #. module: cmis_web #. openerp-web #: code:addons/cmis_web/static/src/js/form_widgets.js:0 @@ -339,6 +356,11 @@ msgstr "Premier" msgid "Folder Name:" msgstr "Nom du répertoire:" +#. module: cmis_web +#: model:ir.model.fields,field_description:cmis_web.field_cmis_document_link_src_folder_mixin__id +msgid "ID" +msgstr "" + #. module: cmis_web #. openerp-web #: code:addons/cmis_web/static/src/xml/form_widgets.xml:0 @@ -397,6 +419,11 @@ msgstr "Dernière modification par" msgid "Last Modified Date" msgstr "Date de dernière modification" +#. module: cmis_web +#: model:ir.model.fields,field_description:cmis_web.field_cmis_document_link_src_folder_mixin____last_update +msgid "Last Modified on" +msgstr "" + #. module: cmis_web #. openerp-web #: code:addons/cmis_web/static/src/js/form_widgets.js:0 @@ -437,7 +464,7 @@ msgstr "Chargement en cours..." #: code:addons/cmis_web/static/src/js/form_widgets.js:0 #, python-format msgid "Loading..." -msgstr "Chargement en cours..." +msgstr "Chargement..." #. module: cmis_web #. openerp-web @@ -464,6 +491,7 @@ msgstr "Mineure" #. openerp-web #: code:addons/cmis_web/static/src/xml/form_widgets.xml:0 #: code:addons/cmis_web/static/src/xml/form_widgets.xml:0 +#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0 #, python-format msgid "Modified" msgstr "Date de modification" @@ -490,6 +518,7 @@ msgstr "Actions supplémentaires" #: code:addons/cmis_web/static/src/xml/form_widgets.xml:0 #: code:addons/cmis_web/static/src/xml/form_widgets.xml:0 #: code:addons/cmis_web/static/src/xml/form_widgets.xml:0 +#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0 #, python-format msgid "Name" msgstr "Nom" @@ -516,6 +545,13 @@ msgstr "Suivant" msgid "No data available in table" msgstr "Aucun élément à afficher" +#. module: cmis_web +#. openerp-web +#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0 +#, python-format +msgid "No document found." +msgstr "" + #. module: cmis_web #. openerp-web #: code:addons/cmis_web/static/src/js/form_widgets.js:0 @@ -651,6 +687,20 @@ msgstr "Racine" msgid "Rotate" msgstr "Tourner" +#. module: cmis_web +#. openerp-web +#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0 +#, python-format +msgid "Search" +msgstr "Rechercher" + +#. module: cmis_web +#. openerp-web +#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0 +#, python-format +msgid "Search based on document name" +msgstr "Recherche sur base du nom et du contenu" + #. module: cmis_web #. openerp-web #: code:addons/cmis_web/static/src/js/form_widgets.js:0 @@ -686,6 +736,16 @@ msgstr "Affichage de l'élément 0 à 0 sur 0 élément" msgid "Showing _START_ to _END_ of _TOTAL_ entries" msgstr "Affichage de l'élément _START_ à _END_ sur _TOTAL_ éléments" +#. module: cmis_web +#. openerp-web +#: code:addons/cmis_web/static/src/js/form_widgets.js:0 +#, python-format +msgid "" +"The search criteria should at least contains 2 characters. Or empty if you " +"want to see all documents." +msgstr "Le critère de recherche doit au moins 2 caractères. Vous pouvez vider " +"la recherche pour afficher tout les documents." + #. module: cmis_web #. openerp-web #: code:addons/cmis_web/static/src/xml/form_widgets.xml:0 @@ -700,9 +760,11 @@ msgstr "Titre" #: code:addons/cmis_web/static/src/js/form_widgets.js:0 #, python-format msgid "" -"Unable to retrieve the document. The resource might have been deleted " -"in the CMIS." -msgstr "Impossible de récupérer le document. La ressource a peut être été supprimée dans la GED." +"Unable to retrieve the document. The resource might have been deleted in the" +" CMIS." +msgstr "" +"Impossible de récupérer le document. La ressource a peut être été supprimée " +"dans la GED." #. module: cmis_web #. openerp-web @@ -729,6 +791,7 @@ msgstr "Mise à jour du contenu de " #. openerp-web #: code:addons/cmis_web/static/src/xml/form_widgets.xml:0 #: code:addons/cmis_web/static/src/xml/form_widgets.xml:0 +#: code:addons/cmis_web/static/src/xml/form_widgets.xml:0 #, python-format msgid "Version" msgstr "" diff --git a/cmis_web/mixins/__init__.py b/cmis_web/mixins/__init__.py new file mode 100644 index 00000000..ed82140a --- /dev/null +++ b/cmis_web/mixins/__init__.py @@ -0,0 +1 @@ +from . import cmis_document_link_src_folder_mixin diff --git a/cmis_web/mixins/cmis_document_link_src_folder_mixin.py b/cmis_web/mixins/cmis_document_link_src_folder_mixin.py new file mode 100644 index 00000000..06daed17 --- /dev/null +++ b/cmis_web/mixins/cmis_document_link_src_folder_mixin.py @@ -0,0 +1,41 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import json + +from odoo import api, fields, models +from odoo.tools.safe_eval import safe_eval + + +class CmisDocumentLinkSrcFolderMixin(models.AbstractModel): + _name = "cmis.document.link.src.folder.mixin" + _description = "Allow to search files to link on parent record folders cmis" + + cmis_document_link_src_folders = fields.Char( + compute='_compute_cmis_document_link_src_folders', + ) + + def _compute_cmis_document_link_src_folders(self): + fnames = self._get_cmis_document_link_src_folders_fnames() + for rec in self: + folders = [] + for fname in fnames: + folder_value = safe_eval(f"rec.{fname}", globals_dict={ + "rec": rec, + }) + if folder_value: + folders.append(folder_value) + rec.cmis_document_link_src_folders = json.dumps(folders) + + # maybe consider to add dynamically the field in the view + # def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): + + @api.model + def _get_cmis_document_link_src_folders_fnames(self): + """ + Should return a list of field names linked to the current record: + For example, if we have a cmis_document on a sale.order.line, and we want to display + documents from the folder of a sale order, we would need to set "order_id.cmis_folder" + Then it will be evaluated with "rec.order_id.cmis_folder" where rec is a sale.order.line + """ + raise NotImplementedError() diff --git a/cmis_web/static/src/js/form_widgets.js b/cmis_web/static/src/js/form_widgets.js index 1747a8d7..36086d3c 100644 --- a/cmis_web/static/src/js/form_widgets.js +++ b/cmis_web/static/src/js/form_widgets.js @@ -347,6 +347,11 @@ odoo.define('cmis_web.form_widgets', function (require) { var CmisLinkDocumentDialog = Dialog.extend({ template: 'CmisLinkDocumentDialog', + events: { + 'click .btn-search': 'on_click_search', + 'keypress .search-input': 'on_keypress_search_input', + }, + init: function (parent, parentCmisObject) { var self = this; var options = { @@ -376,6 +381,116 @@ odoo.define('cmis_web.form_widgets', function (require) { title: _t("Link Document"), }; this._super(parent, options); + this.parent = parent; + this.cmis_src_folder_fname = parent.nodeOptions.link_document_src_folders; + this.search_enabled = ( + this.cmis_src_folder_fname !== undefined + && this.parent.recordData.hasOwnProperty(this.cmis_src_folder_fname) + && this.parent.recordData[this.cmis_src_folder_fname] !== "[]" + ); + this.search_results = []; + }, + + wrap_cmis_object: function (cmisObject) { + if (_.has(cmisObject, 'object')) { + cmisObject = cmisObject.object; + } + return new CmisObjectWrapper(this, cmisObject, this.parent.cmis_session); + }, + + start: function() { + this._super.apply(this, arguments); + this.$search_input = this.$el.find('.search-input'); + this.$document_list = this.$el.find('.document-list'); + this.$identifier = this.$el.find("input[id='identifier']") + this.on_click_search(); + this.add_link_events(); + }, + + get_folder_cmis_ids: function() { + let record = this.parent.recordData; + return JSON.parse(record[this.cmis_src_folder_fname]); + }, + + on_keypress_search_input: function (e) { + if (e.keyCode === 13) { + e.preventDefault(); + e.stopPropagation(); + this.on_click_search(); + } + }, + + on_click_search: function (e) { + let self = this; + let $input = self.$search_input; + let search_value = $input.val(); + if (search_value.length === 1) { + alert(_t( + "The search criteria should at least contains 2 characters. " + + "Or empty if you want to see all documents." + )) + return false; + } + + let parent = self.parent; + let cmis_session = parent.cmis_session; + let cmis_folders = self.get_folder_cmis_ids() + + let tree_where_clauses = []; + _.each(cmis_folders, function(cmis_folder) { + tree_where_clauses.push("IN_TREE('" + cmis_folder + "')"); + }); + + let fnames_to_search = [ + "cmis:name", + "cmis:description", + ] + let text_clauses = []; + if (search_value.length > 0) { + text_clauses.push("CONTAINS('"+ search_value +"')"); + } + _.each(fnames_to_search, function(fname_to_search) { + text_clauses.push(fname_to_search + " like '%" + search_value + "%'"); + }); + + let query = ( + "SELECT * FROM cmis:document " + + "WHERE (" + tree_where_clauses.join(" OR ") + ") "+ + " AND " + + "(" + + text_clauses.join(" OR ") + + ")" + ) + + return cmis_session.query(query).ok(function (search_result) { + let results = []; + _.each(search_result.results, function(result) { + results.push(self.wrap_cmis_object(result)); + }) + self.search_results = results; + self.display_document_list(); + }); + }, + + display_document_list: function() { + let $document_list = QWeb.render("CmisLinkDocumentDialogDocumentList", { + widget: this, + }); + this.$document_list.html($document_list); + this.add_link_events(); + }, + + add_link_events: function() { + let self = this; + this.$document_list.find('.link-button').click(function(e) { + let $target = $(e.target); + let $tr = $target.closest('tr'); + let cmis_object_id = $tr.data('cmis-id'); + self.$identifier.val(cmis_object_id); + if (self.check_validity()) { + self.on_click_link(); + } + }); }, on_click_link: function () { @@ -401,6 +516,7 @@ odoo.define('cmis_web.form_widgets', function (require) { var options = { buttons: [ { + text: _t("Add"), classes: "btn-primary", click: function (e) { diff --git a/cmis_web/static/src/scss/form_widgets.scss b/cmis_web/static/src/scss/form_widgets.scss index a4ef7930..dd44e7dc 100644 --- a/cmis_web/static/src/scss/form_widgets.scss +++ b/cmis_web/static/src/scss/form_widgets.scss @@ -232,3 +232,10 @@ div.cmis-version-row { .o_field_x2many td.o_field_cmis_document_cell { overflow: auto !important; } + +.cmis_link_document { + .document-list { + margin-top: 5px; + } +} + diff --git a/cmis_web/static/src/xml/form_widgets.xml b/cmis_web/static/src/xml/form_widgets.xml index 0ad5765f..4c80193e 100644 --- a/cmis_web/static/src/xml/form_widgets.xml +++ b/cmis_web/static/src/xml/form_widgets.xml @@ -360,8 +360,8 @@ -