Created
May 4, 2011 12:21
-
-
Save lazypower/955139 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Page initialization - The root of all evil | |
$(document).ready(function () | |
{ | |
// hide the template container | |
$('#TemplateContainer').hide(); | |
// Initialize the Notification Daemon | |
$('#StatusBar').jnotifyInizialize({ | |
oneAtTime: true | |
}) | |
$('#Notification') | |
.jnotifyInizialize({ | |
oneAtTime: false, | |
appendType: 'append' | |
}).css({ 'z-index': '10000' }); | |
$('#Notification').jnotifyAddMessage({ text: "Notification system initialized", permanent: false }); | |
// grab the JSON Object via AJAX and process it - we want CURRENT results | |
grabVideoList(); | |
}); // end document.ready | |
/*-------------------------------------------------------- | |
- AJAX CALLS - This could get messy... - | |
-------------------------------------------------------*/ | |
function grabVideoList() | |
{ | |
var jsonString; | |
$.ajax({ | |
url: "service.asmx/getVideoJSON", | |
cache: false, | |
type: 'POST', | |
success: function(data) { | |
// do stuff with the json response object | |
if (data == null) | |
{ | |
$('#Notification').jnotifyAddMessage({ text: "No Videos Loaded", permanent: true, type: 'error' }); | |
} else { | |
$('#Notification').jnotifyAddMessage({ text: "Processing Video List", permanent: false }); | |
//DEBUG | |
console.log(data); | |
buildDisplayList(data); | |
// set the table to sortable | |
$('#VideoList').tablesorter(); | |
$('#Notification').jnotifyAddMessage({ text: "Finished Processing Queue", permanent: false }); | |
} | |
}, | |
failure: function(data) { | |
$('#Notification').jnotifyAddMessage({ text: "We failed to get any videos", permanent: true, type: 'error' }); | |
} | |
}); // end AJAX | |
} | |
function changeApproval(memberID, status) | |
{ | |
if ( !memberID ) | |
{ | |
memberID = $(this).find('img').attr('id'); | |
} | |
//value = $('#VideoList').find('img#' + memberID).attr('name'); | |
// quick status swap - confusing yes, but we want to set the opposite of what it is | |
//since status is being read as a string from the DOM we have to convert it to use the inverse of itself | |
status = isTrue(status); | |
$.ajax({ | |
url: "service.asmx/changeApproval", | |
cache: false, | |
data: "memberid="+ memberID +"&value=" + !status, | |
type: 'POST', | |
success: function(data) { | |
// do stuff with the json response object | |
if (data == null) | |
{ | |
$('#Notification').jnotifyAddMessage({ text: "Error Changing Video Status", permanent: true, type: 'error' }); | |
} else { | |
$('img#' + memberID).attr('name', !status).attr('src', "images/" + !status +'.png'); | |
$('#Notification').jnotifyAddMessage({ text: data['statusMessage'], permanent: false }); | |
} | |
}, | |
failure: function(data) { | |
$('#Notification').jnotifyAddMessage({ text: data['statusMessage'], permanent: true, type: 'error' }); | |
} | |
}); // end AJAX | |
} | |
function convertVideo(originalVideo) | |
{ | |
$('#Notification').jnotifyAddMessage({ text: "Preparing to convert video", permanent: false }); | |
$.ajax({ | |
url: "service.asmx/convertVideo", | |
data: "OriginalVideo=" + originalVideo, | |
cache: false, | |
type: 'POST', | |
success: function(data) { | |
// do stuff with the json response object | |
if (data == null) | |
{ | |
$('#Notification').jnotifyAddMessage({ text: "Error processing request", permanent: true, type: 'error' }); | |
} else { | |
//DEBUG | |
console.log(data); | |
$('#Notification').jnotifyAddMessage({ text: data['statusMessage'], permanent: false }); | |
} | |
}, | |
failure: function(data) { | |
$('#Notification').jnotifyAddMessage({ text: data['statusMessage'], permanent: true, type: 'error' }); | |
} | |
}); // end AJAX | |
} | |
/*--------------------------------------------------- | |
- Template Controls | |
--------------------------------------------------*/ | |
function generateLightBox(videoID, embedVid) | |
{ | |
html = $('.embed-template').clone(); | |
html.css("display", "inline") | |
html.attr('id', 'div_' + videoID); | |
//html.attr('flashvars','value="file=../upload/' + embedVid + '&image=../images/vidThumbs/' + embedVid + '.jpg"'); | |
html.find('embed').attr('flashvars','file=upload/' + embedVid + '&image=images/vidThumbs/' + embedVid + '.jpg"'); | |
return html; | |
} | |
function buildDisplayList(videos) | |
{ | |
if (videos == null) | |
{ | |
$('#Notification').jnotifyAddMessage({ text: "Error processing queue.", permanent: true, type: 'error' }); | |
throw("I failed, sorry."); | |
} | |
// ok the object isnt null, lets build a sortable table with the info | |
for (var i = 0; i < videos.length; i++) | |
{ | |
// generate the lightbox entry prior to appending to the list | |
lbox = generateLightBox(videos[i].VideoId, videos[i].EmbedFile); | |
$('#TemplateContainer').append(lbox); | |
// now append it to the list | |
entry = $('#list-template').clone(); | |
entry.attr('id', videos[i].VideoId); | |
// append the data to the cloned item | |
entry.find('td.memberId').text(videos[i].MemberId).attr('id', videos[i].MemberId); | |
entry.find('td.memberName').text(videos[i].Author); | |
entry.find('td.submittedOn').text(videos[i].CreatedOn); | |
entry.find('td.votes').text(videos[i].Votes); | |
entry.find('img#videoStatus').attr('src', "images/"+ videos[i].IsApproved +".png") | |
.attr('name', videos[i].IsApproved).attr('id', videos[i].MemberId); | |
// temporary hack due to javascript and strange scoping | |
temp_vid = videos[i].OrigFile; | |
if (videos[i].HasThumb == true) | |
{ | |
entry.find('td.view').html('<a id=\"inline\" href=\"#div_' + videos[i].VideoId + '\">View</a></td>'); | |
} else { | |
entry.find('td.view').html('<button>Convert</button>').bind('click', function() { | |
convertVideo(temp_vid); | |
return false; | |
}); | |
} | |
// some messy approval code - probably needs review and refactor | |
entry.find('a.changeStatus').attr('id', videos[i].MemberId).attr('status', videos[i].IsApproved); | |
entry.find('a.changeStatus').bind('click', function () { | |
changeApproval($(this).attr('id'), $(this).attr('status')); | |
return false; | |
}); | |
//stick it in the table | |
$('#VideoList TBody').append(entry); | |
}//end loop | |
//apply the lightbox to our built objects | |
$("a#inline").fancybox({ | |
'hideOnContentClick': true | |
}); | |
} | |
/*--------------------------------------------------------------------- | |
/ Utility Functions -- These belong in a toolbox | |
---------------------------------------------------------------------*/ | |
function isTrue(input) { | |
if (typeof input == 'string') { | |
return input.toLowerCase() == 'true'; | |
} | |
return !!input; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment