from qommon.form import *


class FileWithPreviewAndStrongboxWidget(FileWithPreviewWidget):
    def render_hint(self, hint):
        t = CompositeWidget.render_hint(self, hint)
        if get_publisher().has_site_option('strongbox') and get_request().user and not self.preview:
            get_response().add_javascript(['../../aq/js/strongbox.js'])
            root_url = get_publisher().get_root_url()
            t += htmltext('''<p class="use-file-from-strongbox"><span
                               data-url="%smyspace/strongbox/pick"
                               rel="popup">%s</span></p>''') % (
                                root_url, _('Use file from strongbox'))
        if get_publisher().get_site_option('msp') is not None and not self.preview:
            get_response().add_javascript(['../../aq/js/msp.js'])
            root_url = get_publisher().get_root_url()
            t += htmltext('''<p class="use-file-from-msp"><span
                               data-src="%smsp/pick"
                               data-width="500"
                               data-height="400"
                               data-title="%s"
                               rel="popup">%s</span></p>''') % (
                                root_url, _('Pick a file on mon.Service-Public.fr'),
                                _('Use file from mon.Service-Public.fr'))
        return t
