Sha256: a2424fed7e20ca17ce9fe35f7c71541f263f4daa94e7266ba8ebce03e0ac3dc8

Contents?: true

Size: 1.83 KB

Versions: 18

Compression:

Stored size: 1.83 KB

Contents

<!-- Adds a small button to a select in order to create a new record within a modal

For example, if I want to create a new project in stories/new.dryml:

    <new-page>
      <form:>
        <field-list:>
          <project-view:><select-one-or-new/></project-view:>
        </field-list:>
      </form:>
    </new-page>

You also need to modify the create action of the new record. projects_controller.rb:

    def create
      hobo_create do
        @this = Story.new(:project => @project)  if request.xhr?
        create_response
      end
    end

If you are instead in stories/edit.dryml, you need to make sure the new project is autoselected. Add a couple of lines to the previous code:

    def create
      hobo_create do
        if request.xhr?
          @this = Story.new(:project => @project)
          ajax_update_response(params[:render].values, {}, {:postamble => 
            "$('#select-one-or-new-Project').val(#{@project.id});"})
        else
          create_response
        end
      end
    end

-->
<def tag="select-one-or-new">
  <%# Partial %>
  <div part="select-one-or-new" id="select-one-or-new-#{this_field}" class="pull-left">
    <div class="input-append">
      <select-one id="select-one-or-new-#{this_type}"/>
      <%# Button that triggers the modal %>
      <modal-open-button style="margin-top:-5px;" modal="myModal-#{this_field}">+</modal-open-button>
    </div>
  </div>

  <%# Modal %>
  <modal id="myModal-#{this_field}">
    <modal:>
      <formlet with="&this_type.new" update="select-one-or-new-#{this_field}"
             complete="$('#myModal-#{this_field}').modal('hide')">
        <modal-header><%= t('hobo.actions.create', :model => this_type.to_s) %></modal-header>
        <div class="modal-body">
          <field-list size="0"/>
        </div>
        <modal-form-footer/>
      </formlet>
    </modal:>
  </modal>
</def>

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
hobo_bootstrap_ui-2.2.6 taglibs/select_one_or_new.dryml
hobo_bootstrap_ui-2.2.5 taglibs/select_one_or_new.dryml
hobo_bootstrap_ui-2.2.4 taglibs/select_one_or_new.dryml
hobo_bootstrap_ui-2.2.3 taglibs/select_one_or_new.dryml
hobo_bootstrap_ui-2.2.2 taglibs/select_one_or_new.dryml
hobo_bootstrap_ui-2.2.0 taglibs/select_one_or_new.dryml
hobo_bootstrap_ui-2.1.1 taglibs/select_one_or_new.dryml
hobo_bootstrap_ui-2.1.0 taglibs/select_one_or_new.dryml
hobo_bootstrap_ui-2.1.0.pre4 taglibs/select_one_or_new.dryml
hobo_bootstrap_ui-2.1.0.pre3 taglibs/select_one_or_new.dryml
hobo_bootstrap_ui-2.1.0.pre2 taglibs/select_one_or_new.dryml
hobo_bootstrap_ui-2.1.0.pre1 taglibs/select_one_or_new.dryml
hobo_bootstrap_ui-2.0.1 taglibs/select_one_or_new.dryml
hobo_bootstrap_ui-2.0.0 taglibs/select_one_or_new.dryml
hobo_bootstrap_ui-2.0.0.pre10 taglibs/select_one_or_new.dryml
hobo_bootstrap_ui-2.0.0.pre9 taglibs/select_one_or_new.dryml
hobo_bootstrap_ui-2.0.0.pre8 taglibs/select_one_or_new.dryml
hobo_bootstrap_ui-2.0.0.pre7 taglibs/select_one_or_new.dryml