spree_delivery_options 2.1.9 → 2.1.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a35f137ad18021a487ebfa104d4417b00e8258f
4
- data.tar.gz: e4d9ac7f0118a8bfc6fc307f1a4e871d1b64b017
3
+ metadata.gz: 000257197aa4e88e1516c66905ca43adc002d988
4
+ data.tar.gz: b5913ede5baedf31a6a47dae371eb5bf6a8b473a
5
5
  SHA512:
6
- metadata.gz: 6f61d50ed2351274dada0a0f33409ab53c11304748304241d7a5e3608c5babefc7a7e13a589b5c3268aa81fbd6f856d64dfda20d0c78e1bf918c96a152565740
7
- data.tar.gz: ba6331dbf36caf919d5bb65313fa3c9e69df156489daecd8bbd7b743c08d2b9044d3de7acd0caf6e7c383d9b166134aefb58729fc6845642722b1e756f17d0bb
6
+ metadata.gz: e874be45553226c30884289810d0d03826cbfe2e5eaea382c14cd02fc3d6daf77b89b136eba270a0d635664d779deef728ade7944e8b78715da97d1328c5fc64
7
+ data.tar.gz: 1797709d7fe53097b81a8b256a70fb3cb975f2cd6c5287e216f0220529b3991d5b73b5b6c1f53f6fb86f01e18757134c91008577d8f55738837fed8fb2973849
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
3
  # Provides basic authentication functionality for testing parts of your engine
4
- # gem 'spree_auth_devise', :git => "git://github.com/spree/spree_auth_devise"
4
+ gem 'spree_auth_devise', :git => "git://github.com/spree/spree_auth_devise", :branch => '2-1-stable'
5
+ gem 'haml'
5
6
 
6
7
  gemspec
@@ -0,0 +1,56 @@
1
+ function SpreeDeliveryOptions() {
2
+
3
+ var that = this;
4
+
5
+ this.initializeDeliveryTimeSelect = function() {
6
+ this.update_delivery_time_options();
7
+
8
+ $('#order_delivery_date').change(function(event){
9
+ that.update_delivery_time_options();
10
+ });
11
+ };
12
+
13
+ this.update_delivery_time_options = function() {
14
+ delivery_time_options = $.parseJSON($('.delivery-time-options').attr("data"));
15
+
16
+ if (delivery_time_options){
17
+ weekdays = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
18
+
19
+ var dateParts = []
20
+ if ($('#order_delivery_date').val().indexOf('/') !== -1) {
21
+ dateParts = $('#order_delivery_date').val().split('/')
22
+ } else {
23
+ dateParts = $('#order_delivery_date').val().split('-')
24
+ }
25
+ day_index = new Date(dateParts[0], dateParts[1]-1, dateParts[2]).getDay();
26
+ weekday = weekdays[day_index];
27
+
28
+ day_options = delivery_time_options[weekday];
29
+ this.populate_delivery_time(day_options);
30
+ }
31
+ };
32
+
33
+ this.populate_delivery_time = function(options) {
34
+ if (options) {
35
+ var selected_delivery_time = $('.selected-delivery-time').attr("data");
36
+ var arLen = options.length;
37
+ var newList = "";
38
+ for ( var i=0, len=arLen; i<len; ++i ){
39
+ if (options[i] == selected_delivery_time) {
40
+ newList = newList + '<option selected=true value="' + options[i] + '">' + options[i]+'</option>';
41
+ } else {
42
+ newList = newList + '<option value="' + options[i] + '">' + options[i]+'</option>';
43
+ }
44
+ }
45
+ $('#order_delivery_time').html(newList);
46
+ } else {
47
+ $('#order_delivery_time').html("<option>No deliveries available on this date</option>");
48
+ }
49
+ };
50
+
51
+ }
52
+
53
+ $(document).ready(function() {
54
+ var deliveryOptions = new SpreeDeliveryOptions();
55
+ deliveryOptions.initializeDeliveryTimeSelect();
56
+ });
@@ -0,0 +1,2 @@
1
+ //= require jquery
2
+ //= require admin/delivery_time_options
@@ -0,0 +1,15 @@
1
+ #delivery-options-form {
2
+ .field {
3
+ label {
4
+ display: block;
5
+ }
6
+
7
+ textarea {
8
+ min-height: 100px;
9
+ }
10
+ }
11
+
12
+ .delivery-time-options {
13
+ display: none;
14
+ }
15
+ }
@@ -1,3 +1,4 @@
1
1
  /*
2
2
  *= require admin/order_details
3
+ *= require admin/delivery_options_form
3
4
  */
@@ -0,0 +1,25 @@
1
+ module Spree
2
+ module Admin
3
+ module Orders
4
+ class DeliveryOptionsController < Spree::Admin::BaseController
5
+
6
+ def edit
7
+ @order = Order.find_by(number: params[:order_id])
8
+ end
9
+
10
+ def update
11
+ @order = Order.find_by(number: params[:order_id])
12
+ @order.update_attributes(delivery_options_params)
13
+ render :edit
14
+ end
15
+
16
+ private
17
+
18
+ def delivery_options_params
19
+ params.require(:order).permit(:delivery_date, :delivery_time, :delivery_instructions)
20
+ end
21
+
22
+ end
23
+ end
24
+ end
25
+ end
@@ -3,7 +3,7 @@ Spree::Order.class_eval do
3
3
  require 'spree/order/checkout'
4
4
 
5
5
  def valid_delivery_instructions?
6
- if self.delivery_instructions.length > 500
6
+ if self.delivery_instructions && self.delivery_instructions.length > 500
7
7
  self.errors[:delivery_instructions] << 'cannot be longer than 500 charachters'
8
8
  return false
9
9
  end
@@ -0,0 +1,5 @@
1
+ Deface::Override.new(:virtual_path => "spree/admin/shared/_order_tabs",
2
+ :name => "add_delivery_info_to_order_details",
3
+ :insert_bottom => "[data-hook='admin_order_tabs']",
4
+ :partial => "spree/admin/shared/delivery_options_link",
5
+ :disabled => false)
@@ -0,0 +1,35 @@
1
+ = render :partial => 'spree/admin/shared/order_tabs', :locals => { :current => 'Delivery Options' }
2
+
3
+ = csrf_meta_tags
4
+
5
+ - content_for :page_title do
6
+ %i.icon-arrow-right= Spree.t(:delivery_options)
7
+
8
+ - content_for :page_actions do
9
+ %li= button_link_to Spree.t(:back_to_orders_list), admin_orders_path, :icon => 'icon-arrow-left'
10
+
11
+ = render :partial => 'spree/shared/error_messages', :locals => { :target => @order }
12
+
13
+ #delivery-options-form
14
+ .delivery-time-options{data: SpreeDeliveryOptions::Config.delivery_time_options}
15
+
16
+ = form_for @order, :url => admin_order_delivery_options_url(@order) do |f|
17
+ %fieldset(data-hook="admin_delivery_options_form_fields" class="no-border-top")
18
+ %fieldset(class="index no-border-bottom")
19
+ %legend(align="center")= Spree.t(:delivery_options)
20
+ %div(data-hook="delivery_options_fields" class="row")
21
+ .alpha.twelve.columns
22
+ .field
23
+ = f.label :delivery_date, "Delivery Date"
24
+ = f.text_field :delivery_date, class: "datepicker"
25
+ .field
26
+ - selected_delivery_day = (@order.delivery_date || Date.today).strftime('%A').downcase
27
+ .selected-delivery-time{data: @order.delivery_time}
28
+ = f.label :delivery_time, "Delivery Time"
29
+ = f.select :delivery_time, JSON.parse(SpreeDeliveryOptions::Config.delivery_time_options)[selected_delivery_day]
30
+ .field
31
+ = f.label :delivery_instructions, "Delivery Instructions"
32
+ = f.text_area :delivery_instructions, class: 'fullwidth'
33
+
34
+ .form-buttons.filter-actions.actions
35
+ = button Spree.t('actions.update'), 'icon-refresh'
@@ -0,0 +1,3 @@
1
+ - if can? :update, @order && checkout_steps.include?("delivery") %>
2
+ %li(class="#{'active' if current == 'Delivery Options'}")
3
+ = link_to_with_icon 'icon-truck', Spree.t(:delivery_options), admin_order_delivery_options_url(@order)
data/config/routes.rb CHANGED
@@ -1,3 +1,6 @@
1
1
  Spree::Core::Engine.routes.draw do
2
- # Add your extension routes here
2
+
3
+ get "admin/orders/:order_id/delivery_options/", controller: 'admin/orders/delivery_options', action: 'edit', as: 'admin_order_delivery_options'
4
+ patch "admin/orders/:order_id/delivery_options/", controller: 'admin/orders/delivery_options', action: 'update'
5
+
3
6
  end
@@ -2,8 +2,9 @@ module SpreeDeliveryOptions
2
2
  module Generators
3
3
  class InstallGenerator < Rails::Generators::Base
4
4
 
5
- def add_javascripts
5
+ def add_javascripts
6
6
  append_file 'app/assets/javascripts/store/all.js', "//= require store/spree_delivery_options\n"
7
+ append_file 'app/assets/javascripts/admin/all.js', "//= require admin/spree_delivery_options\n"
7
8
  end
8
9
 
9
10
  def add_stylesheets
@@ -1,6 +1,7 @@
1
1
  module SpreeDeliveryOptions
2
2
  class Engine < Rails::Engine
3
3
  require 'spree/core'
4
+
4
5
  isolate_namespace Spree
5
6
 
6
7
  initializer "spree.spree_delivery_options.preferences", :after => "spree.environment" do |app|
@@ -17,7 +18,10 @@ module SpreeDeliveryOptions
17
18
  end
18
19
 
19
20
  def self.activate
20
- Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
21
+ Dir.glob(File.join(File.dirname(__FILE__), '../../app/controllers/**/*.rb')) do |c|
22
+ Rails.configuration.cache_classes ? require(c) : load(c)
23
+ end
24
+ Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*decorator*.rb')) do |c|
21
25
  Rails.configuration.cache_classes ? require(c) : load(c)
22
26
  end
23
27
  end
@@ -1,2 +1,4 @@
1
1
  require 'spree_core'
2
+ require 'spree_frontend'
3
+ require 'spree_backend'
2
4
  require 'spree_delivery_options/engine'
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Admin::Orders::DeliveryOptionsController do
4
+
5
+ let(:user) { mock_model Spree::User, :last_incomplete_spree_order => nil, :has_spree_role? => true, :spree_api_key => 'fake' }
6
+
7
+ before :each do
8
+ controller.stub :spree_current_user => user
9
+ controller.stub :check_authorization
10
+ end
11
+
12
+ describe 'edit' do
13
+
14
+ it 'should render edit' do
15
+ spree_get :edit
16
+ response.should render_template(:edit)
17
+ end
18
+
19
+ end
20
+
21
+ describe 'update' do
22
+
23
+ let(:order){Spree::Order.new}
24
+ let(:tomorrow){Date.tomorrow.strftime("%d/%m/%Y")}
25
+
26
+ before :each do
27
+ Spree::Order.stub(:find_by).and_return(order)
28
+ order.stub(:update_attributes).and_return(true)
29
+ end
30
+
31
+ it 'should update order' do
32
+ order.should_receive(:update_attributes).with({"delivery_date" => tomorrow})
33
+
34
+ spree_post :update, order: {delivery_date: tomorrow}
35
+ end
36
+
37
+ it 'should render edit when successful' do
38
+ spree_post :update, order: {delivery_date: tomorrow}
39
+ response.should render_template(:edit)
40
+ end
41
+
42
+ it 'should render edit when unsuccessful' do
43
+ order.should_receive(:update_attributes).with({"delivery_date" => tomorrow}).and_return false
44
+ spree_post :update, order: {delivery_date: tomorrow}
45
+ response.should render_template(:edit)
46
+ end
47
+
48
+ it 'should not allow to update invalid attributes' do
49
+ order.should_receive(:update_attributes).with({"delivery_date" => tomorrow})
50
+ spree_post :update, order: {delivery_date: tomorrow, crazy: 'blah'}
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -10,6 +10,18 @@ describe Spree::Order do
10
10
 
11
11
  describe 'delivery instructions' do
12
12
 
13
+ it 'should accept nil delivery instructions' do
14
+ order.delivery_instructions = nil
15
+ order.valid_delivery_instructions?.should be_true
16
+ order.errors[:delivery_instructions].should be_empty
17
+ end
18
+
19
+ it 'should accept empty delivery instructions' do
20
+ order.delivery_instructions = ""
21
+ order.valid_delivery_instructions?.should be_true
22
+ order.errors[:delivery_instructions].should be_empty
23
+ end
24
+
13
25
  it 'should accept valid delivery instructions' do
14
26
  order.delivery_instructions = "This is awesome"
15
27
  order.valid_delivery_instructions?.should be_true
data/spec/spec_helper.rb CHANGED
@@ -40,6 +40,7 @@ RSpec.configure do |config|
40
40
  # visit spree.admin_path
41
41
  # current_path.should eql(spree.products_path)
42
42
  config.include Spree::TestingSupport::UrlHelpers
43
+ config.include Spree::TestingSupport::ControllerRequests
43
44
 
44
45
  # == Mock Framework
45
46
  #
@@ -2,7 +2,7 @@
2
2
  Gem::Specification.new do |s|
3
3
  s.platform = Gem::Platform::RUBY
4
4
  s.name = 'spree_delivery_options'
5
- s.version = '2.1.9'
5
+ s.version = '2.1.10'
6
6
  s.summary = 'Adds delivery date and time during checkout'
7
7
  s.description = ''
8
8
  s.required_ruby_version = '>= 2.0.0'
@@ -17,6 +17,8 @@ Gem::Specification.new do |s|
17
17
 
18
18
  s.add_dependency 'spree_core', '~> 2.1.3'
19
19
 
20
+ s.add_runtime_dependency 'haml'
21
+
20
22
  s.add_development_dependency 'capybara', '~> 2.1'
21
23
  s.add_development_dependency 'coffee-rails'
22
24
  s.add_development_dependency 'database_cleaner'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_delivery_options
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.9
4
+ version: 2.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francisco Trindade
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-31 00:00:00.000000000 Z
11
+ date: 2014-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spree_core
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.1.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: haml
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: capybara
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -205,16 +219,21 @@ files:
205
219
  - app/assets/images/store/ui-icons_666666_256x240.png
206
220
  - app/assets/images/store/ui-icons_ff0084_256x240.png
207
221
  - app/assets/images/store/ui-icons_ffffff_256x240.png
222
+ - app/assets/javascripts/admin/delivery_time_options.js
223
+ - app/assets/javascripts/admin/spree_delivery_options.js
208
224
  - app/assets/javascripts/store/delivery_time_options.js
209
225
  - app/assets/javascripts/store/jquery-ui-1.10.4.custom.js
210
226
  - app/assets/javascripts/store/spree_delivery_options.js
227
+ - app/assets/stylesheets/admin/delivery_options_form.scss
211
228
  - app/assets/stylesheets/admin/order_details.scss
212
229
  - app/assets/stylesheets/admin/spree_delivery_options.css
213
230
  - app/assets/stylesheets/store/delivery_checkout.scss
214
231
  - app/assets/stylesheets/store/jquery-ui-1.10.4.custom.css
215
232
  - app/assets/stylesheets/store/spree_delivery_options.css
233
+ - app/controllers/spree/admin/orders/delivery_options_controller.rb
216
234
  - app/models/spree/order_decorator.rb
217
235
  - app/overrides/add_delivery_info_to_order_details.rb
236
+ - app/overrides/add_delivery_options_link_order_page.rb
218
237
  - app/overrides/admin_order_information.rb
219
238
  - app/overrides/admin_orders_delivery_date_column.rb
220
239
  - app/overrides/admin_orders_delivery_date_filter.rb
@@ -224,7 +243,9 @@ files:
224
243
  - app/views/spree/admin/orders/_delivery_date_filter.html.erb
225
244
  - app/views/spree/admin/orders/_delivery_date_header.html.erb
226
245
  - app/views/spree/admin/orders/_delivery_info.haml
246
+ - app/views/spree/admin/orders/delivery_options/edit.haml
227
247
  - app/views/spree/admin/shared/_admin_order_information_delivery_date.html.erb
248
+ - app/views/spree/admin/shared/_delivery_options_link.haml
228
249
  - app/views/spree/checkout/_delivery_date.haml
229
250
  - app/views/spree/orders/_order_delivery_date_details.html.erb
230
251
  - config/locales/en.yml
@@ -237,6 +258,7 @@ files:
237
258
  - lib/spree_delivery_options/configuration.rb
238
259
  - lib/spree_delivery_options/engine.rb
239
260
  - script/rails
261
+ - spec/controllers/spree/admin/orders/delivery_options_controller_spec.rb
240
262
  - spec/models/order_spec.rb
241
263
  - spec/spec_helper.rb
242
264
  - spree_delivery_options.gemspec
@@ -265,5 +287,6 @@ signing_key:
265
287
  specification_version: 4
266
288
  summary: Adds delivery date and time during checkout
267
289
  test_files:
290
+ - spec/controllers/spree/admin/orders/delivery_options_controller_spec.rb
268
291
  - spec/models/order_spec.rb
269
292
  - spec/spec_helper.rb