diff --git a/app/models/person.rb b/app/models/person.rb index 574fc70..f4cc532 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -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] @@ -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}%"], diff --git a/app/views/people/_person.html.haml b/app/views/people/_person.html.haml index c09273d..f77b8e0 100644 --- a/app/views/people/_person.html.haml +++ b/app/views/people/_person.html.haml @@ -1,6 +1,6 @@ - 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 @@ -8,11 +8,11 @@ = 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" @@ -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 @@ -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 diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index 3bbcb12..d7a7f2f 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -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) diff --git a/config/environment.rb b/config/environment.rb index f29dd11..14c23e4 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -49,3 +49,4 @@ WillPaginate::ViewHelpers.pagination_options[:previous_label] = "« Anterior" WillPaginate::ViewHelpers.pagination_options[:next_label] = "Próximo »" GeoRuby::SimpleFeatures.const_set :DEFAULT_SRID, 4326 +ActiveRecord::Base.send :include, Autocomplete diff --git a/lib/autocomplete.rb b/lib/autocomplete.rb new file mode 100644 index 0000000..50182e5 --- /dev/null +++ b/lib/autocomplete.rb @@ -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 diff --git a/public/images/bigicons/avatar.gif b/public/images/bigicons/avatar.gif new file mode 100644 index 0000000..0bdb4cd Binary files /dev/null and b/public/images/bigicons/avatar.gif differ diff --git a/public/javascripts/app/forms.js b/public/javascripts/app/forms.js index 2578b8c..b6e467e 100644 --- a/public/javascripts/app/forms.js +++ b/public/javascripts/app/forms.js @@ -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 -}); \ No newline at end of file + // 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: '.' +}); + }); diff --git a/public/javascripts/app/formsold.js b/public/javascripts/app/formsold.js new file mode 100644 index 0000000..2578b8c --- /dev/null +++ b/public/javascripts/app/formsold.js @@ -0,0 +1,141 @@ + +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 +}); \ No newline at end of file diff --git a/public/javascripts/app/person.js b/public/javascripts/app/person.js index efa47cd..cecd2c8 100644 --- a/public/javascripts/app/person.js +++ b/public/javascripts/app/person.js @@ -5,42 +5,12 @@ $(document).ready(function() { $("#person_mom_id").val(data[1]); }); + $("#person_dad_text").autocomplete("/people.json", { extraParams: { sex: true } }) + .result(function (evt, data, formatted) { + $("#person_mom_id").val(data[1]); + }); -// $("#person_mom_text").autocomplete({ -// correction: 0, -// ajax_get : function(key, cont) { -// var script_name = '/people.json' -// var params = { nome : key } - -// $.get(script_name, params, function(obj){ -// // obj is just array of strings -// var res = []; -// obj = obj.results; -// for(var i=0;i +* original keydown event attachment by Kaihua Qi +* keydown fixes by Thasmo + +*/ + +(function($) { + + $.fn.priceFormat = function(options) { + + var defaults = { + prefix: 'US$ ', + centsSeparator: '.', + thousandsSeparator: ',', + limit: false, + centsLimit: 2 + }; + + var options = $.extend(defaults, options); + + return this.each(function() { + + // pre defined options + var obj = $(this); + var is_number = /[0-9]/; + + // load the pluggings settings + var prefix = options.prefix; + var centsSeparator = options.centsSeparator; + var thousandsSeparator = options.thousandsSeparator; + var limit = options.limit; + var centsLimit = options.centsLimit; + + // skip everything that isn't a number + // and also skip the left zeroes + function to_numbers (str) { + var formatted = ''; + for (var i=0;i<(str.length);i++) { + char = str.charAt(i); + if (formatted.length==0 && char==0) char = false; + if (char && char.match(is_number)) { + if (limit) { + if (formatted.length < limit) formatted = formatted+char; + }else{ + formatted = formatted+char; + } + } + } + return formatted; + } + + // format to fill with zeros to complete cents chars + function fill_with_zeroes (str) { + while (str.length<(centsLimit+1)) str = '0'+str; + return str; + } + + // format as price + function price_format (str) { + + // formatting settings + var formatted = fill_with_zeroes(to_numbers(str)); + var thousandsFormatted = ''; + var thousandsCount = 0; + + // split integer from cents + var centsVal = formatted.substr(formatted.length-centsLimit,centsLimit); + var integerVal = formatted.substr(0,formatted.length-centsLimit); + + // apply cents pontuation + formatted = integerVal+centsSeparator+centsVal; + + // apply thousands pontuation + if (thousandsSeparator) { + for (var j=integerVal.length;j>0;j--) { + char = integerVal.substr(j-1,1); + thousandsCount++; + if (thousandsCount%3==0) char = thousandsSeparator+char; + thousandsFormatted = char+thousandsFormatted; + } + if (thousandsFormatted.substr(0,1)==thousandsSeparator) thousandsFormatted = thousandsFormatted.substring(1,thousandsFormatted.length); + formatted = thousandsFormatted+centsSeparator+centsVal; + } + + // apply the prefix + if (prefix) formatted = prefix+formatted; + + return formatted; + + } + + // filter what user type (only numbers and functional keys) + function key_check (e) { + + var code = (e.keyCode ? e.keyCode : e.which); + var typed = String.fromCharCode(code); + var functional = false; + var str = obj.val(); + var newValue = price_format(str+typed); + + // allow keypad numbers, 0 to 9 + if(code >= 96 && code <= 105) functional = true; + + // check Backspace, Tab, Enter, and left/right arrows + if (code == 8) functional = true; + if (code == 9) functional = true; + if (code == 13) functional = true; + if (code == 37) functional = true; + if (code == 39) functional = true; + + if (!functional) { + e.preventDefault(); + e.stopPropagation(); + if (str!=newValue) obj.val(newValue); + } + + } + + // inster formatted price as a value of an input field + function price_it () { + var str = obj.val(); + var price = price_format(str); + if (str != price) obj.val(price); + } + + // bind the actions + $(this).bind('keydown', key_check); + $(this).bind('keyup', price_it); + if ($(this).val().length>0) price_it(); + + }); + + }; + +})(jQuery); \ No newline at end of file