Module: Card::Set::Self::Trash::HtmlFormat

Extended by:
AbstractFormat
Defined in:
card/tmpsets/set/mod001-admin/self/trash.rb,
card/tmpsets/set/mod002-core/self/trash.rb

Instance Method Summary collapse

Instance Method Details



39
40
41
42
43
44
45
46
47
48
49
# File 'card/tmpsets/set/mod001-admin/self/trash.rb', line 39

def empty_trash_link
  wrap_with(
    :p,
    button_link("empty trash",
                btn_type: :default,
                path: { mark: :admin, action: :update, task: :empty_trash,
                        success: { id: "~#{card.id}" } },
                "data-confirm" => "Are you sure you want to delete "\
                                  "all cards in the trash?")
  )
end


51
52
53
54
# File 'card/tmpsets/set/mod001-admin/self/trash.rb', line 51

def history_link trashed_card
  link_to_card trashed_card, "history",
               path: { view: :history, look_in_trash: true }
end


56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'card/tmpsets/set/mod001-admin/self/trash.rb', line 56

def restore_link trashed_card
  before_delete = trashed_card.actions[-2]
  link_to "restore", method: :post,
                     rel: "nofollow",
                     remote: true,
                     class: "slotter",
                     path: { id: trashed_card.id,
                             view: :open,
                             look_in_trash: true,
                             action: :update,
                             restore: trashed_card.id,
                             action_ids: [before_delete],
                             success: { id: "~#{card.id}" } }
end

#restoredObject



31
32
33
34
35
36
37
# File 'card/tmpsets/set/mod001-admin/self/trash.rb', line 31

def restored
  return unless (res_id = Env.params[:restore]) &&
                (res_card = Card[res_id.to_i])
  alert :success, true do
    wrap_with(:h5, "restored") + subformat(res_card).render_bar
  end
end

#trash_table_row(card) ⇒ Object



22
23
24
25
26
27
28
29
# File 'card/tmpsets/set/mod001-admin/self/trash.rb', line 22

def trash_table_row card
  [
    card.name,
    "#{time_ago_in_words(card.updated_at)} ago",
    Card[card.updater_id].name,
    "#{history_link(card)} | #{restore_link(card)}"
  ]
end

#trashed_cardsObject



18
19
20
# File 'card/tmpsets/set/mod001-admin/self/trash.rb', line 18

def trashed_cards
  Card.where(trash: true).order(updated_at: :desc)
end

#view: coreObject



9
10
11
12
13
14
15
16
# File 'card/tmpsets/set/mod001-admin/self/trash.rb', line 9

view :core do
  rows = trashed_cards.map { |tc| trash_table_row(tc) }
  output [
    restored,
    (empty_trash_link if rows.present?),
    table(rows, header: ["card", "deleted", "by", ""])
  ]
end