@@ -18,6 +18,8 @@ function attachHandler(jQuery) {
|
||
| 18 | 18 |
|
| 19 | 19 |
$('.popup').popover('toogle')
|
| 20 | 20 |
|
| 21 |
+ // Newsletter Subscription AJAX |
|
| 22 |
+ |
|
| 21 | 23 |
$('.new_subscription').submit(function() {
|
| 22 | 24 |
var valuesToSubmit = $(this).serialize(); |
| 23 | 25 |
$.ajax({
|
@@ -27,7 +29,7 @@ function attachHandler(jQuery) {
|
||
| 27 | 29 |
dataType: "json", |
| 28 | 30 |
async: true, |
| 29 | 31 |
error: function(request, textStatus, errorThrown){
|
| 30 |
- msg = '<div class="alert alert-error span5 subscribe-alert"><h4>' + request.status + " " + errorThrown + '</h4></div>' |
|
| 32 |
+ msg = '<div class="alert alert-error span5 subscribe-alert"><h4>' + request.status + " " + errorThrown + '</h4><br>' + request.responseText + '</div>' |
|
| 31 | 33 |
$('.new_subscription').html(msg);
|
| 32 | 34 |
}, |
| 33 | 35 |
success: function(data){
|
@@ -38,7 +40,7 @@ function attachHandler(jQuery) {
|
||
| 38 | 40 |
$('.new_subscription').html(msg);
|
| 39 | 41 |
break; |
| 40 | 42 |
case 'error': |
| 41 |
- msg = '<div class="alert alert-success subscribe-alert"><h4>' + data.error + '</h4></div>'; |
|
| 43 |
+ msg = '<div class="alert alert-error subscribe-alert"><h4>' + data.failure + '</h4></div>'; |
|
| 42 | 44 |
$('.new_subscription').html(msg);
|
| 43 | 45 |
break; |
| 44 | 46 |
case 'invalid': |
@@ -4,6 +4,8 @@ class SubscriptionController < ApplicationController |
||
| 4 | 4 |
|
| 5 | 5 |
def create |
| 6 | 6 |
@subscription = Subscription.new(subscription_params) |
| 7 |
+ @subscription.language = cookies[:avalanche_locale] |
|
| 8 |
+ @subscription.check_if_registered_user |
|
| 7 | 9 |
@subscribe_status = 'error' |
| 8 | 10 |
respond_to do |format| |
| 9 | 11 |
if Subscription.find_by_email(@subscription.email) == nil && @subscription.valid? |
@@ -8,6 +8,8 @@ class Subscription < ActiveRecord::Base |
||
| 8 | 8 |
track_analytics |
| 9 | 9 |
end |
| 10 | 10 |
|
| 11 |
+ # Methods |
|
| 12 |
+ |
|
| 11 | 13 |
def full_name |
| 12 | 14 |
return self.first_name.to_s + " " + self.last_name.to_s |
| 13 | 15 |
end |
@@ -21,6 +23,17 @@ class Subscription < ActiveRecord::Base |
||
| 21 | 23 |
end |
| 22 | 24 |
end |
| 23 | 25 |
|
| 26 |
+ def check_if_registered_user |
|
| 27 |
+ user = User.find_by_email(self.email) |
|
| 28 |
+ if user != nil |
|
| 29 |
+ self.registered_user = true |
|
| 30 |
+ else |
|
| 31 |
+ self.registered_user = false |
|
| 32 |
+ end |
|
| 33 |
+ end |
|
| 34 |
+ |
|
| 35 |
+ # After Create |
|
| 36 |
+ |
|
| 24 | 37 |
def subscribe_to_mailchimp |
| 25 | 38 |
Resque.enqueue(SubscribeToMailchimp, self.id) |
| 26 | 39 |
end |
@@ -15,6 +15,8 @@ |
||
| 15 | 15 |
<tr> |
| 16 | 16 |
<th>Name</th> |
| 17 | 17 |
<th>Email</th> |
| 18 |
+ <th>User</th> |
|
| 19 |
+ <th>Language</th> |
|
| 18 | 20 |
<th>Registered</th> |
| 19 | 21 |
</tr> |
| 20 | 22 |
</thead> |
@@ -23,6 +25,8 @@ |
||
| 23 | 25 |
<tr> |
| 24 | 26 |
<td><%= subscription.full_name %></td> |
| 25 | 27 |
<td><%= subscription.email %></td> |
| 28 |
+ <td><%= subscription.registered_user %></td> |
|
| 29 |
+ <td><%= subscription.language %></td> |
|
| 26 | 30 |
<td><%= time_ago_in_words(subscription.created_at) %></td> |
| 27 | 31 |
</tr> |
| 28 | 32 |
<% end %> |
@@ -52,7 +52,11 @@ |
||
| 52 | 52 |
|
| 53 | 53 |
</div> |
| 54 | 54 |
<div class="span6"> |
| 55 |
- <%= image_tag "fluxogram_avalanche.jpg", style: 'width: 100%;' %> |
|
| 55 |
+ <% if cookies[:avalanche_locale] == 'en' %> |
|
| 56 |
+ <%= image_tag "fluxogram_avalanche@en.jpg", style: 'width: 100%;' %> |
|
| 57 |
+ <% else %> |
|
| 58 |
+ <%= image_tag "fluxogram_avalanche@pt-BR.jpg", style: 'width: 100%;' %> |
|
| 59 |
+ <% end %> |
|
| 56 | 60 |
</div> |
| 57 | 61 |
|
| 58 | 62 |
</div> |
@@ -5,12 +5,28 @@ class SubscribeToMailchimp |
||
| 5 | 5 |
|
| 6 | 6 |
# Get User |
| 7 | 7 |
subscription = Subscription.find_by_id(id) |
| 8 |
+ |
|
| 9 |
+ if subscription.language == 'pt-BR' |
|
| 10 |
+ lang = 'pt' |
|
| 11 |
+ else |
|
| 12 |
+ lang = subscription.language |
|
| 13 |
+ end |
|
| 14 |
+ |
|
| 15 |
+ merge_vars = {
|
|
| 16 |
+ 'FNAME'=> subscription.first_name, |
|
| 17 |
+ 'LNAME'=> subscription.last_name, |
|
| 18 |
+ 'MC_LANGUAGE' => lang, |
|
| 19 |
+ 'MERGE3'=> subscription.registered_user.to_s |
|
| 20 |
+ |
|
| 21 |
+ } |
|
| 8 | 22 |
|
| 9 | 23 |
return true if (Rails.env.test?) |
| 10 | 24 |
list_id = ENV['MAILCHIMP_LIST_ID'] |
| 11 | 25 |
response = Rails.configuration.mailchimp.lists.subscribe({
|
| 12 | 26 |
id: list_id, |
| 13 |
- email: {email: subscription.email},
|
|
| 27 |
+ email_address: subscription.email, |
|
| 28 |
+ merge_vars: merge_vars, |
|
| 29 |
+ update_existing: true, |
|
| 14 | 30 |
double_optin: false |
| 15 | 31 |
}) |
| 16 | 32 |
|
@@ -0,0 +1,6 @@ |
||
| 1 |
+class AddLangToSubscription < ActiveRecord::Migration |
|
| 2 |
+ def change |
|
| 3 |
+ add_column :subscriptions, :language, :string |
|
| 4 |
+ add_column :subscriptions, :registered_user, :boolean |
|
| 5 |
+ end |
|
| 6 |
+end |
@@ -11,11 +11,24 @@ |
||
| 11 | 11 |
# |
| 12 | 12 |
# It's strongly recommended that you check this file into your version control system. |
| 13 | 13 |
|
| 14 |
-ActiveRecord::Schema.define(version: 20150110020743) do |
|
| 14 |
+ActiveRecord::Schema.define(version: 20150129033808) do |
|
| 15 | 15 |
|
| 16 | 16 |
# These are extensions that must be enabled in order to support this database |
| 17 | 17 |
enable_extension "plpgsql" |
| 18 | 18 |
|
| 19 |
+ create_table "agent_steps", force: true do |t| |
|
| 20 |
+ t.integer "mission_agent_id" |
|
| 21 |
+ t.integer "step" |
|
| 22 |
+ t.string "title" |
|
| 23 |
+ t.text "description" |
|
| 24 |
+ t.boolean "completed" |
|
| 25 |
+ t.datetime "completed_date" |
|
| 26 |
+ t.datetime "created_at" |
|
| 27 |
+ t.datetime "updated_at" |
|
| 28 |
+ end |
|
| 29 |
+ |
|
| 30 |
+ add_index "agent_steps", ["mission_agent_id"], name: "index_agent_steps_on_mission_agent_id", using: :btree |
|
| 31 |
+ |
|
| 19 | 32 |
create_table "blog_posts", force: true do |t| |
| 20 | 33 |
t.string "title" |
| 21 | 34 |
t.string "slug" |
@@ -73,12 +86,87 @@ ActiveRecord::Schema.define(version: 20150110020743) do |
||
| 73 | 86 |
t.string "server_email" |
| 74 | 87 |
end |
| 75 | 88 |
|
| 89 |
+ create_table "mission_agents", force: true do |t| |
|
| 90 |
+ t.integer "mission_id" |
|
| 91 |
+ t.integer "agent_steps_id" |
|
| 92 |
+ t.integer "mission_candidates_id" |
|
| 93 |
+ t.string "objective" |
|
| 94 |
+ t.text "briefing" |
|
| 95 |
+ t.string "role" |
|
| 96 |
+ t.text "description" |
|
| 97 |
+ t.integer "user_id" |
|
| 98 |
+ t.integer "agent_number" |
|
| 99 |
+ t.text "debriefing" |
|
| 100 |
+ t.datetime "created_at" |
|
| 101 |
+ t.datetime "updated_at" |
|
| 102 |
+ end |
|
| 103 |
+ |
|
| 104 |
+ add_index "mission_agents", ["agent_steps_id"], name: "index_mission_agents_on_agent_steps_id", using: :btree |
|
| 105 |
+ add_index "mission_agents", ["mission_candidates_id"], name: "index_mission_agents_on_mission_candidates_id", using: :btree |
|
| 106 |
+ add_index "mission_agents", ["mission_id"], name: "index_mission_agents_on_mission_id", using: :btree |
|
| 107 |
+ add_index "mission_agents", ["user_id"], name: "index_mission_agents_on_user_id", using: :btree |
|
| 108 |
+ |
|
| 109 |
+ create_table "mission_candidates", force: true do |t| |
|
| 110 |
+ t.integer "user_id" |
|
| 111 |
+ t.integer "mission_agent_id" |
|
| 112 |
+ t.integer "status" |
|
| 113 |
+ t.string "mode" |
|
| 114 |
+ t.datetime "created_at" |
|
| 115 |
+ t.datetime "updated_at" |
|
| 116 |
+ end |
|
| 117 |
+ |
|
| 118 |
+ add_index "mission_candidates", ["mission_agent_id"], name: "index_mission_candidates_on_mission_agent_id", using: :btree |
|
| 119 |
+ add_index "mission_candidates", ["user_id"], name: "index_mission_candidates_on_user_id", using: :btree |
|
| 120 |
+ |
|
| 121 |
+ create_table "missions", force: true do |t| |
|
| 122 |
+ t.integer "mission_agents_id" |
|
| 123 |
+ t.string "title" |
|
| 124 |
+ t.string "objective" |
|
| 125 |
+ t.text "briefing" |
|
| 126 |
+ t.integer "owner_id" |
|
| 127 |
+ t.integer "status" |
|
| 128 |
+ t.boolean "launched" |
|
| 129 |
+ t.string "language" |
|
| 130 |
+ t.string "cover_img" |
|
| 131 |
+ t.datetime "created_at" |
|
| 132 |
+ t.datetime "updated_at" |
|
| 133 |
+ end |
|
| 134 |
+ |
|
| 135 |
+ add_index "missions", ["mission_agents_id"], name: "index_missions_on_mission_agents_id", using: :btree |
|
| 136 |
+ add_index "missions", ["owner_id"], name: "index_missions_on_owner_id", using: :btree |
|
| 137 |
+ |
|
| 138 |
+ create_table "step_validations", force: true do |t| |
|
| 139 |
+ t.integer "agent_step_id" |
|
| 140 |
+ t.integer "step_verifications_id" |
|
| 141 |
+ t.string "mode" |
|
| 142 |
+ t.string "description" |
|
| 143 |
+ t.datetime "created_at" |
|
| 144 |
+ t.datetime "updated_at" |
|
| 145 |
+ end |
|
| 146 |
+ |
|
| 147 |
+ add_index "step_validations", ["agent_step_id"], name: "index_step_validations_on_agent_step_id", using: :btree |
|
| 148 |
+ add_index "step_validations", ["step_verifications_id"], name: "index_step_validations_on_step_verifications_id", using: :btree |
|
| 149 |
+ |
|
| 150 |
+ create_table "step_verifications", force: true do |t| |
|
| 151 |
+ t.integer "step_validation_id" |
|
| 152 |
+ t.boolean "validated" |
|
| 153 |
+ t.integer "validated_by_id" |
|
| 154 |
+ t.string "content" |
|
| 155 |
+ t.datetime "created_at" |
|
| 156 |
+ t.datetime "updated_at" |
|
| 157 |
+ end |
|
| 158 |
+ |
|
| 159 |
+ add_index "step_verifications", ["step_validation_id"], name: "index_step_verifications_on_step_validation_id", using: :btree |
|
| 160 |
+ add_index "step_verifications", ["validated_by_id"], name: "index_step_verifications_on_validated_by_id", using: :btree |
|
| 161 |
+ |
|
| 76 | 162 |
create_table "subscriptions", force: true do |t| |
| 77 | 163 |
t.string "first_name" |
| 78 | 164 |
t.string "last_name" |
| 79 | 165 |
t.string "email" |
| 80 | 166 |
t.datetime "created_at" |
| 81 | 167 |
t.datetime "updated_at" |
| 168 |
+ t.string "language" |
|
| 169 |
+ t.boolean "registered_user" |
|
| 82 | 170 |
end |
| 83 | 171 |
|
| 84 | 172 |
create_table "uploads", force: true do |t| |