/* $Id: class_user.js 151 2009-04-01 06:14:22Z nico-izo $ */ // Required language vars: 743-747,773,1113 (status) 759 (delete), 1199 (notifys) // This file will no longer be included by default. A minified version is included as part of core-min.js SocialEngineAPI.User = new Class({ // Properties Base: {}, user_exists : false, user_displayname : false, user_displayname_short : false, user_info : {}, profile_info : {}, level_info : {}, usersetting_info : {}, options : { // Controls ajax request options 'ajaxURL' : 'misc_js.php', 'ajaxMethod' : 'post', 'ajaxSecure' : false, // Display name order method 'displayname_order' : 'standard' }, user_status: '', user_notify_cookie: {}, user_notify_count: 0, // Methods initialize: function() { }, userPhotoFullPath: function() { // No URL class if( !this.Base.URL ) return false; // No user photo if( !this.user_info.user_photo ) return this.Base.URL.url_base + 'images/nophoto.gif'; return this.Base.URL.url_base + this.Base.URL.url_userdir(this.user_info.user_id) + this.user_info.user_photo; }, // Methods - user status userStatusChange: function() { if( !$('ajax_status') ) return false; var userStatus = this.user_status.replace(//g, '').replace(/­/g, ''); var statusHTML = this.user_displayname_short + " " + "
" + "" + this.Base.Language.Translate(746) + " | " + this.Base.Language.Translate(747) + ""; $('ajax_status').innerHTML = statusHTML; $('status_new').focus(); $('status_new').select(); }, userStatusChangeReturn: function() { if( !$('ajax_status') ) return false; if( this.user_status=='' ) { $('ajax_status').innerHTML = "" + this.Base.Language.Translate(743) + ""; } else { $('ajax_status').innerHTML = "
" + this.user_displayname_short + " " + this.user_status + "
" + "
" + "
" + "[ " + this.Base.Language.Translate(745) + " ]" + "
" + "
" + "" + this.Base.Language.Translate(1113) + " " + this.Base.Language.TranslateFormatted(773, [1]) + "" + "
" + "
" + "
" + "
"; } }, userStatusChangeSubmit: function() { if( !$('ajax_status') ) return false; var bind = this; var request = new Request.JSON({ 'url' : this.options.ajaxURL, 'method' : this.options.ajaxMethod, 'secure' : this.options.ajaxSecure, 'data' : { 'task' : 'status_change', 'status' : $('status_new').value }, 'onComplete' : function(responseObject, responseText) { bind.user_status = responseObject.status; bind.userStatusChangeReturn(); } }).send(); }, // Methods - user status userDelete: function() { TB_show(this.Base.Language.Translate(759), '#TB_inline?height=100&width=300&inlineId=confirmdelete', '', '../images/trans.gif'); }, userDeleteConfirm: function(delete_token) { var bind = this; var request = new Request.JSON({ 'url' : 'user_account_delete.php', 'method' : this.options.ajaxMethod, 'secure' : this.options.ajaxSecure, 'data' : { 'task' : 'dodelete', 'token' : delete_token }, 'onComplete' : function(responseObject, responseText) { window.location = 'home.php'; } }).send(); }, // Methods - actions userActionDelete: function(action_id) { var bind = this; var request = new Request.JSON({ 'url' : this.options.ajaxURL, 'method' : this.options.ajaxMethod, 'secure' : this.options.ajaxSecure, 'data' : { 'task' : 'action_delete', 'action_id' : action_id }, 'onComplete' : function(responseObject, responseText) { if( $('action_' + action_id) ) { $('action_' + action_id).style.display = 'none'; total_actions--; if( total_actions == 0 ) $('actions').style.display = "none"; } } }).send(); }, // Methods - notifications userNotifyShow: function() { this.user_notify_cookie = new Hash.Cookie('se_show_newupdates', {duration: 3600}); var minimizedCount = parseInt(this.user_notify_cookie.get('total')); if( !$type(minimizedCount) ) minimizedCount = 0; if( minimizedCount < this.user_notify_count ) { this.user_notify_cookie.set('total', 0); $('newupdates').style.display = 'block'; $('newupdates').fade('in'); } }, userNotifyPopup: function() { TB_show(this.Base.Language.Translate(1198), '#TB_inline?height=150&width=300&inlineId=newupdates_popup', '', './images/trans.gif'); }, userNotifyUpdate: function() { var bind = this; var request = new Request.JSON({ 'url' : this.options.ajaxURL, 'method' : this.options.ajaxMethod, 'secure' : this.options.ajaxSecure, 'data' : { 'task' : 'notify_get' }, 'onComplete' : function(responseObject, responseText) { bind.userNotifyGenerate(responseObject); bind.userNotifyShow(); } }).send(); }, userNotifyGenerate: function(notifyData) { if( !$type(notifyData.notifys) || notifyData.notifys.length==0 || !$('newupdates_popup') ) { $('notify_total').innerHTML = this.user_notify_count = 0; return; } // Update count in red box $('notify_total').innerHTML = this.user_notify_count = notifyData.total; // Update popup contents var HTML = "
" + this.Base.Language.TranslateFormatted(1199, ["" + notifyData.total_grouped + ""]) + "
"; notifyData.notifys.each(function(notify_info) { HTML += "
" + "X" + "" + "" + notify_info.notify_text_output + "" + "
"; }); $('newupdates_popup').innerHTML = HTML; }, userNotifyDelete: function(notifytype_id, notify_grouped) { var bind = this; var request = new Request.JSON({ 'url' : this.options.ajaxURL, 'method' : this.options.ajaxMethod, 'secure' : this.options.ajaxSecure, 'data' : { 'task' : 'notify_delete', 'notifytype_id' : notifytype_id, 'notify_grouped' : notify_grouped }, 'onComplete' : function(responseObject, responseText) { $("TB_window").getElements('div[id=notify_'+notifytype_id+'_'+notify_grouped+']').each(function(el) { if(el.id == 'notify_'+notifytype_id+'_'+notify_grouped) { el.style.display = 'none'; bind.user_notify_count--; } }); $('newupdates_popup').getElements('div[id=notify_'+notifytype_id+'_'+notify_grouped+']').each(function(el) { if(el.id == 'notify_'+notifytype_id+'_'+notify_grouped) el.style.display = 'none'; }); $('notify_total').innerHTML = bind.user_notify_count; $("TB_window").getElements('span[id=notifyscount]').each(function(el) { if(el.id == 'notifyscount') el.innerHTML = bind.user_notify_count; }); if( bind.user_notify_count == 0 ) { TB_remove(); $('newupdates').style.display = 'none'; } } }).send(); }, userNotifyHide: function() { $('newupdates').fade('out'); this.user_notify_cookie.set('total', this.user_notify_count) }, userPhotoRemove: function() { var bind = this; var request = new Request.JSON({ 'url' : 'user_editprofile_photo.php', 'method' : this.options.ajaxMethod, 'secure' : this.options.ajaxSecure, 'data' : { 'task' : 'remove' } }).send(); if( $('userEditRemovePhotoLink' ) && $('userEditPhotoImg') ) { $('userEditRemovePhotoLink' ).destroy(); $('userEditPhotoImg' ).src = 'images/nophoto.gif'; } else { window.location.reload( false ); } }, // Import methods ImportUserInfo: function(user_info) { // Handle anonymous users if( !user_info || $type(user_info)!="object" || !user_info.user_exists ) { this.user_exists = false; return; } this.user_exists = true; // Prepare data user_info.user_id = parseInt(user_info.user_id); delete user_info.user_exists; // Save user info this.user_info = user_info; // Generate display name this.user_info.user_fname = this.user_info.user_fname.trim(); this.user_info.user_lname = this.user_info.user_lname.trim(); if( this.user_info.user_fname && this.user_info.user_lname ) { // Asian if( this.options.displayname_order=="asian" ) { this.user_displayname_short = this.user_info.user_lname; this.user_displayname = this.user_info.user_lname + ' ' + this.user_info.user_fname; } // Standard else { this.user_displayname_short = this.user_info.user_fname; this.user_displayname = this.user_info.user_fname + ' ' + this.user_info.user_lname; } } else if( this.user_info.user_fname ) { this.user_displayname = this.user_displayname_short = this.user_info.user_fname; } else if( this.user_info.user_lname ) { this.user_displayname = this.user_displayname_short = this.user_info.user_lname; } else if( this.user_info.user_username ) { this.user_displayname = this.user_displayname_short = this.user_info.user_username; } } });