You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
468 lines
18 KiB
468 lines
18 KiB
|
|
window.only_noviewed = false;
|
|
$(document).on('change', '[name="by_radio"]', function(){
|
|
if ($('#myModal1').length == 0) {
|
|
if (!window.only_noviewed) {
|
|
$('[viewed=True]').fadeOut('slow');
|
|
window.only_noviewed = true;
|
|
} else {
|
|
$('[viewed=True]').fadeIn('slow');
|
|
window.only_noviewed = false;
|
|
}
|
|
} else {
|
|
$('#myModal1').modal('show')
|
|
}
|
|
});
|
|
function set_favorit(block) {
|
|
if ($('#myModal1').length == 0){
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '/library/set_favorite/',
|
|
data: {'art': $(block).attr('article_id')},
|
|
async: false,
|
|
success: function(data) {
|
|
if (data['code'] == '1') {
|
|
$('[class=article_point][article_id=' + $(block).attr('article_id') + ']').attr('favorite', true);
|
|
$(block).attr('id', 'active');
|
|
$(block).attr('onclick', 'unset_favorit(this)');
|
|
if (!window.favorite_count){
|
|
window.favorite_count = 1;
|
|
} else {
|
|
window.favorite_count += 1
|
|
}
|
|
if (window.favorite_count > 0){
|
|
$('[name=favorite_button]').fadeIn('slow');
|
|
} else {
|
|
$('[name=favorite_button]').fadeOut('slow');
|
|
}
|
|
$('[name="favorite_count"]').html(window.favorite_count)
|
|
} else {
|
|
console.log(data['response'])
|
|
}
|
|
}
|
|
});
|
|
} else {
|
|
$('#myModal1').modal('show')
|
|
}
|
|
}
|
|
function ajax_set_favorit(block) {
|
|
if ($('#myModal1').length == 0){
|
|
$(block).attr('class', 'active');
|
|
$(block).attr('onclick', 'ajax_unset_favorit(this)');
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '/library/set_favorite/',
|
|
data: {'art': $(block).attr('article_id')}
|
|
});
|
|
} else {
|
|
$('#myModal1').modal('show')
|
|
}
|
|
}
|
|
function articles_length() {
|
|
var result = 0;
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: '/library/get_articles_length/',
|
|
async: false,
|
|
success: function (data) {
|
|
if (data['code'] == '1') {
|
|
result = data['data']
|
|
} else {
|
|
console.log(data['response'])
|
|
}
|
|
}
|
|
});
|
|
return result;
|
|
|
|
}
|
|
function unset_favorit(block) {
|
|
if ($('#myModal1').length == 0){
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '/library/unset_favorite/',
|
|
data: {'art': $(block).attr('article_id')},
|
|
async: false,
|
|
success: function(data) {
|
|
if (data['code'] == '1') {
|
|
$('[class=article_point][article_id=' + $(block).attr('article_id') + ']').attr('favorite', false);
|
|
$(block).attr('id', '');
|
|
$(block).attr('onclick', 'set_favorit(this)');
|
|
if (!window.favorite_count){
|
|
window.favorite_count = 0;
|
|
} else {
|
|
window.favorite_count -= 1
|
|
}
|
|
if (window.favorite_count > 0){
|
|
$('[name=favorite_button]').fadeIn('slow');
|
|
} else {
|
|
$('[name=favorite_button]').fadeOut('slow');
|
|
}
|
|
$('[name="favorite_count"]').html(window.favorite_count)
|
|
} else {
|
|
console.log(data['response'])
|
|
}
|
|
}
|
|
});
|
|
} else {
|
|
$('#myModal1').modal('show')
|
|
}
|
|
}
|
|
|
|
function ajax_unset_favorit(block) {
|
|
if ($('#myModal1').length == 0){
|
|
$(block).attr('class', '');
|
|
$(block).attr('onclick', 'ajax_set_favorit(this)');
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '/library/unset_favorite/',
|
|
data: {'art': $(block).attr('article_id')}
|
|
});
|
|
} else {
|
|
$('#myModal1').modal('show')
|
|
}
|
|
}
|
|
|
|
function ajax_unset_like(block) {
|
|
if ($('#myModal1').length == 0){
|
|
$('[name=like_thanks]').fadeOut('slow');
|
|
$(block).attr('class', '');
|
|
$(block).attr('onclick', 'ajax_set_like(this)');
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '/library/unset_like/',
|
|
data: {'id': $(block).attr('article_id')}
|
|
});
|
|
} else {
|
|
$('#myModal1').modal('show')
|
|
}
|
|
}
|
|
|
|
function ajax_set_like(block) {
|
|
if ($('#myModal1').length == 0){
|
|
$('[name=like_thanks]').fadeIn('slow');
|
|
$(block).attr('class', 'active');
|
|
$(block).attr('onclick', 'ajax_unset_like(this)');
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '/library/set_like/',
|
|
data: {'id': $(block).attr('article_id')}
|
|
});
|
|
} else {
|
|
$('#myModal1').modal('show')
|
|
}
|
|
}
|
|
|
|
function check_favorit(id) {
|
|
var block = $('i[article_id='+id+']')
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: '/library/check_favorite/',
|
|
data: {'id': id},
|
|
success: function(data) {
|
|
if (data['code'] == '1'){
|
|
$('[class=article_point][article_id='+id+']').attr('favorite', true);
|
|
$(block).attr('id', 'active');
|
|
$(block).attr('onclick', 'unset_favorit(this)');
|
|
if (!window.favorite_count){
|
|
window.favorite_count = 1;
|
|
} else {
|
|
window.favorite_count += 1
|
|
}
|
|
$('[name="favorite_count"]').html(window.favorite_count)
|
|
} else {
|
|
$('[class=article_point][article_id='+id+']').attr('favorite', false);
|
|
$(block).attr('id', '');
|
|
$(block).attr('onclick', 'set_favorit(this)');
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function set_like(id) {
|
|
if ($('#myModal1').length == 0) {
|
|
var count = parseInt($('[name=like_count]').html(), 10);
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '/library/set_like/',
|
|
data: {'id': id},
|
|
success: function (data) {
|
|
if (data['code'] == '1') {
|
|
$('[name=like_count]').html(count + 1)
|
|
$('[name=like_thanks]').fadeIn('slow');
|
|
} else {
|
|
console.log(data['response'])
|
|
}
|
|
}
|
|
});
|
|
} else {
|
|
$('#myModal1').modal('show')
|
|
}
|
|
}
|
|
|
|
function unset_like(id) {
|
|
if ($('#myModal1').length == 0) {
|
|
var count = parseInt($('[name=like_count]').html(), 10);
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '/library/unset_like/',
|
|
data: {'id': id},
|
|
success: function (data) {
|
|
if (data['code'] == '1') {
|
|
$('[name=like_count]').html(count + 1)
|
|
} else {
|
|
console.log(data['response'])
|
|
}
|
|
}
|
|
});
|
|
} else {
|
|
$('#myModal1').modal('show')
|
|
}
|
|
}
|
|
|
|
function refresh_like(id) {
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: '/library/refresh_like/',
|
|
data: {'id': id},
|
|
success: function (data) {
|
|
if (data['code'] == '1') {
|
|
$('[name=like_count]').html(data['data'])
|
|
} else {
|
|
console.log(data['response'])
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function get_random_article(id) {
|
|
var result = '';
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: '/library/get_random_article/',
|
|
data: {'id': id},
|
|
async: false,
|
|
success: function (data) {
|
|
result = data['data'];
|
|
}
|
|
});
|
|
return result;
|
|
}
|
|
|
|
function send_comment(form, root){
|
|
// Проверить комментарий
|
|
// Отправить
|
|
if (window.EDITOR.getValue()){
|
|
$('[name=sent_comment_progress]').show();
|
|
$('[name=comment_sent_text]').val(window.EDITOR.getValue());
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '/library/sent_comment/',
|
|
data: $('[name='+form+']').serialize(),
|
|
success: function(data){
|
|
if(data['code'] == '1'){
|
|
$('[name=sent_comment_progress]').hide();
|
|
document.forms[form].reset();
|
|
window.EDITOR.setValue('');
|
|
reload_lesson_comments(data['data']);
|
|
$('[name='+$('#'+root).attr('sketch_place')+']').html('')
|
|
}
|
|
}
|
|
});
|
|
|
|
} else {
|
|
show_system_message('Введите текст сообщения')
|
|
}
|
|
}
|
|
|
|
function write_comment(block, data){
|
|
var message;
|
|
var user_status;
|
|
var reply;
|
|
if (NotEmpty(data)) {
|
|
if (!NotEmpty(data['replies'])) {
|
|
reply = ''
|
|
} else {
|
|
reply = '<img src="/static/img/1442036154_reply-circle-blue.png" style="margin-left: 30px;">' +
|
|
'<Br>' +
|
|
'<div class="m-b b-l m-l-md streamline" parent_id="' + data['id'] + '" style="margin-left: 75px;margin-top: -25px;"></div>';
|
|
}
|
|
if (NotEmpty(data['files']) && !data['closed']) {
|
|
message = '<div name="message_files" message_id="' + data['id'] + '"></div>'
|
|
} else {
|
|
message = '';
|
|
}
|
|
var comment_id = '';
|
|
if ($('[name=REQUEST_USER_ROLE]').val() == 'A'){
|
|
comment_id = '<a href="'+location.protocol + '//'+ location.host+ '/admin/management/comment/'+data['id']+'" target="_blank" style="font-weight: bold;border-bottom: 1px dotted;margin-left: 10px;">ID:'+data['id']+'</a>';
|
|
}
|
|
user_status = '<label style="'+data['owner_type']['style'] + '" class="label ' + data['owner_type']['background'] + ' m-l-xs">' + data['owner_type']['title'] + '</label>' + comment_id;
|
|
var background;
|
|
if (data['owner_type']['flag'] == 'A') {
|
|
background = "#f5fce5;"
|
|
} else {
|
|
background = ''
|
|
}
|
|
var avatar;
|
|
if (data['closed']) {
|
|
avatar = '<span class="pull-left thumb-sm avatar m-l-n-md"><img src="/static/img/1442473207_delete.png"></span>'
|
|
} else {
|
|
avatar = '<span class="pull-left thumb-sm avatar m-l-n-md">' +
|
|
'<img src="' + data['owner_avatar'] + '" class="img-circle">' +
|
|
'</span>'
|
|
}
|
|
var head;
|
|
if (data['closed']) {
|
|
head = '<div class="panel-heading pos-rlt b-b b-light" style="background: #f1f1f1; color: #ccc;">' +
|
|
'<span class="arrow left" style="display: none;"></span>' +
|
|
'КОММЕНТАРИЙ УДАЛЕН' +
|
|
'<span class="text-muted m-l-sm pull-right">' +
|
|
'</span></div>'
|
|
} else {
|
|
head = '<div class="panel-heading pos-rlt b-b b-light">' +
|
|
'<span class="arrow left" style="display: none;"></span>' +
|
|
'<b style="margin-right: 5px;">' + data['owner'] + '</b>' +
|
|
'<span class="arrow left" style="border-right-color: ' + background + '"></span>' + user_status +
|
|
'<span class="text-muted m-l-sm pull-right">' +
|
|
//'<button class="btn like_button" title="Мне нравится"><i class="glyphicon glyphicon-heart"></i><span name="like_count" class="like_count">1</span> <span class="visible-lg-inline">Мне нравится</span></button>' +
|
|
//'<button class="btn complain_button" title="Пожаловаться"><i class="glyphicon glyphicon-fire"></i> <span class="visible-lg-inline">Пожаловаться</span></button>' +
|
|
'<i class="fa fa-clock-o" title="Дата записи: ' + data['date'] + '"></i><span class="hidden-xs" style="margin-left: 5px;">' + data['date'] + '</span></span></div>'
|
|
}
|
|
var reply_button;
|
|
var text;
|
|
if (data['closed']) {
|
|
reply_button = '';
|
|
text = '<div class="panel-body" style="display: none;">'
|
|
} else {
|
|
|
|
if (data['owner_id'] == $('[name=REQUEST_USER_ID]').val()) {
|
|
reply_button = '<a type="button" class="btn btn-danger btn-xs" onclick="do_delete_comment(' + data['id'] + ')">' +
|
|
'<i class="glyphicon glyphicon-remove"></i> Удалить</a>'
|
|
} else {
|
|
reply_button = '<a type="button" class="btn btn-default btn-xs" onclick="reply_comment(' + data['id'] + ')"><i class="fa fa-mail-reply text-muted"></i> Ответить</a>';
|
|
if ($('[name=REQUEST_USER_ROLE]').val() == 'A') {
|
|
reply_button += '<a type="button" class="btn btn-danger btn-xs" style="margin-left: 10px;" ' +
|
|
'onclick="do_delete_comment(' + data['id'] + ')"><i class="glyphicon glyphicon-remove"></i> Удалить</a>'
|
|
}
|
|
}
|
|
text = '<div class="panel-body" readable_comment="'+data['id']+'" style="padding: 0 15px;background: #f1f1f1;"><iframe style="width: 100%; border: 0;" srcdoc=\'<div class="m-b-xs" style="font-family: exo_2regular, Helvetica Neue, Helvetica, Arial, sans-serif;font-size: 14px;-webkit-font-smoothing: antialiased;line-height: 1.42857143;color: #58666e;background-color: transparent;">' + data['text'] + '</div>\' sandbox="allow-top-navigation"></iframe></div>'
|
|
}
|
|
|
|
|
|
$(block).append('<a name="comment_' + data['id'] + '"></a><div name="comment_' + data['id'] + '">' +
|
|
avatar +
|
|
'<div class="m-l-lg panel b-a" style="background: ' + background + '">' +
|
|
head +
|
|
text +
|
|
message +
|
|
'<div class="m-t-sm" style=" margin-top: 0;padding: 10px;">'
|
|
+ reply_button +
|
|
'</div>' +
|
|
'</div>' +
|
|
'</div>' +
|
|
'</div>' + reply);
|
|
|
|
for (var r = 0; r < data['replies'].length; r++) {
|
|
write_comment($('[parent_id=' + data['id'] + ']'), data['replies'][r])
|
|
}
|
|
var file_block = $('[name=message_files][message_id=' + data['id'] + ']');
|
|
for (var n = 0; n < data['files'].length; n++) {
|
|
var file_id = '';
|
|
var target = '';
|
|
var context = '';
|
|
if (data['files'][n]['format'] == 'I') {
|
|
file_id = 'single_image';
|
|
target = '__blank';
|
|
context = '<img src="' + data['files'][n]['url'] + '" style="display: none;">';
|
|
}
|
|
var m = '<div class="panel m-b-none"' +
|
|
' style="box-shadow: none; border: 1px solid rgba(0, 0, 0, 0.05); padding: 4px; margin-bottom: 3px !important;">' +
|
|
'<a href="' + data['files'][n]['url'] + '" target="' + target + '" id="' + file_id + '">' + context +
|
|
'<i class="' + data['files'][n]['icon'] + ' text-primary"></i> ' +
|
|
data['files'][n]['title'] +
|
|
'<span class="text-u-l" style="margin-left: 5px;">' + data['files'][n]['name'] + '</span></a></div>';
|
|
file_block.append(m);
|
|
}
|
|
$("a#single_image").fancybox();
|
|
}
|
|
}
|
|
function load_lesson_comments(type, reload_data){
|
|
$('[name=lesson_comments_empty]').hide();
|
|
$('[name=lesson_comments_block]').show();
|
|
var comment_block = $('[name=lesson_comments_block]');
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '/library/load_comments/',
|
|
data: {'lesson': comment_block.attr('lesson_id')},
|
|
success: function(data) {
|
|
$('[name=lesson_comments_load]').hide();
|
|
comment_block.show();
|
|
if (data['code'] == 0){
|
|
$('[name=lesson_comments_empty]').show();
|
|
$('[name=lesson_comments_block]').hide();
|
|
$('[name=comments_length]').html('0');
|
|
} else {
|
|
if (NotEmpty(data['data'])) {
|
|
for (var i = 0; i < data['data'].length; i++) {
|
|
write_comment(comment_block, data['data'][i]);
|
|
}
|
|
if (type == 'reload' && reload_data) {
|
|
location.hash = '';
|
|
location.hash = 'comment_' + reload_data
|
|
}
|
|
$('[name=comments_length]').html(window.lesson_comments_length);
|
|
} else {
|
|
$('[name=lesson_comments_empty]').show();
|
|
$('[name=lesson_comments_block]').hide();
|
|
$('[name=comments_length]').html('0');
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
function reload_lesson_comments(data){
|
|
$('[name=lesson_comments_load]').show();
|
|
$('[name=lesson_comments_block]').html('');
|
|
if (NotEmpty(data)){
|
|
load_lesson_comments('reload', data)
|
|
} else {
|
|
load_lesson_comments('reload')
|
|
}
|
|
|
|
}
|
|
function reply_comment(id){
|
|
$('[name=reply_for_comment_id]').val(id);
|
|
}
|
|
function get_lesson_comments_length(){
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: '/library/get_comments_length/',
|
|
async: true,
|
|
data: {'id': $('[name=ARTICLE_ID]').val()},
|
|
success: function(data){
|
|
if (data['code'] == '1'){
|
|
var comments_length = data['data'];
|
|
if (window.lesson_comments_length != comments_length){
|
|
reload_lesson_comments();
|
|
window.lesson_comments_length = comments_length
|
|
}
|
|
} else {
|
|
//show_system_message(data['response'])
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function get_all_views_length(){
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: '/library/get_all_views_length/',
|
|
async: true,
|
|
success: function(data){
|
|
if (data['code'] == '1'){
|
|
$('[name=all_article_views]').html(data['data'])
|
|
} else {
|
|
//show_system_message(data['response'])
|
|
}
|
|
}
|
|
});
|
|
} |