templus_models 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/javascripts/raro_crud.js +3 -0
- data/app/helpers/crud_helper.rb +17 -2
- data/app/raro_crud/raro_crud.rb +49 -22
- data/app/views/crud/_form.html.erb +1 -2
- data/app/views/crud/_record.html.erb +3 -3
- data/app/views/crud/_shared.html.erb +7 -3
- data/app/views/crud/create.js.erb +1 -1
- data/app/views/layouts/_template_raro_crud.html.erb +6 -7
- data/lib/templus_models/version.rb +1 -1
- data/test/dummy/app/models/usuario.rb +2 -1
- data/test/dummy/app/raro_crud/usuario_crud.rb +5 -4
- data/test/dummy/db/development.sqlite3 +0 -0
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: bfad85131bd19efb453328996e69385d9e4c9342
         | 
| 4 | 
            +
              data.tar.gz: c8d4b46fddeda767f28b832c3ca9bd460a0aa74d
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 603316b3e62cc51bda580620a885b7731056106c9a7902735f5d0c6d7b6295b41d6cef997e200f49a37a2e7679fdd0bb7f24578efa61f6e7be1120395bd8a9aa
         | 
| 7 | 
            +
              data.tar.gz: 483f928f955f6803c94c099bb0e70148848b9ebde9a18da9b2fcc68eb8abeb1773e392fb18e82b29731354e146b13747eda17428c6c2cb7ec8507ceff6df48e7
         | 
| @@ -21,6 +21,9 @@ function new_record(id,name){ | |
| 21 21 | 
             
            					text: entity_desc,
         | 
| 22 22 | 
             
            					selected: 'selected'
         | 
| 23 23 | 
             
            				}));
         | 
| 24 | 
            +
            				if($('#' + id).hasClass("chosen")){
         | 
| 25 | 
            +
            					$('#' + id).trigger("chosen:updated");
         | 
| 26 | 
            +
            				}
         | 
| 24 27 | 
             
            				$(model_target).attr('data-saved','false');
         | 
| 25 28 | 
             
            				$(model_target).attr('data-entity-name','')
         | 
| 26 29 | 
             
            				$(model_target).attr('data-entity-id','')
         | 
    
        data/app/helpers/crud_helper.rb
    CHANGED
    
    | @@ -8,13 +8,13 @@ module CrudHelper | |
| 8 8 | 
             
                  params[:action] == action_name ? "active" : nil
         | 
| 9 9 | 
             
              end
         | 
| 10 10 |  | 
| 11 | 
            -
              def is_raro_crud( | 
| 11 | 
            +
              def is_raro_crud(classe)
         | 
| 12 12 | 
             
                #if(Rails.env == "production")
         | 
| 13 13 | 
             
                #  @@cruds = Dir[Rails.root.join("app","raro_crud","*.rb")].map{|f| f.split(/\//).last.gsub(/_crud\.rb/,'')} unless @@cruds
         | 
| 14 14 | 
             
                #else
         | 
| 15 15 | 
             
                  @@cruds = Dir[Rails.root.join("app","raro_crud","*.rb")].map{|f| f.split(/\//).last.gsub(/_crud\.rb/,'')}
         | 
| 16 16 | 
             
                #end
         | 
| 17 | 
            -
                return @@cruds.include?( | 
| 17 | 
            +
                return @@cruds.include?(classe.underscore.to_s)
         | 
| 18 18 | 
             
              end
         | 
| 19 19 |  | 
| 20 20 | 
             
              def lista_menus_crud(raro_models)
         | 
| @@ -109,6 +109,7 @@ module CrudHelper | |
| 109 109 | 
             
              end
         | 
| 110 110 |  | 
| 111 111 | 
             
              def render_field(field,f,modelo,record)
         | 
| 112 | 
            +
                field[:sf][:wrapper] ||= :default
         | 
| 112 113 | 
             
                if field[:sf].present? && field[:sf][:if].present?
         | 
| 113 114 | 
             
                  return unless field[:sf][:if].call(f.object)
         | 
| 114 115 | 
             
                end
         | 
| @@ -167,4 +168,18 @@ module CrudHelper | |
| 167 168 | 
             
              def render_default_actions_crud
         | 
| 168 169 | 
             
                render "default_actions_crud"
         | 
| 169 170 | 
             
              end
         | 
| 171 | 
            +
              
         | 
| 172 | 
            +
              #Permissions
         | 
| 173 | 
            +
              def shold_view?(crud_helper,record)
         | 
| 174 | 
            +
                return true if crud_helper.condition_view_action.nil?
         | 
| 175 | 
            +
                crud_helper.condition_view_action.call(record)
         | 
| 176 | 
            +
              end
         | 
| 177 | 
            +
              def shold_edit?(crud_helper,record)
         | 
| 178 | 
            +
                return true if crud_helper.condition_edit_action.nil?
         | 
| 179 | 
            +
                crud_helper.condition_edit_action.call(record)
         | 
| 180 | 
            +
              end
         | 
| 181 | 
            +
              def shold_destroy?(crud_helper,record)
         | 
| 182 | 
            +
                return true if crud_helper.condition_destroy_action.nil?
         | 
| 183 | 
            +
                crud_helper.condition_destroy_action.call(record)
         | 
| 184 | 
            +
              end
         | 
| 170 185 | 
             
            end
         | 
    
        data/app/raro_crud/raro_crud.rb
    CHANGED
    
    | @@ -1,26 +1,29 @@ | |
| 1 1 | 
             
            class RaroCrud
         | 
| 2 | 
            -
              @@order_field | 
| 3 | 
            -
              @@per_page | 
| 4 | 
            -
              @@index_fields | 
| 5 | 
            -
              @@form_fields | 
| 6 | 
            -
              @@form_group | 
| 7 | 
            -
              @@form_scripts | 
| 8 | 
            -
              @@view_fields | 
| 9 | 
            -
              @@search_fields | 
| 10 | 
            -
              @@test_fields | 
| 11 | 
            -
              @@top_links | 
| 12 | 
            -
              @@title | 
| 13 | 
            -
              @@subtitle_index | 
| 14 | 
            -
              @@description_index | 
| 15 | 
            -
              @@actions | 
| 16 | 
            -
              @@links | 
| 17 | 
            -
              @@edit_action | 
| 18 | 
            -
              @@ | 
| 19 | 
            -
              @@ | 
| 20 | 
            -
              @@ | 
| 21 | 
            -
              @@ | 
| 22 | 
            -
              @@ | 
| 23 | 
            -
              @@ | 
| 2 | 
            +
              @@order_field               = {}
         | 
| 3 | 
            +
              @@per_page                  = {}
         | 
| 4 | 
            +
              @@index_fields              = {}
         | 
| 5 | 
            +
              @@form_fields               = {}
         | 
| 6 | 
            +
              @@form_group                = {}
         | 
| 7 | 
            +
              @@form_scripts              = {}
         | 
| 8 | 
            +
              @@view_fields               = {}
         | 
| 9 | 
            +
              @@search_fields             = {}
         | 
| 10 | 
            +
              @@test_fields               = {}
         | 
| 11 | 
            +
              @@top_links                 = {} 
         | 
| 12 | 
            +
              @@title                     = {}
         | 
| 13 | 
            +
              @@subtitle_index            = {}
         | 
| 14 | 
            +
              @@description_index         = {}
         | 
| 15 | 
            +
              @@actions                   = {}
         | 
| 16 | 
            +
              @@links                     = {}
         | 
| 17 | 
            +
              @@edit_action               = {}
         | 
| 18 | 
            +
              @@condition_edit_action     = {}
         | 
| 19 | 
            +
              @@destroy_action            = {}
         | 
| 20 | 
            +
              @@condition_destroy_action  = {}
         | 
| 21 | 
            +
              @@view_action               = {}
         | 
| 22 | 
            +
              @@condition_view_action     = {}
         | 
| 23 | 
            +
              @@options_link              = {}
         | 
| 24 | 
            +
              @@scopes                    = {}
         | 
| 25 | 
            +
              @@menus                     = []
         | 
| 26 | 
            +
              @@index_path                = nil
         | 
| 24 27 |  | 
| 25 28 | 
             
              def self.edit_action
         | 
| 26 29 | 
             
                if @@edit_action[self.to_s.to_sym] == false
         | 
| @@ -30,6 +33,10 @@ class RaroCrud | |
| 30 33 | 
             
                end
         | 
| 31 34 | 
             
              end
         | 
| 32 35 |  | 
| 36 | 
            +
              def self.condition_edit_action
         | 
| 37 | 
            +
                (@@condition_edit_action[self.to_s.to_sym]) ? @@condition_edit_action[self.to_s.to_sym] : nil
         | 
| 38 | 
            +
              end
         | 
| 39 | 
            +
              
         | 
| 33 40 | 
             
              def self.destroy_action
         | 
| 34 41 | 
             
                if @@destroy_action[self.to_s.to_sym] == false
         | 
| 35 42 | 
             
                  return false
         | 
| @@ -37,6 +44,10 @@ class RaroCrud | |
| 37 44 | 
             
                  return true
         | 
| 38 45 | 
             
                end
         | 
| 39 46 | 
             
              end
         | 
| 47 | 
            +
              
         | 
| 48 | 
            +
              def self.condition_destroy_action
         | 
| 49 | 
            +
                (@@condition_destroy_action[self.to_s.to_sym]) ? @@condition_destroy_action[self.to_s.to_sym] : nil
         | 
| 50 | 
            +
              end
         | 
| 40 51 |  | 
| 41 52 | 
             
              def self.view_action
         | 
| 42 53 | 
             
                if @@view_action[self.to_s.to_sym] == false
         | 
| @@ -45,6 +56,10 @@ class RaroCrud | |
| 45 56 | 
             
                  return true
         | 
| 46 57 | 
             
                end
         | 
| 47 58 | 
             
              end
         | 
| 59 | 
            +
              
         | 
| 60 | 
            +
              def self.condition_view_action
         | 
| 61 | 
            +
                (@@condition_view_action[self.to_s.to_sym]) ? @@condition_view_action[self.to_s.to_sym] : nil
         | 
| 62 | 
            +
              end
         | 
| 48 63 |  | 
| 49 64 | 
             
              def self.root_path
         | 
| 50 65 | 
             
                "/crud/#{self.to_s.gsub('Crud', '').underscore}"
         | 
| @@ -248,15 +263,27 @@ class RaroCrud | |
| 248 263 | 
             
              def self.sem_visualizacao
         | 
| 249 264 | 
             
                @@view_action[self.to_s.to_sym] = false
         | 
| 250 265 | 
             
              end
         | 
| 266 | 
            +
              
         | 
| 267 | 
            +
              def self.visualizacao(condicao)
         | 
| 268 | 
            +
                @@condition_view_action[self.to_s.to_sym] = condicao
         | 
| 269 | 
            +
              end
         | 
| 251 270 |  | 
| 252 271 | 
             
              def self.sem_edicao
         | 
| 253 272 | 
             
                @@edit_action[self.to_s.to_sym] = false
         | 
| 254 273 | 
             
              end
         | 
| 274 | 
            +
              
         | 
| 275 | 
            +
              def self.edicao(condicao)
         | 
| 276 | 
            +
                @@condition_edit_action[self.to_s.to_sym] = condicao
         | 
| 277 | 
            +
              end
         | 
| 255 278 |  | 
| 256 279 | 
             
              def self.sem_exclusao
         | 
| 257 280 | 
             
                @@destroy_action[self.to_s.to_sym] = false
         | 
| 258 281 | 
             
              end
         | 
| 259 282 |  | 
| 283 | 
            +
              def self.exclusao(condicao)
         | 
| 284 | 
            +
                @@condition_destroy_action[self.to_s.to_sym] = condicao
         | 
| 285 | 
            +
              end
         | 
| 286 | 
            +
              
         | 
| 260 287 | 
             
              def self.acoes(method,desc,proc = nil)
         | 
| 261 288 | 
             
                @@actions[self.to_s.to_sym] = [] unless @@actions[self.to_s.to_sym]
         | 
| 262 289 | 
             
                @@actions[self.to_s.to_sym].push([method,desc,proc])
         | 
| @@ -21,12 +21,11 @@ | |
| 21 21 | 
             
            	<%= simple_nested_form_for @record, remote: remote_form, html: {class: "form-horizontal"}, url: url do |f| %>
         | 
| 22 22 | 
             
            		<%= flash_messages_error(@record.errors) %>
         | 
| 23 23 | 
             
            		<%@crud_helper.form_fields.each do |field|%>
         | 
| 24 | 
            -
            			<% if @model.reflect_on_association(field[:attribute]).class == ActiveRecord::Reflection::BelongsToReflection  | 
| 24 | 
            +
            			<% if @model.reflect_on_association(field[:attribute]).class == ActiveRecord::Reflection::BelongsToReflection && is_raro_crud(@model.reflect_on_association(field[:attribute]).class_name) && field[:sf][:add_registro].nil?%>
         | 
| 25 25 | 
             
            					<%= render_plus_button(field,f,@model,@record) %>
         | 
| 26 26 | 
             
            			<%else%>
         | 
| 27 27 | 
             
            					<%= render_field(field,f,@model,@record) %>
         | 
| 28 28 | 
             
            			<%end%>
         | 
| 29 | 
            -
            		
         | 
| 30 29 | 
             
            		<% end %>
         | 
| 31 30 | 
             
            		<%@crud_helper.form_groups.each do |key, groups|%>
         | 
| 32 31 | 
             
            			<% modelo = @model.reflect_on_association(key.to_s).class_name.constantize %>
         | 
| @@ -52,15 +52,15 @@ | |
| 52 52 | 
             
            				</a>
         | 
| 53 53 | 
             
            			<% end %>
         | 
| 54 54 | 
             
            		<% end %>
         | 
| 55 | 
            -
            		<%if @crud_helper.view_action%>
         | 
| 55 | 
            +
            		<%if @crud_helper.view_action && shold_view?(@crud_helper, record)%>
         | 
| 56 56 | 
             
            			<a href="/crud/<%=@model.name.underscore%>/<%=record.id%>"
         | 
| 57 57 | 
             
            				class="btn btn-primary btn-xs" data-push="partial" data-target="#form">Visualizar</a>
         | 
| 58 58 | 
             
            		<% end %>
         | 
| 59 | 
            -
            		<%if @crud_helper.edit_action%>
         | 
| 59 | 
            +
            		<%if @crud_helper.edit_action && shold_edit?(@crud_helper, record) %>
         | 
| 60 60 | 
             
            			<a href="/crud/<%=@model.name.underscore%>/<%=record.id%>/edit"
         | 
| 61 61 | 
             
            				class="btn btn-primary btn-xs" data-push="partial" data-target="#form">Editar</a>
         | 
| 62 62 | 
             
            		<% end %>
         | 
| 63 | 
            -
            		<%if @crud_helper.destroy_action%>
         | 
| 63 | 
            +
            		<%if @crud_helper.destroy_action && shold_destroy?(@crud_helper, record)%>
         | 
| 64 64 | 
             
            			<a href="/crud/<%=@model.name.underscore%>/<%=record.id%>/destroy"
         | 
| 65 65 | 
             
            				class="btn btn-danger btn-xs" data-push="partial" data-target="#form" data-method="delete">Excluir</a>
         | 
| 66 66 | 
             
            		<% end %>
         | 
| @@ -1,3 +1,4 @@ | |
| 1 | 
            +
            <%unless params[:render] == 'modal'%>
         | 
| 1 2 | 
             
            <div class="wrapper wrapper-content animated fadeInRight">
         | 
| 2 3 | 
             
            	<div class="row">
         | 
| 3 4 | 
             
            		<div class="col-lg-12">
         | 
| @@ -10,7 +11,7 @@ | |
| 10 11 | 
             
            						</h5>
         | 
| 11 12 | 
             
            					<% elsif is_action_create? && @model.present? %>
         | 
| 12 13 | 
             
            						<h5>Cadastrar</h5>
         | 
| 13 | 
            -
            					<% elsif @record.present? %>
         | 
| 14 | 
            +
            					<% elsif @record.present? && !@record.new_record? %>
         | 
| 14 15 | 
             
            						<h5>
         | 
| 15 16 | 
             
            							<%= @record.to_s %>
         | 
| 16 17 | 
             
            							<small style="margin-left: 2px;">#<%= @record.id %></small>
         | 
| @@ -21,7 +22,7 @@ | |
| 21 22 | 
             
            							<small><%= @crud_helper.description(:index) %></small>
         | 
| 22 23 | 
             
            						</h5>
         | 
| 23 24 | 
             
            					<% end %>
         | 
| 24 | 
            -
            					<% if is_action_index? || is_action_query | 
| 25 | 
            +
            					<% if (@crud_helper.present? && (is_action_index? || is_action_query?))%>
         | 
| 25 26 | 
             
            						<div class="pull-right actions">
         | 
| 26 27 | 
             
            							<% @crud_helper.top_links.each do |link| %>
         | 
| 27 28 | 
             
            								<% if link[:can].present? %>
         | 
| @@ -44,4 +45,7 @@ | |
| 44 45 | 
             
            			</div>
         | 
| 45 46 | 
             
            		</div>
         | 
| 46 47 | 
             
            	</div>
         | 
| 47 | 
            -
            </div>
         | 
| 48 | 
            +
            </div>
         | 
| 49 | 
            +
            <% else %>
         | 
| 50 | 
            +
            	<% block.call %>
         | 
| 51 | 
            +
            <% end %>
         | 
| @@ -4,7 +4,7 @@ | |
| 4 4 | 
             
            	<%if @saved %>
         | 
| 5 5 | 
             
            		var modal_target = "#modal_new_record." + '<%=@model.name.underscore%>';
         | 
| 6 6 | 
             
            		$(modal_target).attr('data-saved','true')
         | 
| 7 | 
            -
             | 
| 7 | 
            +
            	   $(modal_target).attr('data-entity-name','<%=@record.to_s%>')
         | 
| 8 8 | 
             
            		$(modal_target).attr('data-entity-id','<%=@record.id%>')
         | 
| 9 9 | 
             
            		$(modal_target).modal('hide')
         | 
| 10 10 | 
             
            	<%else%>
         | 
| @@ -23,11 +23,10 @@ | |
| 23 23 | 
             
            			</div>
         | 
| 24 24 | 
             
            		</div>
         | 
| 25 25 | 
             
            	</div>
         | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
            	<% end %>
         | 
| 26 | 
            +
            <% end %>
         | 
| 27 | 
            +
            <% if content_for? :corpo %>
         | 
| 28 | 
            +
            	<%= yield :corpo %>
         | 
| 29 | 
            +
            <% end %>
         | 
| 30 | 
            +
            <% if content_for? :modal %>
         | 
| 31 | 
            +
            	<%= yield  :modal %>
         | 
| 33 32 | 
             
            <% end %>
         | 
| @@ -4,7 +4,8 @@ class Usuario < ActiveRecord::Base | |
| 4 4 | 
             
              devise :database_authenticatable, :registerable,
         | 
| 5 5 | 
             
                     :recoverable, :rememberable, :trackable, :validatable
         | 
| 6 6 |  | 
| 7 | 
            -
              belongs_to :papel
         | 
| 7 | 
            +
              # belongs_to :papel
         | 
| 8 | 
            +
              belongs_to :perfil, :class_name => "Papel", :foreign_key => "papel_id"
         | 
| 8 9 | 
             
              validates_presence_of :nome, :email
         | 
| 9 10 |  | 
| 10 11 | 
             
              def to_s
         | 
| @@ -4,21 +4,22 @@ class UsuarioCrud < RaroCrud | |
| 4 4 | 
             
              link_superior "Novo Usuário", id: "novo-button", icon: "plus", link: "new"
         | 
| 5 5 |  | 
| 6 6 | 
             
              ordenar_por :nome
         | 
| 7 | 
            +
              edicao Proc.new {|obj| !obj.root? }
         | 
| 8 | 
            +
              exclusao Proc.new {|obj| !obj.root? }
         | 
| 9 | 
            +
              visualizacao Proc.new {|obj| obj.root? }
         | 
| 7 10 |  | 
| 8 11 | 
             
              campo_tabela :nome,  label: "Nome"
         | 
| 9 12 | 
             
              campo_tabela :email, label: "email"
         | 
| 10 13 |  | 
| 11 | 
            -
             | 
| 12 14 | 
             
              campo_formulario :nome, label: "Nome"
         | 
| 13 15 | 
             
              campo_formulario :email, label: "Email", default_test_pos: "@rarolabs.com"
         | 
| 14 16 | 
             
              campo_formulario :password, label: "Senha", default_test: "12345678", edit: false
         | 
| 15 17 | 
             
              campo_formulario :password_confirmation, label: "Confirmação Senha", default_test: "12345678", edit: false
         | 
| 16 | 
            -
              campo_formulario : | 
| 17 | 
            -
                                       label_method: :descricao
         | 
| 18 | 
            +
              campo_formulario :perfil, label: "Perfil", label_method: :descricao, input_html: {class: "chosen" ,   "data-placeholder" => "Escolha o perfil..."}, if: Proc.new {|obj| Usuario.current.root? }
         | 
| 18 19 |  | 
| 19 20 | 
             
              campo_visualizacao :nome,  label: "Nome"
         | 
| 20 21 | 
             
              campo_visualizacao :email, label: "email"
         | 
| 21 | 
            -
              campo_visualizacao : | 
| 22 | 
            +
              campo_visualizacao :perfil, label: "Papel"
         | 
| 22 23 |  | 
| 23 24 | 
             
              campo_busca :nome,  label: "Nome"
         | 
| 24 25 | 
             
              campo_busca :email, label: "email"
         | 
| Binary file | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: templus_models
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.3. | 
| 4 | 
            +
              version: 1.3.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Rodrigo Sol
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2015-07- | 
| 12 | 
            +
            date: 2015-07-13 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: rails
         |