Skip to content

Commit

Permalink
Added support for associations
Browse files Browse the repository at this point in the history
Removed prototype
Refactored views
  • Loading branch information
chicks committed Feb 27, 2011
1 parent b5f217b commit 9b6185f
Show file tree
Hide file tree
Showing 21 changed files with 20,537 additions and 9,288 deletions.
27 changes: 1 addition & 26 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,4 @@ source 'http://rubygems.org'

gem 'rails', '3.0.0'
gem 'sugarcrm', :git => 'git://github.com/chicks/sugarcrm.git'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'


# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug'

# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'

# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
# gem 'webrat'
# end
gem 'jquery-rails', '>= 0.2.6'
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ GEM
erubis (2.6.6)
abstract (>= 1.0.0)
i18n (0.4.2)
jquery-rails (0.2.7)
rails (~> 3.0)
thor (~> 0.14.4)
json (1.5.1)
mail (2.2.15)
activesupport (>= 2.3.6)
Expand Down Expand Up @@ -79,5 +82,6 @@ PLATFORMS
ruby

DEPENDENCIES
jquery-rails (>= 0.2.6)
rails (= 3.0.0)
sugarcrm!
15 changes: 11 additions & 4 deletions app/controllers/sugar_beans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@ class SugarBeansController < ApplicationController
# This controller provides a generic interface to SugarCRM. It expects
# a module name to be passed as an argument
def list
@module = params[:module]
@sugar_module = params[:module]
begin
@beans = class_for(params[:module]).all(:limit => 10)
rescue NameError
@modules = available_modules.sort
@sugar_modules = available_modules.sort
render :action => "available_modules"
end
end

def show
@module = params[:module]
@bean = class_for(params[:module]).find(params[:id])
@sugar_module = params[:module]
@bean = class_for(params[:module]).find(params[:id])
end

def show_associations
@sugar_module = params[:module]
@bean = class_for(params[:module]).find(params[:id])
@association = params[:association]
@beans = @bean.send(@association.to_sym)
end

private
Expand Down
4 changes: 2 additions & 2 deletions app/views/sugar_beans/_associations.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<div class="associations">
<div id="associations">
<h2>Associations</h2>
<table>
<%- @bean.associations.each do |a| %>
<tr>
<th><%= a.proxy_methods[0] %></th>
<td><%= link_to(a.proxy_methods[0], sugar_bean_associations_path(@sugar_module, @bean.id, a.proxy_methods[0])) %></td>
</tr>
<%- end %>
</table>
Expand Down
4 changes: 2 additions & 2 deletions app/views/sugar_beans/_attributes.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<div class="attributes">
<div id="attributes">
<h2>Attributes</h2>
<table>
<%- @bean.attributes.sort.each do |a| %>
<tr>
<th><%= a[0] %></th>
<th><%= a[0] %>:</th>
<td><%= a[1] %></td>
</tr>
<%- end %>
Expand Down
11 changes: 11 additions & 0 deletions app/views/sugar_beans/_beans.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%- if @beans.length > 0 %>
<table class="beans">
<%- @beans.each do |bean| %>
<tr id="<%= bean.id %>">
<td><%= link_to(bean.name, sugar_bean_path(bean.class._module.name.downcase, bean.id)) %></td>
</tr>
<%- end %>
</table>
<%- else %>
<p class="beans">No records found!</p>
<%- end %>
4 changes: 2 additions & 2 deletions app/views/sugar_beans/available_modules.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<h1>Invalid Module: <%= @module %></h1>
<h1>Invalid Module: <%= @sugar_module %></h1>

<div id="available_modules">
<h2>Available modules:</h2>
<ul>
<%- @modules.each do |m| %>
<%- @sugar_modules.each do |m| %>
<% if m.respond_to? :tableize %><li class="module"><%= m.tableize %></li><% end %>
<%- end %>
</ul>
Expand Down
12 changes: 4 additions & 8 deletions app/views/sugar_beans/list.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<div class="container">
<div class="container_header"><%= @module.capitalize %></div>
<table class="beans">
<%- @beans.each do |bean| %>
<tr id="<%= bean.id %>">
<td><%= link_to(bean.name, sugar_bean_path(@module, bean.id)) %></td>
</tr>
<%- end %>
</table>
<div class="container_header"><%= @sugar_module.capitalize %></div>
<div class="container_content">
<%= render :partial => "beans" %>
</div>
</div>
20 changes: 17 additions & 3 deletions app/views/sugar_beans/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
<div class="container">
<div class="container_header">Details</div>
<div class="bean">
<%= render :partial => "attributes", :locals => {:bean => @bean} %>
<%= render :partial => "associations", :locals => {:bean => @bean} %>
<div class="container_content">
<div class="bean">
<div id="tabs">
<ul>
<li><a href="#attributes">Attributes</a></li>
<li><a href="#associations">Associations</a></li>
</ul>
</div>
<%= render :partial => "attributes" %>
<%= render :partial => "associations" %>
</div>
</div>
</div>

<script>
$(function() {
$("#tabs").tabs();
});
</script>
6 changes: 6 additions & 0 deletions app/views/sugar_beans/show_associations.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="container">
<div class="container_header"><%= @sugar_module.capitalize + ": " + @association.capitalize %></div>
<div class="container_content">
<%= render :partial => "beans" %>
</div>
</div>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
SugarOnRailsBasic::Application.routes.draw do
match ':module' => 'sugar_beans#list', :as => "module"
match ':module/:id' => 'sugar_beans#show', :as => "sugar_bean"
match ':module/:id/:association' => 'sugar_beans#show_associations', :as => "sugar_bean_associations"
root :to => "sugar_beans#list", :module => "accounts"
end
Loading

0 comments on commit 9b6185f

Please sign in to comment.