Module: Bureau::Adapter::ClassMethods

Included in:
Sequel::Plugins::BureauAdapter::ClassMethods
Defined in:
lib/bureau/adapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bureau_configObject

Returns the value of attribute bureau_config.



5
6
7
# File 'lib/bureau/adapter.rb', line 5

def bureau_config
  @bureau_config
end

#list_optionsObject

Returns the value of attribute list_options.



5
6
7
# File 'lib/bureau/adapter.rb', line 5

def list_options
  @list_options
end

Instance Method Details

#command_plusObject



33
34
35
36
37
38
# File 'lib/bureau/adapter.rb', line 33

def command_plus
  o = @list_options
  path = "#{o[:path]}/#{self.name}?_no_wrap=true&_destination=#{::Rack::Utils::escape(o[:destination])}"
  o[:filter].each{|k,v|path<<"&model[#{k}]=#{::Rack::Utils::escape(v)}"} unless o[:filter].nil?
  "<a href='#{path}' class='btn btn-plus push-stack' title='Create'></a>\n"
end

#command_reloadObject



29
30
31
# File 'lib/bureau/adapter.rb', line 29

def command_reload
  "<a class='btn btn-reload' href='#' title='Reload'></a>\n"
end

#command_searchObject



40
41
42
43
# File 'lib/bureau/adapter.rb', line 40

def command_search
  o = @list_options
  "<form action='#{o[:destination]}' method='GET' class='search'>Search:<input type='search' name='q' value='#{o[:request]['q']}' /><input type='submit' value='Search' /></form>"
end

#foreign_key_name(plural = false) ⇒ Object



11
# File 'lib/bureau/adapter.rb', line 11

def foreign_key_name(plural=false); "id#{'s' if plural}_"+self.name; end

#human_nameObject



12
# File 'lib/bureau/adapter.rb', line 12

def human_name; self.name.gsub(/([A-Z])/, ' \1')[1..-1]; end

#human_plural_nameObject



13
# File 'lib/bureau/adapter.rb', line 13

def human_plural_name; human_name+'s'; end

#list_titleObject



14
# File 'lib/bureau/adapter.rb', line 14

def list_title; human_plural_name; end

#list_view(r) ⇒ Object



7
8
9
# File 'lib/bureau/adapter.rb', line 7

def list_view(r)
  "Override Me -- #{self.name}#list_view"
end

#list_view_headerObject



16
17
18
19
20
21
22
23
# File 'lib/bureau/adapter.rb', line 16

def list_view_header
  o = @list_options
  out = "<h2 class='list-title slide-title'><span>#{list_title}</span><div class='nut-tree-toolbar'>"
  out << command_plus unless bureau_config[:no_plus]
  out << command_reload
  out << command_search unless bureau_config[:no_search]
  out << "</div></h2>\n"
end

#many_to_many_pickerObject



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/bureau/adapter.rb', line 45

def many_to_many_picker
  opts = @list_options
  klass = bureau_config[:minilist_class].is_a?(Symbol) ? Kernel.const_get(bureau_config[:minilist_class]) : bureau_config[:minilist_class]
  klass.list_options = @list_options
  params_sample = (opts[:filter]||{}).map{|k,v| "model[#{k}]=#{::Rack::Utils::escape(v)}" }
  params_sample << "model[#{klass.foreign_key_name}]="
  o = "<div class='many-to-many-picker' rel='#{params_sample.join('&')}'>\n"
  o << "<div class='many-to-many-search'>Filter:<input type='search' class='minisearch' name='minisearch' /> Drag and Drop what you want to add</div>\n"
  o << "<div class='minilist-wrapper'>\n"
  o << klass.minilist_view
  o << "</div>\n"
  o << "</div>\n"
end

#sortable_on_that_page?Boolean



25
26
27
# File 'lib/bureau/adapter.rb', line 25

def sortable_on_that_page?
  false
end