From 7bcafeb42397ae51eb61f21e8e970a6b8976d17a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Arag=C3=B3n?= Date: Fri, 21 Dec 2018 11:44:11 -0500 Subject: [PATCH] fix modal calendar - refs #2186 --- main/template/default/agenda/month.html.twig | 439 +++++++------------ 1 file changed, 170 insertions(+), 269 deletions(-) diff --git a/main/template/default/agenda/month.html.twig b/main/template/default/agenda/month.html.twig index 964ad57b27..7bf07cb5db 100644 --- a/main/template/default/agenda/month.html.twig +++ b/main/template/default/agenda/month.html.twig @@ -28,8 +28,6 @@ var region_value = '{{ region_value }}'; $(document).ready(function() { - console.log('{{ _p.web_main }}'); - console.log('{{ _p.web_plugin }}'); var cookieData = Cookies.getJSON('agenda_cookies'); var defaultView = (cookieData && cookieData.view) || '{{ default_view }}'; var defaultStartDate = (cookieData && cookieData.start) || moment.now(); @@ -39,23 +37,13 @@ $(document).ready(function() { $("#session_id").find('option').removeAttr("selected"); }); - - - $("#dialog-form").dialog({ - autoOpen : false, - modal : false, - width : 580, - height : 480, - zIndex : 20000 // added because of qtip2 - }); - - /*$("#simple-dialog-form").dialog({ - autoOpen : false, - modal : false, - width : 580, - height : 480, - zIndex : 20000 // added because of qtip2 - });*/ + function loadColors(calEvent){ + $('#color_calendar').removeClass(); + $('#color_calendar').html('{{ type_label | escape('js') }}'); + $('#color_calendar').addClass('label_tag'); + $('#color_calendar').addClass(calEvent.type+'_event'); + $('.type-agenda').show(); + } var title = $("#title"), content = $("#content"), @@ -171,70 +159,66 @@ $(document).ready(function() { //It shows the CKEDITOR while Adding an Event $('#cke_content').show(); //It Fixing a minor bug with textarea ckeditor.remplace - $('#content').css('display','none'); + // $('#content').css('display','none'); //Reset the CKEditor content that persist in memory CKEDITOR.instances['content'].setData(''); allFields.removeClass("ui-state-error"); - $("#dialog-form").dialog("open"); - $("#dialog-form").dialog({ - buttons: { - '{{ "Add" | get_lang }}' : function() { - var bValid = true; - bValid = bValid && checkLength(title, "title", 1, 255); - - //Update the CKEditor Instance to the remplaced textarea, ready to be serializable - for ( instance in CKEDITOR.instances ) { - CKEDITOR.instances[instance].updateElement(); + + $("#modalDialogForm").modal(); + + var btnSave = ''; + $("#modalDialogForm #modalFooter").html(btnSave); + + $("#btnSave").click( function() { + var bValid = true; + bValid = bValid && checkLength(title, "title", 1, 255); + + //Update the CKEditor Instance to the remplaced textarea, ready to be serializable + for ( instance in CKEDITOR.instances ) { + CKEDITOR.instances[instance].updateElement(); + } + + var params = $("#add_event_form").serialize(); + + $.ajax({ + url: url+'&'+params, + success:function(data) { + var user = $('#users_to_send').val(); + if (user) { + if (user.length > 1) { + user = 0; + } else { + user = user[0]; + } + var user_length = String(user).length; + if (String(user).substring(0,1) == 'G') { + var user_id = String(user).substring(6,user_length); + var user_id = "G:"+user_id; + } else { + var user_id = String(user).substring(5,user_length); + } + var temp = "&user_id="+user_id; + var position = String(window.location).indexOf("&user"); + var url = String(window.location).substring(0, position)+temp; + /*if (position > 0) { + window.location.replace(url); + } else { + url = String(window.location)+temp; + window.location.replace(url); + }*/ } - var params = $("#add_event_form").serialize(); - - $.ajax({ - url: url+'&'+params, - success:function(data) { - var user = $('#users_to_send').val(); - if (user) { - if (user.length > 1) { - user = 0; - } else { - user = user[0]; - } - var user_length = String(user).length; - if (String(user).substring(0,1) == 'G') { - var user_id = String(user).substring(6,user_length); - var user_id = "G:"+user_id; - } else { - var user_id = String(user).substring(5,user_length); - } - var temp = "&user_id="+user_id; - var position = String(window.location).indexOf("&user"); - var url = String(window.location).substring(0, position)+temp; - /*if (position > 0) { - window.location.replace(url); - } else { - url = String(window.location)+temp; - window.location.replace(url); - }*/ - } + /*$("#title").val(''); + $("#content").val(''); + $("#comment").val('');*/ - $("#title").val(''); - $("#content").val(''); - $("#comment").val(''); - - calendar.fullCalendar('refetchEvents'); - calendar.fullCalendar('rerenderEvents'); - - $("#dialog-form").dialog('close'); - } - }); - } - }, - close: function() { - $("#title").val(''); - $("#content").val(''); - $("#comment").val(''); - } - }); + calendar.fullCalendar('refetchEvents'); + calendar.fullCalendar('rerenderEvents'); + + $('#modalDialogForm').modal('toggle'); + } + }); + }); calendar.fullCalendar('unselect'); //Reload events @@ -242,83 +226,12 @@ $(document).ready(function() { calendar.fullCalendar("rerenderEvents"); } }, - /*eventRender: function(event, element) { - if (event.attachment) { - /*element.qtip({ - hide: { - delay: 2000 - }, - content: event.attachment, - position: { at:'top right' , my:'bottom right'} - }).removeData('qtip'); // this is an special hack to add multiple qtip in the same target - - } - - var onHoverInfo = ''; - - {#{% if on_hover_info.description %}#} - if (event.description) { - onHoverInfo = event.description; - } - {#{% endif %} - - {% if on_hover_info.comment %}#} - if (event.comment) { - onHoverInfo = onHoverInfo + event.comment; - } - {#{% endif %}#} - - if (onHoverInfo) { - element.qtip({ - content: onHoverInfo, - position: { - at: 'top center', - my: 'bottom center' - } - }); - } - },*/ eventClick: function(calEvent, jsEvent, view) { var start = calEvent.start; var end = calEvent.end; var diffDays = moment(end).diff(start, 'days'); var endDateMinusOne = ''; - - - //$('#modalBody').html(calEvent.description); - - - - // If event is not editable then just return the qtip - /*if (!calEvent.editable) { - var onHoverInfo = ''; - {#{% if calEvent.description %}#} - if (calEvent.description) { - onHoverInfo = calEvent.description; - } - {#{% endif %} - {% if on_hover_info.comment %}#} - if (calEvent.comment) { - onHoverInfo = onHoverInfo + calEvent.comment; - } - {#{% endif %}#} - - if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { - $(this).qtip({ - overwrite: false, - show: {ready: true}, - content: onHoverInfo, - position: { - at: 'top center', - my: 'bottom center' - } - }); - - return; - } - }*/ - if (end) { var clone = end.clone(); endDateMinusOne = clone.subtract(1, 'days').format('{{ js_format_date }}'); @@ -336,15 +249,7 @@ $(document).ready(function() { $(".user-sender").show(); {% endif %} - $('#color_calendar').html('{{ type_label | escape('js') }}'); - $('#color_calendar').addClass('label_tag'); - $('#color_calendar').removeClass('course_event'); - $('#color_calendar').removeClass('personal_event'); - $('#color_calendar').removeClass('group_event'); - $('#color_calendar').addClass(calEvent.type+'_event'); - $('.type-agenda').show(); - // It hides the CKEDITOR while clicking an existing Event - $('#cke_content').hide(); + loadColors(calEvent); $('#simple_start_date').html(startDateToString); if (diffDays > 1) { @@ -364,21 +269,20 @@ $(document).ready(function() { $("#simple_comment").html(calEvent.comment); if (calEvent.course_name) { - $('#type_course').html({{ 'Course' | get_lang }}) $("#calendar_course_info_simple").html(calEvent.course_name); + $("#type_course").html("{{ 'Course' | get_lang }}"); } else { $("#calendar_course_info_simple").html(''); } if (calEvent.session_name) { - $('#type_course').html({{ 'Session' | get_lang }}) $("#calendar_course_info_simple").html(calEvent.session_name); + $('#type_course').html("{{ 'Session' | get_lang }}"); } else { $("#calendar_course_info_simple").html(''); } allFields.removeClass( "ui-state-error" ); - $("#dialog-form").dialog("open"); $('#modalTitle').html(calEvent.title); $('#calendarModal').modal(); @@ -401,6 +305,31 @@ $(document).ready(function() { $('#modalFooter').html(exportCalConfidential+exportCalPrivate+exportCalPublic+btnEdit+btnDelete); + {% if type == 'not_available' %} + $('#btnEdit').click(function() { + var bValid = true; + bValid = bValid && checkLength( title, "title", 1, 255 ); + + var params = $("#add_event_form").serialize(); + $.ajax({ + url: url+'&'+params, + success:function() { + calEvent.title = $("#title").val(); + calEvent.start = calEvent.start; + calEvent.end = calEvent.end; + calEvent.allDay = calEvent.allDay; + calEvent.description = $("#content").val(); + calendar.fullCalendar('updateEvent', + calEvent, + true // make the event "stick" + ); + //close modal + $('#calendarModal').modal('toggle'); + } + }); + }); + {% endif %} + $('#btnDelete').click(function() { if (calEvent.parent_event_id || calEvent.has_children != '') { var newDiv = $('
'); @@ -464,58 +393,12 @@ $(document).ready(function() { ); calendar.fullCalendar('refetchEvents'); calendar.fullCalendar('rerenderEvents'); - $("#dialog-form").dialog('close'); + //close modal + $('#calendarModal').modal('toggle'); } }); }); - $("#dialog-form").dialog({ - buttons: { - - {% if type == 'not_available' %} - '{{ "Edit" | get_lang }}' : function() { - var bValid = true; - bValid = bValid && checkLength( title, "title", 1, 255 ); - - var params = $("#add_event_form").serialize(); - $.ajax({ - url: url+'&'+params, - success:function() { - calEvent.title = $("#title").val(); - calEvent.start = calEvent.start; - calEvent.end = calEvent.end; - calEvent.allDay = calEvent.allDay; - calEvent.description = $("#content").val(); - calendar.fullCalendar('updateEvent', - calEvent, - true // make the event "stick" - ); - $("#dialog-form").dialog("close"); - } - }); - }, - {% endif %} - - - }, - close: function() { - $("#title_edit").hide(); - $("#content_edit").hide(); - $("#comment_edit").hide(); - - $("#title").show(); - $("#content").show(); - $("#comment").show(); - - $("#title_edit").html(''); - $("#content_edit").html(''); - $("#comment_edit").html(''); - - $("#title").val(''); - $("#content").val(''); - $("#comment").val(''); - } - }); } else { // Simple form $('#simple_start_date').html(startDateToString); @@ -531,6 +414,8 @@ $(document).ready(function() { $('#simple_end_date').html(''); } + loadColors(calEvent); + if (calEvent.course_name) { $("#calendar_course_info_simple").html(calEvent.course_name); $("#type_course").html("{{ 'Course' | get_lang }}"); @@ -603,10 +488,24 @@ $(document).ready(function() { {{ actions_div }} {{ toolbar }} -