123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578 |
- var majpushed = false;
- var clickedDate;
- $(window).resize(function() {
- $('#planning').fullCalendar('option', 'height', $(window).height()*0.83);
- });
- //CHARGEMENT DE LA PAGE
- function init_plugin_planning(){
- switch($.urlParam('page')){
- default:
- break;
- }
- if($('.planning-page').attr('data-event-editable')=='0')
- $('#planning-event-form').find('input,select,textarea').attr('readonly','readonly');
-
- $( "#planning-datepicker" ).datepicker({
- dayNames: ["Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"],
- dayNamesMin: ["Di", "Lu", "Ma", "Me", "Je", "Ve", "Sa"],
- dayNamesShort: ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"],
- monthNames: ["Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Aout","Septembre","Octobre","Novembre","Décembre"],
- monthNamesShort: ["Jan","Fév","Mars","Avr","Mai","Juin","Juil","Aout","Sept","Oct","Nov","Déc"],
- onSelect : function(date,element){
- $('#planning').fullCalendar( 'gotoDate', date );
- }
- });
-
- planning_search(function(){
- planning_calendar_init();
- });
- $(document).keydown(function(e){
- switch(e.keyCode){
- //Appuis sur maj
- case 16:
- majpushed = true;
- break;
- //Appuis sur suppr
- case 46:
- planning_event_delete($('.event-selected'));
- break;
- }
- });
- //relachage du maj
- $(document).keyup(function(e){
- if(e.keyCode!=16) return;
- majpushed = false;
- });
- $('#planning-event-type > .dropdown-menu > a').click(function(){
- var id = $(this).attr('data-id');
- var icon = $(this).find('i').attr('class');
- var color = $(this).attr('data-color');
- var text = $(this).text();
- $('#planning-event-type > button').css('background-color',color).attr('data-id',id).html('<i class="'+icon+'"></i> '+text);
- $('#label').focus();
- });
- }
- function init_setting_planning(){
- planning_event_type_search();
- $("#planning_event_types tbody").sortable({
- opacity: 0.75,
- cursor: "move",
- axis: "y",
- update: function(e, ui) {
- var data = { action : 'planning_event_type_sort' ,sort:[] };
- $("#planning_event_types tbody tr:visible").each(function(i,tr){
- data.sort.push($(tr).attr('data-id'));
- });;
- $.action(data);
- }
- }).disableSelection();
- }
- /** PLANNING **/
- //Récuperation d'une liste de planning dans le tableau #plannings
- function planning_search(callback){
- $.action({
- action:'planning_search'
- },function(r){
- var planning = $('#plannings');
- var sharedPlanning = $('#shared-plannings');
- planning.find('li:visible').remove();
- sharedPlanning.find('li:visible').remove();
- var tpl = $('li.hidden',planning).get(0).outerHTML;
- var options = '';
- for(var k in r.rows){
- var line = r.rows[k];
- options +='<option value="'+line.id+'">'+line.label+'</option>';
- var li = $(Mustache.render(tpl,line));
- if(line.selected) li.find('input').prop('checked',true);
- if(line.shared){
- sharedPlanning.append(li);
- }else{
- planning.append(li);
- }
-
- li.removeClass('hidden');
- }
- $('#event-planning').html(options);
- if(callback!=null) callback();
- });
- }
- //Ajout ou modification d'élément planning
- function planning_save(){
- var data = $('#planning-form').toJson();
- data.action = 'planning_save';
- $.action(data,function(r){
- $.message('success','Enregistré');
- $('#planningModal').modal('hide');
- planning_search();
- });
- }
- //Récuperation ou edition d'élément planning
- function planning_edit(element){
- var data = {};
- if(element)
- data.id = $(element).closest('li').attr('data-id');
-
- $('#planningModal .modal-content').load('action.php?action=planning_edit',data,function(){
- init_components('#planningModal .modal-content');
- planning_share_search();
- });
- $('#planningModal').modal('show');
- }
- //Suppression d'élement planning
- function planning_delete(element){
- if(!confirm('Êtes vous sûr de vouloir supprimer cet item ?')) return;
- var line = $(element).closest('li');
- $.action({
- action : 'planning_delete',
- id : line.attr('data-id')
- },function(r){
- line.remove();
- $('#planning').fullCalendar( 'refetchEvents' );
- $.message('info','Élement supprimé');
- });
- }
- function planning_select(){
- $('#planning').fullCalendar( 'refetchEvents' );
- }
- //Récuperation d'une liste de planning dans le tableau #plannings
- function planning_calendar_init(callback){
- var plannings = [];
- planning = $('#planning').fullCalendar({
- locale: 'fr',
- nextDayThreshold: '00:00:00',
- customButtons: {
- refreshButton: {
- text: 'Rafraichir',
- click: function() {
- $('#planning').fullCalendar( 'refetchEvents' );
- }
- }
- },
- header: {
- left: 'prev,next today refreshButton',
- center: 'title',
- right: 'month,agendaWeek,agendaDay,listWeek'
- },
- height: $(window).height()*0.83,
-
- navLinks: true, // can click day/week names to navigate views
- editable: false,
- eventLimit: true, // allow "more" link when too many events
-
- events: {
- url: 'action.php?action=planning_event_search',
- data: function () {
- parameters = { plannings : [] };
- $('.planning-list li:visible input:checked').each(function(i,input){
- parameters.plannings.push($(input).closest('li').attr('data-id'))
- });
- return parameters;
- },
- error: function() {
- $('#script-warning').removeClass('hidden');
- }
- },
- //weekNumbers :true,
- resources: [
- { id: 'a', title: 'Room A' },
- { id: 'b', title: 'Room B' },
- { id: 'c', title: 'Room C' },
- { id: 'd', title: 'Room D' }
- ],
- loading: function(isLoading){
- if(isLoading)
- $('.loaderStd').removeClass('hidden');
- else
- $('.loaderStd').addClass('hidden');
- },
- dayClick: function(date, jsEvent, view) {
- if($('.planning-page').attr('data-event-editable')=='0') return;
- clickedDate = date;
- $("#planning").on("mousemove", function(){
- clickedDate = null;
- $("#planning").off("mousemove");
- });
- },
- eventRender: function(event, element) {
- if(event.rendering=='background') return;
- element.find('.fc-content').append('<span class="fc-icon right"><i class="'+event.icon+'"></i></span>');
- element.attr('title','Planning : '+event.planningLabel);
- element.css('border-bottom','4px solid '+event.underlineColor) ;
- var event = planning_convert_event(event);
- if(event == null) return;
- element.attr('data-id',event.id).on("dblclick",function(){
- planning_event_edit(event);
- });
- },
- eventClick: function(event,jsEvent,view) {
- if(!majpushed) $('.event-selected').removeClass('event-selected');
- $(this).addClass('event-selected');
- jsEvent.stopPropagation();
- },
- eventMouseover: function(event, jsEvent, view){
- if(event.end == null || event.start == null) return;
- var startDay = event.start.format("DD/MM/YYYY");
- var endDay = event.end.format("DD/MM/YYYY");
- var startSchedule = event.start.format("HH:mm");
- var endSchedule = event.end.format("HH:mm");
- var location = event.location == null ? '' : event.location;
- var description = event.description == null ? '' : event.description;
- var info = "Du "+startDay+" au "+endDay+"\r"+event.title+"\r"+'De '+startSchedule+' à '+endSchedule+"\r"+description+"\r"+location;
- $("a[data-id='"+event.id+"']").attr("title", info);
- },
- eventDrop: function(event, delta, revertFunc) {
- if($('.planning-page').attr('data-event-editable')=='0') return;
- var event = planning_convert_event(event);
- if(event == null) return;
- delete event.source;
- delete event.start;
- delete event.end;
- planning_event_save(event,function(r){
- if(r.error)revertFunc();
- });
- },
- eventResize: function(event, delta, revertFunc, jsEvent, ui, view ) {
- if($('.planning-page').attr('data-event-editable')=='0') return;
- var event = planning_convert_event(event);
- if(event == null) return;
- planning_event_save(event,function(r){
- if(r.error )revertFunc();
- });
- },
- eventAfterAllRender : function(){
- if($.urlParam('event')=='') return;
- $('.fc-event[data-id="'+$.urlParam('event')+'"]').addClass('event-selected');
- }
-
- });
-
- if($.urlParam('start'))
- $('#planning').fullCalendar( 'gotoDate', $.urlParam('start') );
- //Ouvre la fenetre lors du double click sur une journée
- $('#planning').dblclick(function(clickEvent){
- if(!clickedDate) return;
- var view = $('#planning').fullCalendar( 'getView' );
- var calculatedEnd = parseInt(clickedDate.format("HH"))+1;
- var newEvent = {
- startDate : clickedDate.format("DD/MM/YYYY"),
- endDate : clickedDate.format("DD/MM/YYYY"),
- startHour : clickedDate.format("HH"),
- endHour : "00".substring(0, 2 - calculatedEnd.length) + ''+ calculatedEnd,
- startMinut : clickedDate.format("mm"),
- endMinut : clickedDate.format("mm")
- };
- if(view.name=='month'){
- newEvent.startHour = '08';
- newEvent.endHour = '12';
- newEvent.startMinut = '00';
- newEvent.endMinut = '00';
- var planningConf = $('#planning').data();
- var defaultStart = planningConf.startHour.split(':');
- var defaultEnd = planningConf.endHour.split(':');
- if(defaultStart.length==2){
- newEvent.startHour = defaultStart[0];
- newEvent.startMinut = defaultStart[1];
- }
- if(defaultEnd.length==2){
- newEvent.endHour = defaultEnd[0];
- newEvent.endMinut = defaultEnd[1];
- }
- }
- planning_event_edit(newEvent);
- clickEvent.stopPropagation();
- });
- $('#planning').click(function(){
- $('#planning-event-panel').addClass('fold');
- $('.event-selected').removeClass('event-selected');
- });
- }
- function planning_convert_event(event){
- if(event.end == null || event.start == null) return null;
- event.label = event.title;
- event.startDate = event.start.format("DD/MM/YYYY"),
- event.endDate = event.end.format("DD/MM/YYYY"),
- event.startHour = event.start.format("HH"),
- event.endHour = event.end.format("HH"),
- event.startMinut = event.start.format("mm"),
- event.endMinut = event.end.format("mm");
- return event;
- }
- /** PLANNING EVENT **/
-
- //Ajout ou modification d'élément planningevent
- function planning_event_save(data,callback){
- if($('.planning-page').attr('data-event-editable')=='0') return;
- if(!data){
- data = $('#planning-event-form').toJson();
- data.type = $('#planning-event-type > button').attr('data-id');
- data.id = $('#planning-event-form').attr('data-event');
- data.planning = $('#event-planning').val();
- data.dailyFrequency = $('[name="dailyRepeatFrequency"]:checked').attr('data-value');
- data.repeatEndType = $('[name="repeatEndType"]:checked').attr('data-value');
-
- data.weeklyDay = [];
- $('[data-type-form="weekly"] input[type="checkbox"]:checked').each(function(){
- data.weeklyDay.push($(this).attr('data-value'));
- });
- }
- data.action = 'planning_event_save';
- $.action(data,function(r){
- $('#planning-event-form').attr('data-event','');
- var eventPanel = $('#planning-event-panel');
- eventPanel.addClass('fold');
- $('#planning').fullCalendar('refetchEvents');
- if(callback) callback(r);
- },function(r){
- if(callback) callback(r);
- });
- }
- //Récuperation ou edition d'élément planningevent
- function planning_event_edit(event){
- var eventPanel = $('#planning-event-panel');
- eventPanel.removeClass('fold');
- eventPanel.find('#label').focus();
- $('#planning-event-form').find('input,textarea').val('');
- $.setForm('#planning-event-form',event);
- $('#event-repeat-type').val(event.repeatType).trigger('change');
- $('#event-repeat-occurences').val(event.repeatOccurence);
- $('#event-repeat-until').val(event.repeatUntil)
- $('#event-repeat-daily-number').val(event.repeatDailyNumber);
- $('#event-repeat-yearly-number').val(event.repeatYearlyNumber);
- $('#event-repeat-monthly-number').val(event.repeatMonthlyNumber);
- $('#event-repeat-yearly-month').val(event.repeatYearlyMonth);
- $('#event-repeat-monthly-day').val(event.repeatMonthlyDay);
- $('[data-type-form="weekly"] input[type="checkbox"]').each(function(){
- $(this).prop('checked',$.inArray($(this).attr('data-value'),event.repeatWeeklyDay) != -1);
- });
- $('[name="repeatEndType"][data-value="'+event.repeatEndType+'"]').prop('checked',true);
-
- $('#planning-event-type > .dropdown-menu > a[data-id="'+event.type+'"]').trigger('click');
- var planning = '';
- var checkedPlannings = $('.planning-list li:visible input:checked');
-
-
- //déduction du planning par défaut ou du planning correspondant a l'event
- if(event.planning){
- planning = event.planning ;
- }else{
- $('#planning-event-type .dropdown-menu > a:eq(0)').trigger('click');
- planning = $('.planning-list li[data-default="1"]').attr('data-id');
- if(checkedPlannings.length==1){
- planning = checkedPlannings.closest('li').attr('data-id');
- }
- }
- $('#event-planning').val(planning);
-
- $('#planning-event-form').attr('data-event',!event.id? '': event.id);
- }
- //Suppression d'élement planningevent
- function planning_event_delete (elements){
- if($('.planning-page').attr('data-event-editable')=='0') return;
- if(!confirm('Êtes vous sûr de vouloir supprimer cet item ?')) return;
- var events = [];
- elements.each(function(i,event){
- if($(event).attr('data-id') != null)
- events.push($(event).attr('data-id'));
- });
- $.action({
- action : 'planning_event_delete',
- events : events
- },function(r){
- $('#planning').fullCalendar( 'refetchEvents' );
- });
- }
- /** PLANNING EVENT TYPE **/
-
- //Récuperation d'une liste de planningeventtype dans le tableau #planningeventtypes
- function planning_event_type_search(callback){
-
- $('#planning_event_types').fill({
- action:'planning_event_type_search'
- },function(){
- if(callback!=null) callback();
- });
- }
- //Ajout ou modification d'élément event_type
- function planning_event_type_save(){
- var data = $('#event-type-form').toJson();
- $.action(data,function(r){
- $('#event-type-form').attr('data-id','');
- planning_event_type_search();
- $.message('success','Enregistré');
- });
- }
- //Récuperation ou edition d'élément event_type
- function planning_event_type_edit(element){
- var line = $(element).closest('tr');
- $.action({action:'planning_event_type_edit',id:line.attr('data-id')},function(r){
- $.setForm('#event-type-form',r);
- $('#event-type-form').attr('data-id',r.id);
- init_components('#event-type-form');
- });
- }
- //Suppression d'élement event_type
- function planning_event_type_delete(element){
- if(!confirm('Êtes vous sûr de vouloir supprimer cet item ?')) return;
- var line = $(element).closest('tr');
- $.action({
- action : 'planning_event_type_delete',
- id : line.attr('data-id')
- },function(r){
- line.remove();
- $.message('info','Élement supprimé');
- });
- }
- function planning_event_repeat_change(){
- var repeatEventType = $('#event-repeat-type').val();
- var eventOption = $('#event-repeat-options');
- if(repeatEventType=='never'){
- eventOption.addClass('hidden');
- }else{
- $('[data-type-form]',eventOption).addClass('hidden');
- $('[data-type-form="'+repeatEventType+'"]',eventOption).removeClass('hidden');
- eventOption.removeClass('hidden');
- }
- }
- /** PLANNINGSHARE **/
-
- //Récuperation d'une liste de planningshare dans le tableau #planningshares
- function planning_share_search(callback){
-
- var planning = $('#planning-form').attr('data-id');
- if(planning=='') return;
-
- $('#planning-shares').fill({
- action:'planning_share_search',
- planning : planning,
-
- },function(){
- if(callback!=null) callback();
- });
- }
- //Ajout ou modification d'élément planningshare
- function planning_share_save(){
- var data = $('#planning-share-form').toJson();
- data.action='planning_share_save';
- data.planning = $('#planning-form').attr('data-id');
- data.recipientEntity = $('#recipient').data('values')[0].entity;
- if(data.planning=='') return $.message('warning','Veuillez enregitrer une fois le planning avant de créer des partages');
- $.action(data,function(r){
- planning_share_search();
- });
- }
- //Suppression d'élement planningshare
- function planning_share_delete(element){
- if(!confirm('Êtes vous sûr de vouloir supprimer cet item ?')) return;
- var line = $(element).closest('tr');
- $.action({
- action : 'planning_share_delete',
- id : line.attr('data-id')
- },function(r){
- line.remove();
- $.message('info','Élement supprimé');
- });
- }
- //Enregistrement des configurations
- function planning_setting_save(){
- $.action({
- action : 'planning_setting_save',
- fields : $('#planning-setting-form').toJson()
- },function(){ $.message('info','Configuration enregistrée'); });
- }
|