From ec1f1ae71af1f70911595316d55f7878b0a8c581 Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Sun, 1 Nov 2015 18:50:03 +0100 Subject: [PATCH] contacts --- app/controllers/admin/contacts_controller.rb | 70 ++++++++++++++++++ .../admin/student_users_controller.rb | 66 ----------------- app/views/admin/contacts/_contact.html.haml | 24 +++++++ app/views/admin/contacts/_form.haml | 27 +++++++ app/views/admin/contacts/_show.html.haml | 63 ++++++++++++++++ app/views/admin/contacts/create.js.erb | 2 + .../destroy.js.erb | 0 .../{student_users => contacts}/edit.haml | 0 .../{student_users => contacts}/edit.js.erb | 0 app/views/admin/contacts/index.html.haml | 44 ++++++++++++ .../{student_users => contacts}/index.js.erb | 0 .../{student_users => contacts}/new.haml | 0 .../{student_users => contacts}/new.js.erb | 0 app/views/admin/contacts/show.html.haml | 6 ++ app/views/admin/contacts/update.js.erb | 4 ++ app/views/admin/student_users/_form.haml | 72 ------------------- .../student_users/_student_user.html.haml | 30 -------- app/views/admin/student_users/create.js.erb | 2 - app/views/admin/student_users/index.html.haml | 45 ------------ app/views/admin/student_users/update.js.erb | 3 - app/views/layouts/admin.html.haml | 20 +----- config/routes.rb | 2 +- .../20151101172457_add_infos_to_contacts.rb | 12 ++++ db/schema.rb | 10 ++- 24 files changed, 264 insertions(+), 238 deletions(-) create mode 100644 app/controllers/admin/contacts_controller.rb delete mode 100644 app/controllers/admin/student_users_controller.rb create mode 100644 app/views/admin/contacts/_contact.html.haml create mode 100644 app/views/admin/contacts/_form.haml create mode 100644 app/views/admin/contacts/_show.html.haml create mode 100644 app/views/admin/contacts/create.js.erb rename app/views/admin/{student_users => contacts}/destroy.js.erb (100%) rename app/views/admin/{student_users => contacts}/edit.haml (100%) rename app/views/admin/{student_users => contacts}/edit.js.erb (100%) create mode 100644 app/views/admin/contacts/index.html.haml rename app/views/admin/{student_users => contacts}/index.js.erb (100%) rename app/views/admin/{student_users => contacts}/new.haml (100%) rename app/views/admin/{student_users => contacts}/new.js.erb (100%) create mode 100644 app/views/admin/contacts/show.html.haml create mode 100644 app/views/admin/contacts/update.js.erb delete mode 100644 app/views/admin/student_users/_form.haml delete mode 100644 app/views/admin/student_users/_student_user.html.haml delete mode 100644 app/views/admin/student_users/create.js.erb delete mode 100644 app/views/admin/student_users/index.html.haml delete mode 100644 app/views/admin/student_users/update.js.erb create mode 100644 db/migrate/20151101172457_add_infos_to_contacts.rb diff --git a/app/controllers/admin/contacts_controller.rb b/app/controllers/admin/contacts_controller.rb new file mode 100644 index 0000000..0acb1bc --- /dev/null +++ b/app/controllers/admin/contacts_controller.rb @@ -0,0 +1,70 @@ +class Admin::ContactsController < ApplicationController + layout "admin" + + before_filter :auth_admin + + def index + + @contacts = Contact.order("created_at DESC").all + end + + + def show + @contact = Contact.find(params[:id]) + + if @contact.readed != true + @contact.readed = true + @contact.save + end + + end + + + def new + @contact = Contact.new + + end + + def edit + @contact = Contact.find(params[:id]) + + end + + def create + @contact = Contact.new(contact_params) + + if @contact.save + @contacts = Contact.order("created_at DESC").all + else + render :action => "new" + end + end + + def update + @contact = Contact.find(params[:id]) + + if @contact.update_attributes(contact_params) + + else + render :action => "edit" + end + + end + + + + def destroy + @contact = Contact.find(params[:id]) + + @contact.destroy if @contact != @current_contact + + end + + private + def contact_params + params.require(:contact).permit! + end + + + +end diff --git a/app/controllers/admin/student_users_controller.rb b/app/controllers/admin/student_users_controller.rb deleted file mode 100644 index 7176b60..0000000 --- a/app/controllers/admin/student_users_controller.rb +++ /dev/null @@ -1,66 +0,0 @@ -class Admin::StudentUsersController < ApplicationController - layout "admin" - - before_filter :auth_admin - - def index - - @student_users = StudentUser.all - end - - - def show - @student_user = StudentUser.find(params[:id]) - - end - - - def new - @student_user = StudentUser.new - - end - - def edit - @student_user = StudentUser.find(params[:id]) - - end - - def create - @student_user = StudentUser.new(student_user_params) - - if @student_user.save - redirect_to admin_student_users_path - else - render :action => "new" - end - end - - def update - @student_user = StudentUser.find(params[:id]) - - if @student_user.update_attributes(student_user_params) - - redirect_to admin_student_users_path - else - render :action => "edit" - end - - end - - - - def destroy - @student_user = StudentUser.find(params[:id]) - - @student_user.destroy if @student_user != @current_student_user - - end - - private - def student_user_params - params.require(:student_user).permit! - end - - - -end diff --git a/app/views/admin/contacts/_contact.html.haml b/app/views/admin/contacts/_contact.html.haml new file mode 100644 index 0000000..d8f17ed --- /dev/null +++ b/app/views/admin/contacts/_contact.html.haml @@ -0,0 +1,24 @@ +%tr.vertical_center.contact#contact{:id => contact.id, :class => ("success" if !contact.readed)} + + %td + =l contact.created_at + %td + =contact.name + %td + =contact.email + %td + =contact.tel + + + %td.actions + + + = link_to i(:"trash-o"), [:admin, contact], :confirm => 'Voulez-vous vraiment supprimer cet utilisateur ?', :method => :delete, :remote => true + + = link_to i(:pencil), edit_admin_contact_path(contact), :remote => true + + = link_to i(:eye), [:admin, contact] + + + + diff --git a/app/views/admin/contacts/_form.haml b/app/views/admin/contacts/_form.haml new file mode 100644 index 0000000..5fc4cb3 --- /dev/null +++ b/app/views/admin/contacts/_form.haml @@ -0,0 +1,27 @@ += semantic_form_for [:admin, @contact], :remote => true do |f| + .content + =f.inputs do + = f.input :readed, :label => "Lu ?" + = f.input :name, :label => "Nom" + = f.input :email, :label => "Email" + = f.input :tel, :label => "Téléphone" + = f.input :place, :label => "Lieu" + + = f.input :message, :label => "Message" + + = f.input :address, :label => "Adresse" + = f.input :address2, :label => "Adresse (suite)" + = f.input :cp, :label => "Code postal" + = f.input :city, :label => "Ville" + = f.input :country, :label => "Pays", :as => :string + + + = f.input :notes, :label => "Notes" + + + + + .actions + =f.submit "Sauvegarder", :class => "btn btn-primary" + + \ No newline at end of file diff --git a/app/views/admin/contacts/_show.html.haml b/app/views/admin/contacts/_show.html.haml new file mode 100644 index 0000000..7478512 --- /dev/null +++ b/app/views/admin/contacts/_show.html.haml @@ -0,0 +1,63 @@ + +%table.table + %tr + %td + Date + %td + =l @contact.created_at + %tr + %td + Nom + %td + =@contact.name + %tr + %td + Email + %td + =@contact.email + %tr + %td + Téléphone + %td + =@contact.tel + %tr + %td + Lieu + %td + =@contact.place + + + +%hr + =simple_format @contact.message +%hr + + +%table.table + %tr + %td + Adresse + %td + =@contact.address + %tr + %td + Adresse suite + %td + =@contact.address2 + %tr + %td + Ville + %td + =@contact.cp + =@contact.city + + %tr + %td + Pays + + %td + =@contact.country + +%hr + =simple_format @contact.notes +%hr \ No newline at end of file diff --git a/app/views/admin/contacts/create.js.erb b/app/views/admin/contacts/create.js.erb new file mode 100644 index 0000000..93bf342 --- /dev/null +++ b/app/views/admin/contacts/create.js.erb @@ -0,0 +1,2 @@ +$('#admin_rows').html("<%= escape_javascript(render(@contacts))%>"); +close_pane_hover(); \ No newline at end of file diff --git a/app/views/admin/student_users/destroy.js.erb b/app/views/admin/contacts/destroy.js.erb similarity index 100% rename from app/views/admin/student_users/destroy.js.erb rename to app/views/admin/contacts/destroy.js.erb diff --git a/app/views/admin/student_users/edit.haml b/app/views/admin/contacts/edit.haml similarity index 100% rename from app/views/admin/student_users/edit.haml rename to app/views/admin/contacts/edit.haml diff --git a/app/views/admin/student_users/edit.js.erb b/app/views/admin/contacts/edit.js.erb similarity index 100% rename from app/views/admin/student_users/edit.js.erb rename to app/views/admin/contacts/edit.js.erb diff --git a/app/views/admin/contacts/index.html.haml b/app/views/admin/contacts/index.html.haml new file mode 100644 index 0000000..de753b7 --- /dev/null +++ b/app/views/admin/contacts/index.html.haml @@ -0,0 +1,44 @@ += link_to 'Ajouter un contact', new_admin_contact_path, :class => "btn btn-primary", :style => "float:right;", :remote => true + + +%h1 Liste des contacts + + +%table.table.table-hover + %thead#Admin_rows_header.rows_header + + %tr + %td + Date + %td + Nom + %td + Email + %td + Tel + + + + + %td{:style => "width:150px"} +   + + + + + %tbody#admin_rows.rows + + =render @contacts + + + + + + + + + + + + + diff --git a/app/views/admin/student_users/index.js.erb b/app/views/admin/contacts/index.js.erb similarity index 100% rename from app/views/admin/student_users/index.js.erb rename to app/views/admin/contacts/index.js.erb diff --git a/app/views/admin/student_users/new.haml b/app/views/admin/contacts/new.haml similarity index 100% rename from app/views/admin/student_users/new.haml rename to app/views/admin/contacts/new.haml diff --git a/app/views/admin/student_users/new.js.erb b/app/views/admin/contacts/new.js.erb similarity index 100% rename from app/views/admin/student_users/new.js.erb rename to app/views/admin/contacts/new.js.erb diff --git a/app/views/admin/contacts/show.html.haml b/app/views/admin/contacts/show.html.haml new file mode 100644 index 0000000..dc76093 --- /dev/null +++ b/app/views/admin/contacts/show.html.haml @@ -0,0 +1,6 @@ += link_to i(:pencil), edit_admin_contact_path(@contact), :remote => true += link_to "retour", admin_contacts_path(), :class => "btn btn-primary" +#show=render :partial => "show" + + + diff --git a/app/views/admin/contacts/update.js.erb b/app/views/admin/contacts/update.js.erb new file mode 100644 index 0000000..3d8d874 --- /dev/null +++ b/app/views/admin/contacts/update.js.erb @@ -0,0 +1,4 @@ +$('#show').html("<%= escape_javascript(render(:partial => "show"))%>"); +$('#contact_<%= @contact.id %>').replaceWith("<%= escape_javascript(render(@contact))%>"); + +close_pane_hover(); \ No newline at end of file diff --git a/app/views/admin/student_users/_form.haml b/app/views/admin/student_users/_form.haml deleted file mode 100644 index f961e80..0000000 --- a/app/views/admin/student_users/_form.haml +++ /dev/null @@ -1,72 +0,0 @@ -= semantic_form_for [:admin, @student_user] do |f| - %hr - .row - .col-md-4 - - =f.input :lock, :label => "Verouillé" - =l f.object.locked_at if f.object.lock - .col-md-4 - =f.input :student_group, :as => :check_boxes, :collection => StudentGroup.all, :label => "Groupe d'étudiant" - %hr - - .row - .col-md-4 - = f.input :name, :label => "Nom" - .col-md-4 - = f.input :firstname, :label => "Prénom" - .col-md-4 - =image_tag(f.object.avatar.square.url, :style => "height:4em;float:left;margin-right:10px;border-radius:50%;") if f.object.avatar - = f.input :avatar, :label => "Image de profil" - - .row - .col-md-4 - = f.input :email, :label => "Email" - .col-md-4 - = f.input :show_email, :label => "Permettre aux étudiants de voir mon mail ?" if f.object.id - .row - .col-md-4 - = f.input :password, :label => "Mot de passe" - .col-md-4 - = f.input :password_confirmation, :label => "Confirmation" - .col-md-4 - - - - .row - .col-md-4 - = f.input :tel, :label => "Téléphone" - .col-md-4 - = f.input :show_tel, :label => "Permettre aux étudiants de voir mon numéro ?" if f.object.id - - .row - .col-md-4 - = f.input :address, :label => "Adresse" - .col-md-4 - = f.input :address2, :label => "Adresse (suite)" - .col-md-4 - .row - .col-md-4 - = f.input :cp, :label => "Code postal" - .col-md-4 - = f.input :city, :label => "Ville" - .col-md-4 - = f.input :country, :label => "Pays", :as => :string - - - - - =f.inputs do - - = f.input :bio, :label => "Présentation" - - - - - - - - - %br - =f.submit "Sauvegarder", :class => "btn btn-primary" - - \ No newline at end of file diff --git a/app/views/admin/student_users/_student_user.html.haml b/app/views/admin/student_users/_student_user.html.haml deleted file mode 100644 index cbdeca3..0000000 --- a/app/views/admin/student_users/_student_user.html.haml +++ /dev/null @@ -1,30 +0,0 @@ -%tr.vertical_center.student_user#student_user{:id => student_user.id} - - %td=image_tag (student_user.avatar? ? student_user.avatar.square.url : ""), :class => "avatar", :style => "width:50px; border-radius:50%;" - - %td=link_to student_user.firstname.to_s+" "+student_user.name.to_s, student_student_user_path(student_user) - - %td - =student_user.cp - =student_user.city - -if student_user.country? - ="-" - =student_user.country - - %td - =student_user.email - %td - =student_user.tel - %td - ="Verouillé" if student_user.lock - - -if !@student_group - %td.actions - = link_to i(:"trash-o"), [:admin, student_user], :confirm => 'Voulez-vous vraiment supprimer cet utilisateur ?', :method => :delete, :remote => true - - = link_to i(:pencil), edit_admin_student_user_path(student_user) - - - - - \ No newline at end of file diff --git a/app/views/admin/student_users/create.js.erb b/app/views/admin/student_users/create.js.erb deleted file mode 100644 index 4bc6130..0000000 --- a/app/views/admin/student_users/create.js.erb +++ /dev/null @@ -1,2 +0,0 @@ -$('#admin_rows').html("<%= escape_javascript(render(@admins))%>"); -close_pane_hover(); \ No newline at end of file diff --git a/app/views/admin/student_users/index.html.haml b/app/views/admin/student_users/index.html.haml deleted file mode 100644 index 01fc46e..0000000 --- a/app/views/admin/student_users/index.html.haml +++ /dev/null @@ -1,45 +0,0 @@ -= link_to 'Ajouter un utilisateur', new_admin_student_user_path, :class => "btn btn-primary", :style => "float:right;" - - -%h1 Liste des étudiants - - -%table.table.table-hover - %thead#Admin_rows_header.rows_header - - %tr - %td - - %td - Nom - %td - Adresse - %td - Email - %td - Téléphone - - - - %td{:style => "width:100px"} -   - - - - - %tbody#admin_rows.rows - - =render @student_users - - - - - - - - - - - - - diff --git a/app/views/admin/student_users/update.js.erb b/app/views/admin/student_users/update.js.erb deleted file mode 100644 index 3c75f21..0000000 --- a/app/views/admin/student_users/update.js.erb +++ /dev/null @@ -1,3 +0,0 @@ -$('#admin_row_<%= @admin.id %>').replaceWith("<%= escape_javascript(render(@admin))%>"); - -close_pane_hover(); \ No newline at end of file diff --git a/app/views/layouts/admin.html.haml b/app/views/layouts/admin.html.haml index 5384caa..04e5f92 100644 --- a/app/views/layouts/admin.html.haml +++ b/app/views/layouts/admin.html.haml @@ -35,24 +35,8 @@ %ul.nav.navbar-nav %li= link_to "admins", admin_admins_path - %li - -Menu.all.each do |menu| - = link_to "Pages", admin_menu_items_path(:menu_id => menu.id) - - %li= link_to "témoignages", admin_testimonies_path - - - %li.dropdown - %a.dropdown-toggle{"data-toggle" => "dropdown", href: "#"} - Etudiants - %ul.dropdown-menu - %li= link_to "Etudiants", admin_student_users_path - %li= link_to "Ressources", admin_topics_path - %li.divider - %li= link_to "Groupe d'étudiants", admin_student_groups_path - - %li= link_to "Images", admin_image_files_path - %li= link_to "Fichiers", admin_data_files_path + + %li= link_to "Contacts", admin_contacts_path diff --git a/config/routes.rb b/config/routes.rb index 5bffd64..ef81e9d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -90,7 +90,7 @@ CMSnb::Application.routes.draw do end namespace :admin do - resources :student_users + resources :contacts resources :student_groups resources :note_files resources :notes diff --git a/db/migrate/20151101172457_add_infos_to_contacts.rb b/db/migrate/20151101172457_add_infos_to_contacts.rb new file mode 100644 index 0000000..d2f36cd --- /dev/null +++ b/db/migrate/20151101172457_add_infos_to_contacts.rb @@ -0,0 +1,12 @@ +class AddInfosToContacts < ActiveRecord::Migration + def change + add_column :contacts, :address, :string + add_column :contacts, :address2, :string + add_column :contacts, :cp, :string + add_column :contacts, :city, :string + add_column :contacts, :country, :string + add_column :contacts, :notes, :text + add_column :contacts, :statut, :string + add_column :contacts, :readed, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index e0e88a9..1db536e 100644 --- a/db/schema.rb +++ b/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: 20141106180846) do +ActiveRecord::Schema.define(version: 20151101172457) do create_table "admins", force: true do |t| t.string "name" @@ -154,6 +154,14 @@ ActiveRecord::Schema.define(version: 20141106180846) do t.datetime "created_at" t.datetime "updated_at" t.string "place" + t.string "address" + t.string "address2" + t.string "cp" + t.string "city" + t.string "country" + t.text "notes" + t.string "statut" + t.boolean "readed" end create_table "content_types", force: true do |t|