1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-07-05 16:04:24 +03:00
ifhub.club/engine/lib/internal/template/js/user.js

519 lines
14 KiB
JavaScript
Raw Normal View History

2011-05-03 11:22:13 +03:00
var ls = ls || {};
/**
* Управление пользователями
*/
ls.user = (function ($) {
this.jcropAvatar=null;
this.jcropFoto=null;
2011-05-03 11:22:13 +03:00
/**
* Добавление в друзья
*/
this.addFriend = function(obj, idUser, sAction){
if(sAction != 'link' && sAction != 'accept') {
2012-01-28 17:52:44 +02:00
var sText = $('#add_friend_text').val();
2011-05-03 11:22:13 +03:00
$('#add_friend_form').children().each(function(i, item){$(item).attr('disabled','disabled')});
} else {
2012-01-28 17:52:44 +02:00
var sText='';
2011-04-01 10:49:36 +03:00
}
2011-05-03 11:22:13 +03:00
if(sAction == 'accept') {
2012-01-28 17:52:44 +02:00
var url = aRouter.profile+'ajaxfriendaccept/';
2011-05-03 11:22:13 +03:00
} else {
2012-01-28 17:52:44 +02:00
var url = aRouter.profile+'ajaxfriendadd/';
2011-04-01 10:49:36 +03:00
}
2012-06-13 11:46:40 +03:00
2012-01-28 17:52:44 +02:00
var params = {idUser: idUser, userText: sText};
2012-06-13 11:46:40 +03:00
2012-04-28 18:40:06 +03:00
ls.hook.marker('addFriendBefore');
2012-01-28 17:52:44 +02:00
ls.ajax(url, params, function(result){
2011-05-03 11:22:13 +03:00
$('#add_friend_form').children().each(function(i, item){$(item).removeAttr('disabled')});
if (!result) {
ls.msg.error('Error','Please try again later');
}
if (result.bStateError) {
ls.msg.error(null,result.sMsg);
} else {
ls.msg.notice(null,result.sMsg);
$('#add_friend_form').jqmHide();
$('#add_friend_item').remove();
$('#profile_actions').prepend($(result.sToggleText));
ls.hook.run('ls_user_add_friend_after', [idUser,sAction,result], obj);
2011-05-03 11:22:13 +03:00
}
});
return false;
};
/**
* Удаление из друзей
*/
this.removeFriend = function(obj,idUser,sAction) {
2012-01-28 17:52:44 +02:00
var url = aRouter.profile+'ajaxfrienddelete/';
var params = {idUser: idUser,sAction: sAction};
2012-06-13 11:46:40 +03:00
2012-04-28 18:40:06 +03:00
ls.hook.marker('removeFriendBefore');
2012-01-28 17:52:44 +02:00
ls.ajax(url, params, function(result) {
2011-05-03 11:22:13 +03:00
if (result.bStateError) {
ls.msg.error(null,result.sMsg);
} else {
ls.msg.notice(null,result.sMsg);
$('#delete_friend_item').remove();
$('#profile_actions').prepend($(result.sToggleText));
ls.hook.run('ls_user_remove_friend_after', [idUser,sAction,result], obj);
}
});
return false;
};
/**
* Загрузка временной аватарки
* @param form
* @param input
*/
this.uploadAvatar = function(form,input) {
if (!form && input) {
var form = $('<form method="post" enctype="multipart/form-data"></form>').css({
'display': 'none'
}).appendTo('body');
2012-04-08 01:21:23 +03:00
var clone=input.clone(true);
input.hide();
clone.insertAfter(input);
input.appendTo(form);
}
ls.ajaxSubmit(aRouter['settings']+'profile/upload-avatar/',form,function(data){
if (data.bStateError) {
ls.msg.error(data.sMsgTitle,data.sMsg);
} else {
this.showResizeAvatar(data.sTmpFile);
}
}.bind(this));
};
/**
* Показывает форму для ресайза аватарки
* @param sImgFile
*/
this.showResizeAvatar = function(sImgFile) {
if (this.jcropAvatar) {
this.jcropAvatar.destroy();
}
$('#avatar-resize-original-img').attr('src',sImgFile+'?'+Math.random());
$('#avatar-resize').jqmShow();
var $this=this;
$('#avatar-resize-original-img').Jcrop({
aspectRatio: 1,
minSize: [32,32]
},function(){
$this.jcropAvatar=this;
});
};
/**
* Выполняет ресайз аватарки
*/
this.resizeAvatar = function() {
if (!this.jcropAvatar) {
return false;
}
var url = aRouter.settings+'profile/resize-avatar/';
var params = {size: this.jcropAvatar.tellSelect()};
2012-04-28 18:40:06 +03:00
ls.hook.marker('resizeAvatarBefore');
ls.ajax(url, params, function(result) {
if (result.bStateError) {
ls.msg.error(null,result.sMsg);
} else {
$('#avatar-img').attr('src',result.sFile+'?'+Math.random());
$('#avatar-resize').jqmHide();
$('#avatar-remove').show();
$('#avatar-upload').text(result.sTitleUpload);
ls.hook.run('ls_user_resize_avatar_after', [params, result]);
2011-05-03 11:22:13 +03:00
}
});
2011-05-03 11:22:13 +03:00
return false;
};
/**
* Удаление аватарки
*/
this.removeAvatar = function() {
var url = aRouter.settings+'profile/remove-avatar/';
var params = {};
2012-04-28 18:40:06 +03:00
ls.hook.marker('removeAvatarBefore');
ls.ajax(url, params, function(result) {
if (result.bStateError) {
ls.msg.error(null,result.sMsg);
} else {
$('#avatar-img').attr('src',result.sFile+'?'+Math.random());
$('#avatar-remove').hide();
$('#avatar-upload').text(result.sTitleUpload);
ls.hook.run('ls_user_remove_avatar_after', [params, result]);
}
});
return false;
};
/**
* Отмена ресайза аватарки, подчищаем временный данные
*/
this.cancelAvatar = function() {
var url = aRouter.settings+'profile/cancel-avatar/';
var params = {};
2012-04-28 18:40:06 +03:00
ls.hook.marker('cancelAvatarBefore');
ls.ajax(url, params, function(result) {
if (result.bStateError) {
ls.msg.error(null,result.sMsg);
} else {
$('#avatar-resize').jqmHide();
ls.hook.run('ls_user_cancel_avatar_after', [params, result]);
}
});
return false;
};
/**
* Загрузка временной фотки
* @param form
* @param input
*/
this.uploadFoto = function(form,input) {
if (!form && input) {
var form = $('<form method="post" enctype="multipart/form-data"></form>').css({
'display': 'none'
}).appendTo('body');
2012-04-08 01:21:23 +03:00
var clone=input.clone(true);
input.hide();
clone.insertAfter(input);
input.appendTo(form);
}
ls.ajaxSubmit(aRouter['settings']+'profile/upload-foto/',form,function(data){
if (data.bStateError) {
ls.msg.error(data.sMsgTitle,data.sMsg);
} else {
this.showResizeFoto(data.sTmpFile);
}
}.bind(this));
};
/**
* Показывает форму для ресайза фотки
* @param sImgFile
*/
this.showResizeFoto = function(sImgFile) {
if (this.jcropFoto) {
this.jcropFoto.destroy();
}
$('#foto-resize-original-img').attr('src',sImgFile+'?'+Math.random());
$('#foto-resize').jqmShow();
var $this=this;
$('#foto-resize-original-img').Jcrop({
minSize: [32,32]
},function(){
$this.jcropFoto=this;
});
};
/**
* Выполняет ресайз фотки
*/
this.resizeFoto = function() {
if (!this.jcropFoto) {
return false;
}
var url = aRouter.settings+'profile/resize-foto/';
var params = {size: this.jcropFoto.tellSelect()};
2012-04-28 18:40:06 +03:00
ls.hook.marker('resizeFotoBefore');
ls.ajax(url, params, function(result) {
if (result.bStateError) {
ls.msg.error(null,result.sMsg);
} else {
$('#foto-img').attr('src',result.sFile+'?'+Math.random());
$('#foto-resize').jqmHide();
$('#foto-remove').show();
$('#foto-upload').text(result.sTitleUpload);
ls.hook.run('ls_user_resize_foto_after', [params, result]);
}
});
return false;
};
/**
* Удаление фотки
*/
this.removeFoto = function() {
var url = aRouter.settings+'profile/remove-foto/';
var params = {};
2012-04-28 18:40:06 +03:00
ls.hook.marker('removeFotoBefore');
ls.ajax(url, params, function(result) {
if (result.bStateError) {
ls.msg.error(null,result.sMsg);
} else {
$('#foto-img').attr('src',result.sFile+'?'+Math.random());
$('#foto-remove').hide();
$('#foto-upload').text(result.sTitleUpload);
ls.hook.run('ls_user_remove_foto_after', [params, result]);
}
});
return false;
};
/**
* Отмена ресайза фотки, подчищаем временный данные
*/
this.cancelFoto = function() {
var url = aRouter.settings+'profile/cancel-foto/';
var params = {};
2012-04-28 18:40:06 +03:00
ls.hook.marker('cancelFotoBefore');
ls.ajax(url, params, function(result) {
if (result.bStateError) {
ls.msg.error(null,result.sMsg);
} else {
$('#foto-resize').jqmHide();
ls.hook.run('ls_user_cancel_foto_after', [params, result]);
}
});
return false;
};
/**
* Валидация полей формы при регистрации
* @param aFields
*/
2012-04-05 11:52:13 +03:00
this.validateRegistrationFields = function(aFields,sForm) {
var url = aRouter.registration+'ajax-validate-fields/';
var params = {fields: aFields};
2012-04-05 11:52:13 +03:00
if (typeof(sForm)=='string') {
sForm=$('#'+sForm);
}
2012-04-28 18:40:06 +03:00
ls.hook.marker('validateRegistrationFieldsBefore');
ls.ajax(url, params, function(result) {
2012-04-05 11:52:13 +03:00
if (!sForm) {
sForm=$('body'); // поиск полей по всей странице
}
$.each(aFields,function(i,aField){
if (result.aErrors && result.aErrors[aField.field][0]) {
2012-04-05 11:52:13 +03:00
sForm.find('.validate-error-field-'+aField.field).removeClass('validate-error-hide').addClass('validate-error-show').text(result.aErrors[aField.field][0]);
sForm.find('.validate-ok-field-'+aField.field).hide();
} else {
2012-04-05 11:52:13 +03:00
sForm.find('.validate-error-field-'+aField.field).removeClass('validate-error-show').addClass('validate-error-hide');
sForm.find('.validate-ok-field-'+aField.field).show();
}
});
2012-04-05 11:52:13 +03:00
ls.hook.run('ls_user_validate_registration_fields_after', [aFields, sForm, result]);
});
};
/**
* Валидация конкретного поля формы
* @param sField
* @param sValue
* @param aParams
*/
2012-04-05 11:52:13 +03:00
this.validateRegistrationField = function(sField,sValue,sForm,aParams) {
var aFields=[];
aFields.push({field: sField, value: sValue, params: aParams || {}});
2012-04-05 11:52:13 +03:00
this.validateRegistrationFields(aFields,sForm);
};
/**
* Ajax регистрация пользователя с проверкой полей формы
* @param form
*/
this.registration = function(form) {
var url = aRouter.registration+'ajax-registration/';
2012-04-28 18:40:06 +03:00
ls.hook.marker('registrationBefore');
ls.ajaxSubmit(url, form, function(result) {
if (result.bStateError) {
ls.msg.error(null,result.sMsg);
} else {
if (typeof(form)=='string') {
form=$('#'+form);
}
form.find('.validate-error-show').removeClass('validate-error-show').addClass('validate-error-hide');
if (result.aErrors) {
$.each(result.aErrors,function(sField,aErrors){
if (aErrors[0]) {
2012-04-05 11:52:13 +03:00
form.find('.validate-error-field-'+sField).removeClass('validate-error-hide').addClass('validate-error-show').text(aErrors[0]);
}
});
} else {
if (result.sMsg) {
ls.msg.notice(null,result.sMsg);
}
if (result.sUrlRedirect) {
window.location=result.sUrlRedirect;
}
}
ls.hook.run('ls_user_registration_after', [form, result]);
}
});
};
2012-04-05 13:15:33 +03:00
/**
* Ajax авторизация пользователя с проверкой полей формы
* @param form
*/
this.login = function(form) {
var url = aRouter.login+'ajax-login/';
2012-04-28 18:40:06 +03:00
ls.hook.marker('loginBefore');
2012-04-05 13:15:33 +03:00
ls.ajaxSubmit(url, form, function(result) {
if (typeof(form)=='string') {
form=$('#'+form);
}
form.find('.validate-error-show').removeClass('validate-error-show').addClass('validate-error-hide');
if (result.bStateError) {
form.find('.validate-error-login').removeClass('validate-error-hide').addClass('validate-error-show').text(result.sMsg);
} else {
if (result.sMsg) {
ls.msg.notice(null,result.sMsg);
}
if (result.sUrlRedirect) {
window.location=result.sUrlRedirect;
}
ls.hook.run('ls_user_login_after', [form, result]);
}
});
};
/**
* Ajax запрос на смену пароля
* @param form
*/
this.reminder = function(form) {
var url = aRouter.login+'ajax-reminder/';
2012-04-28 18:40:06 +03:00
ls.hook.marker('reminderBefore');
ls.ajaxSubmit(url, form, function(result) {
if (typeof(form)=='string') {
form=$('#'+form);
}
form.find('.validate-error-show').removeClass('validate-error-show').addClass('validate-error-hide');
if (result.bStateError) {
form.find('.validate-error-reminder').removeClass('validate-error-hide').addClass('validate-error-show').text(result.sMsg);
} else {
form.find('input').val('');
if (result.sMsg) {
ls.msg.notice(null,result.sMsg);
}
if (result.sUrlRedirect) {
window.location=result.sUrlRedirect;
}
ls.hook.run('ls_user_reminder_after', [form, result]);
}
});
};
2012-06-13 11:46:40 +03:00
/**
* Ajax запрос на ссылку активации
* @param form
*/
this.reminder = function(form) {
var url = aRouter.login+'ajax-reactivation/';
ls.hook.marker('reactivationBefore');
ls.ajaxSubmit(url, form, function(result) {
if (typeof(form)=='string') {
form=$('#'+form);
}
form.find('.validate-error-show').removeClass('validate-error-show').addClass('validate-error-hide');
if (result.bStateError) {
form.find('.validate-error-reactivation').removeClass('validate-error-hide').addClass('validate-error-show').text(result.sMsg);
} else {
form.find('input').val('');
if (result.sMsg) {
ls.msg.notice(null,result.sMsg);
}
if (result.sUrlRedirect) {
window.location=result.sUrlRedirect;
}
ls.hook.run('ls_user_reactivation_after', [form, result]);
}
});
};
/**
* Поиск пользователей
*/
this.searchUsers = function(form) {
var url = aRouter['people']+'ajax-search/';
2012-04-14 12:35:26 +03:00
var inputSearch=$('#'+form).find('input');
inputSearch.addClass('loader');
2012-04-28 18:40:06 +03:00
ls.hook.marker('searchUsersBefore');
ls.ajaxSubmit(url, form, function(result){
2012-04-14 12:35:26 +03:00
inputSearch.removeClass('loader');
if (result.bStateError) {
$('#users-list-search').hide();
$('#users-list-original').show();
} else {
$('#users-list-original').hide();
$('#users-list-search').html(result.sText).show();
ls.hook.run('ls_user_search_users_after',[form, result]);
}
});
};
/**
* Поиск пользователей по началу логина
*/
this.searchUsersByPrefix = function(sPrefix,obj) {
obj=$(obj);
var url = aRouter['people']+'ajax-search/';
var params = {user_login: sPrefix, isPrefix: 1};
2012-04-14 12:35:26 +03:00
$('#search-user-login').addClass('loader');
2012-04-28 18:40:06 +03:00
ls.hook.marker('searchUsersByPrefixBefore');
ls.ajax(url, params, function(result){
2012-04-14 12:35:26 +03:00
$('#search-user-login').removeClass('loader');
$('#user-prefix-filter').find('.active').removeClass('active');
obj.parent().addClass('active');
if (result.bStateError) {
$('#users-list-search').hide();
$('#users-list-original').show();
} else {
$('#users-list-original').hide();
$('#users-list-search').html(result.sText).show();
ls.hook.run('ls_user_search_users_by_prefix_after',[sPrefix, obj, result]);
}
});
return false;
};
/**
* Подписка
*/
this.followToggle = function(obj, iUserId) {
2012-06-13 11:46:40 +03:00
if ($(obj).hasClass('followed')) {
ls.stream.unsubscribe(iUserId);
$(obj).toggleClass('followed').text(ls.lang.get('profile_user_follow'));
2012-06-13 11:46:40 +03:00
} else {
ls.stream.subscribe(iUserId);
$(obj).toggleClass('followed').text(ls.lang.get('profile_user_unfollow'));
2012-06-13 11:46:40 +03:00
}
return false;
};
2011-05-03 11:22:13 +03:00
return this;
}).call(ls.user || {},jQuery);