Quickjump is back. forum/view/id will redirect to external url if it's a redirect...
authorNguyễn Thái Ngọc Duy <[email protected]>
Wed, 23 Aug 2006 07:46:24 +0000 (23 14:46 +0700)
committerNguyễn Thái Ngọc Duy <[email protected]>
Wed, 23 Aug 2006 07:46:24 +0000 (23 14:46 +0700)
app/controllers/forum_controller.rb
app/models/forum.rb
app/views/forum/view.rhtml
app/views/topic/_quickjump.rhtml [new file with mode: 0644]
app/views/topic/view.rhtml

index 92711db..e8d0cf1 100644 (file)
@@ -3,10 +3,11 @@ class ForumController < ApplicationController
   before_filter :can_view?, :except => :index
 
   def index
-    @forums = Forum.find :all, :include => :category, :order => 'categories.disp_position, forums.disp_position'
+    @forums = current_user.is_admin? ? Forum.get_all_forums : Forum.get_forums(current_user.group)
   end
 
   def view
+    redirect_to @forum.redirect_url and return unless @forum.redirect_url.blank?
     per_page = current_user.disp_topics ? current_user.disp_topics : Settings.disp_topics_default
     @topic_pages, @topics = paginate_association(@forum, :topics, { :order => 'last_post DESC'}, per_page)
   end
index 1b187ce..1077667 100644 (file)
@@ -57,4 +57,12 @@ class Forum < ActiveRecord::Base
       forums[f].save!
     end
   end
+
+  def self.get_all_forums
+    Forum.find :all, :include => :category, :order => 'categories.disp_position, forums.disp_position'
+  end
+
+  def self.get_forums(group)
+    Forum.find :all, :include => :category, :joins => "LEFT JOIN forum_perms ON forum_perms.forum_id=forums.id AND forum_perms.group_id = #{group.id} AND (forum_perms.read_forum IS NULL OR forum_perms.read_forum='1')", :order => 'categories.disp_position, forums.disp_position'
+  end
 end
index c16fb74..6a50c20 100644 (file)
@@ -3,6 +3,7 @@
     content_for :foot_links do
 -%>
                        <div class="conl">
+<%= render :partial => 'topic/quickjump', :locals => {:id => @forum.id } if Settings.quickjump == true -%>
                                <p id="modcontrols"><%= link_to "Moderate forum", :action => 'moderate', :id => @forum.id %></p>
                        </div>
 <%
diff --git a/app/views/topic/_quickjump.rhtml b/app/views/topic/_quickjump.rhtml
new file mode 100644 (file)
index 0000000..2958791
--- /dev/null
@@ -0,0 +1,20 @@
+<% forums = Forum.get_forums(current_user.group) -%>
+                               <form name="qjump" id="qjump" method="get" action="<%= url_for :controller => 'forum', :action => 'view', :id => nil %>">
+                                       <div><label>Jump to
+                                       <br /><select name="id" onchange="document.qjump.submit()">
+<% old_cat = nil -%>
+<% for f in forums -%>
+<% if old_cat != f.category -%>
+<% if old_cat != nil -%>
+                                               </optgroup>
+<% end -%>
+                                               <optgroup label="<%=h f.category.cat_name %>">
+<% old_cat = f.category -%>
+<% end -%>
+                                                       <option value="<%= f.id %>"<%= ' selected="selected"' if id == f.id %>><%=h f.redirect_url.blank? ? f.forum_name : f.forum_name + ' >>>' %></option>
+<% end -%>
+                                               </optgroup>
+                                       </select>
+                                       <input type="submit" value="Go" accesskey="g" />
+                                       </label></div>
+                               </form>
index c5a9cc7..92ba441 100644 (file)
@@ -3,6 +3,7 @@
     content_for :foot_links do
 -%>
                        <div class="conl">
+<%= render :partial => 'quickjump', :locals => {:id => @topic.forum.id } if Settings.quickjump == true -%>
                                <dl id="modcontrols">
                                        <dt><strong>Mod controls</strong></dt>
                                        <dd><%= link_to "Delete posts", :controller => "moderate", :action => "delete_post", :tid => @topic.id %></dd>