Skip to content

Commit

Permalink
jquery support and maybe a bug corrected
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Knight <[email protected]>
  • Loading branch information
fguillen authored and Jason Knight committed Mar 22, 2009
1 parent a65c036 commit bffd977
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 36 deletions.
38 changes: 14 additions & 24 deletions assets/exception_logger.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,38 @@
ExceptionLogger = {
filters: ['exception_names', 'controller_actions', 'date_ranges'],
setPage: function(num) {
$('page').value = num;
$('query-form').onsubmit();
$('#page').val(num);
$('#query-form').submit();
},

setFilter: function(context, name) {
var filterName = context + '_filter'
$(filterName).value = ($F(filterName) == name) ? '' : name;
var filterName = '#' + context + '_filter'
$(filterName).value = ($(filterName).val() == name) ? '' : name;
this.deselect(context, filterName);
$('page').value = '1';
$('query-form').onsubmit();
$('#page').value = '1';
$('#query-form').submit();
},

deselect: function(context, filterName) {
$$('#' + context + ' a').each(function(a) {
var value = $(filterName) ? $F(filterName) : null;
$('#' + context + ' a').each(function(a) {
var value = $(filterName) ? $(filterName).val() : null;
a.className = (value && (a.getAttribute('title') == value || a.innerHTML == value)) ? 'selected' : '';
});
},

deleteAll: function() {
return Form.serialize('query-form') + '&' + $$('tr.exception').collect(function(tr) { return tr.getAttribute('id').gsub(/^\w+-/, ''); }).toQueryString('ids');
return $('#query-form').serialize() + '&' + jQuery.map($('tr.exception'), function(tr) { return 'ids[]=' + tr.id.replace(/^\w+-/, '') }).join('&');
}
}

Event.observe(window, 'load', function() {
ExceptionLogger.filters.each(function(context) {
$(document).ready(function(){
jQuery.each(ExceptionLogger.filters, function(context) {
$(context + '_filter').value = '';
});
});

Object.extend(Array.prototype, {
toQueryString: function(name) {
return this.collect(function(item) { return name + "[]=" + encodeURIComponent(item) }).join('&');
}
});

Ajax.Responders.register({
onCreate: function() {
if($('activity') && Ajax.activeRequestCount > 0) $('activity').visualEffect('appear', {duration:0.25});
},
$("#activity")
.ajaxStart(function(){ $(this).show(250); })
.ajaxStop(function(){ $(this).hide(250); });

onComplete: function() {
if($('activity') && Ajax.activeRequestCount == 0) $('activity').visualEffect('fade', {duration:0.25});
}
});
6 changes: 3 additions & 3 deletions init.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$PAGINATION_TYPE = 'none'
#require 'will_paginate'
#$PAGINATION_TYPE = 'will_paginate'
#$PAGINATION_TYPE = 'none'
require 'will_paginate'
$PAGINATION_TYPE = 'will_paginate'
#WillPaginate.enable
#require 'paginating_find'
#$PAGINATION_TYPE = 'paginating_find'
Expand Down
16 changes: 11 additions & 5 deletions lib/logged_exceptions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@ class LoggedExceptionsController < ActionController::Base
def index
@exception_names = LoggedException.find_exception_class_names
@controller_actions = LoggedException.find_exception_controllers_and_actions

query

respond_to do |format|
format.html { render :action => 'index' unless action_name == 'index' }
format.js { render :action => 'query.rjs' }
format.rss { render :action => 'query.rxml' }
end
end

def query
logger.debug( "------query" )
logger.debug( params.to_yaml )
conditions = []
parameters = []
unless params[:id].blank?
Expand All @@ -32,6 +41,7 @@ def query
parameters += params[:controller_actions_filter].split('/').collect(&:downcase)
end
if $PAGINATION_TYPE == 'will_paginate' then
logger.debug( "---------aqui" )
@exceptions = LoggedException.paginate :order => 'created_at desc', :per_page => 30,
:conditions => conditions.empty? ? nil : parameters.unshift(conditions * ' and '), :page => params[:page]
elsif $PAGINATION_TYPE == 'paginating_find' then
Expand All @@ -50,11 +60,7 @@ def query
@exceptions = LoggedException.find(:all, :limit => "#{page},#{params[:limit]}", :conditions => conditions.empty? ? nil : parameters.unshift(conditions * ' and '))
end

respond_to do |format|
format.html { redirect_to :action => 'index' unless action_name == 'index' }
format.js { render :action => 'query.rjs' }
format.rss { render :action => 'query.rxml' }
end

end

def show
Expand Down
2 changes: 1 addition & 1 deletion views/logged_exceptions/_show.rhtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="tools">
<%= link_to_remote 'Delete', {:url => { :action => 'destroy', :id => @exc }} , :class => "util" %>
<span class="pipe">|</span>
<%= link_to_function "Close", "$('showpage').style.display='none';", :class => "util" %>
<%= link_to_function "Close", "$('#showpage').hide();", :class => "util" %>

</div>

Expand Down
2 changes: 1 addition & 1 deletion views/logged_exceptions/destroy.rjs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
page["exception-#{params[:id]}"].addClassName('deleted')
page["exception-#{params[:id]}"].addClass('deleted')
page[:showpage].hide
4 changes: 2 additions & 2 deletions views/logged_exceptions/index.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<title>Logged Exceptions</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<%= javascript_include_tag 'prototype','effects' %>
<%= javascript_include_tag :defaults %>
<script type="text/javascript">
<%= IO.read(File.join(RAILS_ROOT, 'vendor/plugins/exception_logger/assets/exception_logger.js')) %>
</script>
Expand Down Expand Up @@ -50,7 +50,7 @@


<div id="search">
<%= form_remote_tag :url => { :action => 'query' }, :html => { :id => 'query-form' } %>
<%= form_remote_tag :url => { :action => 'index' }, :html => { :id => 'query-form' } %>
<div>

<%= text_field_tag :query, "", :size => 17 %>
Expand Down

0 comments on commit bffd977

Please sign in to comment.