diff --git a/app/controllers/my_profile/manage_products_controller.rb b/app/controllers/my_profile/manage_products_controller.rb index d442d60..0fc0e83 100644 --- a/app/controllers/my_profile/manage_products_controller.rb +++ b/app/controllers/my_profile/manage_products_controller.rb @@ -1,10 +1,12 @@ class ManageProductsController < ApplicationController needs_profile - protect 'manage_products', :profile + protect 'manage_products', :profile, :except => [:show] before_filter :check_environment_feature + before_filter :login_required, :except => [:show] protected + def check_environment_feature if profile.environment.enabled?('disable_products_for_enterprises') render_not_found @@ -13,6 +15,7 @@ class ManageProductsController < ApplicationController end public + def index @products = @profile.products @consumptions = @profile.consumptions @@ -51,15 +54,34 @@ class ManageProductsController < ApplicationController end def edit - @object = @product = @profile.products.find(params[:id]) - @current_category = @product.product_category - @categories = @current_category.nil? ? [] : @current_category.children + @product = @profile.products.find(params[:id]) + field = params[:field] if request.post? - if @product.update_attributes(params[:product]) - flash[:notice] = _('Product succesfully updated') - redirect_back_or_default :action => 'show', :id => @product - else + begin + @product.update_attributes!(params[:product]) + render :partial => "display_#{field}", :locals => {:product => @product} + rescue Exception => e + render :partial => "edit_#{field}", :locals => {:product => @product, :errors => true} + end + else + render :partial => "edit_#{field}", :locals => {:product => @product, :errors => false} + end + end + + def edit_category + @product = @profile.products.find(params[:id]) + @category = @product.product_category + @categories = ProductCategory.top_level_for(environment) + @edit = true + @level = @category.level + if request.post? + begin + @product.update_attributes!(params[:product]) + render :partial => 'shared/redirect_via_javascript', + :locals => { :url => url_for(:controller => 'manage_products', :action => 'show', :id => @product) } + rescue Exception => e flash[:notice] = _('Could not update the product') + render :partial => 'shared/dialog_error_messages', :locals => { :object_name => 'product' } end end end diff --git a/app/controllers/public/catalog_controller.rb b/app/controllers/public/catalog_controller.rb index 6f59dd0..1620001 100644 --- a/app/controllers/public/catalog_controller.rb +++ b/app/controllers/public/catalog_controller.rb @@ -1,15 +1,12 @@ class CatalogController < PublicController needs_profile + before_filter :check_enterprise_and_environment def index @products = @profile.products end - def show - @product = @profile.products.find(params[:id]) - end - protected def check_enterprise_and_environment unless @profile.kind_of?(Enterprise) && !@profile.environment.enabled?('disable_products_for_enterprises') diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2de8e2a..2577a97 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -907,7 +907,7 @@ module ApplicationHelper (@section ? @section.title + ' - ' : '') + (@toc ? _('Online Manual') + ' - ' : '') + environment.name + - (@category ? "→ #{@category.full_name}" : '') + (@category ? " - #{@category.full_name}" : '') end def noosfero_javascript @@ -921,6 +921,7 @@ module ApplicationHelper 'lightbox', 'colorpicker', pngfix_stylesheet_path, + 'jquery.ui/sunny/jquery-ui-1.8.2.custom', ] end @@ -960,13 +961,16 @@ module ApplicationHelper text_field_tag(name, value, options.merge(:class => 'colorpicker_field')) end - # for now force currency to Brazillian format, like: "12.345,20" - def float_to_currency(price) - number_to_currency(price, :unit => 'R$', :separator => ',', :delimiter => '.') - end - def ui_icon(icon_type) "" end + def ui_button(label, url, html_options = {}) + link_to(label, url, html_options.merge(:class => 'ui_button fg-button')) + end + + def ui_button_to_remote(label, options, html_options = {}) + link_to_remote(label, options, html_options.merge(:class => 'ui_button fg-button')) + end + end diff --git a/app/helpers/catalog_helper.rb b/app/helpers/catalog_helper.rb index c1195e7..2bfe021 100644 --- a/app/helpers/catalog_helper.rb +++ b/app/helpers/catalog_helper.rb @@ -1,6 +1,7 @@ module CatalogHelper include DisplayHelper +include ManageProductsHelper def display_products_list(profile, products) data = '' @@ -19,7 +20,7 @@ include DisplayHelper content_tag('h1', _('Products/Services')) + content_tag('ul', data, :id => 'product_list') end -private + private def product_category_name(profile, product_category) if profile.enabled? diff --git a/app/helpers/display_helper.rb b/app/helpers/display_helper.rb index 8409c34..989121c 100644 --- a/app/helpers/display_helper.rb +++ b/app/helpers/display_helper.rb @@ -2,7 +2,7 @@ module DisplayHelper def link_to_product(product, opts={}) return _('No product') unless product - target = product.enterprise.enabled? ? product.enterprise.public_profile_url.merge(:controller => 'catalog', :action => 'show', :id => product) : product.enterprise.url + target = product.enterprise.enabled? ? product.enterprise.public_profile_url.merge(:controller => 'manage_products', :action => 'show', :id => product) : product.enterprise.url link_to content_tag( 'span', product.name ), target, opts diff --git a/app/helpers/manage_products_helper.rb b/app/helpers/manage_products_helper.rb index 3638ffb..6ff212e 100644 --- a/app/helpers/manage_products_helper.rb +++ b/app/helpers/manage_products_helper.rb @@ -49,12 +49,52 @@ module ManageProductsHelper hierarchy.reverse.join(options[:separator] || ' → ') end - def options_for_select_categories(categories) + def options_for_select_categories(categories, selected = nil) categories.sort_by{|cat| cat.name.transliterate}.map do |category| - "" + selected_attribute = selected.nil? ? '' : (category == selected ? "selected='selected'" : '') + "" end.join("\n") end + def build_selects_for_ancestors(ancestors, last_level) + current_category = ancestors.shift + if current_category.nil? + content_tag('div', '', + :class => 'categories_container', + :id => "categories_container_level#{ last_level }" + ) + else + content_tag('div', + select_tag('category_id', + options_for_select_categories(current_category.siblings + [current_category], current_category), + :size => 10, + :onchange => remote_function_to_update_categories_selection("categories_container_level#{ current_category.level + 1 }", :with => "'category_id=' + this.value") + ) + + build_selects_for_ancestors(ancestors, last_level), + :class => 'categories_container', + :id => "categories_container_level#{ current_category.level }" + ) + end + end + + def selects_for_all_ancestors(current_category) + build_selects_for_ancestors(current_category.ancestors.reverse + [current_category], current_category.level + 1) + end + + def select_for_new_category + content_tag('div', + render(:partial => 'categories_for_selection'), + :class => 'categories_container', + :id => 'categories_container_level0' + ) + end + + def categories_container(field_id_html, categories_selection_html, hierarchy_html = '') + field_id_html + + content_tag('div', hierarchy_html, :id => 'hierarchy_navigation') + + content_tag('div', categories_selection_html, :id => 'categories_container_wrapper') + end + def select_for_categories(categories, level = 0) if categories.empty? content_tag('div', '', :id => 'no_subcategories') @@ -68,4 +108,98 @@ module ManageProductsHelper end end + def edit_product_link(product, field, label, html_options = {}) + return '' unless (user && user.has_permission?('manage_products', profile)) + options = html_options.merge(:id => 'link-edit-product-' + field) + + link_to_remote(label, + {:update => "product-#{field}", + :url => { :controller => 'manage_products', :action => "edit", :id => product.id, :field => field }, + :method => :get}, + options) + end + + def edit_product_button(product, field, label, html_options = {}) + the_class = 'button with-text icon-edit' + if html_options.has_key?(:class) + the_class << ' ' << html_options[:class] + end + edit_product_link(product, field, label, html_options.merge(:class => the_class)) + end + + def edit_product_ui_button(product, field, label, html_options = {}) + return '' unless (user && user.has_permission?('manage_products', profile)) + options = html_options.merge(:id => 'edit-product-button-ui-' + field) + + ui_button_to_remote(label, + {:update => "product-#{field}", + :url => { :controller => 'manage_products', :action => "edit", :id => product.id, :field => field }, + :complete => "$('edit-product-button-ui-#{field}').hide()", + :method => :get}, + options) + end + + def cancel_edit_product_link(product, field, html_options = {}) + return '' unless (user && user.has_permission?('manage_products', profile)) + button_to_function(:cancel, _('Cancel'), nil, html_options) do |page| + page.replace_html "product-#{field}", :partial => "display_#{field}", :locals => {:product => product} + end + end + + def edit_product_category_link(product, html_options = {}) + return '' unless (user && user.has_permission?('manage_products', profile)) + options = html_options.merge(:id => 'link-edit-product-category') + link_to(_('Change category'), { :action => 'edit_category', :id => product.id}, options) + end + + def float_to_currency(value) + number_to_currency(value, :unit => environment.currency_unit, :separator => environment.currency_separator, :delimiter => environment.currency_delimiter, :format => "%u %n") + end + + def display_value(product) + price = product.price + unless price.blank? || price.zero? + unit = product.unit + return '' if unit.blank? + discount = product.discount + if discount.blank? || discount.zero? + display_price(_('Price: '), price, unit) + else + display_price_with_discount(price, unit, product.price_with_discount) + end + else + '' + end + end + + def display_price(label, price, unit) + content_tag('span', label, :class => 'field-name') + + content_tag('span', float_to_currency(price), :class => 'field-value') + + ' (%s)' % unit + end + + def display_price_with_discount(price, unit, price_with_discount) + original_value = content_tag('span', float_to_currency(price), :class => 'field-value') + discount_value = display_price(_('On sale: '), price_with_discount, unit) + content_tag('span', _('List price: '), :class => 'field-name') + original_value + "

" + discount_value + end + + def display_qualifiers(product) + data = '' + product.product_qualifiers.each do |pq| + certified_by = pq.certifier ? _(' certified by %s') % link_to(pq.certifier.name, pq.certifier.link) : '' + data << content_tag('li', '✔ ' + pq.qualifier.name + certified_by, :class => 'product-qualifiers-item') + end + content_tag('ul', data, :id => 'product-qualifiers') + end + + def checkboxes_qualifiers(product, qualifier) + check_box_tag("product[qualifiers_list][#{qualifier.id}][qualifier_id]", qualifier.id, product.qualifiers.include?(qualifier)) + qualifier.name + end + + def select_certifiers(product, qualifier, certifiers) + relation = product.product_qualifiers.find(:first, :conditions => {:qualifier_id => qualifier.id}) + selected = relation.nil? ? 0 : relation.certifier_id + select_tag("product[qualifiers_list][#{qualifier.id}][certifier_id]", options_for_select([[_('Select...') , 0 ]] + certifiers.map {|c|[c.name, c.id]}, selected)) + end end diff --git a/app/models/certifier.rb b/app/models/certifier.rb new file mode 100644 index 0000000..cd68824 --- /dev/null +++ b/app/models/certifier.rb @@ -0,0 +1,8 @@ +class Certifier < ActiveRecord::Base + + belongs_to :environment + + def link + self[:link] || '' + end +end diff --git a/app/models/environment.rb b/app/models/environment.rb index 2d6b4d1..c70a01a 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -152,6 +152,9 @@ class Environment < ActiveRecord::Base has_many :roles + has_many :qualifiers + has_many :certifiers + acts_as_accessible def superior_intances @@ -209,6 +212,10 @@ class Environment < ActiveRecord::Base settings_items :help_message_to_add_enterprise, :type => String, :default => '' settings_items :tip_message_enterprise_activation_question, :type => String, :default => '' + settings_items :currency_unit, :type => String, :default => '$' + settings_items :currency_separator, :type => String, :default => '.' + settings_items :currency_delimiter, :type => String, :default => ',' + def news_amount_by_folder=(amount) settings[:news_amount_by_folder] = amount.to_i end diff --git a/app/models/product.rb b/app/models/product.rb index 923ca66..ffcc59c 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -2,10 +2,14 @@ class Product < ActiveRecord::Base belongs_to :enterprise belongs_to :product_category has_many :product_categorizations + has_many :product_qualifiers + has_many :qualifiers, :through => :product_qualifiers validates_uniqueness_of :name, :scope => :enterprise_id, :allow_nil => true validates_presence_of :product_category + validates_numericality_of :price, :allow_nil => true + validates_numericality_of :discount, :allow_nil => true after_update :save_image @@ -31,10 +35,36 @@ class Product < ActiveRecord::Base acts_as_searchable :fields => [ :name, :description, :category_full_name ] - xss_terminate :only => [ :name, :description ], :on => 'validation' + xss_terminate :only => [ :name ], :on => 'validation' + xss_terminate :only => [ :description ], :with => 'white_list', :on => 'validation' acts_as_mappable - + + def self.units + { + _('Litre') => 'litre', + _('Kilo') => 'kilo', + _('Meter') => 'meter', + _('Unit') => 'unit', + } + end + + def name + self[:name].blank? ? category_name : self[:name] + end + + def name=(value) + if (value == category_name) + self[:name] = nil + else + self[:name] = value + end + end + + def default_image(size='thumb') + '/images/icons-app/product-default-pic-%s.png' % size + end + def category_full_name product_category ? product_category.full_name.split('/') : nil end @@ -60,13 +90,21 @@ class Product < ActiveRecord::Base end def url - enterprise.public_profile_url.merge(:controller => 'catalog', :action => 'show', :id => id) + enterprise.public_profile_url.merge(:controller => 'manage_products', :action => 'show', :id => id) end def public? enterprise.public_profile end + def formatted_value(value) + ("%.2f" % self[value]).to_s.gsub('.', enterprise.environment.currency_separator) if self[value] + end + + def price_with_discount + price - discount if discount + end + def price=(value) if value.is_a?(String) super(currency_to_float(value)) @@ -75,6 +113,14 @@ class Product < ActiveRecord::Base end end + def discount=(value) + if value.is_a?(String) + super(currency_to_float(value)) + else + super(value) + end + end + def currency_to_float( num ) if num.count('.') == 1 && num.count(',') == 0 # number like "12.34" @@ -99,4 +145,17 @@ class Product < ActiveRecord::Base return num.tr(',.','').to_f end + def has_basic_info? + %w[description price].each do |field| + return true if !self.send(field).blank? + end + false + end + + def qualifiers_list=(qualifiers) + self.product_qualifiers.delete_all + qualifiers.each do |item| + self.product_qualifiers.create(item[1]) if item[1].has_key?('qualifier_id') + end + end end diff --git a/app/models/product_qualifier.rb b/app/models/product_qualifier.rb new file mode 100644 index 0000000..f60773b --- /dev/null +++ b/app/models/product_qualifier.rb @@ -0,0 +1,5 @@ +class ProductQualifier < ActiveRecord::Base + belongs_to :qualifier + belongs_to :product + belongs_to :certifier +end diff --git a/app/models/products_block.rb b/app/models/products_block.rb index eb724ae..2b64092 100644 --- a/app/models/products_block.rb +++ b/app/models/products_block.rb @@ -20,7 +20,7 @@ class ProductsBlock < Block block_title(title) + content_tag( 'ul', - products.map {|product| content_tag('li', link_to(product.name, product.url, :style => 'background-image:url(%s)' % ( product.image ? product.image.public_filename(:minor) : '/images/icons-app/product-default-pic-minor.png' )), :class => 'product' )} + products.map {|product| content_tag('li', link_to(product.name, product.url, :style => 'background-image:url(%s)' % ( product.image ? product.image.public_filename(:minor) : product.default_image('minor'))), :class => 'product' )} ) end diff --git a/app/models/profile.rb b/app/models/profile.rb index 042a8a9..d9871d0 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -386,7 +386,7 @@ class Profile < ActiveRecord::Base def url_options options = { :host => default_hostname, :profile => (own_hostname ? nil : self.identifier) } - Noosfero.url_options.merge(options) + options.merge(Noosfero.url_options.merge(options)) end private :generate_url, :url_options diff --git a/app/models/qualifier.rb b/app/models/qualifier.rb new file mode 100644 index 0000000..d738a97 --- /dev/null +++ b/app/models/qualifier.rb @@ -0,0 +1,5 @@ +class Qualifier < ActiveRecord::Base + + belongs_to :environment + +end diff --git a/app/views/catalog/show.rhtml b/app/views/catalog/show.rhtml deleted file mode 100644 index 22330c5..0000000 --- a/app/views/catalog/show.rhtml +++ /dev/null @@ -1,25 +0,0 @@ -

- -

<%= @product.name %>

- -<%= image_tag @product.image.public_filename, :class => 'product-pic' if @product.image %> - -
-<%= txt2html @product.description if @product.description %> -
- -<% if @product.price %> -

- <%= _('Price: %s') % ( "%.2f" % @product.price) %> -

-<% end %> - -

-<%= _('Category: %s ') % link_to_product_category(@product.product_category) %> -

- -<% button_bar do %> - <%= button :back, _("%s's products/services listing") % profile.name, :action => 'index', :id => nil %> -<% end %> - -
diff --git a/app/views/cms/_upload_file_form.rhtml b/app/views/cms/_upload_file_form.rhtml index 0a24ae2..dcf7141 100644 --- a/app/views/cms/_upload_file_form.rhtml +++ b/app/views/cms/_upload_file_form.rhtml @@ -11,7 +11,7 @@ <% end %> -<%= hidden_field_tag('back_to', @back_to) if @back_to %> +<%= hidden_field_tag('back_to', @back_to) %> <% button_bar do %> <%= add_upload_file_field(_('More files'), {:size => size}) %> diff --git a/app/views/layouts/_javascript.rhtml b/app/views/layouts/_javascript.rhtml index 6830063..bb65b85 100644 --- a/app/views/layouts/_javascript.rhtml +++ b/app/views/layouts/_javascript.rhtml @@ -1 +1 @@ -<%= javascript_include_tag :defaults, 'jquery-latest.js', 'jquery.noconflict.js', 'jquery.cycle.all.min.js', 'thickbox.js', 'lightbox', 'jquery-ui-1.8.2.custom.min', 'jquery.scrollTo', 'colorpicker', 'colorpicker-noosfero', 'reflection', :cache => 'cache-general' %> +<%= javascript_include_tag :defaults, 'jquery-latest.js', 'jquery.noconflict.js', 'jquery.cycle.all.min.js', 'thickbox.js', 'lightbox', 'jquery-ui-1.8.2.custom.min', 'jquery.scrollTo', 'jquery.form.js', 'colorpicker', 'colorpicker-noosfero', 'reflection', :cache => 'cache-general' %> diff --git a/app/views/layouts/application.rhtml b/app/views/layouts/application.rhtml index a1fff3b..462276e 100644 --- a/app/views/layouts/application.rhtml +++ b/app/views/layouts/application.rhtml @@ -15,7 +15,6 @@ <%= # Load the principal css files: stylesheet_link_tag(noosfero_stylesheets, :cache => 'cache') + - stylesheet_link_tag('jquery.ui/smoothness/jquery-ui-1.8.2.custom') + stylesheet_import( %w( common help menu article button search blocks forms login-box ), :themed_source => true ) + "\n" + import_blocks_stylesheets(:themed_source => true) + "\n" + @@ -126,5 +125,10 @@ app/views/shared/noosfero_layout_features.rhtml! %> <%= noosfero_layout_features %> + + diff --git a/app/views/manage_products/_display_category.rhtml b/app/views/manage_products/_display_category.rhtml new file mode 100644 index 0000000..415b521 --- /dev/null +++ b/app/views/manage_products/_display_category.rhtml @@ -0,0 +1,4 @@ +
+

<%= hierarchy_category_navigation(@product.product_category, :make_links => false)%>

+ <%= edit_product_category_link(@product) %> +
diff --git a/app/views/manage_products/_display_image.rhtml b/app/views/manage_products/_display_image.rhtml new file mode 100644 index 0000000..f24c636 --- /dev/null +++ b/app/views/manage_products/_display_image.rhtml @@ -0,0 +1,5 @@ +
+ <%= image_tag (@product.reload.image ? @product.image.public_filename : @product.default_image('thumb')), :class => 'product-pic' %> +
+ +<%= edit_product_link(@product, 'image', _('Change image')) %> diff --git a/app/views/manage_products/_display_info.rhtml b/app/views/manage_products/_display_info.rhtml new file mode 100644 index 0000000..f3746fe --- /dev/null +++ b/app/views/manage_products/_display_info.rhtml @@ -0,0 +1,14 @@ +<%= render :file => 'shared/tiny_mce', :locals => {:mode => 'simple'} %> +
+ <%= display_value(@product) %> + <%= display_qualifiers(@product) %> +
+ +
<%= @product.description %>
+ +<% if @product.has_basic_info? %> + <%= edit_product_button(@product, 'info', _('Edit basic information')) %> +<% else %> + <%= edit_product_ui_button(@product, 'info', _('Add description, price and other basic information'), :title => _('Click here to add description, price, discount and qualifiers/certifiers to make your product more attractive and detailed for the consumers'), 'data-primary-icon' => 'ui-icon-pencil', 'data-secondary-icon' => 'ui-icon-triangle-1-s') %> + <%= javascript_tag("render_jquery_ui_buttons('edit-product-button-ui-info')") %> +<% end%> diff --git a/app/views/manage_products/_display_name.rhtml b/app/views/manage_products/_display_name.rhtml new file mode 100644 index 0000000..abfd282 --- /dev/null +++ b/app/views/manage_products/_display_name.rhtml @@ -0,0 +1,5 @@ +
+

<%= @product.reload.name %>

+ <%= edit_product_link(@product, 'name', _('Edit name')) %> +
+ diff --git a/app/views/manage_products/_edit_image.rhtml b/app/views/manage_products/_edit_image.rhtml new file mode 100644 index 0000000..65646e1 --- /dev/null +++ b/app/views/manage_products/_edit_image.rhtml @@ -0,0 +1,27 @@ +
+ <%= image_tag (@product.reload.image ? @product.image.public_filename : @product.default_image('thumb')), :class => 'product-pic' %> +
+ +<% form_for(:product, :url => { :controller => 'manage_products', :action => 'edit', :id => @product, :field => 'image' }, :html => { :method => 'post', :id => 'uploadForm', :multipart => true}) do |f| %> + <% f.fields_for :image_builder, @product.image do |i| %> + <%= i.file_field( :uploaded_data, { :size => 10 } ) %> +

<%= _("Max size: %s (.jpg, .gif, .png)")% Image.max_size.to_humanreadable %>

+ <% end %> + + <%= submit_button 'save', _('Save') %> + <%= cancel_edit_product_link(@product, 'image') %> +<% end %> + + + +<% if errors %> + <%= render :partial => 'shared/dialog_error_messages', :locals => { :object_name => 'product' } %> +<% end %> diff --git a/app/views/manage_products/_edit_info.rhtml b/app/views/manage_products/_edit_info.rhtml new file mode 100644 index 0000000..8079dc4 --- /dev/null +++ b/app/views/manage_products/_edit_info.rhtml @@ -0,0 +1,49 @@ +<% if errors %> + <%= render :partial => 'shared/dialog_error_messages', :locals => { :object_name => 'product' } %> +<% end %> + +<%= render :file => 'shared/tiny_mce', :locals => {:mode => 'simple'} %> +<% remote_form_for(@product, + :loading => "open_loading('#{ _('loading...') }')", + :loaded => 'close_loading()', + :before => ("tinyMCE.triggerSave()" unless Rails.env == 'test'), + :update => 'product-info', + :url => {:controller => 'manage_products', :action => 'edit', :id => @product, :field => 'info'}, + :html => {:id => 'product-info-form', :method => 'post'}) do |f| %> + <%= labelled_form_field(_('Description:'), f.text_area(:description, :rows => 15, :style => 'width: 90%;')) %> + <%= labelled_form_field(_('Price (%s):') % environment.currency_unit, f.text_field(:price, :value => @product.formatted_value(:price), :onKeyPress => "return numbersonly(event, '#{environment.currency_separator}');")) %> + <%= labelled_form_field(_('Unit:'), f.select(:unit, Product.units)) %> + <%= labelled_form_field(_('Discount (%s):') % environment.currency_unit, f.text_field(:discount, :value => @product.formatted_value(:discount), :onKeyPress => "return numbersonly(event, '#{environment.currency_separator}');")) %> +
<%= _('Available:') %>
+
+ <%= labelled_radio_button( _('Yes'), 'product[available]', 'true', @product.available) %> + <%= labelled_radio_button( _('No'), 'product[available]', 'false', !@product.available) %> +
+ + + <% if !environment.qualifiers.empty? %> + + + + + + <% environment.qualifiers.each do |qualifier| %> + + + + + <% end %> +
<%= _('Qualifier') %><%= _('Certifier') %>
+ <%= checkboxes_qualifiers(@product, qualifier) %> + + <%= select_certifiers(@product, qualifier, environment.certifiers) %> +
+ <% end %> + + <% button_bar do %> + <%= submit_button :save, _('Save') %> + <%= cancel_edit_product_link(@product, 'info') %> + <% end %> +<% end %> + +
diff --git a/app/views/manage_products/_edit_name.rhtml b/app/views/manage_products/_edit_name.rhtml new file mode 100644 index 0000000..a742397 --- /dev/null +++ b/app/views/manage_products/_edit_name.rhtml @@ -0,0 +1,21 @@ +<% remote_form_for(@product, + :loading => "open_loading('#{ _('loading...') }')", + :loaded => 'close_loading()', + :update => 'product-name', + :url => {:controller => 'manage_products', :action => 'edit', :id => @product, :field => 'name'}, + :html => {:method => 'post'}) do |f| %> + <%= f.text_field(:name, :value => @product.name, :class => 'name_edition') %> + + <% button_bar do %> + <%= submit_button :save, _('Save') %> + <%= cancel_edit_product_link(@product, 'name') %> + <% end %> +<% end %> + + + +<% if errors %> + <%= render :partial => 'shared/dialog_error_messages', :locals => { :object_name => 'product' } %> +<% end %> diff --git a/app/views/manage_products/edit_category.rhtml b/app/views/manage_products/edit_category.rhtml new file mode 100644 index 0000000..686c941 --- /dev/null +++ b/app/views/manage_products/edit_category.rhtml @@ -0,0 +1,34 @@ +
+ <%= hierarchy_category_navigation(@product.product_category, :make_links => false)%> +
+ +
+ +

<%= @product.name %>

+ + + + <% remote_form_for(:product, @product, + :loading => "open_loading('#{ _('loading...') }')", + :loaded => "close_loading()", + :update => "request_result_message", + :url => {:action => 'edit_category', :id => @product, :field => 'category'}, + :html => {:method => 'post', :id => 'product_category_form'}) do |f| %> + +

<%= _('Edit category of this product:') %>

+ + <%= categories_container(f.hidden_field('product_category_id'), selects_for_all_ancestors(@category), hierarchy_category_navigation(@category, :make_links => true)) %> + +
+ <%= button(:back, _('Back to product'), :action => 'show', :id => @product) %> + + <%= submit_button(:save, _('Save and continue'), :id => 'save_and_continue') %> + + <%= ui_icon(:alert) %> + <%= _('This category does not allow registration of products, select a more specific category') %> + + +
+ + <% end %> +
diff --git a/app/views/manage_products/index.rhtml b/app/views/manage_products/index.rhtml index 58b0311..b2770b5 100644 --- a/app/views/manage_products/index.rhtml +++ b/app/views/manage_products/index.rhtml @@ -16,7 +16,6 @@ <%= link_to product.name, :action => 'show', :id => product %> <%= product.price %> - <%= button :edit, _('Edit'), :action => 'edit', :id => product %> <%= button :delete, _('Destroy'), :action => 'destroy', :id => product %> diff --git a/app/views/manage_products/new.rhtml b/app/views/manage_products/new.rhtml index bbe5cbd..e63f448 100644 --- a/app/views/manage_products/new.rhtml +++ b/app/views/manage_products/new.rhtml @@ -6,19 +6,11 @@ :loading => "open_loading('#{ _('loading...') }')", :update => "request_result_message", :url => {:action => 'new'}, - :html => {:method => 'post', :id => 'new_product_form'} do |f| %> + :html => {:method => 'post', :id => 'product_category_form'} do |f| %>

<%= _('Select the category of the new product or service') %>

- <%= f.hidden_field 'product_category_id' %> - -
- -
-
- <%= render :partial => 'categories_for_selection' %> -
-
+ <%= categories_container(f.hidden_field('product_category_id'), select_for_new_category) %>
<%= button :back, _('Back to the product listing'), :action => 'index' %> diff --git a/app/views/manage_products/show.rhtml b/app/views/manage_products/show.rhtml index f2ab94b..f4effd9 100644 --- a/app/views/manage_products/show.rhtml +++ b/app/views/manage_products/show.rhtml @@ -1,12 +1,26 @@ -

<%= @product.name %>

+
+ <%= render :partial => 'manage_products/display_category', :locals => {:product => @product} %> +
-

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

-

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

-

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

-

<%= _('Category:') %> <%= link_to_product_category(@product.product_category) %>

+
-<%= button :back, _('Back'), :action => 'index' %> -          -<%= button :delete, _('Destroy'), :action => 'destroy', :id => @product %> -<%= button :edit, _('Edit'), :action => 'edit', :id => @product %> +
+ <%= render :partial => 'manage_products/display_name', :locals => {:product => @product} %> +
+
+
+ <%= render :partial => 'manage_products/display_image', :locals => {:product => @product} %> +
+ +
+ <%= render :partial => 'manage_products/display_info', :locals => {:product => @product} %> +
+ +
+
+ +<% button_bar do %> + <%= button :back, _('Back to the product listing'), :action => 'index' %> + <%= button :delete, _('Remove product or service'), {:action => 'destroy', :id => @product}, :class => 'requires-permission-manage_products', :style => 'display:none;' %> +<% end %> diff --git a/app/views/shared/_dialog_error_messages.rhtml b/app/views/shared/_dialog_error_messages.rhtml index e530a2b..b9600ff 100644 --- a/app/views/shared/_dialog_error_messages.rhtml +++ b/app/views/shared/_dialog_error_messages.rhtml @@ -1,5 +1,3 @@ -<%= error_messages_for object_name %> - <% javascript_tag do %> close_loading() jQuery('#errorExplanation h2').hide() @@ -11,3 +9,4 @@ title: "<%= ui_icon(:alert) %>Ops…", }); <% end %> +<%= error_messages_for object_name %> diff --git a/app/views/shared/tiny_mce.rhtml b/app/views/shared/tiny_mce.rhtml index c5d1d4b..2130425 100644 --- a/app/views/shared/tiny_mce.rhtml +++ b/app/views/shared/tiny_mce.rhtml @@ -1,6 +1,16 @@ <%= javascript_include_tag 'tinymce/jscripts/tiny_mce/tiny_mce.js' %>