Skip to content

Commit 4fa7afc

Browse files
Make product name mutable again (#1007)
* make product names mutable again * Add context for updating product name in specs * Fix indentation and formatting in product_spec.rb * add warning when changing product name * Fix lintS --------- Co-authored-by: lodewiges <131907615+lodewiges@users.noreply.github.com> Co-authored-by: Lodewiges <jamestreeg@gmail.com>
1 parent aa8363b commit 4fa7afc

4 files changed

Lines changed: 9 additions & 13 deletions

File tree

app/javascript/packs/price_lists.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ document.addEventListener('turbolinks:load', () => {
5555
},
5656

5757
saveProduct: function(product) {
58+
if (product.id && product._beforeEditingCache.name !== product.name) {
59+
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.')) {
60+
return;
61+
}
62+
}
5863
const sanitizedProduct = this.sanitizeProductInput(product);
5964
if (sanitizedProduct.id) { // Existing product
6065
this.$http.put(`/products/${sanitizedProduct.id}.json`, { product: sanitizedProduct }).then( (response) => {

app/models/product.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ class Product < ApplicationRecord
66
has_many :price_lists, through: :product_prices, dependent: :restrict_with_error
77

88
validates :name, :category, presence: true
9-
validate :name_readonly
109

1110
accepts_nested_attributes_for :product_prices, allow_destroy: true
1211

@@ -17,12 +16,4 @@ def requires_age
1716
def t_category
1817
I18n.t category
1918
end
20-
21-
private
22-
23-
def name_readonly
24-
return if new_record?
25-
26-
errors.add(:name, 'is readonly') if name_changed?
27-
end
2819
end

app/views/price_lists/index.html.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
<div class="form-check">
2626
<input class="form-check-input" type="checkbox" id="show-archived-check" v-model="showArchived">
2727
<label class="form-check-label" for="show-archived-check">
28-
Laat gearchieveerde prijslijsten zien
28+
Laat gearchieveerde prijslijsten zien
2929
</label>
3030
</div>
3131
<% end %>
32-
32+
3333
<table id='price-lists-table' class='price-lists-table table table-striped overflow-scroll mw-100 mx-auto d-block pe-2'>
3434
<thead class="table-header-rotated products">
3535
<tr>
@@ -60,7 +60,7 @@
6060
</td>
6161
<td class="products-new products-name">
6262
<div class="d-flex">
63-
<input class="form-control flex-grow-1" placeholder="Productnaam" type="text" v-model="product.name" :disabled="product.id"/>
63+
<input class="form-control flex-grow-1" placeholder="Productnaam" type="text" v-model="product.name">
6464
</div>
6565
</td>
6666
<td class="products-new products-category">

spec/models/product_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
context 'when updating the name' do
2222
subject(:product) { create(:product) }
2323

24-
it { expect(product.update(name: 'new_name')).to be false }
24+
it { expect(product.update(name: 'new_name')).to be true }
2525
end
2626
end
2727

0 commit comments

Comments
 (0)