Commit 3988d2f4 authored by Robert Jean Steven's avatar Robert Jean Steven

ajout de la gestion des invitation pour les pads (en cours non fonctionnel)

parent 3b2f0fa2
......@@ -6,17 +6,48 @@ function Pads_init(){
// *** VARIABLES *** //
// ***************** //
var $Pads_table = $('#Pads_table'); // Table principale Visio
var $Pads_table = $('#Pads_table'), // Table principale Pad
$Pads_users_table = $('#Pads_users_table'), // Table ajouter de nouveau utilisateur
$Users_modale_Pad_table = $('#Users-modale-Pad-table'),
$Groups_modale_Pad_table = $('#Groups-modale-Pad-table'),
$domain_id = "",
$Pad_id = $Pads_users_table.data('params-id');
// ***************** //
// *** EVENEMENTS*** //
// ***************** //
$('#addNewPadButton').click(function() {
var url = window.location.href+'/new';
document.location.href=url;
});
$('#addNewPadButton').click(function() {
var url = window.location.href+'/new';
document.location.href=url;
});
// Ajouter un utilisateur ou un groupe
$('#Pad-ajout-UG').click(function() {
$('#modal-saisie-Pad-UG').modal('show');
initialize_modale_tables();
});
$('#add-users-modal-button').click(function() {
add_groups();
add_users();
add_external_users();
$('#modal-saisie-Pad-UG').modal('hide');
});
$('#Pad-email-UG').click(function() {
send_mails();
});
$('#Pad-supprime-UG').click(function() {
delete_users();
$Pad_users_table.bootstrapTable('refresh');
});
// ***************** //
// *** FONCTIONS *** //
// ***************** //
......@@ -25,6 +56,112 @@ function Pads_init(){
setTimeout(function () {
$Pads_table.bootstrapTable('resetView');
}, 200);
setTimeout(function () {
$Pads_users_table.bootstrapTable('resetView');
}, 200);
function get_domain_id() {
jQuery.ajax({type: "GET",
url: "/current_user/",
dataType: "json",
success: function (data) {
$domain_id = data["domain_id"];
},
error: function (data) {
toastr.error(data.responseText);
}
});
}
function add_groups() {
var ids = Pad_groups_getIdSelections();
for (id of ids) {
jQuery.ajax({type: "POST",
url: "/pads_groups",
dataType: "json",
data: { pads_group: {pad_id: $pad_id, group_id: id} },
success: function (data) {
toastr.success("Le groupe " + id + " a été ajouté.");
$Pad_users_table.bootstrapTable('refresh');
},
error: function (data) {
toastr.error(data.responseText);
}
});
}
}
function add_users() {
var ids = Pad_users_getIdSelections();
for (id of ids) {
jQuery.ajax({type: "POST",
url: "/pads_users",
dataType: "json",
data: { pads_user: {pad_id: $pad_id, uuid: id} },
success: function (data) {
toastr.success("L'utilisateur " + id + " a été ajouté.");
$Visio_users_table.bootstrapTable('refresh');
},
error: function (data) {
toastr.error(data.responseText);
}
});
}
}
function add_external_users() {
var textarea = $('#External-Users-modal-Pad');
var lines = textarea.val().split('\n');
for (line of lines) {
if (line) {
jQuery.ajax({type: "POST",
url: "/pads_users",
dataType: "json",
data: { pads_user: {pad_id: $pad_id, mail: line} },
success: function (data) {
toastr.success("L'utilisateur " + line + " a été ajouté.");
$Pad_users_table.bootstrapTable('refresh');
},
error: function (data) {
toastr.error(data.responseText);
}
});
}
}
}
function send_mails() {
groupe_ids = authorizedUsers_getIdSelections(true);
user_ids = authorizedUsers_getIdSelections(false);
jQuery.ajax({type: "POST",
url: "/pads/" + $pad_id + "/mails",
dataType: "json",
data: { visios: {id: $pad_id, pad_users: user_ids, pad_groups: groupe_ids } },
success: function (data) {
toastr.success("Invitations envoyées par courriel");
},
error: function (data) {
toastr.error(data.responseText);
}
});
}
function delete_users() {
groupe_ids = authorizedUsers_getIdSelections(true);
user_ids = authorizedUsers_getIdSelections(false);
jQuery.ajax({type: "DELETE",
url: "/pads/" + $visio_id + "/users",
dataType: "json",
data: { pads: {id: $pad_id, pad_users: user_ids, pad_groups: groupe_ids } },
success: function (data) {
toastr.success("Les utilisateurs ont été supprimés");
},
error: function (data) {
toastr.error(data.responseText);
}
});
}
// *********************** //
// *** MAIN PAD INIT *** //
......@@ -84,7 +221,7 @@ function Pads_init(){
field: 'url',
title: '',
align: 'right',
//formatter: Visio_Boutons_Show
//formatter: Pad_Boutons_Show
formatter: function(value, row, index) {
html = '<a href="'+ value + '" title="Afficher le pad"><i class="fa fa-pencil tab-button"></i></a>';
if (row["my"]) {
......@@ -94,8 +231,183 @@ function Pads_init(){
return html
}
},
{
field: 'url',
title: '',
align: 'right',
formatter: function(value, row, index) {
return '<a href="'+ value +'/invitation" title="Modifier les paramètres du pad"><i class="fa fa-send tab-button"></i></a>'
}
},
]
]
});
}
\ No newline at end of file
$Pads_table.bootstrapTable('togglePagination'); // Navigation automatique pour changer de page
//**tableau d'invitation aux pad**//
$Pads_users_table.bootstrapTable({
id: 'Pad_users_table',
method: 'get',
url: 'users.json',
toolbar: '#pad-add-user-toolbar',
idField: 'id',
search: true, // active la recherche
reorderableColumns: true,
striped: true, // ligne colore une sur 2
showColumns: false, // bouton afficher et cacher des colonnes, inutile car groupement
showRefresh: true, // bouton refresh
showToggle: false, // affichage different des données tableeau
showExport: true, // bouton d'export de donnees
showFooter: false,
minimumCountColumns:2,
columns: [
[
{
checkbox: true,
align: 'center',
valign: 'bottom'
},
{
field: 'name',
title: 'Liste des personnes invitées à ce pad',
align: 'center',
sortable: true
},
{
field: 'title',
title: 'Type',
align: 'center',
sortable: true,
//formatter: pad_Boutons_Show
formatter: function(value, row, index) {
var icone = "";
icone = (value=="Groupes" ? "fa-users" : (value=="Membre" ? "fa-user" : "fa-globe"));
return '<i class="fa '+ icone +' " title="' + value + '"></i>';
}
}
]
]
});
$Pads_users_table.bootstrapTable('togglePagination'); // Navigation automatique pour changer de page
function initialize_modale_tables() {
//***MODALE TABLEAU GROUPE***//
$Groups_modale_Pad_table.bootstrapTable({
id: 'Groups-modale-pad-table',
method: 'get',
url: '/domains/'+$domain_id+'/groups.json?all=true',
toolbar: '#pad-toolbar',
idField: 'id',
search: true, // active la recherche
reorderableColumns: true,
striped: true, // ligne colore une sur 2
showColumns: false, // bouton afficher et cacher des colonnes, inutile car groupement
showRefresh: true, // bouton refresh
showToggle: false, // affichage different des données tableeau
showExport: true, // bouton d'export de donnees
showFooter: false,
columns: [
[
{
checkbox: true,
align: 'center',
valign: 'bottom'
},
{
field: 'name',
title: 'Nom des groupes',
align: 'center',
sortable: true
},
]
]
});
}
function initialize_modale_tables() {
//***MODALE TABLEAU GROUPE***//
$Groups_modale_Pad_table.bootstrapTable({
id: 'Groups-modale-Pad-table',
method: 'get',
url: '/domains/'+$domain_id+'/groups.json?all=true',
toolbar: '#pad-toolbar',
idField: 'id',
search: true, // active la recherche
reorderableColumns: true,
striped: true, // ligne colore une sur 2
showColumns: false, // bouton afficher et cacher des colonnes, inutile car groupement
showRefresh: true, // bouton refresh
showToggle: false, // affichage different des données tableeau
showExport: true, // bouton d'export de donnees
showFooter: false,
columns: [
[
{
checkbox: true,
align: 'center',
valign: 'bottom'
},
{
field: 'name',
title: 'Nom des groupes',
align: 'center',
sortable: true
},
]
]
});
//***MODALE TABLEAU UTILISATEURS**//
$Users_modale_Pad_table.bootstrapTable({
id: 'Users-modale-Pad-table',
method: 'get',
url: '/domains/'+$domain_id+'/users.json',
toolbar: '#pad-toolbar',
idField: 'id',
search: true, // active la recherche
reorderableColumns: true,
striped: true, // ligne colore une sur 2
showColumns: false, // bouton afficher et cacher des colonnes, inutile car groupement
showRefresh: true, // bouton refresh
showToggle: false, // affichage different des données tableeau
showExport: true, // bouton d'export de donnees
showFooter: false,
columns: [
[
{
checkbox: true,
align: 'center',
valign: 'bottom'
},
{
field: 'last_name',
title: 'Nom',
align: 'center',
sortable: true,
},
{
field: 'first_name',
title: 'Prénom',
align: 'center',
sortable: true,
},
{
field: 'email',
title: 'Email',
align: 'center',
sortable: true
},
]
]
});
}
}
// Place all the styles related to the PadsGroups controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
// Place all the styles related to the PadsUsers controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
......@@ -27,7 +27,7 @@ a {
&:hover {
color: #fff;
//background-color: #000;
background-color: #000;
}
}
......
class PadsController < ApplicationController
before_action :only_logged_users
before_action :set_pad, only: [:show, :edit, :update, :destroy]
before_action :set_pad, only: [:show, :edit, :update, :destroy , :invitation]
# GET /pads
# GET /pads.json
......@@ -34,6 +34,50 @@ class PadsController < ApplicationController
def edit
end
# GET /pads/1/invitation
def invitation
redirect_to "/pad", notice: "Droits insuffisants" unless @pad.owner_id == @current_user.id
end
# GET /pads/1/users.json
def users
groups = PadsGroup.where(pad_id: params[:id])
users = PadsUser.where(pad_id: params[:id])
@users_groups = []
groups.each do |group|
@users_groups << {name: Group.find(group.group_id).name, id: group.id, title: "Groupes"}
end
users.each do |user|
@users_groups << {name: user.mail, id: user.id, title: user.uuid ? "Membre" : "Externe"}
end
end
# DELETE /pads/1/users.json
def destroy_users
groupe_ids = params[:pads][:pad_groups]
if PadsGroup.where(id: groupe_ids).destroy_all
user_ids = params[:pads][:pad_users]
if PadsUser.where(id: user_ids).destroy_all
respond_to do |format|
format.json { head :no_content }
end
else
respond_to do |format|
format.json { render json: "Impossible de supprimer les utilisateurs sélectionnés", status: :unprocessable_entity }
end
end
else
respond_to do |format|
format.json { render json: "Impossible de supprimer les groupes sélectionnés", status: :unprocessable_entity }
end
end
end
# POST /pads
# POST /pads.json
def create
......
class PadsGroupsController < ApplicationController
before_action :set_pads_group, only: [:destroy]
# POST /pads_groups
# POST /pads_groups.json
def create
@pads_group = PadsGroup.new(pads_group_params)
@nb_pads_groups = PadsGroup.where(group_id: @pads_group.group_id, pad_id: @pads_group.pad_id).count
groupe = Group.find(@pads_group.group_id)
respond_to do |format|
if @pads_group.save
format.html { redirect_to @pads_group, notice: 'Pads group was successfully created.' }
format.json { render :show, status: :created, location: @pads_group }
else
format.html { render :new }
format.json { render json: @pads_group.errors, status: :unprocessable_entity }
end
end
end
# DELETE /pads_groups/1
# DELETE /pads_groups/1.json
def destroy
@pads_group.destroy
respond_to do |format|
format.html { redirect_to pads_groups_url, notice: 'Pads group was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_pads_group
@pads_group = PadsGroup.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def pads_group_params
params.require(:pads_group).permit(:group_id, :pad_id)
end
end
class PadsUsersController < ApplicationController
before_action :set_pads_user, only: [:destroy]
# POST /pads_users
# POST /pads_users.json
def create
@pads_user = PadsUser.new(pads_user_params)
@pads_user.mail = User.find(@pads_user.uuid).email if @pads_user.uuid
respond_to do |format|
if @pads_user.save
format.html { redirect_to @pads_user, notice: 'Pads user was successfully created.' }
format.json { render :show, status: :created, location: @pads_user }
else
format.html { render :new }
format.json { render json: @pads_user.errors, status: :unprocessable_entity }
end
end
end
# DELETE /pads_users/1
# DELETE /pads_users/1.json
def destroy
@pads_user.destroy
respond_to do |format|
format.html { redirect_to pads_users_url, notice: 'Pads user was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_pads_user
@pads_user = PadsUser.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def pads_user_params
params.require(:pads_user).permit(:user_id, :pad_id)
end
end
module PadsGroupsHelper
end
module PadsUsersHelper
end
class Pad < ActiveRecord::Base
has_many :pads_users, dependent: :destroy
has_many :pads_groups, dependent: :destroy
end
class PadsGroup < ActiveRecord::Base
belongs_to :pad
end
class PadsUser < ActiveRecord::Base
belongs_to :pad
validates :mail, presence: true, allow_blank: false
end
<!--
Copyright (c) 2017 Robert Jean Steven <robert.steven.974@gmail.com>
This file is part of Zourit.
Zourit is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Zourit is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Zourit. If not, see <http://www.gnu.org/licenses/>.
-->
<div class="z-index-page">
<div class="container">
<div class="panel panel-warning shadow">
<div class="panel-heading clearfix">
<h1>
<%= I18n.t "terms.invitationpad"%>
</h1>
</div>
<div class="panel-body">
<div class="col-sm-12 col-md-12 text-left">
<div class="well well-sm text-center">
<div id="Pad-add-user-toolbar">
<button type="button" id="Pad-ajout-UG" class="btn btn-primary">
<i class="fa fa-plus"></i> <%= I18n.t "terms.adduserorgroup"%>
</button>
<button id="Pad-supprime-UG" class="btn btn-primary z-supprime-utilisateur" disabled>
<i class="glyphicon glyphicon-remove"></i> <%= I18n.t "terms.deleteuserorgroup"%>
</button>
<button id="Pad-email-UG" class="btn btn-primary z-supprime-utilisateur" disabled>
<i class="fa fa-envelope"></i> <%= I18n.t "terms.sendinvit"%>
</button>
</div>
<table id="Pads_users_table" data-params-id="<%= @pad.id %>" data-classes="table table-no-bordered" ></table>
</div>
</div>
</div>
</div>
</div>
<div id="modal-saisie-Pad-UG" class="modal fade z-superadmin-modal-saisie-domaine" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
<div class="modal-dialog modal-m">
<div class="modal-content">
<div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="mySmallModalLabel"><%= I18n.t "terms.adduservisio"%></h4> </div>
<div class="modal-body">
<label><i class="fa fa-users"></i> <%= I18n.t "terms.addgroupuser"%></label><br>
<div class="well well-sm">
<table id="Groups-modale-Pad-table" data-classes="table table-no-bordered" data-pagination="true" ></table>
</div>
<label><i class="fa fa-user"></i> <%= I18n.t "terms.addfielduser"%></label><br>
<div class="well well-sm">
<table id="Users-modale-Pad-table" data-classes="table table-no-bordered" data-pagination="true" ></table>
</div>
<label><i class="fa fa-globe"></i> <%= I18n.t "terms.addexternuser"%></label><br>
<div class="well well-sm">
<div class="field">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></span>
<textarea id="External-Users-modal-Pad" class="form-control" placeholder="<%= I18n.t "terms.saisirmail"%>"/></textarea>
</div>
</div>
</div>
<div class="text-left">
<button id="add-users-modal-button" class="btn btn-primary">
<i class="fa fa-check"></i> <%= I18n.t "terms.valid"%>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
# Copyright (c) 2017 Robert Jean Steven <robert.steven.974@gmail.com>
#
# This file is part of Zourit.
#
# Zourit is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Zourit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Zourit. If not, see <http://www.gnu.org/licenses/>.
json.array!(@users_groups) do |ug|
json.name ug[:name]
json.id ug[:id]
json.title ug[:title]
end
json.extract! pads_group, :id, :group_id, :pad_id, :created_at, :updated_at
json.url pads_group_url(pads_group, format: :json)
json.array!(@pads_groups) do |pads_group|
json.extract! pads_group, :id, :group_id, :pad_id
json.url pads_group_url(pads_group, format: :json)
end
\ No newline at end of file
json.partial! "pads_groups/pads_group", pads_group: @pads_group
json.array!(@pads_users) do |pads_user|
json.extract! pads_user, :id, :mail, :visio_id
json.url pads_user_url(pads_user, format: :json)
end
\ No newline at end of file
json.extract! @pads_user, :id, :mail, :pad_id, :created_at, :updated_at
......@@ -258,6 +258,7 @@ fr:
padname: "Nom du pad"
padlist: "Liste des pads"
modifpad: "Modifier le pad"
invitationpad: "Liste des personnes invité"
#about
version: "Version"
......
Rails.application.routes.draw do
resources :pads_users
resources :pads_groups
resources :pads
resources :visios
resources :domains
resources :users
#root 'accueil#index'
get 'users/:id/alias' => 'users#alias', :defaults => { :format => :json }
delete '/alias/delete.json' => 'users#delete_alias', :defaults => { :format => :json }
post '/alias/create.json' => 'users#create_alias', :defaults => { :format => :json }
......@@ -33,7 +36,9 @@ Rails.application.routes.draw do
post '/visios_users' => 'visios_users#create', :defaults => { :format => :json }
delete 'visios_users/:id' => 'visios_users#destroy', :defaults => { :format => :json }
get 'pads/:id/invitation' => 'pads#invitation'
get 'pads/:id/users' => 'pads#users', :defaults => { :format => :json }
delete 'pads/:id/users' => 'pads#destroy_users', :defaults => { :format => :json }
get 'dates' => "dates#index"
get 'pads' => "pads#show"
get 'compta' => "compta#index"
......
class CreatePadsGroups < ActiveRecord::Migration
def change