2011-06-27 11:57:57 +03:00
|
|
|
var ls = ls || {};
|
|
|
|
|
2011-06-25 11:04:19 +03:00
|
|
|
ls.stream =( function ($) {
|
|
|
|
this.isBusy = false;
|
|
|
|
this.subscribe = function (iTargetUserId) {
|
2011-07-20 00:32:36 +03:00
|
|
|
ls.ajax(aRouter['stream']+'subscribe/', {'id':iTargetUserId}, function(data) {
|
2011-07-31 19:52:50 +03:00
|
|
|
if (data.bStateError) {
|
|
|
|
ls.msg.error(data.sMsgTitle,data.sMsg);
|
2011-07-20 00:32:36 +03:00
|
|
|
} else {
|
|
|
|
ls.msg.notice(data.sMsgTitle,data.sMsg);
|
2011-06-25 11:04:19 +03:00
|
|
|
}
|
2011-07-20 00:32:36 +03:00
|
|
|
|
2011-06-25 11:04:19 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
this.unsubscribe = function (iId) {
|
2011-07-20 00:32:36 +03:00
|
|
|
ls.ajax(aRouter['stream']+'unsubscribe/', {'id':iId}, function(data) {
|
2011-06-25 11:04:19 +03:00
|
|
|
if (!data.bStateError) {
|
|
|
|
ls.msg.notice(data.sMsgTitle,data.sMsg);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this.switchEventType = function (iType) {
|
2011-07-20 00:32:36 +03:00
|
|
|
ls.ajax(aRouter['stream']+'switchEventType/', { 'type':iType}, function(data) {
|
2011-06-25 11:04:19 +03:00
|
|
|
if (!data.bStateError) {
|
|
|
|
ls.msg.notice(data.sMsgTitle,data.sMsg);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this.appendUser = function() {
|
2011-06-27 11:57:57 +03:00
|
|
|
var sLogin = $('#stream_users_complete').val();
|
2011-06-25 11:04:19 +03:00
|
|
|
if (!sLogin) return;
|
2011-07-20 00:32:36 +03:00
|
|
|
ls.ajax(aRouter['stream']+'subscribeByLogin/', {'login':sLogin}, function(data) {
|
2011-06-25 11:04:19 +03:00
|
|
|
if (!data.bStateError) {
|
2011-07-04 13:01:14 +03:00
|
|
|
$('#stream_no_subscribed_users').remove();
|
2011-06-27 11:57:57 +03:00
|
|
|
var checkbox = $('#strm_u_'+data.uid);
|
2011-06-25 11:04:19 +03:00
|
|
|
if (checkbox.length) {
|
|
|
|
if (checkbox.attr('checked')) {
|
2011-07-31 19:52:50 +03:00
|
|
|
ls.msg.error(ls.lang.get('error'),ls.lang.get('stream_subscribes_already_subscribed'));
|
2011-06-25 11:04:19 +03:00
|
|
|
} else {
|
|
|
|
checkbox.attr('checked', 'on');
|
|
|
|
ls.msg.notice(data.sMsgTitle,data.sMsg);
|
|
|
|
}
|
|
|
|
} else {
|
2011-08-15 19:20:42 +03:00
|
|
|
var liElement='<li><input type="checkbox" class="streamUserCheckbox input-checkbox" id="usf_u_'+data.uid+'" checked="checked" onClick="if ($(this).get(\'checked\')) {ls.stream.subscribe(\'users\','+data.uid+')} else {ls.stream.unsubscribe(\'users\','+data.uid+')}" /> <a href="'+data.user_web_path+'">'+data.user_login+'</a></li>';
|
2011-06-27 11:57:57 +03:00
|
|
|
$('#stream_block_users_list').append(liElement);
|
2011-06-25 11:04:19 +03:00
|
|
|
ls.msg.notice(data.sMsgTitle,data.sMsg);
|
|
|
|
}
|
2011-07-20 00:32:36 +03:00
|
|
|
} else {
|
2011-07-31 19:52:50 +03:00
|
|
|
ls.msg.error(data.sMsgTitle,data.sMsg);
|
2011-06-25 11:04:19 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this.getMore = function () {
|
|
|
|
if (this.isBusy) {
|
|
|
|
return;
|
|
|
|
}
|
2011-06-27 11:57:57 +03:00
|
|
|
var lastId = $('#stream_last_id').val();
|
2011-06-25 11:04:19 +03:00
|
|
|
if (!lastId) return;
|
2011-06-27 11:57:57 +03:00
|
|
|
$('#stream_get_more').addClass('stream_loading');
|
2011-06-25 11:04:19 +03:00
|
|
|
this.isBusy = true;
|
2011-07-20 00:32:36 +03:00
|
|
|
ls.ajax(aRouter['stream']+'get_more/', {'last_id':lastId}, function(data) {
|
2011-07-31 19:52:50 +03:00
|
|
|
if (!data.bStateError && data.events_count) {
|
|
|
|
$('#stream-list').append(data.result);
|
2011-06-27 11:57:57 +03:00
|
|
|
$('#stream_last_id').attr('value', data.iStreamLastId);
|
2011-06-25 11:04:19 +03:00
|
|
|
}
|
2011-07-31 19:52:50 +03:00
|
|
|
if (!data.events_count) {
|
2011-06-27 11:57:57 +03:00
|
|
|
$('#stream_get_more').css({'display':'none'});
|
2011-06-25 11:04:19 +03:00
|
|
|
}
|
2011-06-27 11:57:57 +03:00
|
|
|
$('#stream_get_more').removeClass('stream_loading');
|
|
|
|
this.isBusy = false;
|
|
|
|
}.bind(this));
|
2011-06-25 11:04:19 +03:00
|
|
|
}
|
|
|
|
return this;
|
2011-06-27 12:15:57 +03:00
|
|
|
}).call(ls.stream || {},jQuery);
|