foodcoop-adam/foodsoft

View on GitHub
lib/foodsoft_current_orders/app/views/current_orders/ordergroups/_form.html.haml

Summary

Maintainability
Test Coverage
.well
  = form_tag current_orders_ordergroups_path, method: :get, 'data-submit-onchange' => true, style: 'margin: 0' do
    = select_tag 'id',
        options_for_select(@all_ordergroups.map { |g| [ g.name, g.id ] }, (@ordergroup.id rescue '')),
        include_blank: true, id: 'ordergroup_select', style: 'min-width: 300px',
        'data-placeholder' => t('.ordergroup_placeholder'), 'data-submit-on-change' => :true

    - if @ordergroup and FoodsoftConfig[:price_markup_list]
      %span.price_markup_note{style: 'margin-left: 1em'}= show_price_markup @ordergroup, format: :full_label, optional: true

  -#.form-search.pull-right # see below why this is disabled
    .input-append
      = text_field_tag :query, params[:query], class: 'search-query delayed-search resettable', disabled: @ordergroup.nil?,
        'placeholder' => t('orders.show.search_placeholder.articles')
      %button.add-on.btn.reset-search{:type => :button, :title => t('orders.show.search_reset')}
        %i.icon.icon-remove


- if @ordergroup
  %table.table.table-hover#articles_by_groups
    %thead
      %tr
        %th{style: 'width: 35%'}= heading_helper Article, :name
        %th= Order.model_name.human
        %th= heading_helper Article, :unit
        %th.center
          %acronym{:title => t('shared.articles.ordered_desc')}= t 'shared.articles.ordered'
        %th.center
          %acronym{:title => t('shared.articles.received_desc')}= t 'shared.articles.received'
        %th.symbol
        %th= heading_helper Article, :fc_price, short: true
        %th.symbol
        %th= t 'shared.articles_by.price'
      = render 'articles', goas: @goas

  .well#payment_bar
    = render 'payment_bar', ordergroup: @ordergroup

- else
  %i= t '.no_selection'


= render 'shared/articles_by/common', order: @order


- content_for :javascript do
  :javascript

    $(function() {
      // TODO group by ordered / not-ordered
      $('#ordergroup_select').select2();

      // add article
      $('#group_order_article_order_article_id').select2({
        placeholder: '#{j t('orders.receive.add_article')}',
        formatNoMatches: function(term) { return '#{j t('.no_articles_available')}';}
      });
      $(document).on('GroupOrderArticle#create', function(e) {
        // reset selection
        $('#group_order_article_order_article_id').select2('data', null);
        // update table
        $.ajax({
          url: '#{show_on_group_order_article_create_current_orders_ordergroups_path}',
          type: 'get',
          data: {group_order_article_id: e.group_order_article_id}
        });
      });

      $(document).on('GroupOrderArticle#update', function(e) {
        $.ajax({
          url: '#{show_on_group_order_article_update_current_orders_ordergroups_path}',
          type: 'get',
          data: {group_order_id: e.group_order_id, group_order_article_id: e.group_order_article_id}
        });
      });

      // article search
      // DO NOT USE because listjs can't handle updates https://github.com/javve/list.js/issues/86
      /*
      new List(document.body, {
        valueNames: ['name'],
        engine: 'unlist',
        plugins: [
          ['reset', {highlightClass: 'btn-primary'}],
          ['delay', {delayedSearchTime: 500}],
        ],
        // make large pages work too (as we don't have paging)
        page: 10000,
        indexAsync: true
      });
      */
    });