 
 #TODO this code smells and isn't very DRY, make it better later
 #TODO learn rails js conventions
-#TODO panel-dropdown should be a class!!!
 tab_index = 0
 append_bucket_item_panel = (index, bucket_item, collapsed=true) ->
     class_in_or_empty = ''

    $.when(populate_bucket_dropdown_and_items 'New Stuff').then ->
        make_primary_panel $('#sortable-bucket-item-list').find('.panel:first')
    $(document).keypress (e) ->
        get_hotkey_command = (e) ->
            e = e or window.event
            if e.altKey
                return String.fromCharCode(e.which or e.charCode or e.keyCode)
            ''
        switch get_hotkey_command(e)
            when 'l'
                if not $('.bucket-dropdown').hasClass 'open'

    bucket_item_panel += variable_fields
    bucket_item_panel += """
                    <textarea class='panel-input'
                              placeholder='notes'>#{bucket_item['notes']}</textarea>
                    #{move_to_button_or_empty}
                    <button type='button'
                            class='btn btn-default panel-input'>
                        Save
                    </button>
                    <button id='last-input#{index}'
                            type='button' 
                            class='btn btn-default panel-input'>
                        Cancel
                    </button>
                </div>
            </div>
        </li>
    """
    $('#sortable-bucket-item-list').append(bucket_item_panel)
    panel_inputs = $('#panel' + index).find('.panel-input')
    i = 0
    for panel_input in panel_inputs
        i_next = i + 1
        if i_next >= panel_inputs.length then i_next = 0
        panel_input.next_input = panel_inputs[i_next]

        i_prev = i - 1
        if i_prev < 0 then i_prev = panel_inputs.length - 1
        panel_input.prev_input = panel_inputs[i_prev]

        $(panel_input).keypress (e) ->
            if get_hotkey_command(e) == '\t'
                e.preventDefault()
                if e.shiftKey
                    console.log this.prev_input
                    $(this.prev_input).focus()
                else
                    console.log this.next_input
                    $(this.next_input).focus()

        i++

num_bucket_items = 0
populate_bucket_items = (bucket) ->
