suite contacts
This commit is contained in:
parent
1b86493950
commit
89a9647c25
@ -17,6 +17,8 @@
|
||||
#= require vendor/jquery.fileupload-process
|
||||
#= require vendor/select2.min
|
||||
|
||||
#= require note_files/note_files
|
||||
|
||||
|
||||
#= require manager
|
||||
#= require image_files
|
||||
|
@ -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;
|
||||
|
60
app/controllers/admin/contact_files_controller.rb
Normal file
60
app/controllers/admin/contact_files_controller.rb
Normal file
@ -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
|
@ -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!
|
||||
|
@ -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
|
||||
|
16
app/models/contact_file.rb
Normal file
16
app/models/contact_file.rb
Normal file
@ -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
|
59
app/uploaders/contact_file_uploader.rb
Normal file
59
app/uploaders/contact_file_uploader.rb
Normal file
@ -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
|
@ -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
|
||||
|
18
app/views/admin/contact_files/_contact_file.html.haml
Normal file
18
app/views/admin/contact_files/_contact_file.html.haml
Normal file
@ -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
|
||||
|
4
app/views/admin/contact_files/create.js.erb
Normal file
4
app/views/admin/contact_files/create.js.erb
Normal file
@ -0,0 +1,4 @@
|
||||
$("#contact_files").prepend("<%= escape_javascript(render(@contact_file)) %>");
|
||||
$('#contact_file_<%=@contact_file.id %>').addClass('active');
|
||||
|
||||
<%= flash_js %>
|
@ -1 +1 @@
|
||||
$('#admin_row_<%= @admin.id %>').remove();
|
||||
$('#contact_<%= @contact.id %>').remove();
|
@ -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
|
||||
<!-- The template to display files available for upload -->
|
||||
<script id="template-upload" type="text/x-tmpl">
|
||||
{% for (var i=0, file; file=o.files[i]; i++) { %}
|
||||
<tr class="template-upload fade">
|
||||
<td>
|
||||
<span class="preview"></span>
|
||||
</td>
|
||||
<td>
|
||||
<p class="name">{%=file.name%}</p>
|
||||
{% if (file.error) { %}
|
||||
<div><span class="label label-important">Error</span> {%=file.error%}</div>
|
||||
{% } %}
|
||||
</td>
|
||||
<td>
|
||||
<p class="size">{%=o.formatFileSize(file.size)%}</p>
|
||||
{% if (!o.files.error) { %}
|
||||
<div class="progress progress-success progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="bar" style="width:0%;"></div></div>
|
||||
{% } %}
|
||||
</td>
|
||||
<td>
|
||||
{% if (!o.files.error && !i && !o.options.autoUpload) { %}
|
||||
<button class="btn btn-primary start">
|
||||
<i class="icon-upload icon-white"></i>
|
||||
<span>Start</span>
|
||||
</button>
|
||||
{% } %}
|
||||
{% if (!i) { %}
|
||||
<button class="btn btn-warning cancel">
|
||||
<i class="icon-ban-circle icon-white"></i>
|
||||
<span>Cancel</span>
|
||||
</button>
|
||||
{% } %}
|
||||
</td>
|
||||
</tr>
|
||||
{% } %}
|
||||
</script>
|
||||
<!-- The template to display files available for download -->
|
||||
<script id="template-download" type="text/x-tmpl">
|
||||
{% for (var i=0, file; file=o.files[i]; i++) { %}
|
||||
<tr class="template-download fade", :style => "display:none;">
|
||||
|
||||
</tr>
|
||||
{% } %}
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
: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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
14
db/migrate/20161007154739_create_contact_files.rb
Normal file
14
db/migrate/20161007154739_create_contact_files.rb
Normal file
@ -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
|
6
db/migrate/20161020160659_add_infos_sups_to_contacts.rb
Normal file
6
db/migrate/20161020160659_add_infos_sups_to_contacts.rb
Normal file
@ -0,0 +1,6 @@
|
||||
class AddInfosSupsToContacts < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :contacts, :sheet_type, :string
|
||||
add_column :contacts, :owner, :string
|
||||
end
|
||||
end
|
18
db/schema.rb
18
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|
|
||||
|
BIN
public/provenance/2.png
Normal file
BIN
public/provenance/2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
15
test/fixtures/contact_files.yml
vendored
Normal file
15
test/fixtures/contact_files.yml
vendored
Normal file
@ -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
|
7
test/models/contact_file_test.rb
Normal file
7
test/models/contact_file_test.rb
Normal file
@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ContactFileTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user