Advertisement
BakerMan

Alternate resources/event-admin.js (TEC)

Sep 6th, 2012
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.52 KB | None | 0 0
  1. jQuery(document).ready(function($) {
  2.  
  3.     // Load the Chosen JQuery plugin for all select elements with the class 'chosen'.
  4.     $('.chosen, .tribe-field-dropdown_chosen select').chosen();
  5.  
  6.     //not done by default on front end
  7.     $('.hide-if-js').hide();
  8.  
  9.     if(typeof(TEC) != 'undefined'){
  10.         var datepickerOpts = {
  11.             dateFormat: 'yy-mm-dd',
  12.             showAnim: 'fadeIn',
  13.             changeMonth: true,
  14.             changeYear: true,
  15.             numberOfMonths: 3,
  16.             showButtonPanel: true,
  17.             onSelect: function(selectedDate) {
  18.                 var option = this.id == "EventStartDate" ? "minDate" : "maxDate";
  19.                 var instance = $(this).data("datepicker");
  20.                 var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
  21.                 dates.not(this).not('#recurrence_end').datepicker("option", option, date);
  22.             }
  23.         };
  24.         $.extend(datepickerOpts, TEC);
  25.         var dates = $("#EventStartDate, #EventEndDate, .datepicker").datepicker(datepickerOpts);
  26.  
  27.         // toggle time input
  28.         function toggleDayTimeDisplay(){
  29.             if( $('#allDayCheckbox').attr("checked") === true || $('#allDayCheckbox').attr("checked") === "checked" ) {
  30.                 $(".timeofdayoptions").hide();
  31.                 $("#EventTimeFormatDiv").hide();
  32.             } else {
  33.                 $(".timeofdayoptions").show();
  34.                 $("#EventTimeFormatDiv").show();
  35.             }
  36.         }
  37.         // check on click
  38.         $('#allDayCheckbox').click(function(){
  39.             toggleDayTimeDisplay();
  40.         });
  41.         // check on load
  42.         toggleDayTimeDisplay();
  43.  
  44.         var tribeDaysPerMonth = [29,31,28,31,30,31,30,31,31,30,31,30,31];
  45.  
  46.         // start and end date select sections
  47.         var tribeStartDays = [ $('#28StartDays'), $('#29StartDays'), $('#30StartDays'), $('#31StartDays') ];
  48.         var tribeEndDays = [ $('#28EndDays'), $('#29EndDays'), $('#30EndDays'), $('#31EndDays') ];
  49.  
  50.         $("select[name='EventStartMonth'], select[name='EventEndMonth']").change(function() {
  51.             var t = $(this);
  52.             var startEnd = t.attr("name");
  53.             // get changed select field
  54.             if( startEnd == 'EventStartMonth' ) startEnd = 'Start';
  55.             else startEnd = 'End';
  56.             // show/hide date lists according to month
  57.             var chosenMonth = t.attr("value");
  58.             if( chosenMonth.charAt(0) == '0' ) chosenMonth = chosenMonth.replace('0', '');
  59.             // leap year
  60.             var remainder = $("select[name='Event" + startEnd + "Year']").attr("value") % 4;
  61.             if( chosenMonth == 2 && remainder == 0 ) chosenMonth = 0;
  62.             // preserve selected option
  63.             var currentDateField = $("select[name='Event" + startEnd + "Day']");
  64.  
  65.             $('.event' + startEnd + 'DateField').remove();
  66.             if( startEnd == "Start") {
  67.                 var selectObject = tribeStartDays[ tribeDaysPerMonth[ chosenMonth ] - 28 ];
  68.                 selectObject.val( currentDateField.val() );
  69.                 $("select[name='EventStartMonth']").after( selectObject );
  70.             } else {
  71.                 var selectObject = tribeEndDays[ tribeDaysPerMonth[ chosenMonth ] - 28 ];
  72.                 selectObject.val( currentDateField.val() );
  73.                 $('select[name="EventEndMonth"]').after( selectObject );
  74.             }
  75.         });
  76.  
  77.         $("select[name='EventStartMonth'], select[name='EventEndMonth']").change();
  78.  
  79.         $("select[name='EventStartYear']").change(function() {
  80.             $("select[name='EventStartMonth']").change();
  81.         });
  82.  
  83.         $("select[name='EventEndYear']").change(function() {
  84.             $("select[name='EventEndMonth']").change();
  85.         });
  86.  
  87.         // Form validation
  88.         $("form[name='post']").submit(function() {
  89.             if( $("#isEventNo").attr('checked') === true || $("#isEventNo").attr('checked') === "checked" ) {
  90.                 // do not validate since this is not an event
  91.                 return true;
  92.             }
  93.             return true;
  94.         });
  95.  
  96.         // hide unnecessary fields
  97.         var venueFields = $(".venue");
  98.  
  99.         var savedVenue = $("#saved_venue");
  100.  
  101.         if ( savedVenue.size() > 0 && savedVenue.val() != '0' && !$('.nosaved').get(0) ) {
  102.             venueFields.hide();
  103.             $('input',venueFields).val('');
  104.         }
  105.  
  106.         savedVenue.change(function() {
  107.             if ( $(this).val() == '0' ) {
  108.                 venueFields.fadeIn()
  109.                     //.find("input, select").val('').removeAttr('checked');
  110.             }
  111.             else {
  112.                 venueFields.fadeOut();
  113.             }
  114.         });
  115.         // hide unnecessary fields
  116.         var organizerFields = $(".organizer");
  117.  
  118.         var savedorganizer = $("#saved_organizer");
  119.  
  120.         if ( savedorganizer.size() > 0 && savedorganizer.val() != '0' && !$('.nosaved_organizer').get(0) ) {
  121.             organizerFields.hide();
  122.             $('input',organizerFields).val('');
  123.         }
  124.  
  125.         savedorganizer.change(function() {
  126.             if ( $(this).val() == '0' ) {
  127.                 organizerFields.fadeIn()
  128.                     //.find("input, select").val('').removeAttr('checked');
  129.             }
  130.             else {
  131.                 organizerFields.fadeOut();
  132.             }
  133.         });
  134.     }
  135.  
  136.     //show state/province input based on first option in countries list, or based on user input of country
  137.     function tribeShowHideCorrectStateProvinceInput(country) {
  138.         if (country == 'US' || country == 'United States') {
  139.             $("#StateProvinceSelect_chzn").show();
  140.             $("#StateProvinceText").hide();
  141.         } else if ( country != '' ) {
  142.             $("#StateProvinceText").show();
  143.             $("#StateProvinceSelect_chzn").hide();
  144.         } else {
  145.             $("#StateProvinceText").hide();
  146.             $("#StateProvinceSelect_chzn").hide();
  147.         }
  148.     }
  149.  
  150.     tribeShowHideCorrectStateProvinceInput( $("#EventCountry > option:selected").val() );
  151.  
  152.     $("#EventCountry").change(function() {
  153.         var countryLabel = $(this).find('option:selected').val();
  154.         tribeShowHideCorrectStateProvinceInput( countryLabel );
  155.     });
  156.  
  157.     // If recurrence changes on a recurring event, then show warning, and automatically change whole recurrence
  158.     if($('[name="is_recurring"]').val() == "true" && !$('[name="recurrence_action"]').val() ) {
  159.         function recurrenceChanged() {
  160.             $('#recurrence-changed-row').show();
  161.             $('[name="recurrence_action"]').val(2);
  162.         }
  163.  
  164.         $('.recurrence-row input, .custom-recurrence-row input,.recurrence-row select, .custom-recurrence-row select').change(recurrenceChanged)
  165.         $( '[name="recurrence[end]"]' ).datepicker('option', 'onSelect', recurrenceChanged);
  166.     }
  167.  
  168.     $( '[name="recurrence[end]"]' ).datepicker('option', 'onSelect', function() {
  169.         $('[name="recurrence[end]"]').removeClass('placeholder');
  170.     });
  171.  
  172.     /* Fix for deleting multiple events */
  173.     $('.wp-admin.events-cal.edit-php #doaction').click(function(e) {
  174.         if($("[name='action'] option:selected").val() == "trash") {
  175.             if(confirm("Are you sure you want to trash all occurrences of these events? All recurrence data will be lost.")) {
  176.                 var ids = new Array();
  177.  
  178.                 $('[name="post[]"]:checked').each(function() {
  179.                     var curval = $(this).val();
  180.                     if(ids[curval]) {
  181.                         $(this).prop('checked', false);
  182.                     }
  183.  
  184.                     ids[curval] = true;
  185.                 });
  186.             } else {
  187.                 e.preventDefault();
  188.             }
  189.         }
  190.     });
  191.  
  192.     function isExistingRecurringEvent() {
  193.         return $('[name="is_recurring"]').val() == "true" && !$('[name="recurrence_action"]').val() && !$('[name="recurrence_action"]').val()
  194.     }
  195.  
  196.     function resetSubmitButton() {
  197.         $('#publishing-action .button-primary-disabled').removeClass('button-primary-disabled');
  198.         $('#publishing-action #ajax-loading').css('visibility', 'hidden');
  199.  
  200.     }
  201.  
  202.     $('#EventInfo input, #EventInfo select').change(function() {
  203.         $('.rec-error').hide();
  204.     })
  205.  
  206.     var eventSubmitButton = $('.wp-admin.events-cal #post #publishing-action input[type="submit"]');
  207.     eventSubmitButton.click(function(e) {
  208.         $(this).data('clicked', true);
  209.     });
  210.  
  211.     /* Recurring Events Dialog */
  212.     $('.wp-admin.events-cal #post').submit(function(e) {
  213.         var self = $(this);
  214.  
  215.         if( isExistingRecurringEvent() ) { // not a new event
  216.             e.preventDefault();
  217.             $('#recurring-dialog').dialog({
  218.                 modal: true,
  219.                 buttons: [{
  220.                         text:"Only This Event",
  221.                         click: function() {
  222.                             $('[name="recurrence_action"]').val(3);
  223.  
  224.                             if (eventSubmitButton.data('clicked') )
  225.                                 $('<input type="hidden" name="' + eventSubmitButton.attr('name') + '" value="' + eventSubmitButton.val() + '"/>').appendTo(self);
  226.  
  227.                             $(this).dialog("close");
  228.                             self.submit();
  229.                         }
  230.                 }, {
  231.                         text:"Future Events",
  232.                         click: function() {
  233.                             $('[name="recurrence_action"]').val(2);
  234.  
  235.                             if (eventSubmitButton.data('clicked') )
  236.                                 $('<input type="hidden" name="' + eventSubmitButton.attr('name') + '" value="' + eventSubmitButton.val() + '"/>').appendTo(self);
  237.  
  238.                             $(this).dialog("close");
  239.                             self.submit();
  240.                         }
  241.                 }],
  242.                 close: function() {
  243.                     eventSubmitButton.data('clicked', null);
  244.                 }
  245.             });
  246.         }
  247.     });
  248.  
  249.     function setupSubmitButton() {
  250.         //publishing-action
  251.     }
  252.  
  253.     $('.wp-admin.events-cal .submitdelete').click(function(e) {
  254.  
  255.         var link = $(this);
  256.         var isRecurringLink = $(this).attr('href').split('&eventDate');
  257.  
  258.         if(isRecurringLink[1]) {
  259.             e.preventDefault();
  260.  
  261.             $('#deletion-dialog').dialog({
  262.                 //submitdelete
  263.                 modal: true,
  264.                 buttons: [{
  265.                     text: "Delete just this occurrence.",
  266.                     click: function() {
  267.                         document.location = link.attr('href') + '&event_start=' + $(this).data('start');
  268.                     }
  269.                 },
  270.                 {
  271.                     text: "Delete all occurrences of this event.",
  272.                     click: function() {
  273.                         document.location = link.attr('href') + '&deleteAll';
  274.                     }
  275.                 }]
  276.             });
  277.         }
  278.  
  279.     });
  280.  
  281.     // recurrence ui
  282.     $('[name="recurrence[type]"]').change(function() {
  283.         var curOption =  $(this).find("option:selected").val();
  284.         $('.custom-recurrence-row').hide();
  285.  
  286.         if (curOption == "Custom" ) {
  287.             $('#recurrence-end').show();
  288.             $('#custom-recurrence-frequency').show();
  289.             $('[name="recurrence[custom-type]"]').change();
  290.         } else if (curOption == "None") {
  291.             $('#recurrence-end').hide();
  292.             $('#custom-recurrence-frequency').hide();
  293.         } else {
  294.             $('#recurrence-end').show();
  295.             $('#custom-recurrence-frequency').hide();
  296.         }
  297.     });
  298.  
  299.     $('[name="recurrence[end-type]"]').change(function() {
  300.         var val = $(this).find('option:selected').val();
  301.  
  302.         if (val == "On") {
  303.             $('#rec-count').hide();
  304.             $('#recurrence_end').show();
  305.         } else {
  306.             $('#recurrence_end').hide();
  307.             $('#rec-count').show();
  308.         }
  309.     });
  310.  
  311.     $('[name="recurrence[custom-type]"]').change(function() {
  312.         $('.custom-recurrence-row').hide();
  313.         var option = $(this).find('option:selected'), customSelector = option.data('tablerow');
  314.         $(customSelector).show()
  315.         $('#recurrence-interval-type').text(option.data('plural'));
  316.         $('[name="recurrence[custom-type-text]"]').val(option.data('plural'));
  317.     });
  318.  
  319.     $('#recurrence_end_count').change(function() {
  320.         $('[name="recurrence[type]"]').change();
  321.     });
  322.  
  323.     $('[name="recurrence[type]"]').change(function() {
  324.         var option = $(this).find('option:selected'), numOccurrences = $('#recurrence_end_count').val();
  325.         $('#occurence-count-text').text(numOccurrences == 1 ? option.data('single') : option.data('plural'));
  326.         $('[name="recurrence[occurrence-count-text]"]').val($('#occurence-count-text').text());
  327.     });
  328.  
  329.     $('[name="recurrence[custom-month-number]"]').change(function() {
  330.         var option = $(this).find('option:selected'), dayselect = $('[name="recurrence[custom-month-day]"]');
  331.  
  332.         if(isNaN(option.val())) {
  333.             dayselect.show();
  334.         } else {
  335.             dayselect.hide();
  336.         }
  337.     });
  338.  
  339.     function maybeDisplayPressTrendsDialogue() {
  340.         return $('[name="maybeDisplayPressTrendsDialogue"]').val() == "1"
  341.     }
  342.  
  343.     if( maybeDisplayPressTrendsDialogue() ) {
  344.             $('#presstrends-dialog').dialog({
  345.                 modal: true,
  346.                 buttons: [{
  347.                         text:"Send data",
  348.                         click: function() {
  349.                             $('[name="presstrends_action"]').val(1);
  350.                             $(this).dialog("close");
  351.                             $('[name="sendPressTrendsData"]').prop("checked", true);
  352.                             $('#tribeSaveSettings').click();
  353.                         }
  354.                 }, {
  355.                         text:"Do not send data",
  356.                         click: function() {
  357.                             $('[name="presstrends_action"]').val(0);
  358.                             $(this).dialog("close");
  359.                             $('[name="sendPressTrendsData"]').prop("checked", false);
  360.                         }
  361.                 }]
  362.             });
  363.  
  364.         }
  365.  
  366. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement