Permalink
Browse files

Merge branch 'cms-learning-plugin' into ecosol

Conflicts:
	public/stylesheets/token-input.css
  • Loading branch information...
2 parents 16e88c1 + 87dc6b5 commit c4770731514069d5db169763226512cfc4482462 @brauliobo brauliobo committed Apr 10, 2012
Showing with 3,128 additions and 15 deletions.
  1. +2 −1 app/controllers/my_profile/cms_controller.rb
  2. +2 −0 app/controllers/my_profile/profile_design_controller.rb
  3. +4 −0 app/models/article.rb
  4. +4 −0 app/models/enterprise_homepage.rb
  5. +4 −0 app/models/event.rb
  6. +4 −0 app/models/text_article.rb
  7. +1 −1 app/views/cms/edit.rhtml
  8. +3 −0 app/views/profile_editor/_organization.rhtml
  9. +19 −13 app/views/shared/_lead_and_body.rhtml
  10. +6 −0 lib/noosfero/plugin.rb
  11. +22 −0 plugins/cms_learning/controllers/cms_learning_plugin_myprofile_controller.rb
  12. +18 −0 plugins/cms_learning/db/migrate/20111010183943_create_article_resources.rb
  13. +40 −0 plugins/cms_learning/lib/cms_learning_plugin.rb
  14. +29 −0 plugins/cms_learning/lib/cms_learning_plugin/learnings_block.rb
  15. +10 −0 plugins/cms_learning/models/article_resource.rb
  16. +97 −0 plugins/cms_learning/models/cms_learning_plugin_learning.rb
  17. BIN plugins/cms_learning/public/images/cms-learning-16x16.png
  18. BIN plugins/cms_learning/public/images/cms-learning-64x64.png
  19. +2,577 −0 plugins/cms_learning/public/images/cms-learning.svg
  20. +50 −0 plugins/cms_learning/public/style.css
  21. +8 −0 plugins/cms_learning/test/unit/article_resource_test.rb
  22. +9 −0 plugins/cms_learning/views/blocks/cms_learning_plugin/learnings_block.html.erb
  23. +38 −0 plugins/cms_learning/views/cms/_cms_learning_plugin_learning.rhtml
  24. +35 −0 plugins/cms_learning/views/cms/cms_learning_plugin_page.rhtml
  25. +27 −0 plugins/cms_learning/views/search/_cms_learning_plugin_learning.rhtml
  26. +119 −0 public/stylesheets/token-input-cms-learning.css
@@ -37,6 +37,7 @@ def available_article_types
]
articles += special_article_types if params && params[:cms]
parent_id = params ? params[:parent_id] : nil
+
if profile.enterprise?
articles << EnterpriseHomepage
end
@@ -328,7 +329,7 @@ def check_parent(id)
end
def refuse_blocks
- if ['TinyMceArticle', 'TextileArticle', 'Event', 'EnterpriseHomepage'].include?(@type)
+ if !type.blank? and @type.constantize.new.use_media_panel?
@no_design_blocks = true
end
end
@@ -42,6 +42,8 @@ def available_blocks
blocks << RawHTMLBlock
end
+ blocks += @plugins.map(:profile_blocks, profile)
+
blocks
end
View
@@ -261,6 +261,10 @@ def allow_children?
true
end
+ def use_media_panel?
+ false
+ end
+
def folder?
false
end
@@ -25,4 +25,8 @@ def can_display_hits?
false
end
+ def use_media_panel?
+ true
+ end
+
end
View
@@ -112,6 +112,10 @@ def to_html(options = {})
result
end
+ def use_media_panel?
+ true
+ end
+
def event?
true
end
@@ -13,4 +13,8 @@ def self.icon_name(article = nil)
end
end
+ def use_media_panel?
+ true
+ end
+
end
View
@@ -49,7 +49,7 @@
<% end %>
</div>
-<% if environment.enabled?('media_panel') && [TinyMceArticle, TextileArticle, Event, EnterpriseHomepage].any?{|klass| @article.kind_of?(klass)} %>
+<% if environment.enabled?('media_panel') and @article.use_media_panel? %>
<%= render :partial => 'text_editor_sidebar' %>
<% end %>
@@ -1,9 +1,12 @@
+<% extend FormerPlugin::FieldHelper %>
<h2><%= _('General information') %></h2>
<%= required_fields_message %>
<%= required f.text_field(:name) %>
+ <%= widgets_for_form(f, :bsc_fields) %>
+
<% if @environment.enabled?('enable_organization_url_change') %>
<script type="text/javascript">
function updateUrlField(name_field, id) {
@@ -1,28 +1,34 @@
<% object ||= :article %>
+<% abstract = true if abstract.nil? %>
<% abstract_label ||= 'Lead' %>
<% abstract_method ||= :abstract %>
+<% body_required ||= false %>
<% body_label ||= 'Text' %>
<% body_method ||= :body %>
<% editor_type = defined?(tiny_mce) && tiny_mce ? 'mceEditor' : '' %>
<% lead_id ||= 0%>
<% f ||= false%>
-<br style="clear: both;"/>
-<%= button :add, _("Lead"), '#', :class => "lead-button", :article_id => "#article-lead-"+lead_id.to_s, :style => "margin-left: 0px;" %>
-<em><%= _('Used when a short version of your text is needed.') %></em>
+<% if abstract %>
+ <br style="clear: both;"/>
+ <%= button :add, _("Lead"), '#', :class => "lead-button", :article_id => "#article-lead-"+lead_id.to_s, :style => "margin-left: 0px;" %>
+ <em><%= _('Used when a short version of your text is needed.') %></em>
-<div class='article-lead' id="article-lead-<%=lead_id.to_s%>">
+ <div class='article-lead' id="article-lead-<%=lead_id.to_s%>" style="margin-bottom: 10px;">
+ <% if f %>
+ <%= labelled_form_field(_(abstract_label), f.text_area(abstract_method, :style => 'width: 100%; height: 200px;', :class => editor_type)) %>
+ <% else %>
+ <%= labelled_form_field(_(abstract_label), text_area(object, abstract_method, :style => 'width: 100%; height: 200px;', :class => editor_type)) %>
+ <% end %>
+ </div>
+<% end %>
+<div>
<% if f %>
- <%= labelled_form_field(_(abstract_label), f.text_area(abstract_method, :style => 'width: 98%; height: 200px;', :class => editor_type)) %>
+ <% b = labelled_form_field(_(body_label), f.text_area(body_method, :style => 'width: 100%; height: 400px;', :class => editor_type)) %>
+ <%= body_required ? required(b) : b %>
<% else %>
- <%= labelled_form_field(_(abstract_label), text_area(object, abstract_method, :style => 'width: 98%; height: 200px;', :class => editor_type)) %>
- <% end %>
-</div>
-<div style="margin-top: 10px;">
- <% if f %>
- <%= labelled_form_field(_(body_label), f.text_area(body_method, :style => 'width: 98%; height: 400px;', :class => editor_type)) %>
- <% else %>
- <%= labelled_form_field(_(body_label), text_area(object, body_method, :style => 'width: 98%; height: 400px;', :class => editor_type)) %>
+ <% b = labelled_form_field(_(body_label), text_area(object, body_method, :style => 'width: 100%; height: 400px;', :class => editor_type)) %>
+ <%= body_required ? required(b) : b %>
<% end %>
</div>
View
@@ -186,6 +186,12 @@ def parse_content(raw_content)
def admin_panel_links
nil
end
+
+ # -> Adds new block types in profile
+ # returs = class implements Block
+ def profile_blocks(profile)
+ nil
+ end
# -> Adds buttons to manage members page
# returns = { :title => title, :icon => icon, :url => url }
@@ -0,0 +1,22 @@
+class CmsLearningPluginMyprofileController < MyProfileController
+ append_view_path File.join(File.dirname(__FILE__) + '/../views')
+
+ protect 'edit_profile', :profile
+
+ def product_categories
+ @categories = ProductCategory.all :limit => 20, :conditions => ["name ~* ?", params[:q]]
+ respond_to do |format|
+ format.html
+ format.json { render :json => @categories.collect{ |i| {:id => i.id, :name => i.name } } }
+ end
+ end
+
+ def persons
+ @persons = Person.all :limit => 20, :conditions => ["name ~* ?", params[:q]]
+ respond_to do |format|
+ format.html
+ format.json { render :json => @persons.collect{ |i| {:id => i.id, :name => i.name } } }
+ end
+ end
+end
+
@@ -0,0 +1,18 @@
+class CreateArticleResources < ActiveRecord::Migration
+ def self.up
+ create_table :article_resources do |t|
+ t.integer :article_id
+ t.integer :resource_id
+ t.string :resource_type
+
+ t.timestamps
+ end
+ add_index :article_resources, :article_id
+ add_index :article_resources, :resource_id
+ add_index :article_resources, :resource_type
+ end
+
+ def self.down
+ drop_table :article_resources
+ end
+end
@@ -0,0 +1,40 @@
+class CmsLearningPlugin < Noosfero::Plugin
+
+ def self.plugin_name
+ "CmsLearning"
+ end
+
+ def self.plugin_description
+ _("Share your knowledge to the network.")
+ end
+
+ def self.view_path
+ (RAILS_ROOT + '/plugins/cms_learning/views')
+ end
+
+ def stylesheet?
+ true
+ end
+
+ def js_files
+ []
+ end
+
+ def profile_blocks(profile)
+ CmsLearningPlugin::LearningsBlock
+ end
+
+ def content_types
+ [CmsLearningPluginLearning]
+ end
+
+ def search_controller_filter
+ [{
+ :type => 'before_filter',
+ :method_name => 'append_view_path',
+ :options => {},
+ :block => lambda { @controller.append_view_path CmsLearningPlugin.view_path }
+ }]
+ end
+
+end
@@ -0,0 +1,29 @@
+class CmsLearningPlugin::LearningsBlock < Block
+
+ def self.description
+ _("Profile's Learnigs")
+ end
+
+ def self.short_description
+ _("Profile's Learnigs")
+ end
+
+ def default_title
+ _('Learnings')
+ end
+
+ def help
+ _("This block show learnings of your profile")
+ end
+
+ def content
+ block = self
+ lambda do
+ learnings = CmsLearningPluginLearning.by_profile(block.owner)
+ render :file => 'blocks/cms_learning_plugin/learnings_block',
+ :locals => {:block => block, :learnings => learnings}
+ end
+ end
+
+end
+
@@ -0,0 +1,10 @@
+class ArticleResource < ActiveRecord::Base
+ belongs_to :article
+
+ belongs_to :resource, :polymorphic => true
+ belongs_to :product_category, :class_name => 'ProductCategory', :foreign_key => 'resource_id',
+ :conditions => ['resource_type = ?', 'ProductCategory']
+
+ belongs_to :person, :class_name => 'Person', :foreign_key => 'resource_id',
+ :conditions => ['resource_type = ?', 'Person']
+end
@@ -0,0 +1,97 @@
+class CmsLearningPluginLearning < Article
+
+ settings_items :summary, :type => :string, :default => ""
+ settings_items :good_practices, :type => :string, :default => ""
+
+ has_many :resources, :foreign_key => 'article_id', :order => 'id asc', :class_name => 'ArticleResource', :dependent => :destroy
+ has_many :resources_product_categories, :foreign_key => 'article_id', :order => 'id asc', :class_name => 'ArticleResource',
+ :conditions => ['article_resources.resource_type = ?', 'ProductCategory']
+
+ has_many :resources_persons, :foreign_key => 'article_id', :order => 'id asc', :class_name => 'ArticleResource',
+ :conditions => ['article_resources.resource_type = ?', 'Person']
+
+
+ has_many :product_categories, :through => :resources, :source => :product_category, :foreign_key => 'article_id', :readonly => true,
+ :class_name => 'ProductCategory', :conditions => ['article_resources.resource_type = ?', 'ProductCategory']
+
+ has_many :persons, :through => :resources, :source => :person, :foreign_key => 'article_id', :readonly => true,
+ :class_name => 'Person', :conditions => ['article_resources.resource_type = ?', 'Person']
+
+ attr_accessible :name, :body, :summary, :good_practices, :product_category_string_ids, :person_string_ids
+
+ named_scope :by_profile, lambda { |profile| { :conditions => {:profile_id => profile.id} } }
+
+ def self.type_name
+ _('Learning')
+ end
+
+ def self.short_description
+ _('Learning')
+ end
+
+ def self.description
+ _('Share learnings to the network.')
+ end
+
+ def self.icon_name(article = nil)
+ 'cms-learning'
+ end
+
+ def self.type_name
+ _('Learning')
+ end
+
+ def to_html(options = {})
+ lambda do
+ @controller.append_view_path CmsLearningPlugin.view_path
+ render :file => 'cms/cms_learning_plugin_page'
+ end
+ end
+
+ def default_parent
+ profile.articles.find_by_name _('Learnings'), :conditions => {:type => 'Folder'}
+ end
+
+ def use_media_panel?
+ true
+ end
+
+ def tiny_mce?
+ true
+ end
+
+ def product_category_string_ids
+ ''
+ end
+
+ def person_string_ids
+ ''
+ end
+
+ def product_category_string_ids=(ids)
+ ids = ids.split(',')
+ r = ProductCategory.find(ids)
+ self.resources_product_categories.destroy_all
+ @res_product_categories = ids.collect{ |id| r.detect{ |x| x.id == id.to_i } }.map do |pc|
+ ArticleResource.new :resource_id => pc.id, :resource_type => ProductCategory.name
+ end
+ end
+
+ def person_string_ids=(ids)
+ ids = ids.split(',')
+ r = Person.find(ids)
+ self.resources_persons.destroy_all
+ @res_persons = ids.collect{ |id| r.detect{ |x| x.id == id.to_i } }.map do |pc|
+ ArticleResource.new :resource_id => pc.id, :resource_type => Person.name
+ end
+ end
+
+ protected
+
+ after_save :save_associated
+ def save_associated
+ @res_product_categories.each{ |c| c.article_id = self.id; c.save! } unless @res_product_categories.blank?
+ @res_persons.each{ |p| p.article_id = self.id; p.save! } unless @res_persons.blank?
+ end
+
+end
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.

0 comments on commit c477073

Please sign in to comment.