Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

206: edit address #52

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion app/assets/javascripts/manager/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,9 @@ $(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();

$('.preview-image').on("change", previewImages);
});

$('.address-edit').click(function() {
$('.name_address').val($(this).data('address-name'));
$('#edit_address').attr('action', $(this).data('address-url'));
});
});
19 changes: 19 additions & 0 deletions app/controllers/manager/addresses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module Manager
class AddressesController < BaseController
before_action :load_address, only: %i[edit update]

def create
@address = Address.new address_params
if @address.save
Expand All @@ -14,10 +16,27 @@ def create
end
end

def edit; end

def update
if @address.update name: params[:name]
flash[:success] = t ".success"
else
flash.now[:danger] = t ".danger"
end
respond_to do |format|
format.js
end
end

private

def address_params
params.require(:address).permit :name, :area_id
end

def load_address
@address = Address.find params[:id]
end
end
end
6 changes: 6 additions & 0 deletions app/views/manager/addresses/update.js.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- if @address.errors.present?
| $("#message_errors").html("#{j(render 'shared/manager/error_messages', object: @address)}");
toastr.error("#{flash[:danger]}");
- else
| $('.load-address').load(location.href + ' .load-address');
toastr.success("#{flash[:success]}");
4 changes: 2 additions & 2 deletions app/views/manager/areas/_address.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ tr
td
= address_counter.next
td
= address.name
= link_to address.name, "#", class: "link-to-edit address-edit", data: {toggle: "modal", target: "#myModal", address_name: address.name, address_url: manager_address_path(address)}
td
= link_to t(".delete"), "#", class: "btn btn-danger"
= link_to t(".delete"), "#", class: "btn btn-danger"
14 changes: 14 additions & 0 deletions app/views/manager/areas/_edit_address.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#myModal.modal.fade
.modal-dialog
.modal-content
.modal-header
h4.modal-title = t ".edit"
= button_tag t(".btn"), class: "close", data: {dismiss: "modal"}, type: "button"
.modal-body
Copy link
Owner

Choose a reason for hiding this comment

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

Sao ko dùng chung modal với new address

Copy link
Author

Choose a reason for hiding this comment

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

tại vì edit address, em dùng form_tag, method: :patch và url của nó là url của edit, nên viết riêng ra luôn anh

Copy link
Owner

Choose a reason for hiding this comment

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

Em có thể dùng chung 1 modal sau đó dùng JS để thay đổi URL và method trong form sau mà

= form_tag "", method: :patch, id: "edit_address", remote: true do |f|
#message_errors
.form-group
= text_field_tag :name, nil, class: "form-control name_address"
= submit_tag t(".save"), class: "btn btn-primary"
.modal-footer
= button_tag t(".close"), class: "btn btn-danger", data: {dismiss: "modal"}, type: "button"
2 changes: 1 addition & 1 deletion app/views/manager/areas/_new_address.html.slim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#myModal.modal.fade
#new_address_modal.modal.fade
.modal-dialog
.modal-content
.modal-header
Expand Down
3 changes: 2 additions & 1 deletion app/views/manager/areas/edit.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
.card-header
h4.card-title
= t ".address"
= link_to t(".address"), "#", class: "btn btn-primary btn-xs right btn_right", data: {toggle: "modal", target: "#myModal"}
= link_to t(".address"), "#", class: "btn btn-primary btn-xs right btn_right", data: {toggle: "modal", target: "#new_address_modal"}
.card-body.load-address
table.table.table-hover.table-striped
thead
Expand All @@ -29,3 +29,4 @@
= render partial: "address", collection: @addresses
= paginate @addresses, theme: "twitter-bootstrap-4", pagination_class: "pagination-sm"
= render "new_address", address: @address
= render "edit_address"
2 changes: 0 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
en:
please_choose_one: please choose one
sure: "Are you sure?"

layouts:
header:
signup: "Sign Up"
Expand Down Expand Up @@ -44,7 +43,6 @@ en:
acreage: Acreage
address: Address
type_room: Type Rooms

shared:
manager:
left_menu:
Expand Down
24 changes: 20 additions & 4 deletions config/locales/manager/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ en:
name: "Name"
action: "Action"
address: "New Address"
enter_name: "Enter address..."
area:
delete: "Delete"
sure: "Are you sure?"
new_area:
new: "New Areas"
save: "Save Changes"
close: "Close"
update:
success: "Update area successfully!"
danger: "Update area has problem!"
Expand All @@ -126,6 +134,18 @@ en:
btn: "×"
address:
delete: "Delete"
edit_address:
btn: "×"
edit: "Edit Address"
save: "Save Changes"
close: "Close"
addresses:
create:
success: "Create address successfully!"
danger: "Create address has problem!"
update:
success: "Update address successfully!"
danger: "Update address has problem!"
members:
form:
error: "The form contains %{count}."
Expand All @@ -150,10 +170,6 @@ en:
edit:
update: "Update"
edit_member: "Edit Member"
addresses:
create:
success: "Create address successfully!"
danger: "Create address has problem!"
passwords:
new:
title: "Forgot Your Password?"
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
resources :areas, except: %i[new create] do
resources :addresses, only: %i[new create]
end
resources :addresses, only: %i[destroy edit update]
end
root "home#index"
end
12 changes: 0 additions & 12 deletions spec/controllers/home_controller_spec.rb

This file was deleted.