PluginProbe
Jock On Air Now (JOAN) / 5.0
Jock On Air Now (JOAN) v5.0
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.0, at admin.js

378 lines 10.4 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').live('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 $('a.remove-show').live('click', function(e){
250
251 e.preventDefault();
252
253 //Confirm the deletion
254
255 var x = confirm('Are you sure you want to delete this show? This cannot be undone.');
256
257 if (x){
258 var removeShowID = $(this).attr('data-remove-show-id');
259 var removeNonce = $('#delete_entries_nonce_field').val();
260 var referrer = $('.script-src').val();
261
262 $.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){
263 if (result){
264 //Remove this show from the list
265 $('.joan-id-'+removeShowID).slideUp(250, function(){
266 updateTabHeight();
267 });
268 }
269 });
270 }
271
272 });
273
274 //Create the tabs
275
276 if ($.cookie('current-joan-tab')){
277 var currentTab = $.cookie('current-joan-tab');
278 } else {
279 var currentTab = 0;
280 }
281
282 $('.tab-container:eq('+currentTab+')').fadeIn(250);
283 $('.joan-tabs').height($('.tab-container:eq('+currentTab+')').height());
284
285 $('.tab-navigation li').click(function(){
286 //Get the index of the clicked <li>
287 var index = $(this).index();
288
289 if (index != currentTab){
290
291 //Hide the current tab-container, then show the selected one
292 $('.tab-container:eq('+currentTab+')').fadeOut(250);
293 currentTab = index;
294 $('.tab-container:eq('+currentTab+')').fadeIn(250);
295
296 //Set the height
297 $('.joan-tabs').height($('.tab-container:eq('+currentTab+')').height());
298
299 //Update the cookie
300 $.cookie('current-joan-tab', currentTab);
301
302 }
303
304
305 });
306
307 //Make the view type toggleable
308
309 viewType = 0;
310
311 $('a.display-toggle').click(function(e){
312
313 e.preventDefault();
314
315 if ($(this).hasClass('full-display')){
316 viewType = 1;
317 $.cookie('set-full-display', true);
318 } else {
319 viewType = 0;
320 $.cookie('set-full-display', '');
321 }
322
323 update_display_type();
324
325 });
326
327
328 $('.joan-entry input').live('focus', function(){
329
330 if ( ! $.cookie('set-full-display')){
331 $('.editing').removeClass('editing');
332 $(this).closest('.joan-entry').addClass('editing');
333 updateTabHeight();
334 }
335
336
337 });
338
339
340 function update_display_type() {
341
342 if (viewType == 0){
343 $('.joan-entry').removeClass('editing');
344 } else if (viewType ==1 ) {
345 $('.joan-entry').addClass('editing');
346 }
347
348 updateTabHeight();
349
350 }
351 });
352
353
354 //Handle image uploading
355
356 jQuery(document).ready(function($) {
357
358 jQuery('.upload-image').live('click', function() {
359 targetTextField = $(this).attr('data-target-field');
360 target = $('input[data-target-field-name="'+targetTextField+'"]');
361
362 tb_show('', 'media-upload.php?type=image&amp;TB_iframe=true');
363
364 return false;
365 });
366
367 window.send_to_editor = function(html) {
368 imgurl = $('img',html).attr('src');
369 $(target).val(imgurl);
370 tb_remove();
371
372 //Update the image
373 $('img[data-target-field-name="'+targetTextField+'"]').attr('src', imgurl).show();
374
375 }
376
377 });
378