-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathletschat-chatlist.html
119 lines (103 loc) · 4.11 KB
/
letschat-chatlist.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<link href="css/mui.min.css" rel="stylesheet" />
</head>
<body>
<div class="mui-content">
<ul class="mui-table-view" id="ul_friend_request_list" style="margin-bottom: 10px;">
</ul>
</div>
<script src="js/mui.min.js"></script>
<script type="text/javascript" src="js/app.js"></script>
<script type="text/javascript">
mui.init()
window.addEventListener("refresh", function(){
loadingFriendRequests();
});
mui.plusReady(function() {
var user = app.getUserGlobalInfo();
var currentWebview = plus.webview.currentWebview();
currentWebview.addEventListener("show", function() {
loadingFriendRequests();
});
})
// Loads friends request list.
function loadingFriendRequests() {
var user = app.getUserGlobalInfo();
plus.nativeUI.showWaiting( "Loading..." );
mui.ajax(app.serverUrl + "/u/queryFriendRequests?acceptUserId=" + user.id ,{
data:{},
dataType:'json',//服务器返回json格式数据
type:'post',//HTTP请求类型
timeout:10000,//超时时间设置为10秒;
headers:{'Content-Type':'application/json'},
success:function(data){
plus.nativeUI.closeWaiting();
if (data.status==200){
var friendRequestList = data.data;
var ul_friend_request_list = document.getElementById("ul_friend_request_list");
if (friendRequestList != null && friendRequestList.length > 0) {
var requestHtml = "";
for (var i = 0; i < friendRequestList.length; i++) {
requestHtml += renderFriendRequests(friendRequestList[i]);
}
ul_friend_request_list.innerHTML = requestHtml;
// Bind events dynamically.
mui(".btnOper").on("tap", ".ignoreRequest", function(e) {
var friendId = this.getAttribute("friendId");
operatorFriendRequest(user.id, friendId, 0);
});
mui(".btnOper").on("tap", ".acceptRequest", function(e) {
var friendId = this.getAttribute("friendId");
operatorFriendRequest(user.id, friendId, 1);
});
} else {
ul_friend_request_list.innerHTML = "";
}
}
}
});
}
function operatorFriendRequest(userId, friendId, operType) {
plus.nativeUI.showWaiting( "Loading..." );
mui.ajax(app.serverUrl + "/u/operFriendRequest?acceptUserId=" + userId +
"&sendUserId=" + friendId +"&operType=" + operType ,{
data:{},
dataType:'json',//服务器返回json格式数据
type:'post',//HTTP请求类型
timeout:10000,//超时时间设置为10秒;
headers:{'Content-Type':'application/json'},
success:function(data){
plus.nativeUI.closeWaiting();
if (data.status==200){
// TODO connections
loadingFriendRequests();
}
}
});
}
// Deal single friend's request.
function renderFriendRequests(friend) {
var html = "";
html = '<li class="btnOper mui-table-view-cell mui-media">' +
'<a href="javascript:;">' +
'<img class="mui-media-object mui-pull-left" src="' + app.imgServerUrl + friend.sendFaceImage + '">' +
'<span id="span_nickname" class="mui-pull-right">' +
'<button friendId="' + friend.sendUserId + '" class="acceptRequest" style=" background-color: #e69138; color: white; max-width: 70px; margin-right: 10px">Accept</button>' +
'<button friendId="' + friend.sendUserId + '" class="ignoreRequest" style=" background-color: #C0C0C0; color: white; max-width: 70px;">Ignore</button>' +
'</span>' +
'<div class="mui-media-body">' +
'<label>' + friend.sendNickName + '</label>' +
'<p class="mui-ellipsis">Sends you a friend request.</p>' +
'</div>' +
'</a>' +
'</li>';
return html;
}
</script>
</body>
</html>