This commit is contained in:
Nicolas Bally 2015-01-27 23:32:25 +01:00
parent 720eb16c4c
commit 50ebd0dfca
40 changed files with 1 additions and 1415 deletions

View File

@ -37,7 +37,7 @@ gem "twitter-bootstrap-rails"
gem 'formtastic-bootstrap'
gem 'kaminari-bootstrap'
gem 'acts_as_commentable'
gem "mysql2"
gem 'ransack'

View File

@ -36,7 +36,6 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
acts_as_commentable (4.0.2)
acts_as_tree (2.1.0)
activerecord (>= 3.0.0)
arel (6.0.0)
@ -211,7 +210,6 @@ PLATFORMS
ruby
DEPENDENCIES
acts_as_commentable
acts_as_tree
bcrypt (~> 3.1.7)
capistrano (= 2.15.5)

View File

@ -1,5 +0,0 @@
# -*- encoding : utf-8 -*-
class Album < ActiveRecord::Base
validates :name, :presence => true, :uniqueness => true
end

View File

@ -1,5 +0,0 @@
# -*- encoding : utf-8 -*-
class AllowedBlockContent < ActiveRecord::Base
belongs_to :block
belongs_to :content_type
end

View File

@ -1,116 +0,0 @@
class Article < ActiveRecord::Base
has_many :comments, :as => :commentable
belongs_to :image_file
validates :title, :presence => true
validates :slug, :presence => true, :uniqueness => true
has_one :block, :as => :blockable
belongs_to :category
has_many :enabled_comments,-> {where(:enabled => true)}, :source => :comments, :as => :commentable
after_create :after_creation
HUMAN_NAME = "lien vers un article."
before_validation do
self.slug = self.slug.to_slug
self.tags_cache = self.tags_cache.gsub(/ +/, ' ').gsub(/, /,',').gsub(/ ,/,',').gsub(/,+/, ',')
self.tags_cache = self.tags_cache.to_s.gsub(/ +/, ' ').gsub(/, /,',').gsub(/ ,/,',').gsub(/,+/, ',')
end
def after_creation
@block = Block.new(:block_name => "Contenu")
@block.blockable = self
@block.save
end
def alloweds_types
self.block.allow_types :TitleContent, :TextContent, :ImageContent, :LinkContent, :GalleryContent, :HtmlContent
end
scope :recents, -> {where("enabled = ?",true ).order("published_at DESC, created_at DESC")}
scope :between, lambda { |start, stop|
after(start).before(stop)
}
scope :after, lambda { |date|
where("(published_at >= ?)", date )
}
scope :before, lambda { |date|
where("(published_at <= ?)", date )
}
after_initialize do
if self.published_at
self.published_at = self.published_at.strftime('%d/%m/%Y')
end
end
before_save do
#self.tags_cache = nil
tag_list = self.tags_cache.split(',').uniq
tag_names = []
tag_objects_list = []
tag_list.each do |tag_name|
if tag = Tag.create(:name => tag_name.capitalize) and tag.id
self.tags << tag
else
tag = Tag.find_by_slug(tag_name.to_slug)
self.tags << tag if !self.tags.include?(tag)
end
tag_objects_list << tag
tag_names << tag.name
end
self.tags_cache = tag_names.sort.join(",").to_s
tags_to_remove = tags - tag_objects_list
tags_id_to_remove = (tags - tag_objects_list).map {|t| t.id}
self.tag_taggables.where(:tag_id => tags_id_to_remove).each { |t| t.destroy }
end
has_many :tag_taggables, :as => :taggable
has_many :tags, :through => :tag_taggables
def generate_tags_cache
self.tags_cache = self.tags.map{|a| a.name}.join(",").to_s
end
def tag_by_tag_ids(tags_id)
Tag.find(tags_id).each do |tag|
self.tags << tag if !self.tags.include?(tag)
end
self.generate_tags_cache
self.save
end
before_destroy do
self.tags_cache = ""
self.save
end
end

View File

@ -1,60 +0,0 @@
# -*- encoding : utf-8 -*-
class Block < ActiveRecord::Base
ContentTypes = {
TitleContent: "Titre",
TextContent: "Texte",
ImageContent: "Image",
LinkContent:"Lien",
BreakContent: "Séparation",
HtmlContent: "Code HTML",
DownloadContent: "Téléchargement",
GalleryContent: "Galerie",
DynamicContent: "Contenu dynamique",
TableContent: "Tableau",
BlockContent: "Bloc",
MapContent: "Plan",
}
belongs_to :blockable, :polymorphic => true
#has_many :portlets, :dependent => :destroy, -> {:order => :position}
has_many :portlets,-> { order :position }, dependent: :destroy
accepts_nested_attributes_for :portlets
def allow_types(*type)
if type == [:all]
ContentTypes
else
allow_types = {}
type.each do |content|
allow_types[content] = ContentTypes[content]
end
allow_types
end
end
def alloweds_types
allow_types :all #:TitleContent, :ImageContent
end
def dup
@block = Block.new(self.attributes)
@block.id = nil
@block.save
self.portlets.each do |portlet|
new_p = portlet.dup
new_p.save
@block.portlets << new_p
end
@block
end
end

View File

@ -1,60 +0,0 @@
# -*- encoding : utf-8 -*-
class BlockContent < ActiveRecord::Base
has_one :portlet, :as => :content, :dependent => :destroy
has_many :blocks, :as => :blockable, :dependent => :destroy
validates :nbr_columns, :presence => true
STYLES = [["normal",1],["fond gris foncé",2],["fond gris clair",3],["fond bleu",4],["fond jaune",5],["fond vert",6],["fond béton",7],["Contenu centré",8]]
before_create do
self.row1 = self.row2 = self.row3 = self.row4 = 12/self.nbr_columns.to_i
end
def row1_value
self.row1.to_i
end
def row2_value
self.row1.to_i+self.row2.to_i
end
def row3_value
self.row1.to_i+self.row2.to_i+self.row3.to_i
end
def row4_value
self.row1.to_i+self.row2.to_i+self.row3.to_i+self.row4.to_i
end
def dup
@new = BlockContent.new(self.attributes)
@new.id = nil
@new.save
self.blocks.each do |block|
new_b = block.dup
new_b.blockable = @new
new_b.save
end
@new
end
def self.picto
"columns"
end
end

View File

@ -1,10 +0,0 @@
# -*- encoding : utf-8 -*-
class BreakContent < ActiveRecord::Base
has_one :portlet, :as => :content, :dependent => :destroy
STYLES = []#[["Style 1",1], ["Style 2",2]]
def self.picto
"minus"
end
end

View File

@ -1,127 +0,0 @@
class Category < ActiveRecord::Base
has_many :articles
validates :name, :presence => true, :uniqueness => true
validates :slug, :presence => true, :uniqueness => true
before_validation do
self.slug = self.name.to_slug
self.validate_permalink
end
attr_accessor :skip_before_update, :skip_permalink
acts_as_tree
def generate_permalink
r = ""
node, ancestors = self, []
ancestors << node = Category.find(node.parent_id) while node.parent_id?
ancestors.reverse.each do |ancestor|
r += ancestor.slug.to_s
r+= "/"
end
r+= self.slug.to_s
end
def set_permalink
if !skip_permalink
self.permalink = self.generate_permalink
self.skip_permalink = true
self.skip_before_update = true
self.save
end
end
def validate_permalink
self.parent_id = nil if self.parent_id == 0
errors.add(:parent_id, 'doit être différent de la page actuelle') if parent_id == id and id != nil
if self.id
errors.add(:parent_id, 'attention la page parente à pour page parente celle-ci = boucle') if self.parent_id and self.id == Category.find(self.parent_id).parent_id
end
conditions = ["parent_id "+(self.parent_id ? "=" : "IS")+" ? and slug = ? "+("and id != ?" if self.id).to_s,self.parent_id ,self.slug]
conditions << self.id if self.id
if Category.where(conditions).first
errors.add(:slug, 'est déjà utilisé')
end
end
before_create do
if !position
top = Category.where( :parent_id => self.parent_id).order("position DESC")
if top
self.position = top.position.to_i + 1
else
self.position = 1
end
end
end
before_update do
if self.parent_id_changed?
Category.where(["position > ? and parent_id "+(self.changes['parent_id'][0] ? "=" : "IS")+" ?",self.position,self.changes['parent_id'][0]]).each do |portlet|
portlet.position = portlet.position - 1
portlet.save!
end
self.position = 1
Category.where(["parent_id "+(self.parent_id ? "=" : "IS")+" ?",self.parent_id]).each do |portlet|
portlet.position = portlet.position + 1
portlet.save!
end
end
end
before_destroy do
Category.where(["position > ? and parent_id "+(self.parent_id ? "=" : "IS")+" ?",self.position,self.parent_id]).each do |portlet|
portlet.position = portlet.position - 1
portlet.skip_before_update = true
portlet.save!
end
end
end

View File

@ -1,90 +0,0 @@
# -*- encoding : utf-8 -*-
class CelTable < ActiveRecord::Base
belongs_to :table_row
#belongs_to :table_content possible
has_one :block, :as => :blockable, :dependent => :destroy
attr_accessor :skip_before_update
before_create do
if !position
self.position = 1
end
if position
CelTable.where(["position >= ? and table_row_id = ?",self.position,self.table_row_id]).each do |cel_table|
cel_table.position = cel_table.position + 1
cel_table.skip_before_update = true
cel_table.save!
end
end
end
after_create do
block = Block.create()
self.block = block
end
before_update do
if !skip_before_update
if self.position_changed?
#si la position est plus grande que l'ancienne
if self.changes['position'][1] > self.changes['position'][0]
CelTable.where(["position > ? and position <= ? and table_row_id = ?",self.changes['position'][0],self.changes['position'][1],self.table_row_id]).each do |cel_table|
cel_table.position = cel_table.position - 1
cel_table.skip_before_update = true
cel_table.save!
end
end
#si la position est plus petite que l'ancienne.
if self.changes['position'][1] < self.changes['position'][0]
CelTable.where(["position >= ? and position < ? and table_row_id = ?",self.changes['position'][1],self.changes['position'][0],self.table_row_id]).each do |cel_table|
cel_table.position = cel_table.position + 1
cel_table.skip_before_update = true
cel_table.save!
end
end
end
end
end
before_destroy do
CelTable.where(["position > ? and table_row_id = ?",self.position,self.table_row_id]).each do |cel_table|
cel_table.position = cel_table.position - 1
cel_table.skip_before_update = true
cel_table.save!
end
end
def dup
@new = CelTable.new(self.attributes)
@new.id = nil
@new.table_row_id = nil
@new.save
@new.block.destroy
new_b = self.block.dup
new_b.save
@new.block = new_b
@new.save
@new
end
end

View File

@ -1,26 +0,0 @@
# -*- encoding : utf-8 -*-
class CibleAlias < ActiveRecord::Base
include Rails.application.routes.url_helpers
belongs_to :menu_item
validates :menu_item_id, :presence => true
#has_one :link_content, :as => :cible
has_one :cibleable, :as => :cible
def cible_name
"A changer"
end
def cible_url
"A changer"
end
def url
if self.menu_item
menu_item_path(:url => self.menu_item.permalink)
end
end
end

View File

@ -1,11 +0,0 @@
# -*- encoding : utf-8 -*-
class CibleUrl < ActiveRecord::Base
validates :url, :presence => true
def cible_name
"A changer"
end
def cible_url
"A changer"
end
end

View File

@ -1,16 +0,0 @@
# -*- encoding : utf-8 -*-
class Comment < ActiveRecord::Base
include ActsAsCommentable::Comment
belongs_to :commentable, :polymorphic => true
validates :pseudo, :presence => true
validates :comment, :presence => true
scope :recents, where("enabled = ?",true ).order("created_at ASC")
end

View File

@ -1,44 +0,0 @@
# -*- encoding : utf-8 -*-
class DataFile < ActiveRecord::Base
belongs_to :file_folder
mount_uploader :file, FileUploader
before_save do
if !self.name?
self.name = File.basename(self.file.filename, File.extname(self.file.filename)).to_s if self.file?
end
end
before_create { generate_token() }
def file_type
mime = `file --mime -br "#{self.file.path}"`.strip.split(';')[0]
mime
end
def abstract_file_name
self.name
end
def abstract_file_name_slug
self.name.to_slug
end
def generate_token()
begin
self[:token] = SecureRandom.urlsafe_base64
end while DataFile.exists?(:token => self[:token])
end
end

View File

@ -1,12 +0,0 @@
# -*- encoding : utf-8 -*-
class DownloadContent < ActiveRecord::Base
belongs_to :data_file
has_one :portlet, :as => :content, :dependent => :destroy
STYLES = []#[["Medium","1"], ["Small","2"], ["Square","3"], ["Thumb","4"]]
def self.picto
"cloud-download"
end
end

View File

@ -1,13 +0,0 @@
# -*- encoding : utf-8 -*-
class DynamicContent < ActiveRecord::Base
has_one :portlet, :as => :content, :dependent => :destroy
belongs_to :item
NAMES = {}
def self.picto
"cog"
end
end

View File

@ -1,54 +0,0 @@
class Event < ActiveRecord::Base
belongs_to :image_file
validates :title, :presence => true
validates :slug, :presence => true, :uniqueness => true
has_one :block, :as => :blockable
after_create :after_creation
before_validation do
self.slug = self.title.to_slug
end
after_initialize do
if self.start_at
self.start_at = self.start_at.strftime('%d/%m/%Y')
end
end
def after_creation
@block = Block.new(:block_name => "Contenu")
@block.blockable = self
@block.save
end
def alloweds_types
self.block.allow_types :TitleContent, :TextContent, :ImageContent, :LinkContent, :GalleryContent, :HtmlContent
end
#where("enabled = ?",true ).
scope :recents, -> {order("start_at DESC, created_at DESC")}
scope :between, lambda { |start, stop|
after(start).before(stop)
}
scope :after, lambda { |date|
where("(start_at >= ?)", date )
}
scope :before, lambda { |date|
where("(start_at <= ?)", date )
}
end

View File

@ -1,16 +0,0 @@
class ExternalLink < ActiveRecord::Base
validates :url, :presence => true
def cible_name
"Lien externe : #{self.url}"
end
def cible_url
self.url
end
end

View File

@ -1,3 +0,0 @@
# -*- encoding : utf-8 -*-
class FileFolder < ActiveRecord::Base
end

View File

@ -1,49 +0,0 @@
# -*- encoding : utf-8 -*-
class GalleryContent < ActiveRecord::Base
has_many :gallery_images, -> {order :position}
has_one :portlet, :as => :content, :dependent => :destroy
STYLES = [["Petites miniatures",1], ["Diaporama",2], ["Petits carrés",3], ["Réalisations",4]]
def dup
@new = GalleryContent.new(self.attributes)
@new.id = nil
@new.save
self.gallery_images.each do |gallery_image|
new_g = gallery_image.dup
new_g.gallery_content = @new
new_g.save
end
@new
end
def tags
to_r = []
self.gallery_images.each do |gallery_image|
gallery_image.tags.to_s.split(",").each do |tag|
to_r << tag.strip
end
end
to_r = to_r.sort.uniq
return to_r
end
def self.picto
""
end
end

View File

@ -1,17 +0,0 @@
# -*- encoding : utf-8 -*-
class GalleryImage < ActiveRecord::Base
belongs_to :image_file
belongs_to :gallery
belongs_to :gallery_content
validates :title, :presence => true
def tags_class
to_r = []
self.tags.to_s.split(",").each do |tag|
to_r << tag.to_slug
end
to_r = to_r.join(" ")
end
end

View File

@ -1,11 +0,0 @@
# -*- encoding : utf-8 -*-
class HtmlContent < ActiveRecord::Base
has_one :portlet, :as => :content, :dependent => :destroy
STYLES = []#[["Style 1",1], ["Style 2",2]]
CONTENT_TYPES = ["haml","html"]
def self.picto
"code"
end
end

View File

@ -1,35 +0,0 @@
# -*- encoding : utf-8 -*-
class ImageContent < ActiveRecord::Base
belongs_to :image_file
has_one :portlet, :as => :content, :dependent => :destroy
STYLES = [["Grande","5"],["Taille moyenne","1"], ["Petite taille","2"], ["Petit carré","3"], ["Miniature","4"],["Orginale","6"]]
ALIGNS = [["centré","center"], ["gauche","left"],["droite","right"],["Aucun","none"]]
belongs_to :cible, :polymorphic => true
accepts_nested_attributes_for :cible
before_validation do
if !self.with_cible
self.cible_type = nil
self.cible_id = nil
end
end
def url
if self.cible
cible.url
else
""
end
end
def self.picto
"picture-o"
end
end

View File

@ -1,43 +0,0 @@
# -*- encoding : utf-8 -*-
class ImageFile < ActiveRecord::Base
mount_uploader :file, ImageUploader
before_save do
if !self.name?
self.name = File.basename(self.file.filename, File.extname(self.file.filename)).to_s if self.file?
end
end
before_validation do
if self.tags?
self.tags = self.tags.gsub(/ +?,/, ',')
self.tags = self.tags.gsub(/, +?/, ',')
self.tags = self.tags.gsub(/,/, ', ')
end
end
after_save do
tags_to_save = self.tags.to_s.split(',')
tags_to_save.each do |t|
name = t.to_s.strip
Tag.find_or_create_by_name(t.to_s.strip) if name.size > 0
end
end
def rotate(degrees=90)
versions = [self.file.path, self.file.large.path, self.file.large.medium.path, self.file.large.medium.small.path, self.file.large.medium.small.thumb.path, self.file.square.path]
versions.each do |v|
image = Magick::ImageList.new(v)
image = image.rotate(degrees)
image.write(v)
end
self.updated_at = Time.now
self.save
end
end

View File

@ -1,39 +0,0 @@
# -*- encoding : utf-8 -*-
class ImgLinkContent < ActiveRecord::Base
belongs_to :image_file
belongs_to :item
belongs_to :cible, :polymorphic => true
has_one :portlet, :as => :content, :dependent => :destroy
validates :title, :presence => true
accepts_nested_attributes_for :cible, :reject_if => lambda { |a| 1 == 1 }
before_validation do
if !self.with_cible
self.cible_type = nil
self.cible_id = nil
end
end
def url
if self.cible
cible.url
else
""
end
end
STYLES = [["Style 1",1], ["Style 2",2]]
def self.picto
"cloud-download"
end
end

View File

@ -1,45 +0,0 @@
# -*- encoding : utf-8 -*-
class LinkContent < ActiveRecord::Base
belongs_to :item
belongs_to :cible, :polymorphic => true
accepts_nested_attributes_for :cible
CIBLE_TYPES = [
{:slug => "MenuItems", :name => "Alias"},
{:slug => "ExternalLink", :name => "Lien externe"},
]
def url
if self.cible
cible.url
else
""
end
end
has_one :portlet, :as => :content, :dependent => :destroy
validates :name, :presence => true
def url
if self.cible
cible.url
else
""
end
end
STYLES = [["Style 1",1], ["Style 2",2]]
def self.picto
"chain"
end
end

View File

@ -1,16 +0,0 @@
# -*- encoding : utf-8 -*-
class MapContent < ActiveRecord::Base
has_one :portlet, :as => :content, :dependent => :destroy
validates :address, :presence => true
VIEWS = [["Plan",1], ["Mixte",2], ["Satelite",3]]
ZOOMS = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]
def self.picto
"map-marker"
end
end

View File

@ -1,12 +0,0 @@
# -*- encoding : utf-8 -*-
class Menu < ActiveRecord::Base
has_many :menu_items
validates_presence_of :name, :max_levels
validates_uniqueness_of :name
end

View File

@ -1,13 +0,0 @@
# -*- encoding : utf-8 -*-
class MenuAlias < ActiveRecord::Base
belongs_to :menu_item_alias, :foreign_key => :menu_item_id, :class_name => "MenuItem"
has_one :menu_item, :as => :menu_content
validates :menu_item_id, :presence => true
HUMAN_NAME = "Alias"
end

View File

@ -1,8 +0,0 @@
# -*- encoding : utf-8 -*-
class MenuFolder < ActiveRecord::Base
belongs_to :folder
HUMAN_NAME = "Dossier"
end

View File

@ -1,165 +0,0 @@
# -*- encoding : utf-8 -*-
class MenuItem < ActiveRecord::Base
ContentTypes =[
{:slug => "Page", :name => "page"},
{:slug => "MenuAlias", :name => "Alias"},
{:slug => "MenuUrl", :name => "Lien externe"},
{:slug => "Article", :name => "Lien vers un article"},
]
include Rails.application.routes.url_helpers
belongs_to :menu_content, :polymorphic => true
belongs_to :menu
validates :name, :presence => true
validates :slug, :presence => true
attr_accessor :skip_before_update, :skip_permalink
accepts_nested_attributes_for :menu_content
acts_as_tree
def url
if menu_content
self.permalink
else
"/404.html"
end
end
def cible_url
menu_item_path(:url => self.permalink)
end
before_validation do
self.slug = self.slug.to_slug
#self.validate_permalink
end
before_save do
end
def generate_permalink
r = ""
node, ancestors = self, []
ancestors << node = MenuItem.find(node.parent_id) while node.parent_id?
ancestors.reverse.each do |ancestor|
r += ancestor.slug.to_s
r+= "/"
end
r+= self.slug.to_s
end
def set_permalink
if !skip_permalink
self.permalink = self.generate_permalink
self.skip_permalink = true
self.skip_before_update = true
self.save
# self.children.each do |child|
# child.save
# end
end
end
def validate_permalink
self.parent_id = nil if self.parent_id == 0
errors.add(:parent_id, 'doit être différent de la page actuelle') if parent_id == id and id != nil
if self.id
errors.add(:parent_id, 'attention la page parente à pour page parente celle-ci = boucle') if self.parent_id and self.id == MenuItem.find(self.parent_id).parent_id
end
conditions = ["menu_id = ? and parent_id "+(self.parent_id ? "=" : "IS")+" ? and slug = ? "+("and id != ?" if self.id).to_s, self.menu_id,self.parent_id ,self.slug]
conditions << self.id if self.id
if MenuItem.where(conditions).first
errors.add(:slug, 'est déjà utilisé')
end
end
def cible_name
"Elément de menu : #{self.name}"
end
before_create do
if !position
top = MenuItem.where(:parent_id => self.parent_id, :menu_id => self.menu_id).order("position DESC").first
if top
self.position = top.position.to_i + 1
else
self.position = 1
end
end
end
before_update do
if self.parent_id_changed?
MenuItem.where(["menu_id = ? and position > ? and parent_id "+(self.changes['parent_id'][0] ? "=" : "IS")+" ?",self.menu_id,self.position,self.changes['parent_id'][0]]).each do |portlet|
portlet.position = portlet.position - 1
portlet.save!
end
self.position = 1
MenuItem.where(["menu_id = ? and parent_id "+(self.parent_id ? "=" : "IS")+" ?",self.menu_id,self.parent_id]).each do |portlet|
portlet.position = portlet.position + 1
portlet.save!
end
end
end
before_destroy do
MenuItem.where(["menu_id = ? and position > ? and parent_id "+(self.parent_id ? "=" : "IS")+" ?",self.menu_id,self.position,self.parent_id]).each do |portlet|
portlet.position = portlet.position - 1
portlet.skip_before_update = true
portlet.save!
end
end
scope :archived, -> {where("archived = ?",true )}
scope :unarchived, -> {where(:archived => nil )}
end

View File

@ -1,9 +0,0 @@
# -*- encoding : utf-8 -*-
class MenuUrl < ActiveRecord::Base
has_one :menu_item, :as => :menu_content
validates :url, :presence => true
HUMAN_NAME = "Lien externe"
end

View File

@ -1,43 +0,0 @@
# -*- encoding : utf-8 -*-
class Page < ActiveRecord::Base
has_one :menu_item, :as => :menu_content
has_many :blocks, :as => :blockable, :dependent => :destroy
validates :title, :presence => true
HUMAN_NAME = "Page"
after_create :after_creation
def after_creation
@block = Block.new(:block_name => "general")
@block.blockable = self
@block.save
end
def dup
@new = Page.new(self.attributes)
@new.id = nil
@new.save
@new.blocks.destroy_all
self.blocks.each do |block|
new_b = block.dup
new_b.blockable = @new
new_b.save
end
@new
end
end

View File

@ -1,39 +0,0 @@
# -*- encoding : utf-8 -*-
class Portlet < ActiveRecord::Base
belongs_to :block
belongs_to :content, :polymorphic => true
accepts_nested_attributes_for :content
attr_accessor :skip_before_update
def dup
@portlet = Portlet.new(self.attributes)
@portlet.id = nil
@portlet.content = self.content.dup
@portlet.save
@portlet
end
before_create do
end
before_update do
end
before_destroy do
end
end

View File

@ -1,51 +0,0 @@
# -*- encoding : utf-8 -*-
class TableContent < ActiveRecord::Base
has_one :portlet, :as => :content, :dependent => :destroy
has_many :table_rows,->{ order :position}
has_many :cel_tables, :through => :table_rows
STYLES = [["avec bordures",1],["sans bordures",2]]
after_create do
self.nbr_rows.to_i.times do
table_row = TableRow.create(:position => 1, :table_content_id => self.id)
self.nbr_cols.to_i.times do
cel_table = CelTable.new
table_row.cel_tables << cel_table
end
end
end
def dup
@new = TableContent.new(self.attributes)
@new.id = nil
@new.save
@new.table_rows.destroy_all
self.table_rows.each do |table_row|
new_tr = table_row.dup
new_tr.table_content = @new
new_tr.save
end
@new
end
def self.picto
"table"
end
end

View File

@ -1,82 +0,0 @@
# -*- encoding : utf-8 -*-
class TableRow < ActiveRecord::Base
has_many :cel_tables, -> {order :position}
belongs_to :table_content
attr_accessor :skip_before_update
before_create do
if !position
self.position = 1
end
if position
TableRow.where(["position >= ? and table_content_id = ?",self.position,self.table_content_id]).each do |table_row|
table_row.position = table_row.position + 1
table_row.skip_before_update = true
table_row.save!
end
end
end
before_update do
if !skip_before_update
if self.position_changed?
#si la position est plus grande que l'ancienne
if self.changes['position'][1] > self.changes['position'][0]
TableRow.where(["position > ? and position <= ? and table_content_id = ?",self.changes['position'][0],self.changes['position'][1],self.table_content_id]).each do |table_row|
table_row.position = table_row.position - 1
table_row.skip_before_update = true
table_row.save!
end
end
#si la position est plus petite que l'ancienne.
if self.changes['position'][1] < self.changes['position'][0]
TableRow.where(["position >= ? and position < ? and table_content_id = ?",self.changes['position'][1],self.changes['position'][0],self.table_content_id]).each do |table_row|
table_row.position = table_row.position + 1
table_row.skip_before_update = true
table_row.save!
end
end
end
end
end
before_destroy do
TableRow.where(["position > ? and table_content_id = ?",self.position,self.table_content_id]).each do |table_row|
table_row.position = table_row.position - 1
table_row.skip_before_update = true
table_row.save!
end
table = self.table_content
table_past_count = table.nbr_rows
table.nbr_rows = table_past_count - 1
table.save
end
def dup
@new = TableRow.new(self.attributes)
@new.id = nil
@new.table_content_id = nil
@new.save
@new.cel_tables.destroy_all
self.cel_tables.each do |cel_table|
new_td = cel_table.dup
new_td.table_row = @new
new_td.save
end
@new
end
end

View File

@ -1,30 +0,0 @@
class Tag < ActiveRecord::Base
before_validation do
self.slug = self.name.to_s.to_slug
end
has_many :tag_taggables
has_many :taggable, :through => :tag_taggables
def recents_articles
articles_id = self.tag_taggables.where(:taggable_type => "Article").map {|t| t.taggable_id}
Article.recents.where(:id => articles_id)
end
validates :slug, :presence => true, :uniqueness => true
def self.tag_list
r = []
Tag.all.each do |tag|
r << tag.name
end
r
end
end

View File

@ -1,16 +0,0 @@
class TagTaggable < ActiveRecord::Base
belongs_to :tag
belongs_to :taggable, :polymorphic => true
before_destroy do
puts self.tag
if self.tag
Tag.find(self.tag_id).destroy if self.tag.tag_taggables.size == 1
end
end
end

View File

@ -1,10 +0,0 @@
# -*- encoding : utf-8 -*-
class TextContent < ActiveRecord::Base
has_one :portlet, :as => :content, :dependent => :destroy
STYLES = []#[["Style 1",1], ["Style 2",2]]
def self.picto
"align-justify"
end
end

View File

@ -1,11 +0,0 @@
# -*- encoding : utf-8 -*-
class TitleContent < ActiveRecord::Base
has_one :portlet, :as => :content, :dependent => :destroy
validates :content, :presence => true
LEVELS = [1,2,3,4,5,6]
STYLES = []#[["Style 1",1], ["Style 2",2]]
def self.picto
"header"
end
end