Skip to content

Commit

Permalink
Merge pull request #216 from Crowdtilt/homepage_and_site_settings
Browse files Browse the repository at this point in the history
Split website tab into "homepage" and "site settings" tabs
  • Loading branch information
liuhenry committed Feb 2, 2014
2 parents 37f63d8 + f42e12a commit 9f07df3
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 54 deletions.
7 changes: 6 additions & 1 deletion app/assets/javascripts/unsaved_changes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ var unsavedChangesChecker = function() {
}

$(function() {
if ($('#admin_website_form, #admin_campaign_form').length) {
var elements = '#admin_homepage_form, #admin_site_settings_form, #admin_campaign_form';
if ($(elements).length) {
$(window).bind('beforeunload', unsavedChangesChecker);

$(elements).submit(function() {
$(window).unbind('beforeunload', unsavedChangesChecker);
});
}
});
4 changes: 2 additions & 2 deletions app/assets/javascripts/validate.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

$( document ).ready(function() {

// validate '/admin'
$("#admin_website_form").validate({
// validate '/admin/site-settings'
$("#admin_site_settings_form").validate({

// custom handler to call named function ""
submitHandler: function (form) {
Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/admin.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
}

#admin_website, #admin_campaigns {
#admin_homepage, #admin_site_settings, #admin_campaigns {

fieldset {
margin-bottom: 30px;
Expand Down
15 changes: 13 additions & 2 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,22 @@ def admin_dashboard
redirect_to admin_campaigns_url, flash: flash
end

def admin_website
def admin_homepage
#Handle the form submission if request is PUT
if request.put?
if @settings.update_attributes(params[:settings])
flash.now[:success] = "Website settings successfully updated!"
flash.now[:success] = "Homepage successfully updated!"
else
flash.now[:error] = @settings.errors.full_messages.join(', ')
end
end
end

def admin_site_settings
#Handle the form submission if request is PUT
if request.put?
if @settings.update_attributes(params[:settings])
flash.now[:success] = "Site settings successfully updated!"
else
flash.now[:error] = @settings.errors.full_messages.join(', ')
end
Expand Down
7 changes: 5 additions & 2 deletions app/views/admin/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
<li class="<%= 'active' if active == 'campaigns' %>">
<%= link_to "Campaigns", admin_campaigns_path, :class => 'show_loader', :'data-loader' => "admin_header" %>
</li>
<li class="<%= 'active' if active == 'website' %>">
<%= link_to "Website", admin_website_path, :class => 'show_loader', :'data-loader' => "admin_header" %>
<li class="<%= 'active' if active == 'homepage' %>">
<%= link_to "Homepage", admin_homepage_path, :class => 'show_loader', :'data-loader' => "admin_header" %>
</li>
<li class="<%= 'active' if active == 'site_settings' %>">
<%= link_to "Site Settings", admin_site_settings_path, :class => 'show_loader', :'data-loader' => "admin_header" %>
</li>
<li class="<%= 'active' if active == 'payments' %>">
<%= link_to "Payment Settings", admin_processor_setup_path, :class => 'show_loader', :'data-loader' => "admin_header" %>
Expand Down
61 changes: 61 additions & 0 deletions app/views/admin/admin_homepage.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<div id="admin">
<div class="container content_box clearfix">

<%= render 'admin/header', active: 'homepage' %>

<div id="admin_homepage">

<%= form_for(@settings, url: admin_homepage_path, multipart: true, html: { id: "admin_homepage_form" }) do |f| %>

<fieldset>
<legend>Homepage Content</legend>

<div class="field clearfix">
<p class="explanation inline">This content is shown on the homepage in addition to the campaign titles.</p>
<%= f.cktext_area :homepage_content %>
</div>

</fieldset>

<fieldset>
<legend>Sharing Details</legend>

<div class="field clearfix">
<p class="explanation">This is the default text that will be used for the tweet button.</p>
<label>Tweet Text</label>
<%= f.text_area :tweet_text, rows: 2 %>
</div>

<div class="field clearfix">
<p class="explanation">The title shown when your site is shared via Facebook. Leave this blank if you want to use your project name.</p>
<label>Facebook Title</label>
<%= f.text_field :facebook_title %>
</div>

<div class="field clearfix">
<p class="explanation">The description shown when your site is shared via Facebook.</p>
<label>Facebook Description</label>
<%= f.text_area :facebook_description, rows: 2 %>
</div>

<div class="field clearfix">
<p class="explanation">The image shown when your site is shared via facebook. This should have a square aspect ratio and be at least 200px by 200px.</p>
<label>Facebook Image</label>
<% if @settings.facebook_image.file? %>
<%= image_tag @settings.facebook_image.url(:thumb) %><br/>
<%= f.file_field :facebook_image %><br/>
<%= f.check_box :facebook_image_delete %><span>Delete current image</span>
<% else %>
<%= f.file_field :facebook_image %>
<% end %>
</div>

</fieldset>

<%= f.submit "Save", :'class' => "btn btn-primary show_loader", :'data-loader' => "project_form" %>
<span class="loader" data-loader="project_form" style="display:none"></span>

<% end %>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<div id="admin">
<div class="container content_box clearfix">

<%= render 'admin/header', active: 'website' %>
<%= render 'admin/header', active: 'site_settings' %>

<div id="admin_website">
<div id="admin_site_settings">

<%= form_for(@settings, url: admin_website_path, multipart: true, html: { id: "admin_website_form" }) do |f| %>
<%= form_for(@settings, url: admin_site_settings_path, multipart: true, html: { id: "admin_site_settings_form" }) do |f| %>

<fieldset>
<legend>Basic Information</legend>
Expand Down Expand Up @@ -48,47 +48,6 @@
<%= f.text_field :header_link_url %>
</div>

<div class="field clearfix">
<label>Homepage Content</label>
<p class="explanation inline">This content is shown on the homepage in addition to the campaign titles.</p>
<%= f.cktext_area :homepage_content %>
</div>

</fieldset>

<fieldset>
<legend>Sharing Details</legend>

<div class="field clearfix">
<p class="explanation">This is the default text that will be used for the tweet button.</p>
<label>Tweet Text</label>
<%= f.text_area :tweet_text, rows: 2 %>
</div>

<div class="field clearfix">
<p class="explanation">The title shown when your site is shared via Facebook. Leave this blank if you want to use your project name.</p>
<label>Facebook Title</label>
<%= f.text_field :facebook_title %>
</div>

<div class="field clearfix">
<p class="explanation">The description shown when your site is shared via Facebook.</p>
<label>Facebook Description</label>
<%= f.text_area :facebook_description, rows: 2 %>
</div>

<div class="field clearfix">
<p class="explanation">The image shown when your site is shared via facebook. This should have a square aspect ratio and be at least 200px by 200px.</p>
<label>Facebook Image</label>
<% if @settings.facebook_image.file? %>
<%= image_tag @settings.facebook_image.url(:thumb) %><br/>
<%= f.file_field :facebook_image %><br/>
<%= f.check_box :facebook_image_delete %><span>Delete current image</span>
<% else %>
<%= f.file_field :facebook_image %>
<% end %>
</div>

</fieldset>

<fieldset>
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<% if current_page?(root_path) %>
<li>
<a href="<%= url_for admin_website_path %>"><i class="icon-edit icon-white"></i> Edit homepage</a>
<a href="<%= url_for admin_homepage_path %>"><i class="icon-edit icon-white"></i> Edit homepage</a>
</li>
<li>
<a href="<%= url_for new_admin_campaign_path %>"><i class="icon-plus icon-white"></i> New Campaign</a>
Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

# ADMIN
get '/admin', to: 'admin#admin_dashboard', as: :admin_dashboard
match '/admin/website', to: 'admin#admin_website', as: :admin_website
match '/admin/homepage', to: 'admin#admin_homepage', as: :admin_homepage
match '/admin/site-settings', to: 'admin#admin_site_settings', as: :admin_site_settings
namespace :admin do
resources :campaigns
post '/payments/:id/refund', to: 'payments#refund_payment', as: :admin_payment_refund
Expand Down

0 comments on commit 9f07df3

Please sign in to comment.