diff --git a/app/assets/javascripts/admin.js.coffee b/app/assets/javascripts/admin.js.coffee index f5d91297..6694270e 100644 --- a/app/assets/javascripts/admin.js.coffee +++ b/app/assets/javascripts/admin.js.coffee @@ -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({ @@ -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 @@ -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() diff --git a/app/assets/javascripts/unsaved_changes.js b/app/assets/javascripts/unsaved_changes.js index a87cc8db..28d3a0c1 100644 --- a/app/assets/javascripts/unsaved_changes.js +++ b/app/assets/javascripts/unsaved_changes.js @@ -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); diff --git a/app/assets/javascripts/validate.js b/app/assets/javascripts/validate.js index 5df84b1a..f306009b 100644 --- a/app/assets/javascripts/validate.js +++ b/app/assets/javascripts/validate.js @@ -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(); @@ -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({ diff --git a/app/assets/stylesheets/admin.css.scss b/app/assets/stylesheets/admin.css.scss index 1de1e264..9604a417 100644 --- a/app/assets/stylesheets/admin.css.scss +++ b/app/assets/stylesheets/admin.css.scss @@ -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; diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index cea1e6cc..3e67c1c8 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -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? diff --git a/app/views/admin/_header.html.erb b/app/views/admin/_header.html.erb index f9be8cfb..066f5647 100644 --- a/app/views/admin/_header.html.erb +++ b/app/views/admin/_header.html.erb @@ -10,6 +10,9 @@
  • <%= link_to "Homepage", admin_homepage_path, :class => 'show_loader', :'data-loader' => "admin_header" %>
  • +
  • + <%= link_to "Customize", admin_customize_path, :class => 'show_loader', :'data-loader' => "admin_header" %> +
  • <%= link_to "Site Settings", admin_site_settings_path, :class => 'show_loader', :'data-loader' => "admin_header" %>
  • diff --git a/app/views/admin/admin_customize.html.erb b/app/views/admin/admin_customize.html.erb new file mode 100644 index 00000000..a254f8b6 --- /dev/null +++ b/app/views/admin/admin_customize.html.erb @@ -0,0 +1,37 @@ +
    +
    + + <%= render 'admin/header', active: 'customize' %> + +
    + + <%= form_for(@settings, url: admin_customize_path, multipart: true, html: { id: "admin_customize_form" }) do |f| %> + + Customize +
    + +
    +

    Add your own CSS styles to fully customize the look and feel of your site.

    + + + <%= f.text_area :custom_css, rows: 3, style: "width:400px; height: 200px", :placeholder => "#campaign #funding_area { background: white; }" %> +
    + +
    +

    Add your own JavaScript here. Use this field to paste in scripts for analytics tracking, retargeting, etc.

    + + + <%= f.text_area :custom_js, rows: 3, style: "width:400px; height: 200px", :placeholder => "" %> +
    + +
    + + + + <%= f.submit "Save", :'class' => "btn btn-primary show_loader", :'data-loader' => "project_form" %> + + + <% end %> +
    +
    +
    diff --git a/app/views/admin/admin_homepage.html.erb b/app/views/admin/admin_homepage.html.erb index 671e8172..a77189c0 100644 --- a/app/views/admin/admin_homepage.html.erb +++ b/app/views/admin/admin_homepage.html.erb @@ -54,7 +54,7 @@ <%= f.submit "Save", :'class' => "btn btn-primary show_loader", :'data-loader' => "project_form" %> - + <% end %> diff --git a/app/views/admin/admin_site_settings.html.erb b/app/views/admin/admin_site_settings.html.erb index e4cb78ac..31b6cb67 100644 --- a/app/views/admin/admin_site_settings.html.erb +++ b/app/views/admin/admin_site_settings.html.erb @@ -87,27 +87,13 @@ <%= f.text_field :facebook_app_id %> -
    -

    Add your own CSS styles to fully customize the look and feel of your site.

    - - - <%= f.text_area :custom_css, rows: 3, style: "width:400px; height: 200px", :placeholder => "#campaign #funding_area { background: white; }" %> -
    - -
    -

    Add your own JavaScript here. Use this field to paste in scripts for analytics tracking, retargeting, etc.

    - - - <%= f.text_area :custom_js, rows: 3, style: "width:400px; height: 200px", :placeholder => "" %> -
    - <%= f.submit "Save", :'class' => "btn btn-primary show_loader", :'data-loader' => "project_form" %> - + <% end %> diff --git a/config/routes.rb b/config/routes.rb index 5d22bce7..48144a31 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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