diff --git a/app/assets/stylesheets/colors.css b/app/assets/stylesheets/colors.css index 786241a..7af4a41 100644 --- a/app/assets/stylesheets/colors.css +++ b/app/assets/stylesheets/colors.css @@ -1,4 +1,5 @@ :root { + --text-color: #000; --background-color: #333; --main-background-color: --header-color: #15345b; diff --git a/app/assets/stylesheets/forms.css b/app/assets/stylesheets/forms.css index 6cd93b0..d8b7dbc 100644 --- a/app/assets/stylesheets/forms.css +++ b/app/assets/stylesheets/forms.css @@ -40,3 +40,17 @@ form, fieldset { background-color: var(--input-background); } } + +form.stat-form { + display: flex; + flex-direction: column; + + input:disabled { + color: var(--text-color); + background-color: var(--input-background); + } + + input[type=number]:disabled { + -moz-appearance: textfield; + } +} diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index b96ac25..4047f42 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -3,6 +3,7 @@ class StatsController < ApplicationController before_action :set_section, only: [ :new, :create ] before_action :set_character, only: [ :new, :create ] + before_action :set_stat, only: [ :update, :destroy ] def new @stat = @section.stats.new @@ -15,10 +16,13 @@ class StatsController < ApplicationController end end + def update + @stat.update(stat_params) + end + def destroy - stat = Current.user.stats.find(params[:id]) - @id = helpers.dom_id(stat) - stat.destroy + @id = helpers.dom_id(@stat) + @stat.destroy end private @@ -30,6 +34,10 @@ class StatsController < ApplicationController @section = Current.user.character_sheet_sections.find(params[:character_sheet_section_id]) end + def set_stat + @stat = Current.user.stats.find(params[:id]) + end + def stat_params params.require(:stat).permit( :name, diff --git a/app/javascript/controllers/stat_update_controller.js b/app/javascript/controllers/stat_update_controller.js new file mode 100644 index 0000000..246db33 --- /dev/null +++ b/app/javascript/controllers/stat_update_controller.js @@ -0,0 +1,15 @@ +import { Controller } from "@hotwired/stimulus" + +export default class extends Controller { + static values = { + updateUrl: String, + } + + connect() { + this.element.addEventListener("change", this.#updateValue.bind(this)) + } + + #updateValue() { + this.element.requestSubmit() + } +} diff --git a/app/views/stats/_stat.html.erb b/app/views/stats/_stat.html.erb index 584b344..6528816 100644 --- a/app/views/stats/_stat.html.erb +++ b/app/views/stats/_stat.html.erb @@ -1,7 +1,11 @@