Skip to content

Commit

Permalink
Added support for column sorting in grid.js
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed May 30, 2012
1 parent be2b8f0 commit 28a53a8
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 147 deletions.
2 changes: 1 addition & 1 deletion bricks/tags/lib/bricks/tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Tags
def self.included(base)
base.after_save :update_tags
base.safe_context :tags => ['Link']
base.safe_method :tag_list => String, :tag => String, :tagged => StringHash, :tag_names => [String]
base.safe_method :tag_list => String, :tag => String, :tagged => ::StringHash, :tag_names => [String]

base.class_eval <<-END
include Bricks::Tags::InstanceMethods
Expand Down
53 changes: 0 additions & 53 deletions public/en/404.html.png.1144713600

This file was deleted.

87 changes: 0 additions & 87 deletions public/en/textdocument54.css.1144713600

This file was deleted.

33 changes: 31 additions & 2 deletions public/javascripts/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,15 @@ Grid.openCell = function(cell) {

Grid.click = function(event) {
var cell = event.findElement('td, th')
var row = event.findElement('tr')
var row = cell.up('tr')
var table = cell.up('table')
if (row.hasClassName('action')) {
Grid.action(event, cell, row, true)
} else if (cell.hasClassName('action')) {
Grid.action(event, cell, row, false)
} else if (cell.tagName == 'TH' && !table.grid.attr_name) {
// sort
Grid.sort(cell)
} else {
Grid.openCell(cell)
}
Expand Down Expand Up @@ -515,7 +519,7 @@ Grid.action = function(event, cell, row, is_col) {

// map grid position to attribute and reverse.
Grid.makeAttrPos = function(table) {
var heads = table.childElements()[0].select('th');
var heads = table.select('th');
var attr = {};
var pos = {};
var helper = {}
Expand Down Expand Up @@ -949,6 +953,29 @@ Grid.simulateClick = function(l) {
}
}

Grid.sort = function(cell) {
var table = cell.up('table')
var desc = false
if (cell.hasClassName('asc')) {
desc = true
cell.removeClassName('asc')
cell.addClassName('desc')
} else {
table.select('.asc, .desc').each(function(e) { e.removeClassName('asc').removeClassName('desc') })
cell.addClassName('asc')
}
var body = table.childElements()[0]
var rows = body.select('tr')
rows.splice(0,1)
var col_i = Grid.pos(cell)

rows.sort(function(a, b) {
var atxt = a.childElements()[col_i].innerHTML.stripTags().toLowerCase()
var btxt = b.childElements()[col_i].innerHTML.stripTags().toLowerCase()
return atxt.localeCompare(btxt) * (desc ? -1 : 1)
}).each(Element.prototype.appendChild, body)
}

/////////// Tags
Tags = {}

Expand Down Expand Up @@ -997,3 +1024,5 @@ Tags.make = function(elem, opts) {
}
})
}


3 changes: 3 additions & 0 deletions public/stylesheets/grid.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@

.tags li {border-radius:2px; background:#ccc url('/images/remove_tag.png') no-repeat; padding:2px 5px 2px 15px; margin:3px; display:inline; background-position:2px 4px}
.tags li.add {background:#8c8 url('/images/add.png') no-repeat;background-position:1px 2px}

.grid .asc {background:#7b7}
.grid .desc {background:#fa0}
9 changes: 5 additions & 4 deletions zena.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |s|

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Gaspard Bucher"]
s.date = %q{2012-05-21}
s.date = %q{2012-05-30}
s.default_executable = %q{zena}
s.description = %q{zena is a Ruby on Rails CMS (content managment system) with a focus on usability, ease of customization and web 2.0 goodness (application like behaviour).}
s.email = %q{gaspard@teti.ch}
Expand Down Expand Up @@ -86,6 +86,7 @@ Gem::Specification.new do |s|
"app/models/section.rb",
"app/models/site.rb",
"app/models/skin.rb",
"app/models/string_hash.rb",
"app/models/template.rb",
"app/models/template_content.rb",
"app/models/template_version.rb",
Expand Down Expand Up @@ -2469,7 +2470,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency(%q<httparty>, ["= 0.7.8"])
s.add_runtime_dependency(%q<simple_xlsx_writer>, [">= 0"])
s.add_runtime_dependency(%q<rubyless>, ["= 0.8.6"])
s.add_runtime_dependency(%q<property>, ["= 2.2.0"])
s.add_runtime_dependency(%q<property>, ["= 2.3.0"])
s.add_runtime_dependency(%q<uuidtools>, ["= 2.0.0"])
s.add_runtime_dependency(%q<authlogic>, ["= 2.1.3"])
s.add_runtime_dependency(%q<shoulda>, ["= 2.10.3"])
Expand All @@ -2495,7 +2496,7 @@ Gem::Specification.new do |s|
s.add_dependency(%q<httparty>, ["= 0.7.8"])
s.add_dependency(%q<simple_xlsx_writer>, [">= 0"])
s.add_dependency(%q<rubyless>, ["= 0.8.6"])
s.add_dependency(%q<property>, ["= 2.2.0"])
s.add_dependency(%q<property>, ["= 2.3.0"])
s.add_dependency(%q<uuidtools>, ["= 2.0.0"])
s.add_dependency(%q<authlogic>, ["= 2.1.3"])
s.add_dependency(%q<shoulda>, ["= 2.10.3"])
Expand All @@ -2522,7 +2523,7 @@ Gem::Specification.new do |s|
s.add_dependency(%q<httparty>, ["= 0.7.8"])
s.add_dependency(%q<simple_xlsx_writer>, [">= 0"])
s.add_dependency(%q<rubyless>, ["= 0.8.6"])
s.add_dependency(%q<property>, ["= 2.2.0"])
s.add_dependency(%q<property>, ["= 2.3.0"])
s.add_dependency(%q<uuidtools>, ["= 2.0.0"])
s.add_dependency(%q<authlogic>, ["= 2.1.3"])
s.add_dependency(%q<shoulda>, ["= 2.10.3"])
Expand Down

0 comments on commit 28a53a8

Please sign in to comment.