about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/admin/settings_controller.rb37
-rw-r--r--app/javascript/styles/forms.scss6
-rw-r--r--app/views/admin/settings/edit.html.haml58
-rw-r--r--app/views/admin/settings/index.html.haml40
4 files changed, 85 insertions, 56 deletions
diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb
index fc9064068..fcd42c79c 100644
--- a/app/controllers/admin/settings_controller.rb
+++ b/app/controllers/admin/settings_controller.rb
@@ -2,38 +2,43 @@
 
 module Admin
   class SettingsController < BaseController
+    ADMIN_SETTINGS = %w(
+      site_contact_username
+      site_contact_email
+      site_title
+      site_description
+      site_extended_description
+      open_registrations
+      closed_registrations_message
+    ).freeze
     BOOLEAN_SETTINGS = %w(open_registrations).freeze
 
-    def index
+    def edit
       @settings = Setting.all_as_records
     end
 
     def update
-      @setting = Setting.where(var: params[:id]).first_or_initialize(var: params[:id])
-      @setting.update(value: value_for_update)
-
-      respond_to do |format|
-        format.html { redirect_to admin_settings_path }
-        format.json { respond_with_bip(@setting) }
+      settings_params.each do |key, value|
+        setting = Setting.where(var: key).first_or_initialize(var: key)
+        setting.update(value: value_for_update(key, value))
       end
+
+      flash[:notice] = 'Success!'
+      redirect_to edit_admin_settings_path
     end
 
     private
 
     def settings_params
-      params.require(:setting).permit(:value)
+      params.permit(ADMIN_SETTINGS)
     end
 
-    def value_for_update
-      if updating_boolean_setting?
-        settings_params[:value] == 'true'
+    def value_for_update(key, value)
+      if BOOLEAN_SETTINGS.include?(key)
+        value == 'true'
       else
-        settings_params[:value]
+        value
       end
     end
-
-    def updating_boolean_setting?
-      BOOLEAN_SETTINGS.include?(params[:id])
-    end
   end
 end
diff --git a/app/javascript/styles/forms.scss b/app/javascript/styles/forms.scss
index 18258099b..18e8657cd 100644
--- a/app/javascript/styles/forms.scss
+++ b/app/javascript/styles/forms.scss
@@ -9,6 +9,12 @@ code {
   margin: 0 auto;
 }
 
+.admin {
+  input, textarea {
+    width: 100%;
+  }
+}
+
 .simple_form {
   .input {
     margin-bottom: 15px;
diff --git a/app/views/admin/settings/edit.html.haml b/app/views/admin/settings/edit.html.haml
new file mode 100644
index 000000000..0808f467c
--- /dev/null
+++ b/app/views/admin/settings/edit.html.haml
@@ -0,0 +1,58 @@
+- content_for :page_title do
+  = t('admin.settings.title')
+
+= form_tag(admin_settings_path, method: :put) do
+  %table.table
+    %thead
+      %tr
+        %th{width: '40%'}
+          = t('admin.settings.setting')
+        %th
+    %tbody
+      %tr
+        %td
+          %strong= t('admin.settings.contact_information.label')
+        %td= text_field_tag :site_contact_username,
+          @settings['site_contact_username'].value,
+          place_holder: t('admin.settings.contact_information.username')
+      %tr
+        %td
+          %strong= t('admin.accounts.email')
+        %td= text_field_tag :site_contact_email,
+          @settings['site_contact_email'].value,
+          place_holder: t('admin.settings.contact_information.email')
+      %tr
+        %td
+          %strong= t('admin.settings.site_title')
+        %td= text_field_tag :site_title,
+          @settings['site_title'].value
+      %tr
+        %td
+          %strong= t('admin.settings.site_description.title')
+          %p= t('admin.settings.site_description.desc_html')
+        %td= text_area_tag :site_description,
+          @settings['site_description'].value,
+          rows: 8
+      %tr
+        %td
+          %strong= t('admin.settings.site_description_extended.title')
+          %p= t('admin.settings.site_description_extended.desc_html')
+        %td= text_area_tag :site_extended_description,
+          @settings['site_extended_description'].value,
+          rows: 8
+      %tr
+        %td
+          %strong= t('admin.settings.registrations.open.title')
+        %td
+          = select_tag :open_registrations,
+          options_for_select({ t('admin.settings.registrations.open.disabled') => false, t('admin.settings.registrations.open.enabled') => true }, @settings['open_registrations'].value)
+      %tr
+        %td
+          %strong= t('admin.settings.registrations.closed_message.title')
+          %p= t('admin.settings.registrations.closed_message.desc_html')
+        %td= text_area_tag :closed_registrations_message,
+          @settings['closed_registrations_message'].value,
+          rows: 8
+
+  .simple_form.actions
+    = button_tag t('generic.save_changes'), type: :submit, class: :btn
diff --git a/app/views/admin/settings/index.html.haml b/app/views/admin/settings/index.html.haml
deleted file mode 100644
index b00e75a16..000000000
--- a/app/views/admin/settings/index.html.haml
+++ /dev/null
@@ -1,40 +0,0 @@
-- content_for :page_title do
-  = t('admin.settings.title')
-
-%table.table
-  %colgroup
-    %col{ width: '35%' }/
-  %thead
-    %tr
-      %th= t('admin.settings.setting')
-      %th= t('admin.settings.click_to_edit')
-  %tbody
-    %tr
-      %td{ rowspan: 2 }
-        %strong= t('admin.settings.contact_information.label')
-      %td= best_in_place @settings['site_contact_username'], :value, url: admin_setting_path(@settings['site_contact_username']), place_holder: t('admin.settings.contact_information.username')
-    %tr
-      %td= best_in_place @settings['site_contact_email'], :value, url: admin_setting_path(@settings['site_contact_email']), place_holder: t('admin.settings.contact_information.email')
-    %tr
-      %td
-        %strong= t('admin.settings.site_title')
-      %td= best_in_place @settings['site_title'], :value, url: admin_setting_path(@settings['site_title'])
-    %tr
-      %td
-        %strong= t('admin.settings.site_description.title')
-        %p= t('admin.settings.site_description.desc_html')
-      %td= best_in_place @settings['site_description'], :value, as: :textarea, url: admin_setting_path(@settings['site_description'])
-    %tr
-      %td
-        %strong= t('admin.settings.site_description_extended.title')
-        %p= t('admin.settings.site_description_extended.desc_html')
-      %td= best_in_place @settings['site_extended_description'], :value, as: :textarea, url: admin_setting_path(@settings['site_extended_description'])
-    %tr
-      %td
-        %strong= t('admin.settings.registrations.open.title')
-      %td= best_in_place @settings['open_registrations'], :value, as: :checkbox, collection: { false: t('admin.settings.registrations.open.disabled'), true: t('admin.settings.registrations.open.enabled')}, url: admin_setting_path(@settings['open_registrations'])
-    %tr
-      %td
-        %strong= t('admin.settings.registrations.closed_message.title')
-        %p= t('admin.settings.registrations.closed_message.desc_html')
-      %td= best_in_place @settings['closed_registrations_message'], :value, as: :textarea, url: admin_setting_path(@settings['closed_registrations_message'])