diff options
| -rw-r--r-- | app/assets/javascripts/main_menu.coffee | 2 | ||||
| -rw-r--r-- | app/assets/javascripts/selectable_table.coffee | 31 | ||||
| -rw-r--r-- | app/assets/stylesheets/components/_forms.sass | 54 | ||||
| -rw-r--r-- | app/helpers/newapplication_helper.rb | 18 | ||||
| -rw-r--r-- | app/views/workbenches/show.html.slim | 1 | 
5 files changed, 104 insertions, 2 deletions
| diff --git a/app/assets/javascripts/main_menu.coffee b/app/assets/javascripts/main_menu.coffee index e67889e8a..e762ebaa9 100644 --- a/app/assets/javascripts/main_menu.coffee +++ b/app/assets/javascripts/main_menu.coffee @@ -2,7 +2,7 @@    $('#main_nav').each ->      # Opening/closing left-side menu      $(this).on 'click', '.openMenu', (e) -> -      console.log 'clicked' +      # console.log 'clicked'        $(this).parent().addClass 'open'      $(this).on 'click', '.closeMenu', (e) -> diff --git a/app/assets/javascripts/selectable_table.coffee b/app/assets/javascripts/selectable_table.coffee new file mode 100644 index 000000000..bb5fd6484 --- /dev/null +++ b/app/assets/javascripts/selectable_table.coffee @@ -0,0 +1,31 @@ +@selectTable = -> +  $('.table').each -> +    selection = [] +    $(this).on 'click', "[type='checkbox']", (e)-> +      if e.currentTarget.id == '0' +        if e.currentTarget.checked +          $("[type='checkbox']").each -> +            $(this).prop('checked', true) +            # Add each element to selection +            selection.push($(this).attr('id')) + +          # Remove th checkbox from selection +          selection.splice(0, 1) + +        else +          $("[type='checkbox']").each -> +            $(this).prop('checked', false) +          # Empty selection +          selection = [] + +      else +        if e.currentTarget.checked +          selection.push(e.currentTarget.id) +        else +          elm = selection.indexOf(e.currentTarget.id) +          selection.splice(elm, 1) + +      # We log the selection (for now) +      console.log selection + +$(document).on 'ready page:load', selectTable diff --git a/app/assets/stylesheets/components/_forms.sass b/app/assets/stylesheets/components/_forms.sass index 9ef1fd6d4..f0667555a 100644 --- a/app/assets/stylesheets/components/_forms.sass +++ b/app/assets/stylesheets/components/_forms.sass @@ -75,3 +75,57 @@          background-color: transparent          color: #fff          height: 100% + +// Checkbox +$cbx-size: 20px +.checkbox +  position: relative +  display: block +  height: $cbx-size +  width: $cbx-size +  margin: 0 auto + +  > input +    &[type='checkbox']:not(:checked), &[type='checkbox']:checked +      position: absolute +      left: -9999px + +      + label +        position: relative +        cursor: pointer +        display: inline-block +        height: $cbx-size +        margin: 0 +        padding-left: $cbx-size + +        &:before +          content: '' +          position: absolute +          left: 0 +          top: 50% +          margin-top: -($cbx-size / 2) +          width: $cbx-size +          height: $cbx-size +          border: 2px solid $blue +          background-color: #fff +          border-radius: 3px + +        &:after +          content: '\f00c' +          font: normal normal normal 14px/1 FontAwesome +          font-size: inherit +          text-rendering: auto +          -webkit-font-smoothing: antialiased +          position: absolute +          left: 50% +          top: 50% +          margin-top: -($cbx-size / 2) +          margin-left: -($cbx-size / 2) +          font-size: $cbx-size - 2px +          width: $cbx-size +          line-height: $cbx-size +          text-align: center +          color: #fff + +    &[type='checkbox']:checked + label:before +      background-color: $blue diff --git a/app/helpers/newapplication_helper.rb b/app/helpers/newapplication_helper.rb index a9bd11d11..70b16ce01 100644 --- a/app/helpers/newapplication_helper.rb +++ b/app/helpers/newapplication_helper.rb @@ -1,12 +1,20 @@  module NewapplicationHelper    # Table Builder -  def table_builder collection, columns, actions, cls = nil +  def table_builder collection, columns, actions, selectable, cls = nil      return unless collection.present?      head = content_tag :thead do        content_tag :tr do          hcont = [] + +        if selectable.to_s == 'selectable' +          cbx = content_tag :div, '', class: 'checkbox' do +            check_box_tag('0', 'all').concat(content_tag(:label, '', for: '0')) +          end +          hcont << content_tag(:th, cbx) +        end +          columns.map do |k, v|            hcont << content_tag(:th, sortable_columns(collection, k))          end @@ -20,6 +28,14 @@ module NewapplicationHelper        collection.collect do |item|          content_tag :tr do            bcont = [] + +          if selectable.to_s == 'selectable' +            cbx = content_tag :div, '', class: 'checkbox' do +              check_box_tag(item.try(:id), item.try(:id)).concat(content_tag(:label, '', for: item.try(:id))) +            end +            bcont << content_tag(:td, cbx) +          end +            columns.map do |k, attribute|              value =                if Proc === attribute diff --git a/app/views/workbenches/show.html.slim b/app/views/workbenches/show.html.slim index 732e306c4..17da76ec8 100644 --- a/app/views/workbenches/show.html.slim +++ b/app/views/workbenches/show.html.slim @@ -43,6 +43,7 @@                @wbench_refs.human_attribute_name(:updated_at) => Proc.new {|w| l(w.updated_at, format: :short)},                @wbench_refs.human_attribute_name(:published_at) => ''},              [:show, :edit, :archive, :unarchive, :delete], +            :selectable,              'table'            / Old one | 
