Skip to content

Commit

Permalink
206: edit address
Browse files Browse the repository at this point in the history
  • Loading branch information
HoVietHieu123 committed Sep 3, 2019
1 parent 1cb612c commit 96fadf5
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ config/environments/*.local.yml

# Ignore application configuration
/config/application.yml

/public/uploads
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ GEM
dry-logic (~> 1.0, >= 1.0.2)
erubi (1.8.0)
execjs (2.7.0)
faker (2.2.0)
faker (2.1.2)
i18n (>= 0.8)
ffi (1.11.1)
figaro (1.1.1)
Expand Down Expand Up @@ -266,7 +266,7 @@ GEM
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
sassc (2.2.0)
sassc (2.1.0)
ffi (~> 1.9)
sassc-rails (2.1.2)
railties (>= 4.0.0)
Expand Down
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
= 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.

0 comments on commit 96fadf5

Please sign in to comment.