Add weekday selection and client side date formatting

This commit is contained in:
2013-02-19 09:32:24 +01:00
parent 43073e10f8
commit c5f6813765
17 changed files with 89 additions and 12 deletions
+1 -11
View File
@@ -1,14 +1,3 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//= require jquery
//= require jquery_ujs
//= require jquery-ui
@@ -32,6 +21,7 @@
//= require qwaiter
//= require_directory .
//= require_self
//= require moment
var Qstorage = localStorage;
String.prototype.capitalize = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
@@ -1,5 +1,16 @@
$( ->
$('.week-day-select').each( (i)->
select = $(this)
container = select.siblings('.btn-group')
toggle = $('<button type="button" class="btn"></button>')
toggle.attr('data-t', 'product_category.week_days.abbreviation.'+select.data('day'))
toggle.addClass('active') if select.val() == '1'
container.append(toggle)
toggle.click( -> select.val(Math.abs(select.val() - 1)))
)
# GOOGLE LOCATION PICKER
$("input.location_picker").each( (i)->
return if typeof(google) == 'undefined'
location_input = $(this)
map_div = $('<div>').addClass("location_picker_map")
@@ -13,6 +13,7 @@ var $translations = {
}
}
$transformation_mappings = {
downcase: 'toLowerCase',
upcase: 'toUpperCase'
@@ -62,4 +63,8 @@ function setTranslations(selector){
}else{
$('[data-t]').each(function(){$(this).text(t($(this).data('t'),$(this).data('tAttributes')))})
}
moment.lang($locale);
$('[data-time]').each(function(){
$(this).text(moment($(this).data('time')).format($(this).data('timeFormat') || 'dd D HH:MM'))
})
}
@@ -5,3 +5,8 @@
margin-bottom: 8px
.name
padding: 5px 5px
#week_days-group
.btn
opacity: 0.4
&.active
opacity: 1
+10
View File
@@ -3,6 +3,7 @@ class ProductCategory
property :name
property :position, type: Fixnum, default: 0
property :week_days, type: Array, default: Array.new(7, 1)
belongs_to :supplier
has_and_belongs_to_many :products, storing_keys: true
@@ -14,6 +15,15 @@ class ProductCategory
validates :supplier_id, presence: true
view :by_supplier_id_and_id, key: [:supplier_id, :_id]
#alias orignal_week_days= week_days=
def week_days=(ary)
#write_attribute(:week_days, ary.map(&:to_i))
typecasted_value = ary.map(&:to_i)
#return typecasted_value if @week_days == typecasted_value
week_days_will_change! unless @skip_dirty_tracking || typecasted_value == week_days
@week_days = typecasted_value
end
def self.for_user(user, options = {})
table = options[:table]
raise "ProductCategory.for_user requires a table" unless table.present?
+1
View File
@@ -6,6 +6,7 @@ class Supplier
property :name
property :open, type: :boolean, default: false
property :time_zone, default: 'UTC'
property :night_offset, type: Float
#LOCATION
+5
View File
@@ -21,6 +21,11 @@
= f.label :location, class: 'control-label'
.controls
= f.text_field :location, class: 'location_picker'
.control-group
= f.label :time_zone, class: 'control-label'
.controls
/= f.input :time_zone, collection: ActiveSupport::TimeZone.all, label_method: :to_s, value_method: :name, include_blank: false
= f.collection_select :time_zone, ActiveSupport::TimeZone.all, :name, :to_s
.accordion-group
.accordion-heading
a.accordion-toggle data-toggle="collapse" data-parent="#settings-sections" href="#settings-wifi" data-t="attributes.supplier.offer_wifi"
@@ -9,6 +9,11 @@
= check_box_tag "product_category[product_ids][]", product.id, @product_category.product_ids.to_a.include?(product.id), id: "product-checker-#{product.id}"
= label_tag "product-checker-#{product.id}", product.name
br
.control-group
#week_days-group.btn-group data-toggle="buttons-checkbox"
- @product_category.week_days.each.with_index do |day, i|
= select_tag 'product_category[week_days][]', options_for_select([0,1], day), class: 'week-day-select', data: {day:%w[sunday monday tuesday wednesday thursday friday saturday][i]}
.form-actions
= f.button :submit, class: 'btn-primary'
'
+1 -1
View File
@@ -22,7 +22,7 @@ div.page-header= title :index, model_class
tr
td.link= link_to table.number, [:suppliers, table]
td.link= link_to_if table.section.present?, table.section.try(:title), [:suppliers, table.section]
td.timestamp=l table.created_at, format: :short
td.timestamp data-time=table.created_at.utc.iso8601
td.actions
= link_to t('helpers.links.edit'), [:edit, :suppliers, table], class: 'btn btn-mini'
'
+1
View File
@@ -35,6 +35,7 @@ module Qwaiter
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
config.time_zone = 'UTC'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
+10
View File
@@ -59,3 +59,13 @@ en:
reviews:
title: Reviews
explanation: Fill in your Iens id. You can find this id in the web location of your profile
product_category:
week_days:
abbreviation:
sunday: S
monday: M
tuesday: T
wednesday: W
thursday: T
friday: F
saturday: S
+10
View File
@@ -59,3 +59,13 @@ nl:
reviews:
title: Reviews
explanation: Vul hier je iens id in. Deze kan je halen uit de url van je iens profiel
product_category:
week_days:
abbreviation:
sunday: Z
monday: M
tuesday: D
wednesday: W
thursday: D
friday: V
saturday: Z
@@ -41,6 +41,7 @@ feature 'Supplier main board spec.rb', %q{
product = create :product, supplier: @supplier
visit '/supplier'
@list.place_order @user, {product.id => 369}
sleep 0.1
page.should have_selector ".of-list-#{@list.id}"
end
end
+14
View File
@@ -0,0 +1,14 @@
require 'spec_helper'
describe ProductCategory do
describe '#week_days' do
let(:product_category) { create :product_category }
subject { product_category }
let(:default) { Array.new(7, 1) }
its(:week_days) { should == default }
it "typecasts strings into integers" do
subject.week_days = Array.new(7, "0")
subject.week_days.should == Array.new(7, 0)
end
end
end
File diff suppressed because one or more lines are too long
+2
View File
@@ -0,0 +1,2 @@
//= require './moment.min'
//= require './langs.min'
File diff suppressed because one or more lines are too long