Skip to content
This repository has been archived by the owner on Aug 15, 2018. It is now read-only.

Commit

Permalink
added class to page div, ability to view a form builder's responses.
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Adams committed Jan 28, 2009
1 parent 20766f1 commit 5219700
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 15 deletions.
4 changes: 4 additions & 0 deletions app/models/page.rb
Expand Up @@ -238,6 +238,10 @@ def is_draft?
status == 'draft'
end

def permalinkable_title
title.downcase.gsub(/ /, '-')
end

protected
def check_page_type
self.page_type = "page" and return if self.body.blank? || (@split_pages = self.body.split(/\{pagebreak\}/i)).length == 1
Expand Down
30 changes: 16 additions & 14 deletions app/views/content/_page.html.erb
@@ -1,16 +1,18 @@
<% if page.page_plugins.any? -%>
<% page.page_plugins.each_with_index do |plugin, i| -%>
<%# render :partial => plugin.module_class.view_partial, :locals => { :plugin_module => plugin.module } -%>
<div class='page-plugin page-plugin-<%= i -%>'>
<%= render :partial => plugin.module.view_partial, :locals => { :plugin_module => plugin.module } -%>
<% if logged_in? && get_setting('show_inline_edit_links') %>
<div class='clear'></div>
<% if current_user.can_author_content? %>
<%= link_to "[Edit]", edit_admin_page_path(:id => page.id, :anchor => "page-plugin-#{plugin.id}") %>
<% elsif current_user.can_approve_content? %>
<%= link_to "[Manage Content]", edit_admin_page_path(:id => page.id, :anchor => "page-plugin-#{plugin.id}") %>
<div class='page <%= page.permalinkable_title %>'>
<% if page.page_plugins.any? -%>
<% page.page_plugins.each_with_index do |plugin, i| -%>
<%# render :partial => plugin.module_class.view_partial, :locals => { :plugin_module => plugin.module } -%>
<div class='page-plugin page-plugin-<%= i -%>'>
<%= render :partial => plugin.module.view_partial, :locals => { :plugin_module => plugin.module } -%>
<% if logged_in? && get_setting('show_inline_edit_links') %>
<div class='clear'></div>
<% if current_user.can_author_content? %>
<%= link_to "[Edit]", edit_admin_page_path(:id => page.id, :anchor => "page-plugin-#{plugin.id}") %>
<% elsif current_user.can_approve_content? %>
<%= link_to "[Manage Content]", edit_admin_page_path(:id => page.id, :anchor => "page-plugin-#{plugin.id}") %>
<% end %>
<% end %>
<% end %>
</div>
</div>
<% end -%>
<% end -%>
<% end -%>
</div>
1 change: 0 additions & 1 deletion public/stylesheets/admin.css
Expand Up @@ -459,7 +459,6 @@ ul.admin_actions li{
}
/* -- tree ---*/
table.tree tr{
border: 0 !important;
font-size: 1.4em;
height: 35px !important;
min-height: 35px !important;
Expand Down
@@ -0,0 +1,17 @@
class Admin::FormResponsesController < Admin::BaseController
before_filter :load_form_builder
before_filter :load_form_responses

protected
def load_form_builder
@form_builder = Ansuz::JAdams::FormBuilder.find(params[:form_builder_id])
end

def load_form_responses
@form_responses = @form_builder.form_builder_responses
end

public
def index
end
end
Expand Up @@ -30,4 +30,13 @@ def render_form_field_builder_view field, options={}
render :partial => "/admin/form_fields/builder_views/#{partial_name}",
:locals => { :form_field => field }.merge(options[:locals] || {})
end

def form_field_response_for(form_field, form_response)
res = form_response.form_field_responses.find_by_form_field_id(form_field.id)
if res
res.value
else
'N/A'
end
end
end
Expand Up @@ -3,6 +3,10 @@ module JAdams
class FormFieldResponse < ActiveRecord::Base
belongs_to :form_builder_response, :class_name => "Ansuz::JAdams::FormBuilderResponse"
belongs_to :form_field, :class_name => "Ansuz::JAdams::FormField"

def value
self.send(form_field.field.value_field) || "N/A"
end
end
end
end
Expand Up @@ -4,6 +4,12 @@ class FormFieldRichTextArea < ActiveRecord::Base
has_one :form_field, :as => :field, :class_name => "Ansuz::JAdams::FormField"
before_create :ensure_label

# This is the field that this form field's value should be stored in
# on the form field response
def value_field
"text"
end

protected
def ensure_label
self.label = "Field Label" unless self.label
Expand Down
Expand Up @@ -5,6 +5,12 @@ class FormFieldTextArea < ActiveRecord::Base
before_create :ensure_label
has_settings

# This is the field that this form field's value should be stored in
# on the form field response
def value_field
"text"
end

protected
def ensure_label
self.label = "Field Label" unless self.label
Expand Down
Expand Up @@ -5,6 +5,12 @@ class FormFieldTextField < ActiveRecord::Base
has_one :form_field, :as => :field, :class_name => "Ansuz::JAdams::FormField"
before_create :ensure_label

# This is the field that this form field's value should be stored in
# on the form field response
def value_field
"string"
end

protected
def ensure_label
self.label = "Field Label" unless self.label
Expand Down
Expand Up @@ -10,3 +10,4 @@
</table>
<br />
<%= link_to "Add a field", new_admin_form_builder_form_field_path(plugin_module), :class => "icon button add" %>
<%= link_to "View Submitted Data", admin_form_builder_form_responses_path(plugin_module), :class => "icon button page" %>
@@ -0,0 +1,26 @@
<%= title "Form Responses" %>
<% content_for :sidebar do %>
<%= link_to "Form Builder", admin_form_builder_path(@form_builder), :class => "icon button back" %>
<% end %>

<table class='subdued'>
<thead>
<tr>
<% @form_builder.form_fields.each do |form_field| %>
<th><%= form_field.label %></th>
<% end %>
</tr>
</thead>
<tbody>
<% @form_responses.each do |form_response| %>
<tr>
<% @form_builder.form_fields.each do |form_field| %>
<td>
<%= form_field_response_for(form_field, form_response) %>
</td>
<% end %>
</tr>
<% end %>
</tbody>
</table>
1 change: 1 addition & 0 deletions vendor/plugins/ansuz_form_builder/routes.rb
@@ -1,6 +1,7 @@
namespace :admin do |admin|
admin.resources :form_builders do |form_builder|
form_builder.resources :form_fields
form_builder.resources :form_responses
end
admin.resources :form_field_text_fields
admin.resources :form_field_text_areas
Expand Down

0 comments on commit 5219700

Please sign in to comment.