move desktop mode to user pref

This commit is contained in:
r888888888
2017-12-15 13:52:25 -08:00
parent 4dabbde05d
commit a95af95eae
8 changed files with 25 additions and 34 deletions

View File

@@ -28,6 +28,17 @@ $(function() {
$('#notice').fadeOut("fast");
e.preventDefault();
});
$("#desktop-version-link a").click(function() {
$.ajax("/users/" + Danbooru.meta("current-user-id"), {
method: "PUT",
data: {
"user[disable_responsive_mode]": "true"
}
}).success(function() {
location.reload();
});
});
});
var Danbooru = {};

View File

@@ -1,6 +1,4 @@
class StaticController < ApplicationController
before_filter :check_desktop_mode, only: :site_map
def terms_of_service
end
@@ -19,15 +17,5 @@ class StaticController < ApplicationController
def site_map
end
private
def check_desktop_mode
if params[:dm]
cookies[:dm] = "1"
redirect_to :back
return false
end
end
end

View File

@@ -1,7 +1,6 @@
class UsersController < ApplicationController
respond_to :html, :xml, :json
skip_before_filter :api_check
before_filter :process_session_actions, only: [:update]
def new
@user = User.new
@@ -79,16 +78,6 @@ class UsersController < ApplicationController
private
def process_session_actions
if params[:user].has_key?(:desktop_mode)
if params[:user].delete(:desktop_mode) == "0"
cookies.delete(:dm)
else
cookies[:dm] = "1"
end
end
end
def check_privilege(user)
raise User::PrivilegeError unless (user.id == CurrentUser.id || CurrentUser.is_admin?)
end

View File

@@ -269,6 +269,10 @@ class AnonymousUser
false
end
def disable_responsive_mode?
false
end
User::Roles.reject {|r| r == :anonymous}.each do |name|
define_method("is_#{name}?") do
false

View File

@@ -57,13 +57,14 @@ class User < ApplicationRecord
disable_cropped_thumbnails
disable_mobile_gestures
enable_safe_mode
disable_responsive_mode
)
include Danbooru::HasBitFlags
has_bit_flags BOOLEAN_ATTRIBUTES, :field => "bit_prefs"
attr_accessor :password, :old_password
attr_accessible :dmail_filter_attributes, :enable_privacy_mode, :enable_post_navigation, :new_post_navigation_layout, :password, :old_password, :password_confirmation, :password_hash, :email, :last_logged_in_at, :last_forum_read_at, :has_mail, :receive_email_notifications, :comment_threshold, :always_resize_images, :favorite_tags, :blacklisted_tags, :name, :ip_addr, :time_zone, :default_image_size, :enable_sequential_post_navigation, :per_page, :hide_deleted_posts, :style_usernames, :enable_auto_complete, :custom_style, :show_deleted_children, :disable_categorized_saved_searches, :disable_tagged_filenames, :enable_recent_searches, :disable_cropped_thumbnails, :disable_mobile_gestures, :enable_safe_mode, :as => [:moderator, :gold, :platinum, :member, :anonymous, :default, :builder, :admin]
attr_accessible :dmail_filter_attributes, :enable_privacy_mode, :enable_post_navigation, :new_post_navigation_layout, :password, :old_password, :password_confirmation, :password_hash, :email, :last_logged_in_at, :last_forum_read_at, :has_mail, :receive_email_notifications, :comment_threshold, :always_resize_images, :favorite_tags, :blacklisted_tags, :name, :ip_addr, :time_zone, :default_image_size, :enable_sequential_post_navigation, :per_page, :hide_deleted_posts, :style_usernames, :enable_auto_complete, :custom_style, :show_deleted_children, :disable_categorized_saved_searches, :disable_tagged_filenames, :enable_recent_searches, :disable_cropped_thumbnails, :disable_mobile_gestures, :enable_safe_mode, :disable_responsive_mode, :as => [:moderator, :gold, :platinum, :member, :anonymous, :default, :builder, :admin]
attr_accessible :level, :as => :admin
validates :name, user_name: true, on: :create

View File

@@ -5,7 +5,7 @@
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link rel="top" title="<%= Danbooru.config.app_name %>" href="/">
<%= csrf_meta_tag %>
<% unless cookies[:dm] %>
<% unless CurrentUser.disable_responsive_mode? %>
<meta name="viewport" content="width=device-width,initial-scale=1">
<% end %>
<meta name="tag-category-names" content="<%= TagCategory.categories %>">

View File

@@ -8,8 +8,10 @@
<% if CurrentUser.user.enable_post_navigation %>
&ndash; <%= link_to "Keyboard shortcuts available", keyboard_shortcuts_path %>
<% end %>
<span id="desktop-version-link">
&ndash;
<%= link_to "Desktop version", site_map_path(:dm => "1"), :rel => "nofollow" %>
</span>
<% if CurrentUser.is_member? %>
<span id="desktop-version-link">
&ndash;
<%= link_to "Disable responsive mode", edit_user_path(CurrentUser.id), :rel => "nofollow" %>
</span>
<% end %>
</footer>

View File

@@ -91,11 +91,7 @@
<%= f.input :favorite_tags, :label => "Frequent tags", :hint => "A list of tags that you use often. They will appear when using the list of Related Tags.", :input_html => { :rows => 5, :data => { :autocomplete => "tag-query" } } %>
<div class="input select field_with_hint">
<label class="select optional" for="user_desktop_mode">Desktop mode</label>
<%= select_tag "user[desktop_mode]", options_for_select([["No", "0"], ["Yes", "1"]], cookies[:dm]), :class => "select optional" %>
<span class="hint">Force desktop version of site even on mobile.</span>
</div>
<%= f.input :disable_responsive_mode, :as => :select, :collection => [["No", "false"], ["Yes", "true"]], :include_blank => false, :hint => "Disable alternative layout for mobile and tablet" %>
<%= f.input :custom_style, :label => "Custom <a href='http://en.wikipedia.org/wiki/Cascading_Style_Sheets'>CSS</a> style".html_safe, :hint => "Style to apply to the whole site.", :input_html => {:size => "40x5"} %>
</fieldset>