mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-07-01 05:55:02 +03:00
Добавлен виджет jquery для кнопки подписки на пользователя
This commit is contained in:
parent
f53ae7dc6d
commit
dda259e8a7
|
@ -534,6 +534,7 @@ $config['head']['default']['js'] = array(
|
|||
"___path.application.web___/frontend/common/js/comments.js",
|
||||
"___path.application.web___/frontend/common/js/blog.js",
|
||||
"___path.application.web___/frontend/common/js/user.js",
|
||||
"___path.application.web___/frontend/common/js/user-follow.js",
|
||||
"___path.application.web___/frontend/common/js/feed.js",
|
||||
"___path.application.web___/frontend/common/js/feed-blogs.js",
|
||||
"___path.application.web___/frontend/common/js/activity.js",
|
||||
|
|
79
application/frontend/common/js/user-follow.js
Normal file
79
application/frontend/common/js/user-follow.js
Normal file
|
@ -0,0 +1,79 @@
|
|||
/**
|
||||
* Follow user
|
||||
*
|
||||
* @module ls/user/follow
|
||||
*
|
||||
* @license GNU General Public License, version 2
|
||||
* @copyright 2013 OOO "ЛС-СОФТ" {@link http://livestreetcms.com}
|
||||
* @author Denis Shakhov <denis.shakhov@gmail.com>
|
||||
*/
|
||||
|
||||
(function($) {
|
||||
"use strict";
|
||||
|
||||
$.widget( "livestreet.lsUserFollow", {
|
||||
/**
|
||||
* Дефолтные опции
|
||||
*/
|
||||
options: {
|
||||
// Ссылки
|
||||
urls: {
|
||||
// Подписаться
|
||||
follow: null,
|
||||
|
||||
// Отписаться
|
||||
unfollow: null
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Конструктор
|
||||
*
|
||||
* @constructor
|
||||
* @private
|
||||
*/
|
||||
_create: function () {
|
||||
this._on({ click: this.onClick });
|
||||
},
|
||||
|
||||
/**
|
||||
* Коллбэк вызываемый при клике на кнопку подписки
|
||||
*/
|
||||
onClick: function( event ) {
|
||||
this[ this.element.hasClass( ls.options.classes.states.active ) ? 'unfollow' : 'follow' ]();
|
||||
event.preventDefault();
|
||||
},
|
||||
|
||||
/**
|
||||
* Подписаться
|
||||
*/
|
||||
follow: function() {
|
||||
ls.ajax.load( this.option( 'urls.follow' ), { aUserList: [ this.element.data('login') ] }, function( response ) {
|
||||
this.onFollow( response );
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
/**
|
||||
* Коллбэк вызываемый при подписке
|
||||
*/
|
||||
onFollow: function( response ) {
|
||||
this.element.addClass( ls.options.classes.states.active ).text( ls.lang.get('user.actions.unfollow') );
|
||||
},
|
||||
|
||||
/**
|
||||
* Отписаться
|
||||
*/
|
||||
unfollow: function() {
|
||||
ls.ajax.load( this.option( 'urls.follow' ), { iUserId: [ this.element.data('id') ] }, function( response ) {
|
||||
this.onUnfollow( response );
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
/**
|
||||
* Коллбэк вызываемый при отписке
|
||||
*/
|
||||
onUnfollow: function( response ) {
|
||||
this.element.removeClass( ls.options.classes.states.active ).text( ls.lang.get('user.actions.follow') );
|
||||
}
|
||||
});
|
||||
})(jQuery);
|
|
@ -83,17 +83,12 @@ ls.user = (function ($) {
|
|||
});
|
||||
|
||||
// Добавление пользователя в свою активность
|
||||
$('.js-user-follow').on('click', function (e) {
|
||||
var oElement = $(this);
|
||||
|
||||
if (oElement.hasClass(ls.options.classes.states.active)) {
|
||||
_this.unfollow(oElement, oElement.data('user-id'));
|
||||
} else {
|
||||
_this.follow(oElement, oElement.data('user-login'));
|
||||
$('.js-user-follow').lsUserFollow({
|
||||
urls: {
|
||||
follow: aRouter['stream'] + 'ajaxadduser/',
|
||||
unfollow: aRouter['stream'] + 'ajaxremoveuser/'
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
});
|
||||
})
|
||||
|
||||
// Добавление выбранных пользователей
|
||||
$(document).on('click', '.js-user-list-select-add', function (e) {
|
||||
|
@ -192,24 +187,6 @@ ls.user = (function ($) {
|
|||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Подписка на пользователя
|
||||
*/
|
||||
this.follow = function(oElement, sUserLogin) {
|
||||
ls.ajax.load(this.options.urls.follow, { aUserList: [ sUserLogin ] }, function(oResponse) {
|
||||
oElement.addClass(ls.options.classes.states.active).text( ls.lang.get('user.actions.unfollow') );
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
/**
|
||||
* Отписаться от пользователя
|
||||
*/
|
||||
this.unfollow = function(oElement, iUserId) {
|
||||
ls.ajax.load(this.options.urls.unfollow, { iUserId: iUserId }, function(oResponse) {
|
||||
oElement.removeClass(ls.options.classes.states.active).text( ls.lang.get('user.actions.follow') );
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
/**
|
||||
* Добавляет жалобу
|
||||
*/
|
||||
|
|
|
@ -5,11 +5,19 @@
|
|||
{$user = $smarty.local.user}
|
||||
|
||||
<ul class="profile-actions" id="profile_actions">
|
||||
{* Добавление в друзья *}
|
||||
{include 'components/user/friend_item.tpl' oUserFriend=$user->getUserFriend()}
|
||||
|
||||
<li><a href="{router page='talk'}add/?talk_users={$user->getLogin()}">{lang name='user.actions.send_message'}</a></li>
|
||||
{* Отправить сообщение *}
|
||||
<li>
|
||||
<a href="#" class="js-user-follow {if $user->isFollow()}active{/if}" data-user-id="{$user->getId()}" data-user-login="{$user->getLogin()}">
|
||||
<a href="{router page='talk'}add/?talk_users={$user->getLogin()}">
|
||||
{lang name='user.actions.send_message'}
|
||||
</a>
|
||||
</li>
|
||||
|
||||
{* Подписаться *}
|
||||
<li>
|
||||
<a href="#" class="js-user-follow {if $user->isFollow()}active{/if}" data-id="{$user->getId()}" data-login="{$user->getLogin()}">
|
||||
{if $user->isFollow()}
|
||||
{$aLang.user.actions.unfollow}
|
||||
{else}
|
||||
|
@ -17,6 +25,8 @@
|
|||
{/if}
|
||||
</a>
|
||||
</li>
|
||||
|
||||
{* Пожаловаться *}
|
||||
<li>
|
||||
<a href="#" data-type="modal-toggle" data-modal-url="{router page='profile/ajax-modal-complaint'}" data-param-user_id="{$user->getId()}">{$aLang.user_complaint_title}</a>
|
||||
</li>
|
||||
|
|
Loading…
Reference in a new issue