From 81c928b3758d93367f2659009238a07b7cd2d0d6 Mon Sep 17 00:00:00 2001 From: yamin Date: Mon, 28 Aug 2017 17:55:47 +0630 Subject: [PATCH] InJutyUpdate --- .../origami/in_juties_controller.rb | 27 ++++++++---- .../in_juties/_assign_in_juty.html.erb | 22 +++++++--- .../origami/in_juties/_edit_in_juty.html.erb | 3 +- .../origami/in_juties/index_in_juty.html.erb | 42 ++++++++++++------- config/routes.rb | 7 ++-- 5 files changed, 66 insertions(+), 35 deletions(-) diff --git a/app/controllers/origami/in_juties_controller.rb b/app/controllers/origami/in_juties_controller.rb index 821aa409..5903ace3 100644 --- a/app/controllers/origami/in_juties_controller.rb +++ b/app/controllers/origami/in_juties_controller.rb @@ -8,9 +8,10 @@ class Origami::InJutiesController < BaseOrigamiController end def index_in_juty - @juties_in= InJuty.where("dinning_id=?",params[:table_id]) + @juty_in= InJuty.where("dinning_id=?",params[:table_id]) @table = DiningFacility.find(params[:table_id]) @in_juty = InJuty.new + @juties_in = Kaminari.paginate_array(@juty_in).page(params[:page]).per(10) end # GET /in_juties/1 @@ -31,6 +32,9 @@ class Origami::InJutiesController < BaseOrigamiController def edit_in_juty @in_juty = InJuty.find(params[:id]) @table = DiningFacility.find(params[:table_id]) + @commissioner = @in_juty.commissioner + + render json: {in_juty: @in_juty, commissioner: @commissioner} end def assign_in_juty @@ -89,12 +93,19 @@ class Origami::InJutiesController < BaseOrigamiController end - def update_for_in_juty - @in_juty.dinning_id = params[:dining_id] - @in_juty.commissioner_ids = params[:commissioner_ids] - @in_juty.in_time = params[:in_time] - @in_juty.out_time = params[:out_time] - @in_juty.save + def update_for_in_juty + @in_juty.commissioner_ids = in_juty_params[:commissioner_ids] + @in_juty.in_time = in_juty_params[:in_time] + @in_juty.out_time = in_juty_params[:out_time] + respond_to do |format| + if @in_juty.save + format.html { redirect_to origami_index_in_juty_path(in_juty_params[:dinning_id]), notice: 'In juty was successfully updated.' } + format.json { render :show, status: :ok, location: @in_juty } + else + format.html { render :edit } + format.json { render json: @in_juty.errors, status: :unprocessable_entity } + end + end end # DELETE /in_juties/1 @@ -125,6 +136,6 @@ class Origami::InJutiesController < BaseOrigamiController # Never trust parameters from the scary internet, only allow the white list through. def in_juty_params - params.require(:in_juty).permit(:dinning_id,:commissioner_ids,:in_time,:out_time) + params.require(:in_juty).permit(:id,:dinning_id,:commissioner_ids,:in_time,:out_time) end end diff --git a/app/views/origami/in_juties/_assign_in_juty.html.erb b/app/views/origami/in_juties/_assign_in_juty.html.erb index f2f0ed16..258c5eb7 100644 --- a/app/views/origami/in_juties/_assign_in_juty.html.erb +++ b/app/views/origami/in_juties/_assign_in_juty.html.erb @@ -1,9 +1,12 @@ -<%= simple_form_for @in_juty,:url => origami_create_for_in_juty_path, :method => :post do |f| %> +<%= simple_form_for @in_juty,:url => origami_index_in_juty_path(@table.id), :method => :post do |f| %> <%= f.error_notification %> - + <%= f.hidden_field :id, :class => "form-control col-md-6 " %> +
+ <%= f.hidden_field :dinning_id,:value => @table.id, :class => "form-control col-md-6 " %> + <%= @table.name %>
@@ -12,14 +15,14 @@ <%= f.collection_select :commissioner_ids, Commissioner.all, :id, :name, {prompt: 'Select Commissioner'}, {class: 'form-control'} %>

- <%= f.text_field :in_time, :value=>DateTime.now.strftime("%Y-%m-%d / %I:%M %p"),:class=>"form-control datepicker"%>
+ <%= f.text_field :in_time, :value=>'',:class=>"form-control datepicker"%>
- <%= f.text_field :out_time, :value=>DateTime.now.strftime("%Y-%m-%d / %I:%M %p"),:class=>"form-control datepicker"%> + <%= f.text_field :out_time, :value=>'',:class=>"form-control datepicker"%>

<%= f.button :submit, "Create",:class => 'btn btn-primary ', :id => 'create' %> - <%= f.button :submit, "Update",:class => 'btn btn-primary ', :disabled =>'disabled', :id => 'update' %> + <%= f.button :submit, "Update",:class => 'btn btn-primary ', :disabled =>'', :id => 'update' %> <%= f.button :button, "Reset",:class => 'btn btn-danger ', :id => 'reset' %>
@@ -30,11 +33,18 @@ $(function() { $('.datepicker').datepicker({ - format : 'dd-mm-yyyy', + format : 'yyyy-mm-dd', autoclose: true }); $('.datepicker').attr('ReadOnly','true'); $('.datepicker').css('cursor','pointer'); }); +$('#reset').click(function() { + + // window.location.href = '/origami/assign_in_juty/'+ table_id; + location.reload(); + + return false; + }); \ No newline at end of file diff --git a/app/views/origami/in_juties/_edit_in_juty.html.erb b/app/views/origami/in_juties/_edit_in_juty.html.erb index a2405f58..9eaf8353 100644 --- a/app/views/origami/in_juties/_edit_in_juty.html.erb +++ b/app/views/origami/in_juties/_edit_in_juty.html.erb @@ -2,8 +2,7 @@ <%= f.error_notification %>
- <%= f.input :dinning_id %> - <%= f.input :commissioner_ids %> + <%= f.collection_select :commissioner_ids, Commissioner.all, :id, :name, {prompt: 'Select Commissioner'}, {class: 'form-control'} %>

<%= f.input :in_time %> <%= f.input :out_time %>
diff --git a/app/views/origami/in_juties/index_in_juty.html.erb b/app/views/origami/in_juties/index_in_juty.html.erb index 0141af05..2ac1048e 100644 --- a/app/views/origami/in_juties/index_in_juty.html.erb +++ b/app/views/origami/in_juties/index_in_juty.html.erb @@ -4,6 +4,7 @@ + @@ -21,13 +22,12 @@ - - <% end %>
Select Dining Facility Name Commissioner Ids In time<%= in_juty.commissioner.name rescue '-' %> <%= in_juty.in_time.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") rescue '-' %> <%= in_juty.out_time.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") rescue '-' %><%= link_to 'Back', origami_path(in_juty.dining_facility.id) %><%= link_to 'Edit', origami_edit_in_juty_path(in_juty.dining_facility.id,in_juty) %> <%= link_to 'Destroy', origami_destroy_in_juty_path(in_juty.dining_facility.id,in_juty),method: :delete, data: {confirm: 'Are you sure?'} %>
+ <%= paginate @juties_in %>
@@ -35,40 +35,45 @@
+
+ +
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 83e7c150..ec72efa9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -94,10 +94,11 @@ Rails.application.routes.draw do post 'select_commissioner' => 'product_commissions#set_commissioner_to_sale_item' # in_juties get '/table/:table_id/assign_in_juty' => 'in_juties#assign_in_juty', as: 'assign_in_juty' - post 'assign_in_juty' => 'in_juties#create_for_in_juty', as: 'create_for_in_juty' get 'assign_in_juty/:table_id' => 'in_juties#index_in_juty', as: 'index_in_juty' - get 'table/:table_id/in_juty/:id/edit' => 'in_juties#edit_in_juty' ,as: 'edit_in_juty' - put '/edit_in_juty/:id' => 'in_juties#update_for_in_juty', as: 'update_for_in_juty' + post 'assign_in_juty/:table_id' => 'in_juties#create_for_in_juty' + + get 'assign_in_juty/table/:table_id/in_juty/:id/edit' => 'in_juties#edit_in_juty' ,as: 'edit_in_juty' + patch 'edit_in_juty/:id' => 'in_juties#update_for_in_juty', as: 'update_for_in_juty' delete 'table/:table_id/destroy_in_juty/:id' => 'in_juties#destroy_in_juty', as: 'destroy_in_juty' get 'table/:dining_id/movetable' => "movetable#move_dining"