Permalink
Browse files

Added support for associations

Removed prototype
Refactored views
  • Loading branch information...
1 parent b5f217b commit 9b6185fc3929eb6e48427b3f1309ecc197152144 @chicks chicks committed Feb 27, 2011
View
27 Gemfile
@@ -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'
View
@@ -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)
@@ -79,5 +82,6 @@ PLATFORMS
ruby
DEPENDENCIES
+ jquery-rails (>= 0.2.6)
rails (= 3.0.0)
sugarcrm!
@@ -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
@@ -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>
@@ -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 %>
@@ -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 %>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
View
@@ -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
Oops, something went wrong.

0 comments on commit 9b6185f

Please sign in to comment.