Skip to content

Commit

Permalink
#27 copy letter
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Sep 9, 2018
1 parent cd7a3a4 commit 595f251
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
12 changes: 11 additions & 1 deletion mailanes.rb
Expand Up @@ -311,7 +311,8 @@
haml :letter, layout: :layout, locals: merged(
title: "##{letter.id}",
letter: letter,
lists: owner.lists
lists: owner.lists,
lanes: owner.lanes
)
end

Expand All @@ -337,6 +338,15 @@
redirect "/letter?id=#{letter.id}"
end

post '/copy-letter' do
letter = owner.lanes.letter(params[:id].to_i)
lane = owner.lanes.lane(params[:lane].to_i)
copy = lane.letters.add(letter.title + ' / COPY')
copy.save_yaml(letter.yaml)
copy.save_liquid(letter.liquid)
redirect "/letter?id=#{copy.id}"
end

get '/toggle-letter' do
letter = owner.lanes.letter(params[:id].to_i)
letter.toggle
Expand Down
11 changes: 11 additions & 0 deletions views/letter.haml
Expand Up @@ -12,6 +12,8 @@
Edit YAML and Liquid
%a.item{onclick: '$("#test").show();'}
Test Email
%a.item{onclick: '$("#copy").show();'}
Copy

%p
It belongs to the lane
Expand Down Expand Up @@ -60,3 +62,12 @@
%input{type: 'submit', value: 'Test'}
%label.small.gray
The email will be sent to a random recipient from the given list.

%form.hidden{method: 'POST', action: '/copy-letter', id: 'copy'}
%input{type: 'hidden', name: 'id', value: letter.id}
%select{name: 'lane'}
- lanes.all.each do |lane|
%option{value: lane.id}= "##{lane.id}: #{lane.title}"
%input{type: 'submit', value: 'Copy'}
%label.small.gray
A duplicate letter will be created in this lane.

0 comments on commit 595f251

Please sign in to comment.