edit order user-interface update

also closes foodcoops#145
This commit is contained in:
wvengen 2014-02-20 12:37:51 +01:00
parent 63e2ec9d49
commit 8c0df3b4e8
12 changed files with 62 additions and 15 deletions

View file

@ -16,6 +16,7 @@ gem 'therubyracer', platforms: :ruby
gem 'jquery-rails'
gem 'select2-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 'i18n-js', git: 'git://github.com/fnando/i18n-js.git' # to avoid US-ASCII js.erb error
gem 'rails-i18n'

View file

@ -134,6 +134,8 @@ GEM
thor
daemons (1.1.9)
database_cleaner (1.3.0)
date_time_attribute (0.0.6)
activesupport (>= 3.0.0)
debug_inspector (0.0.2)
deface (1.0.0)
colorize (>= 0.5.8)
@ -412,6 +414,7 @@ DEPENDENCIES
coveralls
daemons
database_cleaner
date_time_attribute
exception_notification
factory_girl_rails (~> 4.0)
faker

View file

@ -140,7 +140,7 @@ $(function() {
});
// 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)
// Extra options don't work when using selector, so override defaults

View file

@ -62,7 +62,7 @@ class OrdersController < ApplicationController
# Page to create a new order.
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
# Save a new order.

View file

@ -207,5 +207,16 @@ module ApplicationHelper
def show_user_link(user=@current_user)
show_user user
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

View file

@ -2,4 +2,4 @@ class DatePickerInput < SimpleForm::Inputs::StringInput
def input
@builder.text_field(attribute_name, input_html_options.merge({class: 'datepicker'}))
end
end
end

View file

@ -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

View file

@ -1,7 +1,6 @@
# encoding: utf-8
#
class Order < ActiveRecord::Base
attr_accessor :ignore_warnings
# Associations
@ -30,9 +29,12 @@ class Order < ActiveRecord::Base
scope :finished_not_closed, -> { where(state: 'finished').order('ends DESC') }
scope :closed, -> { where(state: 'closed').order('ends DESC') }
scope :stockit, -> { where(supplier_id: 0).order('ends DESC') }
scope :recent, -> { order('starts DESC').limit(10) }
# Allow separate inputs for date and time
include DateTimeAttribute
date_time_attribute :starts, :ends
def stockit?
supplier_id == 0
end

View file

@ -1,8 +1,9 @@
= simple_form_for @order do |f|
= f.hidden_field :supplier_id
= f.input :note, input_html: {rows: 8}
= f.input :starts, input_html: {class: 'input-small'}
= f.input :ends, input_html: {class: 'input-small'}
.fold-line
= f.input :starts, as: :date_picker_time
= f.input :ends, as: :date_picker_time
= f.input :note, input_html: {rows: 2, class: 'input-xxlarge'}
%h2= t '.title'
- if @order.errors.has_key?(:articles)
@ -18,7 +19,7 @@
- else
%th= heading_helper Article, :origin
%th= heading_helper Article, :manufacturer
%th= heading_helper Article, :unit_quantity
%th= heading_helper Article, :units
%th= t '.prices'
- for category_name, articles in @order.articles_for_ordering
%tr.article-category
@ -37,13 +38,16 @@
%tr{class: row_class, id: 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=h truncate article.note, :length => 25
%td= truncate article.note, length: 25, tooltip: true
- if @order.stockit?
%td= "#{article.quantity_available} * #{article.unit}"
- else
%td=h truncate article.origin, :length => 15
%td=h truncate article.manufacturer, :length => 15
%td= "#{article.unit_quantity} x #{article.unit}"
%td= truncate article.origin, length: 15, tooltip: true
%td= truncate article.manufacturer, length: 15, tooltip: true
%td
= article.unit
- if article.unit_quantity > 1
%span{style: 'color: grey'} &times; #{article.unit_quantity}#{pkg_helper_icon}
%td= "#{number_to_currency(article.price)} / #{number_to_currency(article.fc_price)}"
%tr
%td

View file

@ -1,3 +1,3 @@
- title t('.title')
- title t('.title', name: @order.name)
= render :partial => 'form'

View file

@ -1,3 +1,10 @@
- title t('.title')
= render 'form'
- content_for :javascript do
:javascript
// select all articles by default
$(function() {
$('#checkall').click();
});

View file

@ -1089,7 +1089,7 @@ en:
create:
notice: The order was created.
edit:
title: Edit order
title: ! 'Edit order: %{name}'
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_unlocked_title: The distribution of this article among the ordergroups was changed manually. When you change the amount, those manual changes will be overwritten.