Use bootstrap switch for the private/public button
This commit is contained in:
parent
7561685e79
commit
3a602b55dc
7 changed files with 40 additions and 11 deletions
1
Gemfile
1
Gemfile
|
@ -6,6 +6,7 @@ gem 'rails', '4.2.4'
|
|||
# Assets
|
||||
gem 'sass-rails', '~> 4.0.3'
|
||||
gem 'bootstrap-sass', '3.2.0.0'
|
||||
gem 'bootstrap-switch-rails'
|
||||
gem 'uglifier', '>= 1.3.0'
|
||||
gem 'jquery-rails'
|
||||
# Haml for templating!
|
||||
|
|
|
@ -47,6 +47,7 @@ GEM
|
|||
bcrypt (3.1.10)
|
||||
bootstrap-sass (3.2.0.0)
|
||||
sass (~> 3.2)
|
||||
bootstrap-switch-rails (3.3.3)
|
||||
bootstrap-will_paginate (0.0.10)
|
||||
will_paginate
|
||||
builder (3.2.2)
|
||||
|
@ -307,6 +308,7 @@ DEPENDENCIES
|
|||
airbrake (~> 4)
|
||||
annotate
|
||||
bootstrap-sass (= 3.2.0.0)
|
||||
bootstrap-switch-rails
|
||||
bootstrap-will_paginate (= 0.0.10)
|
||||
cancancan
|
||||
capistrano (~> 3.1)
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
//= require jquery
|
||||
//= require jquery_ujs
|
||||
//= require bootstrap
|
||||
//= require bootstrap-switch
|
||||
//= require turbolinks
|
||||
//= require_tree .
|
||||
|
||||
|
|
13
app/assets/javascripts/switch.js
Normal file
13
app/assets/javascripts/switch.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
ready = function() {
|
||||
$('[data-switch]').bootstrapSwitch({ onText: "private", offText: "public" });
|
||||
$('[data-switch]').on('switchChange.bootstrapSwitch', function(event, state) {
|
||||
$(this).closest('form').submit();
|
||||
});
|
||||
|
||||
$('#edit_user_1').on("ajax:error", function(xhr, status, error) {
|
||||
alert("An error occured. Your account has not been updated.");
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(ready);
|
||||
$(document).on('page:load', ready);
|
|
@ -16,8 +16,10 @@
|
|||
|
||||
|
||||
@import "bootstrap-sprockets";
|
||||
@import "bootstrap3-switch";
|
||||
@import "bootstrap";
|
||||
|
||||
|
||||
/* mixins, variables, etc. */
|
||||
|
||||
$gray-medium-light: #eaeaea;
|
||||
|
|
|
@ -9,13 +9,25 @@ class UsersController < ApplicationController
|
|||
if user_params.empty?
|
||||
flash[:notice] = "Nothing happened."
|
||||
redirect_to @user
|
||||
elsif @user.update_attributes(user_params)
|
||||
flash[:success] = "Successfully updated!"
|
||||
redirect_to @user
|
||||
else
|
||||
flash[:error] = "Update failed!"
|
||||
@user.reload
|
||||
render 'show'
|
||||
if @user.update_attributes(user_params)
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
flash[:success] = "Successfully updated!"
|
||||
redirect_to @user
|
||||
end
|
||||
format.js { head :ok }
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
flash[:error] = "Update failed!"
|
||||
@user.reload
|
||||
render 'show'
|
||||
end
|
||||
format.js { head :bad_request }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -26,11 +26,9 @@
|
|||
= link_to "Set dagschotel", edit_dagschotel_user_path(@user), class: "btn btn-default btn-block"
|
||||
%li.list-group-item.text-muted
|
||||
%p Orders can be placed on koelkast for every public account. Private accounts can only order products by logging in here.
|
||||
// = link_to "Go #{if @user.private then "public" else "private" end}", toggle_privacy_user_path(@user), class: "btn btn-default btn-block"
|
||||
= f_form_for @user do |f|
|
||||
.hidden
|
||||
= f.check_box :private, checked: !@user.private
|
||||
= f.submit "Go #{@user.private ? "public" : "private"}", class: "btn btn-default btn-block"
|
||||
= f_form_for @user, remote: true do |f|
|
||||
.center
|
||||
= f.check_box :private, skip_label: true, data: { switch: true }
|
||||
%li.list-group-item.text-muted
|
||||
= f_form_for @user do |f|
|
||||
= f.file_field :avatar
|
||||
|
|
Loading…
Reference in a new issue