PluginProbe
Timed Content / 2.3.1
Timed Content v2.3.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.3.1, at js/timed-content-ajax.js

155 lines 7.8 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
40 args.ex_days = {};
41 var ex_days_num = 0;
42 jQuery( '#timed_content_rule_exceptions_dates option' ).each( function() {
43 args.ex_days[ex_days_num] = jQuery( this ).val();
44 ex_days_num++;
45 });
46 //alert(JSON.stringify(args.ex_days));
47
48 return args;
49 }
50
51 jQuery('#timed_content_rule_test').click( function() {
52 var args = getArgs();
53 //This tag will the hold the dialog content.
54 var tag = jQuery("<div id='tcr-dialogHolder'></div>");
55 var dialogHTML;
56 tag.append('<div id="tcr-loading"><img src="' + timedContentRuleAjax.loadingimg + '" /> Loading...</div>');
57 tag.dialog({modal: 'true',
58 title: timedContentRuleAjax.dialog_label,
59 width: timedContentRuleAjax.dialog_width,
60 height: timedContentRuleAjax.dialog_height,
61 buttons: [{ "text": timedContentRuleAjax.close_label,
62 "click": function() {
63 jQuery( this ).dialog( "close" );
64 }
65 }]
66 }).dialog('open');
67
68 jQuery.post(
69 timedContentRuleAjax.ajaxurl,
70 {
71 // additional data to be included along with the form fields
72 action: 'timedContentPluginGetRulePeriodsAjax',
73 timed_content_rule_human_readable: 'true',
74 timed_content_rule_frequency: args.fsel,
75 timed_content_rule_timezone: args.tz,
76 timed_content_rule_recurrence_duration: args.rd,
77 timed_content_rule_recurrence_duration_num_repeat: args.nr,
78 timed_content_rule_recurrence_duration_end_date: args.ed,
79 timed_content_rule_weekly_days_of_week_to_repeat: args.days,
80 timed_content_rule_interval_multiplier: args.im,
81 timed_content_rule_instance_start: args.start,
82 timed_content_rule_instance_end: args.end,
83 timed_content_rule_monthly_nth_weekday_of_month: args.nth,
84 timed_content_rule_monthly_nth_weekday_of_month_nth: args.ntho,
85 timed_content_rule_monthly_nth_weekday_of_month_weekday: args.nthw,
86 timed_content_rule_exceptions_dates: args.ex_days
87
88 },
89 function(data, textStatus, jqXHR) {
90 // code that's executed when the request is processed successfully
91 dialogHTML = "<table style='width: 100%;'>";
92 dialogHTML += "<tr class='heading_row'><th>" + timedContentRuleAjax.start_label + "</th><th>" + timedContentRuleAjax.end_label + "</th></tr>";
93 dialogHTML += '</table>';
94
95 tag.find("div#tcr-loading").remove();
96 tag.append(dialogHTML);
97 jQuery.each(data, function(key, value) {
98 tag.find("table").append('<tr class="day_row ' + value.status + '" title="' + value.time + '"><td>' + value.start + '</td><td>' + value.end + '</td></tr>');
99 });
100 },
101 'json'
102 ).fail( function(xhr, textStatus, errorThrown) {
103 tag.find("div#tcr-loading").remove();
104 var errorText = '<div class="tcr-error"><p><strong>' + timedContentRuleAjax.error + '</strong></p>';
105 errorText += '<p class="heading">' + timedContentRuleAjax.error_desc + '</p>';
106 errorText += '<div>' + xhr.responseText + '</div></div>';
107 tag.append(errorText);
108 });
109 });
110
111 jQuery( 'input[id^="timed_content_rule_"], select[id^="timed_content_rule_"]' ).change(function(e) {
112 var target = jQuery(e.target);
113 if (target.is("#timed_content_rule_exceptions_dates"))
114 return;
115 var args = getArgs();
116 var tag = jQuery("div#schedule_desc");
117 var button = jQuery('input#timed_content_rule_test');
118
119 button.prop('disabled', 'disabled');
120 tag.html('<img src="' + timedContentRuleAjax.loadingimg + '" /> Loading...');
121
122 jQuery.post(
123 timedContentRuleAjax.ajaxurl,
124 {
125 // additional data to be included along with the form fields
126 action: 'timedContentPluginGetScheduleDescriptionAjax',
127 timed_content_rule_action: jQuery( "input[name=timed_content_rule_action]:checked" ).val(),
128 timed_content_rule_frequency: args.fsel,
129 timed_content_rule_timezone: args.tz,
130 timed_content_rule_recurrence_duration: args.rd,
131 timed_content_rule_recurrence_duration_num_repeat: args.nr,
132 timed_content_rule_recurrence_duration_end_date: args.ed,
133 timed_content_rule_weekly_days_of_week_to_repeat: args.days,
134 timed_content_rule_interval_multiplier: args.im,
135 timed_content_rule_instance_start: args.start,
136 timed_content_rule_instance_end: args.end,
137 timed_content_rule_monthly_nth_weekday_of_month: args.nth,
138 timed_content_rule_monthly_nth_weekday_of_month_nth: args.ntho,
139 timed_content_rule_monthly_nth_weekday_of_month_weekday: args.nthw,
140 timed_content_rule_exceptions_dates: args.ex_days
141 },
142 function(data, textStatus, jqXHR) {
143 // code that's executed when the request is processed successfully
144 tag.html(data);
145 button.removeAttr('disabled');
146 },
147 'text'
148 ).fail( function(xhr, textStatus, errorThrown) {
149 var errorText = '<div class="tcr-error"><p><strong>' + timedContentRuleAjax.error + '</strong></p>';
150 errorText += '<p class="heading">' + timedContentRuleAjax.error_desc + '</p>';
151 errorText += '<div>' + xhr.responseText + '</div></div>';
152 tag.append(errorText);
153 });
154 });
155 });