module AjaxScaffoldHelper def column_value(data_object, column) column_value = data_object.send(column.name) if column_value.instance_of? Time column_value = format_time(column_value) elsif column_value.instance_of? Date column_value = format_date(column_value) end column_value end def format_time(time) time.strftime("%m/%d/%Y %I:%M %p") end def format_date(date) date.strftime("%m/%d/%Y") end # Generates a temporary id for creating a new element def generate_temporary_id (Time.now.to_f*1000).to_i.to_s end def pagination_ajax_links(paginator, params) params = params.merge(:controller => 'widgets', :action => 'list') pagination_links_each(paginator, {}) do |n| link_to_remote n, { :url => params.merge(:page => n ), :update => scaffold_content_id(params) }, { :href => url_for(params.merge(:page => n )) } end end def column_class(column_name, column_value, sort_column) class_name = String.new class_name += "empty " if column_empty?(column_value) class_name += "sorted " if (!sort_column.nil? && column_name == sort_column) class_name end def column_empty?(column_value) column_value.nil? || (column_value.empty? rescue false) end def loading_indicator_tag(options) "\"loading" end # The following are a bunch of helper methods to produce the common scaffold view id's def scaffold_content_id(options) "#{options[:scaffold_id]}-content" end def scaffold_tbody_id(options) "#{options[:scaffold_id]}-tbody" end def scaffold_messages_id(options) "#{options[:scaffold_id]}-messages" end def empty_message_id(options) "#{options[:scaffold_id]}-empty-message" end def element_row_id(options) "#{options[:scaffold_id]}-#{options[:action]}-#{options[:id]}" end def element_cell_id(options) "#{options[:scaffold_id]}-#{options[:action]}-#{options[:id]}-cell" end def element_form_id(options) "#{options[:scaffold_id]}-#{options[:action]}-#{options[:id]}-form" end def loading_indicator_id(options) if options[:id].nil? "#{options[:scaffold_id]}-#{options[:action]}-loading-indicator" else "#{options[:scaffold_id]}-#{options[:action]}-#{options[:id]}-loading-indicator" end end def element_messages_id(options) "#{options[:scaffold_id]}-#{options[:action]}-#{options[:id]}-messages" end end