flexa_lib 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +45 -0
- data/README.txt +18 -0
- data/lib/flexa_lib/brcpfcnpj/cnpj.rb +46 -0
- data/lib/flexa_lib/brcpfcnpj/cnpj_validator.rb +6 -0
- data/lib/flexa_lib/brcpfcnpj/cpf.rb +52 -0
- data/lib/flexa_lib/brcpfcnpj/cpf_cnpj.rb +90 -0
- data/lib/flexa_lib/brcpfcnpj/cpf_cnpj_activerecord.rb +61 -0
- data/lib/flexa_lib/brcpfcnpj/cpf_validator.rb +6 -0
- data/lib/flexa_lib/brcpfcnpj/version.rb +10 -0
- data/lib/flexa_lib/brcpfcnpj.rb +14 -0
- data/lib/flexa_lib/engine.rb +5 -0
- data/lib/flexa_lib/helpers/button_grid_helpers.rb +43 -0
- data/lib/flexa_lib/helpers/button_helpers.rb +58 -0
- data/lib/flexa_lib/helpers/link_helpers.rb +12 -0
- data/lib/flexa_lib/helpers/lookup_helpers.rb +21 -0
- data/lib/flexa_lib/helpers/other_helpers.rb +66 -0
- data/lib/flexa_lib/helpers/paginate_helpers.rb +43 -0
- data/lib/flexa_lib/helpers/tab_helpers.rb +39 -0
- data/lib/flexa_lib/helpers/table_helpers.rb +33 -0
- data/lib/flexa_lib/helpers.rb +28 -0
- data/lib/flexa_lib/inputs/date_picker_input.rb +36 -0
- data/lib/flexa_lib/inputs/lookup_input.rb +51 -0
- data/lib/flexa_lib/inputs.rb +8 -0
- data/lib/flexa_lib/version.rb +8 -0
- data/lib/flexa_lib.rb +47 -0
- data/lib/generators/flexa_lib/crud/flexa_generator.rb +139 -0
- data/lib/generators/flexa_lib/lookup/lookup_generator.rb +21 -0
- data/lib/generators/flexa_lib/lookup/lookup_generator_test.rb +11 -0
- data/lib/generators/flexa_lib/lookup/templates/lookup_controller.rb +19 -0
- metadata +267 -0
data/LICENSE
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
Copyright (c) 2012 FlexaIT Team
|
2
|
+
www.flexait.com.br
|
3
|
+
http://github.com/flexait
|
4
|
+
|
5
|
+
--------------------------------- EN ------------------------------------
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
a copy of this software and associated documentation files (the
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
--------------------------------- pt-BR ------------------------------------
|
28
|
+
A permissão é concedida, a título gratuito, para qualquer pessoa que obtenha
|
29
|
+
uma cópia deste software e arquivos de documentação associados (o
|
30
|
+
"Software"), para lidar com o Software sem restrição, incluindo
|
31
|
+
sem limitação, os direitos para usar, copiar, modificar, mesclar, publicar,
|
32
|
+
distribuir, sublicenciar, e / ou vender cópias do Software, e para
|
33
|
+
permitir a pessoas a quem o Software é fornecido façam isso, sujeitas a
|
34
|
+
as seguintes condições:
|
35
|
+
|
36
|
+
O aviso de copyright acima e este aviso de permissão devem ser
|
37
|
+
incluído em todas as cópias ou partes substanciais do Software.
|
38
|
+
|
39
|
+
O SOFTWARE É FORNECIDO "COMO ESTÁ", SEM GARANTIA DE QUALQUER TIPO,
|
40
|
+
EXPRESSA OU IMPLÍCITA, INCLUINDO, MAS NÃO LIMITADO ÀS GARANTIAS DE
|
41
|
+
ADEQUAÇÃO COMERCIALIZAÇÃO, PARA UMA FINALIDADE ESPECÍFICA E
|
42
|
+
LEGALIDADE. EM NENHUM CASO OS AUTORES OU TITULARES DE DIREITOS AUTORAIS BE
|
43
|
+
RESPONSÁVEL POR QUALQUER RECLAMAÇÃO, DANOS OU RESPONSABILIDADE, SEJA EM UMA AÇÃO
|
44
|
+
DE CONTRATO, OU DE OUTRA FORMA, DECORRENTES DE, OU EM CONEXÃO
|
45
|
+
COM O SOFTWARE OU O USO OU OUTROS NO SOFTWARE.
|
data/README.txt
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
===== No arquivo application.js
|
4
|
+
Deixar dessa forma:
|
5
|
+
|
6
|
+
//= require jquery
|
7
|
+
//= require jquery_ujs
|
8
|
+
//= require flexa
|
9
|
+
|
10
|
+
===== No arquivo application.css
|
11
|
+
Deixar dessa forma:
|
12
|
+
|
13
|
+
/*
|
14
|
+
*= require_self
|
15
|
+
*= require flexa
|
16
|
+
*/
|
17
|
+
|
18
|
+
##
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
# Representa um numero de CNPJ. Objetos da classe Cnpj recebem strings representando numeros de cnpj e verificam a validade destes numeros usando dois criterios:
|
3
|
+
# 1. O formato da string, que deve seguir o padrao xx.xxx.xxx/xxxx-xx, onde 'x' pode ser qualquer digito de 0 a 9 e os tracos (-), barra (/) e pontos (.) *sao opcionais*.
|
4
|
+
# 2. O conteudo numerico desta string, que eh validado atraves do calculo do 'modulo 11' dos digitos que compoe a string.
|
5
|
+
#
|
6
|
+
# Caso o conteudo da string obedeca ao formato especificado acima, o mesmo sera formatado para obedecer ao padrao xx.xxx.xxx/xxxx-xx
|
7
|
+
#
|
8
|
+
# Eh importante observar que caso voce associe um valor de cnpj invalido ao seu model, o mesmo passara automaticamente a ser invalido, o que impede que valores de cpf incorretos sejam salvos no banco de dados.
|
9
|
+
#
|
10
|
+
# Como usar a classe Cnpj no seu ActiveRecord:
|
11
|
+
#
|
12
|
+
# Suponha que temos um model Empresa, com um atributo 'cnpj'
|
13
|
+
# que voce quer usar como um numero de documento para cnpj. Basta usar o
|
14
|
+
# metodo <tt>usar_como_cnpj</tt>, assim:
|
15
|
+
#
|
16
|
+
# class Empresa < ActiveRecord::Base
|
17
|
+
# usar_como_cnpj :cnpj
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# Agora voce pode usar o atributo para cnpj da seguinte forma:
|
21
|
+
#
|
22
|
+
# e = Empresa.new
|
23
|
+
# e.cnpj = "69103604000160"
|
24
|
+
# puts e.cnpj # ==> 69.103.604/0001-60
|
25
|
+
# e.cnpj.valido? # ==> true
|
26
|
+
# e.cnpj_valido? # ==> true
|
27
|
+
#
|
28
|
+
# e = Empresa.new(:cnpj => "69.103.604/0001-60")
|
29
|
+
# puts e.cnpj # ==> 69.103.604/0001-60
|
30
|
+
#
|
31
|
+
# e = Empresa.new
|
32
|
+
# e.cnpj = Cnpj.new("691036040001-60")
|
33
|
+
# puts e.cnpj # ==> 69.103.604/0001-60
|
34
|
+
#
|
35
|
+
# e = Empresa.new
|
36
|
+
# e.cnpj = "12343" # ==> um cnpj invalido
|
37
|
+
# puts e.valid? # ==> false
|
38
|
+
# e.save # ==> false
|
39
|
+
# e.errors.on(:cnpj) # ==> 'não é válido' # de acordo com a I18n
|
40
|
+
#
|
41
|
+
# c = Cnpj.new("69103604000160")
|
42
|
+
# e.cnpj = "69.103.604/0001-60"
|
43
|
+
# c == e.cnpj # ==> true
|
44
|
+
class Cnpj
|
45
|
+
include CpfCnpj
|
46
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
# Representa um numero de CPF. Objetos da classe Cpf recebem strings representando
|
3
|
+
# numeros de cpf e verificam a validade destes numeros usando dois criterios:
|
4
|
+
# 1. O formato da string, que deve seguir o padrao xxx.xxx.xxx-xx, onde 'x' pode ser qualquer digito de 0 a 9 e os tracos (-) e pontos (.) *sao opcionais*.
|
5
|
+
# 2. O conteudo numerico desta string, que eh validado atraves do calculo do 'modulo 11' dos digitos que compoe a string.
|
6
|
+
#
|
7
|
+
# Caso o conteudo da string obedeca ao formato especificado acima, o mesmo sera formatado para obedecer ao padrao xxx.xxx.xxx-xx
|
8
|
+
#
|
9
|
+
# Eh importante observar que caso voce associe um valor de cpf invalido ao seu model, o mesmo passara automaticamente a ser invalido, o que impede que valores de cpf incorretos sejam salvos no banco de dados.
|
10
|
+
#
|
11
|
+
# Como usar a classe Cpf no seu ActiveRecord:
|
12
|
+
#
|
13
|
+
# Suponha que temos um model Pessoa, com um atributo 'cpf'
|
14
|
+
# que voce quer usar como um numero de documento para cpf. Basta usar o
|
15
|
+
# metodo <tt>usar_como_cpf</tt>, assim:
|
16
|
+
#
|
17
|
+
# class Pessoa < ActiveRecord::Base
|
18
|
+
# usar_como_cpf :cpf
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# O atributo que sera usado como cpf pode ter qualquer nome e nao apenas 'cpf'
|
22
|
+
#
|
23
|
+
# Agora voce pode usar o atributo para cpf da seguinte forma:
|
24
|
+
#
|
25
|
+
# p = Pessoa.new
|
26
|
+
# p.cpf = "11144477735"
|
27
|
+
# puts p.cpf # ==> 111.444.777-35
|
28
|
+
# p.cpf.valido? # ==> true
|
29
|
+
# p.cpf_valido? # ==> true
|
30
|
+
#
|
31
|
+
# p = Pessoa.new(:cpf => "111.444.777-35")
|
32
|
+
# puts p.cpf # ==> 111.444.777-35
|
33
|
+
#
|
34
|
+
# p = Pessoa.new
|
35
|
+
# p.cpf = Cpf.new("111444777-35")
|
36
|
+
# puts p.cpf # ==> 111.444.777-35
|
37
|
+
#
|
38
|
+
# p = Pessoa.new
|
39
|
+
# p.cpf = "12345" # ==> um cpf invalido
|
40
|
+
# puts p.valid? # ==> false
|
41
|
+
# p.save # ==> false
|
42
|
+
# p.errors.on(:cpf) # ==> 'não é válido' # de acordo com o I18n
|
43
|
+
#
|
44
|
+
# c = Cpf.new("11144477735")
|
45
|
+
# p.cpf = "111.444.777-35"
|
46
|
+
# c == p.cpf # ==> true
|
47
|
+
#
|
48
|
+
class Cpf
|
49
|
+
include CpfCnpj
|
50
|
+
end
|
51
|
+
|
52
|
+
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module CpfCnpj
|
3
|
+
attr_reader :numero
|
4
|
+
|
5
|
+
def initialize(numero)
|
6
|
+
@numero = numero
|
7
|
+
@match = self.instance_of?(Cpf) ? @numero =~ CPF_REGEX : @numero =~ CNPJ_REGEX
|
8
|
+
@numero_puro = $1
|
9
|
+
@para_verificacao = $2
|
10
|
+
@numero = (@match ? format_number! : nil)
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
@numero || ""
|
15
|
+
end
|
16
|
+
|
17
|
+
def ==(outro_doc)
|
18
|
+
self.numero == outro_doc.numero
|
19
|
+
end
|
20
|
+
|
21
|
+
# Verifica se o numero possui o formato correto e se
|
22
|
+
# constitui um numero de documento valido, dependendo do seu
|
23
|
+
# tipo (Cpf ou Cnpj).
|
24
|
+
def valido?
|
25
|
+
return false unless @match
|
26
|
+
verifica_numero
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
DIVISOR = 11
|
31
|
+
|
32
|
+
CPF_LENGTH = 11
|
33
|
+
CPF_REGEX = /^(\d{3}\.?\d{3}\.?\d{3})-?(\d{2})$/
|
34
|
+
CPF_ALGS_1 = [10, 9, 8, 7, 6, 5, 4, 3, 2]
|
35
|
+
CPF_ALGS_2 = [11, 10, 9, 8, 7, 6, 5, 4, 3, 2]
|
36
|
+
|
37
|
+
CNPJ_LENGTH = 14
|
38
|
+
CNPJ_REGEX = /^(\d{2}\.?\d{3}\.?\d{3}\/?\d{4})-?(\d{2})$/ # <= 11.222.333/0001-XX
|
39
|
+
CNPJ_ALGS_1 = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
|
40
|
+
CNPJ_ALGS_2 = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
|
41
|
+
|
42
|
+
|
43
|
+
def verifica_numero
|
44
|
+
limpo = @numero.gsub(/[\.\/-]/, "")
|
45
|
+
if self.instance_of? Cpf
|
46
|
+
return false if limpo.length != 11
|
47
|
+
elsif self.instance_of? Cnpj
|
48
|
+
return false if limpo.length != 14
|
49
|
+
end
|
50
|
+
return false if limpo.scan(/\d/).uniq.length == 1
|
51
|
+
primeiro_verificador = primeiro_digito_verificador
|
52
|
+
segundo_verificador = segundo_digito_verificador(primeiro_verificador)
|
53
|
+
verif = primeiro_verificador + segundo_verificador
|
54
|
+
verif == @para_verificacao
|
55
|
+
end
|
56
|
+
|
57
|
+
def multiplica_e_soma(algs, numero_str)
|
58
|
+
multiplicados = []
|
59
|
+
numero_str.scan(/\d{1}/).each_with_index { |e, i| multiplicados[i] = e.to_i * algs[i] }
|
60
|
+
multiplicados.inject { |s,e| s + e }
|
61
|
+
end
|
62
|
+
|
63
|
+
def digito_verificador(resto)
|
64
|
+
resto < 2 ? 0 : DIVISOR - resto
|
65
|
+
end
|
66
|
+
|
67
|
+
def primeiro_digito_verificador
|
68
|
+
array = self.instance_of?(Cpf) ? CPF_ALGS_1 : CNPJ_ALGS_1
|
69
|
+
soma = multiplica_e_soma(array, @numero_puro)
|
70
|
+
digito_verificador(soma%DIVISOR).to_s
|
71
|
+
end
|
72
|
+
|
73
|
+
def segundo_digito_verificador(primeiro_verificador)
|
74
|
+
array = self.instance_of?(Cpf) ? CPF_ALGS_2 : CNPJ_ALGS_2
|
75
|
+
soma = multiplica_e_soma(array, @numero_puro + primeiro_verificador)
|
76
|
+
digito_verificador(soma%DIVISOR).to_s
|
77
|
+
end
|
78
|
+
|
79
|
+
def format_number!
|
80
|
+
if self.instance_of? Cpf
|
81
|
+
@numero =~ /(\d{3})\.?(\d{3})\.?(\d{3})-?(\d{2})/
|
82
|
+
@numero = "#{$1}.#{$2}.#{$3}-#{$4}"
|
83
|
+
else
|
84
|
+
@numero =~ /(\d{2})\.?(\d{3})\.?(\d{3})\/?(\d{4})-?(\d{2})/
|
85
|
+
@numero = "#{$1}.#{$2}.#{$3}/#{$4}-#{$5}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module CpfCnpjActiveRecord #:nodoc:
|
3
|
+
def self.included(base) #:nodoc:
|
4
|
+
base.extend ClassMethods
|
5
|
+
end
|
6
|
+
module ClassMethods #:nodoc:
|
7
|
+
def usar_como_cpf(*args) #:nodoc:
|
8
|
+
init(args, 'Cpf')
|
9
|
+
end
|
10
|
+
|
11
|
+
def usar_como_cnpj(*args) #:nodoc:
|
12
|
+
init(args, 'Cnpj')
|
13
|
+
end
|
14
|
+
|
15
|
+
def init(args, klass)
|
16
|
+
unless args.size.zero?
|
17
|
+
args.each do |name|
|
18
|
+
add_composed_class(name, klass)
|
19
|
+
module_eval create_code(name.to_s, klass)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_composed_class(name, klass)
|
25
|
+
options = {:class_name => klass, :mapping => [name.to_s, "numero"], :allow_nil => true}
|
26
|
+
constructor = Proc.new { |numero| eval(klass).new(numero) }
|
27
|
+
converter = Proc.new { |value| eval(klass).new(value) }
|
28
|
+
begin
|
29
|
+
composed_of name, options.merge( { :constructor => constructor, :converter => converter } )
|
30
|
+
rescue Exception
|
31
|
+
composed_of name, options { eval(klass).new(name[:numero]) }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_code(name, klass)
|
36
|
+
str = <<-CODE
|
37
|
+
validate :#{name}_valido?
|
38
|
+
def #{name}_valido?
|
39
|
+
value = read_attribute('#{name}')
|
40
|
+
if !value.nil? && value.strip != '' && !#{name}.nil? && !#{name}.valido?
|
41
|
+
self.errors.add('#{name}', :invalid)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
def #{name}=(value)
|
45
|
+
if value.blank?
|
46
|
+
write_attribute('#{name}', nil)
|
47
|
+
elsif value.kind_of?(#{eval(klass)})
|
48
|
+
write_attribute('#{name}', value.numero)
|
49
|
+
else
|
50
|
+
begin
|
51
|
+
c = #{eval(klass)}.new(value)
|
52
|
+
c.valido? ? write_attribute('#{name}', c.numero) : write_attribute('#{name}', value)
|
53
|
+
rescue
|
54
|
+
@#{name} = value
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
CODE
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
3
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
4
|
+
|
5
|
+
%w(cpf_cnpj cnpj cpf cpf_cnpj_activerecord cnpj_validator cpf_validator).each {|req| require File.dirname(__FILE__) + "/brcpfcnpj/#{req}"}
|
6
|
+
|
7
|
+
%w(rubygems active_record active_support).each {|req| require req }
|
8
|
+
|
9
|
+
ActiveRecord::Base.send :include, CpfCnpjActiveRecord
|
10
|
+
|
11
|
+
module FlexaLib
|
12
|
+
module BrCpfCnpj
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module FlexaLib
|
2
|
+
module Helpers
|
3
|
+
module ButtonGridHelpers
|
4
|
+
|
5
|
+
|
6
|
+
#BUTTON_GRID_HELPERS
|
7
|
+
def flexa_grid_button_show_to(obj)
|
8
|
+
link_to content_tag("i", "",:class=>"icon-search icon-white"), obj, :class=>"btn btn-smallest btn-info"
|
9
|
+
end
|
10
|
+
|
11
|
+
#BUTTON_GRID_HELPERS
|
12
|
+
def flexa_grid_button_edit_to(obj)
|
13
|
+
model_name = obj.class.to_s.underscore
|
14
|
+
link_to content_tag("i", "",:class=>"icon-pencil icon-white"), send("edit_#{model_name}_path",obj), :class=>"btn btn-smallest btn-warning"
|
15
|
+
end
|
16
|
+
|
17
|
+
#BUTTON_GRID_HELPERS
|
18
|
+
def flexa_grid_button_delete_to(obj)
|
19
|
+
link_to content_tag("i", "",:class=>"icon-minus icon-white"), obj, :confirm => 'Are you sure?', :method => :delete, :class=>"btn btn-smallest btn-danger"
|
20
|
+
end
|
21
|
+
|
22
|
+
#BUTTON_GRID_HELPERS
|
23
|
+
def flexa_grid_button_select_to(obj,fill)
|
24
|
+
afill=fill.split(",")
|
25
|
+
fill = ""
|
26
|
+
afill.each do |f|
|
27
|
+
fill << "window.parent.$('##{f}').attr('value','"+obj.send(f).to_s+"');"
|
28
|
+
end
|
29
|
+
link_to content_tag("i", "",:class=>"icon-ok icon-white"), "#", :class=>"btn btn-smallest btn-success",:onclick=>fill+"window.parent.$('#div_"+afill.first.to_s+"').modal('hide');"
|
30
|
+
#flexa_grid_button_generic("success","ok","#",:onclick=>fill+"window.parent.$('#lookup').modal('hide');")
|
31
|
+
end
|
32
|
+
|
33
|
+
#BUTTON_GRID_HELPERS
|
34
|
+
def flexa_grid_button_generic(button,icon,path,*args)
|
35
|
+
options = args.extract_options!
|
36
|
+
options[:class]= "btn btn-smallest btn-"+button
|
37
|
+
concat(link_to content_tag("i", "",:class=>"icon-"+icon+" icon-white"), path, options)
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module FlexaLib
|
2
|
+
module Helpers
|
3
|
+
module ButtonHelpers
|
4
|
+
|
5
|
+
#BUUTTON_HELPERS
|
6
|
+
def flexa_cancel_button_to(model)
|
7
|
+
model_name = model.class.to_s.underscore
|
8
|
+
content_tag :li do
|
9
|
+
link_to content_tag("i", "",:class=>"icon-backward")<<' Cancelar', send("#{model_name.pluralize}_path"),:id=>"cancel"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
#BUUTTON_HELPERS
|
14
|
+
def flexa_edit_button_to(model)
|
15
|
+
model_name = model.class.to_s.underscore
|
16
|
+
content_tag :li do
|
17
|
+
link_to content_tag("i", "",:class=>"icon-pencil")<<' Editar', send("edit_#{model_name}_path",model)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
#BUUTTON_HELPERS
|
23
|
+
def flexa_delete_button_to(model)
|
24
|
+
content_tag :li do
|
25
|
+
link_to content_tag("i", "",:class=>"icon-minus")<<' Excluir', model, :confirm => 'Deseja realmente excluir?', :method => :delete
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
#BUUTTON_HELPERS
|
30
|
+
def flexa_add_button_to(class_ref)
|
31
|
+
class_name = class_ref.name.to_s.underscore
|
32
|
+
content_tag :li do
|
33
|
+
link_to content_tag("i", "",:class=>"icon-plus")<<" Adicionar", send("new_#{class_name}_path"), :id=>"add"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
#BUUTTON_HELPERS
|
38
|
+
# para criar botôes genéricos
|
39
|
+
def flexa_generic_button_to(text,link,icon="",*args)
|
40
|
+
options = args.extract_options!
|
41
|
+
if !icon.nil?
|
42
|
+
text = raw content_tag("i", "",:class=>"icon-"+icon.to_s)<<" "+text
|
43
|
+
end
|
44
|
+
content_tag :li do
|
45
|
+
link_to text, link, options
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
#BUUTTON_HELPERS
|
50
|
+
def flexa_submit_button(text="Salvar")
|
51
|
+
content_tag :li do
|
52
|
+
flexa_link_to_submit content_tag("i", "",:class=>"icon-ok")<<" "<<text,:id=>"submit"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module FlexaLib
|
2
|
+
module Helpers
|
3
|
+
module LookupHelpers
|
4
|
+
|
5
|
+
#LOOKUP_HELPERS
|
6
|
+
def flexa_lookup_search_tool(class_ref)
|
7
|
+
class_name = class_ref.name.to_s.underscore
|
8
|
+
content_tag :li do
|
9
|
+
form_tag(send("lookups_#{class_name.pluralize}_path"), :method=>"get", :id=>"formsearch", :style=>"padding-top:4px;padding-left:50px;",:class=>"form-search") do
|
10
|
+
concat(hidden_field_tag :fill, params[:fill])
|
11
|
+
concat(text_field_tag :search, params[:search], :class=>"input-medium search-query")
|
12
|
+
concat(content_tag("button",:type=>"submit",:class=>"btn btn-info",:style=>"margin-left:4px;",:id=>"search") do
|
13
|
+
content_tag("i", "",:class=>"icon-search icon-white")
|
14
|
+
end)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module FlexaLib
|
2
|
+
module Helpers
|
3
|
+
module OtherHelpers
|
4
|
+
|
5
|
+
|
6
|
+
#OTHER_HELPERS
|
7
|
+
def flexa_search_tool(class_ref)
|
8
|
+
class_name = class_ref.name.to_s.underscore
|
9
|
+
content_tag :li do
|
10
|
+
form_tag(send("#{class_name.pluralize}_path"), :method=>"get", :id=>"formsearch", :style=>"padding-top:4px;padding-left:50px;",:class=>"form-search") do
|
11
|
+
concat(hidden_field_tag :fill, params[:fill])
|
12
|
+
concat(text_field_tag :search, params[:search], :class=>"input-medium search-query")
|
13
|
+
concat(content_tag("button",:type=>"submit",:class=>"btn btn-info",:style=>"margin-left:4px;",:id=>"search") do
|
14
|
+
content_tag("i", "",:class=>"icon-search icon-white")
|
15
|
+
end)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
#OTHER_HELPERS
|
21
|
+
def flexa_page_title(title, path)
|
22
|
+
content_tag :li do
|
23
|
+
link_to(content_tag("b", title), path)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
#OTHER_HELPERS
|
28
|
+
def flexa_icon_text(icon,text)
|
29
|
+
content_tag("i", "",:class=>"icon-"+icon)<<text
|
30
|
+
end
|
31
|
+
|
32
|
+
#OTHER_HELPERS
|
33
|
+
def flexa_flash_message
|
34
|
+
messages = ""
|
35
|
+
css_class = {:notice => "success", :info => "info", :warning => "info", :error => "error"}
|
36
|
+
[:notice, :info, :warning, :error].each {|type|
|
37
|
+
if flash[type]
|
38
|
+
messages += content_tag('div',flash[type],:class=>'alert alert-'<<css_class[type.to_sym])
|
39
|
+
end
|
40
|
+
}
|
41
|
+
raw messages
|
42
|
+
end
|
43
|
+
|
44
|
+
#OTHER_HELPERS
|
45
|
+
def flexa_fixed_toolbar(title="",path="",&block)
|
46
|
+
content_tag :header,:class=>"jumbotron subhead" do
|
47
|
+
content_tag :div,:class=>"subnav subnav-fixed" do
|
48
|
+
content_tag :ul,:class=>"nav nav-pills", :id=>"overview" do
|
49
|
+
concat(flexa_page_title(title, path))
|
50
|
+
block.call
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
#OTHER_HELPERS
|
57
|
+
def flexa_column(size="3",&block)
|
58
|
+
content_tag :div, :class=>"span"+size.to_s do
|
59
|
+
block.call
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module FlexaLib
|
2
|
+
module Helpers
|
3
|
+
module PaginateHelpers
|
4
|
+
|
5
|
+
#PAGINATE_HELPERS
|
6
|
+
def flexa_will_paginate(resource,*args)
|
7
|
+
options = args.extract_options!
|
8
|
+
options[:page_links] = true if options[:page_links].present?
|
9
|
+
options[:previous_label] = content_tag("i"," ",:class=>"icon-arrow-left")
|
10
|
+
options[:next_label] = content_tag("i"," ",:class=>"icon-arrow-right")
|
11
|
+
new_options = options
|
12
|
+
begin
|
13
|
+
flexa_wp = will_paginate resource, new_options
|
14
|
+
rescue
|
15
|
+
""
|
16
|
+
end
|
17
|
+
begin
|
18
|
+
flexa_wp["<ul>"]= ""
|
19
|
+
rescue
|
20
|
+
""
|
21
|
+
end
|
22
|
+
begin
|
23
|
+
flexa_wp["</ul>"]= ""
|
24
|
+
rescue
|
25
|
+
""
|
26
|
+
end
|
27
|
+
begin
|
28
|
+
flexa_wp['<div class="pagination">']= ""
|
29
|
+
rescue
|
30
|
+
""
|
31
|
+
end
|
32
|
+
begin
|
33
|
+
flexa_wp["</div>"]= ""
|
34
|
+
rescue
|
35
|
+
""
|
36
|
+
end
|
37
|
+
flexa_wp
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module FlexaLib
|
2
|
+
module Helpers
|
3
|
+
module TabHelpers
|
4
|
+
|
5
|
+
#TABS_HELPER
|
6
|
+
def flexa_tabs(&block)
|
7
|
+
content_tag :ul,:class=>"nav nav-tabs" do
|
8
|
+
block.call
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
#TABS_HELPER
|
13
|
+
def flexa_tab_link(tab,title,active="")
|
14
|
+
content_tag :li, :class=>active.to_s do
|
15
|
+
content_tag :a, :href=>"#"+tab.to_s, "data-toggle"=>"tab" do
|
16
|
+
title
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
#TABS_HELPER
|
22
|
+
def flexa_tabs_area(&block)
|
23
|
+
content_tag :div,:class=>"tab-content" do
|
24
|
+
block.call
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
#TABS_HELPER
|
29
|
+
def flexa_tab_frame(tab,active="",&block)
|
30
|
+
content_tag :div, :class=>"tab-pane "+active.to_s, :id=>tab do
|
31
|
+
block.call
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|