Permalink
Browse files

Fixed shipping date form for orders and added validation.

  • Loading branch information...
1 parent 28e7a23 commit 8e23ae73d077630b0ad0818d9fb72408b8e5b5d9 @Jellyfishboy committed Aug 4, 2016
@@ -17,12 +17,13 @@ def edit
def update
set_order
+ @order.validate_shipping_date!
if @order.update(params[:order])
OrderMailer.updated_dispatched(@order).deliver_later if @order.changed_shipping_date?
render json:
{
order_id: @order.id,
- date: @order.updated_at.strftime("%d/%m/%Y"),
+ date: @order.shipping_date.strftime("%d/%m/%Y %R"),
row: render_to_string(partial: 'admin/orders/single', locals: { order: @order })
}, status: 200
else
@@ -0,0 +1,18 @@
+module HasShippingDateValidation
+ extend ActiveSupport::Concern
+
+ included do
+ validates :shipping_date, presence: true, if: :validate_shipping_date
+
+ attr_accessor :validate_shipping_date
+ after_initialize :set_validate_shipping_date
+
+ def validate_shipping_date!
+ @validate_shipping_date = true
+ end
+ end
+
+ def set_validate_shipping_date
+ @validate_shipping_date = false
+ end
+end
View
@@ -31,6 +31,7 @@
require 'reportatron_4000'
class Order < ActiveRecord::Base
+ include HasShippingDateValidation
attr_accessible :shipping_status, :shipping_date, :actual_shipping_cost,
:email, :delivery_id, :ip_address, :user_id, :cart_id, :net_amount, :tax_amount,
@@ -16,7 +16,7 @@
<fieldset class="widget widget-content widget-last">
<div class="form-group">
<%= f.label 'Dispatch Date' %>
- <%= f.text_field :shipping_date, class: 'form-control datetimepicker', value: (@order.shipping_date.strftime('%d/%m/%Y %I:%M%p') unless @order.shipping_date.nil?) %>
+ <%= f.text_field :shipping_date, class: 'form-control datetimepicker', value: (@order.shipping_date.strftime('%d/%m/%Y %R') unless @order.shipping_date.nil?) %>
</div>
<div class="form-group form-last">
<%= f.label :consignment_number %>
@@ -1,4 +1,10 @@
$(document).ajaxComplete(function()
{
- soca.misc.datepicker();
+ var date = new Date();
+ date.setDate(date.getDate());
+ $('.datetimepicker').datetimepicker(
+ {
+ format: "d/m/Y H:m",
+ minDate: date
+ });
});

0 comments on commit 8e23ae7

Please sign in to comment.