Class: Dashboard::V2::SharedReservationsGrid::Action

Inherits:
Object
  • Object
show all
Includes:
ActionView::Context, ActionView::Helpers::UrlHelper
Defined in:
app/grids/dashboard/v2/shared_reservations_grid.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_owner, model) ⇒ Action

Returns a new instance of Action.



281
282
283
284
# File 'app/grids/dashboard/v2/shared_reservations_grid.rb', line 281

def initialize(current_owner, model)
  @current_owner = current_owner
  @model = model
end

Instance Attribute Details

#current_ownerObject (readonly)

Returns the value of attribute current_owner.



279
280
281
# File 'app/grids/dashboard/v2/shared_reservations_grid.rb', line 279

def current_owner
  @current_owner
end

#modelObject (readonly)

Returns the value of attribute model.



279
280
281
# File 'app/grids/dashboard/v2/shared_reservations_grid.rb', line 279

def model
  @model
end

Instance Method Details

#buildObject



286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
# File 'app/grids/dashboard/v2/shared_reservations_grid.rb', line 286

def build
  model_policy = ReservationPolicy.new(current_owner, model)
  links = []
  html = '<div style="display:flex">'

  restaurant = model.restaurant
  address = model.address

  if model_policy.edit?
    edit = link_to(current_owner.dashboard_v2_edit_reservation_path(model.id, restaurant.id),
                   class: 'pure-menu-link pure-button pure-button-primary', title: I18n.t('views.d.edit').titlecase) do
      I18n.t('actions.edit')
    end
    links.push(edit)

    edit_table = link_to('#', id: "edit-table-#{model.id}", 'data': { table: model.table.to_s, id: model.id },
                              class: 'pure-menu-link pure-button pure-button-primary edit-table-number', title: 'Table Number') do
      raw('Table Number')
    end

    links.push(edit_table)
  end

  custom_sms = link_to('#', id: "custom-sms-#{model.id}", 'data-id': model.id,
                            class: 'pure-menu-link pure-button pure-button-primary send-sms-to-single-id', title: 'Send custom SMS') do
    raw('<i class="far fa-envelope"></i>')
  end

  if restaurant.any_offers?
    title = model.voucher.present? ? 'Edit Voucher' : I18n.t('views.d.add_voucher').titlecase
    voucher = link_to(title, '#', id: "voucher-#{model.id}", 'data-id': model.id,
                                  class: 'pure-menu-link pure-button pure-button-primary add-voucher-btn update-status', title: title)
  end

  if model_policy.mark_no_show?(by_owner: true) && model_policy.mark_arrived?(by_owner: true) && model_policy.editable?
    links.push(custom_sms)
  elsif model_policy.mark_arrived?(by_owner: true) && model_policy.editable? && model_policy.mark_no_show?(by_owner: true)
    links.push(custom_sms)
  elsif !model_policy.owner_has_sent_custom_sms? && model.active? && !model.no_show?
    links.push(custom_sms)
  end

  if links.present?
    html += '<div class="pure-menu pure-menu-vertical"><ul class="pure-menu-list">'
    links.each do |link|
      html += "<li class=\"pure-menu-item\">#{link}</li>"
    end
    html += '</ul></div>'
  end

  links = []

  if model_policy.edit? && model.delivery? && restaurant.has_self_delivery? && address.present? && model.delivery_channel.blank?
    self_deliver_channel_id = DeliveryChannel.fetch_by_lib_class('DeliveryChannel::RestaurantDelivery').id
    self_deliver_button_expired_at = if model.is_order_now? && restaurant.support_order_now? && restaurant.order_now.present?
                                       model.reservation_time - restaurant.order_now.call_driver_before_food_ready.minute
                                     else
                                       model.reservation_time - restaurant.minute_before_delivery_time.minute
                                     end
    links.push link_to(I18n.t('self_deliver'), '#',
                       'data-url': current_owner.dashboard_v2_update_reservation_path(model.id, reservation: {
                                                                                        delivery_channel_id: self_deliver_channel_id,
                                                                                      }, update_status: true),
                       class: 'pure-menu-link pure-button pure-button-primary update-status',
                       'data-id': model.id,
                       'data-button-expired-at': self_deliver_button_expired_at.iso8601,
                       'data-reservation-time': model.reservation_time.iso8601,
                       '@click.prevent': 'updateStatus')
  end

  if model_policy.editable? && model.dine_in? && model_policy.mark_arrived?(by_owner: true)
    arrive = link_to(I18n.t('views.d.arrive').titlecase, '#',
                     'data-url': current_owner.dashboard_v2_update_reservation_path(model.id, reservation: { arrived: true }, update_status: true),
                     class: 'pure-menu-link pure-button pure-button-primary update-status',
                     'data-reservation-time': model.reservation_time.iso8601,
                     '@click.prevent': 'updateStatus')
    links.push(arrive)
  end

  if restaurant.any_offers? && (model_policy.editable? && model_policy.mark_no_show?(by_owner: true))
    links.push(voucher)
  end

  if model_policy.editable? && model.dine_in? && model_policy.mark_no_show?(by_owner: true)
    no_show = link_to(I18n.t('views.d.no_show').titleize, '#',
                      'data-url': current_owner.dashboard_v2_update_reservation_path(model.id, reservation: { no_show: true }, update_status: true),
                      'data-reservation-time': model.reservation_time.iso8601,
                      class: 'pure-menu-link pure-button pure-button-primary update-status',
                      '@click.prevent': 'updateStatus')
    links.push(no_show) unless model.arrived?
  end

  if links.present?
    html += '<div class="pure-menu pure-menu-vertical" ><ul class="pure-menu-list">'
    links.each do |link|
      html += "<li class=\"pure-menu-item\">#{link}</li>"
    end
    html += '</ul></div>'
  end

  links = []

  if model_policy.be_reminded? && model_policy.editable? && !model.delivery?
    remind = link_to(current_owner.dashboard_v2_reservation_send_reminder_path(model.id),
                     class: 'pure-menu-link pure-button pure-button-primary', 'v-on:click.prevent': 'sendReminder', title: I18n.t('views.d.send_custom_reminder').titlecase) do
      raw('<i class="far fa-bell"></i>')
    end
    links.push(remind)
  end

  if model_policy.can_give_review?
    method = if model.owner_review.present?
               "addReviewPopup(#{model.id}, #{model.owner_review.try(:id)})"
             else
               "addReviewPopup(#{model.id})"
             end

    add_review = link_to(I18n.t('views.d.review_customer'), '#', id: "add-review-btn-#{model.id}",
                                                                 class: 'pure-menu-link pure-button pure-button-primary', 'v-on:click.prevent': method)
    links.push(add_review)
  elsif model.owner_review.present?
    links.push "<a v-on:click.prevent='showReviewPopup(#{model.owner_review.id})' href='#' class='bg-green pure-button white'>#{model.owner_review.rating}&nbsp;<i class='fas fa-star'></i></a>"
  end

  if model.can_request_more_bike?
    links.push "<a v-on:click.prevent='showRequestBikePopup(#{model.id})' id='request-more-bike-#{model.id}' href='#' class='bg-green pure-button white'>Request more bike</a>"
  end

  if links.present?
    html += '<div class="pure-menu pure-menu-vertical"><ul class="pure-menu-list">'
    links.each do |link|
      html += "<li class=\"pure-menu-item\">#{link}</li>"
    end
    html += '</ul></div>'
  end
  html += '</div>'

  if model.active && !model.ack && !model.rejected?
    confirm_html = '<br><div class="flex">'
    confirm_html += link_to('#',
                            class: 'bg-green br1 f5 ml1 mr1 ph2 pv1 black link',
                            '@click.prevent': raw("(e) => confirmOrRejectBooking(e, '#{current_owner.dashboard_v2_confirm_reservation_path(
                              model.id, restaurant.id, confirm: true
                            )}', '#{model.id}')")) do
      raw("<i class='far fa-check-circle'></i> #{I18n.t('views.booking.confirm')}")
    end
    confirm_html += link_to(raw("<i class='fas fa-ban'></i> #{I18n.t('views.booking.reject')}"), '#', id: "reject-btn-#{model.id}",
                                                                                                      class: 'bg-dark-red br1 f5 ml2 ph2 pv1 white link', 'v-on:click.prevent': "rejectPopup(#{model.id}, #{restaurant.id})")
    confirm_html += '</div>'

    html += confirm_html
  end

  html.html_safe
end