Module: SourcesHelper

Defined in:
app/helpers/sources_helper.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) add_source_to_project_form(source)



47
48
49
50
51
52
53
54
55
56
57
# File 'app/helpers/sources_helper.rb', line 47

def add_source_to_project_form(source)
  if !source_in_project?(source)
    form_for(ProjectSource.new(source_id: source.to_param, project_id: sessions_current_project_id) , remote: true) do |f|
      f.hidden_field(:source_id) +
        f.hidden_field(:project_id) +
        f.submit('Add to project') 
    end
  else
    button_to('Remove from project', project_source_path(project_source_for_source(source)), method: :delete, remote: true) 
  end
end

- (Object) project_source_for_source(source)



59
60
61
# File 'app/helpers/sources_helper.rb', line 59

def project_source_for_source(source)
  ProjectSource.find_by(source_id: source.to_param, project_id: sessions_current_project_id)
end

- (Object) source_attributes_for(source)



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/helpers/sources_helper.rb', line 17

def source_attributes_for(source)
  w = (:em, 'ERROR, unkown class of Source, contact developers', class: :warning)  
  content_for :attributes do
    case source.class.name 
    when 'Source::Bibtex' 
      render '/sources/bibtex/attributes'
    when 'Source::Verbatim'
      render '/sources/verbatim/attributes'
    when 'Source::Source'
      w 
    else
      w
    end
  end
end

- (Boolean) source_in_other_project?(source)

Returns:

  • (Boolean)


67
68
69
# File 'app/helpers/sources_helper.rb', line 67

def source_in_other_project?(source)
  source.project_sources.where.not(project_id: sessions_current_project_id).references(:projects_sources).any?
end

- (Boolean) source_in_project?(source)

Returns:

  • (Boolean)


63
64
65
# File 'app/helpers/sources_helper.rb', line 63

def source_in_project?(source)
  ProjectSource.exists?(project_id: sessions_current_project_id, source_id: source.to_param)
end


12
13
14
15
# File 'app/helpers/sources_helper.rb', line 12

def source_link(source)
  return nil if source.nil?
  link_to(source_tag(source).html_safe, source.metamorphosize )
end

- (Object) source_nomenclature_tag(source, topics)



71
72
73
74
75
76
# File 'app/helpers/sources_helper.rb', line 71

def source_nomenclature_tag(source, topics)
  t = [source_tag(source)]
  t.push [':', topic_list_tag(topics).html_safe] if !topics.blank?
  t.push link_to('', nomenclature_by_source_task_path(source), class: 'separate-left', data: {icon: 'link'}, target: :_blank)
  t.flatten.compact.join(' ').html_safe
end


33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/helpers/sources_helper.rb', line 33

def source_related_attributes(source)
  content_for :related_attributes do
     if source.class.name == 'Source::Bibtex'
        (:h3, 'Authors') do
          (:ul) do
            source.authors.collect{|a| (:li, a.last_name)} 
          end
        end
     else

     end
  end
end

- (Object) source_tag(source)



3
4
5
6
# File 'app/helpers/sources_helper.rb', line 3

def source_tag(source)
  return nil if source.nil?
  source.cached ? source.cached : (source.new_record? ? nil : 'ERROR - Source cache not set, please notify admin.')
end

- (Object) sources_search_form



8
9
10
# File 'app/helpers/sources_helper.rb', line 8

def sources_search_form
  render('/sources/quick_search_form')
end