FAQ admin
This commit is contained in:
parent
a3d3c6063d
commit
9e3dd91a06
110
app/controllers/admin/faqs_controller.rb
Normal file
110
app/controllers/admin/faqs_controller.rb
Normal file
@ -0,0 +1,110 @@
|
||||
# -*- encoding : utf-8 -*-
|
||||
|
||||
class Admin::FaqsController < ApplicationController
|
||||
|
||||
before_filter :auth_admin
|
||||
|
||||
layout "admin"
|
||||
|
||||
|
||||
|
||||
before_filter :find_faqs
|
||||
|
||||
def index
|
||||
|
||||
end
|
||||
|
||||
|
||||
def cible
|
||||
|
||||
render :layout => false
|
||||
|
||||
end
|
||||
|
||||
|
||||
def new
|
||||
|
||||
@faq = Faq.new
|
||||
|
||||
end
|
||||
|
||||
|
||||
def edit
|
||||
|
||||
@faq = Faq.find(params[:id])
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
|
||||
@faq = Faq.new(faq_params)
|
||||
|
||||
|
||||
if @faq.save
|
||||
flash[:notice] = "L'faq à été ajouté avec succès."
|
||||
self.find_faqs
|
||||
|
||||
else
|
||||
render :action => "new"
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
def update
|
||||
|
||||
@faq = Faq.find(params[:id])
|
||||
|
||||
|
||||
if params[:faq]
|
||||
if @faq.update_attributes(faq_params)
|
||||
flash[:notice] = "L'faq à été modifié avec succès."
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
|
||||
|
||||
elsif params[:tag_id]
|
||||
@faq.tag_by_tag_ids(params[:tag_id])
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
def destroy
|
||||
|
||||
@faq = Faq.find(params[:id])
|
||||
@faq.destroy
|
||||
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def find_faqs
|
||||
|
||||
|
||||
@faqs = Faq.all
|
||||
per_page = (params[:per_page] and params[:per_page] != "") ? params[:per_page] : 5000
|
||||
page = (params[:page] and params[:page] != "") ? params[:page] : 1
|
||||
@faqs = @faqs.page(page).per(per_page)
|
||||
|
||||
#@faqs = Event.order('start_at, stop_at').after(start).before(stop)
|
||||
end
|
||||
|
||||
private
|
||||
def faq_params
|
||||
params.require(:faq).permit(:author_id, :category_id, :enabled, :published_at, :title, :slug, :tags_cache, :description, :image_file_id, :title_cached)
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
140
app/models/faq.rb
Normal file
140
app/models/faq.rb
Normal file
@ -0,0 +1,140 @@
|
||||
class Faq < ActiveRecord::Base
|
||||
|
||||
belongs_to :image_file
|
||||
|
||||
has_one :block, :as => :blockable
|
||||
|
||||
after_create :after_creation
|
||||
|
||||
before_validation do
|
||||
|
||||
self.slug = self.title.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
|
||||
|
||||
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
|
22
app/views/admin/faqs/_faq.html.haml
Normal file
22
app/views/admin/faqs/_faq.html.haml
Normal file
@ -0,0 +1,22 @@
|
||||
%tr#faq_row.faq_row{:id => faq.id, :class => ("warning" if !faq.enabled)}
|
||||
|
||||
|
||||
%td=faq.title
|
||||
|
||||
%td{:style => "width:300px;"}
|
||||
-faq.tags.order(:name).each do |tag|
|
||||
.tag_label=tag.name
|
||||
|
||||
|
||||
|
||||
%td{:style => "width:140px"}
|
||||
= link_to i(:"trash-o"), [:admin, faq], :confirm => 'Voulez-vous vraiment supprimer cet faq ?', :method => :delete, :remote => true
|
||||
|
||||
= link_to i(:pencil), edit_admin_faq_path(faq), :style => "padding:0px 0px 0px 0px;", :remote => true
|
||||
= link_to i(:plus), edit_admin_faq_path(faq), :style => "padding:0px 0px 0px 0px;"
|
||||
|
||||
=link_to i(:"level-down"), admin_faq_path(:id => faq.id, :format => "js"), :class => "set_tag"
|
||||
|
||||
|
||||
|
||||
|
24
app/views/admin/faqs/_form.html.haml
Normal file
24
app/views/admin/faqs/_form.html.haml
Normal file
@ -0,0 +1,24 @@
|
||||
= semantic_form_for [:admin,@faq], :remote => true do |form|
|
||||
.content
|
||||
= form.inputs do
|
||||
=form.input :enabled, :label => "Publier"
|
||||
=form.input :image_file_id, :as => :qi_image_select
|
||||
|
||||
= form.input :title, :label => "Titre :"
|
||||
|
||||
=# form.input :slug, :label => "Slug :"
|
||||
|
||||
= form.input :description, :label => "Description courte :", :as => :text
|
||||
|
||||
= form.input :tags_cache, :label => "Tags :"
|
||||
|
||||
%script
|
||||
$("#faq_tags_cache").select2({
|
||||
=raw'tags:'+Tag.tag_list.to_json+','
|
||||
tokenSeparators: [","]});
|
||||
|
||||
|
||||
|
||||
|
||||
.actions
|
||||
= form.submit "Sauvegarder", :class => "btn btn-primary"
|
10
app/views/admin/faqs/_index_block.html.haml
Normal file
10
app/views/admin/faqs/_index_block.html.haml
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
.search_pannel
|
||||
|
||||
|
||||
%table#faqs.table
|
||||
=render @faqs
|
||||
#pagination
|
||||
= paginate @faqs, :remote => true
|
||||
|
||||
|
13
app/views/admin/faqs/_show.html.haml
Normal file
13
app/views/admin/faqs/_show.html.haml
Normal file
@ -0,0 +1,13 @@
|
||||
#faq_show.QI_background_middle.QI_padding_small
|
||||
%table
|
||||
|
||||
%tr
|
||||
%td{:style => "width:150px;"} Nom :
|
||||
%td=@faq.title
|
||||
|
||||
|
||||
|
||||
|
||||
%tr
|
||||
%td{:style => "vertical-align:top"} Description courte :
|
||||
%td= simple_format @faq.description
|
14
app/views/admin/faqs/_tags.html.haml
Normal file
14
app/views/admin/faqs/_tags.html.haml
Normal file
@ -0,0 +1,14 @@
|
||||
#tags
|
||||
-Tag.order(:name).all.each do |tag|
|
||||
.tag_label#tag_label{:"data-tag_id" => tag.id, :id => tag.id}
|
||||
=tag.name
|
||||
=ic(:"level-up")
|
||||
|
||||
|
||||
:coffeescript
|
||||
|
||||
if typeof(tag_id) != 'undefined'
|
||||
$(".set_tag").show()
|
||||
$.each tag_id, (i,a) ->
|
||||
$("#tag_label_"+a).addClass("active")
|
||||
|
5
app/views/admin/faqs/create.js.erb
Normal file
5
app/views/admin/faqs/create.js.erb
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
close_pane_hover();
|
||||
|
||||
$('#faqs').html("<%= escape_javascript(render(@faqs))%>");
|
||||
|
2
app/views/admin/faqs/destroy.js.erb
Normal file
2
app/views/admin/faqs/destroy.js.erb
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
$('#article_row_<%=@article.id%>').remove();
|
81
app/views/admin/faqs/edit.html.haml
Normal file
81
app/views/admin/faqs/edit.html.haml
Normal file
@ -0,0 +1,81 @@
|
||||
#toolbar-text
|
||||
|
||||
#menu_item_block_edit{:style => "margin-right:330px;margin-top:45px;"}
|
||||
|
||||
=render :partial => "admin/blocks/block", :locals => {:block => @faq.block, :sortable => true}
|
||||
|
||||
|
||||
%br
|
||||
%br
|
||||
%br
|
||||
%br
|
||||
%br
|
||||
%br
|
||||
%br
|
||||
%br
|
||||
%br
|
||||
%br
|
||||
%br
|
||||
#menu_item_inspector_container
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#menu_item_informations
|
||||
%h4
|
||||
Infos sur l'faq
|
||||
|
||||
|
||||
.panel#collapseOne{:style => "display:none;"}
|
||||
=render :partial => "form"
|
||||
|
||||
%h4 éléments
|
||||
|
||||
.panel#collapse2
|
||||
.block_portlets_sortable#content_types
|
||||
-@faq.block.alloweds_types.each do |slug, name|
|
||||
|
||||
.content_type{:id => slug, :"data-type" => slug}
|
||||
=#i slug.to_s.constantize.picto
|
||||
=image_tag("admin/content_type/type_"+slug.to_s+".png", :alt => name, :title => name, :class => "handle")
|
||||
|
||||
|
||||
#collapse3{:style => "display:none;"}
|
||||
%h4 Modifier l'élément
|
||||
|
||||
|
||||
.panel
|
||||
#element_form
|
||||
|
||||
%div#element_form_action
|
||||
%a.move.btn.btn-default.portlet_handle{:href => "#", :data => {:portlet_id => nil}}
|
||||
%span.move_message
|
||||
=ic :arrows
|
||||
|
||||
déplacer
|
||||
%span.cancel_message
|
||||
=ic :ban
|
||||
|
||||
annuler
|
||||
|
||||
=link_to ic(:"trash-o"), "#", :method => :delete, :data => { :confirm => "Etes-vous sûr ?"}, :remote => true, :class => "btn btn-danger trash"
|
||||
|
||||
%button.save.btn.btn-primary
|
||||
=ic(:"floppy-o")
|
||||
|
||||
Sauvegarder
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
2
app/views/admin/faqs/edit.js.erb
Normal file
2
app/views/admin/faqs/edit.js.erb
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900);
|
54
app/views/admin/faqs/index.html.haml
Normal file
54
app/views/admin/faqs/index.html.haml
Normal file
@ -0,0 +1,54 @@
|
||||
.row{:style => "max-width:inherit;"}
|
||||
.col-xs-9
|
||||
.right= link_to 'Ajouter un faq', new_admin_faq_path(), :class => "btn btn-primary", :remote => true
|
||||
%h1 Liste des faqs
|
||||
|
||||
#faqs_index=render :partial => "index_block"
|
||||
|
||||
.col-xs-3
|
||||
%h3 Tags
|
||||
=render :partial => "tags"
|
||||
|
||||
|
||||
:coffeescript
|
||||
root = exports ? this
|
||||
root.tag_id = []
|
||||
|
||||
|
||||
$(document.body).on "click", "#tags .tag_label", ->
|
||||
|
||||
if $(this).hasClass("active")
|
||||
$(this).removeClass "active"
|
||||
|
||||
else
|
||||
$(this).addClass "active"
|
||||
|
||||
root.tag_id = []
|
||||
|
||||
$("#tags .tag_label.active").each ->
|
||||
root.tag_id.push $(this).data "tag_id"
|
||||
|
||||
if root.tag_id.length > 0
|
||||
$(".set_tag").show()
|
||||
else
|
||||
$(".set_tag").hide()
|
||||
|
||||
|
||||
$(document.body).on "click", ".set_tag", ->
|
||||
|
||||
$.ajax({
|
||||
url:$(this).attr("href"),
|
||||
type: "PUT",
|
||||
data: {
|
||||
tag_id : tag_id
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
return false
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
2
app/views/admin/faqs/index.js.erb
Normal file
2
app/views/admin/faqs/index.js.erb
Normal file
@ -0,0 +1,2 @@
|
||||
$('#articles_index').html("<%= escape_javascript(render(:partial => "index_block"))%>");
|
||||
unset_busy();
|
2
app/views/admin/faqs/new.js.erb
Normal file
2
app/views/admin/faqs/new.js.erb
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",700,900);
|
9
app/views/admin/faqs/update.js.erb
Normal file
9
app/views/admin/faqs/update.js.erb
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
|
||||
$('#faq_row_<%= @faq.id %>').replaceWith("<%= escape_javascript(render(@faq))%>");
|
||||
|
||||
$('#faq_show').replaceWith("<%= escape_javascript(render(:partial => "show"))%>");
|
||||
|
||||
|
||||
$('#tags').replaceWith("<%= escape_javascript(render(:partial => 'tags'))%>");
|
||||
close_pane_hover();
|
@ -60,6 +60,7 @@
|
||||
%li.divider
|
||||
%li= link_to "Actualité", admin_articles_path
|
||||
%li= link_to "Agenda", admin_events_path
|
||||
%li= link_to "FAQ", admin_faqs_path
|
||||
%li.divider
|
||||
%li= link_to "Images", admin_image_files_path
|
||||
%li= link_to "Fichiers", admin_data_files_path
|
||||
|
@ -7,6 +7,9 @@ Survey::Application.routes.draw do
|
||||
get 'actualites/:id.html' => "public/articles#show", :as => "public_article"
|
||||
get 'actualites.html' => "public/articles#index", :as => "articles"
|
||||
|
||||
get 'faqs/:id.html' => "public/faqs#show", :as => "public_faq"
|
||||
get 'faqs.html' => "public/faqs#index", :as => "faqs"
|
||||
|
||||
|
||||
get "blog/archives/:year/:month.html"=> "public/articles#archives", :as => :archive_public_article
|
||||
get "blog/tags/:id.html"=> "public/articles#tags", :as => :public_tag
|
||||
@ -20,10 +23,14 @@ Survey::Application.routes.draw do
|
||||
get 'plaquettes/gaspillage.:f' => 'plaquettes#gaspillage', :f => "html"
|
||||
get 'plaquettes/:slug.:f' => 'plaquettes#show', :f => "html"
|
||||
|
||||
|
||||
|
||||
get 'mail_assets/:token.png' => "admin/mail_trackings#update", :as => :image_tracking
|
||||
|
||||
|
||||
namespace :public do
|
||||
resources :faqs
|
||||
|
||||
resources :orders do
|
||||
|
||||
member do
|
||||
@ -64,8 +71,18 @@ Survey::Application.routes.draw do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
#admin
|
||||
namespace :admin do
|
||||
|
||||
|
||||
resources :faqs
|
||||
|
||||
|
||||
|
||||
resources :orders do
|
||||
member do
|
||||
get :resend
|
||||
|
17
db/migrate/20151021135332_create_faqs.rb
Normal file
17
db/migrate/20151021135332_create_faqs.rb
Normal file
@ -0,0 +1,17 @@
|
||||
class CreateFaqs < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :faqs do |t|
|
||||
t.string :title
|
||||
t.text :description
|
||||
t.boolean :enabled
|
||||
t.string :slug
|
||||
t.references :image_file
|
||||
|
||||
t.string :tags_cache
|
||||
t.string :tags_cache_slug
|
||||
t.integer :category_id
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
15
db/schema.rb
15
db/schema.rb
@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20151021132546) do
|
||||
ActiveRecord::Schema.define(version: 20151021135332) do
|
||||
|
||||
create_table "admins", force: true do |t|
|
||||
t.string "email", default: "", null: false
|
||||
@ -225,6 +225,19 @@ ActiveRecord::Schema.define(version: 20151021132546) do
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "faqs", force: true do |t|
|
||||
t.string "title"
|
||||
t.text "description"
|
||||
t.boolean "enabled"
|
||||
t.string "slug"
|
||||
t.integer "image_file_id"
|
||||
t.string "tags_cache"
|
||||
t.string "tags_cache_slug"
|
||||
t.integer "category_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "file_folders", force: true do |t|
|
||||
t.string "name"
|
||||
t.boolean "super_admin"
|
||||
|
Loading…
x
Reference in New Issue
Block a user