diff --git a/app/assets/javascripts/admin/spree_simple_cms.js b/app/assets/javascripts/admin/spree_simple_cms.js index 7cace55..e69de29 100644 --- a/app/assets/javascripts/admin/spree_simple_cms.js +++ b/app/assets/javascripts/admin/spree_simple_cms.js @@ -1,2 +0,0 @@ -//= require admin/spree_core -//= require ckeditor/init diff --git a/app/assets/javascripts/store/spree_simple_cms.js b/app/assets/javascripts/store/spree_simple_cms.js index e7624f2..83a4ef3 100644 --- a/app/assets/javascripts/store/spree_simple_cms.js +++ b/app/assets/javascripts/store/spree_simple_cms.js @@ -1,6 +1,3 @@ -//= require store/spree_core -//= require ckeditor/init - (function($){ $(document).ready(function(){ diff --git a/app/assets/stylesheets/admin/spree_simple_cms.css b/app/assets/stylesheets/admin/spree_simple_cms.css index ef47b5b..e69de29 100644 --- a/app/assets/stylesheets/admin/spree_simple_cms.css +++ b/app/assets/stylesheets/admin/spree_simple_cms.css @@ -1,21 +0,0 @@ -/* - *= require admin/spree_core - *= require formtastic -*/ - -.formtastic input, .formtastic textarea, .formtastic select { - font-size: 100%; - padding: 5px; -} - -.formtastic button { - margin: 0; - padding: 0 20px 0 0; -} -.formtastic button:hover { - text-shadow: #FFFFFF -1px -1px 0px; -} - -.tags { - margin-right: 5px; -} diff --git a/app/assets/stylesheets/store/spree_simple_cms.css b/app/assets/stylesheets/store/spree_simple_cms.css index 94dbe33..e69de29 100644 --- a/app/assets/stylesheets/store/spree_simple_cms.css +++ b/app/assets/stylesheets/store/spree_simple_cms.css @@ -1,3 +0,0 @@ -/* - *= require store/spree_core -*/ diff --git a/app/controllers/spree/admin/blogs_controller.rb b/app/controllers/spree/admin/blogs_controller.rb deleted file mode 100644 index 63f662d..0000000 --- a/app/controllers/spree/admin/blogs_controller.rb +++ /dev/null @@ -1,28 +0,0 @@ -module Spree - module Admin - class BlogsController < ResourceController - def index - params[:search] ||= {} - params[:search][:meta_sort] ||= "name.asc" - @blogs = @search.result.page(params[:name]).per(Spree::Config[:admin_products_per_page]) - end - - def collection - @search = super.ransack(params[:search]) - end - - def new - @blog = @object - end - - def edit - @blog = @object - end - - def location_after_save - admin_blogs_url - end - - end - end -end \ No newline at end of file diff --git a/app/controllers/spree/admin/posts_controller.rb b/app/controllers/spree/admin/posts_controller.rb index 78f9bab..305720d 100644 --- a/app/controllers/spree/admin/posts_controller.rb +++ b/app/controllers/spree/admin/posts_controller.rb @@ -2,26 +2,41 @@ module Spree module Admin class PostsController < ResourceController def index - params[:search] ||= {} - params[:search][:meta_sort] ||= "name.asc" - @posts = @search.result.published.page(params[:name]).per(Spree::Config[:admin_products_per_page]) + respond_with(@collection) end - - def collection - @search = super.ransack(params[:search]) + + def show + redirect_to( :action => :edit ) end + + def destroy + @static_page = StaticPage.where(:permalink => params[:id]).first! + @static_page.delete - def new - @post = @object - end + flash.notice = I18n.t('notice_messages.page_deleted') - def edit - @post = @object + respond_with(@static_page) do |format| + format.html { redirect_to collection_url } + format.js { render_js_for_destroy } + end end protected + def find_resource + Post.find_by_permalink!(params[:id]) + end + def location_after_save - admin_static_pages_url + edit_admin_post_url(@post) + end + + def collection + return @collection if @collection.present? + params[:q] ||= {} + params[:q][:s] ||= "title asc" + + @search = super.ransack(params[:q]) + @collection = @search.result.page(params[:page]).per(Spree::Config[:admin_post_per_page]) end end end diff --git a/app/controllers/spree/admin/static_pages_controller.rb b/app/controllers/spree/admin/static_pages_controller.rb index 03dd455..e3ca787 100644 --- a/app/controllers/spree/admin/static_pages_controller.rb +++ b/app/controllers/spree/admin/static_pages_controller.rb @@ -1,14 +1,29 @@ module Spree module Admin class StaticPagesController < ResourceController + def index - params[:search] ||= {} - params[:search][:meta_sort] ||= "name.asc" - @static_pages = @search.result.page(params[:name]).per(Spree::Config[:admin_products_per_page]) + respond_with(@collection) end + + def show + redirect_to( :action => :edit ) + end + + def destroy + @static_page = StaticPage.where(:permalink => params[:id]).first! + @static_page.delete + + flash.notice = I18n.t('notice_messages.page_deleted') + respond_with(@static_page) do |format| + format.html { redirect_to collection_url } + format.js { render_js_for_destroy } + end + end + def published - sp = Spree::StaticPage.find(params[:id]) + sp = StaticPage.find(params[:id]) if sp.update_attribute(:published_at, Time.now) flash[:notice] = t("info_published_static_page") @@ -19,7 +34,7 @@ def published end def in_nav_menu - sp = Spree::StaticPage.find(params[:id]) + sp = StaticPage.find(params[:id]) if sp.update_attribute(:in_nav_menu, true) flash[:notice] = t("info_in_nav_menu_static_page") @@ -29,31 +44,25 @@ def in_nav_menu redirect_to spree.admin_static_pages_path end - def update_positions - params[:positions].each do |id, index| - Spree::StaticPage.where(:id => id).update_all(:position => index) - end - respond_to do |format| - format.js { render :text => 'Ok' } - end - end - - def collection - @search = super.ransack(params[:search]) - end - - def new - @static_page = @object - end - - def edit - @static_page = @object - end protected + def find_resource + StaticPage.find_by_permalink!(params[:id]) + end + def location_after_save - admin_static_pages_url + edit_admin_static_page_url(@static_page) + end + + def collection + return @collection if @collection.present? + params[:q] ||= {} + params[:q][:s] ||= "title asc" + + @search = super.ransack(params[:q]) + @collection = @search.result.page(params[:page]).per(Spree::Config[:admin_post_per_page]) end + end end end \ No newline at end of file diff --git a/app/controllers/spree/admin/store_settings_controller.rb b/app/controllers/spree/admin/store_settings_controller.rb index 915c53b..3f353b9 100644 --- a/app/controllers/spree/admin/store_settings_controller.rb +++ b/app/controllers/spree/admin/store_settings_controller.rb @@ -1,25 +1,21 @@ module Spree module Admin class StoreSettingsController < BaseController - def show - @preferences = ['store_name', 'store_default_email', 'store_address', - 'store_phone_number', 'store_fax_number', 'store_twitter_id', - 'store_facebook_id', 'store_skype', 'store_location', 'store_description', 'store_welcome_title', 'store_welcome_description'] - end - + def edit - @preferences = [:store_name, :store_default_email, :store_address, + @preferences = [:store_default_email, :store_address, :store_phone_number, :store_fax_number, :store_twitter_id, :store_facebook_id, :store_skype, :store_location, :store_description, :store_welcome_title, :store_welcome_description] end - + def update params.each do |name, value| next unless Spree::Config.has_preference? name Spree::Config[name] = value end + flash[:success] = t(:successfully_updated, :resource => t(:general_settings)) - redirect_to admin_store_settings_path + redirect_to edit_admin_store_settings_path end end diff --git a/app/controllers/spree/static_pages_controller.rb b/app/controllers/spree/static_pages_controller.rb index 777ef8b..bde44da 100644 --- a/app/controllers/spree/static_pages_controller.rb +++ b/app/controllers/spree/static_pages_controller.rb @@ -1,17 +1,21 @@ module Spree class StaticPagesController < BaseController - before_filter :load_obj + before_filter :load_page, :only => :show + rescue_from ActiveRecord::RecordNotFound, :with => :render_404 + helper 'spree/taxons' + + respond_to :html def contacts end def show - @page = Spree::StaticPage.find(params[:id]) + return unless @static_page end def create_mail unless (params[:name].blank? && params[:email].blank? && params[:messaggio].blank?) - Spree::ContactMailer.contacts_form(params[:name], params[:email], params[:messaggio]).deliver + Spree::ContactMailer.contact_form(params[:name], params[:email], params[:messaggio]).deliver flash[:notice] = t('create_mail_static_page') else flash[:notice] = t('not_create_mail_static_page')#'Si e` verificato un problema durante l\'invio della mail. Verifica di aver compilato tutti i campi' @@ -19,9 +23,13 @@ def create_mail redirect_to contacts_url end - def load_obj - @static_pages = Spree::StaticPage.published + private + def accurate_title + @static_page ? @static_page.title : super end + def load_page + @static_page = Spree::StaticPage.find_by_permalink!(params[:id]) + end end end diff --git a/app/mailers/spree/contact_mailer.rb b/app/mailers/spree/contact_mailer.rb index e80043a..665ed53 100644 --- a/app/mailers/spree/contact_mailer.rb +++ b/app/mailers/spree/contact_mailer.rb @@ -1,15 +1,12 @@ module Spree class ContactMailer < ActionMailer::Base helper 'spree/base' - - default :from => Spree::Config[:store_default_email] - def contacts_form(name, email, text) + def contact_form(name, email, text) @name = name @email = email @messaggio = text - mail(:to => "#{email} - #{name}", - :subject => Spree::Config[:store_default_contact_subject]) + mail(:to => Spree::Config[:store_default_email], :subject => "#{Spree::Config[:site_name]} - #{Spree::Config[:store_default_contact_subject]}") end end end diff --git a/app/models/comment.rb b/app/models/comment.rb deleted file mode 100644 index 1d8c0c0..0000000 --- a/app/models/comment.rb +++ /dev/null @@ -1,52 +0,0 @@ -module Spree - class Comment < ActiveRecord::Base - acts_as_nested_set :scope => [:commentable_id, :commentable_type] - - validates_presence_of :body - validates_presence_of :user - - # NOTE: install the acts_as_votable plugin if you - # want user to vote on the quality of comments. - #acts_as_voteable - - belongs_to :commentable, :polymorphic => true - - # NOTE: Comments belong to a user - belongs_to :user - - # Helper class method that allows you to build a comment - # by passing a commentable object, a user_id, and comment text - # example in readme - def self.build_from(obj, user_id, comment) - c = self.new - c.commentable_id = obj.id - c.commentable_type = obj.class.base_class.name - c.body = comment - c.user_id = user_id - c - end - - #helper method to check if a comment has children - def has_children? - self.children.size > 0 - end - - # Helper class method to lookup all comments assigned - # to all commentable types for a given user. - scope :find_comments_by_user, lambda { |user| - where(:user_id => user.id).order('created_at DESC') - } - - # Helper class method to look up all comments for - # commentable class name and commentable id. - scope :find_comments_for_commentable, lambda { |commentable_str, commentable_id| - where(:commentable_type => commentable_str.to_s, :commentable_id => commentable_id).order('created_at DESC') - } - - # Helper class method to look up a commentable object - # given the commentable class name and id - def self.find_commentable(commentable_str, commentable_id) - commentable_str.constantize.find(commentable_id) - end - end -end diff --git a/app/models/spree/app_configuration_decorator.rb b/app/models/spree/app_configuration_decorator.rb index f381869..aa8bc7e 100644 --- a/app/models/spree/app_configuration_decorator.rb +++ b/app/models/spree/app_configuration_decorator.rb @@ -1,8 +1,24 @@ +# This is the primary location for defining spree preferences +# +# The expectation is that this is created once and stored in +# the spree environment +# +# setters: +# a.color = :blue +# a[:color] = :blue +# a.set :color = :blue +# a.preferred_color = :blue +# +# getters: +# a.color +# a[:color] +# a.get :color +# a.preferred_color +# Spree::AppConfiguration.class_eval do - preference :store_name, :string, :default => 'Spree Demo' preference :store_default_email, :string, :default => 'spree@example.com' - preference :store_default_contact_subject, :string, :default => "[Spree Demo] Contact form subject" + preference :store_default_contact_subject, :string, :default => "Contact form subject" preference :store_address, :string, :default => 'Address, 123 - 123456 City (IT)' preference :store_phone_number, :string, :default => '012 - 3456789' preference :store_fax_number, :string, :default => '012 - 3456789' @@ -13,5 +29,7 @@ preference :store_description, :text, :default => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed tincidunt, sem id vulputate auctor, dui lectus lacinia ipsum, placerat euismod felis tellus a nulla. Nunc fermentum tincidunt dui, ac iaculis quam elementum et. Mauris sit amet vehicula tortor. Maecenas euismod fringilla venenatis. In accumsan ultricies odio at venenatis. Duis aliquam euismod libero, nec eleifend massa fermentum iaculis. Donec imperdiet egestas ligula pretium aliquam.' preference :store_welcome_title, :string, :default => 'Welcome' preference :store_welcome_description, :text, :default => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed tincidunt, sem id vulputate auctor, dui lectus lacinia ipsum, placerat euismod felis tellus a nulla. Nunc fermentum tincidunt dui, ac iaculis quam elementum et. Mauris sit amet vehicula tortor. Maecenas euismod fringilla venenatis. In accumsan ultricies odio at venenatis. Duis aliquam euismod libero, nec eleifend massa fermentum iaculis. Donec imperdiet egestas ligula pretium aliquam.' + preference :admin_post_per_page, :integer, :default => 10 preference :post_per_page, :integer, :default => 5 + end \ No newline at end of file diff --git a/app/models/spree/blog.rb b/app/models/spree/blog.rb index 0e0c974..515c89c 100644 --- a/app/models/spree/blog.rb +++ b/app/models/spree/blog.rb @@ -1,38 +1,31 @@ module Spree class Blog < ActiveRecord::Base + has_many :blog_images, :source => :images, :as => :viewable, :order => :position, :dependent => :destroy + has_many :uploads, :as => :uploadable + + attr_accessible :title, :permalink, :tag_title, :meta_description, :meta_keywords, :description, :content, :link, + :position, :in_nav_menu, :published_at # TAGGING AND COMMENT SYSTEM acts_as_taggable acts_as_taggable_on :tags - validates_presence_of :name, :content - validate :no_image_errors + make_permalink :order => :title - extend ::FriendlyId - friendly_id :name, :use => :slugged - - has_attached_file :image, :styles => { - :thumbnail => "100x100>", - :small => "200x200>", - :medium => "300x300>", - :big => "400x400#", - :custom => Proc.new { |instance| "#{instance.image_width}x#{instance.image_height}#" }} - + validates_presence_of :title, :content + + has_many :products, :through => :post_products + has_many :blog_images, :source => :images, :as => :viewable, :order => :position, :dependent => :destroy has_many :uploads, :as => :uploadable accepts_nested_attributes_for :uploads, :allow_destroy => true before_save :set_published_at, :if => Proc.new {|model| model.published_at.nil? } - - def set_published_at - self.published_at = Time.now - end - - #TODO: spostare in libreria - def no_image_errors - unless image.errors.empty? - errors.add :image, "Paperclip returned errors for file '#{image_file_name}' - check ImageMagick installation or image source file." - false - end + + def to_param + permalink.present? ? permalink : (permalink_was || title.to_s.to_url) end + def set_published_at + self.published_at = Time.now + end end end diff --git a/app/models/spree/page.rb b/app/models/spree/page.rb index 18cd28a..92a3e83 100644 --- a/app/models/spree/page.rb +++ b/app/models/spree/page.rb @@ -1,20 +1,23 @@ module Spree - class Page < ActiveRecord::Base - extend ::FriendlyId - friendly_id :name, :use => :slugged - + class Page < ActiveRecord::Base + has_and_belongs_to_many :products, :join_table => 'spree_pages_products' + has_and_belongs_to_many :taxons, :join_table => 'spree_pages_taxons' has_many :images, :as => :viewable, :order => :position, :dependent => :destroy + has_many :uploads, :as => :uploadable + + attr_accessible :title, :permalink, :tag_title, :meta_description, :meta_keywords, :body, :link, + :position, :in_nav_menu, :published_at + + accepts_nested_attributes_for :uploads, :allow_destroy => true - def should_generate_new_friendly_id? - new_record? + make_permalink :order => :title + + def to_param + permalink.present? ? permalink : (permalink_was || title.to_s.to_url) end - - def link_is_blank + + def link_is_blank? self.link.blank? end - - def content_is_blank - self.content.blank? - end end end diff --git a/app/models/spree/post.rb b/app/models/spree/post.rb index 30bacd2..736c1f5 100644 --- a/app/models/spree/post.rb +++ b/app/models/spree/post.rb @@ -1,7 +1,12 @@ module Spree class Post < Blog - #acts_as_commentable - belongs_to :post_category + has_and_belongs_to_many :products, :join_table => 'spree_posts_products' + has_and_belongs_to_many :taxons, :join_table => 'spree_posts_taxons' + acts_as_commentable + + has_and_belongs_to_many :post_categories, :join_table => "spree_post_categories_posts", :class_name => "Spree::PostCategory" + alias_attribute :categories, :post_categories + attr_accessible :name, :content, :published_at, :active, :tag_list scope :published, lambda { where("published_at <= '#{Time.now}' AND active = 1") } scope :valid, lambda { where("from <= #{Time.now} AND to >= #{Time.now}") } diff --git a/app/models/spree/post_category.rb b/app/models/spree/post_category.rb index 788c7c9..294931e 100644 --- a/app/models/spree/post_category.rb +++ b/app/models/spree/post_category.rb @@ -1,10 +1,15 @@ module Spree class PostCategory < ActiveRecord::Base - extend ::FriendlyId - friendly_id :name, :use => :slugged - has_many :posts + attr_accessible :title, :permalink, :tag_title, :meta_description, :meta_keywords, :presentation, + :position, :published_at + + make_permalink :order => :title + has_and_belongs_to_many :posts, :join_table => 'spree_post_categories_posts', :uniq => true scope :published, lambda { where(:published_at => "published_at <= #{Time.now}", :active => true) } + def to_param + permalink.present? ? permalink : (permalink_was || title.to_s.to_url) + end end end \ No newline at end of file diff --git a/app/models/spree/product_decorator.rb b/app/models/spree/product_decorator.rb index 8799af2..9733bad 100644 --- a/app/models/spree/product_decorator.rb +++ b/app/models/spree/product_decorator.rb @@ -1,4 +1,4 @@ Spree::Product.class_eval do - has_many :static_pages - + has_and_belongs_to_many :static_pages, :join_table => 'spree_pages_products' + has_and_belongs_to_many :posts, :join_table => 'spree_posts_products' end \ No newline at end of file diff --git a/app/models/spree/static_page.rb b/app/models/spree/static_page.rb index ee66d6c..6a192b7 100644 --- a/app/models/spree/static_page.rb +++ b/app/models/spree/static_page.rb @@ -1,16 +1,7 @@ module Spree - class StaticPage < Page - belongs_to :product - - attr_accessible :name, :slug, :tag_title, :meta_description, :meta_keywords, :content, :published_at + class StaticPage < Page scope :published, lambda { where("published_at <= ? AND published_at IS NOT NULL", Time.now) } - def initialize(*args) - super(*args) - last_static_page = StaticPage.last - self.position = last_static_page ? last_static_page.position + 1 : 0 - end - def published? !self.published_at.blank? end diff --git a/app/models/spree/taxon_decorator.rb b/app/models/spree/taxon_decorator.rb index 14ce000..335c9be 100644 --- a/app/models/spree/taxon_decorator.rb +++ b/app/models/spree/taxon_decorator.rb @@ -1,8 +1,14 @@ Spree::Taxon.class_eval do has_and_belongs_to_many :pages, :join_table => 'spree_pages_taxons' + has_and_belongs_to_many :posts, :join_table => 'spree_posts_taxons' - def active_products + def active_pages scope = pages.published scope end + + def active_posts + scope = posts.published + scope + end end \ No newline at end of file diff --git a/app/overrides/simple_cms_admin_tabs.rb b/app/overrides/simple_cms_admin_tabs.rb index 7588094..64cd89d 100644 --- a/app/overrides/simple_cms_admin_tabs.rb +++ b/app/overrides/simple_cms_admin_tabs.rb @@ -1,12 +1,10 @@ Deface::Override.new(:virtual_path => "spree/layouts/admin", :name => "pages_tab", :insert_bottom => "[data-hook='admin_tabs'], #admin_tabs[data-hook]", - :text => "<%= tab(t('simple_cms.pages'), :url => spree.admin_static_pages_path) %>", - :disabled => false) + :text => "<%= tab(t('simple_cms.pages'), :url => spree.admin_static_pages_path) %>") Deface::Override.new(:virtual_path => "spree/layouts/admin", :name => "posts_tab", :insert_bottom => "[data-hook='admin_tabs'], #admin_tabs[data-hook]", - :text => "<%= tab(:posts, :url => spree.admin_posts_path) %>", - :disabled => false) + :text => "<%= tab(:posts, :url => spree.admin_posts_path) %>") diff --git a/app/overrides/store_setting_admin_configuration_menu.rb b/app/overrides/store_setting_admin_configuration_menu.rb index 557e2c7..a08bbb8 100644 --- a/app/overrides/store_setting_admin_configuration_menu.rb +++ b/app/overrides/store_setting_admin_configuration_menu.rb @@ -1,11 +1,9 @@ Deface::Override.new(:virtual_path => "spree/admin/shared/_configuration_menu", :name => "add_store_setting_link_configuration_menu", :insert_bottom => "[data-hook='admin_configurations_sidebar_menu']", - :text => %q{<%= configurations_sidebar_menu_item t("simple_cms.store_settings"), admin_store_settings_url %>}, - :disabled => false) + :text => %q{<%= configurations_sidebar_menu_item t("simple_cms.store_settings"), admin_store_settings_url %>}) Deface::Override.new(:virtual_path => "spree/admin/configurations/index", :name => "add_store_setting_to_configuration_menu", :insert_after => "[data-hook='admin_configurations_menu']", - :partial => "spree/admin/shared/store_setting_configurations_menu", - :disabled => false) \ No newline at end of file + :partial => "spree/admin/shared/store_setting_configurations_menu") \ No newline at end of file diff --git a/app/views/spree/admin/posts/_form.html.erb b/app/views/spree/admin/posts/_form.html.erb index 8ad7823..d532422 100644 --- a/app/views/spree/admin/posts/_form.html.erb +++ b/app/views/spree/admin/posts/_form.html.erb @@ -11,4 +11,10 @@
<%= t(:insert_tag_instruction) %>
<%= f.input :tag_list, :label => t(:tag_list) %> <% end %> - \ No newline at end of file + + +<%= form.field_container :tag_list do %> + <%= form.label :tag_list, t("activerecord.attributes.post.tags") %>