Expose class into a component

41 views
Skip to first unread message

CrC Nommack

unread,
Feb 12, 2015, 10:52:54 AM2/12/15
to web...@googlegroups.com
Hi guys, I have a problem that I don't really know how to deal with.
I will explain the context:
I have an index.html that calls two components (LOAD)
One of the components is a controller with an index function and within this function I put the following code:

def index():
path = os.path.join(request.folder, 'static', 'folder_files')
related_media = Expose(path, basename='folder_files')

return dict(related_media=related_media)

The view is trivial:

{{=related_media}}

The problem is that when I click for example in a folder the result is not loaded in the component.

Is it possible to make it work only inside the component?

Thank you very much for your help.
Kind regards

Leonel Câmara

unread,
Feb 12, 2015, 11:38:31 AM2/12/15
to web...@googlegroups.com
You could make the links in the loaded component have a cid with the same id so they will load in the same place. I have never used Expose so this may not be entirely correct

{{
related_html
= DIV(
            H2
(related_media.breadcrumbs(related_media.basename)),
            related_media
.paragraph or '',
            related_media
.table_folders(),
            related_media
.table_files()
)


for a in related_html.elements('a'):
    a
['cid'] = request.cid
pass
}}
{{=related_html}}





I'm going around expose xml method because we need to change the DOM.

Anthony

unread,
Feb 12, 2015, 11:41:00 AM2/12/15
to web...@googlegroups.com
For now you'll probably have to write some custom JS to catch link clicks and load the URL into the component div via Ajax. We could probably add an Ajax trap option to Expose to handle this automatically. Feel free to submit a github issue with this feature request.

Anthony

CrC Nommack

unread,
Feb 13, 2015, 2:23:40 AM2/13/15
to web...@googlegroups.com
Thank you very much Leonel.
It worked!!

The only thing is that if I click on a picture it doesn't open as a picture but as raw data.
Any idea?

Thank you very much.
Kind regards.

CrC Nommack

unread,
Feb 13, 2015, 2:25:49 AM2/13/15
to web...@googlegroups.com
Anthony thank you very much for your answer.
As Leonel's answer partially worked I will try it first before going with yours.
Anyway thank you very much.

Kind regards

Anthony

unread,
Feb 13, 2015, 9:30:18 AM2/13/15
to
If you specify the name of the target div for the component (e.g., LOAD(..., target='expose')), the JS would be something like this:

$('#expose a').click(function(e) {
    e
.preventDefault();
    $
.web2py.component(this.href, 'expose');
});

Anthony
Reply all
Reply to author
Forward
0 new messages