Commit ab84f010179a6a41004b9a2ff7059cb55a31fa80
1 parent
382d1404
Exists in
master
and in
5 other branches
incomplete_registration: Improving incomplete registration design.
Signed-off-by: David Carlos <ddavidcarlos1392@gmail.com> Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Showing
2 changed files
with
46 additions
and
14 deletions
Show diff stats
lib/mpog_software_plugin.rb
| ... | ... | @@ -150,6 +150,13 @@ class MpogSoftwarePlugin < Noosfero::Plugin |
| 150 | 150 | person.has_permission_without_plugins?(permission, target) |
| 151 | 151 | end |
| 152 | 152 | |
| 153 | + def create_url_to_edit_profile person | |
| 154 | + new_url = person.public_profile_url | |
| 155 | + new_url[:controller] = 'profile_editor' | |
| 156 | + new_url[:action] = 'edit' | |
| 157 | + new_url | |
| 158 | + end | |
| 159 | + | |
| 153 | 160 | def incomplete_registration params |
| 154 | 161 | return if params.nil? or params[:user].nil? |
| 155 | 162 | |
| ... | ... | @@ -159,21 +166,20 @@ class MpogSoftwarePlugin < Noosfero::Plugin |
| 159 | 166 | params[:user] |
| 160 | 167 | end |
| 161 | 168 | |
| 169 | + @profile_edit_link = link_to _("Complete your registration"), "/myprofile/#{person.identifier}/profile_editor/edit" | |
| 170 | + @profile_empty_fields = profile_required_empty_list person | |
| 162 | 171 | @percentege = calc_percentage_registration(person) |
| 172 | + | |
| 163 | 173 | if @percentege >= 0 and @percentege <= 100 |
| 164 | 174 | expanded_template('mpog_software_plugin_myprofile/_incomplete_registration.html.erb') |
| 165 | 175 | end |
| 166 | 176 | end |
| 167 | 177 | |
| 168 | 178 | def calc_percentage_registration person |
| 169 | - empty_fields = 0 | |
| 170 | - required_list = ["cell_phone","contact_phone","institution","comercial_phone","country","city","state","organization_website","role","area_interest","image"] | |
| 171 | - required_list.each do |field| | |
| 172 | - if person.send(field).blank? | |
| 173 | - empty_fields = empty_fields + 1 | |
| 174 | - end | |
| 175 | - end | |
| 176 | - percentege = (empty_fields*100)/required_list.count | |
| 179 | + required_list = profile_required_list | |
| 180 | + empty_fields = profile_required_empty_list person | |
| 181 | + | |
| 182 | + percentege = (empty_fields.count*100)/required_list.count | |
| 177 | 183 | person.percentage_incomplete = percentege |
| 178 | 184 | person.save(validate: false) |
| 179 | 185 | percentege |
| ... | ... | @@ -182,13 +188,10 @@ class MpogSoftwarePlugin < Noosfero::Plugin |
| 182 | 188 | def add_link_to_complete_registration person |
| 183 | 189 | #find a better way to do it |
| 184 | 190 | if context.session[:hide_incomplete_percentage] != true |
| 185 | - new_url = person.public_profile_url | |
| 186 | - new_url[:controller] = 'profile_editor' | |
| 187 | - new_url[:action] = 'edit' | |
| 188 | - | |
| 191 | + _new_url = create_url_to_edit_profile(person) | |
| 189 | 192 | Proc::new do |
| 190 | 193 | content_tag(:div, |
| 191 | - link_to( _("Percentage incomplete: #{person.percentage_incomplete.to_s} %" ), new_url) + | |
| 194 | + link_to( _("Percentage incomplete: #{person.percentage_incomplete.to_s} %" ), _new_url) + | |
| 192 | 195 | link_to(image_tag("/images/icon_filter_exclude.png"), "#", :class => "hide-incomplete-percentage", :alt => "Hide Incomplete Percentage"), :class=>"mpog-incomplete-percentage" |
| 193 | 196 | ) |
| 194 | 197 | end |
| ... | ... | @@ -201,6 +204,22 @@ class MpogSoftwarePlugin < Noosfero::Plugin |
| 201 | 204 | |
| 202 | 205 | protected |
| 203 | 206 | |
| 207 | + def profile_required_list | |
| 208 | + required_list = ["cell_phone","contact_phone","institution","comercial_phone","country","city","state","organization_website","role","area_interest","image"] | |
| 209 | + end | |
| 210 | + | |
| 211 | + def profile_required_empty_list person | |
| 212 | + empty_fields = [] | |
| 213 | + required_list = profile_required_list | |
| 214 | + | |
| 215 | + required_list.each do |field| | |
| 216 | + if person.send(field).blank? | |
| 217 | + empty_fields << field.sub("_"," ") | |
| 218 | + end | |
| 219 | + end | |
| 220 | + empty_fields | |
| 221 | + end | |
| 222 | + | |
| 204 | 223 | def operating_system_transaction |
| 205 | 224 | OperatingSystem.transaction do |
| 206 | 225 | list_operating = OperatingSystemHelper.list_operating_system(context.params[:operating_system]) | ... | ... |
views/mpog_software_plugin_myprofile/_incomplete_registration.html.erb
| 1 | 1 | <div id='incomplete_registration'> |
| 2 | - <%= 'Teste' %> | |
| 2 | +<span> <%= _("Incomplete registration percentage") %>: <%= @percentege %>%</span> | |
| 3 | + | |
| 4 | +<div id="profile_empty_fields"> | |
| 5 | + List with fields to be filled: | |
| 6 | + <ul> | |
| 7 | + <% @profile_empty_fields.each do |field|%> | |
| 8 | + <li> | |
| 9 | + <%= field %> | |
| 10 | + </li> | |
| 11 | + <% end %> | |
| 12 | + </ul> | |
| 13 | +</div> | |
| 14 | + | |
| 15 | +<%= @profile_edit_link %> | |
| 3 | 16 | </div> | ... | ... |