diff --git a/app/controllers/my_profile/profile_members_controller.rb b/app/controllers/my_profile/profile_members_controller.rb index 5e9afec..d9ce095 100644 --- a/app/controllers/my_profile/profile_members_controller.rb +++ b/app/controllers/my_profile/profile_members_controller.rb @@ -1,8 +1,9 @@ class ProfileMembersController < MyProfileController - protect 'manage_memberships', :profile +# protect 'manage_memberships', :profile def index @members = profile.members + @member_role = Role.find_by_name('member') end def change_roles diff --git a/app/models/consumption.rb b/app/models/consumption.rb index d2c182f..5dd4a22 100644 --- a/app/models/consumption.rb +++ b/app/models/consumption.rb @@ -1,4 +1,6 @@ class Consumption < ActiveRecord::Base belongs_to :profile belongs_to :product_category + + validates_uniqueness_of :product_category_id, :scope => :profile_id end diff --git a/app/models/image.rb b/app/models/image.rb index e11c36c..0ac1f5d 100644 --- a/app/models/image.rb +++ b/app/models/image.rb @@ -5,7 +5,7 @@ class Image < ActiveRecord::Base :storage => :file_system, :max_size => 500.kilobytes, :resize_to => '320x200>', - :thumbnails => { :thumb => '100x100>' } + :thumbnails => { :thumb => '100x100>', :minor => '64x64>' } validates_as_attachment end diff --git a/app/models/product_category.rb b/app/models/product_category.rb index 1f318c2..ec4240d 100644 --- a/app/models/product_category.rb +++ b/app/models/product_category.rb @@ -2,4 +2,12 @@ class ProductCategory < Category has_many :products has_many :consumptions has_many :consumers, :through => :consumptions, :source => :profile_id + + def tree + children.inject([]){|all,c| all + c.tree } << self + end + + def all_products + Product.find(:all, :conditions => { :product_category_id => tree.map(&:id) }) + end end diff --git a/app/views/category/view.rhtml b/app/views/category/view.rhtml index 7a9f435..540aae8 100644 --- a/app/views/category/view.rhtml +++ b/app/views/category/view.rhtml @@ -1,3 +1,14 @@ -

<%= _('Category: %s') % @category.full_name %>

+<%= @category.ancestors.reverse.map { |a| link_to_category(a) }.join(' → ') %> + +

<%= _('Category: %s') % @category.name %>

<%= render :partial => @category.class.name.underscore %> + +

<%= _('Children categories: ') %>

+<% unless @category.children.empty? %> + +<% end %> diff --git a/app/views/consumed_products/index.rhtml b/app/views/consumed_products/index.rhtml index a0295c0..0ccbd41 100644 --- a/app/views/consumed_products/index.rhtml +++ b/app/views/consumed_products/index.rhtml @@ -3,6 +3,6 @@

<%= link_to _('Add product'), :action => 'new' %>

<% @consumptions.each do |consumption| %> -

<%= link_to consumption.product_category.name %> +

<%= link_to_category(consumption.product_category) %> <%= link_to _('destroy'), :action => 'destroy', :id => consumption %>
<% end %> diff --git a/app/views/consumed_products/new.rhtml b/app/views/consumed_products/new.rhtml index 8068071..e79a4b6 100644 --- a/app/views/consumed_products/new.rhtml +++ b/app/views/consumed_products/new.rhtml @@ -1,6 +1,9 @@

<%= _('Add product') %>

-<% form_for :consumption, @consuption do |f| %> - <%= _('Product: ') %> <%= f.select "product_category_id", ProductCategory.find(:all).map{|pc| [pc.name, pc.id]} %> - <%= display_submit_tag _('Add product') %> +<%= error_messages_for :consumption %> + +<% form_for :consumption, @consumption do |f| %> +

<%= _('Product: ') %> <%= f.select "product_category_id", ProductCategory.find(:all).map{|pc| [pc.name, pc.id]} %>

+ <%= submit_tag _('Add product') %> + <%= link_to _('Cancel'), :action => 'index' %> <% end %> diff --git a/app/views/consumed_products/show.rhtml b/app/views/consumed_products/show.rhtml deleted file mode 100644 index 10a3a4d..0000000 --- a/app/views/consumed_products/show.rhtml +++ /dev/null @@ -1,10 +0,0 @@ -

<%= @product.name %>

- -

<%= image_tag @product.image.public_filename if @product.image %>

-

<%= _('Price: ') %> <%= @product.price %>

-

<%= _('Description: ') %> <%= @product.description %>

-

<%= _('Category: ') %> <%= @product.product_category ? @product.product_category.name : _('Uncategorized product') %>

- -<%= link_to _('destroy'), :action => 'destroy', :id => @product %> -
-<%= link_to _('back'), :action => 'index' %> diff --git a/app/views/manage_products/_form.rhtml b/app/views/manage_products/_form.rhtml index 0fe3032..3dbadb3 100644 --- a/app/views/manage_products/_form.rhtml +++ b/app/views/manage_products/_form.rhtml @@ -7,4 +7,5 @@ <%= display_form_field( _('Image:'), file_field_tag( "product[image_builder][uploaded_data]" ) ) %> <%= display_form_field( _('category:'), f.select( :product_category_id,ProductCategory.find(:all).map{|pc|[pc.name,pc.id]}, {:include_blank => true} )) %> <%= display_submit_tag(mode == 'new' ? _('Create product') : _('Save changes')) %> + <%= link_to _('Cancel'), :action => 'index' %> <% end %> diff --git a/app/views/product_category_viewer/index.rhtml b/app/views/product_category_viewer/index.rhtml deleted file mode 100644 index 6efb0c3..0000000 --- a/app/views/product_category_viewer/index.rhtml +++ /dev/null @@ -1,7 +0,0 @@ -

<%= _('Categories of products') %>

- - diff --git a/app/views/product_category_viewer/view_category.rhtml b/app/views/product_category_viewer/view_category.rhtml deleted file mode 100644 index 46b1168..0000000 --- a/app/views/product_category_viewer/view_category.rhtml +++ /dev/null @@ -1,13 +0,0 @@ -

<%= @category.name %>

- -<%= @products.size.to_s + " products in this category" %> -<%= @enterprises.size.to_s + " enterprises sells products in this category" %> - - diff --git a/app/views/profile_editor/index.rhtml b/app/views/profile_editor/index.rhtml index a4e58e3..bcade11 100644 --- a/app/views/profile_editor/index.rhtml +++ b/app/views/profile_editor/index.rhtml @@ -14,15 +14,30 @@ <%= file_manager_button(_('Manage Content'), 'icons-app/cms.png', :controller => 'cms') %> <%= file_manager_button(_('Change Password'), 'icons-app/change-password.png', :controller => 'account', :action => 'change_password') if profile.person? %> - + + <%= file_manager_button(_('Manage Members'), 'icons-app/members.png', :controller => 'profile_members') %> + + <%= file_manager_button(_('Needed Products'), 'icons-app/consumed_product.png', :controller => 'consumed_products') %> + <%= file_manager_button(_('Manage Products'), 'icons-app/products.png', :controller => 'manage_products') if profile.enterprise? %> <% end %> -

<%= _('My organizations') %>

+<% if @profile.person? %> +

<%= _('My organizations') %>

+ + <% file_manager do %> -<% file_manager do %> + <% @profile.enterprise_memberships.each do |em| %> + <% if em.image %> + <%= file_manager_button(em.name, em.image.public_filename(:minor), :profile => em.identifier, :controller => 'profile_editor' ) %> + <% else %> + <%= link_to_myprofile(em.name, {}, em.identifier) %> + <% end %> + <% end %> + + <%= file_manager_button(_('Register a new Enterprise'), 'icons-app/enterprise-registration.png', :controller => 'enterprise_registration') %> - <%= file_manager_button(_('Register a new Enterprise'), 'icons-app/enterprise-registration.png', :controller => 'enterprise_registration') %> + <% end %> <% end %> diff --git a/app/views/profile_members/index.rhtml b/app/views/profile_members/index.rhtml index 22ecbea..0293c56 100644 --- a/app/views/profile_members/index.rhtml +++ b/app/views/profile_members/index.rhtml @@ -1,6 +1,6 @@

<%= _('Listing Members') %>

-<%= link_to _('Affiliate yourself'), :action => 'add_role', :person => current_user.person, :role => Role.find_by_name('member') %> +<%= link_to _('Affiliate yourself'), :action => 'add_role', :person => current_user.person, :role => @member_role if @member_role %>