-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NewAdmin BO] Simple candidacies management
- Loading branch information
Showing
9 changed files
with
113 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,37 @@ | ||
ul.candidates | ||
list-style-type: none | ||
li.candidate | ||
$candidacy_height: 50px | ||
$candidacy_width: 250px | ||
$candidacy_link_width: 220px | ||
$candidacy_delete_padding: ($candidacy_width - $candidacy_link_width) / 2 | ||
$candidacy_border_size: 1px | ||
$candidacy_border_color: #c2c2c2 | ||
$candidacy_published_color: #DCF7E3 | ||
$candidacy_unpublished_color: #F2D3D3 | ||
|
||
|
||
.candidacy | ||
border: $candidacy_border_size solid $candidacy_border_color | ||
display: inline-block | ||
width: $candidacy_width | ||
a | ||
display: inline-block | ||
background-color: #e0e0e0 | ||
height: 50px | ||
width: 250px | ||
margin-bottom: 5px | ||
border: 1px solid #c2c2c2 | ||
height: $candidacy_height | ||
width: $candidacy_link_width | ||
vertical-align: middle | ||
&.candidacy-published | ||
background-color: $candidacy_published_color | ||
&.candidacy-unpublished | ||
background-color: $candidacy_unpublished_color | ||
&.candidacy-delete | ||
border-left: $candidacy_border_size solid darken($candidacy_border_color, 20%) | ||
float: right | ||
text-align: center | ||
height: 100% | ||
padding-top: $candidacy_delete_padding | ||
padding-bottom: $candidacy_delete_padding | ||
font-size: 40px | ||
color: darken($candidacy_unpublished_color, 40%) | ||
width: $candidacy_width - $candidacy_link_width - $candidacy_border_size | ||
background-color: darken($candidacy_unpublished_color, 20%) | ||
|
||
#s2id_candidacy_candidates .select2-choice | ||
height: 50px |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,53 @@ | ||
class NewAdmin::CandidaciesController < AdminController | ||
def index | ||
@election = Election.find params[:election_id] | ||
@candidates = @election.candidacies.map{|c| c.candidates[0]}.sort do |c1,c2| | ||
c1.last_name <=> c2.last_name | ||
end | ||
load_candidates | ||
@candidacy ||= Candidacy.new | ||
@available_candidates = Candidate.all.to_a.select do |c| !@candidates.include? c end | ||
end | ||
|
||
def create | ||
@election = Election.find params[:election_id] | ||
|
||
if params[:candidacy][:candidates].empty? | ||
flash[:error] = "Please choose a candidate to add" | ||
return respond_with nil, location: new_admin_election_candidacies_path(@election) | ||
end | ||
|
||
candidate = Candidate.find params[:candidacy][:candidates] | ||
|
||
@candidacy = Candidacy.new election: @election, candidates: [candidate] | ||
|
||
if @candidacy.save | ||
flash[:notice] = "#{candidate} attends to the election : #{@election}" | ||
respond_with @candidacy, location: new_admin_election_candidacies_path(@election) | ||
else | ||
flash[:error] = "Fail to add #{candidate} to #{@election}" | ||
render :index | ||
end | ||
end | ||
|
||
def destroy | ||
candidacy = Candidacy.find params[:id] | ||
candidacy.destroy | ||
@election = Election.find params[:election_id] | ||
respond_with nil, location: new_admin_election_candidacies_path(@election) | ||
end | ||
|
||
def toggle | ||
candidacy = Candidacy.find params[:candidacy_id] | ||
candidacy.published = !candidacy.published | ||
candidacy.save | ||
@election = Election.find params[:election_id] | ||
respond_with nil, location: new_admin_election_candidacies_path(@election) | ||
end | ||
|
||
protected | ||
|
||
def load_candidates | ||
@candidacies = @election.candidacies.to_a.sort do |c1,c2| | ||
c1.candidates[0].last_name <=> c2.candidates[0].last_name | ||
end | ||
candidates = @candidacies.map{ |c| c.candidates[0]} | ||
@available_candidates = Candidate.all.to_a.select do |c| !candidates.include? c end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.candidacy | ||
= link_to "×", new_admin_election_candidacy_path(@election, candidacy), class: "candidacy-delete", method: "DELETE" | ||
|
||
= link_to new_admin_election_candidacy_toggle_path(@election, candidacy), class: "candidacy-#{candidacy_state}", method: "POST" do | ||
= image_tag candidacy.candidates[0].photo_url(:small) | ||
= candidacy.candidates[0] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
= simple_form_for [:new_admin, @election, @candidacy], html: {class: "form-inline"} do |f| | ||
= f.label :candidates, "Candidate : " | ||
= f.input_field :candidates, collection: @available_candidates | ||
= f.submit "Add" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
= simple_form_for [:new_admin, @election, @candidacy] do |f| | ||
= f.input :candidates, collection: @available_candidates | ||
= render '/new_admin/flash', flash: flash | ||
|
||
%ul.candidates | ||
- @candidates.each do |candidate| | ||
%li.candidate | ||
= image_tag candidate.photo_url(:small) | ||
= candidate.name | ||
= render 'form' | ||
|
||
.candidates | ||
- @candidacies.each do |candidacy| | ||
- candidate = candidacy.candidates[0] | ||
- if candidacy.published | ||
= render "candidacy", candidacy: candidacy, candidacy_state: "published" | ||
- else | ||
= render "candidacy", candidacy: candidacy, candidacy_state: "unpublished" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters