Add some search input.

This commit is contained in:
BoHung Chiu 2022-06-30 12:17:47 +08:00
parent 7cfbaaf3df
commit 9579179685
4 changed files with 29 additions and 4 deletions

View File

@ -6,8 +6,10 @@ class Admin::AdminModulesController < OrbitAdminController
end end
def index def index
@registered_modules = RegisteredModule.where(:completed => true).page(params[:page]).per(10) @filter_fields = {}
@registered_modules = RegisteredModule.where(:completed => true)
@table_fields = table_fields @table_fields = table_fields
@registered_modules = search_data(@registered_modules,[:name, :module_key]).page(params[:page]).per(10)
if request.xhr? if request.xhr?
render :partial => "index" render :partial => "index"
end end

View File

@ -1,4 +1,5 @@
<%= javascript_include_tag "plugin/jquery.form.min" %> <%= javascript_include_tag "plugin/jquery.form.min" %>
<%= render_filter @filter_fields, "index_table" %>
<span id="index_table"> <span id="index_table">
<%= render 'index'%> <%= render 'index'%>
</span> </span>
@ -64,7 +65,7 @@
var actionsModal = $("#actionsModal"); var actionsModal = $("#actionsModal");
var btn_type = null; var btn_type = null;
var module_id = null; var module_id = null;
$(".action-btns").on("click",function(){ $(document).on("click", ".action-btns", function(){
btn_type = $(this).attr("for"); btn_type = $(this).attr("for");
module_id = $(this).data("id"); module_id = $(this).data("id");
$.ajax({ $.ajax({

View File

@ -2,11 +2,22 @@
<% if @registered_sites.blank? %> <% if @registered_sites.blank? %>
<span>Sorry no sites active or all the websites already have this module.</span> <span>Sorry no sites active or all the websites already have this module.</span>
<% else %> <% else %>
<input id="search_webs" type="text" placeholder="Domain, ex: example.com">
<% @registered_sites.each do |rs|%> <% @registered_sites.each do |rs|%>
<label> <label data-domain="<%=rs.site_domain%>">
<input type="checkbox" name="websites[]" value="<%= rs.id.to_s %>" /> <input type="checkbox" name="websites[]" value="<%= rs.id.to_s %>" />
<a href="<%= "http://" + rs.site_domain %>" target="_blank"><%= rs.title || rs.site_domain %></a> <a href="<%= "http://" + rs.site_domain %>" target="_blank"><%= rs.title || rs.site_domain %></a>
</label> </label>
<% end %> <% end %>
<script>
$('#search_webs').on('input',function(){
var domain = $(this).val().replace(/http[s]:\/\//,'');
if(domain == ""){
$(this).siblings('label').removeClass('hide');
}else{
$(this).siblings('label').removeClass('hide').filter(':not([data-domain*="'+domain+'"])').addClass('hide');
}
})
</script>
<% end %> <% end %>
</div> </div>

View File

@ -2,12 +2,23 @@
<% if @registered_sites.blank? %> <% if @registered_sites.blank? %>
<span>Sorry no sites active or this module is not installed anywhere.</span> <span>Sorry no sites active or this module is not installed anywhere.</span>
<% else %> <% else %>
<input id="search_webs" type="text" placeholder="Domain, ex: example.com">
<% @registered_sites.each_with_index do |rs, index|%> <% @registered_sites.each_with_index do |rs, index|%>
<label> <label data-domain="<%=rs.site_domain%>">
<input type="checkbox" name="websites[]" value="<%= rs.id.to_s %>" /> <input type="checkbox" name="websites[]" value="<%= rs.id.to_s %>" />
<a href="<%= "http://" + rs.site_domain %>" target="_blank"><%= rs.title || rs.site_domain %></a> <a href="<%= "http://" + rs.site_domain %>" target="_blank"><%= rs.title || rs.site_domain %></a>
<span class="pull-right"><%= @times[index] %></span> <span class="pull-right"><%= @times[index] %></span>
</label> </label>
<% end %> <% end %>
<script>
$('#search_webs').on('input',function(){
var domain = $(this).val().replace(/http[s]:\/\//,'');
if(domain == ""){
$(this).siblings('label').removeClass('hide');
}else{
$(this).siblings('label').removeClass('hide').filter(':not([data-domain*="'+domain+'"])').addClass('hide');
}
})
</script>
<% end %> <% end %>
</div> </div>