johnrees/fablabs

View on GitHub
app/views/labs/_form.html.haml

Summary

Maintainability
Test Coverage
= javascript_include_tag "//maps.googleapis.com/maps/api/js?libraries=places&key=#{ENV['GOOGLE_MAPS_API_KEY']}"
= simple_form_for lab, html: { class: 'row' } do |f|
  = render 'form_errors', resource: lab

  %fieldset.col-12
    .text-large
      Adding Basic Details

    = f.input :name, label: 'Your fablab name'

    .question
      %h5
        %strong More lab details:
        %span What kind of Fab Lab is your Lab?

      = f.input :kind, as: :radio_buttons, collection: Lab::KINDS

    .question
      %h5
        %strong Current status of your Lab:
        %span Is this Lab already open, planned or closed?

      = f.input :activity_status, as: :radio_buttons, collection: Lab::ACTIVITY_STATUS

    .question
      %h5
        %strong Lab tags:
      %p Select the appropriate lab tags

      <br>
      = f.association :lab_tags

    .question
      %h5
        %strong Lab history:
        %span Please indicate these important dates in the history of your Lab:

      = f.input :activity_start_at, label: 'When did you start designing and planning your Lab?', as: 'string', input_html: { class: 'flatpickr' }
      = f.input :activity_inaugurated_at, label: 'When was the Lab officially inaugurated?', as: 'string', input_html: { class: 'flatpickr' }
      = f.input :activity_closed_at, label: 'When was the Lab closed?', as: 'string', input_html: { class: 'flatpickr' }



  %fieldset.col-12
    .text-large
      What qualifies as a Fab Lab
    %h5
      Fab Labs have a list of qualities and requirements that defines them.
      More information can be found
      %a{href: "https://fabfoundation.org/getting-started/", target: "_blank"} here.

    .form-check.mb-0.mt-3
      %div.form-check-input.mt-0.px-4
        = f.check_box :charter
      %label.radio.form-check-label.px-4
        Charter: You need to agree with the
        = succeed "." do
          %a{:href => "https://fab.cba.mit.edu/about/charter/", target: "_blank"} Fab Charter

    .form-check.mb-0.mt-3
      %div.form-check-input.mt-0.px-4
        = f.check_box :tools
      %label.radio.form-check-label.px-4
        Tools: The submitted Fab Lab has a compatible set of tools related with the
        = succeed "." do
          %a{:href => "https://inventory.fabcloud.io/", target: "_blank"} official Fab Lab inventory

    .form-check.mb-0.mt-3
      %div.form-check-input.mt-0.px-4
        = f.check_box :network
      %label.radio.form-check-label.px-4
        Network: The submitted Fab Lab commits to participate in the network activities: regional meetings, FABX conferences,
        = succeed "." do
          %a{:href => "https://forum.fablabs.io/", target: "_blank"} the Discuss section on FabLabs.io

    .form-check.mb-0.mt-3
      %div.form-check-input.mt-0.px-4
        = f.check_box :programs
      %label.radio.form-check-label.px-4
        Programs: Our staff is (or will be) trained in the
        %a{:href => "https://fabacademy.org/", target: "_blank"} Fab Academy
        or compatible programs

    .form-check.mb-0.mt-3
      %div.form-check-input.mt-0.px-4
        = f.check_box :public
      %label.radio.form-check-label.px-4
        Access: Public access to the Fab Lab is essential

  %fieldset.col-12
    .text-large
      Description
    = f.input :blurb, as: 'text', hint: 'A very brief overview of the lab, maybe include what it specializes in. <span id="description-count"></span> characters available.'.html_safe, input_html: { rows: 3, data: { limit: 200, counter: '#description-count'} }
    = f.input :description, hint: 'An in-depth description of the lab', input_html: { style: 'height: 8em' }
    = f.input :slug, hint: "This is the unique 'username' of the lab, it will be in the URL" do
      .input-group
        %span.input-group-prepend.p-2= "https://fablabs.io/"
        = f.input_field :slug, class: 'form-control'

  %fieldset.col-12
    .text-large
      Lab Images

    .row
      .col-lg-3.mt-2
        - if @lab&.avatar&.url&.present?
          = image_tag @lab.avatar.url, class: 'avatar big'
      .col-lg-9
        = f.input :avatar, as: :file, label: 'Avatar', hint: "This will be a square image next shown next to the lab name throughout the site"
        = f.hidden_field :retained_avatar

    .row
      .col-lg-3
        - if @lab&.header&.url&.present?
          = image_tag @lab.header.url, class: 'avatar big'
      .col-lg-9
        = f.input :header, as: :file, label: 'Header', hint: "A single (large) photo of your lab. You will be able to add more photos soon."
        = f.hidden_field :retained_header

  %fieldset.col-12
    .text-large
      Lab Location

    .address
      .question
        %h5 Step 1
        .text-small Enter the lab's address in the textbox below. Then drag the map marker to pinpoint its exact position.
        = f.input :geocomplete, input_html: { id: 'geocomplete', data: { latlng: (@lab.latitude.present? ? "#{@lab.latitude}, #{@lab.longitude}" : "false")} }, label: false
      .question.step-2
        %h5 Step 2
        .text-small Edit the details in the address fields below.
        .row
          .col-lg-6#map-holder
            #location-picker-map
          .col-lg-6
            #lab_geoinfo
              %p Marker Lat/Lng coordinates: <strong>#{(@lab.latitude.present? ? "#{@lab.latitude} / #{@lab.longitude}" : "")}</strong>
            = f.input :address_1, input_html: { data: {geo: "street_address"}}, label: 'Lab Address', placeholder: 'Address Line 1'
            = f.input :address_2, label: false, placeholder: 'Address Line 2 (Optional)'
            = f.input :city, input_html: { data: {geo: "locality"}}
            = f.input :county, label: 'State/Province/County'

            = f.input :postal_code, input_html: { data: {geo: "postal_code"}}
            = f.input :country_code, as: 'country', label: 'Country', input_html: { data: {geo: "country_short"} }, wrapper_html: { class: 'boo'}, iso_codes: true#, input_html: { class: 'enhanced'}
            = f.input :latitude, as: :hidden, input_html: { data: {geo: "lat"}}
            = f.input :longitude, as: :hidden, input_html: { data: {geo: "lng"}}
            = f.input :zoom, as: :hidden
      .question
        %h5 Step 3
        = f.input :address_notes, hint: 'Any details that might be useful for someone trying to find the lab. For example, "Go up the stairs and through the red door".'

  %fieldset.col-12
    .text-large
      Lab Contact Details
    = f.input :phone, hint: "A general enquiries phone number for the lab", label: "Lab Phone Number"
    = f.input :email, hint: "A general enquiries email address for the lab", label: "Lab Email Address"
    = render 'form_links', f: f

    - if @lab.new_record?
      .question
        %h5
          %strong Your Role
        = f.simple_fields_for :employees do |e|
          = e.input :job_title, placeholder: "e.g. Lab Manager"
          = e.input :description, placeholder: "e.g. Coordinates Workshops and Events"

    - if @lab.new_record?
      .question
        %h5
          %strong Applications Notes
        = f.input :application_notes


  %fieldset.col-12
    .text-large
      Lab Technologies

    %h5
      %strong Add Capabilities:
      %span Check all of the boxes that apply to this lab

    .form-check.mb-3.pb-3
      = f.input :capabilities, as: 'check_boxes', inline_label: true, item_wrapper_class: 'checkbox_container mr-3', label: false, collection: Lab::Capabilities.map{|f| [ I18n.t("capabilities.#{f}"), f]}, checked: f.object.capabilities, input_html: { class: 'form-check-input' }

    - if lab.new_record?
      .mb-3.pb-3
        %strong You will be able to add individual machines once your lab is approved.
    - else
      %label{for: "facilities_attributes"}
        %h5
          %strong Add Machines:
      .mt-3.px-0.mx-4
        = f.association :machines
    = f.input :tools_list, hint: "Please list any machines that you have so that we can add them to the directory.", input_html: { style: "height: 8em" }, placeholder: "e.g. Makerbot Industries - Makerbot 2"
  - if lab.workflow_state != "approved"
    %fieldset.col-12
      .text-large
        Please select 3 Referee Labs
      %h5
        Please choose 3 of the Referee Labs available and contact them, they will approve you after you have exchanged more information with them. The list of Referee Labs is limited to some Fab Labs with experience and a history of collaborating with the global Fab Lab Network, at the moment it is not possible to choose Referee Labs outside that list. It's not important that you already know them, it's important that you start a discussion with them. We are doing this so that the connections among the Labs (especially for new Labs) get strengthened.
        = render 'referees', :f => f

      %br
      .text-large
        Please select a Parent Lab
      %h5
        Is this Lab connected to another Lab? If so, which Lab?
        = f.input :parent_id, as: 'select', collection: Lab.with_approved_state.order('name ASC'), input_html: { class: 'enhanced' }


  = f.submit (lab.new_record? ? 'Add Lab' : 'Update Lab'), class: 'btn btn-primary btn-lg mt-4'