Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/javascript/packs/price_lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ document.addEventListener('turbolinks:load', () => {
},

saveProduct: function(product) {
if (product.id && product._beforeEditingCache.name !== product.name) {
if (!confirm('Weet je zeker dat je de productnaam wilt wijzigen? Pas hier mee op want dit kan problemen geven in bestaande orders. Als je twijfelt, maak dan een nieuw product aan in plaats van het bestaande te hernoemen.')) {
return;
}
}
const sanitizedProduct = this.sanitizeProductInput(product);
if (sanitizedProduct.id) { // Existing product
this.$http.put(`/products/${sanitizedProduct.id}.json`, { product: sanitizedProduct }).then( (response) => {
Expand Down
9 changes: 0 additions & 9 deletions app/models/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class Product < ApplicationRecord
has_many :price_lists, through: :product_prices, dependent: :restrict_with_error

validates :name, :category, presence: true
validate :name_readonly

accepts_nested_attributes_for :product_prices, allow_destroy: true

Expand All @@ -17,12 +16,4 @@ def requires_age
def t_category
I18n.t category
end

private

def name_readonly
return if new_record?

errors.add(:name, 'is readonly') if name_changed?
end
end
6 changes: 3 additions & 3 deletions app/views/price_lists/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
<div class="form-check">
<input class="form-check-input" type="checkbox" id="show-archived-check" v-model="showArchived">
<label class="form-check-label" for="show-archived-check">
Laat gearchieveerde prijslijsten zien
Laat gearchieveerde prijslijsten zien
</label>
</div>
<% end %>

<table id='price-lists-table' class='price-lists-table table table-striped overflow-scroll mw-100 mx-auto d-block pe-2'>
<thead class="table-header-rotated products">
<tr>
Expand Down Expand Up @@ -60,7 +60,7 @@
</td>
<td class="products-new products-name">
<div class="d-flex">
<input class="form-control flex-grow-1" placeholder="Productnaam" type="text" v-model="product.name" :disabled="product.id"/>
<input class="form-control flex-grow-1" placeholder="Productnaam" type="text" v-model="product.name">
</div>
</td>
<td class="products-new products-category">
Expand Down
2 changes: 1 addition & 1 deletion spec/models/product_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
context 'when updating the name' do
subject(:product) { create(:product) }

it { expect(product.update(name: 'new_name')).to be false }
it { expect(product.update(name: 'new_name')).to be true }
end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of removing the test we could edit it

end

Expand Down