viewer_helper.rb
7.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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
126
127
128
129
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
module PairwisePlugin::Helpers::ViewerHelper
def choose_link(direction, pairwise_content, question, prompt, embeded = false, source = nil, appearance_id = nil)
link_target = { :controller => 'pairwise_plugin_profile',
:profile => pairwise_content.profile.identifier,
:action => 'choose', :id => pairwise_content.id, :question_id => question.id , :prompt_id => prompt.id,
:choice_id => prompt.send("#{direction}_choice_id"), :direction => direction, :appearance_id => appearance_id}
link_target.merge!(:embeded => 1) if embeded
link_target.merge!(:source => source) if source
loading_javascript = pairwise_spinner_show_function_call(pairwise_content) + pairwise_hide_skip_call(pairwise_content)
content_tag(:div, prompt.send("#{direction}_choice_text"), :class => 'choice-text') +
link_to_remote(_('Vote'), :loading => loading_javascript, :url => link_target, :html => {:class => 'vote-link'})
end
def choose_right_link(pairwise_content, question, prompt, embeded = false, source = nil, appearance_id = nil)
choose_link('right', pairwise_content, question, prompt, embeded, source, appearance_id)
end
def choose_left_link(pairwise_content, question, prompt, embeded = false, source = nil, appearance_id = nil)
choose_link('left', pairwise_content, question, prompt, embeded, source, appearance_id)
end
def skip_vote_open_function(pairwise_content)
link_to_function _('Skip vote'), "jQuery('#skip_vote_reasons_#{pairwise_content.id}').slideToggle()"
end
def skip_vote_link(pairwise_content, question, prompt, embeded = false, source = nil, appearance_id = nil, reason = nil)
link_target = {:controller => 'pairwise_plugin_profile',
:profile => pairwise_content.profile.identifier,
:action => 'skip_prompt', :id => pairwise_content.id,:question_id => question.id , :prompt_id => prompt.id,
:appearance_id => appearance_id}
link_target.merge!(:embeded => 1) if embeded
link_target.merge!(:source => source) if source
link_target.merge!(:appearance_id => appearance_id) if appearance_id
link_target.merge!(:reason => reason) if reason
link_text = reason ? reason : _('Skip vote')
if reason
loading_javascript = pairwise_spinner_show_function_call(pairwise_content) + pairwise_hide_skip_call(pairwise_content)
"<li class='skip_vote_item'>" + link_to_remote(link_text, :loading => loading_javascript, :url => link_target) + "</li>"
else
link_to_remote(link_text, link_target)
end
end
def pairwise_spinner_id(pairwise_content)
return "pairwise_spinner#{pairwise_content.id}"
end
def pairwise_spinner(pairwise_content)
text = content_tag :h5, _('Processing... please wait.')
content_tag :div, text, :class => "spinner", :id => pairwise_spinner_id(pairwise_content)
end
def pairwise_spinner_show_function_call(pairwise_content)
pairwise_spinner_show_function_name(pairwise_content) + "();"
end
def pairwise_hide_skip_call(pairwise_content)
"jQuery('#skip_vote_reasons_#{pairwise_content.id}').hide();"
end
def pairwise_spinner_show_function_name(pairwise_content)
"jQuery('##{pairwise_spinner_id(pairwise_content)}').fadeIn"
end
def pairwise_spinner_hide_function_call(pairwise_content)
pairwise_spinner_hide_function_name(pairwise_content) + "();"
end
def pairwise_spinner_hide_function_name(pairwise_content)
"jQuery('##{pairwise_spinner_id(pairwise_content)}').fadeOut"
end
def pairwise_user_identifier(user)
if user.nil?
is_external_vote ? "#{params[:source]}-#{request.session_options[:id]}" : "participa-#{request.session_options[:id]}"
else
user.identifier
end
end
def pairwise_embeded_code(pairwise_content)
embeded_url = url_for({:controller => "pairwise_plugin_profile",
:profile => pairwise_content.profile.identifier,
:action => "prompt",
:id => pairwise_content.id,
:question_id => pairwise_content.question.id,
:embeded => 1,
:source => "SOURCE_NAME",
:only_path => false})
embeded_code = "<iframe src='#{embeded_url}' style='width:100%;height:400px' frameborder='0' allowfullscreen ></iframe>"
label = "<hr/>"
label += content_tag :h5, _('Pairwise Embeded')
textarea = text_area_tag 'embeded_code', embeded_code, {:style => "width: 100%; background-color: #ccc; font-weight:bold", :rows => 7}
hint = content_tag :quote, _("You can put this iframe in your site. Replace <b>source</b> param with your site address and make any needed adjusts in width and height.")
label + textarea + hint + "<hr/>"
end
def pairwise_edit_link(label, pairwise_content)
link_target = myprofile_path(:controller => :cms, :profile => pairwise_content.profile.identifier, :action => :edit, :id => pairwise_content.id)
link_to label, link_target
end
def pairwise_result_link(label, pairwise_content, embeded = false, options = {})
link_target = pairwise_content.result_url
link_target.merge!(:embeded => 1) if embeded
link_to label, link_target, options
end
def pairwise_tab_remote_link(label, link_target, pairwise_content, embeded = false, options = {})
link_target.merge!(:embeded => 1) if embeded
loading_javascript = pairwise_spinner_show_function_call(pairwise_content) + pairwise_hide_skip_call(pairwise_content)
link_to_remote label, :loading => loading_javascript, :url => link_target, :html => options
end
def pairwise_suggestion_url(question, embeded = false, source = nil)
target = { :controller => :pairwise_plugin_profile, :profile => question.profile.identifier,:action => 'suggest_idea', :id => question.id }
target.merge!({ :embeded => 1 }) if embeded
target.merge!({ :source => source }) if source
target
end
def is_external_vote
params.has_key?("source") && !params[:source].empty?
end
def ideas_management_link(label, pairwise_content, user)
return "" unless user
return "" unless pairwise_content.allow_edit?(user)
link_to label, :controller => :pairwise_plugin_suggestions, :profile => pairwise_content.profile.identifier, :action => :index, :id => pairwise_content.id
end
def has_param_pending_choices?
params.has_key?("pending") && "1".eql?(params[:pending])
end
def has_param_reproved_choices?
params.has_key?("reproved") && "1".eql?(params[:reproved])
end
def choices_showing_text
ideas_or_suggestions_text = has_param_pending_choices? ? "Suggestions" : "Ideas"
_("Showing") + " " + ideas_or_suggestions_text
end
def pairwise_span_arrow(index)
content_tag :span, '', :class => (index == 0 ? 'active' : '')
end
def pairwise_group_row_classes(index)
index == 0 ? 'row' : 'row secondary'
end
def pairwise_group_content_body(index, pairwise_content, prompt_id = nil)
style = (index > 0) ? 'display:none' : ''
content_tag :div, :class => "pairwise_inner_body", :id => "pairwise_inner_body_#{pairwise_content.id}", :style => style do
render :partial => 'content_viewer/prompt_body',
:locals => {
:embeded => params[:embeded],
:source => params[:source],
:pairwise_content => pairwise_content,
:question => nil
}
end
end
end