Exemple #1
0
    def js_extra(self):
        # Get bound source to extract path
        source = self.bound_source
        form_url = self.request.getURL()
        url = "%s/++widget++%s/@@contenttree-fetch" % (form_url, self.name)

        return """\

                $('#%(id)s-widgets-query').each(function() {
                    if($(this).siblings('input.searchButton').length > 0) { return; }
                    $(document.createElement('input'))
                        .attr({
                            'type': 'button',
                            'value': '%(button_val)s'
                        })
                        .addClass('searchButton')
                        .click( function () {
                            var parent = $(this).parents("*[id$='-autocomplete']")
                            var window = parent.siblings("*[id$='-contenttree-window']")
                            window.showDialog('%(url)s', %(expandSpeed)d);
                            $('#' + parent.attr('id').replace('autocomplete', 'contenttree')).contentTree(
                    {
                        script: '%(url)s',
                        folderEvent: '%(folderEvent)s',
                        selectEvent: '%(selectEvent)s',
                        expandSpeed: %(expandSpeed)d,
                        collapseSpeed: %(collapseSpeed)s,
                        multiFolder: %(multiFolder)s,
                        multiSelect: %(multiSelect)s,
                        rootUrl: '%(rootUrl)s'
                    },
                    function(event, selected, data, title) {
                        // alert(event + ', ' + selected + ', ' + data + ', ' + title);
                    }
                );
                        }).insertAfter($(this));
                });
                $('#%(id)s-contenttree-window').find('.contentTreeAdd').unbind('click').click(function () {
                    $(this).contentTreeAdd();
                });
                $('#%(id)s-contenttree-window').find('.contentTreeCancel').unbind('click').click(function () {
                    $(this).contentTreeCancel();
                });
                $('#%(id)s-widgets-query').after(" ");

        """ % dict(url=url,
                   id=self.name.replace('.', '-'),
                   folderEvent=self.folderEvent,
                   selectEvent=self.selectEvent,
                   expandSpeed=self.expandSpeed,
                   collapseSpeed=self.collapseSpeed,
                   multiFolder=str(self.multiFolder).lower(),
                   multiSelect=str(self.multi_select).lower(),
                   rootUrl=source.navigation_tree_query['path']['query'],
                   name=self.name,
                   klass=self.klass,
                   title=self.title,
                   button_val=translate(_(u'label_contenttree_browse',
                                          default=u'browse...'),
                                        context=self.request))
    def js_extra(self):
        # Get bound source to extract path
        source = self.bound_source
        form_url = self.request.getURL()
        url = "%s/++widget++%s/@@contenttree-fetch" % (form_url, self.name)

        return """\

                $('#%(id)s-widgets-query').each(function() {
                    if($(this).siblings('input.searchButton').length > 0) { return; }
                    $(document.createElement('input'))
                        .attr({
                            'type': 'button',
                            'value': '%(button_val)s'
                        })
                        .addClass('searchButton')
                        .click( function () {
                            var parent = $(this).parents("*[id$='-autocomplete']")
                            var window = parent.siblings("*[id$='-contenttree-window']")
                            window.showDialog('%(url)s', %(expandSpeed)d);
                            $('#' + parent.attr('id').replace('autocomplete', 'contenttree')).contentTree(
                    {
                        script: '%(url)s',
                        folderEvent: '%(folderEvent)s',
                        selectEvent: '%(selectEvent)s',
                        expandSpeed: %(expandSpeed)d,
                        collapseSpeed: %(collapseSpeed)s,
                        multiFolder: %(multiFolder)s,
                        multiSelect: %(multiSelect)s,
                        rootUrl: '%(rootUrl)s'
                    },
                    function(event, selected, data, title) {
                        // alert(event + ', ' + selected + ', ' + data + ', ' + title);
                    }
                );
                        }).insertAfter($(this));
                });
                $('#%(id)s-contenttree-window').find('.contentTreeAdd').unbind('click').click(function () {
                    $(this).contentTreeAdd();
                });
                $('#%(id)s-contenttree-window').find('.contentTreeCancel').unbind('click').click(function () {
                    $(this).contentTreeCancel();
                });
                $('#%(id)s-widgets-query').after(" ");

        """ % dict(url=url,
                   id=self.name.replace('.', '-'),
                   folderEvent=self.folderEvent,
                   selectEvent=self.selectEvent,
                   expandSpeed=self.expandSpeed,
                   collapseSpeed=self.collapseSpeed,
                   multiFolder=str(self.multiFolder).lower(),
                   multiSelect=str(self.multi_select).lower(),
                   rootUrl=source.navigation_tree_query['path']['query'],
                   name=self.name,
                   klass=self.klass,
                   title=self.title,
                   button_val=translate(
                       _(u'label_contenttree_browse', default=u'browse...'),
                       context=self.request))
    def __call__(self):

        # We want to check that the user was indeed allowed to access the
        # form for this widget. We can only this now, since security isn't
        # applied yet during traversal.
        self.validate_access()

        widget = self.context
        context = widget.context

        # Update the widget before accessing the source.
        # The source was only bound without security applied
        # during traversal before.
        widget.update()
        source = widget.bound_source

        # Convert token from request to the path to the object
        token = self.request.form.get('href', None)
        directory = self.context.bound_source.tokenToPath(token)

        navtree_query = source.navigation_tree_query.copy()
        navtree_query['path'] = {'query': directory}

        if 'is_default_page' not in navtree_query:
            navtree_query['is_default_page'] = False
        if navtree_query['is_default_page'] in [(True,False), (False, True)]:
            del navtree_query['is_default_page']

        content = context
        if not IAcquirer.providedBy(content):
            content = closest_content(context)

        catalog = getToolByName(content, 'portal_catalog')
        results = catalog(navtree_query)

        if len(results) > 0:
            obj = results[0].getObject()

            preview = queryMultiAdapter(
                (obj, self.context), IContentTreeWidgetPreview)

            if preview is None:
                return _(u"No preview available.")

            return preview()
 def js_extra(self):
     # Get bound source to extract path
     source = self.bound_source
     form_url = self.request.getURL()
     url = "%s/++widget++%s/@@contenttree-fetch" % (form_url, self.name)
     return ADDITIONAL_JS % dict(
         url=url,
         id=self.name.replace('.', '-'),
         folderEvent=self.folderEvent,
         selectEvent=self.selectEvent,
         expandSpeed=self.expandSpeed,
         collapseSpeed=self.collapseSpeed,
         multiFolder=str(self.multiFolder).lower(),
         multiSelect=str(self.multi_select).lower(),
         rootUrl=source.navigation_tree_query['path']['query'],
         name=self.name,
         klass=self.klass,
         title=self.title,
         button_val=translate(_(u'label_contenttree_browse',
                                default=u'browse...'),
                              context=self.request),
     )
Exemple #5
0
 def js_extra(self):
     # Get bound source to extract path
     source = self.bound_source
     form_url = self.request.getURL()
     url = "%s/++widget++%s/@@contenttree-fetch" % (form_url, self.name)
     return ADDITIONAL_JS % dict(
         url=url,
         id=self.name.replace('.', '-'),
         folderEvent=self.folderEvent,
         selectEvent=self.selectEvent,
         expandSpeed=self.expandSpeed,
         collapseSpeed=self.collapseSpeed,
         multiFolder=str(self.multiFolder).lower(),
         multiSelect=str(self.multi_select).lower(),
         rootUrl=source.navigation_tree_query['path']['query'],
         name=self.name,
         klass=self.klass,
         title=self.title,
         button_val=translate(
             _(u'label_contenttree_browse', default=u'browse...'),
             context=self.request
         ),
     )