Commit 10f47566eeeb2b89d7a91657c55a26d4c6652bec
Committed by
Paulo Meireles
1 parent
e2a6a002
Exists in
master
and in
28 other branches
[Mezuro] Draft to reading views and controller.
Showing
3 changed files
with
100 additions
and
7 deletions
Show diff stats
plugins/mezuro/controllers/myprofile/mezuro_plugin_reading_controller.rb
0 → 100644
| ... | ... | @@ -0,0 +1,76 @@ |
| 1 | +class MezuroPluginReadingController < MezuroPluginMyprofileController | |
| 2 | + | |
| 3 | + append_view_path File.join(File.dirname(__FILE__) + '/../../views') | |
| 4 | + | |
| 5 | + def new | |
| 6 | + reading_group_content = profile.articles.find(params[:id]) | |
| 7 | + @reading_group_name = reading_group_content.name | |
| 8 | + @data_profile = reading_group_content.profile.identifier | |
| 9 | + @reading_group_content_id = reading_group_content.id | |
| 10 | + end | |
| 11 | + | |
| 12 | + def create | |
| 13 | + reading_group_content = profile.articles.find(params[:id]) | |
| 14 | + | |
| 15 | + reading = Kalibro::Reading.new( params[:reading] ) | |
| 16 | + reading.save(reading_group_content.reading_group_id) | |
| 17 | + | |
| 18 | + if( reading.errors.empty? ) | |
| 19 | + redirect_to "/#{profile.identifier}/#{reading_group_content.name.downcase.gsub(/\s/, '-').gsub(/[^0-9A-Za-z\-]/, '')}" | |
| 20 | + else | |
| 21 | + redirect_to_error_page reading.errors[0].message | |
| 22 | + end | |
| 23 | + end | |
| 24 | + | |
| 25 | + def edit | |
| 26 | + reading_group_content = profile.articles.find(params[:id]) | |
| 27 | + @reading_group_name = reading_group_content.name | |
| 28 | + @data_profile = reading_group_content.profile.identifier | |
| 29 | + @reading_group_content_id = reading_group_content.id | |
| 30 | + | |
| 31 | + @reading_types = Kalibro::Reading.reading_types | |
| 32 | + | |
| 33 | + configurations = Kalibro::Configuration.all | |
| 34 | + configurations = [] if (configurations.nil?) | |
| 35 | + @configuration_select = configurations.map do |configuration| | |
| 36 | + [configuration.name,configuration.id] | |
| 37 | + end | |
| 38 | + | |
| 39 | + @reading = reading_group_content.repositories.select{ |reading| reading.id.to_s == params[:reading_id] }.first | |
| 40 | + end | |
| 41 | + | |
| 42 | + def update | |
| 43 | + reading_group_content = profile.articles.find(params[:id]) | |
| 44 | + | |
| 45 | + reading = Kalibro::Reading.new( params[:reading] ) | |
| 46 | + reading.save(reading_group_content.reading_group_id) | |
| 47 | + | |
| 48 | + if( reading.errors.empty? ) | |
| 49 | + reading.process | |
| 50 | + redirect_to "/profile/#{profile.identifier}/plugin/mezuro/reading/show/#{reading_group_content.id}?reading_id=#{reading.id}" | |
| 51 | + else | |
| 52 | + redirect_to_error_page reading.errors[0].message | |
| 53 | + end | |
| 54 | + end | |
| 55 | + | |
| 56 | + def show | |
| 57 | + reading_group_content = profile.articles.find(params[:id]) | |
| 58 | + @reading_group_name = reading_group_content.name | |
| 59 | + @reading = reading_group_content.repositories.select{ |reading| reading.id.to_s == params[:reading_id] }.first | |
| 60 | + @configuration_name = Kalibro::Configuration.configuration_of(@reading.id).name | |
| 61 | + @data_profile = reading_group_content.profile.identifier | |
| 62 | + @data_content = reading_group_content.id | |
| 63 | + end | |
| 64 | + | |
| 65 | + def destroy | |
| 66 | + reading_group_content = profile.articles.find(params[:id]) | |
| 67 | + reading = reading_group_content.repositories.select{ |reading| reading.id.to_s == params[:reading_id] }.first | |
| 68 | + reading.destroy | |
| 69 | + if( reading.errors.empty? ) | |
| 70 | + redirect_to "/#{profile.identifier}/#{reading_group_content.name.downcase.gsub(/\s/, '-')}" | |
| 71 | + else | |
| 72 | + redirect_to_error_page reading.errors[0].message | |
| 73 | + end | |
| 74 | + end | |
| 75 | + | |
| 76 | +end | ... | ... |
plugins/mezuro/views/content_viewer/show_reading_group.rhtml
| ... | ... | @@ -23,16 +23,13 @@ |
| 23 | 23 | <table> |
| 24 | 24 | <% @page.readings.each do |reading| %> |
| 25 | 25 | <tr> |
| 26 | - <td><%= link_to reading.name, :controller => "mezuro_plugin_reading", | |
| 27 | - :profile => @page.profile.identifier, | |
| 28 | - :action => "show", | |
| 29 | - :id => @page.id, | |
| 30 | - :reading_id => reading.id %></td> | |
| 31 | - <td ><%= link_to _('Edit'), {:controller => "mezuro_plugin_reading", | |
| 26 | + <td><%= link_to reading.label, :controller => "mezuro_plugin_reading", | |
| 32 | 27 | :profile => @page.profile.identifier, |
| 33 | 28 | :action => "edit", |
| 34 | 29 | :id => @page.id, |
| 35 | - :reading_id => reading.id}, :class=>"button with-text icon-edit" %></td> | |
| 30 | + :reading_id => reading.id %></td> | |
| 31 | + <td><%= reading.grade %></td> | |
| 32 | + <td><%= reading.color %></td> | |
| 36 | 33 | <td ><%= link_to _('Remove'), {:controller => "mezuro_plugin_reading", |
| 37 | 34 | :profile => @page.profile.identifier, |
| 38 | 35 | :action => "destroy", | ... | ... |
| ... | ... | @@ -0,0 +1,20 @@ |
| 1 | +<script src="/javascripts/colorpicker.js" type="text/javascript"></script> | |
| 2 | +<script src="/javascripts/colorpicker-noosfero.js" type="text/javascript"></script> | |
| 3 | +<h3> <%= link_to( @reading_group_name, homepage_url(@data_profile, @reading_group_name.downcase.gsub(/[^0-9A-Za-z\-]/, '')) ) %></h3> | |
| 4 | + | |
| 5 | +<% form_for :reading, :url => {:action =>"create", :controller => "mezuro_plugin_reading"}, :method => :get do |f| %> | |
| 6 | + <%= hidden_field_tag :id, @reading_group_content_id %> | |
| 7 | + | |
| 8 | + <%= required labelled_form_field _('label:'), f.text_field(:label) %> | |
| 9 | + | |
| 10 | + <%= required labelled_form_field _('grade:'), | |
| 11 | + f.text_field(:grade) %> | |
| 12 | + | |
| 13 | + <%= required labelled_form_field _('color:'), | |
| 14 | + colorpicker_field(:reading, :color) %>Click in the field to change Color | |
| 15 | + | |
| 16 | + <p> | |
| 17 | + <%= f.submit "Add" %> | |
| 18 | + </p> | |
| 19 | + | |
| 20 | +<% end %> | ... | ... |