Module: Zena::Use::Grid::ViewMethods

Includes:
Common
Included in:
Zazen::ViewMethods
Defined in:
lib/zena/use/grid.rb

Instance Method Summary collapse

Methods included from Common

#get_table_from_json

Instance Method Details

#make_table(opts) ⇒ Object

Create a table from an attribute



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/zena/use/grid.rb', line 111

def make_table(opts)
  style, node, attribute, title, table = opts[:style], opts[:node], opts[:attribute], opts[:title], opts[:table]
  case (style || '').sub('.', '')
  when ">"
    prefix = "<div class='img_right'>"
    suffix = "</div>"
  when "<"
    prefix = "<div class='img_left'>"
    suffix = "</div>"
  when "="
    prefix = "<div class='img_center'>"
    suffix = "</div>"
  else
    prefix = ''
    suffix = ''
  end

  if node.can_write?
    prefix << "<div class='table_add'>"
    prefix << link_to_remote("<img src='/images/column_add.png' alt='#{_('add column')}'/>",
                              :url => "/nodes/#{node.zip}/table_update?add=column&attr=#{attribute}")
    prefix << link_to_remote("<img src='/images/column_delete.png' alt='#{_('add column')}'/>",
                              :url => "/nodes/#{node.zip}/table_update?remove=column&attr=#{attribute}")
    prefix << link_to_remote("<img src='/images/row_add.png' alt='#{_('add column')}'/>",
                              :url => "/nodes/#{node.zip}/table_update?add=row&attr=#{attribute}")
    prefix << link_to_remote("<img src='/images/row_delete.png' alt='#{_('add column')}'/>",
                              :url => "/nodes/#{node.zip}/table_update?remove=row&attr=#{attribute}")
    prefix << "</div>"
  end

  table ||= get_table_from_json(node.prop[attribute])

  prefix + render_to_string( :partial=>'nodes/table', :locals => {
    :table     => table,
    :node      => node,
    :attribute => attribute
  }) + suffix
rescue JSON::ParserError
  "<span class='unknownLink'>could not build table from text</span>"
end