Browse files

Modelo no persistente Contract y modificaciones en login

  • Loading branch information...
1 parent e74f16c commit 63dec85fe414e236b95ef1c259d4a5bf0e8670e7 @martinvega committed Mar 20, 2012
View
3 Gemfile
@@ -12,6 +12,7 @@ gem 'validates_timeliness'
gem "dynamic_form", "~> 1.1.4"
gem "jquery_datepicker", "~> 0.3.2"
+
# Gems used only for assets and not required
# in production environments by default.
group :assets do
@@ -21,7 +22,7 @@ group :assets do
end
gem 'jquery-rails'
-
+gem "validatable", "~> 1.6.7"
# Use unicorn as the web server
# gem 'unicorn'
View
2 Gemfile.lock
@@ -106,6 +106,7 @@ GEM
uglifier (1.2.3)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
+ validatable (1.6.7)
validates_timeliness (3.0.8)
timeliness (~> 0.3.4)
will_paginate (3.0.2)
@@ -123,5 +124,6 @@ DEPENDENCIES
rails (= 3.1.0)
sass-rails (~> 3.1.0)
uglifier
+ validatable (~> 1.6.7)
validates_timeliness
will_paginate
View
3 app/assets/javascripts/contact.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3 app/assets/stylesheets/contact.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the contact controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
49 app/assets/stylesheets/scaffolds.css.scss
@@ -180,12 +180,6 @@ td {
padding: .3em .5em;
}
-textarea {
- font: inherit;
- height: 10em;
-}
-
-
th {
padding: .5em .5em;
text-align: left;
@@ -270,6 +264,47 @@ div#links {
}
}
+div#contract_form {
+ width: 41%;
+ margin: 1% auto;
+ padding: 1em 1em 2em 1em;
+ position: absolute;
+ top: 4em;
+ left: 27em;
+
+ background-color: #f6f6f6;
+ border: 2px solid $second-color;
+ padding: 1em;
+ -moz-border-radius: 15px 15px 15px 15px;
+ -webkit-border-radius: 15px 15px 15px 15px;
+ box-shadow: 8px 8px 25px black;
+ .field {
+ margin-left: auto;
+ margin-right: auto;
+ width: 70%;
+ }
+ img {
+ margin-left: 12.5em;
+ }
+ .field input {
+ width: 25em;
+ }
+ .field input[type="submit"]{
+ margin-left: 8em;
+ width: 10em;
+ padding: 0.5em;
+ background: #819FF7;
+ -moz-border-radius: 5px 5px 5px 5px;
+ -webkit-border-radius: 5px 5px 5px 5px;
+ @include transition(background, 0.7s);
+ }
+ .field input[type="submit"]:hover{
+ background: $second-color;
+ color: #ffffff;
+ }
+
+}
+
div#login_container {
div#contact {
@@ -333,7 +368,7 @@ div#login_container {
-moz-border-radius: 0px 0px 15px 15px;
-webkit-border-radius: 0px 0px 15px 15px;
box-shadow: 8px 8px 25px black;
- .field {
+ .field {
margin-left: auto;
margin-right: auto;
width: 70%;
View
29 app/controllers/contracts_controller.rb
@@ -0,0 +1,29 @@
+class ContractsController < ApplicationController
+ def new
+
+ @contract = Contract.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+
+ end
+ end
+
+ def send_contact
+
+ @contract = Contract.new(params)
+
+ respond_to do |format|
+ if @contract.valid?
+ ContractMailer.send_consultation(@contract).deliver
+ format.html {redirect_to login_users_path,
+ :notice => 'Su consulta ha sido enviada satisfactoriamente'
+ }
+ else
+ format.html { render :action => "new" }
+ format.json { render :json => @contract.errors, :status => :unprocessable_entity }
+ end
+ end
+
+ end
+end
View
20 app/models/contract.rb
@@ -0,0 +1,20 @@
+class Contract
+ include Validatable
+ attr_accessor :nombre, :dni, :email, :telefono, :interesado_en, :comentarios
+
+ validates_presence_of :nombre, :dni, :telefono, :email
+ validates_numericality_of :dni, :only_integer => true
+ validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
+ validates_length_of :nombre, :email, :telefono, :maximum => 30
+ validates_length_of :comentarios, :maximum => 255
+
+ def initialize(attributes = {})
+ self.nombre = attributes[:nombre]
+ self.dni = attributes[:dni]
+ self.telefono = attributes[:telefono]
+ self.interesado_en = attributes[:interesado_en]
+ self.email = attributes[:email]
+ self.comentarios = attributes[:comentarios]
+ end
+
+end
View
55 app/views/contracts/new.html.erb
@@ -0,0 +1,55 @@
+<% options = [] %>
+
+<% DIRECTV_OPTIONS.each do |dtv_option| %>
+ <% options << dtv_option %>
+<% end %>
+
+<%= form_tag :action => :send_contact do %>
+
+<div id="contract_form">
+ <% if @contract.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@contract.errors.count, "error") %> prohibited this contract from being saved:</h2>
+
+ <ul>
+ <% @contract.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+ <%= image_tag 'directvLogo.jpg', :size => "150x100",
+ :alt => "Multisat Digital" %>
+
+ <div class="field">
+ <%= label_tag 'Nombre completo' %><br />
+ <%= text_field_tag :nombre %>
+ </div>
+ <div class="field">
+ <%= label_tag 'DNI' %><br />
+ <%= text_field_tag :dni %>
+ </div>
+ <div class="field">
+ <%= label_tag 'E-mail' %><br />
+ <%= text_field_tag :email %>
+ </div>
+ <div class="field">
+ <%= label_tag 'Teléfono' %><br />
+ <%= text_field_tag :telefono %>
+ </div>
+ <div class="field">
+ <%= label_tag 'Interesado en (opcional)' %><br />
+ <%= select_tag :interesado_en , options_for_select(options), :prompt => 'Seleccione ..' %>
+ </div>
+ <div class="field">
+ <%= label_tag 'Comentarios (opcional)' %><br />
+ <%= text_area_tag :comentarios, nil, :rows => 5, :cols => 40 %>
+ </div>
+
+ <div class="field">
+ <%= submit_tag 'Enviar' %>
+ </div>
+
+</div>
+
+<% end %>
View
20 app/views/users/contract_now.html.erb
@@ -1,20 +0,0 @@
-<div id="contract_form">
- <div class="field">
- <%= f.label 'INTRANET' %>
- <%= image_tag 'directvLogo.jpg', :size => "150x100",
- :alt => "Multisat Digital" %>
- </div>
- <div class="field">
- <%= f.label 'Usuario' %><br />
- <%= f.text_field :user, :maxlength => 18, :autofocus => true %>
- </div>
- <div class="field">
- <%= f.label 'Contraseña' %><br />
- <%= f.password_field :password, :maxlength => 18 %>
- </div>
-
- <div class="field">
- <span><%= f.submit "Ingresar" %></span>
- </div>
- <% end %>
- </div>
View
2 app/views/users/login.html.erb
@@ -4,7 +4,7 @@
<%= image_tag 'directvLogo.jpg', :size => '230x180', :alt => 'Directv logo' %>
</div>
<div id="contract_now">
- <%= link_to 'Contrátalo ahora', :action => :contract_now, :controller => :users %>
+ <%= link_to 'Contrátalo ahora', new_contract_path %>
</div>
<div id="phone">
<%= image_tag 'consultas.png', :size => '200x30', :alt => 'Consultas al 4225341' %>
View
9 config/routes.rb
@@ -1,4 +1,6 @@
Dtv::Application.routes.draw do
+ get "contact/index"
+
resources :contacts do
collection do
get :import_csv
@@ -7,11 +9,18 @@
end
resources :campaigns
+
+ resources :contracts do
+ collection do
+ post :send_contact
+ end
+ end
resources :users do
collection do
get :login
post :create_session
+ get :contract_now
end
member do
View
9 test/functional/contact_controller_test.rb
@@ -0,0 +1,9 @@
+require 'test_helper'
+
+class ContactControllerTest < ActionController::TestCase
+ test "should get index" do
+ get :index
+ assert_response :success
+ end
+
+end
View
7 test/functional/contract_mailer_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class ContractMailerTest < ActionMailer::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
View
4 test/unit/helpers/contact_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class ContactHelperTest < ActionView::TestCase
+end

0 comments on commit 63dec85

Please sign in to comment.