Skip to content

Commit

Permalink
Merge pull request #1 from rb512/master
Browse files Browse the repository at this point in the history
Web-To-Lead form
  • Loading branch information
Bob Roberts committed Oct 22, 2012
2 parents eccec2b + 0358b14 commit b1b5906
Show file tree
Hide file tree
Showing 16 changed files with 151 additions and 12 deletions.
4 changes: 3 additions & 1 deletion Gemfile
@@ -1,6 +1,7 @@

source 'http://rubygems.org'

gem 'gibberish'
gem 'rails'

# Gems used only for assets and not required
Expand Down Expand Up @@ -28,7 +29,8 @@ gem 'stripe'

group :production do
gem 'thin'
ruby '1.9.3'
# ruby '1.9.3'
gem 'pg'
end

group :development do
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Expand Up @@ -93,6 +93,7 @@ GEM
railties (>= 3.0.0)
fakeweb (1.3.0)
ffi (1.1.5)
gibberish (1.2.0)
girl_friday (0.10.0)
connection_pool (~> 0.9.0)
haml (3.1.7)
Expand Down Expand Up @@ -167,6 +168,7 @@ GEM
activesupport (>= 3.0.0)
cocaine (>= 0.0.2)
mime-types
pg (0.14.1)
polyglot (0.3.3)
pry (0.9.10)
coderay (~> 1.0.5)
Expand Down Expand Up @@ -308,6 +310,7 @@ DEPENDENCIES
email_spec
factory_girl_rails
fakeweb
gibberish
haml
haml-rails
heroku
Expand All @@ -317,6 +320,7 @@ DEPENDENCIES
mongoid
mongoid-paperclip
mongoid-rspec
pg
pry
pry-nav
pry-rails
Expand Down
17 changes: 17 additions & 0 deletions app/assets/javascripts/validate.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 56 additions & 1 deletion app/controllers/leads_controller.rb
@@ -1,4 +1,6 @@
class LeadsController < ApplicationController
class LeadsController < ApplicationController
before_filter :authenticate_user!, :except => ['external_form']

def new
@lead = Lead.new
@lead_owner = User.all.map(&:email)
Expand Down Expand Up @@ -79,4 +81,57 @@ def convert_lead
redirect_to opportunity_path(@opportunity)
end

def new_web_lead
leads = Lead.new
minus_lead = ["_type","_id","created_at", "updated_at", "lead_source", "lead_status","lead_owner", "account_name","opportunity_name","opportunity_owner","assigned_to_id"]
lead = leads.attribute_names.to_a
@lead = lead-minus_lead
end

def create_web_lead
@in_lead = []
default_url = "http://demo.railscrm.com" #CHANGE THIS TO A VALID URL
default_fields = ["first_name","last_name", "email", "company", "phone"]
@params = params[:lead].split(' ')
@params.each do |param|
if params["#{param}"].to_i == 1
@in_lead << param
end
end
@redirect_url = params[:redirect_url]
if @in_lead.empty?
@in_lead = default_fields
end
@lead_owner = encrypt(current_user.email)
@redirect_url = params[:redirect_url].empty? ? default_url : params[:redirect_url]
render "web_form"
end

def external_form
email = decrypt(params[:lead_owner])
user = User.where(:email =>email).first
requestor = "#{request.protocol}#{request.fullpath}"
if user.nil?
redirect_to requestor
else
redirect_url = params[:redirect_url]
leads = params[:params].split(" ")
@lead = Lead.new
leads.each do |lead|
@lead.update_attribute("#{lead}", params["#{lead}"])
end
@lead.update_attributes(:lead_owner => email,:lead_source => requestor)
@lead.save
redirect_to redirect_url
end
end

private
def encrypt(data)
return encrypted_data = KEY.enc(data)
end

def decrypt(encrypted_data)
return data = KEY.dec(encrypted_data)
end
end
9 changes: 9 additions & 0 deletions app/views/leads/convert_form.html.haml
@@ -0,0 +1,9 @@
=form_tag "http://localhost:3000/generate" do
=hidden_field_tag :lead_owner, @lead_owner
=hidden_field_tag :params, @in_lead
=hidden_field_tag :redirect_url, @redirect_url
-for a in 0..@in_lead.size-1 do
=label_tag @in_lead[a]
=text_field_tag @in_lead[a]

=submit_tag "Generate Form", class: 'btn btn-primary'
2 changes: 1 addition & 1 deletion app/views/leads/index.html.haml
@@ -1,7 +1,7 @@
.well
.functions.pull-right
= link_to 'Create Lead', new_lead_path

= link_to 'Web-to-Lead', web_to_lead_path
%table.table.table-striped
%thead
%tr
Expand Down
32 changes: 32 additions & 0 deletions app/views/leads/new_web_lead.html.haml
@@ -0,0 +1,32 @@
.form.well
.label
%h2
New Web Form
%br
.span12.offset9
%br
.form-horizontal
=form_tag create_lead_path,:class => 'simple_form' do
%fieldset
%legend Lead Info
.row
.span4
%p
Redirect URL
=text_field_tag :redirect_url
%br
-for a in 0..@lead.size/2-1 do
=check_box_tag @lead[a]
=@lead[a]
%br
.span4
%br
%br
=hidden_field_tag :lead,@lead
-for b in @lead.size/2..@lead.size-1 do
=check_box_tag @lead[b]
=@lead[b]
%br
%br
= submit_tag "Generate Form", class: 'btn btn-primary'
= link_to 'Cancel', leads_path, class: "btn btn-danger"
5 changes: 5 additions & 0 deletions app/views/leads/web_form.html.haml
@@ -0,0 +1,5 @@
%h3 Web Form
Copy the form below and use it anywhere in your website.
=text_area_tag "web_form",(render file: 'leads/convert_form.html.haml'), readonly: true, style: "width:850px; height:400px"
%br
=link_to "Back", leads_path, class: 'btn btn-primary'
2 changes: 2 additions & 0 deletions config/environment.rb
@@ -1,5 +1,7 @@
# Load the rails application
require File.expand_path('../application', __FILE__)
require 'gibberish'

# Initialize the rails application
RebelFoundation::Application.initialize!
::KEY = Gibberish::AES.new("awerwrREWdfER1645")
10 changes: 1 addition & 9 deletions config/mongoid.yml
Expand Up @@ -19,12 +19,4 @@ test:
# mongodb://heroku_app7056684:i49vdi86vsoidg0sn5unrqkf54@ds037387-a.mongolab.com:37387/heroku_app7056684

production:
sessions:
default:
database: heroku_app7056684
username: heroku_app7056684
password: i49vdi86vsoidg0sn5unrqkf54
hosts:
- ds037387-a.mongolab.com:37387
options:
consistency: :strong
uri: <%= ENV['MONGOLAB_URI'] %>
4 changes: 4 additions & 0 deletions config/routes.rb
Expand Up @@ -8,6 +8,10 @@
match "signup" => "devise/registrations#new", :as => "signup"
end

match "web_to_lead" => "leads#new_web_lead", :as => "web_to_lead"
match "create_lead" => "leads#create_web_lead", :as => "create_lead"
match "generate" => "leads#external_form"

resources :organizations
resources :leads do
resources :notes
Expand Down
1 change: 1 addition & 0 deletions nbproject/private/private.properties
@@ -0,0 +1 @@
rails.servertype=[/Applications/NetBeans/glassfish-3.0.1/glassfish]deployer:gfv3ee6:localhost:4848
4 changes: 4 additions & 0 deletions nbproject/private/private.xml
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
</project-private>
Empty file added nbproject/private/rake-d.txt
Empty file.
3 changes: 3 additions & 0 deletions nbproject/project.properties
@@ -0,0 +1,3 @@
platform.active=default
rails.port=8080
source.encoding=UTF-8
9 changes: 9 additions & 0 deletions nbproject/project.xml
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.ruby.railsprojects</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/rails-project/1">
<name>railscrm</name>
</data>
</configuration>
</project>

0 comments on commit b1b5906

Please sign in to comment.