items error

This commit is contained in:
unknown 2012-02-16 11:30:54 +08:00
parent 4d361857cb
commit 7ea1745f73
6 changed files with 48 additions and 32 deletions

View File

@ -10,7 +10,9 @@ class Panel::WebResource::BackEnd::WebLinksController < ApplicationController
get_categorys(params[:web_link_category_id])
@web_links = WebLink.search(params[:search],params[:category_id])
@web_links = WebLink.search(params[:category_id])
get_tags()
respond_to do |format|
format.html # index.html.erb
@ -35,6 +37,8 @@ class Panel::WebResource::BackEnd::WebLinksController < ApplicationController
def new
@web_link = WebLink.new
get_tags()
get_categorys
respond_to do |format|
@ -47,6 +51,7 @@ class Panel::WebResource::BackEnd::WebLinksController < ApplicationController
def edit
@web_link = WebLink.find(params[:id])
get_categorys
get_tags()
end
# POST /web_links
@ -75,6 +80,8 @@ class Panel::WebResource::BackEnd::WebLinksController < ApplicationController
@web_link.update_user_id = current_user.id
params[:web_link][:tag_ids] ||=[]
respond_to do |format|
if @web_link.update_attributes(params[:web_link])
format.html { redirect_to(panel_web_resource_back_end_web_links_url, :notice => t('web_resource.update_web_resource_success')) }
@ -106,4 +113,9 @@ class Panel::WebResource::BackEnd::WebLinksController < ApplicationController
@web_link_categorys = (id ? WebLinkCategory.find(id).to_a : WebLinkCategory.excludes('disabled' => true))
end
def get_tags()
module_app = ModuleApp.first(:conditions => {:key => 'web_resource'})
@tags = Tag.all(:conditions => {:module_app_id => module_app.id})
end
end

View File

@ -12,9 +12,7 @@ class Panel::WebResource::FrontEnd::WebLinksController < ObitWidgetController
date_now = Time.now
# @web_links = WebLink.any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate).page( params[:page]).per(1)
@web_links = WebLink.desc("is_top").page( params[:page])
@web_links = WebLink.where( :is_hidden => false ).desc(:is_top, :name).page( params[:page]).per(20)
get_categorys
end

View File

@ -25,26 +25,15 @@ class WebLink
before_save :set_key
def self.search( search = nil, category_id = nil )
def self.search( category_id = nil )
if category_id.to_s.size > 0 and search.to_s.size > 0
if category_id.to_s.size > 0
key = /#{search}/
find(:all, :conditions => {web_link_category_id: category_id}).desc( :is_top, :name )
find(:all, :conditions => {name: key, web_resource_category_id: category_id}).desc( :is_top, :postdate )
elsif category_id.to_s.size > 0 and search.to_s.size < 1
find(:all, :conditions => {web_resource_category_id: category_id}).desc( :is_top, :postdate )
elsif search.to_s.size > 0 and category_id.to_s.size < 1
key = /#{search}/
find(:all, :conditions => {name: key}).desc( :is_top, :postdate )
else
find(:all).desc( :is_top, :postdate)
find(:all).desc( :is_top, :name)
end
@ -55,10 +44,10 @@ class WebLink
date_now = Time.now
# find(:all, :conditions => {:postdate => {"$lte" => Date.today}, deadline: nil} ).desc( :is_top, :postdate)
# where( :postdate.lte => date_now ).where( :deadline => nil ).desc(:is_top, :postdate)
# find(:all, :conditions => {:postdate => {"$lte" => Date.today}, deadline: nil} ).desc( :is_top, :name)
where( :is_hidden => false ).desc(:is_top, :name)
# any_of({ :name => "test" },{:deadline => nil, :name => "123"})
any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :postdate)
# any_of( {deadline: nil,:postdate.lte => date_now} , {:deadline.gte => date_now,:postdate.lte => date_now} ).desc( :is_top, :name)
end

View File

@ -44,6 +44,14 @@
<%= f.check_box :is_hidden %><%= t('hidden') %>
</div>
<div class="field">
<%= f.label :tags %><br />
<% @tags.each do |tag| %>
<%= check_box_tag 'web_link[tag_ids][]', tag.id, @web_link.tag_ids.include?(tag.id)%>
<%= tag[I18n.locale] %>
<% end %>
</div>
<br />
<br />

View File

@ -1,10 +1,25 @@
<tr id="<%= dom_id post %>">
<td></td>
<td>
<% if post.is_top? %>
<span class="label label-success"><%= t(:top) %></span>
<% end %>
<% if post.is_hot? %>
<span class="label label-important"><%= t(:hot) %></span>
<% end %>
<% if post.is_hidden? %>
<span class="label"><%= t(:hidden) %></span>
<% end %>
</td>
<td><%= post.web_link_category.i18n_variable[I18n.locale] %></td>
<td>
<%= link_to post.name[I18n.locale], panel_web_resource_back_end_web_link_path(post) %>
</td>
<td>
<% post.tags.each do |tag| %>
<span class="label label-tags"><%= tag[I18n.locale] %></span>
<% end %>
</td>
<td>
<%= link_to t('web_link.edit'), edit_panel_web_resource_back_end_web_link_path(post) %> |

View File

@ -19,23 +19,16 @@
<br />
<br />
<fieldset><legend><%= t('web_link.search') %></legend>
<%= form_for :web_link, :action => 'search', :method => 'get', :url => panel_web_resource_back_end_web_links_path do |f| %>
<%#= f.select :web_link_category_id, @web_link_categorys.collect {|t| [ t.i18n_variable[I18n.locale], t.id ] },{ :include_blank => t('web_link.select') }%>
Category <%= select_tag "category_id", options_for_select(@web_link_categorys.collect{|t| [t.i18n_variable[I18n.locale], t.id]}), :prompt => t('web_link.select') %>
KeyWord <%= text_field_tag :search, params[:search], :id => 'search_field' %>
<%= submit_tag "Search", :name => nil %>
<%= submit_tag "OK", :name => nil %>
<% end %>
</fieldset>
<br />
<br />
@ -46,6 +39,7 @@
<th><%= t('web_link.status') %></th>
<th><%= t('web_link.category') %></th>
<th><%= t('web_link.name') %></th>
<th><%= t('web_link.tags') %></th>
<th><%= t('web_link.action') %></th>
</tr>