From 29a5062b85802f3b7895f8b77f73140a955d08e3 Mon Sep 17 00:00:00 2001 From: yamin Date: Fri, 25 Aug 2017 13:06:25 +0630 Subject: [PATCH] InJutiesUpdate --- app/controllers/origami/in_juties_controller.rb | 12 ++++++++---- .../origami/in_juties/_assign_in_juty.html.erb | 12 ++++++------ ..._edit_form.html.erb => _edit_in_juty.html.erb} | 14 +++++++------- .../origami/in_juties/assign_in_juty.html.erb | 3 +++ app/views/origami/in_juties/edit_in_juty.html.erb | 8 ++------ .../origami/in_juties/index_in_juty.html.erb | 15 +++++++++++++-- config/routes.rb | 6 +++--- 7 files changed, 42 insertions(+), 28 deletions(-) rename app/views/origami/in_juties/{_edit_form.html.erb => _edit_in_juty.html.erb} (82%) diff --git a/app/controllers/origami/in_juties_controller.rb b/app/controllers/origami/in_juties_controller.rb index f13c6fb6..4106b77a 100644 --- a/app/controllers/origami/in_juties_controller.rb +++ b/app/controllers/origami/in_juties_controller.rb @@ -1,5 +1,5 @@ class Origami::InJutiesController < BaseOrigamiController - before_action :set_in_juty, only: [:show, :edit, :update,:edit_in_juty, :update_for_in_juty , :destroy ,:destroy_in_juty] + before_action :set_in_juty, only: [:show, :edit, :update, :edit_in_juty, :update_for_in_juty , :destroy ,:destroy_in_juty] # GET /in_juties # GET /in_juties.json @@ -9,6 +9,8 @@ class Origami::InJutiesController < BaseOrigamiController def index_in_juty @juties_in= InJuty.where("dinning_id=?",params[:table_id]) + @table = params[:table_id] + end # GET /in_juties/1 # GET /in_juties/1.json @@ -49,7 +51,7 @@ class Origami::InJutiesController < BaseOrigamiController end def create_for_in_juty - + @in_juty = InJuty.new @in_juty.dinning_id = params[:dining_id] @in_juty.commissioner_ids = params[:commissioner_ids] @in_juty.in_time = params[:in_time] @@ -77,7 +79,7 @@ class Origami::InJutiesController < BaseOrigamiController @in_juty.commissioner_ids = params[:commissioner_ids] @in_juty.in_time = params[:in_time] @in_juty.out_time = params[:out_time] - @in_juty.update + @in_juty.save end # DELETE /in_juties/1 @@ -91,9 +93,11 @@ class Origami::InJutiesController < BaseOrigamiController end def destroy_in_juty + @table_id = params[:table_id] @in_juty.destroy + respond_to do |format| - format.html { redirect_to origami_in_juties_path, notice: 'In juty was successfully destroyed.' } + format.html { redirect_to origami_index_in_juty_path(@table_id), notice: 'In juty was successfully destroyed.' } format.json { head :no_content } 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 14469fde..8463c191 100644 --- a/app/views/origami/in_juties/_assign_in_juty.html.erb +++ b/app/views/origami/in_juties/_assign_in_juty.html.erb @@ -3,13 +3,13 @@ <%= f.error_notification %>
- <%= f.label :dinning_id %> -
+ <%= @table.name %>
+
- <%= f.label :commissioner_ids %> - <%= f.collection_select :commissioner_ids, Commissioner.all, :id, :name, {prompt: 'Select Commissioner'}, {class: 'form-control'} %>
+ + <%= 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"%>
@@ -18,7 +18,7 @@
- <%= link_to 'Back', origami_path(@table.id), class: 'btn btn-success' %> + <%= link_to 'Back', origami_index_in_juty_path(@table.id), class: 'btn btn-success' %>
@@ -50,7 +50,7 @@ $(function() { url: ajax_url, data: 'dining_id=' + dining_id + "&commissioner_ids=" + commissioner_ids +'&in_time=' + in_time + "&out_time=" + out_time, success: function (result) { - window.location.href = '/origami/table/' + dining_id; + window.location.href = '/origami/assign_in_juty/'+ dining_id; } }); }) diff --git a/app/views/origami/in_juties/_edit_form.html.erb b/app/views/origami/in_juties/_edit_in_juty.html.erb similarity index 82% rename from app/views/origami/in_juties/_edit_form.html.erb rename to app/views/origami/in_juties/_edit_in_juty.html.erb index 61f6512f..86622c66 100644 --- a/app/views/origami/in_juties/_edit_form.html.erb +++ b/app/views/origami/in_juties/_edit_in_juty.html.erb @@ -3,13 +3,13 @@ <%= f.error_notification %>
- <%= f.label :dinning_id %> -
+ <%= @table.name %>
+
- <%= f.label :commissioner_ids %> - <%= f.collection_select :commissioner_ids, Commissioner.all, :id, :name, {prompt: 'Select Commissioner'}, {class: 'form-control'} ,:value => @in_juty.commissioner.name %>
+ + <%= f.collection_select :commissioner_ids, Commissioner.all, :id, :name, {class: 'form-control'} ,:value => @in_juty.commissioner.name %>

<%= f.text_field :in_time, :value=>DateTime.now.strftime("%Y-%m-%d / %I:%M %p"),:class=>"form-control datepicker" ,:value => @in_juty.in_time %>
@@ -18,7 +18,7 @@
- <%= link_to 'Back', origami_index_in_juty_path, class: 'btn btn-success' %> + <%= link_to 'Back', origami_index_in_juty_path(@table.id), class: 'btn btn-success' %>
@@ -49,9 +49,9 @@ $(function() { $.ajax({ type: "PUT", url: ajax_url, - data: 'dining_id=' + dining_id + "&commissioner_ids=" + commissioner_ids +'&in_time=' + in_time + "&out_time=" + out_time, + data: 'dining_id=' + dining_id + "&commissioner_ids=" + commissioner_ids +'&in_time=' + in_time + "&out_time=" + out_time + "&table_id=" + dining_id, success: function (result) { - window.location.href = '/origami/assign_in_juty'; + window.location.href = '/origami/assign_in_juty/'+ dining_id; } }); }) 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 09dd646a..93dd4745 100644 --- a/app/views/origami/in_juties/assign_in_juty.html.erb +++ b/app/views/origami/in_juties/assign_in_juty.html.erb @@ -1,3 +1,6 @@
+ <%= render 'assign_in_juty', in_juty: @in_juty %>
\ 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 3a6fc774..473071d0 100644 --- a/app/views/origami/in_juties/edit_in_juty.html.erb +++ b/app/views/origami/in_juties/edit_in_juty.html.erb @@ -1,10 +1,6 @@
- <%= render 'form', in_juty: @in_juty %> + <%= render 'edit_in_juty', in_juty: @in_juty %>
\ No newline at end of file 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 29e4ebab..fc5128bb 100644 --- a/app/views/origami/in_juties/index_in_juty.html.erb +++ b/app/views/origami/in_juties/index_in_juty.html.erb @@ -28,10 +28,21 @@ <%= 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 'Edit', origami_edit_in_juty_path(in_juty) %> - <%= link_to 'Destroy', origami_destroy_in_juty_path(in_juty), method: :delete, data: {confirm: 'Are you sure?'} %> + <%= 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?'} %> <% end %>
+ + \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 3e8caa28..3552d8f3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -94,9 +94,9 @@ Rails.application.routes.draw do 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 '/in_juty/:in_juty_id/edit' => 'in_juties#edit_in_juty' ,as: 'edit_in_juty' - put '/edit_in_juty/:in_juty_id' => 'in_juties#update_for_in_juty', as: 'update_for_in_juty' - delete '/destroy_in_juty/:in_juty_id' => 'in_juties#destroy_in_juty', as: 'destroy_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' + delete 'table/:table_id/destroy_in_juty/:id' => 'in_juties#destroy_in_juty', as: 'destroy_in_juty'