Permalink
Browse files

Lots of changes.

  • Loading branch information...
1 parent 1884fb4 commit f3b5af99102eb55ce4ef6b864ddf97509487a594 @briandmcnabb committed Mar 28, 2012
View
31 .rvmrc
@@ -0,0 +1,31 @@
+#!/usr/bin/env bash
+
+# This is an RVM Project .rvmrc file, used to automatically load the ruby
+# development environment upon cd'ing into the directory
+
+# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
+
+environment_id="ruby-1.9.2-p290@sortable_columns"
+
+
+# First we attempt to load the desired environment directly from the environment
+# file. This is very fast and efficient compared to running through the entire
+# CLI and selector. If you want feedback on which environment was used then
+# insert the word 'use' after --create as this triggers verbose mode.
+
+if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
+then
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
+
+ if [[ -s ".rvm/hooks/after_use" ]]
+ then
+ . ".rvm/hooks/after_use"
+ fi
+else
+ # If the environment file has not yet been created, use the RVM CLI to select.
+ if ! rvm --create "$environment_id"
+ then
+ echo "Failed to create RVM environment '$environment_id'."
+ fi
+fi
@@ -0,0 +1,6 @@
+jQuery ->
+ $('tbody#positionable').sortable
+ axis: 'y'
+ handle: '.handle'
+ update: ->
+ $.post($(this).data('position_url'), $(this).sortable('serialize'))
View
@@ -1,10 +1,14 @@
require 'action_view'
-require 'sortable_columns/config'
-require 'sortable_columns/column_sorter'
module SortableColumns
+ autoload :Sortablizer, 'sortable_columns/sortablizer'
+ autoload :Positionable, 'sortable_columns/positionable'
+
+
ActiveSupport.on_load(:action_view) do
require 'sortable_columns/action_view_extensions/sort_helper'
+ require 'sortable_columns/action_view_extensions/position_helper'
include SortableColumns::ActionViewExtensions::SortHelper
+ include SortableColumns::ActionViewExtensions::PositionHelper
end
end
@@ -0,0 +1,14 @@
+module SortableColumns
+ module ActionViewExtensions
+ module PositionHelper
+
+ def position_url
+ url_for(action: 'position', controller: params[:controller], only_path: false)
+ end
+
+ def positioning_handle
+ content_tag(:span, "[drag]", class: 'ir')
+ end
+ end
+ end
+end
@@ -1,27 +0,0 @@
-require 'active_support/configurable'
-
-module SortableColumns
- # Configures global settings for SortableColumns
- # SortableColumns.configure do |config|
- # config.default_sort_column = 'created_at'
- # end
- def self.configure(&block)
- yield @config ||= SortableColumns::Configuration.new
- end
-
- # Global settings for SortableColumns
- def self.config
- @config
- end
-
- class Configuration #:nodoc:
- include ActiveSupport::Configurable
- config_accessor :default_sort_column
- config_accessor :default_sort_direction
- end
-
- configure do |config|
- config.default_sort_column = 'created_at'
- config.default_sort_direction = 'desc'
- end
-end
@@ -0,0 +1,11 @@
+module SortableColumns
+ module Positionable
+
+ def position
+ params[resource_class.name.downcase.to_sym].each_with_index do |id, index|
+ resource_class.update_all({position: index+1}, {id: id})
+ end
+ render nothing: true
+ end
+ end
+end
@@ -1,19 +1,25 @@
module SortableColumns
- class ColumnSorter
+ class Sortablizer
attr_reader :resource
def initialize(resource)
@resource = resource
end
- def column(column=nil)
- return SortableColumns.config.default_sort_column if column.nil?
- sanitize_column(column) || SortableColumns.config.default_sort_column
+ def column(column=nil, options={})
+ if column.nil?
+ options[:default] || 'created_at'
+ else
+ sanitize_column(column) || options[:default]
+ end
end
- def direction(direction=nil)
- return SortableColumns.config.default_sort_direction if direction.nil?
- sanitize_direction(direction) || SortableColumns.config.default_sort_direction
+ def direction(direction=nil, options={})
+ if direction.nil?
+ options[:default] || 'desc'
+ else
+ sanitize_direction(direction) || options[:default]
+ end
end
Binary file not shown.

0 comments on commit f3b5af9

Please sign in to comment.