Skip to content

Commit

Permalink
campos de dinheiro, mini lib pra autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
nofxx committed Apr 19, 2009
1 parent 2d28545 commit 022e294
Show file tree
Hide file tree
Showing 11 changed files with 358 additions and 195 deletions.
9 changes: 1 addition & 8 deletions app/models/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Person < ActiveRecord::Base

has_money :revenue
has_permalink :name
autocomplete :dad, :mom, :spouse

symbolize :blood, :in => [:"A+", :"A-", :"O+", :"O-", :"B+", :"B-", :"AB+", :"AB-"], :i18n => false
symbolize :marital, :in => [:unknown, :single, :divorced, :married, :widowed, :common_law]
Expand Down Expand Up @@ -77,14 +78,6 @@ def calc_age
write_attribute(:age, (Time.now - born_at)/60/60/24/360)
end

def mom_text
mom.name if mom
end

def mom_text=(v)
@mom_text = v
end

def self.search(filter, page)
paginate :per_page => 20, :page => page,
:conditions => ['name like ?', "%#{filter}%"],
Expand Down
19 changes: 10 additions & 9 deletions app/views/people/_person.html.haml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
- content_for :head do
= javascript_include_tag "jquery/ui.datepicker", "jquery/jquery.template"
= javascript_include_tag "jquery/jquery.autocomplete.min", "app/person"
= javascript_include_tag "jquery/ui.datepicker", "jquery/jquery.template", "jquery/jquery.price"
= javascript_include_tag "jquery/jquery.autocomplete.min", "app/person", "app/forms"

- semantic_form_for(@person, :html => { :class => "form" }) do |f|
.columns
.column.left
= f.input :name, :input_html => { :size => 40 }
= f.input :sex, :as => :radio, :collection => Person.get_sex_values
= f.input :marital, :as => :radio, :collection => Person.get_marital_values
= f.input :born_at, :as => :string, :input_html => { :size => 15 }
= f.input :born_at, :as => :string, :input_html => { :size => 15, :class => "calendar" }
= f.input :birthplace_id, :as => :string
- f.inputs :name => "Residencia", :id => "basic" do
= f.input :arrival_at, :as => :string, :input_html => { :size => 10, :id => "calendar" }
= f.input :leave_at, :as => :string, :input_html => { :size => 10, :id => "calendar" }
= f.input :arrival_at, :as => :string, :input_html => { :size => 10, :class => "calendar" }
= f.input :leave_at, :as => :string, :input_html => { :size => 10, :class => "calendar" }
- f.inputs :name => "Documentos", :id => "documents" do
= f.render_associated_form @person.documents, :partial => "documents/document"
= f.add_associated_link "+ Novo documento", :documents, :partial => "documents/document"
Expand All @@ -21,8 +21,10 @@
- f.inputs :name => "Pessoal", :id => "basic" do
= f.input :mom_text, :as => :string
= f.hidden_field :mom_id
=# f.input :dad, :as => :string
=# f.input :spouse, :as => :string
= f.input :dad_text, :as => :string
= f.hidden_field :dad_id
= f.input :spouse_text, :as => :string
= f.hidden_field :spouse_id
= f.input :prefix, :as => :select, :collection => %w{Sr Sra}
= f.input :blood, :as => :select, :collection => Person.get_blood_values
= f.input :race, :as => :select, :collection => Person.get_race_values
Expand All @@ -31,13 +33,12 @@
- f.inputs :name => "Profissional", :id => "basic" do
= f.input :profession, :label => "Profissao"
= f.input :profession_state, :as => :select, :collection => Person.get_profession_state_values
= f.input :revenue
= f.input :revenue, :input_html => { :class => "money" }

//- f.semantic_fields_for :contact do |con|
- f.inputs :name => "Contatos", :id => "contacts" do
= f.render_associated_form @person.contacts, :partial => "contacts/contact"
= f.add_associated_link "+ Novo contato", :contacts, :partial => "contacts/contact"
//= con.input :value, :as => :string, :input_html => { :size => 10, :id => "calendar" }

.clear
.navform
Expand Down
3 changes: 2 additions & 1 deletion app/views/people/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
.column.left
%h3= @person.name
= show @person, :sex_text, :state_text, :arrival_at, :profession_state_text
= show @person, :profession, :income, :revenue, :marital_text, :born_at, :blood
= show @person, :profession, :marital_text, :born_at, :blood
= @person.revenue.format
.column.right
%b Mae:
= @person.mom.try(:name)
Expand Down
1 change: 1 addition & 0 deletions config/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@
WillPaginate::ViewHelpers.pagination_options[:previous_label] = "&laquo; Anterior"
WillPaginate::ViewHelpers.pagination_options[:next_label] = "Próximo &raquo;"
GeoRuby::SimpleFeatures.const_set :DEFAULT_SRID, 4326
ActiveRecord::Base.send :include, Autocomplete
28 changes: 28 additions & 0 deletions lib/autocomplete.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module Autocomplete

def self.included(base)
base.extend ClassMethods
end

module ClassMethods

def autocomplete(*fields)
for field in fields
self.class_eval <<-CLASS_METHODS
def #{field}_text
#{field}.try(:name)
end
def #{field}_text=(value)
@#{field}_text = value
end
CLASS_METHODS
end

end

end

end
Binary file added public/images/bigicons/avatar.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
167 changes: 26 additions & 141 deletions public/javascripts/app/forms.js
Original file line number Diff line number Diff line change
@@ -1,141 +1,26 @@

function Telefone(campo)
{
qtdcaracteres = (campo.value).length;

if(qtdcaracteres == 0)
campo.value = "(";

if(qtdcaracteres == 3)
campo.value = campo.value + ")";

if(qtdcaracteres == 8)
campo.value = campo.value + "-";

}
// Fim da fun��o telefone

// Formatar o cep
function Cep(campo)
{
qtdcaracteres = (campo.value).length;

if(qtdcaracteres == 2)
campo.value = campo.value + ".";

if(qtdcaracteres ==6)
campo.value = campo.value + "-";
}
// Fim da fun��o cep

// Formatar cgc
function Cgc(campo)
{
qtdcaracteres = (campo.value).length;

if(qtdcaracteres == 2)
campo.value = campo.value + ".";

if(qtdcaracteres == 6)
campo.value = campo.value + ".";

if(qtdcaracteres == 10)
campo.value = campo.value + "/";

if(qtdcaracteres == 15)
campo.value = campo.value + "-";

}
// Fim da fun��o cgc

// Fun��o caixa alta
function upper(campo)
{
campo.value = campo.value.toUpperCase();
}

// Formatar data
function Data(campo)
{
qtdcaracteres = (campo.value).length;

if(qtdcaracteres == 2)
campo.value = campo.value + "/";

if(qtdcaracteres ==5)
campo.value = campo.value + "/";
}
// Fim da fun��o cep

// Fun��o placa
function Placa(campo)
{
qtdcaracteres = (campo.value).length;

if(qtdcaracteres == 3)
campo.value = campo.value + "-";
}
// Fim da fun��o placa
// Função sip
function Sip(campo)
{
qtdcaracteres = (campo.value).length;

if(qtdcaracteres == 1)
campo.value = campo.value + ".";

if(qtdcaracteres == 5)
campo.value = campo.value + ".";

if(qtdcaracteres == 9)
campo.value = campo.value + "-";


}
// Fim da fun��o placa

// Fim da fun��o placa
// Função sip
function Cpf(campo)
{
qtdcaracteres = (campo.value).length;

if(qtdcaracteres == 3)
campo.value = campo.value + ".";

if(qtdcaracteres == 7)
campo.value = campo.value + ".";

if(qtdcaracteres == 11)
campo.value = campo.value + "-";

}
// Fim da função cpf
$(document).ready(function () {

// abas
// Ocultando as abas
$$('.contaba').invoke ('hide');
// Mostra somente a primeira aba
$$('.contaba').first ().show ();
// seta a primeira aba como selecionada (na lista de abas)
$$('#abas a').first ().addClassName ('active');
// Quando clicar no link de uma aba
$$('#abas a').each (function (e){
Event.observe (e, 'click', function (e){
// Oculta todas as abas
$$('div.contaba').invoke ('hide');
// tira a seleção da aba atual
$$('#abas a').invoke ('removeClassName', 'active');
// adiciona a classe selected na selecionada atualmente
Event.element (e).addClassName ('active');
// Mostra a aba clicada
var tab = $$(Event.element (e).getAttribute ('href'));

(tab[0]).show ();
// pra nao ir para o link
Event.stop (e);

}); // Fim do Event.observe
}); // Fim do each
});
// Limpa os campos de busca
$.fn.clearClick = function() {
return this.focus(function() {
if( this.value == this.defaultValue ) {
this.value = "";
}
}).blur(function() {
if( !this.value.length ) {
this.value = this.defaultValue;
}
});
};

/**
* Set grid table in list
*/
$(document).ready(function () {

$("#search").clearClick();
$(".calendar").datepicker();
$(".money").priceFormat({
prefix: '',
centsSeparator: ',',
thousandsSeparator: '.'
});
});
Loading

0 comments on commit 022e294

Please sign in to comment.