For pull
This commit is contained in:
@@ -164,6 +164,26 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("#shop_image").fileinput({
|
||||||
|
previewFileType: "image",
|
||||||
|
allowedFileExtensions: ["jpg", "gif", "png"],
|
||||||
|
browseClass: "btn btn-success",
|
||||||
|
browseLabel: "Pick Image",
|
||||||
|
browseIcon: "<i class=\"fa fa-image\"></i> ",
|
||||||
|
removeClass: "btn btn-danger",
|
||||||
|
removeLabel: "Delete",
|
||||||
|
removeIcon: "<i class=\"fa fa-trash\"></i> ",
|
||||||
|
showUpload: false,
|
||||||
|
// uploadClass: "btn btn-info",
|
||||||
|
// uploadLabel: "Upload",
|
||||||
|
// uploadIcon: "<i class=\"fa fa-upload\"></i> ",
|
||||||
|
previewTemplates: {
|
||||||
|
image: '<div class="file-preview-frame" id="{previewId}" data-fileindex="{fileindex}">\n' +
|
||||||
|
' <img src="{data}" class="file-preview-image" title="{caption}" alt="{caption}" style="width: 200px;height: 200px;">\n' +
|
||||||
|
'</div>\n',
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// first input focus for all form
|
// first input focus for all form
|
||||||
$('form:first *input[data-behaviour!=datepicker]:input[type!=hidden]:first').focus();
|
$('form:first *input[data-behaviour!=datepicker]:input[type!=hidden]:first').focus();
|
||||||
|
|
||||||
|
|||||||
11
app/controllers/settings/display_images_controller.rb
Normal file
11
app/controllers/settings/display_images_controller.rb
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
class Settings::DisplayImagesController < ApplicationController
|
||||||
|
def destroy
|
||||||
|
#byebug
|
||||||
|
@item_photo = DisplayImage.find(params[:shop_id])
|
||||||
|
item = @item_photo.id
|
||||||
|
@item_photo.destroy
|
||||||
|
respond_to do |format|
|
||||||
|
format.html {redirect_to settings_shops_url+'/1/edit', notice: 'Image was successfully destroyed.'}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
class Settings::ShopsController < ApplicationController
|
class Settings::ShopsController < ApplicationController
|
||||||
load_and_authorize_resource except: [:create]
|
load_and_authorize_resource except: [:create]
|
||||||
before_action :set_shop, only: [:show, :edit, :update]
|
before_action :set_shop, only: [:show, :edit, :update, :destroy]
|
||||||
|
|
||||||
# GET /settings/shops
|
# GET /settings/shops
|
||||||
# GET /settings/shops.json
|
# GET /settings/shops.json
|
||||||
@@ -11,11 +11,13 @@ class Settings::ShopsController < ApplicationController
|
|||||||
# GET /settings/shops/1
|
# GET /settings/shops/1
|
||||||
# GET /settings/shops/1.json
|
# GET /settings/shops/1.json
|
||||||
def show
|
def show
|
||||||
|
@display_images = @settings_shop.display_images.all
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /settings/shops/new
|
# GET /settings/shops/new
|
||||||
def new
|
def new
|
||||||
@settings_shop = Shop.new
|
@settings_shop = Shop.new
|
||||||
|
@display_image = @settings_shop.display_images.build
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /settings/shops/1/edit
|
# GET /settings/shops/1/edit
|
||||||
@@ -28,6 +30,11 @@ class Settings::ShopsController < ApplicationController
|
|||||||
@settings_shop = Shop.new(shop_params)
|
@settings_shop = Shop.new(shop_params)
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @settings_shop.save
|
if @settings_shop.save
|
||||||
|
if params[:display_images].present?
|
||||||
|
params[:display_images]['image'].each do |a|
|
||||||
|
@display_image = @settings_shop.display_images.create!(:shop_id => @shop.id, :image => a)
|
||||||
|
end
|
||||||
|
end
|
||||||
format.html { redirect_to settings_shops_url, notice: 'Shop was successfully created.' }
|
format.html { redirect_to settings_shops_url, notice: 'Shop was successfully created.' }
|
||||||
format.json { render :index, status: :created, location: @settings_shop }
|
format.json { render :index, status: :created, location: @settings_shop }
|
||||||
else
|
else
|
||||||
@@ -42,6 +49,11 @@ class Settings::ShopsController < ApplicationController
|
|||||||
def update
|
def update
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @settings_shop.update(shop_params)
|
if @settings_shop.update(shop_params)
|
||||||
|
if params[:display_images].present?
|
||||||
|
params[:display_images]['image'].each do |a|
|
||||||
|
@display_image = @settings_shop.display_images.create!(:shop_id => @shop.id, :image => a)
|
||||||
|
end
|
||||||
|
end
|
||||||
format.html { redirect_to settings_shops_url, notice: 'Shop was successfully updated.' }
|
format.html { redirect_to settings_shops_url, notice: 'Shop was successfully updated.' }
|
||||||
format.json { render :index, status: :ok, location: @settings_shop }
|
format.json { render :index, status: :ok, location: @settings_shop }
|
||||||
else
|
else
|
||||||
@@ -71,6 +83,6 @@ class Settings::ShopsController < ApplicationController
|
|||||||
|
|
||||||
# Never trust parameters from the scary internet, only allow the white list through.
|
# Never trust parameters from the scary internet, only allow the white list through.
|
||||||
def shop_params
|
def shop_params
|
||||||
params.require(:shop).permit(:logo, :name,:address,:city,:township,:state,:country,:phone_no,:reservation_no,:license,:activated_at,:license_data,:base_currency,:cloud_token,:cloud_url,:owner_token,:id_prefix,:is_rounding_adj,:quick_sale_summary,:calc_tax_order,:show_account_info)
|
params.require(:shop).permit(:logo, :name,:address,:city,:township,:state,:country,:phone_no,:reservation_no,:license,:activated_at,:license_data,:base_currency,:cloud_token,:cloud_url,:owner_token,:id_prefix,:is_rounding_adj,:quick_sale_summary,:calc_tax_order,:show_account_info, display_images_attributes: [:id, :shop_id, :image])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
5
app/models/display_image.rb
Normal file
5
app/models/display_image.rb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
class DisplayImage < ApplicationRecord
|
||||||
|
mount_uploader :image, DisplayImageUploader
|
||||||
|
belongs_to :shop
|
||||||
|
|
||||||
|
end
|
||||||
@@ -3,4 +3,7 @@ class Shop < ApplicationRecord
|
|||||||
|
|
||||||
# Shop Image Uploader
|
# Shop Image Uploader
|
||||||
mount_uploader :logo, ShopImageUploader
|
mount_uploader :logo, ShopImageUploader
|
||||||
|
|
||||||
|
has_many :display_images
|
||||||
|
accepts_nested_attributes_for :display_images
|
||||||
end
|
end
|
||||||
|
|||||||
59
app/uploaders/display_image_uploader.rb
Normal file
59
app/uploaders/display_image_uploader.rb
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
class DisplayImageUploader < CarrierWave::Uploader::Base
|
||||||
|
|
||||||
|
# Include RMagick or MiniMagick support:
|
||||||
|
# include CarrierWave::RMagick
|
||||||
|
include CarrierWave::MiniMagick
|
||||||
|
|
||||||
|
# Choose what kind of storage to use for this uploader:
|
||||||
|
storage :file
|
||||||
|
# storage :fog
|
||||||
|
|
||||||
|
# def root
|
||||||
|
# Rails.root.join 'public/'
|
||||||
|
# end
|
||||||
|
|
||||||
|
# Override the directory where uploaded files will be stored.
|
||||||
|
# This is a sensible default for uploaders that are meant to be mounted:
|
||||||
|
def store_dir
|
||||||
|
#"image/image"
|
||||||
|
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
||||||
|
end
|
||||||
|
|
||||||
|
# def cache_dir
|
||||||
|
# '/tmp/images'
|
||||||
|
# end
|
||||||
|
|
||||||
|
# Provide a default URL as a default if there hasn't been a file uploaded:
|
||||||
|
# def default_url(*args)
|
||||||
|
# # For Rails 3.1+ asset pipeline compatibility:
|
||||||
|
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
|
||||||
|
#
|
||||||
|
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
|
||||||
|
# end
|
||||||
|
|
||||||
|
# Process files as they are uploaded:
|
||||||
|
# process scale: [200, 300]
|
||||||
|
process :resize_to_fit => [200, 150]
|
||||||
|
#
|
||||||
|
# def scale(width, height)
|
||||||
|
# # do something
|
||||||
|
# end
|
||||||
|
|
||||||
|
# Create different versions of your uploaded files:
|
||||||
|
# version :thumb do
|
||||||
|
# process resize_to_fit: [50, 50]
|
||||||
|
# end
|
||||||
|
|
||||||
|
# Add a white list of extensions which are allowed to be uploaded.
|
||||||
|
# For images you might use something like this:
|
||||||
|
def extension_whitelist
|
||||||
|
%w(jpg jpeg gif png)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Override the filename of the uploaded files:
|
||||||
|
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
||||||
|
# def filename
|
||||||
|
# "something.jpg" if original_filename
|
||||||
|
# end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
|
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="body">
|
<div class="body">
|
||||||
<%= simple_form_for([:settings,@settings_shop]) do |f| %>
|
<%= simple_form_for([:settings,@settings_shop], :html => { :multipart => true }) do |f| %>
|
||||||
<%= f.error_notification %>
|
<%= f.error_notification %>
|
||||||
<div class="form-group p-l-15">
|
<div class="form-group p-l-15">
|
||||||
<%= f.input :name ,:input_html=>{:class=>"col-md-10"},:required=>true%>
|
<%= f.input :name ,:input_html=>{:class=>"col-md-10"},:required=>true%>
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
<%= f.input :show_account_info %>
|
<%= f.input :show_account_info %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<label>Shop Image</label>
|
<label>Shop Logo</label>
|
||||||
<div class="panel padding-10">
|
<div class="panel padding-10">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="menu-item-img">
|
<div class="menu-item-img">
|
||||||
@@ -40,6 +40,31 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<label>Shop Images</label>
|
||||||
|
<div class="panel padding-10">
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="menu-item-img">
|
||||||
|
|
||||||
|
<%= f.fields_for :display_images do |p| %>
|
||||||
|
<div class="field">
|
||||||
|
<%= p.label :image %><br>
|
||||||
|
<%= image_tag p.object.image, :class => "img-thumbnail" %>
|
||||||
|
<%= p.file_field :image, :multiple => true, name: "display_images[image][]" %>
|
||||||
|
<%= link_to "Destroy", settings_shop_display_image_path(p.object), method: :delete %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- <%= f.fields_for :display_images do |p| %>
|
||||||
|
<div class="field">
|
||||||
|
<%= p.label :image %><br>
|
||||||
|
<%= p.file_field :image, :multiple => true, name: "display_images[image][]" %>
|
||||||
|
</div>
|
||||||
|
<% end %> -->
|
||||||
|
|
||||||
<div class="form-actions p-l-15">
|
<div class="form-actions p-l-15">
|
||||||
<%= f.submit "Submit",:class => 'btn btn-primary btn-lg waves-effect' %>
|
<%= f.submit "Submit",:class => 'btn btn-primary btn-lg waves-effect' %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -99,6 +99,14 @@
|
|||||||
<td style="width:20%">Shop Image</td>
|
<td style="width:20%">Shop Image</td>
|
||||||
<td><%= image_tag @settings_shop.logo, :size => '200x200'%></td>
|
<td><%= image_tag @settings_shop.logo, :size => '200x200'%></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td style="width:20%">Shop Images</td>
|
||||||
|
<td>
|
||||||
|
<% @display_images.each do |p| %>
|
||||||
|
<%= image_tag p.image , :size => '200x200'%><br>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= link_to t("views.btn.edit"), edit_settings_shop_path(@settings_shop),:class => 'btn btn-primary btn-sm waves-effect' %>
|
<td><%= link_to t("views.btn.edit"), edit_settings_shop_path(@settings_shop),:class => 'btn btn-primary btn-sm waves-effect' %>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@@ -285,7 +285,10 @@ scope "(:locale)", locale: /en|mm/ do
|
|||||||
|
|
||||||
#--------- System Settings ------------#
|
#--------- System Settings ------------#
|
||||||
namespace :settings do
|
namespace :settings do
|
||||||
resources :shops
|
resources :shops do
|
||||||
|
resources :display_images
|
||||||
|
end
|
||||||
|
|
||||||
#employees
|
#employees
|
||||||
resources :employees
|
resources :employees
|
||||||
#menu
|
#menu
|
||||||
|
|||||||
Reference in New Issue
Block a user