提交 368e31b1 编写于 作者: 街头小贩's avatar 街头小贩

增加消息和话题.js

上级 9713ccdc
......@@ -236,36 +236,18 @@ var jForum = (function ($) {
//console.log(rawdata);
loader.action(rawdata.uri, rawdata.callFun, rawdata.data, false, _j);
});
// 收件箱内容页中的加载更多
$('.letter-more-action').on('click', function(){
var pbx = $(this).parents('.letter-item-collect');
var rawdata = {};
rawdata.uri = pbx.attr('data-handler');
rawdata.page = parseInt(pbx.attr('data-page') || '1') +1;
rawdata.ele = pbx.attr('id');
//
var self = $(this);
self.addClass('disabled').html('正在玩命加载');
$.getJSON(rawdata.uri+'&p='+rawdata.page, function( data ){
//self是否显示
if(jQuery.isEmptyObject(data)){
return;
}
//遍历data.result
$.each(data.result, function(index, item){
jForum.template.drawLetterHistoryMessage(item, rawdata.ele);
});
pbx.attr('data-page', rawdata.page).scrollTop();
var letter = $.parseJSON(data.letter);
if(letter.more){
self.removeClass('disabled').html('更多历史消息');
}else{
self.hide();
}
});
});
//提示
$('[data-toggle="tooltip"]').tooltip();$('[data-toggle="popover"]').popover();
$('[data-toggle="tooltip"]').tooltip();
$('[data-toggle="popover"]').popover();
try{
$('.dropdown-toggle').dropdown();
}catch(e){}
//返回浏览历史的上一条
$('.historyBack').on('click', function(e){
e.preventDefault();
window.history.back();
return false;
});
//防止多次提交
$('[data-submit="once"]').one('submit', function(){
var submitBtn = $(this).find('[type="submit"]');
......@@ -285,45 +267,37 @@ var jForum = (function ($) {
//版块主页的 汇总统计
function getBoardStats(pURI) {
var def = $.Deferred();
$.getJSON(pURI, function (json) {
$('#online-list-stats').find('#stats-replies').html(json.replies);
$('#online-list-stats').find('#stats-threads').html(json.threads);
def.resolve();
jForum.xhr.jsonGet(pURI, {
jsonCallback : function(json){
$('#online-list-stats').find('#stats-replies').html(json.replies);
$('#online-list-stats').find('#stats-threads').html(json.threads);
def.resolve();
}
});
return def.promise();
};
//版块主页的 会员统计
function getMemberStats(pURI) {
$.getJSON(pURI, function (json) {
$('#online-list-stats').find('#stats-member').html(json.members);
$('#stats-onlines').html(json.onlines);
$('#stats-onlines-member').html(json.onlines);
var rm = $.parseJSON(json.recentMember);
jForum.xhr.jsonGet(pURI, {
jsonCallback : function(json){
$('#online-list-stats').find('#stats-member').html(json.members);
$('#stats-onlines').html(json.onlines);
$('#stats-onlines-member').html(json.onlines);
var rm = $.parseJSON(json.recentMember);
if (!$.isEmptyObject(rm)) {
var T = '<a href="/member/%MID%.xhtml" class="username">%MN%</a>'.replace('%MID%', rm.id).replace('%MN%', rm.title);
$('#online-list-stats').find('#stats-recent-member').html(T);
if (!$.isEmptyObject(rm)) {
var T = '<a href="/member/%MID%.xhtml" class="username">%MN%</a>'.replace('%MID%', rm.id).replace('%MN%', rm.title);
$('#online-list-stats').find('#stats-recent-member').html(T);
}
}
});
};
function showTodayNotice() {
$.getJSON(BASE + '/message/notice', function (json) {
jForum.template.poperNotice(json);
});
jForum.xhr.jsonGet(BASE + '/message/notice', {jsonCallback : jForum.template.poperNotice});
};
//jQuery extends function
$.fn.pagination = function (option) {
var gtx = new jForum.pagination(option);
//增加外部回调函数
//拿到数据后的回调
//pagination.jsonCallbackHandler = option.jsonCallback || null;
//ajax开始的回调,用以显示loading...
//pagination.ajaxBeforeHandler = option.ajaxBefore || null;
//ajax完成后的回调,用以删除loading...
//pagination.ajaxCompleteHandler = option.ajaxComplete || null;
//附加回调,在完成HTML分页元素时触发
//pagination.renderCompleteHandler = option.randerPageStruct || null;
var _self = this;
// 没有总记录数
gtx.getData(gtx.getPage(), _self);
......@@ -410,16 +384,17 @@ jForum.defer = (function () {
var params = $('#member-message-records').find('.badge').map(function(){
return this.id.replace('notice_', '');
}).get().join(",");
//
$.getJSON(requestURI+'?sender='+params, function( data ){
if(jQuery.isEmptyObject(data)){
return $('.badge').hide();
jForum.xhr.jsonGet(requestURI+'?sender='+params, {
jsonCallback : function( data ){
if(jQuery.isEmptyObject(data)){
return $('.badge').hide();
}
$.each(data, function(index, item) {
$('#notice_'+item.id).addClass('badge-info').html(item.title);
});
//没有的
$('.badge').not( ".badge-info").hide();
}
$.each(data, function(index, item) {
$('#notice_'+item.id).addClass('badge-info').html(item.title);
});
//没有的
$('.badge').not( ".badge-info").hide();
});
};
//版块中的两个收藏按钮
......
......@@ -17,21 +17,18 @@ jForum.member = (function ($) {
return false;
}
form.find('input[type=submit]').prop('disabled', true).val('正在登录');
$.ajax({
type: 'POST',
url: form.attr('action'),
data: requestData,
dataType: 'json'
}).done(function (response) {
quickLoginCallFun(response);
}).fail(function(jqXHR, textStatus, errorThrown){
if(textStatus === 'error'){
var err = $.parseJSON(jqXHR.responseText);
if(err.level && err.level ==='err'){
return util.errorMessage(err.message);
jForum.xhr.jsonPost(form.attr('action'), {
data : requestData,
jsonCallback : quickLoginCallFun,
failCallback : function(jqXHR, textStatus, errorThrown){
if(textStatus === 'error'){
var err = $.parseJSON(jqXHR.responseText);
if(err.level && err.level ==='err'){
return util.errorMessage(err.message);
}
}
util.errorMessage('当前操作因错误而异外中止');
}
util.errorMessage('当前操作因错误而异外中止');
});
return false;
});
......@@ -44,12 +41,14 @@ jForum.member = (function ($) {
return getCacheMemberInfo(mv, _mp);
}
//没有缓存命中
$.getJSON(_mp.attr('data-handler'), function( data ){
if(!jQuery.isEmptyObject(data)){
//[HMP]创建缓存拉取标记
setMemberVerify(data.verify);
//[HMP]生成会员面板
jForum.template.drawMemberPanel(data, _mp); //怎么显示由drawMemberPanel负责
jForum.xhr.jsonGet(_mp.attr('data-handler'), {
jsonCallback : function(data){
if(!jQuery.isEmptyObject(data)){
//[HMP]创建缓存拉取标记
setMemberVerify(data.verify);
//[HMP]生成会员面板
jForum.template.drawMemberPanel(data, _mp); //怎么显示由drawMemberPanel负责
}
}
});
}).trigger('loadDataEvent');
......@@ -57,27 +56,25 @@ jForum.member = (function ($) {
$('img.member_default_avtar').on('click', function(e){
var _ma = $(e.target);
var v = _ma.attr('data-path');
//
$.ajax({
type: 'POST',
url: BASE+'/member/home/avatar',
data: {"file" : v},
dataType: 'json'
}).done(function (response) {
if(response.level === 'acc' ){
_ma.addClass('active');
response.refresh = false;
$('img.member_default_avtar').not(_ma).removeClass('active');
}
return util.tipDialog(response);
}).fail(function(jqXHR, textStatus, errorThrown){
if(textStatus === 'error'){
var err = $.parseJSON(jqXHR.responseText);
if(err.level && err.level ==='err'){
return util.errorMessage(err.message);
jForum.xhr.jsonPost(BASE+'/member/home/avatar', {
data : {"file" : v},
jsonCallback : function(response){
if(response.level === 'acc' ){
_ma.addClass('active');
response.refresh = false;
$('img.member_default_avtar').not(_ma).removeClass('active');
}
return util.tipDialog(response);
},
failCallback : function(jqXHR, textStatus, errorThrown){
if(textStatus === 'error'){
var err = $.parseJSON(jqXHR.responseText);
if(err.level && err.level ==='err'){
return util.errorMessage(err.message);
}
}
return util.errorMessage('当前操作因错误而异外中止');
}
return util.errorMessage('当前操作因错误而异外中止');
});
return false;
});
......
jForum.message = (function($){
function init(){
// 收件箱内容页中的加载更多
$('.letter-more-action').on('click', function(){
var pbx = $(this).parents('.letter-item-collect');
var rawdata = {};
rawdata.uri = pbx.attr('data-handler');
rawdata.page = parseInt(pbx.attr('data-page') || '1') +1;
rawdata.ele = pbx.attr('id');
//
var self = $(this);
self.addClass('disabled').html('正在玩命加载');
$.getJSON(rawdata.uri+'&p='+rawdata.page, function( data ){
//self是否显示
if(jQuery.isEmptyObject(data)){
return;
}
//遍历data.result
$.each(data.result, function(index, item){
jForum.template.drawLetterHistoryMessage(item, rawdata.ele);
});
pbx.attr('data-page', rawdata.page).scrollTop();
var letter = $.parseJSON(data.letter);
if(letter.more){
self.removeClass('disabled').html('更多历史消息');
}else{
self.hide();
}
});
});
//聊天消息页中的发送动作
$('.send-message-action').on('click', function(e){
var self = $(this);
var callFun = self.attr('data-function') || 'drawMessageItem';
var requestParam = parseQueryJson(self.attr('data-query'));
requestParam.content = self.parents('form').find('.form-control').val();
if(isBlank(requestParam.content)){
self.parents('form').find('.form-control').focus();
return false;
}
self.addClass('disabled');
$.ajax({
url: self.attr('data-handler'),
dataType: 'json',
method: 'POST',
data: requestParam
}).done(function (response) {
window[callFun].call(this, response, self);
}).fail(function(jqXHR, textStatus, errorThrown){
if(textStatus === 'error'){
var err = $.parseJSON(jqXHR.responseText);
if(err.level && err.level ==='err'){
return errorMessage(err.message);
}
}
errorMessage('当前操作因错误而异外中止');
});
return false;
});
//创建消息页面的检查uid[NW]
$('body').on('click', '#suggest-btn', function(e){
var self = $('#suggest-uid');
var p = self.parents('.form-group');
if(isBlank(self.val())){
self.attr('placeholder', '输入收件人的UID').focus();
return;
}
self.attr("disabled","disabled");
$.getJSON(self.attr('data-handler'), 'value='+self.val(), function( data ){
if(data.level ==='acc'){
uidDetectionHandler(data.message, p);
}else{
$('input[name=snames]').val('');
self.addClass('is-invalid').removeAttr("disabled").focus();
}
});
});
//会员主页的发送消息|话题会员弹出层的消息[NW]
$('body').on('click', '.message-transmit', function(e){
//在线吗
var cam = getCurrentActiveMemberInfo();
if(jQuery.isEmptyObject(cam) || parseInt(cam.id) < 1){
return errorMessage('暂不支持游客发送消息');
}
var requestURI = $(this).attr('data-handler');
$.confirm({
title: '新消息',
closeIcon: true,
closeIconClass: 'ico-sm mdi mdi-close',
content: '<form action=""><div class="form-group"><textarea class="form-control" name="content" required="required" rows="3" placeholder="输入消息的内容"></textarea></div></form>',
buttons: {
formSubmit: {
text: '发送',
btnClass: 'btn-blue',
action: function () {
var content = this.$content.find('textarea[name=content]').val();
if(isBlank(content)){
this.$content.find('textarea[name=content]').focus();
return false;
}
var requestParam={};
requestParam.content=content;
$.ajax({
url: requestURI,
dataType: 'json',
method: 'POST',
data: requestParam
}).done(function (response) {
transmitMessageResult(response);
}).fail(function(jqXHR, textStatus, errorThrown){
if(textStatus === 'error'){
var err = $.parseJSON(jqXHR.responseText);
if(err.level && err.level ==='err'){
return errorMessage(err.message);
}
}
errorMessage('当前操作因错误而异外中止');
});
}
}
},
onContentReady: function () {
var jc = this;
this.$content.find('form').on('submit', function (e) {
e.preventDefault();
jc.$$formSubmit.trigger('click');
});
}
});
return false;
});
}
//UID检查的回调
function uidDetectionHandler(nickname, jqEle){
jqEle.find('input[name=uid]').removeAttr("disabled").removeClass('is-invalid');
$('#suggest-uid').parents('form').find('input[name=snames]').val(nickname);
};
return { init: init };
})(jQuery);
\ No newline at end of file
......@@ -679,6 +679,7 @@ jForum.template = (function ($) {
}
});
};
// Message start
// 聊天页中的历史记录[NW][8]
tmp.drawLetterHistoryMessage = function(json, jqEle){
var T=''
......@@ -706,6 +707,73 @@ jForum.template = (function ($) {
var ext = $.extend(json, rs);
$(Mustache.render(T, ext)).insertAfter($('#'+jqEle).find('p.text-center'));
};
//chat界面的响应
tmp.drawMessageItem = function(json){
if(jQuery.isEmptyObject(json)){
return;
}
var T=''
+'<div class="media media-master" id="letter-{id}">'
+' <div class="media-avatar media-left">'
+' <a href="javascript:;">'
+' <img class="media-object img-circle" src="{APP}/member/avatar/{sender}.png" style="height:64px;width:64px;">'
+' </a>'
+' </div>'
+' <div class="media-body">'
+' <div class="media-bubble">'
+' <h6 class="media-heading"><small>{datetime}</small></h6>'
+' <p>{body}</p>'
+' </div>'
+' </div>'
+'</div>';
Mustache.parse(T, ['{', '}']);
var rs = $.extend(json, {"APP":BASE});
var targetEleSelector = '#message-'+json.receiver+'-box';
$(targetEleSelector).append(Mustache.render(T, rs)).scrollTop($(targetEleSelector)[0].scrollHeight);
$('#send-message-form').find('.form-control').val('');
$('#send-message-form').find('.send-message-action').removeClass('disabled');
};
//Threads start
//话题内容页中会员弹出菜单的内容
tmp.buildMemberProfileMenu = function(json, jqEle){
var MP = ''
+'<div class="popmenu-member-header member-bg-{label}">'
+' <div class="popmenu-member-header-avatar"><img src="{APP}/member/avatar/{id}.png" class="img-circle" width="64px" height="64px" /></div>'
+' <div class="popmenu-member-header-info">'
+' <h6>{nickname}</h6>'
+' <p class="txt-sm">{levelNo}级 / {level}</p>'
+' </div>'
+'</div>'
+'<div class="popmenu-member-body">'
+' <ul class="list-inline"><li class="list-inline-item">{score}<span>积分</span></li><li class="list-inline-item">{threads}<span>主题</span></li><li class="list-inline-item">{replies}<span>回复</span></li></ul>'
+'</div>'
+'<div class="popmenu-member-footer">'
+' <a href="{APP}/member/{id}.xhtml" title="会员个人中心" role="button" class="btn btn-light btn-sm">'
+' <i class="ico-sm mdi mdi-home" aria-hidden="true"></i> 个人中心'
+' </a>'
+' <a href="javascript:;" title="发送消息" data-handler="{APP}/message/transmit?receiver={id}&names={nickname}" role="button" class="btn btn-light btn-sm message-transmit">'
+' <i class="ico-sm mdi mdi-email" aria-hidden="true"></i> 短消息'
+' </a>'
+'</div>'
var menuContent = '正在努力加载中...';
if(!jQuery.isEmptyObject(json)){
Mustache.parse(MP, ['{', '}']);
var rs = $.extend(json, {"APP":BASE});
menuContent = Mustache.render(MP, rs);
}
var linkDefaultWhiteList = $.fn.popover.Constructor.Default.whiteList;
linkDefaultWhiteList.a=['target', 'href', 'title', 'rel', 'data-handler'];
jqEle.popover({
placement : 'right',
title : '',
trigger: 'focus',
html : true,
content : menuContent
});
jqEle.popover('show');
};
tmp.poperNotice = function(json){
if(jQuery.isEmptyObject(json)){
return;
......
jForum.threads = (function ($) {
function init() {
//话题内容页中会员信息弹出菜单
$('body').on('click', 'a.poper-member-menu', function (e) {
e.preventDefault();
var self = $(this);
var rawdata = {};
rawdata.uri = self.parents('.topic_posts_item_left').attr('data-handler');
//本地缓存命中
rawdata.member = $.url(rawdata.uri).param('id');
var cacheData = store.get('member_profile#' + rawdata.member);
//本人的不缓存[20200118]
if (!jQuery.isEmptyObject(cacheData)) {
buildMemberProfileMenu(cacheData, self);
return;
}
//
console.log('[MP]不存在缓存去拉取数据');
$.getJSON(rawdata.uri, function (data) {
store.set('member_profile#' + rawdata.member, data);
buildMemberProfileMenu(data, self);
});
});
//引用回复@20200506
$('body').on('click', '.post-action-quote', function () {
var self = $(this);
var options = parseQueryJson(self.attr('data-query'));
$.getJSON(self.attr('data-handler'), 'id=' + options.id, function (json) {
if (jQuery.isEmptyObject(json)) {
return errorMessage('读取原文内容失败');
}
if (json.level === 'err') {
return errorMessage(json.message);
}
if (json.infoTip) {
insertEditorHtml('');
$('#reply-tip-message').html('<strong>提示!</strong>&nbsp;' + json.infoTip);
//插入到表单中@20200506
$('#quick_reply_form').find('input[name=quote]').val(json.quote);
$('#quick_reply_form').find('input[name=scale]').val(json.scale);
}
}).fail(function (jqXHR, textStatus, errorThrown) {
if (textStatus === 'error') {
var err = $.parseJSON(jqXHR.responseText);
if (err.level && err.level === 'err') {
return errorMessage(err.message);
}
}
errorMessage('当前操作因错误而异外中止');
});
return false;
});
//举报回复[NW]
$('body').on('click', '.post-action-report', function () {
var self = $(this);
var requestParam = parseQueryJson(self.attr('data-query'));
//
$.confirm({
title: '',
closeIcon: true,
closeIconClass: 'ico-sm mdi mdi-close',
content: '<form action="">' +
'<div class="form-group">' +
'<label>类型</label>' +
'<select name="type" size="1" class="form-control">' +
'<option value="">请选择类型</option>' +
'<option value="1">广告</option>' +
'<option value="2">色情</option>' +
'<option value="3">政治</option>' +
'<option value="4">暴力</option>' +
'<option value="5">语言暴力</option>' +
'<option value="6">其它</option>' +
'</select></div><div class="form-group"><textarea class="form-control" name="reason" required="required" rows="3" placeholder="输入举报的理由"></textarea></div></form>',
buttons: {
formSubmit: {
text: '举报',
btnClass: 'btn-blue',
action: function () {
var reason = this.$content.find('textarea[name=reason]').val();
if (isBlank(reason)) {
this.$content.find('textarea[name=reason]').focus();
return false;
}
requestParam.reason = reason;
requestParam.type = this.$content.find("select[name=type]").val();
$.ajax({
url: self.attr('data-handler'),
dataType: 'json',
method: 'POST',
data: requestParam
}).done(function (response) {
response.refresh = false;
tipDialog(response);
}).fail(function (jqXHR, textStatus, errorThrown) {
if (textStatus === 'error') {
var err = $.parseJSON(jqXHR.responseText);
if (err.level && err.level === 'err') {
return errorMessage(err.message);
}
}
errorMessage('当前操作因错误而异外中止');
});
}
}
},
onContentReady: function () {
var jc = this;
this.$content.find('form').on('submit', function (e) {
e.preventDefault();
jc.$$formSubmit.trigger('click');
});
}
});
return false;
});
//快速回复[NW]@20200506
$('#quick_reply_posts').on('submit', '#quick_reply_form', function (e) {
e.preventDefault();
var self = $(this);
//
var requestData = {}
requestData.token = self.find('input[name=token]').val();
requestData.quote = self.find('input[name=quote]').val();
requestData.scale = self.find('input[name=scale]').val();
try {