PluginProbe
Jock On Air Now (JOAN) / 5.6
Jock On Air Now (JOAN) v5.6
4.7.3 4.7.4 4.7.5 4.7.6 4.7.7 4.7.8 5.0 5.1 5.2.0 5.3.0 5.4.0 5.5.0 5.5.1 5.5.2 5.5.3 5.5.4 5.5.6 5.5.7 5.5.8 5.5.9 5.6 5.6.1 5.6.2 5.6.3 5.6.4 All 77 releases
joan / admin.js

admin.js in Jock On Air Now (JOAN) 5.6, at admin.js

373 lines 10.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /*jshint eqnull:true */
2 /*!
3 * jQuery Cookie Plugin v1.2
4 * https://github.com/carhartl/jquery-cookie
5 *
6 * Copyright 2011, Klaus Hartl
7 * Dual licensed under the MIT or GPL Version 2 licenses.
8 * http://www.opensource.org/licenses/mit-license.php
9 * http://www.opensource.org/licenses/GPL-2.0
10 */
11 (function(a,b,c){function e(a){return a}function f(a){return decodeURIComponent(a.replace(d," "))}var d=/\+/g;a.cookie=function(d,g,h){if(g!==c&&!/Object/.test(Object.prototype.toString.call(g))){h=a.extend({},a.cookie.defaults,h);if(g===null){h.expires=-1}if(typeof h.expires==="number"){var i=h.expires,j=h.expires=new Date;j.setDate(j.getDate()+i)}g=String(g);return b.cookie=[encodeURIComponent(d),"=",h.raw?g:encodeURIComponent(g),h.expires?"; expires="+h.expires.toUTCString():"",h.path?"; path="+h.path:"",h.domain?"; domain="+h.domain:"",h.secure?"; secure":""].join("")}h=g||a.cookie.defaults||{};var k=h.raw?e:f;var l=b.cookie.split("; ");for(var m=0,n;n=l[m]&&l[m].split("=");m++){if(k(n.shift())===d){return k(n.join("="))}}return null};a.cookie.defaults={};a.removeCookie=function(b,c){if(a.cookie(b,c)!==null){a.cookie(b,null,c);return true}return false}})(jQuery,document)
12
13 jQuery(function($){
14
15 function updateTabHeight(){
16 $('.joan-tabs').height($('.tab-container:eq(0)').height());
17 }
18
19 message_is_being_displayed = false;
20
21 function display_message(message, state){
22
23
24 var textColor = '';
25 var borderColor = '';
26 var backgroundColor = '';
27
28 if (state == 'good'){
29 var backgroundColor = '#49ac3c';
30 var borderColor = '#227017';
31 var textColor = '#fff';
32 } else if (state == 'bad') {
33 var backgroundColor = '#9b2121';
34 var borderColor = '#400909'
35 var textColor = '#fff';
36
37 } else if (state == 'warning') {
38 var borderColor = '#8b8525';
39 var backgroundColor = '#c8c25b';
40 var textColor = '#fff';
41
42 }
43
44 if ( ! message_is_being_displayed )
45 {
46
47 message_is_being_displayed = true;
48 $('.joan-message-window').css({right : '-2em', opacity: 0, display: 'block', backgroundColor: backgroundColor, color : textColor, borderColor: borderColor}).animate({ right: '2em', opacity : 1 }, 450).text(message).delay(5000).animate({right: '4em', opacity: 0}, 350, function(){
49 message_is_being_displayed = false;
50 });
51 } else {
52
53 $('.joan-message-window').stop(true, true).css({ backgroundColor: backgroundColor, color : textColor, borderColor: borderColor}).text(message).delay(5000).animate({right: '4em', opacity: 0}, 350, function(){
54 message_is_being_displayed = false;
55 });
56
57 }
58
59 $('.joan-message-window').click(function(){
60 $('.joan-message-window').stop(true, true).animate({right: '4em', opacity: 0}, 350, function(){
61 message_is_being_displayed = false;
62 });
63 });
64
65
66
67 }
68
69
70 function buildShowObject(show){
71
72 var formHTML = '';
73
74 var showName = show.showName;
75 var imageURL = show.imageURL;
76 var linkURL = show.linkURL;
77 var showID = show.id;
78 var startDay = show.dayOfTheWeek;
79 var startTime = show.startTime;
80 var endTime = show.endTime;
81
82 // Get the start and end times from the UNIX timestamps
83 var startTimeClock = show.startClock;
84 var endTimeClock = show.endClock;
85
86 //Build the HTML for each show entry change form
87 formHTML += '<div class="joan-entry joan-id-'+showID+'" data-show-end-time="'+endTime+'">'+"\r";
88
89 if (imageURL){
90 formHTML += '<img class="joan-image hide-on-simple" src="'+imageURL+'" data-target-field-name="'+showID+'" />';
91 }
92
93 formHTML += '<p class="joan-show-name"><strong>'+startTimeClock+'</strong> to <strong>'+endTimeClock+'</strong><br/><input type="text" name="showName['+showID+']" value="'+showName+'" /> <span class="joan-delete-show"><a href="#" data-remove-show-id="'+showID+'" class="remove-show">Delete</a></span></p>'+"\r";
94 formHTML += '<p class="joan-show-urls hide-on-simple"><input type="text" name="linkURL['+showID+']" value="'+linkURL+'" placeholder="Link URL" class="image-url" /> <input type="hidden" name="imageURL['+showID+']" data-target-field-name="'+showID+'" value="'+imageURL+'" /></p>'+"\r";
95 formHTML += '<p class="hide-on-simple"><input type="button" class="secondary-button button upload-image" data-target-field="'+showID+'" value="Upload Image" /> <input type="submit" value="Save Changes" class="button button-primary" /></p>';
96 formHTML += '</div>';
97
98 return formHTML;
99 }
100
101 function loadEntireSchedule(scriptURL){
102
103 $.post(scriptURL, {action:"show-time-curd","crud-action": "read"}, function(scheduleJSON){
104
105 var days = $.parseJSON(scheduleJSON);
106
107 var formHTML = '';
108
109 for (var day in days){
110
111 formHTML += '<div class="'+ day.toLowerCase() +'-container day-container">';
112 formHTML += '<h2>' + day + '</h2>';
113
114 $(days[day]).each(function(key, entries){
115
116 $(entries).each(function(){
117
118 formHTML += buildShowObject(this);
119
120 });
121
122 });
123
124 formHTML += '</div><!-- end this day of the week -->';
125
126 }
127
128 formHTML += '</form>';
129
130
131 $('.joan-schedule').html(formHTML).removeClass('loading');
132 $('.joan-entry').show();
133 updateTabHeight();
134 });
135
136 }
137
138 //Load the schedule on page load
139 loadEntireSchedule($('#add-joan-entry').attr('action'));
140
141 function insertShowIntoSchedule (show){
142
143 var show = show[0];
144
145 //First, find the appropriate day container
146 var dayContainer = $('.'+show.dayOfTheWeek.toLowerCase()+'-container');
147
148 var showAdded = false;
149
150 //Find the last show to air right before this one and insert it after
151 $($('.joan-entry', dayContainer).get().reverse()).each(function(){
152 if ($(this).attr('data-show-end-time') < show.startTime){
153
154 var insertHTML = buildShowObject(show);
155 $(this).after(insertHTML);
156 showAdded = true;
157
158 return false;
159
160 }
161
162 });
163
164 //If there are no shows, just add it
165 if ($('.joan-entry', dayContainer).length == 0 || showAdded == false) {
166 var insertHTML = buildShowObject(show);
167 $('h2', dayContainer).after(insertHTML);
168 }
169
170
171
172 //Slide down the newly created element
173 $('.joan-id-'+show.id).slideDown(250, function(){
174 //Update the tab height
175 updateTabHeight();
176 });
177
178
179 }
180
181 //Update the end day when the start day changes
182 $('select.startDay').change(function(){
183
184 $('select.endDay').val($('select.startDay').val());
185
186 });
187
188 $('#starttime').change(function(){
189 $('#endtime').val($('#starttime').val());
190 });
191
192 //Updates to the Joan Table
193
194 $('#add-joan-entry').submit(function(e){
195
196 e.preventDefault();
197
198 //Serialze the new entry and send it the CRUD script
199
200 var data = $(this).serialize();
201 var scriptURL = $(this).attr('action');
202
203 $.post(scriptURL, data, function (results){
204 if (results == 'scheduling conflict'){
205
206 display_message('You already have a show sceduled at that time.', 'bad');
207
208 } else if (results == 'bad linkURL'){
209
210 display_message('Check your Link URL. It\'s no good.', 'bad');
211
212
213 } else if (results == 'bad name'){
214
215 display_message('You forgot to add a name.', 'bad');
216
217 } else if (results == 'too soon'){
218
219 display_message('The show can\'t start before it ends. Check your times.', 'bad');
220
221 } else {
222
223 display_message('Show added.', 'good');
224
225 insertShowIntoSchedule($.parseJSON(results));
226
227 }
228 });
229
230 });
231
232 $('.joan-update-shows').on('submit', function(e){
233
234 e.preventDefault();
235
236 var data = $(this).serialize();
237 var scriptURL = $(this).attr('action');
238
239 $.post(scriptURL, data, function (results){
240 if (results == 'good updates'){
241
242 display_message('Changes saved.', 'good');
243
244 }
245 });
246
247 });
248
249 $(document).on('click','a.remove-show', function(e){
250 console.log(this);
251 e.preventDefault();
252 //Confirm the deletion
253 var x = confirm('Are you sure you want to delete this show? This cannot be undone.');
254 if (x){
255 var removeShowID = $(this).attr('data-remove-show-id');
256 var removeNonce = $('#delete_entries_nonce_field').val();
257 var referrer = $('.script-src').val();
258 $.post($('#add-joan-entry').attr('action'), {action:"show-time-curd","crud-action" : "delete", "id" : removeShowID, "delete_entries_nonce_field" : removeNonce, "_wp_http_referer" : referrer}, function(result){
259 if (result){
260 //Remove this show from the list
261 $('.joan-id-'+removeShowID).slideUp(250, function(){
262 updateTabHeight();
263 });
264 }
265 });
266 }
267 });
268
269 //Create the tabs
270
271 if ($.cookie('current-joan-tab')){
272 var currentTab = $.cookie('current-joan-tab');
273 } else {
274 var currentTab = 0;
275 }
276
277 $('.tab-container:eq('+currentTab+')').fadeIn(250);
278 $('.joan-tabs').height($('.tab-container:eq('+currentTab+')').height());
279
280 $('.tab-navigation li').click(function(){
281 //Get the index of the clicked <li>
282 var index = $(this).index();
283
284 if (index != currentTab){
285
286 //Hide the current tab-container, then show the selected one
287 $('.tab-container:eq('+currentTab+')').fadeOut(250);
288 currentTab = index;
289 $('.tab-container:eq('+currentTab+')').fadeIn(250);
290
291 //Set the height
292 $('.joan-tabs').height($('.tab-container:eq('+currentTab+')').height());
293
294 //Update the cookie
295 $.cookie('current-joan-tab', currentTab);
296
297 }
298
299
300 });
301
302 //Make the view type toggleable
303
304 viewType = 0;
305
306 $('a.display-toggle').click(function(e){
307
308 e.preventDefault();
309
310 if ($(this).hasClass('full-display')){
311 viewType = 1;
312 $.cookie('set-full-display', true);
313 } else {
314 viewType = 0;
315 $.cookie('set-full-display', '');
316 }
317
318 update_display_type();
319
320 });
321
322
323 $('.joan-entry input').on('focus', function(){
324
325 if ( ! $.cookie('set-full-display')){
326 $('.editing').removeClass('editing');
327 $(this).closest('.joan-entry').addClass('editing');
328 updateTabHeight();
329 }
330
331
332 });
333
334
335 function update_display_type() {
336
337 if (viewType == 0){
338 $('.joan-entry').removeClass('editing');
339 } else if (viewType ==1 ) {
340 $('.joan-entry').addClass('editing');
341 }
342
343 updateTabHeight();
344
345 }
346 });
347
348
349 //Handle image uploading
350
351 jQuery(document).ready(function($) {
352
353 jQuery(document).on('click', '.upload-image',function() {
354 targetTextField = $(this).attr('data-target-field');
355 target = $('input[data-target-field-name="'+targetTextField+'"]');
356
357 tb_show('', 'media-upload.php?type=image&amp;TB_iframe=true');
358
359 return false;
360 });
361
362 window.send_to_editor = function(html) {
363 imgurl = $('img',html).attr('src');
364 $(target).val(imgurl);
365 tb_remove();
366
367 //Update the image
368 $('img[data-target-field-name="'+targetTextField+'"]').attr('src', imgurl).show();
369
370 }
371
372 });
373