function dbg(content) {
$('debug-content').innerHTML = content + '
' + $('debug-content').innerHTML;
}
/* *********************************************************************************
CORE FUNCTIONS / AJAX
*********************************************************************************
*/
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g,"");
}
function rest(restMethod, restParams, onReturn, returnParams) {
showAjaxWait();
// Build the parameters to pass
var sendMethod = 'post';
var paramString = "&method="+restMethod;
for (var varName in restParams) paramString += '&' + varName + '=' + encodeURIComponent(restParams[varName]);
options = { method: sendMethod, onLoading: function() {}, parameters: paramString, onComplete: function(resp) { hideAjaxWait(); var returnString = resp.responseText; returnParamString = (returnParams == null) ? 'returnString' : 'returnString,returnParams'; if(onReturn != null) eval(onReturn + '(' + returnParamString + ')'); } } //"
//var req = new Ajax.Request('rest/', options );
var req = new Ajax.Request('http://news.kiiosk.com/rest/', options );
}
function toJson(respString) {
return eval('(' + respString + ')');
}
function showAjaxWait() {
$('ajax-loading').style.display = 'block';
}
function hideAjaxWait() {
$('ajax-loading').style.display = 'none';
}
/* *********************************************************************************
POPUP WINDOW FRAMEWORK
*********************************************************************************
*/
function updatePopupEventListeners() {
// Currently using lightwindow framework, need to add listeners to all the
// lightwindow links that loaded via Ajax
lightwindowInit();
}
function goTop(acceleration, time) {
acceleration = acceleration || 0.5;
time = time || 16;
var dx = 0;
var dy = 0;
var bx = 0;
var by = 0;
var wx = 0;
var wy = 0;
if (document.documentElement) {
dx = document.documentElement.scrollLeft || 0;
dy = document.documentElement.scrollTop || 0;
}
if (document.body) {
bx = document.body.scrollLeft || 0;
by = document.body.scrollTop || 0;
}
var wx = window.scrollX || 0;
var wy = window.scrollY || 0;
var x = Math.max(wx, Math.max(bx, dx));
var y = Math.max(wy, Math.max(by, dy));
var speed = 1 + acceleration;
window.scrollTo(Math.floor(x / speed), Math.floor(y / speed));
if(x > 0 || y > 0) {
var invokeFunction = "goTop(" + acceleration + ", " + time + ")"
window.setTimeout(invokeFunction, time);
}
}
function goToPage() {
// Is there even a hash? if not, ignore this
var hash = location.hash;
if(hash) {
hash = parseInt(hash.substring(1))
if(hash > 0) {
$('page-selector').selectedIndex = (hash-1);
$('page-selector').onchange();
}
}
}
/* *********************************************************************************
FLASH COMMUNICATION FRAMEWORK WITH LOCAL JAVASCRIPT
*********************************************************************************
*/
var flashSaveId = null;
function setFlashItemSaveID(item_id) {
flashSaveId = item_id;
// Update Link incase this item is already saved!
rest('news.item.is.saved',{'item_id' : item_id}, 'updateFlashSaveLink');
}
function updateFlashSaveLink(respString) {
// Evla this to json
var json = toJson(respString);
if(json!=null) {
$('mediaview-action-save').className = (json) ? 'action-saved' : 'action-save';
$('mediaview-action-save').innerHTML = (json) ? 'Item Saved' : 'Save';
}
}
/* *********************************************************************************
JAVASCRIPT COOKIES
*********************************************************************************
*/
function setCookie( name, value, expires, path, domain, secure ) {
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );
document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}
function getCookie( check_name ) {
var a_all_cookies = document.cookie.split( ';' );
var a_temp_cookie = '';
var cookie_name = '';
var cookie_value = '';
var b_cookie_found = false; // set boolean t/f default f
for ( i = 0; i < a_all_cookies.length; i++ )
{
a_temp_cookie = a_all_cookies[i].split( '=' );
cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
// if the extracted name matches passed check_name
if ( cookie_name == check_name )
{
b_cookie_found = true;
if ( a_temp_cookie.length > 1 )
{
cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
}
return cookie_value;
break;
}
a_temp_cookie = null;
cookie_name = '';
}
if ( !b_cookie_found )
{
return null;
}
}
function showCompatibilityNotice() {
// Already shown?
if(getCookie('compat_notice') != null)
return;
setCookie('compat_notice', true, 0, '/', '','');
$('compatibility-notice').style.display = 'block';
}
/* *********************************************************************************
NEWS & NEWS ITEM FUNCTIONS
*********************************************************************************
*/
/* Sending Item to Friend */
function sendItemToFriend(email, item_id) {
// Call Rest
rest('news.item.sendtofriend',{'email' : email, 'item_id' : item_id}, 'sendItemToFriendConfirm', {'email' : email, 'item_id' : item_id});
}
function sendItemToFriendConfirm(respString, paramList) {
// Eval this to json
var json = toJson(respString);
// Show the result div
$('send-item-result').style.display = 'block';
if(json.error) {
$('send-item-result').innerHTML = '
' + json.error['description'] + '
';
} else {
$('send-item-result').innerHTML = 'Email sent to ' + paramList.email + '
';
// Record the share!
trackShareItem(-1, paramList.item_id, paramList.email);
$('recipient-email-addr').value = '';
}
}
/* Set the news item langauge */
function setNewsFilterLanguage(languageid) {
rest('news.set.language.filter', {'languageid' : languageid}, 'setNewsFilterLanguageConfirm');
}
function setNewsFilterLanguageConfirm() {
// just refresh the page
window.location = window.location;
}
/* Track an item share in the system */
function trackShareItem(share_type, item_id, email) {
// Precheck the email
email = (email == null) ? "" : email;
rest('news.item.share', {'item_id' : item_id, 'email' : email, 'share_type' : share_type});
}
/* Adds a tag to a news item */
function addTag(item_id, tag) {
rest('news.item.tag', {'item_id' : item_id, 'tag' : tag}, 'updateTags');
}
function updateTags(respString) {
$('tag-list').innerHTML = respString;
$('add-tag-link').style.display="inline";
$('tag-item-form').style.display="none";
}
/* Load Votes Inline */
function updateInlineVotes(respString, paramList) {
$(paramList.div_id).innerHTML = respString;
$(paramList.div_id).className = 'inline-votes';
$(paramList.div_id).style.display = 'block';
}
function getInlineVotes(item_id, div_id) {
rest('news.item.get.votes', {'record_start' : 0, 'num_records' : 7, 'item_id' : item_id, 'print_html' : 'true'}, 'updateInlineVotes', {'div_id' : div_id});
}
/* Loads votes for a given item */
function loadMoreVotes(record_start, num_records, item_id) {
rest('news.item.get.votes', {'item_id' : item_id, 'record_start' : record_start, 'num_records' : num_records, 'print_html' : 'true'}, 'updateVotes', {'item_id' : item_id});
}
function updateVotes(respString, paramList) {
$('item-votes-' + paramList.item_id).innerHTML = respString;
}
/* Load More News Items */
function loadMoreNews(record_start, num_records, listtype, listparam, language, sortby, exclude) {
rest('news.get.set', {'record_start' : record_start, 'num_records' : num_records, 'listtype' : listtype, 'listparam' : listparam, 'language' : language, 'sortby' : sortby, 'exclude' : exclude, 'print_html' : 'true'},'loadMoreNewsConfirm');
}
function loadMoreNewsConfirm(respString) {
$('news-item-listing').innerHTML = respString;
//window.location = '#page-content';
goTop();
// Update the Event Listeners for which popup framework is being utilized
updatePopupEventListeners();
}
/* Load Comments for an item */
function loadMoreComments(record_start, num_records, item_id, div_id) {
rest('news.item.get.comments', {'record_start' : record_start, 'num_records' : num_records, 'item_id' : item_id, 'print_html' : 'true'}, 'updateComments', {'div_id' : div_id, 'item_id' : item_id});
}
/* Load Comments Inline */
function updateInlineComments(respString, paramList) {
$(paramList.div_id).innerHTML = respString;
$(paramList.div_id).className = 'inline-comments';
$(paramList.div_id).style.display = 'block';
updatePopupEventListeners();
}
function getInlineComments(item_id, div_id) {
rest('news.item.get.comments', {'record_start' : 0, 'num_records' : 3, 'item_id' : item_id, 'print_html' : 'true'}, 'updateInlineComments', {'div_id' : div_id, 'item_id' : item_id});
}
function updateComments(respString, paramList) {
$('item-comments-' + paramList.item_id).innerHTML = respString;
// User just added a comment?
if(paramList.div_id != null)
highlight('comment_' + paramList.div_id)
//else
// highlight('item-comments');
// Update the Event Listeners for which popup framework is being utilized
updatePopupEventListeners();
}
function loadMoreFeeds(record_start, num_records) {
rest('feeds.get.list', {'print_html' : 'true', 'record_start' : record_start, 'num_records' : num_records }, 'loadMoreFeedsConfirm');
}
function loadMoreFeedsConfirm(respString) {
$('the-feed-list').innerHTML = respString;
}
/* *********************************************************************************
USER RELATED FUNCTIONS
*********************************************************************************
*/
function refreshNewsDropCalendar() {
rest('user.update.newsdrop.calendar',null,'refreshNewsDropCalendarConfirm');
}
function refreshNewsDropCalendarConfirm(respString) {
$('my-newsdrops-calendar').innerHTML = respString;
updatePopupEventListeners();
myLightWindow.deactivate();
}
function getSelectedTopicElement() {
// Make it selected, unselect the rest
var childrenLinks = $('my-topic-list').descendants();
for(i=0; i 0) {
window.location = 'http://news.kiiosk.com/index.php?action=mysearches&autoaddtopic=' + topic;
}
}
/* Add a myNews topic */
function addMyTopic(topic, languageFilter) {
rest('user.mytopics.add', {'topic' : topic}, 'addMyTopicConfirm', {'topic' : topic, 'languageFilter' : languageFilter});
}
function addMyTopicConfirm(respString, paramList) {
// Eval this to json
var json = toJson(respString);
if(!json.error) {
// Refresh the list
refreshMyTopicsList(paramList.topic);
// Is this the first topic? if so, we need to refresh the page to build the tab structure necessary
if(!$('topic-name'))
window.location = window.location;
else {
// Show that topic as the current search
loadMoreNewsSearch(0,20,paramList.topic, paramList.languageFilter);
$('topic-name').innerHTML=paramList.topic;
}
} else {
alert(json.error.description);
}
}
var deletingTopic = false;
function deleteMyTopic(topic, linkObjectID, lastOne) {
deletingTopic = true;
rest('user.mytopics.delete', {'topic' : topic}, 'deleteMyTopicConfirm', {'linkObjectID' : linkObjectID, 'lastOne' : lastOne});
}
function deleteMyTopicConfirm(respString, paramList) {
// Eval this to json
var json = toJson(respString);
if(!json.error) {
// Was it the last one?
if(paramList.lastOne)
window.location = 'http://news.kiiosk.com/index.php?action=mysearches';
// was it selected?
$theObject = $(paramList.linkObjectID);
if($theObject.className == "selected") {
selectedTopic = "";
} else {
// Get the currently selected topic name
selectedTopic = $('topic-name').innerHTML;
}
deletingTopic = false;
refreshMyTopicsList(selectedTopic);
} else {
alert(json.error.description);
}
deletingTopic = false;
}
function refreshMyTopicsList(currentTopic) {
var selectFirstObject = false;
if(currentTopic == "")
selectFirstObject = true;
rest('user.refresh.mytopics.list', {'currentTopic' : currentTopic}, 'refreshMyTopicsListConfirm', {'selectFirstObject' : selectFirstObject});
}
function refreshMyTopicsListConfirm(respString, paramList) {
$('my-news-topics-content').innerHTML = respString;
if(paramList.selectFirstObject) {
// Get the topic name
var topic = $('mytopic-0').readAttribute('topic');
selectMyTopic(topic, 0, $('mytopic-0'));
}
}
/* Comment an Item */
function commentItem(item_id, comment) {
rest('news.item.comment', {'item_id' : item_id, 'comment' : comment}, 'commentItemConfirm', {'item_id' : item_id});
}
function commentItemConfirm(respString,paramList) {
// Eval this to json
var json = toJson(respString);
if(!json.error)
loadMoreComments(0, 5, paramList.item_id, json.value);
}
/* Vote for an item */
function voteItem(item_id, buttonObject, refreshVotes) {
rest('news.item.vote', { 'item_id' : item_id }, 'voteItemConfirm', { 'buttonObject' : buttonObject, 'refreshVotes' : refreshVotes, 'item_id' : item_id});
}
function voteItemConfirm(respString , paramList) {
// Eval this to json
var json = toJson(respString);
if(!json.error) {
paramList.buttonObject.style.display = 'none';
if(paramList.refreshVotes)
loadMoreVotes(0,14,paramList.item_id);
}
}
function refreshSaveList() {
rest('user.refresh.saves.list', null, 'refreshSaveListConfirm');
}
function refreshSaveListConfirm(respString) {
var theDiv = $('saved-item-box-list');
theDiv.innerHTML = respString;
}
/* User saves an item */
function saveItem(item_id, buttonObject, refreshSaves, changeText) {
rest('news.item.save', {'item_id' : item_id}, 'saveItemConfirm', {'buttonObject' : buttonObject, 'refreshSaves' : refreshSaves, 'changeText' : changeText});
}
function saveItemConfirm(respString, paramList) {
// Eval this to json
var json = toJson(respString);
if(!json.error) {
// Lets keep it this way for now (item-saved) and not give them the op to delete it unless its loaded
// via php. otherwise its going to get complicated with the ajax and subject to lots of errors!
paramList.buttonObject.className = 'action-saved';
//paramList.buttonObject.className = 'action-delete-save';
if(paramList.changeText) {
paramList.buttonObject.innerHTML = "Item Saved";
//paramList.buttonObject.innerHTML = "Remove Saved";
}
if(paramList.refreshSaves) {
refreshSaveList();
}
} else {
//alert(json.error.description);
}
}
/* Deletes an item from a users save history */
function deleteSavedItem(item_id, refresh_page, refresh_page_location, page_start, num_on_page, num_per_page, buttonObject) {
rest('user.delete.saved.item', {'item_id' : item_id}, 'deleteSavedItemConfirm', {'item_id': item_id, 'page_start' : page_start, 'num_on_page' : num_on_page, 'num_per_page' : num_per_page, 'refresh_page' : refresh_page, 'refresh_page_location' : refresh_page_location, 'buttonObject' : buttonObject});
}
function deleteSavedItemConfirm(respString, paramList) {
// Eval this to json
var json = toJson(respString);
if(!json.error) {
if(paramList.refresh_page) {
// Two locations here -- one in myaccount/mysaves and the other - anywhere else!
if(paramList.refresh_page_location == "myaccount") {
// If we're on page 0, who cares, just refresh
if(paramList.page_start == 0) {
getMoreSaveHistory(0, paramList.num_per_page);
} else {
// This is more complicated
// Anything left on this page?
paramList.num_on_page--;
if(paramList.num_on_page == 0) {
// Refresh the last page
var lastPageStart = (paramList.page_start - paramList.num_per_page < 0) ? 0 : (paramList.page_start - paramList.num_per_page);
getMoreSaveHistory(lastPageStart, paramList.num_per_page);
} else {
// refresh this page
getMoreSaveHistory(paramList.page_start, paramList.num_per_page);
}
}
var currentTotal = $('save-count').innerHTML;
currentTotal = parseInt(currentTotal);
$('save-count').innerHTML = (currentTotal - 1);
} else {
// Update the icon
//paramList.buttonObject.className = 'action-save';
//paramList.buttonObject.innerHTML = "Save";
if(paramList.refresh_page_location == "saveslisting") {
// We have to refresh the current page to remove the item from showing up
// Anything left on this page?
paramList.num_on_page--;
if(paramList.num_on_page == 0) {
// Refresh the last page
var lastPageStart = (paramList.page_start - paramList.num_per_page < 0) ? 0 : (paramList.page_start - paramList.num_per_page);
loadMoreNews(lastPageStart, paramList.num_per_page, 'saves');
} else {
// refresh this page
loadMoreNews(paramList.page_start, paramList.num_per_page, 'saves');
}
}
// Update the save list on the left, if necessary
// refreshSaveList();
}
}
} else {
alert(json.error.description);
}
}
/* Tracks an item click (read) */
function trackItemClick(item_id) {
rest('news.item.click', {'item_id' : item_id});
}
/* Signup - Name Available */
function signupNameAvailable(name) {
rest('user.check.name.availability', {'name' : name }, 'signupNameAvailableConfirm');
}
function signupNameAvailableConfirm(respString) {
// Eval this to json
var json = toJson(respString);
if(json.available)
setFormFieldStatus('name', 'Username Available!', 'ok');
else
setFormFieldStatus('name', 'Username not available', 'error');
}
/* Signup - Password is OK */
function signupPasswordValid(password) {
rest('user.password.format.valid', {'password' : password}, 'signupPasswordValidConfirm');
}
function signupPasswordValidConfirm(respString) {
// Eval this to json
var json = toJson(respString);
if(!json.valid)
setFormFieldStatus('password', 'Password must be atleast 6 characters', 'error');
else
setFormFieldStatus('password', 'Password OK!', 'ok');
}
function signupConfirmPassword(password, confirm) {
if(confirm == '') {
$('confirmPasswordStatus').innerHTML = '';
return;
}
if(password == confirm)
$('confirmPasswordStatus').innerHTML = '';
else
setFormFieldStatus('confirmPassword', 'Passwords must be the same', 'error');
}
/* Get a user property */
function getUserProperty(property, object) {
rest('user.get.property', {'property' : property}, 'getUserPropertyConfirm', {'object' : object});
}
function getUserPropertyConfirm(respString, paramList) {
// Eval this to json
var json = toJson(respString);
if(!json.error) {
paramList.object.value = json['value'];
}
}
/* Gets User Activity for a users profile page */
function getMoreUserActivity(record_start, num_records, user_id) {
rest('user.get.activity.history', {'record_start' : record_start, 'num_records' : num_records, 'user_id' : user_id, 'print_html' : 'true'}, 'getMoreUserActivityConfirm');
}
function getMoreUserActivityConfirm(respString) {
$('user-activity-stream').innerHTML = respString;
}
/* Gets read history for a user (logged in)*/
function getMoreReadHistory(record_start, num_records) {
rest('user.get.read.history', {'record_start' : record_start, 'num_records' : num_records, 'print_html' : 'true'}, 'getMoreReadHistoryConfirm');
}
function getMoreReadHistoryConfirm(respString) {
$('read-history').innerHTML = respString;
}
/* Gets Share History for a user (logged in) */
function getMoreShareHistory(record_start, num_records) {
rest('user.get.share.history', {'record_start' : record_start, 'num_records' : num_records, 'print_html' : 'true'}, 'getMoreShareHistoryConfirm');
}
function getMoreShareHistoryConfirm(respString) {
$('share-history').innerHTML = respString;
}
/* Gets Vote History for a user (logged in) */
function getMoreVoteHistory(record_start, num_records) {
rest('user.get.voting.history', {'record_start' : record_start, 'num_records' : num_records, 'print_html' : 'true'}, 'getMoreVoteHistoryConfirm');
}
function getMoreVoteHistoryConfirm(respString) {
$('vote-history').innerHTML = respString;
}
/* Gets Save History for a user (logged in) */
function getMoreSaveHistory(record_start, num_records) {
rest('user.get.save.history', {'record_start' : record_start, 'num_records' : num_records, 'print_html' : 'true'}, 'getMoreSaveHistoryConfirm');
}
function getMoreSaveHistoryConfirm(respString) {
$('save-history').innerHTML = respString;
}
/* Gets Comment History for a user (logged in) */
function getMoreCommentHistory(record_start, num_records) {
rest('user.get.comment.history', {'record_start' : record_start, 'num_records' : num_records, 'print_html' : 'true'}, 'getMoreCommentHistoryConfirm');
}
function getMoreCommentHistoryConfirm(respString) {
$('comment-history').innerHTML = respString;
}
/* Updates a user property (logged in) */
function updateUserProperty(property, value, object, forceUpdate, refreshPage) {
rest('user.set.property', {'property' : property, 'value' : value}, 'updateUserPropertyConfirm', {'property' : property, 'object' : object, 'forceUpdate' : forceUpdate, 'refreshPage' : refreshPage});
}
function updateUserPropertyConfirm(respString, paramList) {
// Eval this to json
var json = toJson(respString);
if(json.error) {
highlight(paramList.object,true);
getUserProperty(paramList.property, paramList.object);
alert(json.error.description);
} else {
// Do we need to force the update?
if(paramList.forceUpdate)
getUserProperty(paramList.property,paramList.object);
// Do we need to refresh the page?
if(paramList.refreshPage)
window.location = window.location;
highlight(paramList.object);
}
}
/* Reverts a users photo back to default */
function revertUserPhoto() {
rest('user.set.property', {'property' : 'photo', 'value' : ''}, 'revertUserPhotoConfirm');
}
function revertUserPhotoConfirm() {
window.location = window.location; //refresh the page
}
/* Changing a users password (logged in) */
function changePassword(passwordObject, newPasswordObject, confirmPasswordObject) {
var currentPassword = passwordObject.value;
var newPassword = newPasswordObject.value;
var confirmPassword = confirmPasswordObject.value;
// Do some simple checking
if(currentPassword == "") {
$('passwordStatus').innerHTML = 'Password cannot be empty
';
return;
} else
$('passwordStatus').innerHTML = "";
if(newPassword != confirmPassword) {
$('newPasswordStatus').innerHTML = 'Passwords must be the same
';
return;
} else
$('newPasswordStatus').innerHTML ="";
if(newPassword == "") {
$('newPasswordStatus').innerHTML = 'Password cannot be empty
';
return;
} else
$('newPasswordStatus').innerHTML = "";
// Is the current password valid?
rest('user.check.current.password', {'password' : currentPassword}, 'changePasswordConfirm', {'passwordObject' : passwordObject, 'newPasswordObject' : newPasswordObject, 'confirmPasswordObject' : confirmPasswordObject} );
}
function changePasswordConfirm(respString, paramList) {
// Eval this to json
var json = toJson(respString);
// Did the user enter the correct current password?
if(json.valid == false) {
$('passwordStatus').innerHTML = 'Current Password Invalid
';
return;
} else {
$('passwordStatus').innerHTML = '';
// Try to update the password
var currentPassword = paramList.passwordObject.value;
var newPassword = paramList.newPasswordObject.value;
rest('user.update.password', { 'currentpassword' : currentPassword, 'newpassword' : newPassword }, 'changePasswordConfirmFinal', paramList );
}
}
function changePasswordConfirmFinal(respString, paramList) {
// Eval this to json
var json = toJson(respString);
if(!json.error) {
$('passwordStatus').innerHTML = 'Update Complete
';
paramList.passwordObject.value = '';
paramList.newPasswordObject.value = '';
paramList.confirmPasswordObject.value = '';
} else {
$('passwordStatus').innerHTML = '';
$('newPasswordStatus').innerHTML = '' + json.error['description'] + '
';
}
}
/* *********************************************************************************
SITE ADMIN FUNCTIONS
*********************************************************************************
*/
function adminResetPropertyConfirm(respString, paramList) {
alert(respString);
var json = toJson(respString);
if(json.error) {
alert(json.error.description);
} else {
paramList.object.value = json.value;
}
}
function adminResetProperty(object, property) {
rest('admin.get.property', {'property' : property }, 'adminResetPropertyConfirm', {'object' : object});
}
function adminSetPropertyConfirm(respString, paramList) {
var json = toJson(respString);
if(json.error) {
highlight(paramList.object,true);
alert(json.error.description);
adminResetProperty(paramList.object, paramList.property);
} else {
highlight(paramList.object);
if(paramList.forceRefresh)
window.location = window.location;
}
}
function adminSetProperty(property, value, object, forceRefresh) {
var forceRefresh = (forceRefresh) ? true : false;
rest('admin.set.property', {'property' : property, 'value' : value}, 'adminSetPropertyConfirm', {'object' : object, 'property' : property, 'forceRefresh' : forceRefresh});
}
function adminUpdateDictionaryConfirm(respString, paramList) {
var json = toJson(respString);
if(json.error) {
highlight(paramList.object,true);
alert(json.error.description);
} else {
var dispString = json.value.replace(/\\/g, "");
paramList.object.value = dispString;
highlight(paramList.object);
}
}
function adminUpdateDictionary(dict_name, value, object) {
rest('admin.update.dictionary', {'dict_name' : dict_name, 'value' : value}, 'adminUpdateDictionaryConfirm', {'object' : object, 'dict_name' : dict_name});
}
function adminSetLanguageProperty(language_id, property, value, object, forceRefresh) {
var forceRefresh = (forceRefresh) ? true : false;
rest('admin.set.language.property', {'language_id' : language_id, 'property' : property, 'value' : value}, 'adminSetLanguagePropertyConfirm', {'forceRefresh' : forceRefresh, 'object' : object});
}
function adminSetLanguagePropertyConfirm(respString, paramList) {
var json = toJson(respString);
if(json.error) {
alert(json.error.description);
} else {
highlight(paramList.object);
if(paramList.forceRefresh) {
window.location = window.location;
}
}
}
function adminAddLanguage(language_name, language_code_name, rss_codes) {
rest('admin.add.language', {'language_name' : language_name, 'language_code_name' : language_code_name, 'rss_codes' : rss_codes}, 'adminAddLanguageConfirm');
}
function adminAddLanguageConfirm(respString) {
var json = toJson(respString);
if(json.error) {
alert(json.error.description);
} else {
window.location = window.location;
}
}
function adminAddLevelLanguage(cat_level, cat_level_code_name, language_id, cat_level_name, cat_level_name_plural) {
rest('admin.add.level.language', {'cat_level' : cat_level, 'cat_level_code_name' : cat_level_code_name, 'language_id' : language_id, 'cat_level_name' : cat_level_name, 'cat_level_name_plural' : cat_level_name_plural}, 'adminAddLevelLanguageConfirm');
}
function adminAddLevelLanguageConfirm(respString) {
var json = toJson(respString);
if(json.error) {
alert(json.error.description);
} else {
window.location = window.location;
}
}
function adminUpdateLevelLanguage(unique_id, cat_level_name, cat_level_name_plural) {
rest('admin.update.level.language', {'unique_id' : unique_id, 'cat_level_name' : cat_level_name, 'cat_level_name_plural' : cat_level_name_plural}, 'adminUpdateLevelLanguageConfirm');
}
function adminUpdateLevelLanguageConfirm(respString) {
var json = toJson(respString);
if(json.error) {
alert(json.error.description);
} else {
window.location = window.location;
}
}
function adminUpdateLevelCodeName(cat_level, cat_level_code_name) {
rest('admin.update.level.codename', {'cat_level' : cat_level, 'cat_level_code_name' : cat_level_code_name}, 'adminUpdateLevelCodeNameConfirm');
}
function adminUpdateLevelCodeNameConfirm(respString) {
var json = toJson(respString);
if(json.error) {
alert(json.error.description);
} else {
window.location = window.location;
}
}
function adminUpdateCategoryProperty(cat_id, property_name, property_value, language_id, forceRefresh, object) {
var forceRefresh = (forceRefresh) ? true : false;
var object = (object) ? object : null;
rest('admin.update.category.property', {'cat_id' : cat_id, 'property_name' : property_name, 'property_value' : property_value, 'language_id' : language_id}, 'adminUpdateCategoryPropertyConfirm', {'forceRefresh' : forceRefresh, 'object' : object});
}
function adminUpdateCategoryPropertyConfirm(respString, paramList) {
var json = toJson(respString);
if(json.error) {
alert(json.error.description);
} else {
if(paramList.object != null)
highlight(paramList.object);
if(paramList.forceRefresh) {
window.location = window.location;
}
}
}
function mb_length(str) {
var trueLength = 0;
for(var i = 0; i < str.length; i++ )
trueLength += (str.charCodeAt(i) > 127) ? 2 : 1;
return trueLength;
}
function adminAddCategory(cat_level, parent, cat_code_name, cat_values, keywords) {
// this is a little experimental now, might have to change this in the future!
var catvals = 'a:' + cat_values.length + ':{';
for(var i = 0; i < cat_values.length; i++) {
catvals += 'i:' + i + ';a:2:{s:11:"language_id";i:' + cat_values[i][0] + ';s:5:"value";s:' + mb_length(cat_values[i][1]) + ':"' + cat_values[i][1] + '";}';
}
catvals += '}';
rest('admin.add.category', {'cat_level' : cat_level, 'parent' : parent, 'cat_code_name' : cat_code_name, 'cat_values' : catvals, 'keywords' : keywords},'adminAddCategoryConfirm');
}
function adminAddCategoryConfirm(respString) {
var json = toJson(respString);
if(json.error) {
alert(json.error.description);
} else {
alert("Category Added");
window.location = window.location;
}
}
function adminDeleteCategory(cat_id) {
rest('admin.delete.category', {'cat_id' : cat_id},'adminDeleteCategoryConfirm');
}
function adminDeleteCategoryConfirm(respString) {
var json = toJson(respString);
if(json.error) {
alert(json.error.description);
} else {
window.location = window.location;
}
}
function adminUpdateConstant(const_name, language_id, const_value, object) {
rest('admin.update.constant', {'const_name' : const_name, 'language_id' : language_id, 'const_value' : const_value}, 'adminUpdateConstantConfirm',{'object' : object});
}
function adminUpdateConstantConfirm(respString,paramList) {
var json = toJson(respString);
if(json.error) {
alert(json.error.description);
} else {
highlight(paramList.object);
}
}
function adminSaveAllConstants(constantTable, language_id) {
var theEl;
var theForm = $(constantTable);
for(i=0; i -1) ? "" : "expanded";
$('category_' + cat_id).className = className;
if(className == "expanded")
object.src = 'http://news.kiiosk.com/img/icons/minimize.gif';
else
object.src = 'http://news.kiiosk.com/img/icons/maximize.gif';
}
function expandCollapseLeftCol() {
var className = ($('left-col').className == 'maximized') ? 'minimized' : 'maximized';
var rightColClass = (className == "minimized") ? "maximized" : "";
$('left-col').className = className;
$('right-col').className = rightColClass;
setLayoutProperty("layout_leftcol_state", className);
}
function toggleNewsView() {
var className = ($('main-news-display').className == "list-view") ? 'full-view' : 'list-view';
$('main-news-display').className = className;
setLayoutProperty('layout_view_news', className);
// Set all sub elememts to normal if the user has been toggling
var f = $$('div#main-news-display .news-item');
var s = '';
for(var i=0; i -1)
obj.className = "news-item";
else
obj.className = "news-item showhide-override";
}
/* *********************************************************************************
LANGUAGE RELATED FUNCTIONS
*********************************************************************************
*/
/* Function called when the translate link is clicked */
function translatePhraseLink(phrase) {
// Fix up the phrase a little bit
phrase = unescape(phrase.toString());
// Show the form
$('translate-results').style.display="block";
$('translate-result-text').innerHTML = '';
if(phrase != "") {
$('translate-text').value = phrase;
// First try to detect the language
showAjaxWait();
google.language.detect(phrase, detectResult);
return false;
}
}
/* Form submit for translation */
function translateSubmit() {
showAjaxWait();
$('translate-result-text').innerHTML = '';
var phrase = $('translate-text').value;
var langpair = $('langpair');
var pair = langpair.options[langpair.selectedIndex].value.split('|');
var src = pair[0];
var dest = pair[1];
google.language.translate(phrase, src, dest, translateResult);
}
/* Result of the translation call */
function translateResult(result) {
hideAjaxWait();
if(result.translation) {
var resultText = unescape(result.translation);
$('translate-result-text').innerHTML = resultText;
} else
$('translate-result-text').innerHTML = "Error";
}
/* Detects a langauge of a block of text - result */
function detectResult(result) {
hideAjaxWait();
// Did it find the language?
if(result.language){
var src = result.language;
var dest = "";
// Set some defaults
switch(src) {
case "en" :
dest = "es";
break;
default :
dest = "en";
break;
}
// Select this option box
for(var i = 0; i < $('langpair').options.length; i++) {
if($('langpair').options[i].value == (src + "|" + dest)) {
$('langpair').options[i].selected = true;
}
}
// Do an initial translation
translateSubmit();
return false;
}
}
/* *********************************************************************************
LOOKUP API FUNCTIONS
*********************************************************************************
*/
var gSearchObject = null;
function loadSearchBox(query) {
// create a tabbed mode search control
gSearchObject = new GSearchControl();
gSearchObject.addSearcher(new GnewsSearch());
//gSearchObject.addSearcher(new GlocalSearch());
gSearchObject.addSearcher(new GwebSearch());
gSearchObject.addSearcher(new GvideoSearch());
gSearchObject.addSearcher(new GimageSearch());
// draw in tabbed layout mode
var drawOptions = new GdrawOptions();
drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);
gSearchObject.draw(document.getElementById("search_control_tabbed"), drawOptions);
gSearchObject.execute(query);
}
function gSearch(query){
if(gSearchObject != null)
gSearchObject.execute(query);
else {
loadSearchBox(query);
}
hideAjaxWait();
}
function lookupPhrase(phrase) {
// Fix up the phrase a little bit
phrase = unescape(phrase.toString());
showAjaxWait();
// Ok, now lets draw the search
$('lookup-results').style.display="block";
gSearch(phrase);
}
/* *********************************************************************************
FORM RELATED FUNCTIONS
*********************************************************************************
*/
function setFormFieldStatus(divId, displayText, statusType) {
$(divId + 'Status').innerHTML = '' + displayText + '
';
}
function formFieldFocused(formObject, focusedItem, displayText, itemsToClear) {
if(!itemsToClear) itemsToClear = '';
if(itemsToClear == 'all') {
for( var i = 0; i < formObject.length; i++ ) {
fieldObject = formObject[i];
if(fieldObject.type == "text" || fieldObject.type == "password") {
$(fieldObject.name + 'Status').innerHTML = fieldOptional(fieldObject) ? 'Optional' : '';
}
}
} else {
if (itemsToClear != '') {
// Clear the individual items
itemsToClear = itemsToClear.split(',');
for(var i =0; i < itemsToClear.length; i++)
$(itemsToClear[i] + 'Status').innerHTML = '';
}
}
// Set the current item
setFormFieldStatus(focusedItem, displayText, 'focused');
}
function fieldOptional(fieldObject){
if(!fieldObject)
return false;
var fieldClass = fieldObject.className;
if(fieldClass.length == 0)
return false;
if(fieldClass.indexOf("optional")>-1)
return true;
else
return false;
}
function fieldRequired(fieldObject){
if(!fieldObject)
return false;
var fieldClass = fieldObject.className;
if(fieldClass.length == 0)
return false;
if(fieldClass.indexOf("required")>-1)
return true;
else
return false;
}
function validateForm(formObject){
if(!formObject)
return false;
var foundErrors = false;
for( var i = 0; i < formObject.length; i++ ) {
fieldObject = formObject[i];
if(fieldRequired(fieldObject)){
// Check for values
if(fieldObject.value.length == 0) {
foundErrors = true;
fieldObject.className = "text-input-error required";
} else {
fieldObject.className = 'text-input required';
}
}
}
return (foundErrors) ? false : true;
}
/* *********************************************************************************
SITEWIDE FUNCTIONS
*********************************************************************************
*/
/* Flagging an item (comment, profile content, miscatagorized news item, etc) */
function flagItem(item_id, type_id, description) {
rest('flag.item.problem', {'item_id' : item_id, 'type_id' : type_id, 'description' : description}, 'flagItemConfirm');
}
function flagItemConfirm(respString) {
// Eval this to json
var json = toJson(respString);
if(json.error)
$('flag-item-window').innerHTML = '' + json.error.description + '
';
else
$('flag-item-window').innerHTML = 'Thank You
This item has been flagged and will be reviewed shortly
';
}
/* *********************************************************************************
EFFECT FUNCTIONS (Uses scriptaculous framework)
*********************************************************************************
*/
function highlight(element, error) {
if(error) {
e = new Effect.Highlight(element, {startcolor:'#BB0000', endcolor:'#FFFFFF', duration : 1.5});
} else
e = new Effect.Highlight(element, {startcolor:'#4BCC60', endcolor:'#FFFFFF', duration : 1.5});
}
function randomString() {
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = 8;
var randomstring = '';
for (var i=0; i