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 @@
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 => "" %> +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 => "" %> -