PluginProbe
Timed Content / 2.1
Timed Content v2.1
2.99 trunk 1.0 1.1 1.2 2.0 2.1 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.10 2.11 2.12 2.15 2.2 2.3 2.3.1 2.4 2.5 2.5.1 2.50 2.51 2.52 All 67 releases
timed-content / js / timed-content-ajax.js

timed-content-ajax.js in Timed Content 2.1, at js/timed-content-ajax.js

142 lines 7.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(document).ready( function() {
2
3 function getArgs() {
4 var args = {};
5
6 args.fsel = jQuery( 'select#timed_content_rule_frequency option:selected' ).val();
7 args.tz = jQuery( 'select#timed_content_rule_timezone option:selected' ).val();
8 args.nr = jQuery( 'input#timed_content_rule_recurrence_duration_num_repeat' ).val();
9 args.ed = jQuery( 'input#timed_content_rule_recurrence_duration_end_date' ).val();
10 if ( jQuery( "#timed_content_rule_monthly_nth_weekday_of_month" ).prop( "checked" ) ) {
11 args.nth = "yes";
12 } else {
13 args.nth = "no";
14 }
15 args.ntho = jQuery( 'select#timed_content_rule_monthly_nth_weekday_of_month_nth option:selected' ).val();
16 args.nthw = jQuery( 'select#timed_content_rule_monthly_nth_weekday_of_month_weekday option:selected' ).val();
17
18 args.im = 1;
19 if ( 0 === args.fsel ) { args.im = jQuery( 'input#timed_content_rule_hourly_num_of_hours' ).val(); }
20 if ( 1 == args.fsel ) { args.im = jQuery( 'input#timed_content_rule_daily_num_of_days' ).val(); }
21 if ( 2 == args.fsel ) { args.im = jQuery( 'input#timed_content_rule_weekly_num_of_weeks' ).val(); }
22 if ( 3 == args.fsel ) { args.im = jQuery( 'input#timed_content_rule_monthly_num_of_months' ).val(); }
23 if ( 4 == args.fsel ) { args.im = jQuery( 'input#timed_content_rule_yearly_num_of_years' ).val(); }
24 args.days = {};
25 var days_num = 0;
26 jQuery( 'input[id^="timed_content_rule_weekly_days_of_week_to_repeat"]' ).each( function() {
27 if ( jQuery( this ).prop( "checked" ) ) {
28 args.days[days_num] = jQuery( this ).val();
29 }
30 days_num++;
31 });
32 args.start = { "date": jQuery( 'input#timed_content_rule_instance_start_date' ).val(), "time": jQuery( 'input#timed_content_rule_instance_start_time' ).val() };
33 args.end = { "date": jQuery( 'input#timed_content_rule_instance_end_date' ).val(), "time": jQuery( 'input#timed_content_rule_instance_end_time' ).val() };
34 if ( "recurrence_duration_end_date" == jQuery("input[name=timed_content_rule_recurrence_duration]:checked").val() ) {
35 args.rd = "recurrence_duration_end_date";
36 } else {
37 args.rd = "recurrence_duration_num_repeat";
38 }
39 return args;
40 }
41
42 jQuery('#timed_content_rule_test').click( function() {
43 var args = getArgs();
44 //This tag will the hold the dialog content.
45 var tag = jQuery("<div id='tcr-dialogHolder'></div>");
46 var dialogHTML;
47 tag.append('<div id="tcr-loading"><img src="' + timedContentRuleAjax.loadingimg + '" /> Loading...</div>');
48 tag.dialog({modal: 'true',
49 title: timedContentRuleAjax.dialog_label,
50 width: timedContentRuleAjax.dialog_width,
51 height: timedContentRuleAjax.dialog_height,
52 buttons: [{ "text": timedContentRuleAjax.close_label,
53 "click": function() {
54 jQuery( this ).dialog( "close" );
55 }
56 }]
57 }).dialog('open');
58
59 jQuery.post(
60 timedContentRuleAjax.ajaxurl,
61 {
62 // additional data to be included along with the form fields
63 action: 'timedContentPluginGetRulePeriodsAjax',
64 timed_content_rule_human_readable: 'true',
65 timed_content_rule_frequency: args.fsel,
66 timed_content_rule_timezone: args.tz,
67 timed_content_rule_recurrence_duration: args.rd,
68 timed_content_rule_recurrence_duration_num_repeat: args.nr,
69 timed_content_rule_recurrence_duration_end_date: args.ed,
70 timed_content_rule_weekly_days_of_week_to_repeat: args.days,
71 timed_content_rule_interval_multiplier: args.im,
72 timed_content_rule_instance_start: args.start,
73 timed_content_rule_instance_end: args.end,
74 timed_content_rule_monthly_nth_weekday_of_month: args.nth,
75 timed_content_rule_monthly_nth_weekday_of_month_nth: args.ntho,
76 timed_content_rule_monthly_nth_weekday_of_month_weekday: args.nthw
77
78 },
79 function(data, textStatus, jqXHR) {
80 // code that's executed when the request is processed successfully
81 dialogHTML = "<table style='width: 100%;'>";
82 dialogHTML += "<tr class='heading_row'><th>" + timedContentRuleAjax.start_label + "</th><th>" + timedContentRuleAjax.end_label + "</th></tr>";
83 dialogHTML += '</table>';
84
85 tag.find("div#tcr-loading").remove();
86 tag.append(dialogHTML);
87 jQuery.each(data, function(key, value) {
88 tag.find("table").append('<tr class="day_row ' + value.status + '" title="' + value.time + '"><td>' + value.start + '</td><td>' + value.end + '</td></tr>');
89 });
90 },
91 'json'
92 ).fail( function(xhr, textStatus, errorThrown) {
93 tag.find("div#tcr-loading").remove();
94 var errorText = '<div class="tcr-error"><p><strong>' + timedContentRuleAjax.error + '</strong></p>';
95 errorText += '<p class="heading">' + timedContentRuleAjax.error_desc + '</p>';
96 errorText += '<div>' + xhr.responseText + '</div></div>';
97 tag.append(errorText);
98 });
99 });
100
101 jQuery( 'input[id^="timed_content_rule_"], select[id^="timed_content_rule_"]' ).change(function(e) {
102 var args = getArgs();
103 var tag = jQuery("div#schedule_desc");
104 var button = jQuery('input#timed_content_rule_test');
105
106 button.prop('disabled', 'disabled');
107 tag.html('<img src="' + timedContentRuleAjax.loadingimg + '" /> Loading...');
108
109 jQuery.post(
110 timedContentRuleAjax.ajaxurl,
111 {
112 // additional data to be included along with the form fields
113 action: 'timedContentPluginGetScheduleDescriptionAjax',
114 timed_content_rule_action: jQuery( "input[name=timed_content_rule_action]:checked" ).val(),
115 timed_content_rule_frequency: args.fsel,
116 timed_content_rule_timezone: args.tz,
117 timed_content_rule_recurrence_duration: args.rd,
118 timed_content_rule_recurrence_duration_num_repeat: args.nr,
119 timed_content_rule_recurrence_duration_end_date: args.ed,
120 timed_content_rule_weekly_days_of_week_to_repeat: args.days,
121 timed_content_rule_interval_multiplier: args.im,
122 timed_content_rule_instance_start: args.start,
123 timed_content_rule_instance_end: args.end,
124 timed_content_rule_monthly_nth_weekday_of_month: args.nth,
125 timed_content_rule_monthly_nth_weekday_of_month_nth: args.ntho,
126 timed_content_rule_monthly_nth_weekday_of_month_weekday: args.nthw
127
128 },
129 function(data, textStatus, jqXHR) {
130 // code that's executed when the request is processed successfully
131 tag.html(data);
132 button.removeAttr('disabled');
133 },
134 'text'
135 ).fail( function(xhr, textStatus, errorThrown) {
136 var errorText = '<div class="tcr-error"><p><strong>' + timedContentRuleAjax.error + '</strong></p>';
137 errorText += '<p class="heading">' + timedContentRuleAjax.error_desc + '</p>';
138 errorText += '<div>' + xhr.responseText + '</div></div>';
139 tag.append(errorText);
140 });
141 });
142 });