1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-06-26 03:30:48 +03:00

Универсальный блок подгрузки контента

This commit is contained in:
Denis Shakhov 2014-03-04 15:32:38 +07:00
parent 9d372bee46
commit 9c2a8568db
21 changed files with 378 additions and 339 deletions

View file

@ -186,6 +186,7 @@ class ActionProfile extends Action {
if (count($aEvents)) {
$oEvenLast=end($aEvents);
$this->Viewer_Assign('iStreamLastId', $oEvenLast->getId());
$this->Viewer_Assign('sDateLast', $oEvenLast->getDateAdded());
}
$this->SetTemplateAction('activity');
}
@ -486,9 +487,17 @@ class ActionProfile extends Action {
/**
* Получаем записи стены
*/
$aWall=$this->Wall_GetWall(array('wall_user_id'=>$this->oUserProfile->getId(),'pid'=>null),array('id'=>'desc'),1,Config::Get('module.wall.per_page'));
$this->Viewer_Assign('aWall',$aWall['collection']);
$aWall = $this->Wall_GetWall(array('wall_user_id'=>$this->oUserProfile->getId(),'pid'=>null),array('id'=>'desc'),1,Config::Get('module.wall.per_page'));
$aPosts = $aWall['collection'];
$this->Viewer_Assign('aWall', $aPosts);
$this->Viewer_Assign('iCountWall',$aWall['count']);
if (count($aPosts)) {
$oPostLast = end($aPosts);
$this->Viewer_Assign('iWallLastId', $oPostLast->getId());
}
/**
* Устанавливаем шаблон вывода
*/
@ -582,80 +591,92 @@ class ActionProfile extends Action {
}
return $this->EventErrorDebug();
}
/**
* Ajax подгрузка сообщений стены
*/
public function EventWallLoad() {
/**
* Устанавливаем формат Ajax ответа
*/
// Устанавливаем формат Ajax ответа
$this->Viewer_SetResponseAjax('json');
if (!$this->CheckUserProfile()) {
// Валидация
if ( ! $this->CheckUserProfile() ) {
return $this->EventErrorDebug();
}
/**
* Формируем фильтр для запроса к БД
*/
$aFilter=array(
'wall_user_id'=>$this->oUserProfile->getId(),
'pid'=>null
// Формируем фильтр для запроса к БД
$aFilter = array(
'wall_user_id' => $this->oUserProfile->getId(),
'pid' => null
);
if (is_numeric(getRequest('iIdLess'))) {
$aFilter['id_less']=getRequest('iIdLess');
} elseif (is_numeric(getRequest('iIdMore'))) {
$aFilter['id_more']=getRequest('iIdMore');
if ( is_numeric(getRequest('iLastId')) ) {
$aFilter['id_less'] = getRequest('iLastId');
} else if ( is_numeric(getRequest('iFirstId')) ) {
$aFilter['id_more'] = getRequest('iFirstId');
} else {
$this->Message_AddError($this->Lang_Get('error'));
return;
return $this->EventErrorDebug();
}
// Получаем сообщения и формируем ответ
$aWall = $this->Wall_GetWall($aFilter, array('id' => 'desc'), 1, Config::Get('module.wall.per_page'));
$this->Viewer_Assign('aWall', $aWall['collection']);
$this->Viewer_Assign('oUserCurrent', $this->oUserCurrent); // хак, т.к. к этому моменту текущий юзер не загружен в шаблон
$this->Viewer_AssignAjax('sHtml', $this->Viewer_Fetch('actions/ActionProfile/wall.posts.tpl'));
$this->Viewer_AssignAjax('iCountLoaded', count($aWall['collection']));
if (count($aWall['collection'])) {
$this->Viewer_AssignAjax('iLastId', end($aWall['collection'])->getId());
}
/**
* Получаем сообщения и формируем ответ
*/
$aWall=$this->Wall_GetWall($aFilter,array('id'=>'desc'),1,Config::Get('module.wall.per_page'));
$this->Viewer_Assign('aWall',$aWall['collection']);
$this->Viewer_Assign('oUserCurrent',$this->oUserCurrent); // хак, т.к. к этому моменту текущий юзер не загружен в шаблон
$this->Viewer_AssignAjax('sText', $this->Viewer_Fetch('actions/ActionProfile/wall.posts.tpl'));
$this->Viewer_AssignAjax('iCountWall',$aWall['count']);
$this->Viewer_AssignAjax('iCountWallReturn',count($aWall['collection']));
}
/**
* Подгрузка ответов на стене к сообщению
*/
public function EventWallLoadReply() {
/**
* Устанавливаем формат Ajax ответа
*/
// Устанавливаем формат Ajax ответа
$this->Viewer_SetResponseAjax('json');
if (!$this->CheckUserProfile()) {
// Валидация
if ( ! $this->CheckUserProfile() ) {
return $this->EventErrorDebug();
}
if (!($oWall=$this->Wall_GetWallById(getRequestStr('iPid'))) or $oWall->getPid()) {
if ( ! ($oWall = $this->Wall_GetWallById(getRequestStr('iTargetId'))) or $oWall->getPid() ) {
return $this->EventErrorDebug();
}
/**
* Формируем фильтр для запроса к БД
*/
$aFilter=array(
'wall_user_id'=>$this->oUserProfile->getId(),
'pid'=>$oWall->getId()
// Формируем фильтр для запроса к БД
$aFilter = array(
'wall_user_id' => $this->oUserProfile->getId(),
'pid' => $oWall->getId()
);
if (is_numeric(getRequest('iIdLess'))) {
$aFilter['id_less']=getRequest('iIdLess');
} elseif (is_numeric(getRequest('iIdMore'))) {
$aFilter['id_more']=getRequest('iIdMore');
if ( is_numeric(getRequest('iLastId')) ) {
$aFilter['id_less'] = getRequest('iLastId');
} else if ( is_numeric(getRequest('iFirstId')) ) {
$aFilter['id_more'] = getRequest('iFirstId');
} else {
return $this->EventErrorDebug();
}
/**
* Получаем сообщения и формируем ответ
* Необходимо вернуть все ответы, но ставим "разумное" ограничение
*/
$aWall=$this->Wall_GetWall($aFilter,array('id'=>'asc'),1,300);
$this->Viewer_Assign('aReplyWall',$aWall['collection']);
$this->Viewer_AssignAjax('sText', $this->Viewer_Fetch('actions/ActionProfile/wall.comments.tpl'));
$this->Viewer_AssignAjax('iCountWall',$aWall['count']);
$this->Viewer_AssignAjax('iCountWallReturn',count($aWall['collection']));
// Получаем сообщения и формируем ответ
// Необходимо вернуть все ответы, но ставим "разумное" ограничение
$aWall = $this->Wall_GetWall($aFilter, array('id' => 'asc'), 1, 300);
// Передаем переменные
$this->Viewer_Assign('aReplyWall', $aWall['collection']);
$this->Viewer_AssignAjax('sHtml', $this->Viewer_Fetch('actions/ActionProfile/wall.comments.tpl'));
$this->Viewer_AssignAjax('iCountLoaded', count($aWall['collection']));
if (count($aWall['collection'])) {
$this->Viewer_AssignAjax('iLastId', end($aWall['collection'])->getId());
}
}
/**
* Сохраняет заметку о пользователе
*/

View file

@ -70,7 +70,7 @@ class ActionStream extends Action {
$this->AddEvent('ajaxadduser', 'EventAjaxAddUser');
$this->AddEvent('ajaxremoveuser', 'EventAjaxRemoveUser');
$this->AddEvent('switchEventType', 'EventSwitchEventType');
$this->AddEvent('get_more', 'EventGetMore');
$this->AddEvent('get_more_custom', 'EventGetMore');
$this->AddEvent('get_more_user', 'EventGetMoreUser');
$this->AddEvent('get_more_all', 'EventGetMoreAll');
}
@ -88,7 +88,7 @@ class ActionStream extends Action {
}
$this->Viewer_AddBlock('right','activitySettings');
$this->Viewer_AddBlock('right','activityUsers');
/**
* Читаем события
*/
@ -98,6 +98,7 @@ class ActionStream extends Action {
if (count($aEvents)) {
$oEvenLast=end($aEvents);
$this->Viewer_Assign('iStreamLastId', $oEvenLast->getId());
$this->Viewer_Assign('sDateLast', $oEvenLast->getDateAdded());
}
}
/**
@ -115,6 +116,7 @@ class ActionStream extends Action {
if (count($aEvents)) {
$oEvenLast=end($aEvents);
$this->Viewer_Assign('iStreamLastId', $oEvenLast->getId());
$this->Viewer_Assign('sDateLast', $oEvenLast->getDateAdded());
}
}
/**
@ -172,15 +174,16 @@ class ActionStream extends Action {
$oViewer=$this->Viewer_GetLocalViewer();
$oViewer->Assign('aStreamEvents', $aEvents);
$oViewer->Assign('sDateLast', getRequestStr('sDateLast'));
$this->Viewer_AssignAjax('iCountLoaded', count($aEvents));
if (count($aEvents)) {
$oEvenLast=end($aEvents);
$this->Viewer_AssignAjax('iStreamLastId', $oEvenLast->getId());
$this->Viewer_AssignAjax('iLastId', $oEvenLast->getId());
}
/**
* Возвращаем данные в ajax ответе
*/
$this->Viewer_AssignAjax('result', $oViewer->Fetch('actions/ActionStream/events.tpl'));
$this->Viewer_AssignAjax('events_count', count($aEvents));
$this->Viewer_AssignAjax('sHtml', $oViewer->Fetch('actions/ActionStream/events.tpl'));
}
/**
* Погрузка событий для всего сайта
@ -207,15 +210,17 @@ class ActionStream extends Action {
$oViewer=$this->Viewer_GetLocalViewer();
$oViewer->Assign('aStreamEvents', $aEvents);
$oViewer->Assign('sDateLast', getRequestStr('sDateLast'));
$this->Viewer_AssignAjax('iCountLoaded', count($aEvents));
if (count($aEvents)) {
$oEvenLast=end($aEvents);
$this->Viewer_AssignAjax('iStreamLastId', $oEvenLast->getId());
$this->Viewer_AssignAjax('sDateLast', $oEvenLast->getDateAdded());
$this->Viewer_AssignAjax('iLastId', $oEvenLast->getId());
}
/**
* Возвращаем данные в ajax ответе
*/
$this->Viewer_AssignAjax('result', $oViewer->Fetch('actions/ActionStream/events.tpl'));
$this->Viewer_AssignAjax('events_count', count($aEvents));
$this->Viewer_AssignAjax('sHtml', $oViewer->Fetch('actions/ActionStream/events.tpl'));
}
/**
* Подгрузка событий для пользователя
@ -234,7 +239,7 @@ class ActionStream extends Action {
$this->Message_AddError($this->Lang_Get('system_error'),$this->Lang_Get('error'));
return;
}
if (!($oUser=$this->User_GetUserById(getRequestStr('iUserId')))) {
if (!($oUser=$this->User_GetUserById(getRequestStr('iTargetId')))) {
$this->Message_AddError($this->Lang_Get('system_error'),$this->Lang_Get('error'));
return;
}
@ -246,15 +251,17 @@ class ActionStream extends Action {
$oViewer=$this->Viewer_GetLocalViewer();
$oViewer->Assign('aStreamEvents', $aEvents);
$oViewer->Assign('sDateLast', getRequestStr('sDateLast'));
$this->Viewer_AssignAjax('iCountLoaded', count($aEvents));
if (count($aEvents)) {
$oEvenLast=end($aEvents);
$this->Viewer_AssignAjax('iStreamLastId', $oEvenLast->getId());
$this->Viewer_AssignAjax('sDateLast', $oEvenLast->getDateAdded());
$this->Viewer_AssignAjax('iLastId', $oEvenLast->getId());
}
/**
* Возвращаем данные в ajax ответе
*/
$this->Viewer_AssignAjax('result', $oViewer->Fetch('actions/ActionStream/events.tpl'));
$this->Viewer_AssignAjax('events_count', count($aEvents));
$this->Viewer_AssignAjax('sHtml', $oViewer->Fetch('actions/ActionStream/events.tpl'));
}
/**
* Подписка на пользователя по ID

View file

@ -92,7 +92,7 @@ class ActionUserfeed extends Action {
/**
* Проверяем последний просмотренный ID топика
*/
$iFromId = getRequestStr('last_id');
$iFromId = getRequestStr('iLastId');
if (!$iFromId) {
$this->Message_AddError($this->Lang_Get('system_error'),$this->Lang_Get('error'));
return;
@ -110,11 +110,11 @@ class ActionUserfeed extends Action {
*/
$oViewer=$this->Viewer_GetLocalViewer();
$oViewer->Assign('aTopics', $aTopics);
$this->Viewer_AssignAjax('result', $oViewer->Fetch('topics/topic_list.tpl'));
$this->Viewer_AssignAjax('topics_count', count($aTopics));
$this->Viewer_AssignAjax('sHtml', $oViewer->Fetch('topics/topic_list.tpl'));
$this->Viewer_AssignAjax('iCountLoaded', count($aTopics));
if (count($aTopics)) {
$this->Viewer_AssignAjax('iUserfeedLastId', end($aTopics)->getId());
$this->Viewer_AssignAjax('iLastId', end($aTopics)->getId());
}
}
/**

View file

@ -325,7 +325,7 @@ class ModuleBlog extends Module {
public function CreatePersonalBlog(ModuleUser_EntityUser $oUser) {
$oBlog=Engine::GetEntity('Blog');
$oBlog->setOwnerId($oUser->getId());
$oBlog->setTitle($this->Lang_Get('blog.personal_title').' '.$oUser->getLogin());
$oBlog->setTitle($this->Lang_Get('blog.personal_prefix').' '.$oUser->getLogin());
$oBlog->setType('personal');
$oBlog->setDescription($this->Lang_Get('blog.personal_description'));
$oBlog->setDateAdd(date("Y-m-d H:i:s"));

View file

@ -362,7 +362,7 @@ $config['block']['rule_blogs'] = array(
'blocks' => array(
'right' => array(
'blocks/block.blogAdd.tpl' => array('priority' => 100),
'blogCategories' => array('priority' => 50)
'blogsSearch' => array('priority' => 50)
)
),
);
@ -397,6 +397,7 @@ $config['block']['rule_users'] = array(
'blocks' => array(
'right' => array(
'blocks/block.usersStatistics.tpl',
'blocks/block.usersSearch.tpl',
'tagsCountry',
'tagsCity',
)
@ -416,7 +417,7 @@ $config['block']['rule_profile'] = array(
$config['block']['rule_blog'] = array(
'action' => array('blog' => array('{blog}')),
'blocks' => array(
'right' => array(
'right' => array(
'blocks/block.blogActions.tpl' => array('priority'=>300),
'blocks/block.blogUsers.tpl' => array('priority'=>300),
'blocks/block.blogAdmins.tpl' => array('priority'=>300)
@ -492,7 +493,7 @@ $config['head']['default']['js'] = array(
"___path.application.web___/frontend/common/js/blog.js",
"___path.application.web___/frontend/common/js/user.js",
"___path.application.web___/frontend/common/js/userfeed.js",
"___path.application.web___/frontend/common/js/stream.js",
"___path.application.web___/frontend/common/js/activity.js",
"___path.application.web___/frontend/common/js/toolbar.js",
"___path.application.web___/frontend/common/js/settings.js",
"___path.application.web___/frontend/common/js/topic.js",
@ -503,6 +504,8 @@ $config['head']['default']['js'] = array(
"___path.application.web___/frontend/common/js/tags.js",
"___path.application.web___/frontend/common/js/content.js",
"___path.application.web___/frontend/common/js/user_list_add.js",
"___path.application.web___/frontend/common/js/search.js",
"___path.application.web___/frontend/common/js/more.js",
"___path.application.web___/frontend/common/js/init.js",
"http://yandex.st/share/share.js" => array('merge'=>false),

View file

@ -0,0 +1,105 @@
/**
* Подгрузка контента
*
* @module more
*
* @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.more", {
/**
* Дефолтные опции
*/
options: {
// Селектор блока с содержимым
target: null,
// Добавление контента в конец/начало контейнера
// true - в конец
// false - в начало
append: true,
// Ссылка
url: null,
// Название переменной с результатом
result: 'sHtml',
// Параметры запроса
params: {}
},
/**
* Конструктор
*
* @constructor
* @private
*/
_create: function () {
this.options = $.extend({}, this.options, ls.utils.getDataOptions(this.element, this.widgetName));
this.target = $( this.options.target );
this.counter = this.element.find('.js-more-count');
this._on({
click: function (e) {
! this.isLocked && this.load();
e.preventDefault();
}
});
},
/**
* Блокирует блок подгрузки
*/
lock: function () {
this.isLocked = true;
this.element.addClass(ls.options.classes.states.loading);
},
/**
* Разблокировывает блок подгрузки
*/
unlock: function () {
this.isLocked = false;
this.element.removeClass(ls.options.classes.states.loading);
},
/**
* Подгрузка
*/
load: function () {
this._trigger("beforeload", null, this);
this.options.params = ls.utils.getDataOptions(this.element, 'param');
this.lock();
ls.ajax.load(this.options.url, this.options.params, function (oResponse) {
if (oResponse.iCountLoaded > 0) {
this.target[ this.options.append ? 'append' : 'prepend' ]($.trim(oResponse[this.options.result]));
this.element.data('param-i-last-id', oResponse.iLastId);
// Обновляем счетчик
if (this.counter.length) {
var iCountLeft = parseInt(this.counter.text(), 10) - oResponse.iCountLoaded;
if (iCountLeft <= 0) {
this.element.remove();
} else {
this.counter.text(iCountLeft);
}
}
} else {
// Для блоков без счетчиков
ls.msg.notice(null, 'Больше нечего подгружать');
this.element.remove();
}
this.unlock();
this._trigger("afterload", null, { context: this, response: oResponse });
}.bind(this));
}
});
})(jQuery);

View file

@ -1,100 +0,0 @@
/**
* Активность
*
* @module ls/stream
*
* @license GNU General Public License, version 2
* @copyright 2013 OOO "ЛС-СОФТ" {@link http://livestreetcms.com}
* @author Denis Shakhov <denis.shakhov@gmail.com>
*/
var ls = ls || {};
ls.stream = (function ($) {
"use strict";
this.isBusy = false;
this.sDateLast = null;
/**
* Дефолтные опции
*/
var defaults = {
selectors: {
getMoreButton: '#activity-get-more',
}
};
/**
* Инициализация
*
* @param {Object} options Опции
*/
this.init = function(options) {
this.options = $.extend({}, defaults, options);
var self = this;
$(this.options.selectors.getMoreButton).on('click', function () {
self.getMore(this);
});
};
this.switchEventType = function (iType) {
var url = aRouter['stream']+'switchEventType/';
var params = {'type':iType};
ls.hook.marker('switchEventTypeBefore');
ls.ajax.load(url, params, function(data) {
if (!data.bStateError) {
ls.msg.notice(data.sMsgTitle,data.sMsg);
ls.hook.run('ls_stream_switch_event_type_after',[params,data]);
}
});
};
/**
* Подгрузка событий
* @param {Object} oGetMoreButton Кнопка
*/
this.getMore = function (oGetMoreButton) {
if (this.isBusy) return;
var $oGetMoreButton = $(oGetMoreButton),
$oLastId = $('#activity-last-id'),
iLastId = $oLastId.val();
if ( ! iLastId ) return;
$oGetMoreButton.addClass('loading');
this.isBusy = true;
var params = $.extend({}, {
'iLastId': iLastId,
'sDateLast': this.sDateLast
}, ls.utilities.getDataOptions($oGetMoreButton, 'param'));
var url = aRouter['stream'] + 'get_more' + (params.type ? '_' + params.type : '') + '/';
ls.hook.marker('getMoreBefore');
ls.ajax.load(url, params, function(data) {
if ( ! data.bStateError && data.events_count ) {
$('#activity-event-list').append(data.result);
$oLastId.attr('value', data.iStreamLastId);
}
if ( ! data.events_count) {
$oGetMoreButton.hide();
}
$oGetMoreButton.removeClass('loading');
ls.hook.run('ls_stream_get_more_after',[iLastId, data]);
this.isBusy = false;
}.bind(this));
};
return this;
}).call(ls.stream || {},jQuery);

View file

@ -1,8 +1,8 @@
/**
* Лента
*
*
* @module ls/userfeed
*
*
* @license GNU General Public License, version 2
* @copyright 2013 OOO "ЛС-СОФТ" {@link http://livestreetcms.com}
* @author Denis Shakhov <denis.shakhov@gmail.com>
@ -13,13 +13,12 @@ var ls = ls || {};
ls.userfeed = (function ($) {
"use strict";
this.isBusy = false;
/**
* Дефолтные опции
*
* @private
*/
var defaults = {
var _defaults = {
};
/**
@ -28,61 +27,60 @@ ls.userfeed = (function ($) {
* @param {Object} options Опции
*/
this.init = function(options) {
this.options = $.extend({}, defaults, options);
var _this = this;
this.options = $.extend({}, _defaults, options);
// Подписаться / отписаться
$('.js-userfeed-subscribe').on('click', function () {
var oCheckbox = $(this);
_this[ oCheckbox.is(':checked') ? 'subscribe' : 'unsubscribe' ]('blogs', oCheckbox.data('id'));
});
// Подгрузка контента
$('.js-more-userfeed').more({
url: aRouter['feed'] + 'get_more',
target: '#userfeed-topic-list'
});
};
this.subscribe = function (sType, iId) {
var url = aRouter['feed']+'subscribe/';
var params = {'type':sType, 'id':iId};
ls.hook.marker('subscribeBefore');
ls.ajax.load(url, params, function(data) {
if (!data.bStateError) {
ls.msg.notice(data.sMsgTitle,data.sMsg);
ls.hook.run('ls_userfeed_subscribe_after',[sType, iId, data]);
}
});
}
this.unsubscribe = function (sType, iId) {
var url = aRouter['feed']+'unsubscribe/';
var params = {'type':sType, 'id':iId};
ls.hook.marker('unsubscribeBefore');
ls.ajax.load(url, params, function(data) {
if (!data.bStateError) {
ls.msg.notice(data.sMsgTitle,data.sMsg);
ls.hook.run('ls_userfeed_unsubscribe_after',[sType, iId, data]);
}
});
}
this.getMore = function () {
if (this.isBusy) {
return;
/**
* Подписаться / отписаться
*/
this.subscribeAccessor = function(sName) {
return function (sType, iId) {
var sUrl = aRouter['feed'] + sName + '/',
oParams = { 'type': sType, 'id': iId };
ls.ajax.load(sUrl, oParams, function(oResponse) {
if ( ! oResponse.bStateError ) {
ls.msg.notice(oResponse.sMsgTitle, oResponse.sMsg);
ls.hook.run('ls_userfeed_subscribe_after', [sType, iId, oResponse]);
}
});
}
var lastId = $('#userfeed_last_id').val();
if (!lastId) return;
$('#userfeed_get_more').addClass('loading');
this.isBusy = true;
var url = aRouter['feed']+'get_more/';
var params = {'last_id':lastId};
ls.hook.marker('getMoreBefore');
ls.ajax.load(url, params, function(data) {
if (!data.bStateError && data.topics_count) {
$('#userfeed_loaded_topics').append(data.result);
$('#userfeed_last_id').attr('value', data.iUserfeedLastId);
}
if (!data.topics_count) {
$('#userfeed_get_more').hide();
}
$('#userfeed_get_more').removeClass('loading');
ls.hook.run('ls_userfeed_get_more_after',[lastId, data]);
this.isBusy = false;
}.bind(this));
}
};
/**
* Подписаться
*
* @param {String} sType Тип
* @param {Number} iId ID объекта
*/
this.subscribe = function(sType, iId) {
this.subscribeAccessor('subscribe').apply(this, arguments);
};
/**
* Отписаться
*
* @param {String} sType Тип
* @param {Number} iId ID объекта
*/
this.unsubscribe = function(sType, iId) {
this.subscribeAccessor('unsubscribe').apply(this, arguments);
};
return this;
}).call(ls.userfeed || {},jQuery);

View file

@ -1,8 +1,8 @@
/**
* Стена пользователя
*
*
* @module ls/wall
*
*
* @license GNU General Public License, version 2
* @copyright 2013 OOO "ЛС-СОФТ" {@link http://livestreetcms.com}
* @author Denis Shakhov <denis.shakhov@gmail.com>
@ -15,7 +15,7 @@ ls.wall = (function ($) {
/**
* Дефолтные опции
*
*
* @private
*/
var _defaults = {
@ -97,12 +97,6 @@ ls.wall = (function ($) {
e.preventDefault();
});
// Подгрузка записей
this.elements.document.on('click', this.options.selectors.get_more.self, function(e) {
_this.loadNext( $(this).data('id') );
e.preventDefault();
});
// Сворачиваем открытые формы
this.elements.document.on('click', function(e) {
// TODO: IE8 support
@ -112,9 +106,9 @@ ls.wall = (function ($) {
iId = oForm.data('id'),
oReply = $(_this.options.selectors.entry.reply + '[data-id=' + iId + ']');
if ( ! oForm.is(e.target) &&
oForm.has(e.target).length === 0 &&
! oReply.is(e.target) &&
if ( ! oForm.is(e.target) &&
oForm.has(e.target).length === 0 &&
! oReply.is(e.target) &&
! oForm.find(_this.options.selectors.form.text).val() ) {
if ( $(_this.options.selectors.entry_container + '[data-id=' + iId + ']' ).find(_this.options.selectors.entry.self).length || iId === 0 ) {
_this.form.close(oForm);
@ -125,6 +119,16 @@ ls.wall = (function ($) {
});
}
});
$('.js-more-wall').more({
url: aRouter['profile'] + USER_PROFILE_LOGIN + '/wall/load/',
});
$('.js-more-wall-comments').livequery(function () {
$(this).more({
url: aRouter['profile'] + USER_PROFILE_LOGIN + '/wall/load-reply/',
});
});
};
/**
@ -138,8 +142,7 @@ ls.wall = (function ($) {
ls.hook.marker('addBefore');
oButton.prop('disabled', true).addClass(ls.options.classes.states.loading);
oTextarea.prop('disabled', true);
ls.utils.formLock(oForm);
ls.ajax.load(this.options.routers.add, { sText: sText, iPid: iId }, function(result) {
if (result.bStateError) {
@ -152,14 +155,13 @@ ls.wall = (function ($) {
ls.hook.run('ls_wall_add_after', [sText, iId, result]);
}
oButton.prop('disabled', false).removeClass(ls.options.classes.states.loading);
oTextarea.prop('disabled', false);
ls.utils.formUnlock(oForm);
}.bind(this));
};
/**
* Удаление записи/комментария
*
*
* @param {Number} iId ID записи
*/
this.remove = function(iId) {
@ -185,72 +187,29 @@ ls.wall = (function ($) {
});
};
/**
* Подгрузка
*/
this.load = function(iIdLess, iIdMore, iPid, callback) {
var params = { iIdLess: iIdLess ? iIdLess : '', iIdMore: iIdMore ? iIdMore : '', iPid: iPid };
ls.hook.marker('loadBefore');
ls.ajax.load(iPid === 0 ? this.options.routers.load : this.options.routers.load_comments, params, callback);
};
/**
* Подгрузка новых записей
*/
this.loadNew = function(iPid) {
var oContainer = $(this.options.selectors.entry_container + '[data-id=' + iPid + ']'),
iMoreId = oContainer.find(' > ' + this.options.selectors.entry.self + ':' + (iPid === 0 ? 'first' : 'last')).data('id') || -1;
iFirstId = oContainer.find(' > ' + this.options.selectors.entry.self + ':' + (iPid === 0 ? 'first' : 'last')).data('id') || -1,
oParams = { iFirstId: iFirstId, iTargetId: iPid };
this.load('', iMoreId, iPid, function(result) {
ls.ajax.load(iPid === 0 ? this.options.routers.load : this.options.routers.load_comments, oParams, function(result) {
if (result.bStateError) {
ls.msg.error(null, result.sMsg);
} else {
if (result.iCountWall) {
oContainer[iPid === 0 ? 'prepend' : 'append'](result.sText);
if (result.iCountLoaded) {
oContainer[iPid === 0 ? 'prepend' : 'append'](result.sHtml);
}
this.form.close( $(this.options.selectors.form.self + '[data-id=' + iPid + ']') );
ls.hook.run('ls_wall_loadnew_after', [iPid, iMoreId, result]);
ls.hook.run('ls_wall_loadnew_after', [iPid, iFirstId, result]);
}
}.bind(this));
};
/**
* Подгрузка записей
*/
this.loadNext = function(iPid) {
var oContainer = $(this.options.selectors.entry_container + '[data-id=' + iPid + ']'),
oGetMore = $(this.options.selectors.get_more.self + '[data-id=' + iPid + ']'),
iLessId = oContainer.find(' > ' + this.options.selectors.entry.self + ':' + (iPid === 0 ? 'last' : 'first')).data('id') || undefined;
oGetMore.addClass(ls.options.classes.states.loading);
this.load(iLessId, '', iPid, function(result) {
if (result.bStateError) {
ls.msg.error(null, result.sMsg);
} else {
if (result.iCountWall) {
oContainer[ iPid === 0 ? 'append' : 'prepend' ](result.sText);
}
var iCount = result.iCountWall - result.iCountWallReturn;
if (iCount) {
oGetMore.find(this.options.selectors.get_more.count).text(iCount);
} else {
oGetMore.remove();
}
ls.hook.run('ls_wall_loadnext_after', [iLessId, result]);
}
oGetMore.removeClass(ls.options.classes.states.loading);
}.bind(this));
};
/**
* Форма
*/

View file

@ -7,5 +7,5 @@
{block name='layout_user_page_title'}{$aLang.user_menu_profile_stream}{/block}
{block name='layout_content'}
{include file='actions/ActionStream/event_list.tpl' sActivityType='user' sActivityParams="data-param-i-user-id=\"{$oUserProfile->getId()}\""}
{include 'actions/ActionStream/event_list.tpl' iLoadTargetId=$oUserProfile->getId() sActivityType='user'}
{/block}

View file

@ -2,8 +2,8 @@
* Стена / Запись (Пост / Комментарий)
*
* @param object $oWallEntry Комментарий
* @param boolean $bWallEntryShowReply Показывать или нет кнопку комментирования
* @param string $sWallEntryClasses Классы
* @param boolean $bWallEntryShowReply Показывать или нет кнопку комментирования
* @param string $sWallEntryClasses Классы
*
* TODO: Унаследовать от базового шаблона комментария
*}

View file

@ -13,9 +13,13 @@
<div class="wall-comments js-wall-comment-wrapper" data-id="{$oPost->getId()}">
{* Кнопка подгрузки комментариев *}
{if count($aPostComments) < $oPost->getCountReply()}
<div class="get-more get-more-wall-comments js-wall-get-more" data-id="{$oPost->getId()}">
{$aLang.wall_load_reply_more} <span class="js-wall-get-more-count">{$oPost->getCountReply()}</span> {$oPost->getCountReply()|declension:$aLang.comments.comments_declension}
</div>
{include 'more.tpl'
sLoadClasses = 'more-wall-comments js-more-wall-comments'
iLoadLastId = $aPostComments[0]->getId()
iLoadTargetId = $oPost->getId()
iLoadCount = $oPost->getCountReply() - Config::Get('module.wall.count_last_reply')
bLoadAppend = 'false'
sLoadAttributes = "data-more-target=\".js-wall-entry-container[data-id={$oPost->getId()}]\""}
{/if}
{* Комментарии *}

View file

@ -25,8 +25,10 @@
{* Кнопка подгрузки записей *}
{if $iCountWall - count($aWall)}
<div class="get-more js-wall-get-more" data-id="0">
{$aLang.wall_load_more} (<span class="js-wall-get-more-count">{$iCountWall - count($aWall)}</span>)
</div>
{include 'more.tpl'
sLoadClasses = 'js-more-wall'
iLoadLastId = $iWallLastId
iLoadCount = $iCountWall - count($aWall)
sLoadAttributes = "data-more-target=\".js-wall-entry-container[data-id=0]\""}
{/if}
{/block}

View file

@ -1,21 +1,23 @@
{**
* Список событий активности
*
* sActivityParams Дополнительные параметры активности
* sActivityType Тип активности
* all Вся активность
* user Активность пользователя
* @param string $sActivityType Тип активности
* all Вся активность
* user Активность пользователя
* custom Персональная (настраиваемая) активность
*}
{if count($aStreamEvents)}
{if $aStreamEvents}
<ul class="activity-event-list" id="activity-event-list">
{include file='actions/ActionStream/events.tpl'}
</ul>
{if ! $bDisableGetMoreButton}
<input type="hidden" id="activity-last-id" value="{$iStreamLastId}" />
<div class="get-more" id="activity-get-more" data-param-type="{$sActivityType}" {$sActivityParams}>{$aLang.stream_get_more}</div>
{include 'more.tpl'
sLoadClasses = "js-more-activity-$sActivityType"
iLoadLastId = $iStreamLastId
sLoadAttributes = "data-param-s-date-last=\"$sDateLast\""}
{/if}
{else}
{$aLang.stream_no_events}
{include 'alert.tpl' mAlerts=$aLang.common.empty sAlertStyle='empty'}
{/if}

View file

@ -2,17 +2,19 @@
* События (добавлен комментарий, добавлен топик и т.д.)
*}
{$sDateLast = {date_format date=$sDateLast format="j F Y"}}
{if count($aStreamEvents)}
{foreach $aStreamEvents as $oStreamEvent}
{foreach $aStreamEvents as $oStreamEvent}
{$oTarget = $oStreamEvent->getTarget()}
{$oUser = $oStreamEvent->getUser()}
{$bUserIsMale = $oUser->getProfileSex() != 'woman'}
{* Дата группы событий *}
{if {date_format date=$oStreamEvent->getDateAdded() format="j F Y"} != $sDateLast}
{$sDateLast = {date_format date=$oStreamEvent->getDateAdded() format="j F Y"}}
<li class="activity-date">
{if {date_format date=$smarty.now format="j F Y"} == $sDateLast}
{$aLang.today}
@ -31,7 +33,7 @@
{* Дата *}
<time datetime="{date_format date=$oStreamEvent->getDateAdded() format='c'}"
class="activity-event-date"
class="activity-event-date"
title="{date_format date=$oStreamEvent->getDateAdded()}">
{date_format date=$oStreamEvent->getDateAdded() hours_back="12" minutes_back="60" now="60" day="day H:i" format="j F Y, H:i"}
</time>
@ -39,8 +41,8 @@
{* Логин *}
<a href="{$oUser->getUserWebPath()}"><strong>{$oUser->getDisplayName()}</strong></a>
{*
* Текст события
{*
* Текст события
*}
{if $oStreamEvent->getEventType() == 'add_topic'}
{* Добавлен топик *}
@ -159,9 +161,4 @@
{/if}
</li>
{/foreach}
<script>
ls.stream.sDateLast = {json var=$sDateLast};
</script>
{/if}

View file

@ -11,5 +11,5 @@
{block name='layout_page_title'}{$aLang.stream_menu}{/block}
{block name='layout_content'}
{include file='actions/ActionStream/event_list.tpl' sActivityType=''}
{include file='actions/ActionStream/event_list.tpl' sActivityType='custom'}
{/block}

View file

@ -9,15 +9,15 @@
{/block}
{block name='layout_content'}
{include file='topics/topic_list.tpl'}
{if $aTopics}
<div id="userfeed-topic-list">
{include 'topics/topic_list.tpl'}
</div>
{if count($aTopics)}
{if !$bDisableGetMoreButton}
<div id="userfeed_loaded_topics"></div>
<input type="hidden" id="userfeed_last_id" value="{$iUserfeedLastId}" />
<div class="get-more" id="userfeed_get_more" onclick="ls.userfeed.getMore()">{$aLang.userfeed_get_more} &darr;</div>
{if ! $bDisableGetMoreButton}
{include 'more.tpl' sLoadClasses="js-more-userfeed" iLoadLastId=$iUserfeedLastId}
{/if}
{else}
{$aLang.userfeed_no_events}
{include 'alert.tpl' mAlerts=$aLang.common.empty sAlertStyle='empty'}
{/if}
{/block}

View file

@ -150,7 +150,7 @@
/**
* More
*/
.get-more {
.more {
display: block;
text-align: center;
padding: 12px 0;
@ -161,8 +161,8 @@
text-decoration: none;
cursor: pointer;
}
.get-more:hover { background: #f7f7f7; color: #555; }
.get-more.loading { background: #f7f7f7 url(../images/loader.gif) 50% 50% no-repeat; text-indent: -9999px; }
.more:hover { background: #f7f7f7; color: #555; }
.more.loading { background: #f7f7f7 url(../images/loader.gif) 50% 50% no-repeat; text-indent: -9999px; }
/**
@ -232,6 +232,16 @@
.user-note-actions li { float: left; margin-right: 15px; }
/**
* Алфавитный указатель
*/
.alphanumeric { overflow: hidden; background: #f7f7f7; margin-bottom: 20px; padding: 15px; }
.alphanumeric-item { float: left; margin-right: 1px; }
.alphanumeric-item a { float: left; padding: 5px 10px; color: #333; }
.alphanumeric-item.active { background: #333; border-radius: 3px; }
.alphanumeric-item.active a { color: #fff; }
/**
* Список с информацией
*/

View file

@ -3,7 +3,7 @@
*
* @template actions/ActionProfile/wall.*.tpl
* @scripts <frontend>/common/js/wall.js
*
*
* @license GNU General Public License, version 2
* @copyright 2013 OOO "ЛС-СОФТ" {@link http://livestreetcms.com}
* @author Denis Shakhov <denis.shakhov@gmail.com>
@ -41,4 +41,4 @@
/**
* Кнопка подгрузки комментариев
*/
.get-more.get-more-wall-comments { border: none; margin: 0; }
.more.more-wall-comments { border: none; margin: 0; }

View file

@ -123,7 +123,7 @@ jQuery(document).ready(function($){
/**
* Activity
*/
ls.stream.init();
ls.activity.init();
/**
@ -251,6 +251,12 @@ jQuery(document).ready(function($){
$('a.js-lbx').colorbox({ width:"100%", height:"100%" });
/**
* Поиск
*/
ls.search.init();
// Временный костыль для сабмита форм
// TODO: Перенести в плагин button
$(document).on('click', 'button[data-button-submit-form]', function () {

View file

@ -0,0 +1,25 @@
{**
* Уведомления
*
* @param string $sLoadText
* @param string $sLoadTarget
* @param integer $iLoadCount
* @param integer $iLoadTargetId
* @param integer $iLoadLastId
* @param bool $bLoadAppend
*
* @styles <framework>/css/common.css
*}
<div class="more {$sLoadClasses}"
data-more-append="{$bLoadAppend|default:'true'}"
{if $iLoadLastId}data-param-i-last-id="{$iLoadLastId}"{/if}
data-param-i-target-id="{$iLoadTargetId|default:0}"
{$sLoadAttributes}>
{$sLoadText|default:'Подгрузить еще'}
{if isset($iLoadCount)}
(<span class="js-more-count">{$iLoadCount}</span>)
{/if}
</div>