Skip to content

Commit

Permalink
moved customization options to their own tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt LeBel committed Feb 2, 2014
1 parent 9f07df3 commit 94309b1
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 43 deletions.
12 changes: 5 additions & 7 deletions app/assets/javascripts/admin.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@ Crowdhoster.admin =
e.preventDefault()
$('#advanced').slideToggle()

# Settings Form
# Customization Form
$('#settings_custom_css').on "change", (e) ->
occ_msg = Crowdhoster.admin.checkSafety('settings_custom_css')
Crowdhoster.admin.checkSafetyAlert(occ_msg, 'settings_custom_css', 'settings_custom_css_alert')

$('#settings_custom_js').on "change", (e) ->
occ_msg = Crowdhoster.admin.checkSafety('settings_custom_js')
Crowdhoster.admin.checkSafetyAlert(occ_msg, 'settings_custom_js', 'settings_custom_js_alert')



# Campaign Form

$('#campaign_expiration_date').datetimepicker({
Expand Down Expand Up @@ -173,7 +172,7 @@ Crowdhoster.admin =
# Custom Named Functions
checkSafety : (editor) ->
reg = new RegExp(/(\s*[:]*?[=]?\s*["]?\s*\b(http)\s*:\s*\/\/[a-zA-Z0-9+&@#\/%?=~_-|!,;:.~-]*)/g)
regDisp = new RegExp(/(\b(http)\s*:\s*\/\/[a-zA-Z0-9+&@#\/%?=~_-|!,;:.~-]*)/g)
regDisp = new RegExp(/(\b(http)\s*:\s*\/\/[a-zA-Z0-9+&@#\/%?=~_-|!,;:.~-]*)/g)
str = $("#" + editor).val()
occ_msg = ""
while (result = reg.exec(str)) isnt null
Expand All @@ -194,8 +193,7 @@ Crowdhoster.admin =
$('#' + element).removeClass('text-area-border')
if( Crowdhoster.admin.checkSafety('settings_custom_css') == '' )
$('#settings_custom_alert').hide();



submitWebsiteForm: (form) ->
form.submit()

Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/unsaved_changes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var unsavedChangesChecker = function() {
}

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

Expand Down
41 changes: 23 additions & 18 deletions app/assets/javascripts/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,6 @@ $( document ).ready(function() {
// validate '/admin/site-settings'
$("#admin_site_settings_form").validate({

// custom handler to call named function ""
submitHandler: function (form) {
$(window).unbind('beforeunload', unsavedChangesChecker);
var occ_msg_css = Crowdhoster.admin.checkSafety('settings_custom_css');
var occ_msg_js = Crowdhoster.admin.checkSafety('settings_custom_js');
if ( ( occ_msg_css != '' || occ_msg_js != '' ) && !Crowdhoster.admin.isSecurityCheckWarningDisplayed ){
Crowdhoster.admin.checkSafetyAlert(occ_msg_css, 'settings_custom_css', 'settings_custom_css_alert');
Crowdhoster.admin.checkSafetyAlert(occ_msg_js, 'settings_custom_js', 'settings_custom_js_alert');
$('#settings_custom_alert').html('Please see the security warnings above with your custom CSS/JS. To continue anyway, click the save button again.');
$('#settings_custom_alert').show();
$(".loader").hide();
Crowdhoster.admin.isSecurityCheckWarningDisplayed = true;
}
else{
Crowdhoster.admin.submitWebsiteForm(form);
}
},

// validate the previously selected element when the user clicks out
onfocusout: function(element) {
$(element).valid();
Expand Down Expand Up @@ -64,6 +46,29 @@ $( document ).ready(function() {

});

// validate customizations
$("#admin_customize_form").validate({

// custom handler to call named function ""
submitHandler: function (form) {
$(window).unbind('beforeunload', unsavedChangesChecker);
var occ_msg_css = Crowdhoster.admin.checkSafety('settings_custom_css');
var occ_msg_js = Crowdhoster.admin.checkSafety('settings_custom_js');
if ( ( occ_msg_css != '' || occ_msg_js != '' ) && !Crowdhoster.admin.isSecurityCheckWarningDisplayed ){
Crowdhoster.admin.checkSafetyAlert(occ_msg_css, 'settings_custom_css', 'settings_custom_css_alert');
Crowdhoster.admin.checkSafetyAlert(occ_msg_js, 'settings_custom_js', 'settings_custom_js_alert');
$('#settings_custom_alert').html('Please see the security warnings above with your custom CSS/JS. To continue anyway, click the save button again.');
$('#settings_custom_alert').show();
$(".loader").hide();
Crowdhoster.admin.isSecurityCheckWarningDisplayed = true;
}
else{
Crowdhoster.admin.submitWebsiteForm(form);
}
}

});

// validate '/admin/campaigns/_form'
$("#admin_campaign_form").validate({

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_homepage, #admin_site_settings, #admin_campaigns {
#admin_homepage, #admin_site_settings, #admin_customize, #admin_campaigns {

fieldset {
margin-bottom: 30px;
Expand Down
11 changes: 11 additions & 0 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ def admin_site_settings
end
end

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

def admin_processor_setup
if request.post?
flash.now[:error] = "Missing API credentials" and return if params[:ct_prod_api_key].blank? || params[:ct_prod_api_secret].blank?
Expand Down
3 changes: 3 additions & 0 deletions app/views/admin/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<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 == 'customize' %>">
<%= link_to "Customize", admin_customize_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>
Expand Down
37 changes: 37 additions & 0 deletions app/views/admin/admin_customize.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<div id="admin">
<div class="container content_box clearfix">

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

<div id="admin_customize_settings">

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

<legend>Customize</legend>
<div id="customize_tools">

<div class="field clearfix">
<p class="explanation">Add your own CSS styles to fully customize the look and feel of your site.</p>
<div id="settings_custom_css_alert" class="alert alert-danger inline-alert" style="display:none;" ></div>
<label>Custom CSS</label>
<%= f.text_area :custom_css, rows: 3, style: "width:400px; height: 200px", :placeholder => "#campaign #funding_area { background: white; }" %>
</div>

<div class="field clearfix">
<p class="explanation">Add your own JavaScript here. Use this field to paste in scripts for analytics tracking, retargeting, etc.</p>
<div id="settings_custom_js_alert" class="alert alert-danger inline-alert" style="display:none;" ></div>
<label>Custom JavaScript</label>
<%= f.text_area :custom_js, rows: 3, style: "width:400px; height: 200px", :placeholder => "<script> CODE </script>" %>
</div>

</div>
</fieldset>

<div id="settings_custom_alert" class="alert alert-danger box-alert" style="display:none;" ></div>
<%= 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>
2 changes: 1 addition & 1 deletion app/views/admin/admin_homepage.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

<%= 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>
Expand Down
16 changes: 1 addition & 15 deletions app/views/admin/admin_site_settings.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,13 @@
<label>Custom Facebook App ID</label>
<%= f.text_field :facebook_app_id %>
</div>
<div class="field clearfix">
<p class="explanation">Add your own CSS styles to fully customize the look and feel of your site. </p>
<div id="settings_custom_css_alert" class="alert alert-danger inline-alert" style="display:none;" ></div>
<label>Custom CSS</label>
<%= f.text_area :custom_css, rows: 3, style: "width:400px; height: 200px", :placeholder => "#campaign #funding_area { background: white; }" %>
</div>

<div class="field clearfix">
<p class="explanation">Add your own JavaScript here. Use this field to paste in scripts for analytics tracking, retargeting, etc.</p>
<div id="settings_custom_js_alert" class="alert alert-danger inline-alert" style="display:none;" ></div>
<label>Custom JavaScript</label>
<%= f.text_area :custom_js, rows: 3, style: "width:400px; height: 200px", :placeholder => "<script> CODE </script>" %>
</div>

</div>
</fieldset>

<div id="settings_custom_alert" class="alert alert-danger box-alert" style="display:none;" ></div>
<%= 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>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
get '/admin', to: 'admin#admin_dashboard', as: :admin_dashboard
match '/admin/homepage', to: 'admin#admin_homepage', as: :admin_homepage
match '/admin/site-settings', to: 'admin#admin_site_settings', as: :admin_site_settings
match '/admin/customize', to: 'admin#admin_customize', as: :admin_customize
namespace :admin do
resources :campaigns
post '/payments/:id/refund', to: 'payments#refund_payment', as: :admin_payment_refund
Expand Down

0 comments on commit 94309b1

Please sign in to comment.