Module: HBLTags::TagsHelper

Defined in:
lib/hbl_tags/tags_helper.rb

Constant Summary collapse

HBL_ADD_TAG_SCRIPT =

creates a tagged field selector

<<-EOF
    
function hbl_append_tagged_field( url) {
  $.ajax({
    url: url,
    async: false,
    method: 'get',
    dataType: 'script'
  });
}

var formElements = new Array();
var formElementPrefix = "";

function hbl_update_selector_field() {

  /* define variables */
  var id = "";
  
  /* enable all select options */
  $('#tagged_field_selector').children().removeAttr('disabled');
  
  /* collect all current text input tags */
  formElements = [];
  $("#entity-tagged_fields-fields :input").each(function(){
    formElements.push($(this).attr('id'));
  });
  
  /* now diable all elements, not ending with "_", which are not multiple */
  formElements.forEach( function (item, index) {
    id = item.replace(formElementPrefix,'');
    $('#tagged_field_selector').children('option[value="' + id + '"]').attr('disabled', 'disabled');
  });
}

EOF

Instance Method Summary collapse

Instance Method Details

#boolean_values_options(options) ⇒ Object

def



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/hbl_tags/tags_helper.rb', line 62

def boolean_values_options(options)
  if @bulk && !options[:nobulk]
  [ [l(:label_no_change_option),"none"],
    [l(:label_none),             nil],
    [l(:general_text_Yes),       1],
    [l(:general_text_No),        0] ]
  else
  [ [],
    [l(:general_text_Yes),       1],
    [l(:general_text_No),        0] ]
  end
end

#currencies_optionsObject

def



678
679
680
681
682
683
# File 'lib/hbl_tags/tags_helper.rb', line 678

def currencies_options
  ["DE", "US", "CH"].map do |cc|
    c = ISO3166::Country[cc]; 
    I18n.with_locale(:de) { [c.currency.name, c.currency.iso_code] }
  end
end

#currency_options_for_select(blank = true) ⇒ Object



674
675
676
# File 'lib/hbl_tags/tags_helper.rb', line 674

def currency_options_for_select(blank=true)
  (blank ? [["(auto)", ""]] : []) + currencies_options
end

#get_tagged_fields_hash_name(model, k) ⇒ Object


private methods



613
614
615
616
617
# File 'lib/hbl_tags/tags_helper.rb', line 613

def get_tagged_fields_hash_name(model, k)
  tagged_fields = TaggedField.of(model.project).where(:identifier => k)
  return tagged_fields[0].name if tagged_fields.present?
  return k.to_s.humanize
end

#hbl_boolean_select(f, model, field, editable, options = {}, html_options = {}) ⇒ Object


creates a boolean select field



58
59
60
# File 'lib/hbl_tags/tags_helper.rb', line 58

def hbl_boolean_select(f, model, field, editable, options = {}, html_options={} )
  hbl_select_field( f, model, field, boolean_values_options(options), options, html_options)
end

#hbl_check_box(f, model, field, editable, options = {}) ⇒ Object


creates a check box field



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/hbl_tags/tags_helper.rb', line 28

def hbl_check_box( f, model, field, editable, options = {} )
  check_box_options = options.deep_dup
  if @bulk && !check_box_options[:nobulk]; return hbl_boolean_select(f, model, field, editable, check_box_options ); end
  check_box_options[:class] = check_box_options[:class].to_s << " checked_box" if options[:mimic_checked]
  check_box_options[:label] = label_text(model, field)
  check_box_options[:disabled] ||= !editable
  if check_box_options.delete(:boolean)
    checked = "true"; unchecked = "false"
  else
    checked = 1; unchecked = 0
  end
  (:div, :class => ("flash error"  if !model.errors[field].empty? ) ) do
    (:p ) do
      f.check_box( field, check_box_options.compact, checked, unchecked ) + 
      (:a, :href =>'#', :class => 'icon icon-help', :title => l(:label_help), :onclick => "$('##{help_tag_id(model, field)}').toggle(); return false;" ) do
        l(:label_help)
      end + 
      tag(:br ) +
      (:span, :id => "#{help_tag_id(model, field)}", :class => "info", :style => "display:none;" ) do
        (:em, :class => "info") do
          help_text(model, field)
        end
      end
    end
  end
end

#hbl_country_select_field(f, model, field, values, options = {}, html_options = {}) ⇒ Object


creates a country select drop down menu



336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
# File 'lib/hbl_tags/tags_helper.rb', line 336

def hbl_country_select_field( f, model, field, values, options={}, html_options={})
  country_field_options = options.deep_dup
  country_field_options[:label] ||= label_text(model, field)
  #country_field_options[:disabled] ||= !editable
  (:div, :class => ("flash error"  if !model.errors[field].empty? ) ) do
    (:p ) do
      (:label, country_field_options[:label]) + 
      f.country_select( field, values, country_field_options.compact, html_options ) + 
      (:a, :href =>'#', :class => 'icon icon-help', :title => l(:label_help), :onclick => "$('##{help_tag_id(model, field)}').toggle(); return false;" ) do
        l(:label_help)
      end + 
      tag(:br ) +
      (:span, :id => "#{help_tag_id(model, field)}", :class => "info", :style => "display:none;" ) do
        (:em, :class => "info") do
          help_text(model, field)
        end
      end
    end
  end
end

#hbl_date_field(f, model, field, editable, options = {}) ⇒ Object


creates a date field



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/hbl_tags/tags_helper.rb', line 160

def hbl_date_field( f, model, field, editable, options = {} )
 date_field_options = options.deep_dup
 date_field_options[:label] = label_text(model, field)
 date_field_options[:placeholder] = placeholder(field, model, options)
 date_field_options[:size] ||= 32
 date_field_options[:disabled] ||= !editable
 (:div, :class => ("flash error"  if !model.errors[field].empty? ) ) do
    (:p ) do
      f.date_field( field, date_field_options.compact ) + 
      if @bulk && !date_field_options[:nobulk]
        name = model.class.name.underscore
        check_box_tag( "#{name}[#{field}]", "none", (model.send(field) == 'none'), :id => nil, :disabled => !editable, :class => 'inline', :data => {:disables => "##{name}_#{field}"} ) + tag(:span, :class=>"icon icon-del")
      end.to_s + 
      (:a, :href =>'#', :class => 'icon icon-help', :title => l(:label_help), :onclick => "$('##{help_tag_id(model, field)}').toggle(); return false;" ) do
        l(:label_help)
      end + 
      tag(:br ) +
      (:span, :id => "#{help_tag_id(model, field)}", :class => "info", :style => "display:none;" ) do
        (:em, :class => "info") do
          help_text(model, field)
        end
      end
    end
  end
end

#hbl_datetime_field(f, model, field, editable, options = {}) ⇒ Object


creates a date time field



247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/hbl_tags/tags_helper.rb', line 247

def hbl_datetime_field( f, model, field, editable, options = {} )
 date_field_options = options.deep_dup
 date_field_options[:label] = label_text(model, field)
 date_field_options[:placeholder] = placeholder(field, model, options)
 date_field_options[:size] ||= 32
 date_field_options[:disabled] ||= !editable
 (:div, :class => ("flash error"  if !model.errors[field].empty? ) ) do
    (:p ) do
      f.datetime_field( field, date_field_options.compact ) + 
      if @bulk && !text_field_options[:nobulk]
        name = model.class.name.underscore
        check_box_tag( "#{name}[#{field}]", "none", (model.send(field) == 'none'), :id => nil, :disabled => !editable, :class => 'inline', :data => {:disables => "##{name}_#{field}"} ) + tag(:span, :class=>"icon icon-del")
      end.to_s + 
      (:a, :href =>'#', :class => 'icon icon-help', :title => l(:label_help), :onclick => "$('##{help_tag_id(model, field)}').toggle(); return false;" ) do
        l(:label_help)
      end + 
      tag(:br ) +
      (:span, :id => "#{help_tag_id(model, field)}", :class => "info", :style => "display:none;" ) do
        (:em, :class => "info") do
          help_text(model, field)
        end
      end
    end
  end
end

#hbl_edit_array_tag(column, model, value, options = {}) ⇒ Object


creates an edit array tag



507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
# File 'lib/hbl_tags/tags_helper.rb', line 507

def hbl_edit_array_tag( column, model, value, options={} )

  klass                = options[:class]           || model.class
  denominator          = klass.name.underscore
  
  project              = model.project             || @project 
  view_permission      = options[:view_permission] || "view_#{denominator.pluralize}".to_sym
  edit_permission      = options[:edit_permission] || "edit_#{denominator.pluralize}".to_sym
  update_function      = options[:update_function] || "update_field_of_project_#{denominator}_path".to_sym
  width                = options[:width]           || 12
  css_class            = options[:css_class]       || "ipmclickempty"
  
  if User.current.allowed_to?(edit_permission, project) && (model.respond_to?(:editable?) ? model.editable? : true)
    ( 
      "div", 
      value.to_s.split(/;|,|\ /).select(&:present?).join(", "),
      :field      => column.name.to_s,
      :id         => "#{denominator}-#{model.id}-#{column.name.to_s}",
      :onclick    => "editTextField(this, '#{send(update_function, project.identifier, model)}', #{width}); return false;",
      :class      => css_class
    )
  elsif User.current.allowed_to?(view_permission, project) 
    ( 
      "div", 
      value.to_s.split(/;|,|\ /).select(&:present?).join(", "),
      :id         => "#{denominator}-#{model.id}-#{column.name.to_s}",
    )
  else
    ( 
      "div", 
      "---x---",
      :id         => "#{denominator}-#{model.id}-#{column.name.to_s}"
    )
  end #if
end

#hbl_edit_string_tag(column, model, value, options = {}) ⇒ Object


edit tags for inline editing

require: 
           update_field_of_project_#{model}_path or options[:update_function]
           edit_#{models} as permission           or options[:edit_permissions]
           view_#{models} as permission           or options[:view_permissions]


462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
# File 'lib/hbl_tags/tags_helper.rb', line 462

def hbl_edit_string_tag( column, model, value, options={} )
  
  klass                = options[:class]           || model.class
  denominator          = klass.name.underscore
  
  project              = model.project             || @project 
  view_permission      = options[:view_permission] || "view_#{denominator.pluralize}".to_sym
  edit_permission      = options[:edit_permission] || "edit_#{denominator.pluralize}".to_sym
  update_function      = options[:update_function] || "update_field_of_project_#{denominator}_path".to_sym
  width                = options[:width]           || 12
  value_representation = options[:value]           || value
  style                = options[:style]           || ""
  css_class            = options[:css_class]       || "ipmclickempty"
  data_text            = options[:data_text]       || "\xE2\x80\x8B" # zero width space
  
  if User.current.allowed_to?(edit_permission, project) && (model.respond_to?(:editable?) ? model.editable? : true)
    ( 
      "div", 
      value_representation,
      :field      => column.name.to_s,
      :id         => "#{denominator}-#{model.id}-#{column.name.to_s}",
      :onclick    => "editTextField(this, '#{send(update_function, project.identifier, model)}', #{width}); return false;",
      :class      => css_class,
      :content_editable => true,
      :data       => {:text => data_text}, # placeholder text
      :style      => style
    )
  elsif User.current.allowed_to?(view_permission, project) 
    ( 
      "div", 
      value_representation,
      :id         => "#{column.name.to_s}_#{model.id}"
    )
  else
    ( 
      "div", 
      "---x---",
      :id         => "#{denominator}-#{model.id}-#{column.name.to_s}"
    )
  end #if
end

#hbl_edit_text_tag(column, model, value, options = {}) ⇒ Object


creates an edit text tag



546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
# File 'lib/hbl_tags/tags_helper.rb', line 546

def hbl_edit_text_tag( column, model, value, options={} )

  klass                = options[:class]           || model.class
  denominator          = klass.name.underscore
  
  project              = model.project             || @project 
  view_permission      = options[:view_permission] || "view_#{denominator.pluralize}".to_sym
  edit_permission      = options[:edit_permission] || "edit_#{denominator.pluralize}".to_sym
  update_function      = options[:update_function] || "update_field_of_project_#{denominator}_path".to_sym
  height               = options[:height]          || 5
  value_representation = options[:value]           || value
  css_class            = options[:css_class]       || "ipmclickempty"
  inner_css_class      = options[:inner_css_class] || "ipmclickpre"
  
  if User.current.allowed_to?(edit_permission, project) && (model.respond_to?(:editable?) ? model.editable? : true)
    ( 
      "div", 
      value_representation,
      #content_tag("pre", value_representation, :class => inner_css_class),
      :field      => column.name.to_s,
      :id         => "#{denominator}-#{model.id}-#{column.name.to_s}",
      :onclick    => "editTextAreaField(this, '#{send(update_function, project.identifier, model)}', #{height}); return false;",
      :class      => css_class
    )
  elsif User.current.allowed_to?(view_permission, project) 
    ( 
      "div", 
      value_representation,
      :id         => "#{column.name.to_s}_#{model.id}"
    )
  else
    ( 
      "div", 
      "---x---",
      :id         => "#{denominator}-#{model.id}-#{column.name.to_s}"
    )
  end #if
end

#hbl_email_field(f, model, field, editable, options = {}) ⇒ Object


creates an email address field



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/hbl_tags/tags_helper.rb', line 189

def hbl_email_field( f, model, field, editable, options = {} )
 date_field_options = options.deep_dup
 date_field_options[:label] = label_text(model, field)
 date_field_options[:placeholder] = placeholder(field, model, options)
 date_field_options[:size] ||= 32
 date_field_options[:disabled] ||= !editable
 (:div, :class => ("flash error"  if !model.errors[field].empty? ) ) do
    (:p ) do
      f.email_field( field, date_field_options.compact ) + 
      if @bulk && !date_field_options[:nobulk]
        name = model.class.name.underscore
        check_box_tag( "#{name}[#{field}]", "none", (model.send(field) == 'none'), :id => nil, :disabled => !editable, :class => 'inline', :data => {:disables => "##{name}_#{field}"} ) + tag(:span, :class=>"icon icon-del")
      end.to_s + 
      (:a, :href =>'#', :class => 'icon icon-help', :title => l(:label_help), :onclick => "$('##{help_tag_id(model, field)}').toggle(); return false;" ) do
        l(:label_help)
      end + 
      tag(:br ) +
      (:span, :id => "#{help_tag_id(model, field)}", :class => "info", :style => "display:none;" ) do
        (:em, :class => "info") do
          help_text(model, field)
        end
      end
    end
  end
end

#hbl_file_field(f, model, field, editable, options = {}) ⇒ Object


creates a file select field



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/hbl_tags/tags_helper.rb', line 78

def hbl_file_field( f, model, field, editable, options = {} )
  file_field_options = options.deep_dup
  file_field_options[:label] = label_text(model, field)
  file_field_options[:disabled] ||= !editable
  (:div, :class => ("flash error"  if !model.errors[field].empty? ) ) do
    (:p ) do
      f.file_field( field, file_field_options.compact ) + 
      (:a, :href =>'#', :class => 'icon icon-help', :title => l(:label_help), :onclick => "$('##{help_tag_id(model, field)}').toggle(); return false;" ) do
        l(:label_help)
      end + 
      tag(:br ) +
      (:span, :id => "#{help_tag_id(model, field)}", :class => "info", :style => "display:none;" ) do
        (:em, :class => "info") do
          help_text(model, field)
        end
      end
    end
  end
end

#hbl_hidden_field(f, field, options = {}) ⇒ Object


creates a hidden field



360
361
362
# File 'lib/hbl_tags/tags_helper.rb', line 360

def hbl_hidden_field( f, field, options={})
  f.hidden_field( field, options )
end

#hbl_password_field(f, model, field, editable, options = {}) ⇒ Object


creates a password field



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/hbl_tags/tags_helper.rb', line 130

def hbl_password_field( f, model, field, editable, options = {} )
 text_field_options = options.deep_dup
 text_field_options[:label] = label_text(model, field)
 text_field_options[:value] = model.send(field.to_sym) unless text_field_options[:novalue]
 text_field_options[:placeholder] = placeholder(field, model, options)
 text_field_options[:size] ||= 32
 text_field_options[:disabled] ||= !editable
 (:div, :class => ("flash error"  if !model.errors[field].empty? ) ) do
    (:p ) do
      f.password_field( field, text_field_options.compact ) + 
      if @bulk && !text_field_options[:nobulk]
        name = model.class.name.underscore
        check_box_tag( "#{name}[#{field}]", "none", (model.send(field) == 'none'), :id => nil, :disabled => !editable, :class => 'inline', :data => {:disables => "##{name}_#{field}"} ) + tag(:span, :class=>"icon icon-del")
      end.to_s + 
      (:a, :href =>'#', :class => 'icon icon-help', :title => l(:label_help), :onclick => "$('##{help_tag_id(model, field)}').toggle(); return false;" ) do
        l(:label_help)
      end + 
      tag(:br ) +
      (:span, :id => "#{help_tag_id(model, field)}", :class => "info", :style => "display:none;" ) do
        (:em, :class => "info") do
          help_text(model, field)
        end
      end
    end
  end
end

#hbl_select_field(f, model, field, values, options = {}, html_options = {}) ⇒ Object


creates a select drop down menu



306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'lib/hbl_tags/tags_helper.rb', line 306

def hbl_select_field( f, model, field, values, options={}, html_options={})
  select_field_options = options.deep_dup
  select_field_options[:label] = label_text(model, field)
  select_field_options[:disabled] ||= !options[:editable]
  
  if @bulk && !select_field_options[:nobulk] 
    pvalue = placeholder(field, model, options)
    option_label = values.map{|l,v| l if v == pvalue }.compact.first
    values.unshift([(l(:label_no_change_option) + " #{option_label}").html_safe, ''])
  end
  
  (:div, :class => ("flash error"  if !model.errors[field].empty? ) ) do
    (:p ) do
      f.select( field, values, select_field_options.compact, html_options ) + 
      (:a, :href =>'#', :class => 'icon icon-help', :title => l(:label_help), :onclick => "$('##{help_tag_id(model, field)}').toggle(); return false;" ) do
        l(:label_help)
      end + 
      tag(:br ) +
      (:span, :id => "#{help_tag_id(model, field)}", :class => "info", :style => "display:none;" ) do
        (:em, :class => "info") do
          help_text(model, field)
        end
      end
    end
  end
end

#hbl_tagged_fields_hash(f, model, field, editable, options = {}) ⇒ Object


creates a tagged field



367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
# File 'lib/hbl_tags/tags_helper.rb', line 367

def hbl_tagged_fields_hash(f, model, field, editable, options={} )
 tagged_fields_options = options.deep_dup
 tagged_fields_options[:label] = label_text(model, field)
 tagged_fields_options[:size] ||= 32
 tagged_fields_options[:disabled] ||= !editable
 (:div, :class => ("flash error"  if !model.errors[field].empty? ) ) do
    tags = model.send(field).map do |k, v|
      case v.class.name
      when "Array"
        v.map do |av|
          (:p ) do
            (:label, get_tagged_fields_hash_name(model, k)) + 
            text_field_tag( "[#{model.class.name.underscore}][#{field}][#{k}][]", av, tagged_fields_options ) +
            (editable ? (:a, "", :href=>"#", :class=>"icon icon-del", :onclick=>"$(this).parent().remove();" ) : "")
          end
        end.join("\n").html_safe
      else
        (:p ) do
          (:label, get_tagged_fields_hash_name(model, k)) +
          text_field_tag( "[#{model.class.name.underscore}][#{field}][#{k}]", v, tagged_fields_options ) +
          (editable ? (:a, "", :href=>"#", :class=>"icon icon-del", :onclick=>"$(this).parent().remove();" ) : "")
        end
      end
    end
    tags.join("\n").html_safe
  end
end

#hbl_tagged_fields_selector(project, model, field, tag_id, editable) ⇒ Object



435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
# File 'lib/hbl_tags/tags_helper.rb', line 435

def hbl_tagged_fields_selector(project, model, field, tag_id, editable )
  tagged_fields = TaggedField.of(project)
  mod           = model.class.name.underscore
  (:p) do
    (:label, l(:label_new_tagged_field)) +
    select_tag(
      "tagged_field_selector", 
      options_for_select([[l(:label_select_tagged_field),""]] + tagged_fields.collect{ |u| [u.name, u.identifier] } ),
      :onchange => "hbl_append_tagged_field('#{add_project_tagged_fields_path(project,:m=>mod,:f=>field,:t=>tag_id)}&identifier='+this.value);this.selectedIndex = 0;hbl_update_selector_field();".html_safe,
      :disabled => !editable
    ) + 
    (:script) do
      HBL_ADD_TAG_SCRIPT.html_safe + 
      "formElementPrefix='_#{escape_javascript mod}_#{escape_javascript field.to_s}_';\n".html_safe +
      "$(function() {hbl_update_selector_field();});"
    end
  end
end

#hbl_telephone_field(f, model, field, editable, options = {}) ⇒ Object


creates a telephone numer field



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/hbl_tags/tags_helper.rb', line 218

def hbl_telephone_field( f, model, field, editable, options = {} )
 field_options = options.deep_dup
 field_options[:label] = label_text(model, field)
 field_options[:placeholder] = placeholder(field, model, options)
 field_options[:size] ||= 32
 field_options[:disabled] ||= !editable
 (:div, :class => ("flash error"  if !model.errors[field].empty? ) ) do
    (:p ) do
      f.telephone_field( field, field_options.compact ) + 
      if @bulk && !field_options[:nobulk]
        name = model.class.name.underscore
        check_box_tag( "#{name}[#{field}]", "none", (model.send(field) == 'none'), :id => nil, :disabled => !editable, :class => 'inline', :data => {:disables => "##{name}_#{field}"} ) + tag(:span, :class=>"icon icon-del")
      end.to_s + 
      (:a, :href =>'#', :class => 'icon icon-help', :title => l(:label_help), :onclick => "$('##{help_tag_id(model, field)}').toggle(); return false;" ) do
        l(:label_help)
      end + 
      tag(:br ) +
      (:span, :id => "#{help_tag_id(model, field)}", :class => "info", :style => "display:none;" ) do
        (:em, :class => "info") do
          help_text(model, field)
        end
      end
    end
  end
end

#hbl_text_area_field(f, model, field, editable, options = {}) ⇒ Object


creates a text area



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/hbl_tags/tags_helper.rb', line 276

def hbl_text_area_field( f, model, field, editable, options = {} )
 text_area_options = options.deep_dup
 text_area_options[:label] = label_text(model, field)
 text_area_options[:placeholder] = placeholder(field, model, options)
 text_area_options[:rows] ||= 4
 text_area_options[:cols] ||= 29
 text_area_options[:disabled] ||= !editable
  (:div, :class => ("flash error"  if !model.errors[field].empty? ) ) do
    (:p ) do
      f.text_area( field, text_area_options.compact ) + 
      if @bulk && !text_area_options[:nobulk]
        name = model.class.name.underscore
        check_box_tag( "#{name}[#{field}]", "none", (model.send(field) == 'none'), :id => nil, :disabled => !editable, :class => 'inline', :data => {:disables => "##{name}_#{field}"} ) + tag(:span, :class=>"icon icon-del")
      end.to_s + 
      (:a, :href =>'#', :class => 'icon icon-help', :title => l(:label_help), :onclick => "$('##{help_tag_id(model, field)}').toggle(); return false;" ) do
        l(:label_help)
      end + 
      tag(:br ) +
      (:span, :id => "#{help_tag_id(model, field)}", :class => "info", :style => "display:none;" ) do
        (:em, :class => "info") do
          help_text(model, field)
        end
      end
    end
  end
end

#hbl_text_field(f, model, field, editable, options = {}) ⇒ Object


creates a text field



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/hbl_tags/tags_helper.rb', line 101

def hbl_text_field( f, model, field, editable, options = {} )
 text_field_options = options.deep_dup
 text_field_options[:label] = label_text(model, field)
 text_field_options[:placeholder] = placeholder(field, model, options)
 text_field_options[:size] ||= 32
 text_field_options[:disabled] ||= !editable
 (:div, :class => ("flash error"  if !model.errors[field].empty? ) ) do
    (:p ) do
      f.text_field( field, text_field_options.compact ) +
      if @bulk && !text_field_options[:nobulk]
        name = model.class.name.underscore
        check_box_tag( "#{name}[#{field}]", "none", (model.send(field) == 'none'), :id => nil, :disabled => !editable, :class => 'inline', :data => {:disables => "##{name}_#{field}"} ) + tag(:span, :class=>"icon icon-del")
      end.to_s + 
      (:a, :href =>'#', :class => 'icon icon-help', :title => l(:label_help), :onclick => "$('##{help_tag_id(model, field)}').toggle(); return false;" ) do
        l(:label_help)
      end + 
      tag(:br ) +
      (:span, :id => "#{help_tag_id(model, field)}", :class => "info", :style => "display:none;" ) do
        (:em, :class => "info") do
          help_text(model, field)
        end
      end
    end
  end
end

#help_tag_id(model, field) ⇒ Object

def



619
620
621
622
# File 'lib/hbl_tags/tags_helper.rb', line 619

def help_tag_id(model, field)
  stem = field.to_s.gsub(/_id\z/, "")
  "help_#{model.class.name.demodulize.underscore}_#{stem}_#{model.id}"
end

#help_text(model, field) ⇒ Object

def



624
625
626
627
# File 'lib/hbl_tags/tags_helper.rb', line 624

def help_text(model, field)
  stem = field.to_s.gsub(/_id\z/, "")
  hbl_label( "help_#{stem}".to_sym, model )
end

#ipm_iframe_tag(path, title, id, options = {}) ⇒ Object


creates an iframe tag



589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
# File 'lib/hbl_tags/tags_helper.rb', line 589

def ipm_iframe_tag(path, title, id, options={})

  (:div, 
    (
      :iframe,
      "",
      { :src                  => path,
        :id                   => id,
        :title                => title,
        :frameborder          => "0",
        :scrolling            => "no",
        :allowtransparency    => "true",
        :seamless             => "seamless",
        :style                => "width:100%;height:16px;",
        :onload               => "resizeIframe(this);"
       }
    ),
    options
  )
end

#label_text(model, field) ⇒ Object

def



629
630
631
632
# File 'lib/hbl_tags/tags_helper.rb', line 629

def label_text(model, field)
  stem = field.to_s.gsub(/_id\z/, "")
  hbl_label( "field_#{stem}".to_sym, model )
end

#placeholder(field, model, options = {}) ⇒ Object

get placeholder value in the following hierarchy:

  1. options

  2. an instance variable containing a model named #HBLTags::TagsHelper.modelmodel.classmodel.class.namemodel.class.name.underscore_placeholder

  3. an instance variable with a hash contaning attributes with placeholders name #HBLTags::TagsHelper.modelmodel.classmodel.class.namemodel.class.name.underscore_attributes

  4. preset values from init.rb



641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
# File 'lib/hbl_tags/tags_helper.rb', line 641

def placeholder( field, model, options={} )

  placeholder   = options[:placeholder]
  name          = "#{model.class.name.underscore}"
  attr_model    = instance_variable_get("@#{name}_placeholder")
  attr_hash     = instance_variable_get("@#{name}_attributes")
  
  name          = "#{model.class.base_class.name.underscore}"
  attr_model  ||= instance_variable_get("@#{name}_placeholder")
  attr_hash   ||= instance_variable_get("@#{name}_attributes")
  
  placeholder ||= (attr_model && attr_model.send(field) rescue "__error__")
  placeholder ||= attr_hash.symbolize_keys[field.to_sym] if attr_hash.is_a?(Hash)
  placeholder ||= I18n.translate( "#{model.class.name.underscore}.#{field}".to_sym )
  
  placeholder
end

#project_tree_options_array(projects, options = {}) ⇒ Object

def



659
660
661
662
663
664
665
666
667
668
669
670
671
672
# File 'lib/hbl_tags/tags_helper.rb', line 659

def project_tree_options_array(projects, options = {})
  s = []
  if blank_text = options[:include_blank]
    if blank_text == true
      blank_text = '&nbsp;'.html_safe
    end
    s << [blank_text, '']
  end
  Project.project_tree(projects) do |project, level|
    name_prefix = (level > 0 ? '&nbsp;' * 2 * level + '&#187; ' : '').html_safe
    s << [name_prefix + h(project), project.id]
  end
  s
end