edit order user-interface update
also closes foodcoops#145
This commit is contained in:
parent
63e2ec9d49
commit
8c0df3b4e8
1
Gemfile
1
Gemfile
|
@ -16,6 +16,7 @@ gem 'therubyracer', platforms: :ruby
|
||||||
gem 'jquery-rails'
|
gem 'jquery-rails'
|
||||||
gem 'select2-rails'
|
gem 'select2-rails'
|
||||||
gem 'bootstrap-datepicker-rails'
|
gem 'bootstrap-datepicker-rails'
|
||||||
|
gem 'date_time_attribute'
|
||||||
gem 'rails-assets-listjs', '0.2.0.beta.4' # remember to maintain list.*.js plugins and template engines on update
|
gem 'rails-assets-listjs', '0.2.0.beta.4' # remember to maintain list.*.js plugins and template engines on update
|
||||||
gem 'i18n-js', git: 'git://github.com/fnando/i18n-js.git' # to avoid US-ASCII js.erb error
|
gem 'i18n-js', git: 'git://github.com/fnando/i18n-js.git' # to avoid US-ASCII js.erb error
|
||||||
gem 'rails-i18n'
|
gem 'rails-i18n'
|
||||||
|
|
|
@ -134,6 +134,8 @@ GEM
|
||||||
thor
|
thor
|
||||||
daemons (1.1.9)
|
daemons (1.1.9)
|
||||||
database_cleaner (1.3.0)
|
database_cleaner (1.3.0)
|
||||||
|
date_time_attribute (0.0.6)
|
||||||
|
activesupport (>= 3.0.0)
|
||||||
debug_inspector (0.0.2)
|
debug_inspector (0.0.2)
|
||||||
deface (1.0.0)
|
deface (1.0.0)
|
||||||
colorize (>= 0.5.8)
|
colorize (>= 0.5.8)
|
||||||
|
@ -412,6 +414,7 @@ DEPENDENCIES
|
||||||
coveralls
|
coveralls
|
||||||
daemons
|
daemons
|
||||||
database_cleaner
|
database_cleaner
|
||||||
|
date_time_attribute
|
||||||
exception_notification
|
exception_notification
|
||||||
factory_girl_rails (~> 4.0)
|
factory_girl_rails (~> 4.0)
|
||||||
faker
|
faker
|
||||||
|
|
|
@ -140,7 +140,7 @@ $(function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Use bootstrap datepicker for dateinput
|
// Use bootstrap datepicker for dateinput
|
||||||
$('.datepicker').datepicker({format: 'yyyy-mm-dd', language: I18n.locale});
|
$('.datepicker').datepicker({format: 'yyyy-mm-dd', language: I18n.locale, todayHighlight: true});
|
||||||
|
|
||||||
// bootstrap tooltips (for price)
|
// bootstrap tooltips (for price)
|
||||||
// Extra options don't work when using selector, so override defaults
|
// Extra options don't work when using selector, so override defaults
|
||||||
|
|
|
@ -62,7 +62,7 @@ class OrdersController < ApplicationController
|
||||||
|
|
||||||
# Page to create a new order.
|
# Page to create a new order.
|
||||||
def new
|
def new
|
||||||
@order = Order.new :ends => 4.days.from_now, :supplier_id => params[:supplier_id]
|
@order = Order.new starts: Time.now, ends: 4.days.from_now, supplier_id: params[:supplier_id]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Save a new order.
|
# Save a new order.
|
||||||
|
|
|
@ -207,5 +207,16 @@ module ApplicationHelper
|
||||||
def show_user_link(user=@current_user)
|
def show_user_link(user=@current_user)
|
||||||
show_user user
|
show_user user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# allow truncate to add title when tooltip option is given
|
||||||
|
def truncate(text, options={}, &block)
|
||||||
|
return text if not text or text.length <= (options[:length] or 30)
|
||||||
|
text_truncated = super(text, options, &block)
|
||||||
|
if options[:tooltip]
|
||||||
|
content_tag :span, text_truncated, title: text
|
||||||
|
else
|
||||||
|
text_truncated
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,4 +2,4 @@ class DatePickerInput < SimpleForm::Inputs::StringInput
|
||||||
def input
|
def input
|
||||||
@builder.text_field(attribute_name, input_html_options.merge({class: 'datepicker'}))
|
@builder.text_field(attribute_name, input_html_options.merge({class: 'datepicker'}))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
# DateTime picker using bootstrap-datepicker for the time part
|
||||||
|
# requires `date_time_attribute` gem and active on the attribute
|
||||||
|
# http://stackoverflow.com/a/20317763/2866660
|
||||||
|
# https://github.com/einzige/date_time_attribute
|
||||||
|
class DatePickerTimeInput < SimpleForm::Inputs::StringInput
|
||||||
|
def input
|
||||||
|
# Date format must match datepicker's, see app/assets/application.js .
|
||||||
|
# And for html5 inputs, match RFC3339, see http://dev.w3.org/html5/markup/datatypes.html#form.data.date .
|
||||||
|
# In the future, use html5 date&time inputs. This needs modernizr or equiv. to avoid
|
||||||
|
# double widgets, and perhaps conditional css to adjust input width (chrome).
|
||||||
|
value = @builder.object.send attribute_name
|
||||||
|
date_options = {as: :string, class: 'input-small datepicker', value: value.try {|e| e.strftime('%Y-%m-%d')}}
|
||||||
|
time_options = {as: :string, class: 'input-mini', value: value.try {|e| e.strftime('%H:%M')}}
|
||||||
|
@builder.input_field("#{attribute_name}_date", input_html_options.merge(date_options)) + ' ' +
|
||||||
|
@builder.input_field("#{attribute_name}_time", input_html_options.merge(time_options))
|
||||||
|
# time_select requires a date_select
|
||||||
|
#@builder.time_select("#{attribute_name}_time", {ignore_date: true}, input_html_options.merge(time_options))
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,7 +1,6 @@
|
||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
#
|
#
|
||||||
class Order < ActiveRecord::Base
|
class Order < ActiveRecord::Base
|
||||||
|
|
||||||
attr_accessor :ignore_warnings
|
attr_accessor :ignore_warnings
|
||||||
|
|
||||||
# Associations
|
# Associations
|
||||||
|
@ -30,9 +29,12 @@ class Order < ActiveRecord::Base
|
||||||
scope :finished_not_closed, -> { where(state: 'finished').order('ends DESC') }
|
scope :finished_not_closed, -> { where(state: 'finished').order('ends DESC') }
|
||||||
scope :closed, -> { where(state: 'closed').order('ends DESC') }
|
scope :closed, -> { where(state: 'closed').order('ends DESC') }
|
||||||
scope :stockit, -> { where(supplier_id: 0).order('ends DESC') }
|
scope :stockit, -> { where(supplier_id: 0).order('ends DESC') }
|
||||||
|
|
||||||
scope :recent, -> { order('starts DESC').limit(10) }
|
scope :recent, -> { order('starts DESC').limit(10) }
|
||||||
|
|
||||||
|
# Allow separate inputs for date and time
|
||||||
|
include DateTimeAttribute
|
||||||
|
date_time_attribute :starts, :ends
|
||||||
|
|
||||||
def stockit?
|
def stockit?
|
||||||
supplier_id == 0
|
supplier_id == 0
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
= simple_form_for @order do |f|
|
= simple_form_for @order do |f|
|
||||||
= f.hidden_field :supplier_id
|
= f.hidden_field :supplier_id
|
||||||
= f.input :note, input_html: {rows: 8}
|
.fold-line
|
||||||
= f.input :starts, input_html: {class: 'input-small'}
|
= f.input :starts, as: :date_picker_time
|
||||||
= f.input :ends, input_html: {class: 'input-small'}
|
= f.input :ends, as: :date_picker_time
|
||||||
|
= f.input :note, input_html: {rows: 2, class: 'input-xxlarge'}
|
||||||
|
|
||||||
%h2= t '.title'
|
%h2= t '.title'
|
||||||
- if @order.errors.has_key?(:articles)
|
- if @order.errors.has_key?(:articles)
|
||||||
|
@ -18,7 +19,7 @@
|
||||||
- else
|
- else
|
||||||
%th= heading_helper Article, :origin
|
%th= heading_helper Article, :origin
|
||||||
%th= heading_helper Article, :manufacturer
|
%th= heading_helper Article, :manufacturer
|
||||||
%th= heading_helper Article, :unit_quantity
|
%th= heading_helper Article, :units
|
||||||
%th= t '.prices'
|
%th= t '.prices'
|
||||||
- for category_name, articles in @order.articles_for_ordering
|
- for category_name, articles in @order.articles_for_ordering
|
||||||
%tr.article-category
|
%tr.article-category
|
||||||
|
@ -37,13 +38,16 @@
|
||||||
%tr{class: row_class, id: article.id}
|
%tr{class: row_class, id: article.id}
|
||||||
%td= check_box_tag "order[article_ids][]", article.id, included, :id => "checkbox_#{article.id}"
|
%td= check_box_tag "order[article_ids][]", article.id, included, :id => "checkbox_#{article.id}"
|
||||||
%td.click-me{'data-check-this' => "#checkbox_#{article.id}"}= article.name
|
%td.click-me{'data-check-this' => "#checkbox_#{article.id}"}= article.name
|
||||||
%td=h truncate article.note, :length => 25
|
%td= truncate article.note, length: 25, tooltip: true
|
||||||
- if @order.stockit?
|
- if @order.stockit?
|
||||||
%td= "#{article.quantity_available} * #{article.unit}"
|
%td= "#{article.quantity_available} * #{article.unit}"
|
||||||
- else
|
- else
|
||||||
%td=h truncate article.origin, :length => 15
|
%td= truncate article.origin, length: 15, tooltip: true
|
||||||
%td=h truncate article.manufacturer, :length => 15
|
%td= truncate article.manufacturer, length: 15, tooltip: true
|
||||||
%td= "#{article.unit_quantity} x #{article.unit}"
|
%td
|
||||||
|
= article.unit
|
||||||
|
- if article.unit_quantity > 1
|
||||||
|
%span{style: 'color: grey'} × #{article.unit_quantity}#{pkg_helper_icon}
|
||||||
%td= "#{number_to_currency(article.price)} / #{number_to_currency(article.fc_price)}"
|
%td= "#{number_to_currency(article.price)} / #{number_to_currency(article.fc_price)}"
|
||||||
%tr
|
%tr
|
||||||
%td
|
%td
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
- title t('.title')
|
- title t('.title', name: @order.name)
|
||||||
|
|
||||||
= render :partial => 'form'
|
= render :partial => 'form'
|
||||||
|
|
|
@ -1,3 +1,10 @@
|
||||||
- title t('.title')
|
- title t('.title')
|
||||||
|
|
||||||
= render 'form'
|
= render 'form'
|
||||||
|
|
||||||
|
- content_for :javascript do
|
||||||
|
:javascript
|
||||||
|
// select all articles by default
|
||||||
|
$(function() {
|
||||||
|
$('#checkall').click();
|
||||||
|
});
|
||||||
|
|
|
@ -1089,7 +1089,7 @@ en:
|
||||||
create:
|
create:
|
||||||
notice: The order was created.
|
notice: The order was created.
|
||||||
edit:
|
edit:
|
||||||
title: Edit order
|
title: ! 'Edit order: %{name}'
|
||||||
edit_amount:
|
edit_amount:
|
||||||
field_locked_title: The distribution of this article among the ordergroups was changed manually. This field is locked to protect those changes. To redistribute and overwrite those changes, press the unlock button and change the amount.
|
field_locked_title: The distribution of this article among the ordergroups was changed manually. This field is locked to protect those changes. To redistribute and overwrite those changes, press the unlock button and change the amount.
|
||||||
field_unlocked_title: The distribution of this article among the ordergroups was changed manually. When you change the amount, those manual changes will be overwritten.
|
field_unlocked_title: The distribution of this article among the ordergroups was changed manually. When you change the amount, those manual changes will be overwritten.
|
||||||
|
|
Loading…
Reference in New Issue