From ed6de144121ed7c8b03afeb7ddb84eb68bf0094c Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 2 Jun 2017 13:17:09 +0630 Subject: [PATCH] update booking controller in crm --- app/controllers/api/bookings_controller.rb | 14 -------------- app/views/crm/home/_booking.html.erb | 22 +++++++++------------- config/routes.rb | 3 +-- 3 files changed, 10 insertions(+), 29 deletions(-) diff --git a/app/controllers/api/bookings_controller.rb b/app/controllers/api/bookings_controller.rb index ca7df569..401cd4a8 100644 --- a/app/controllers/api/bookings_controller.rb +++ b/app/controllers/api/bookings_controller.rb @@ -1,6 +1,5 @@ class Api::BookingsController < Api::ApiController skip_before_action :authenticate - #Show customer by ID def index @customer = Customer.find_by(params[:id]) @@ -10,19 +9,6 @@ class Api::BookingsController < Api::ApiController @booking = Booking.find(params[:id]) end - def update_booking - booking = Booking.find(params[:booking_id]) - status = booking.update_attributes(booking_status: params[:type]) - - if status - render json: JSON.generate({:status => true ,:type => params[:type]}) - - else - render json: JSON.generate({:status => false, :error_message => "Record not found"}) - - end - end - # private # def Bookings_params # params.permit(:id, :order_id) diff --git a/app/views/crm/home/_booking.html.erb b/app/views/crm/home/_booking.html.erb index c9200f3e..7075d685 100644 --- a/app/views/crm/home/_booking.html.erb +++ b/app/views/crm/home/_booking.html.erb @@ -20,10 +20,10 @@ @@ -42,13 +42,15 @@ $(function(){ }); $('.assign').click(function(e){ - var booking_id = $('#assign').attr('data-ref'); + var booking_id = $('#assign').attr('data-booking-ref'); + alert(booking_id); var type = $('#assign').attr('data-type'); update_booking(booking_id,type) }); $('.cancel').click(function(e){ - var booking_id = $('#cancel').attr('data-ref'); + var booking_id = $('#cancel').attr('data-booking-ref'); + alert(booking_id); var type = $('#cancel').attr('data-type'); update_booking(booking_id,type) }); @@ -91,17 +93,11 @@ function show_details(url_item){ function update_booking(booking_id,type) { $.ajax({ type: "POST", - url: "api/update_booking/" , + url: "crm/update_booking/" , data: {booking_id:booking_id,type:type}, - dataType: "json", + // dataType: "json", success: function(data) { - if(data.status == true && data.type == "cancel") - { - alert('Booking has canceled!'); - }else{ - alert('Booking has completed!'); - } - location.reload(); + } }); } diff --git a/config/routes.rb b/config/routes.rb index 0aaa2cea..698fff68 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -47,8 +47,6 @@ Rails.application.routes.draw do resources :bookings, only: [:index, :show, :create, :update] resources :customers, only: [:index, :show, :create, :update] - post "update_booking" , to: "bookings#update_booking", as: "update_booking" - #Generating Invoice and making payments - output render @sale resources :invoices, only: [:index, :show, :create, :update, :destroy ] do resources :sale_items, only:[:create, :update, :destroy] @@ -89,6 +87,7 @@ Rails.application.routes.draw do resources :customers #membership #bookings + post "update_booking" , to: "bookings#update_booking", as: "update_booking" #queue end