-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ability to Create/Update/Delete a campaign
- Loading branch information
Gabriel Forestier
committed
Aug 17, 2015
1 parent
cae4f40
commit 3317985
Showing
15 changed files
with
279 additions
and
14 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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# encoding: utf-8 | ||
|
||
## | ||
# The Controller that manage Campaigns | ||
# | ||
class CampaignsController < ApplicationController | ||
load_and_authorize_resource | ||
|
||
## | ||
# Display the list of all Campaigns by paginate_by | ||
# | ||
# GET /campaigns | ||
def index | ||
@campaigns = Campaign.order('date_begin DESC').page(params[:page]) | ||
|
||
respond_to do |format| | ||
format.html # index.html.erb | ||
end | ||
end | ||
|
||
## | ||
# Render a page to create new Campaign | ||
# | ||
def new | ||
@campaign = Campaign.new | ||
|
||
respond_to do |format| | ||
format.html # new.html.erb | ||
end | ||
end | ||
|
||
## | ||
# Process to insert a new Campaign into the DataBase | ||
# | ||
def create | ||
@campaign = Campaign.new(params[:campaign]) | ||
@campaign.created_by = current_user.id | ||
|
||
respond_to do |format| | ||
if @campaign.save | ||
format.html { redirect_to campaigns_path, :notice => t('app.message.notice.created_campaign') } | ||
else | ||
format.html { render :action => "new" } | ||
end | ||
end | ||
end | ||
|
||
|
||
def edit | ||
@campaign = Campaign.find(params[:id]) | ||
end | ||
|
||
## | ||
# Process that udpate an existing Campaign | ||
# | ||
def update | ||
@campaign = Campaign.find(params[:id]) | ||
@campaign.modified_by = current_user.id | ||
|
||
respond_to do |format| | ||
if @campaign.update_attributes(params[:campaign]) | ||
format.html { redirect_to(campaigns_url, :notice => t('app.message.notice.updated_campaign')) } | ||
else | ||
flash[:error] = t('app.save_undefined_error') | ||
format.html { render :action => "edit" } | ||
end | ||
end | ||
end | ||
|
||
## | ||
# Process that remove a Campaign from the DB | ||
# | ||
def destroy | ||
@campaign = Campaign.find(params[:id]) | ||
respond_to do |format| | ||
begin | ||
if @campaign.destroy | ||
format.html { redirect_to(campaigns_url, :notice => t('app.message.notice.deleted_campaign')) } | ||
else | ||
flash[:error] = t('app.delete_undefined_error') | ||
format.html { render :action => "edit" } | ||
end | ||
rescue ActiveRecord::DeleteRestrictionError | ||
@campaign.errors.add(:base, t('errors.messages.restrict_dependent_destroy', count: 1)) | ||
ensure | ||
format.html { render :action => "edit" } | ||
end | ||
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
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,60 @@ | ||
<%= form_for(@campaign, :html => { :class => "well "}) do |f| %> | ||
<% if @campaign.errors.any? %> | ||
<div id="error_explanation" class="alert alert-error"> | ||
<button type="button" class="close" data-dismiss="alert">×</button> | ||
<h4><%= t('app.message.error.occured_error') %></h4> | ||
<ul> | ||
<% @campaign.errors.full_messages.each do |msg| %> | ||
<li><%= msg %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div class="field"> | ||
<div class="span2"><%= f.label :name %> :</div> | ||
<%= f.text_field :name,{ :class => 'required'} %><span class="req" /> | ||
</div> | ||
|
||
<div class="field"> | ||
<div class="span2"><%= f.label :date_begin %> :</div> | ||
<%= f.text_field :date_begin, :value => @campaign.date_begin.strftime(t('date.formats.default')) unless @campaign.date_begin.blank? %> | ||
<%= f.time_select :date_begin %> | ||
</div> | ||
|
||
<div class="field"> | ||
<div class="span2"><%= f.label :date_end %> :</div> | ||
<%= f.text_field :date_end, :value => @campaign.date_end.strftime(t('date.formats.default')) unless @campaign.date_end.blank? %> | ||
<%= f.time_select :date_end %> | ||
</div> | ||
|
||
<div class="field"> | ||
<div class="span2"><%= f.label :event_type %> :</div> <%= f.collection_select :event_type_id, EventType.order('label ASC, direction ASC').all, :id, :full_type, :include_blank => true %> | ||
</div> | ||
|
||
<div class="field"> | ||
<div class="span2"><%= f.label :notes %> :</div> | ||
<%=f.text_area :notes , :display_with => :simple_format, :rows => "5", :style => 'width: 50%;' %> | ||
</div> | ||
|
||
<br /> | ||
|
||
<div class="field"> | ||
<% if !@campaign.id.nil? %> | ||
<div class="span9"> <%= t("app.actions.created_by")%> : <%= @campaign.author.full_name %>, le </strong><%= @campaign.created_at.strftime("%d/%m/%y à %H:%M") %>. </div> | ||
<br /> | ||
<% if !@campaign.modified_by.nil? %> | ||
<div class="span9"> <%= t("app.actions.updated_by")%> : <%= @campaign.editor.full_name %>, le <%= @campaign.updated_at.strftime("%d/%m/%y à %H:%M") %>. </div> | ||
<br /> | ||
<% end %> | ||
<% end %> | ||
</div> | ||
|
||
<hr /> | ||
|
||
<div class="row"> | ||
<%= if !@campaign.id.nil? then f.button t("app.actions.update") + " " + Campaign.model_name.human, :type => :submit, :class =>"btn btn-primary",:id =>"campaign_validate_form" else f.button t("app.actions.create") + " " + Campaign.model_name.human, :type => :submit, :class =>"btn btn-primary",:id =>"campaign_validate_form" end%> | ||
<%= if !@campaign.id.nil? then link_to '<i class="fa fa-trash fa-lg"></i>'.html_safe, @campaign, :title => t("app.actions.destroy") + " " + Campaign.model_name.human, :confirm => t("app.message.confirm.delete"), :class=>"pull-right btn", :method => :delete end %> | ||
</div> | ||
|
||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<div class="container-fluid" style="margin-top: 1em;"> | ||
<div class="well"> | ||
<div class="row-fluid"> | ||
<div class="span9"> | ||
<h1><i class="fa fa-university"></i> <%= Campaign.model_name.human(count: 2).capitalize %></h1> | ||
</div> | ||
<%= link_to '<i class="fa fa-plus-circle fa-3x action-icon"></i>'.html_safe, new_campaign_path ,{:title => t("app.actions.create") + " " + Campaign.model_name.human, :class=>"pull-right"}%> | ||
</div> | ||
</div> | ||
</div> |
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,10 @@ | ||
<div class="container-fluid"> | ||
<div class="well" style="margin-top: 1em;"> | ||
<div class="row-fluid"> | ||
<div class="span9"> | ||
<h1><i class="fa fa-university"></i> <%= t('app.actions.edition').capitalize + " " + Campaign.model_name.human.capitalize %> n°<%= @campaign.id %></h1> | ||
</div> | ||
<%= link_to '<i class="fa fa-arrow-circle-left fa-3x action-icon"></i>'.html_safe, :back ,{:title => t("link.back"), :class=>"pull-right"} %> | ||
</div> | ||
</div> <%= render 'form' %> | ||
</div> |
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,34 @@ | ||
<%= render 'title', :locals => { :title => @title }%> | ||
|
||
<div class="container-fluid"> | ||
|
||
<table class="table table-bordered table-striped"> | ||
<thead> | ||
<tr> | ||
<th class="text-center"><%= t("helpers.label.campaign.name") %></th> | ||
<th class="text-center"><%= t("helpers.label.campaign.date_begin") %></th> | ||
<th class="text-center"><%= t("helpers.label.campaign.date_end") %></th> | ||
<th class="text-center"><%= t("helpers.label.campaign.event_type") %></th> | ||
<th class="text-center"><%= t("app.actions.edit") %></th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
<% @campaigns.each do |campaign| %> | ||
<tr> | ||
<td class="text-center"><%= campaign.name %></td> | ||
<td class="text-center"><%= campaign.date_begin.strftime(t('datetime.formats.default')) unless campaign.date_begin.blank? %></td> | ||
<td class="text-center"><%= campaign.date_end.strftime(t('datetime.formats.default')) unless campaign.date_end.blank? %></td> | ||
<td class="text-center"><%= campaign.event_type.full_type unless campaign.event_type.blank? %></td> | ||
<td class="text-center"><%= link_to '<i class="fa fa-edit fa-2x action-icon"></i>'.html_safe, edit_campaign_path(campaign),{:title => t("app.actions.edit") + " " + Campaign.model_name.human} %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
|
||
</table> | ||
|
||
<br /> | ||
|
||
<%= paginate @campaigns %> | ||
|
||
</div> |
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,13 @@ | ||
<div class="container-fluid"> | ||
|
||
<div class="well" style="margin-top: 1em;"> | ||
<div class="row-fluid"> | ||
<div class="span9"> | ||
<h1><i class="fa fa-university"></i> <%= t('app.default.new_female').capitalize + " " + Campaign.model_name.human.capitalize %></h1> | ||
</div> | ||
<%= link_to '<i class="fa fa-arrow-circle-left fa-3x action-icon"></i>'.html_safe, :back ,{:title => t('link.back'), :class=>"pull-right"}%> | ||
</div> | ||
</div> | ||
|
||
<%= render 'form' %> | ||
</div> |
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
Oops, something went wrong.