Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #874 (closed enhancement: fixed)

Opened 13 years ago

Last modified 12 years ago

[PATCH] Jump Menu widget

Reported by: fredlin Owned by: fredlin
Priority: normal Milestone:
Component: TG Widgets Version: 0.9a6
Severity: normal Keywords: jump menu
Cc:

Description

select a host from the menu, the page will be redirect to that link.

Dreamweaver Users may familiar with this widget.

from turbogears.widgets.base import JSSource

class JumpMenuField(SelectionField):
    js = JSSource("""
    <!--
    function TG_jumpMenu(targ,f,restore){ 
      eval(targ+".location='"+f.options[f.selectedIndex].value+"'");
      if (restore) f.selectedIndex=0;
    }
    //-->
    """)
    
    template = """
    <select xmlns:py="http://purl.org/kid/ns#"
        name="${name}"
        class="${field_class}"
        id="${field_id}" 
        onchange="TG_jumpMenu('parent',this,0)"
        py:attrs="attrs"
    >
        <optgroup py:for="group, options in grouped_options"
            label="${group}"
            py:strip="not group"
        >
            <option py:for="value, desc, attrs in options"
                value="${value}"
                py:attrs="attrs"
                py:content="desc"
            />
        </optgroup>
    </select>
    """
    javascript = [js]
    _selected_verb = 'selected'
    params = ["attrs"]
    params_doc = {'attrs' : 'Dictionary containing extra (X)HTML attributes for'
                            ' the select tag'}
    attrs = {}

class JumpMenuFieldDesc(CoreWD):
    name = "Jump Menu Field"
    for_widget = JumpMenuField("your_jump_menu_field", 
                                   options=[('http://www.python.org', "Python"), 
                                            ('http://www.turbogears.org', "TurboGears"), 
                                            ('http://www.python.org/pypi', "Cheese Shop"),
                                            ('http://www.pythonware.com/daily/', "Daily Python")],
                                   default='http://www.turbogears.org')

Attachments

jumpmenu.zip Download (12.2 KB) - added by fredlin 13 years ago.
jumpmenu widget plugin

Change History

comment:1 Changed 13 years ago by fredlin

Excuse me,

I think its better to call it "JumpMenu?" but not "JumpMenuField?",

since its not a field to be filled anymore.

comment:2 Changed 13 years ago by michele

Personally I don't think we should include this in TG core, we agreed on shipping only form-oriented widgets and this is not a FormField/InputWidget? (no input coming in), that's why you shouldn't even subclass SelectionField? that provides far more feature, it seems you just need the option managing things but you can also get away without an update_data method most probably.

Moreover 1.0 is in feature freeze.

comment:3 Changed 13 years ago by godoy

I have the same opinion and this is why I asked on the trunk mailing list about making this an external widget... It can be done with "tg-admin quickstart -t tgwidget" and uploaded to CheeseShop?.

I'm also -1 on this going into TG core.

comment:4 Changed 13 years ago by godoy

  • Version changed from 0.9a5 to 0.9a6
  • Component changed from CherryPy to Widgets

This is about widgets, so I'm fixing the component in this ticket. Also, since this was posted on the trunk ML, I believe it should have been based at least on TG 0.9a6, so I also changed the version.

Changed 13 years ago by fredlin

jumpmenu widget plugin

comment:5 Changed 13 years ago by fredlin

Revised one

from turbogears.widgets import JSSource, SelectionField,CoreWD

class JumpMenu(SelectionField):
    """
    Choose a link from the menu, 
    the page will be redirect to the selected link.
    """
    js = JSSource("""
    <!--
    function TG_jumpMenu(targ,f,restore){ 
      eval(targ+".location='"+f.options[f.selectedIndex].value+"'");
      if (restore) f.selectedIndex=0;
    }
    //-->
    """)
    
    template = """
    <select xmlns:py="http://purl.org/kid/ns#"
        name="${name}"
        class="${field_class}"
        id="${field_id}" 
        onchange="TG_jumpMenu('parent',this,0)"
        py:attrs="attrs"
    >
        <optgroup py:for="group, options in grouped_options"
            label="${group}"
            py:strip="not group"
        >
            <option py:for="value, desc, attrs in options"
                value="${value}"
                py:attrs="attrs"
                py:content="desc"
            />
        </optgroup>
    </select>
    """
    javascript = [js]
    _selected_verb = 'selected'
    params = ["attrs"]
    params_doc = {'attrs' : 'Dictionary containing extra (X)HTML attributes for'
                            ' the select tag'}
    attrs = {}

#jumpmenu = JumpMenu()

class JumpMenuDesc(CoreWD):
    name = "Jump Menu"
    for_widget = JumpMenu("your_jump_menu_field",
                          options=[('http://www.python.org', "Python"),
                                   ('http://www.turbogears.org', "TurboGears"),
                                   ('http://www.python.org/pypi', "Cheese Shop"),
                                   ('http://www.pythonware.com/daily/', "Daily Python")],
                          #default='http://www.turbogears.org'
)

comment:6 Changed 13 years ago by roger.demetrescu

Making this one visible in "Pending Patches" report

comment:7 Changed 13 years ago by roger.demetrescu

  • Summary changed from Jump Menu widget to [PATCH] Jump Menu widget

:)

comment:8 Changed 13 years ago by fredlin

  • Owner changed from anonymous to fredlin

comment:9 Changed 13 years ago by fredlin

  • Status changed from new to closed
  • Resolution set to fixed
Note: See TracTickets for help on using tickets.