2012-03-11 19:52:17 +02:00
|
|
|
|
/**
|
|
|
|
|
* Стена пользователя
|
2014-03-04 10:32:38 +02:00
|
|
|
|
*
|
2013-08-29 12:30:04 +03:00
|
|
|
|
* @module ls/wall
|
2014-03-04 10:32:38 +02:00
|
|
|
|
*
|
2013-08-29 12:30:04 +03:00
|
|
|
|
* @license GNU General Public License, version 2
|
|
|
|
|
* @copyright 2013 OOO "ЛС-СОФТ" {@link http://livestreetcms.com}
|
|
|
|
|
* @author Denis Shakhov <denis.shakhov@gmail.com>
|
2012-03-11 19:52:17 +02:00
|
|
|
|
*/
|
2013-08-29 12:30:04 +03:00
|
|
|
|
|
2014-07-07 13:50:14 +03:00
|
|
|
|
(function($) {
|
2014-01-13 08:33:20 +02:00
|
|
|
|
"use strict";
|
2012-03-11 19:52:17 +02:00
|
|
|
|
|
2014-07-07 13:50:14 +03:00
|
|
|
|
$.widget( "livestreet.lsWall", {
|
|
|
|
|
/**
|
|
|
|
|
* Дефолтные опции
|
|
|
|
|
*/
|
|
|
|
|
options: {
|
|
|
|
|
// Ссылки
|
|
|
|
|
urls: {
|
|
|
|
|
add: null,
|
|
|
|
|
remove: null,
|
|
|
|
|
load: null,
|
|
|
|
|
load_comments: null
|
2014-01-13 08:33:20 +02:00
|
|
|
|
},
|
2012-03-11 19:52:17 +02:00
|
|
|
|
|
2014-07-07 13:50:14 +03:00
|
|
|
|
// Селекторы
|
|
|
|
|
selectors: {
|
|
|
|
|
entry: {
|
|
|
|
|
self: '.js-wall-entry',
|
|
|
|
|
remove: '.js-comment-remove',
|
|
|
|
|
reply: '.js-comment-reply'
|
|
|
|
|
},
|
|
|
|
|
comment: '.js-wall-comment',
|
|
|
|
|
post: '.js-wall-post',
|
|
|
|
|
form: '.js-wall-form',
|
|
|
|
|
more: '.js-wall-more',
|
|
|
|
|
more_comments: '.js-wall-more-comments',
|
|
|
|
|
comment_wrapper: '.js-wall-comment-wrapper',
|
|
|
|
|
container: '.js-wall-entry-container',
|
|
|
|
|
empty: '.js-wall-alert-empty'
|
|
|
|
|
}
|
|
|
|
|
},
|
2014-01-13 08:33:20 +02:00
|
|
|
|
|
2014-07-07 13:50:14 +03:00
|
|
|
|
/**
|
|
|
|
|
* Конструктор
|
|
|
|
|
*
|
|
|
|
|
* @constructor
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
_create: function () {
|
|
|
|
|
var _this = this;
|
|
|
|
|
|
|
|
|
|
this.elements = {
|
|
|
|
|
empty: this.element.find( this.option( 'selectors.empty' ) ),
|
|
|
|
|
more: this.element.find( this.option( 'selectors.more' ) ),
|
|
|
|
|
more_comments: this.element.find( this.option( 'selectors.more_comments' ) ),
|
|
|
|
|
entries: this.element.find( this.option( 'selectors.entry.self' ) ),
|
|
|
|
|
forms: this.element.find( this.option( 'selectors.form' ) ),
|
|
|
|
|
container: this.element.find( this.option( 'selectors.container' ) )
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.userId = this.getUserId();
|
|
|
|
|
|
|
|
|
|
// Подгрузка новых постов
|
|
|
|
|
this.elements.more.more({
|
|
|
|
|
url: this.option( 'urls.load' ),
|
|
|
|
|
params: {
|
|
|
|
|
user_id: this.getUserId()
|
2014-01-13 08:33:20 +02:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2014-07-07 13:50:14 +03:00
|
|
|
|
// Подгрузка комментариев
|
|
|
|
|
this.elements.more_comments.livequery( function () {
|
|
|
|
|
$( this ).more({
|
|
|
|
|
url: _this.option( 'urls.load_comments' ),
|
|
|
|
|
params: {
|
|
|
|
|
user_id: _this.getUserId()
|
2014-01-13 08:33:20 +02:00
|
|
|
|
}
|
|
|
|
|
});
|
2014-03-04 10:32:38 +02:00
|
|
|
|
});
|
2014-01-13 08:33:20 +02:00
|
|
|
|
|
2014-07-07 13:50:14 +03:00
|
|
|
|
// Записи
|
|
|
|
|
this.elements.entries.livequery( function () {
|
|
|
|
|
$( this ).lsWallEntry({
|
|
|
|
|
wall: _this.element,
|
|
|
|
|
urls: {
|
|
|
|
|
remove: _this.option( 'urls.remove' )
|
|
|
|
|
},
|
|
|
|
|
selectors: {
|
|
|
|
|
wrapper: _this.option( 'selectors.comment_wrapper' ),
|
|
|
|
|
remove: _this.option( 'selectors.entry.remove' ),
|
|
|
|
|
reply: _this.option( 'selectors.entry.reply' ),
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
});
|
2012-03-12 13:40:26 +02:00
|
|
|
|
|
2014-07-07 13:50:14 +03:00
|
|
|
|
// Формы
|
|
|
|
|
this.elements.forms.livequery( function () {
|
|
|
|
|
$( this ).lsWallForm({
|
|
|
|
|
wall: _this.element
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
2012-03-12 13:40:26 +02:00
|
|
|
|
|
2014-07-07 13:50:14 +03:00
|
|
|
|
/**
|
|
|
|
|
* Добавление
|
|
|
|
|
*
|
|
|
|
|
* TODO: Оптимизировать
|
|
|
|
|
*/
|
|
|
|
|
add: function( pid, text ) {
|
|
|
|
|
var form = this.getFormById( pid );
|
2012-03-11 19:52:17 +02:00
|
|
|
|
|
2014-07-07 13:50:14 +03:00
|
|
|
|
ls.ajax.load( this.option( 'urls.add' ), { user_id: this.getUserId(), pid: pid, text: text }, function( response ) {
|
|
|
|
|
if ( response.bStateError ) {
|
|
|
|
|
ls.msg.error(null, response.sMsg);
|
|
|
|
|
} else {
|
|
|
|
|
if ( pid === 0 ) this.elements.empty.hide();
|
2014-01-13 08:33:20 +02:00
|
|
|
|
|
2014-07-07 13:50:14 +03:00
|
|
|
|
this.load( pid );
|
|
|
|
|
form.lsWallForm( 'close' );
|
|
|
|
|
}
|
2014-01-13 08:33:20 +02:00
|
|
|
|
|
2014-07-07 13:50:14 +03:00
|
|
|
|
ls.utils.formUnlock( form );
|
|
|
|
|
}.bind(this));
|
|
|
|
|
},
|
2014-01-13 08:33:20 +02:00
|
|
|
|
|
2014-07-07 13:50:14 +03:00
|
|
|
|
/**
|
|
|
|
|
* Подгружает записи
|
|
|
|
|
*
|
|
|
|
|
* TODO: Оптимизировать
|
|
|
|
|
*/
|
|
|
|
|
load: function( pid ) {
|
|
|
|
|
var container = this.element.find( this.options.selectors.container + '[data-id=' + pid + ']' ),
|
|
|
|
|
firstId = container.find( '>' + this.option( 'selectors.entry.self' ) + ':' + ( pid === 0 ? 'first' : 'last' ) ).data( 'id' ) || -1,
|
|
|
|
|
params = { user_id: this.getUserId(), first_id: firstId, target_id: pid };
|
|
|
|
|
|
|
|
|
|
ls.ajax.load( this.option( pid === 0 ? 'urls.load' : 'urls.load_comments' ), params, function( response ) {
|
|
|
|
|
if (response.bStateError) {
|
|
|
|
|
ls.msg.error(null, response.sMsg);
|
|
|
|
|
} else {
|
|
|
|
|
if ( response.count_loaded ) {
|
|
|
|
|
container[ pid === 0 ? 'prepend' : 'append' ]( response.html );
|
|
|
|
|
}
|
2012-03-12 13:40:26 +02:00
|
|
|
|
}
|
2014-07-07 13:50:14 +03:00
|
|
|
|
}.bind(this));
|
|
|
|
|
},
|
2014-01-13 08:33:20 +02:00
|
|
|
|
|
2014-07-07 13:50:14 +03:00
|
|
|
|
/**
|
|
|
|
|
* Получает посты
|
|
|
|
|
*/
|
|
|
|
|
getPosts: function() {
|
|
|
|
|
return this.element.find( this.option( 'selectors.post' ) );
|
|
|
|
|
},
|
2014-01-13 08:33:20 +02:00
|
|
|
|
|
2014-07-07 13:50:14 +03:00
|
|
|
|
/**
|
|
|
|
|
* Получает комментарии по ID поста
|
|
|
|
|
*/
|
|
|
|
|
getCommentsByPostId: function( pid ) {
|
|
|
|
|
return this.getCommentWrapperById( pid ).find( this.option( 'selectors.comment' ) );
|
|
|
|
|
},
|
2012-03-12 13:40:26 +02:00
|
|
|
|
|
2014-01-13 08:33:20 +02:00
|
|
|
|
/**
|
2014-07-07 13:50:14 +03:00
|
|
|
|
* Получает запись по ID
|
2014-01-13 08:33:20 +02:00
|
|
|
|
*/
|
2014-07-07 13:50:14 +03:00
|
|
|
|
getEntryById: function( id ) {
|
|
|
|
|
return this.element.find( this.option( 'selectors.entry.self' ) + '[data-id=' + id + ']' ).eq( 0 );
|
|
|
|
|
},
|
2012-03-22 17:18:34 +02:00
|
|
|
|
|
2014-01-13 08:33:20 +02:00
|
|
|
|
/**
|
2014-07-07 13:50:14 +03:00
|
|
|
|
* Получает враппер комментариев по ID поста
|
2014-01-13 08:33:20 +02:00
|
|
|
|
*/
|
2014-07-07 13:50:14 +03:00
|
|
|
|
getCommentWrapperById: function( id ) {
|
|
|
|
|
return this.element.find( this.option( 'selectors.comment_wrapper' ) + '[data-id=' + id + ']' ).eq( 0 );
|
|
|
|
|
},
|
2012-03-12 13:40:26 +02:00
|
|
|
|
|
2014-01-13 08:33:20 +02:00
|
|
|
|
/**
|
2014-07-07 13:50:14 +03:00
|
|
|
|
* Получает форму по ID поста
|
2014-01-13 08:33:20 +02:00
|
|
|
|
*/
|
2014-07-07 13:50:14 +03:00
|
|
|
|
getFormById: function( id ) {
|
|
|
|
|
return this.element.find( this.option( 'selectors.form' ) + '[data-id=' + id + ']' ).eq( 0 );
|
|
|
|
|
},
|
2012-04-13 20:12:59 +03:00
|
|
|
|
|
2014-01-13 08:33:20 +02:00
|
|
|
|
/**
|
2014-07-07 13:50:14 +03:00
|
|
|
|
* Получает ID владельца стены
|
2014-01-13 08:33:20 +02:00
|
|
|
|
*/
|
2014-07-07 13:50:14 +03:00
|
|
|
|
getUserId: function() {
|
|
|
|
|
return this.userId ? this.userId : this.userId = this.element.data( 'user-id' );
|
|
|
|
|
},
|
2012-04-13 20:12:59 +03:00
|
|
|
|
|
2014-07-07 13:50:14 +03:00
|
|
|
|
/**
|
|
|
|
|
* Получает развернутые формы
|
|
|
|
|
*/
|
|
|
|
|
getOpenedForms: function() {
|
|
|
|
|
return this.element.find( this.option( 'selectors.form' ) + '.' + ls.options.classes.states.open );
|
|
|
|
|
},
|
2012-03-11 19:52:17 +02:00
|
|
|
|
|
2014-07-07 13:50:14 +03:00
|
|
|
|
/**
|
|
|
|
|
* Проверяет и если нужно показывает/скрывает сообщение о пустом списке
|
|
|
|
|
*/
|
|
|
|
|
checkEmpty: function() {
|
|
|
|
|
this.elements.empty[ this.getPosts().length ? 'hide' : 'show' ]();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
})(jQuery);
|