camdub/Internships

View on GitHub
app/views/internships/_form.html.erb

Summary

Maintainability
Test Coverage
<script>
/*
    $(function(){
        $("#internship_provider_id").change(function(){
            $.ajax({
                url: '/provider_contacts.json',
                data: {"provider_id":$("#internship_provider_id").val()},
                dataType: 'json',
                success: function(data){
                    $("#internship_provider_contact_id").html('');
                    var provider_contact = $("#internship_provider_contact_id").val();
                    $.each(data, function(){
                        var selected = '';
                        if(provider_contact == this.provider_contact.id){
                            selected = 'selected="selected"';
                        }
                        $("#internship_provider_contact_id").append(
                            '<option value="' + this.provider_contact.id + '" ' + selected + '>'
                            + this.provider_contact.name + '</option>'
                        );
                    });
                }
            });
        });        
        $("#internship_provider_id").trigger('change');
        
        $(".add_img").attr('src','http://humadvisement.byu.edu/sites/default/files/menu_icons/Add-Button_64x64.png');
        $(".add_img").click(function(){
            addNew($(this).attr('model'));
        });
    });
    function addNew(model){
        var dialog = "";
        $.ajax({
            type: "GET",
               url: "/" + model + "/new",
               data: {'dialog':true},
               success: function(data){
                dialog = '<div id="dialog">' + data + '</div>';
                $('body').append(dialog);
                $( "#dialog" ).dialog({width: 800, height: 500, close: function(event, ui) { 
                    $("#dialog").dialog('destroy');
                    $("#dialog").remove();
                    model_singular = model.substring(0,model.length-1);    
                    if($("#internship_" + model_singular + "_id").is("select")){
                        $.ajax({
                            url: '/' + model + '.json',
                            data: {},
                            dataType: 'json',
                            success: function(data){
                                $("#internship_" + model_singular + "_id").html('');
                                var selected_value = $("#internship_" + model_singular + "_id").val();
                                $.each(data, function(index){
                                    var selected = '';
                                    if(selected_value == data[index][model_singular].id){
                                        selected = 'selected="selected"';
                                    }
                                    $("#internship_" + model_singular + "_id").append(
                                        '<option value="' + data[index][model_singular].id + '" ' + selected + '>'
                                        + data[index][model_singular].name + '</option>'
                                    );
                                    
                                 });
                                //this trigger is being called just in case the the reload was on contact provider
                                $("#internship_provider_id").trigger('change');
                            }
                        });
                    }
                    
                }});
               },
               error: function(){
                alert( "ERROR!");
               }
        });
    }
*/
</script>
<style>
    .add_img{
        float: right;
        width: 25px;
        margin-top: -35px;
        cursor: pointer;
    }
    .field label{
        clear: both;
    }
    .add_img.select{
        /*margin-right: 350px;*/
        float: none;
        /*margin-top: -40px;*/
    }

</style>
<%= form_for(@internship) do |f| %>

    <% if @internship.errors.any? %>
        <div class="box grid_16 round_all">
            <div class="alert alert_red">
                    <img src="<%= icon_path %>/Alarm%20Bell.png" />
              <strong><%= pluralize(@internship.errors.count, "error") %></strong> prohibited this internship from being saved:
            </div>
        </div>
        <div class="box grid_16 round_all">
            <div class="alert_sub_red">
                <ul>
                    <% @internship.errors.full_messages.each do |msg| %>
                <li><%= msg %></li>
              <% end %>
                </ul>
            </div>
        </div>
    <% end %>
    
    
    <div class="actions grid_16">
        <% content_tag :button, :type => :submit, :class => "green round_all" do %>
                 <%= image_tag "icons/small/white/Bended%20Arrow%20Right.png" %>
                <span>Save this Internship!</span>
            <% end %>
            <%# link_to "Cancel", internships_path %>
    </div>
    
    <%= theme_box(8, "Basic Information") do %>
          <div class="field">
            <%= f.label :name %>
             <%= f.text_field :name %>
        </div>
        <div class="field">
            <%= f.label :provider_id %>
            <div class="input_group">
                <%= f.collection_select :provider_id, Provider.all, :id, :name, {}, {:class => 'chosen'} %>
            </div>
            <img class="add_img select" model="providers">
        </div>
        <div class="input_group">
            <%= f.check_box :is_paid %><b>Paid?</b><br />
             <%= f.check_box :is_full_time %><b>Full-time?</b><br />
             <%= f.check_box :is_part_time %><b>Part-time?</b>
        </div>    
        
        <div class="field">
            <%= f.label :stipend %>
            <%= f.text_field :stipend %>
        </div>
        <div class="field">
            <%= f.label :description %>
            <%= f.text_area :description, :class => 'tiny_editor' %>
        </div>        
    <% end %>
    
    <%= theme_box(8, "Tags", true) do %>
        <div class="field">
            <%= f.label :fields, "Fields" %><br />
            <%= f.collection_select :field_ids, Field.all, :id, :name, {}, {:multiple => true, :class => 'chosen'} %>
            <img class="add_img" model="fields">
        </div>
        <div class="field">
            <%= f.label :academic_focuses, "Majors/Minors" %><br />
            <%= f.collection_select :academic_focus_ids, AcademicFocus.all, :id, :name, {}, {:multiple => true, :class => 'chosen'} %>
            <img class="add_img" model="academic_focuses">
        </div>
        <div class="field">
            <%= f.label :locations, "Locations" %><br />
            <%= f.collection_select :location_ids, Location.all, :id, :display_name, {}, {:multiple => true, :class => 'chosen'} %>
            <img class="add_img" model="locations">
        </div>
        <div class="field">
            <%= f.label :semesters, "Semesters" %><br />
            <%= f.collection_select :semester_ids, Semester.all, :id, :name, {}, {:multiple => true, :class => 'chosen'} %>
            <img class="add_img" model="semesters">
        </div>
        <div class="field">
            <%= f.label :languages, "Languages" %><br />
            <%= f.collection_select :language_ids, Language.all, :id, :name, {}, {:multiple => true, :class => 'chosen'} %>
            <img class="add_img" model="languages">
        </div>
        <div class="field">
            <%= f.label :financial_assistance_options, "Financial Assistance Options" %><br />
            <%= f.collection_select :financial_assistance_options, FinancialAssistanceOption.all, :id, :name, {}, {:multiple => true, :class => 'chosen'} %>
            <img class="add_img" model="financial_assistance_options">
        </div>
    <% end %>
    <div class="grid_8">
        <%= theme_box(16, "Contact Information", true) do %>
            <div class="field">
                <%= f.label :academic_contact_id %>
                <div class="input_group">
                    <%= f.collection_select :academic_contact_id, AcademicContact.all, :id, :name, {}, {:class => 'chosen'} %>
                </div>
                <img class="add_img select" model="academic_contacts">
            </div>
            <div class="field">
                <%= f.label :provider_contact_id %>
                <div class="input_group">
                    <%= f.collection_select :provider_contact_id, ProviderContact.all, :id, :name, {}, {:class => 'chosen'} %>
                </div>
                <img class="add_img select" model="provider_contacts">
            </div>
        <% end %>
        <%= theme_box(16, "Qualifications", true, false) do %>
            <div class="field">
                <%= f.label :qualifications %>
                <%= f.text_area :qualifications, :class => 'tiny_editor' %>
              </div>
            <div class="field">
                <%= f.label :qualifications_academic %>
                <%= f.text_area :qualifications_academic, :class => 'tiny_editor' %>
              </div>
            <div class="field">
                <%= f.check_box :requires_us_citizenship %><b>Requires us citizenship?</b>
              </div>
        <% end %>
    </div>
    
    <%= theme_box(8, "Additional Information", true) do %>    
        <div class="field">
            <%= f.label :for_credit %>
            <%= f.check_box :for_credit %>
        </div>
        <div class="field">
            <%= f.label :application_process %>
            <%= f.text_area :application_process, :class => "tiny_editor" %>
          </div>
        <div class="field">
            <%= f.label :deadline %><br />
            <%= f.text_field :deadline %>
          </div>
        <div class="field">
            <%= f.label :notes %><br />
            <%= f.text_area :notes, :class => 'tiny_editor' %>
        </div>
        <% if can? :manage, :users %>
        
            <div class="field">
                <label>Owner</label>
                <div class="input_group">
                    <%= f.collection_select :user_id, User.all, :id, :net_id, {:selected => @internship.user.id}, {:class => 'chosen'} %>
                </div>
            </div>
        
        <% else %>
                <%= f.hidden_field :user_id %>
        <% end %>
    <% end %>    
    
<% end %>

<script>
    $(function(){
        //$(".as-selections").width($(".as-selections").width() - 30);
    });
</script>