Permalink
Browse files

add expander for edit play

  • Loading branch information...
1 parent d9f8562 commit 3ee2560f6a36d77d294959f3c49a6429d8919402 @geraldb geraldb committed Sep 28, 2012
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,227 @@
+/* todo:
+ make input[type=text] configurable!!!!
+
+
+ use data-td-type: number|string|date
+ use data-td-input: true|false (default is false)
+
+ use data-cell|table|??
+
+ add support for date
+ add icons for up and down
+
+
+ ***** uses stable merge sort or use pos hack on equal
+ ***** add to docu
+
+*/
+
+
+ var keyFuncs = {
+ "input" : function( $cell ) { return $cell.find('input[type=text]').val(); },
+ "text": function( $cell ) { return $cell.text(); },
+ "void": function( $cell ) { return ''; }
+ };
+
+
+
+ function table_filter_worker( $rows, query, keyFuncMap ) {
+ query = $.trim(query); //trim white space
+ query = query.replace(/ /gi, '|'); //add OR for regex query
+
+ var regex = new RegExp(query, 'i');
+
+ $rows.each( function() {
+ var text = "| ";
+ $(this).find( 'td' ).each( function( index ) {
+ text += keyFuncMap[index]( $(this) ) + " |";
+ } );
+
+ // console.log( "[debug] text: " + text );
+
+ if( text.search( regex ) < 0 ) {
+ $(this).hide().removeClass('visible')
+ } else {
+ $(this).show().addClass('visible');
+ }
+ }); // each row
+ }
+
+ function table_filter( filter_id, table_id )
+ {
+ var $table = $( table_id );
+
+ // build keyFuncMap for/from columns
+ var keyFuncMap = [];
+
+ // NB: by default use :last (if more than one table header row; only use the last one)
+ $table.find( 'thead tr:last th' ).each( function( columnIndex ) {
+
+ // NB: lets you use data-filter=false to make column NOT filterable
+ var filterable = $(this).data( 'filter' );
+ if( filterable === undefined )
+ filterable = true;
+
+ if( filterable )
+ {
+ var keyType = $(this).data( 'input' );
+ if( keyType === true )
+ keyType = 'input';
+ else
+ keyType = 'text';
+
+ keyFuncMap[ columnIndex ] = keyFuncs[ keyType ];
+ }
+ else
+ {
+ keyFuncMap[ columnIndex ] = keyFuncs['void'];
+ }
+ }); // each th
+
+
+ var $rows = $table.find( 'tbody tr,tfoot tr' );
+ $rows.addClass('visible'); //default each row to visible
+
+ $( filter_id ).keyup( function(event) {
+ //if esc is pressed or nothing is entered
+ if( event.keyCode == 27 || $(this).val() == '' ) {
+ //if esc is pressed we want to clear the value of search box
+ $(this).val('');
+ //we want each row to be visible because if nothing
+ //is entered then all rows are matched.
+ $rows.removeClass('visible').show().addClass('visible');
+ }
+ //if there is text, lets filter
+ else {
+ table_filter_worker( $rows, $(this).val(), keyFuncMap );
+ }
+ });
+ }
+
+
+ function table_sorter( table_id )
+ {
+ var sortFuncs = {
+ "int" : function(left,right) { return left - right; },
+ "float" : function(left,right) { return left - right; },
+ "string" : function(left,right) { if (left<right) return -1; if (left>right) return 1; return 0;}
+ };
+
+ // NB: use replace( /,/g, '' ) for numbers (remove , lets you use 123,444,444 instead of 123444444 )
+ // convert from text to data type
+ var convFuncs = {
+ "int" : function(text) { return parseInt( text.replace( /,/g, ''), 10); },
+ "float" : function(text) { return parseFloat( text.replace( /,/g, '')); },
+ "string" : function(text) { return text; }
+ };
+
+ var $table = $( table_id );
+
+ // NB: by default use :last (if more than one table header row; only use the last one)
+ $table.find( 'thead tr:last th' ).each( function( columnIndex ) {
+
+ // NB: lets you use data-sort=false to make column NOT sortable
+ var sortable = $(this).data( 'sort' );
+ if( sortable === undefined )
+ sortable = true;
+
+ if( sortable )
+ {
+ // console.log( "sortable["+columnIndex+"]" );
+
+ // NB: add class .sortable for easy styling
+ $(this).addClass( 'sortable' );
+
+ var keyType = $(this).data( 'input' );
+ if( keyType === true )
+ keyType = 'input';
+ else
+ keyType = 'text';
+
+ var sortType = $(this).data( 'type' );
+ if( sortType === undefined )
+ sortType = 'string';
+
+ // console.log( "keytype: " + keyType + ", sortType: " + sortType );
+
+ var keyFunc = keyFuncs[ keyType ];
+ var convFunc = convFuncs[ sortType ];
+ var sortFunc = sortFuncs[ sortType ];
+
+ $(this).click( function() {
+
+ // console.log( "onclick sortable["+columnIndex+"]");
+
+ var sortDirection = $(this).is( '.sorted-asc' ) ? -1 : 1;
+
+ var $rows = $table.find( 'tbody tr' );
+
+ // console.log( $rows );
+
+ $rows.each( function( index, row ) {
+ row.sortKey = convFunc( keyFunc( $(row).children( 'td' ).eq( columnIndex ) ));
+ row.sortPos = index; // NB: stable sort hack, part i - on equal use sortPos to keep stable sort with unstable sort
+ // console.log( "["+index+"]" + row.sortKey );
+ });
+
+ $rows.sort( function( left, right ) {
+ var result = sortFunc( left.sortKey, right.sortKey );
+
+ if( sortDirection == -1 )
+ result = -result;
+
+ // NB: stable sort hack, part ii
+ if( result == 0 )
+ result = left.sortPos - right.sortPos;
+
+ return result;
+ });
+
+ $rows.each( function( index, row ) {
+ $table.find( 'tbody' ).append( row );
+ // row.sortKey = null;
+ // row.sortPos = null;
+ });
+
+ $table.find( 'thead tr:last th').removeClass( 'sorted-asc sorted-desc' );
+ sortDirection == 1 ? $(this).addClass( 'sorted-asc' ) : $(this).addClass( 'sorted-desc' );
+ });
+ }
+ });
+ }
+
+
+ function table_hovered( table_id )
+ {
+ $( table_id ).find( 'tbody tr,tfoot tr' ).hover( function() {
+ $(this).find( 'td' ).addClass( 'hovered' );
+ }, function() {
+ $(this).find( 'td' ).removeClass( 'hovered' );
+ });
+ }
+
+
+ function table_expander( table_sel, group_class )
+ {
+ var up_class = 'expander-hide';
+ var down_class = 'expander-show';
+
+ $( table_sel ).each( function() {
+
+ var $table = $( this );
+ var $groups = $table.find( "tr."+group_class );
+
+ // NB: by default rows started out shown/expanded
+ $groups.addClass( up_class );
+
+ // NB: add last style class to last td for easy styling with icons
+ // ie8 doesn't support :last-child in css
+ $groups.find( "td:last" ).addClass( 'last' );
+ $groups.find( "td:first" ).addClass( 'first' );
+
+ $groups.click( function() {
+ $(this).nextUntil("tr."+group_class ).toggle();
+ $(this).toggleClass( up_class + " " + down_class ); // adds first; removes second class
+ });
+ }); // each table
+ }
@@ -28,7 +28,7 @@ def edit
@pool = @play.pool
@user = @play.user
- # do NOT show odds by default
+ # show odds by default
@show_odds = param_show_odds?
@@ -141,8 +141,8 @@ def param_show_tips?
end
def param_show_odds?
- # do NOT show odds (quotes) by default
- params[:odds].present? && ['1','t','true','yes', 'on'].include?( params[:odds])
+ # show odds (quotes) by default
+ params[:odds].nil? || (params[:odds].present? && ['1','t','true','yes', 'on'].include?( params[:odds]))
end
end # class PlaysController
@@ -11,11 +11,15 @@
8 => date
-->
+
+
<% rounds.each do |round| %>
+
+<a name="<%= round.id %>"></a>
<table class='play keep-together' cellspacing=0>
<tr class='game-round'>
<td colspan='3'></td>
- <td colspan='6' class='game-round-title'><%= round.title %></td>
+ <td colspan='6' class='game-round-title'><%= round.title %> / <%= round.title2 %></td>
</tr>
<% if round.games.count == 0 %>
<tr>
@@ -3,7 +3,8 @@
<% content_for :breadcrumb do %>
<%= link_to 'Wettpools', pools_path() %>
<%= link_to @pool.full_title, pool_path(@pool) %>
- <%= link_to @user.name, edit_play_path( @play ) %>
+ <%= link_to @user.name, play_path( @play ) %>
+ <%= link_to 'Edit', edit_play_path( @play ) %>
<% end %>
<p class='view'>
@@ -13,8 +14,45 @@
</p>
-<!-- add hotkey handler for quick tip autofill -->
+<style>
+ /* styling for table_expander */
+
+ tr.game-round {
+ cursor: pointer;
+ }
+
+ tr.game-round.expander-hide {
+ background-color: navy;
+ color: white;
+ }
+ tr.game-round.expander-hide td {
+ background-color: navy;
+ color: white;
+ }
+
+
+ tr.game-round.expander-hide td.first,
+ tr.game-round.expander-show td.first {
+ padding-left: 17px; /* 2+15 */
+ background-repeat: no-repeat;
+ background-position: left center;
+ }
+
+ tr.game-round.expander-hide td.first {
+ background-image: url(<%= asset_path('down-arrow.png') %>);
+ }
+
+ tr.game-round.expander-show td.first {
+ background-image: url(<%= asset_path('right-arrow.png') %>);
+ }
+
+
+</style>
+
+
+
<script>
+ // add hotkey handler for quick tip autofill
// function testTimer()
// {
@@ -23,6 +61,8 @@
$(document).ready( function() {
+ table_expander( 'table.play', 'game-round' );
+
recalcPlayTips();
$(document).on( 'keydown', function( event ) {
@@ -161,6 +201,19 @@
<% if @pool.flex? %>
+
+ <p>
+ <% @pool.event.flex_rounds.each_with_index do |round,i| %>
+ <% if i > 0 %>
+ &bull;
+ <% end %>
+ <!-- todo: use prettified cleaned url
+ add ready only attr to model
+ -->
+ <%= link_to round.title, "##{round.id}" %>
+ <% end %>
+ </p>
+
<%= render :partial => 'games_by_round', :locals => { :rounds => @pool.event.flex_rounds, :user => @user, :pool => @pool, :f => f, :tabindex => 1000, :show_odds => @show_odds } %>
<!-- todo: include group tables if groups exist -->
<% else %>
@@ -171,7 +224,7 @@
<p>
- <%= f.submit t(:edit_bets), :class => 'btn-primary' %>
+ <%= f.submit t(:save_bets), :class => 'btn-primary' %>
<%= link_to t(:back), play_path( @play ), :class => 'btn' %>
</p>
<% end %>
Oops, something went wrong.

0 comments on commit 3ee2560

Please sign in to comment.