diff --git a/app/assets/javascripts/admin.coffee b/app/assets/javascripts/admin.coffee
index de53fc0..ced06d9 100644
--- a/app/assets/javascripts/admin.coffee
+++ b/app/assets/javascripts/admin.coffee
@@ -17,6 +17,8 @@
#= require vendor/jquery.fileupload-process
#= require vendor/select2.min
+#= require note_files/note_files
+
#= require manager
#= require image_files
diff --git a/app/assets/javascripts/note_files/note_files.js b/app/assets/javascripts/note_files/note_files.js
index f4113fd..85ad701 100644
--- a/app/assets/javascripts/note_files/note_files.js
+++ b/app/assets/javascripts/note_files/note_files.js
@@ -1,8 +1,9 @@
-function init_note_upload_fields(note_id){
- drop = $('#note_'+note_id+' .fileupload').closest(".bottom")
+function init_contact_upload_fields(contact_id){
+ alert("t");
+ drop = $('#contact_'+contact_id+' .fileupload').closest(".bottom")
- $('#note_'+note_id+' .fileupload').fileupload({
+ $('#contact_'+contact_id+' .fileupload').fileupload({
url: $(this).attr("action"),
dropZone: drop,
autoUpload: true,
@@ -20,17 +21,17 @@ function init_note_upload_fields(note_id){
drop: function (e, data) {
- $('#note_'+note_id+' .fileupload').closest(".bottom").css("background", "rgb(255, 255, 204)");
+ $('#contact_'+contact_id+' .fileupload').closest(".bottom").css("background", "rgb(255, 255, 204)");
}
});
- $(".note .bottom").bind('dragover', function (e) {
+ $(".contact .bottom").bind('dragover', function (e) {
$(this).css("background", "#B7DF63");
});
- $(".note .bottom").bind('dragleave', function (e) {
+ $(".contact .bottom").bind('dragleave', function (e) {
$(this).css("background", "rgb(255, 255, 204)");
});
@@ -44,7 +45,7 @@ function init_note_upload_fields(note_id){
$(document).ready(function () {
- $("body").on("click", ".note .add_files",function(){
+ $("body").on("click", ".contact .add_files",function(){
$(this).next('input').click();
return false;
diff --git a/app/controllers/admin/contact_files_controller.rb b/app/controllers/admin/contact_files_controller.rb
new file mode 100644
index 0000000..56ab5ca
--- /dev/null
+++ b/app/controllers/admin/contact_files_controller.rb
@@ -0,0 +1,60 @@
+# -*- encoding : utf-8 -*-
+ class Admin::ContactFilesController < ApplicationController
+ before_filter :auth_admin
+
+
+ layout "admin"
+
+ def index
+ params[:file_folder_id] = params[:file_folder_id] || 1
+
+ @file_folder = FileFolder.find(params[:file_folder_id])
+ @file_folders = FileFolder.all(:order => :name)
+ @contact_files = DataFile.all(:order => "created_at DESC", :conditions => {:file_folder_id => @file_folder.id})
+ @contact_file = DataFile.new(:file_folder_id => @file_folder.id)
+ if request.xhr?
+ render :layout => false
+ end
+ end
+
+ def new
+ end
+
+ def edit
+ end
+
+ def create
+ @contact_file_create = true
+ @contact_file = ContactFile.new(:name => params[:files].original_filename, :contact_id => params[:contact_id], :file =>params[:files])
+
+ if @contact_file.save
+
+ else
+
+ end
+
+
+ end
+
+ def update
+ @contact_file = DataFile.find(params[:id])
+ if @contact_file.update_attributes(params.require(:contact_file).permit!)
+
+ else
+
+ end
+ end
+
+ def destroy
+ @contact_file = DataFile.find(params[:id])
+ @contact_file.destroy
+
+ flash[:notice] = "Le fichier à bien été supprimée."
+ end
+
+ def show
+ @contact_file = DataFile.find(params[:id])
+
+ end
+
+end
diff --git a/app/controllers/admin/contacts_controller.rb b/app/controllers/admin/contacts_controller.rb
index d1602ae..7bd3044 100644
--- a/app/controllers/admin/contacts_controller.rb
+++ b/app/controllers/admin/contacts_controller.rb
@@ -1,8 +1,8 @@
class Admin::ContactsController < ApplicationController
layout "admin"
- before_filter :auth_admin
-
+ before_filter :auth_admin, :except => :api
+ skip_before_filter :verify_authenticity_token, :only => :api
def index
@contacts = Contact.order("created_at DESC")
@@ -69,6 +69,52 @@ class Admin::ContactsController < ApplicationController
end
+
+ def api
+
+ contact_api_params = {
+ :name => params[:name],
+
+ :address => params[:address],
+
+ :address2 => params[:address2],
+
+ :cp => params[:cp],
+
+ :city => params[:city],
+
+ :tel => params[:tel],
+
+ :email => params[:mail],
+
+ :place => params[:place],
+
+ :sheet_type => params[:type],
+
+ :owner => params[:owner],
+
+ :message => params[:message]
+
+ }
+
+ @contact = Contact.new(contact_api_params)
+ @contact.provenance_id = 2
+ if @contact.save(:validate => false)
+ render :inline => "ok"
+ puts "OK"
+ else
+ render :inline => "erreur"
+ puts "ERREUR"
+ @contact.errors.each do |error|
+ puts error
+ end
+ end
+
+
+ end
+
+
+
private
def contact_params
params.require(:contact).permit!
diff --git a/app/models/contact.rb b/app/models/contact.rb
index 08b528e..19c7162 100644
--- a/app/models/contact.rb
+++ b/app/models/contact.rb
@@ -6,5 +6,7 @@ class Contact < ActiveRecord::Base
validates :email, :presence => true, :format => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
validates :message, :presence => true
validates :tel, :presence => true
+
+ has_many :contact_files
end
diff --git a/app/models/contact_file.rb b/app/models/contact_file.rb
new file mode 100644
index 0000000..87f5b4b
--- /dev/null
+++ b/app/models/contact_file.rb
@@ -0,0 +1,16 @@
+class ContactFile < ActiveRecord::Base
+ mount_uploader :file, ContactFileUploader
+
+ belongs_to :admin
+ belongs_to :contact
+
+ def file_type
+
+
+ mime = `file --mime -br "#{self.file.path}"`.strip.split(';')[0]
+ mime
+
+ end
+
+
+end
diff --git a/app/uploaders/contact_file_uploader.rb b/app/uploaders/contact_file_uploader.rb
new file mode 100644
index 0000000..b7c2ed8
--- /dev/null
+++ b/app/uploaders/contact_file_uploader.rb
@@ -0,0 +1,59 @@
+# -*- encoding : utf-8 -*-
+
+class ContactFileUploader < CarrierWave::Uploader::Base
+
+ # Include RMagick or ImageScience support:
+ # include CarrierWave::RMagick
+ # include CarrierWave::ImageScience
+
+ # Choose what kind of storage to use for this uploader:
+ storage :file
+ # storage :s3
+
+ # Override the directory where uploaded files will be stored.
+ # This is a sensible default for uploaders that are meant to be mounted:
+ def store_dir
+ "#{Rails.root}/private_medias/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
+ end
+
+ def url
+ "/download_data_files/#{model.token}"
+
+ end
+
+ # Provide a default URL as a default if there hasn't been a file uploaded:
+ def default_url
+ "/images/fallback/" + [version_name, "default.png"].compact.join('_')
+
+ end
+
+ # Process files as they are uploaded:
+ # process :scale => [200, 300]
+ #
+ # def scale(width, height)
+ # # do something
+ # end
+
+ # Create different versions of your uploaded files:
+ # version :thumb do
+ # process :scale => [50, 50]
+ # end
+
+ # Add a white list of extensions which are allowed to be uploaded.
+ # For images you might use something like this:
+ # def extension_white_list
+ # %w(jpg jpeg gif png)
+ # end
+
+ # Override the filename of the uploaded files:
+ # def filename
+ # "something.jpg" if original_filename
+ # end
+
+ def filename
+ File.basename(original_filename, File.extname(original_filename)).to_s.to_slug + File.extname(original_filename).to_s if original_filename
+
+
+ end
+
+end
diff --git a/app/views/admin/contact_actions/_contact_action.html.haml b/app/views/admin/contact_actions/_contact_action.html.haml
index 801d5be..89c84a8 100644
--- a/app/views/admin/contact_actions/_contact_action.html.haml
+++ b/app/views/admin/contact_actions/_contact_action.html.haml
@@ -1,7 +1,7 @@
-.contact_action#contact_action{:id => contact_action.id, :style => "border-color:#{contact_action.admin.color};"}
+.contact_action#contact_action{:id => contact_action.id, :style => ("border-color:#{contact_action.admin.color};" if contact_action.admin)}
%p.name
- -if contact_action.contact.admin
+ -if contact_action.admin
%span{:style => "background:#{contact_action.admin.color};padding:5px 10px;color:white"}
=contact_action.admin.username
%p
diff --git a/app/views/admin/contact_files/_contact_file.html.haml b/app/views/admin/contact_files/_contact_file.html.haml
new file mode 100644
index 0000000..b07c5de
--- /dev/null
+++ b/app/views/admin/contact_files/_contact_file.html.haml
@@ -0,0 +1,18 @@
+- if contact_file.file?
+
+
+ %tr#contact_file.contact_file{:id => contact_file.id, :class => ("new" if @contact_file_create)}
+
+ %td{:style => "width:32px;text-align:center;"}
+ -ext = File.extname(contact_file.file.path)[1..-1]
+ =image_tag "file_types/"+ext+".png", :style => "height:30px;"
+ %td
+ =contact_file.name
+ %td{:style => "width:300px;"}
+
+
+ =contact_file.file_type
+ %td{:style => "width:100px;"}
+ = link_to i(:"trash-o"), admin_contact_file_path(:id => contact_file.id, :manager => params[:manager], :multiple => params[:multiple]), :data => {:confirm => 'Voulez-vous vraiment supprimer cette pièce jointe ?'}, :method => :delete, :remote => true
+ =link_to i(:"download"), contact_file.file.url
+
diff --git a/app/views/admin/contact_files/create.js.erb b/app/views/admin/contact_files/create.js.erb
new file mode 100644
index 0000000..98d8326
--- /dev/null
+++ b/app/views/admin/contact_files/create.js.erb
@@ -0,0 +1,4 @@
+$("#contact_files").prepend("<%= escape_javascript(render(@contact_file)) %>");
+$('#contact_file_<%=@contact_file.id %>').addClass('active');
+
+<%= flash_js %>
diff --git a/app/views/admin/contacts/destroy.js.erb b/app/views/admin/contacts/destroy.js.erb
index f6f6315..bb6b32a 100644
--- a/app/views/admin/contacts/destroy.js.erb
+++ b/app/views/admin/contacts/destroy.js.erb
@@ -1 +1 @@
-$('#admin_row_<%= @admin.id %>').remove();
\ No newline at end of file
+$('#contact_<%= @contact.id %>').remove();
\ No newline at end of file
diff --git a/app/views/admin/contacts/show.html.haml b/app/views/admin/contacts/show.html.haml
index c332ad9..abda07d 100644
--- a/app/views/admin/contacts/show.html.haml
+++ b/app/views/admin/contacts/show.html.haml
@@ -7,9 +7,134 @@
-= link_to 'Ajouter une action', new_admin_contact_action_path(:contact_id => @contact.id, :test => "test"), :class => "btn btn-success", :style => "float:right;", :remote => true
+%h2 Fichiers
+
+
+%form#fileupload{:action => admin_contact_files_path(:contact_id => @contact.id ),:method=>"POST", :enctype=>"multipart/form-data", :style => "display:inline;"}
+ %input{:name => "redirect", :type => "hidden", :value => "/"}/
+
+
+
+ .fileupload-progress.fade{:style => "float:left;"}
+ #upload_details{:style => ""}
+ .content
+ .fileupload-buttonbar
+ %button.btn.btn-warning.cancel{:type => "reset"}
+ %i.icon-ban-circle.icon-white
+ %span Cancel upload
+ %span.fileupload-loading
+
+ %table.table.table-striped{:role => "presentation"}
+ %tbody.ulpoad_files
+
+
+
+ .progress-extended{:style => "float:left;padding: 10px;font-size:14px;line-height:20px;"}
+
+
+ .progress.progress-success.progress-striped.active{"aria-valuemax" => "100", "aria-valuemin" => "0", :role => "progressbar",:style => "width:200px;float:left;margin: 10px;height:20px;"}
+ .bar{:style => "width:0%;"}
+
+
+
+
+
+
+
+
+ .right
+ %a.btn.btn-primary{:href => "#", :onclick => "$(this).next('input').click();"}
+ %span.fileinput-button{}
+ %i.icon-plus.icon-white
+ %span Ajouter des fichiers
+ %input{:multiple => "", :name => "files[]", :type => "file", :style => "display:none;"}
+ %br
+ %br
+
+
+
+
+
+
+
+
+ :plain
+
+
+
+
+
+
+
+
+:coffeescript
+ $('#fileupload').fileupload({
+ paramName:"files",
+ dataType:"script",
+ autoUpload:true,
+ filesContainer:".ulpoad_files"
+
+ }).bind('fileuploadadded',(e, data)->
+ $("#upload_details").show();
+ ).bind('fileuploadfinished',(e, data)->
+ $("#upload_details").hide();
+ )
+
+
+.clear
+%br
+%br
+%table#contact_files.table.table-stripped{:style => "width:100%;"}
+ =render @contact.contact_files
+%br
+%br
+
+
+
+= link_to 'Ajouter une action', new_admin_contact_action_path(:contact_id => @contact.id, :test => "test"), :class => "btn btn-success", :style => "float:right;", :remote => true
+
%h2 Interactions
diff --git a/config/routes.rb b/config/routes.rb
index 06345ef..a78c608 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -90,7 +90,13 @@ CMSnb::Application.routes.draw do
end
namespace :admin do
- resources :contacts
+
+ resources :contact_files
+ resources :contacts do
+ collection do
+ post :api
+ end
+ end
resources :contact_actions
resources :student_groups
resources :note_files
diff --git a/db/migrate/20161007154739_create_contact_files.rb b/db/migrate/20161007154739_create_contact_files.rb
new file mode 100644
index 0000000..384be43
--- /dev/null
+++ b/db/migrate/20161007154739_create_contact_files.rb
@@ -0,0 +1,14 @@
+class CreateContactFiles < ActiveRecord::Migration
+ def change
+ create_table :contact_files do |t|
+ t.references :admin, index: true
+ t.references :contact, index: true
+ t.string :name
+ t.text :description
+ t.string :file
+ t.string :token
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/migrate/20161020160659_add_infos_sups_to_contacts.rb b/db/migrate/20161020160659_add_infos_sups_to_contacts.rb
new file mode 100644
index 0000000..007d3d3
--- /dev/null
+++ b/db/migrate/20161020160659_add_infos_sups_to_contacts.rb
@@ -0,0 +1,6 @@
+class AddInfosSupsToContacts < ActiveRecord::Migration
+ def change
+ add_column :contacts, :sheet_type, :string
+ add_column :contacts, :owner, :string
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 998899b..70d6c25 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: 20161007085559) do
+ActiveRecord::Schema.define(version: 20161020160659) do
create_table "admins", force: true do |t|
t.string "name"
@@ -167,6 +167,20 @@ ActiveRecord::Schema.define(version: 20161007085559) do
add_index "contact_actions", ["contact_id"], name: "index_contact_actions_on_contact_id", using: :btree
+ create_table "contact_files", force: true do |t|
+ t.integer "admin_id"
+ t.integer "contact_id"
+ t.string "name"
+ t.text "description"
+ t.string "file"
+ t.string "token"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ add_index "contact_files", ["admin_id"], name: "index_contact_files_on_admin_id", using: :btree
+ add_index "contact_files", ["contact_id"], name: "index_contact_files_on_contact_id", using: :btree
+
create_table "contacts", force: true do |t|
t.string "name"
t.string "email"
@@ -187,6 +201,8 @@ ActiveRecord::Schema.define(version: 20161007085559) do
t.integer "admin_id"
t.boolean "archived", default: false
t.integer "provenance_id", default: 1
+ t.string "sheet_type"
+ t.string "owner"
end
create_table "content_types", force: true do |t|
diff --git a/public/provenance/2.png b/public/provenance/2.png
new file mode 100644
index 0000000..e49fb00
Binary files /dev/null and b/public/provenance/2.png differ
diff --git a/test/fixtures/contact_files.yml b/test/fixtures/contact_files.yml
new file mode 100644
index 0000000..3fe1894
--- /dev/null
+++ b/test/fixtures/contact_files.yml
@@ -0,0 +1,15 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+
+one:
+ admin_id:
+ contact_id:
+ name: MyString
+ description: MyText
+ file: MyString
+
+two:
+ admin_id:
+ contact_id:
+ name: MyString
+ description: MyText
+ file: MyString
diff --git a/test/models/contact_file_test.rb b/test/models/contact_file_test.rb
new file mode 100644
index 0000000..271d18b
--- /dev/null
+++ b/test/models/contact_file_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class ContactFileTest < ActiveSupport::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end