Module: EgovUtils::GridHelper
- Defined in:
- app/helpers/egov_utils/grid_helper.rb
Instance Method Summary collapse
- #additional_grid_edit_buttons(schema) ⇒ Object
- #column_for_grid(grid, attribute) ⇒ Object
-
#entity_template_path(schema, attribute) ⇒ Object
TODO - what if the attribute is main for associated schema (legal_person-name for person schema).
- #entity_template_path_for_schema(schema, id_template = '{id}') ⇒ Object
- #field_for_grid(attribute) ⇒ Object
- #grid_necessary_fields(schema) ⇒ Object
- #type_for_grid(type) ⇒ Object
Instance Method Details
#additional_grid_edit_buttons(schema) ⇒ Object
74 75 |
# File 'app/helpers/egov_utils/grid_helper.rb', line 74 def (schema) end |
#column_for_grid(grid, attribute) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/helpers/egov_utils/grid_helper.rb', line 49 def column_for_grid(grid, attribute) s = "{" s << "field: '#{attribute.name}'" s << ", title: '#{attribute.attribute_name.human}'" if (template_path = entity_template_path(grid.schema, attribute)) s << ", columnTemplate: '<a href=\"#{template_path}\">{#{attribute.name}}</div>'" end if attribute.type == 'list' s << ", format: ( (value) -> I18n.t('#{attribute.attribute_name.i18n_scoped_list_prefix}'+'.'+value, {defaults: $.map( #{attribute.attribute_name.i18n_list_fallback_prefixes.to_json}, (pref, i)-> {scope: (pref + '.' + value)} )}) ) " elsif %w(date datetime).include?(attribute.type) s << ", format: ( (value)-> I18n.l('date.formats.default', value) )" elsif attribute.type == 'currency' s << ", columnTemplate: ( (cell, item, index)-> $('<div></div>').appendTo(cell).html( I18n.toCurrency(item['#{attribute.name}'], { unit: window.currency_symbols[item['#{attribute.try(:currency_code_col)}']]}) ) )" end s << "}" end |
#entity_template_path(schema, attribute) ⇒ Object
TODO - what if the attribute is main for associated schema (legal_person-name for person schema)
41 42 43 44 45 46 47 |
# File 'app/helpers/egov_utils/grid_helper.rb', line 41 def entity_template_path(schema, attribute) if attribute.name == schema.main_attribute_name entity_template_path_for_schema(schema) elsif (base_schema = attribute.try(:base_schema)) && attribute.name =~ /#{base_schema.main_attribute_name}/ entity_template_path_for_schema(base_schema, "{#{attribute.primary_key_name}}") end end |
#entity_template_path_for_schema(schema, id_template = '{id}') ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'app/helpers/egov_utils/grid_helper.rb', line 30 def entity_template_path_for_schema(schema, id_template='{id}') if schema.respond_to?('engine_name') self.public_send(schema.engine_name).polymorphic_path(schema.model) + "/#{id_template}" else polymorphic_path(schema.model) + "/#{id_template}" end rescue NoMethodError => e nil end |
#field_for_grid(attribute) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'app/helpers/egov_utils/grid_helper.rb', line 19 def field_for_grid(attribute) s = "\'" s << attribute.name s << '\': {path: "' s << attribute.path s << '", type: ' s << type_for_grid(attribute.type) s << '}' s end |
#grid_necessary_fields(schema) ⇒ Object
68 69 70 71 72 |
# File 'app/helpers/egov_utils/grid_helper.rb', line 68 def grid_necessary_fields(schema) fields = schema.columns.dup pks = [schema.model.primary_key].concat(fields.collect{|col| col.primary_key_name }).uniq fields.concat(pks.map{|pk_name| schema.attribute(pk_name) }) end |
#type_for_grid(type) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/helpers/egov_utils/grid_helper.rb', line 4 def type_for_grid(type) case type when 'integer', 'float', 'decimal', 'currency' 'Number' when 'string', 'text', 'list', 'love' 'String' when 'date', 'datetime' 'Date' when 'boolean' 'Boolean' else raise "Undefined grid type for type #{type}" end end |