Use advanced search modal in related docs edit widget

This commit is contained in:
Nicolas Demonte 2019-07-24 10:32:16 +02:00
parent 8c2e7c0fd6
commit ba1d9cd185
4 changed files with 65 additions and 0 deletions

View File

@ -72,6 +72,8 @@
for="Products.CMFPlone.interfaces.IPloneSiteRoot"
/>
<adapter factory=".widget.PFWBRelatedDocsFieldWidget" />
<!--
<browser:page
name="pfwbgedcollection.view"

View File

@ -14,6 +14,10 @@ msgstr ""
"Preferred-Encodings: utf-8 latin1\n"
"Domain: pfwbged.collection\n"
#: ../widget.py:55
msgid "Add"
msgstr "Ajouter"
#: ../portlet.py:170
msgid "Add Collection Portlet"
msgstr "Ajouter un portlet de collection"

View File

@ -17,6 +17,10 @@ msgstr ""
"Preferred-Encodings: utf-8 latin1\n"
"Domain: pfwbged.collection\n"
#: ../widget.py:55
msgid "Add"
msgstr ""
#: ../portlet.py:170
msgid "Add Collection Portlet"
msgstr ""

View File

@ -0,0 +1,55 @@
# -*- coding: utf8 -*-
from collective.dms.basecontent.relateddocs import IRelatedDocs
from collective.dms.basecontent.relateddocs import RelatedDocsWidget
from pfwbged.collection import _
from pfwbged.policy.interfaces import IPfwbgedPolicyLayer
from plone import api
from z3c.form.interfaces import IFieldWidget
from z3c.form.widget import FieldWidget
from zope.component import adapter
from zope.i18n import translate
from zope.interface import implementer
@adapter(IRelatedDocs, IPfwbgedPolicyLayer)
@implementer(IFieldWidget)
def PFWBRelatedDocsFieldWidget(field, request):
return FieldWidget(field, PFWBRelatedDocsWidget(field.display_backrefs, request))
class PFWBRelatedDocsWidget(RelatedDocsWidget):
def js_extra(self):
return """\
$('#%(id)s-widgets-query').each(function() {
if($(this).siblings('a.pfwbSearchButton').length > 0) { return; }
$(document.createElement('a'))
.attr({
'href': '%(search_url)s'
})
.html('%(anchor_text)s')
.addClass('pfwbSearchButton')
.prepOverlay({
subtype: 'iframe',
config: {
onBeforeClose : function (e) {
var selectedRows = this.getOverlay().find("iframe").contents().find("tr.selected");
var input_box = $('#%(id)s-widgets-query');
selectedRows.each(function(index, row) {
var path = $(row).find(".colour-column input").data("value");
var title = $(row).find(".title-column a").html();
formwidget_autocomplete_new_value(input_box, path, title);
});
return true;
}
}
})
.insertAfter($(this));
$(this).after(" ");
});
""" % dict(search_url=api.portal.get().absolute_url() + '/pfwbsearch?iframe',
id=self.name.replace('.', '-'),
anchor_text=translate(_(u'Add'), context=self.request))