Skip to content

Commit a41b027

Browse files
勤硕JacksonTian
authored andcommitted
refactor: admin script
1 parent 258f4fe commit a41b027

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

app/view/user/index.html

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,65 @@
124124
</div>
125125
<% } %>
126126
</div>
127+
128+
<% if (current_user) { %>
129+
<script>
130+
$(document).ready(function () {
131+
$('#set_star_btn').click(function () {
132+
var $me = $(this);
133+
var action = $me.attr('action');
134+
var params = {
135+
user_id: '<%= user._id %>',
136+
_csrf: '<%- csrf %>'
137+
};
138+
$.post('/user/' + action, params, function (data) {
139+
if (data.status === 'success') {
140+
if (action === 'set_star') {
141+
$me.html('取消达人');
142+
$me.attr('action', 'cancel_star');
143+
} else {
144+
$me.html('设为达人');
145+
$me.attr('action', 'set_star');
146+
}
147+
}
148+
}, 'json');
149+
});
150+
$('#set_block_btn').click(function () {
151+
var $me = $(this);
152+
var action = $me.attr('action');
153+
var params = {
154+
_csrf: '<%- csrf %>',
155+
action: action
156+
};
157+
if (action === 'set_block' && !confirm('确定要屏蔽该用户吗?')) {
158+
return;
159+
}
160+
$.post('/user/<%- user.loginname %>/block', params, function (data) {
161+
if (data.status === 'success') {
162+
if (action === 'set_block') {
163+
$me.html('取消屏蔽用户');
164+
$me.attr('action', 'cancel_block');
165+
} else if (action === 'cancel_block') {
166+
$me.html('屏蔽用户');
167+
$me.attr('action', 'set_block');
168+
}
169+
}
170+
}, 'json');
171+
})
172+
$('#delete_all').click(function () {
173+
var $me = $(this);
174+
var params = {
175+
_csrf: '<%- csrf %>',
176+
};
177+
if (!confirm('确定要删除吗?(不会永久删除,只做标记位)')) {
178+
return;
179+
}
180+
$.post('/user/<%- user.loginname %>/delete_all', params, function (data) {
181+
if (data.status === 'success') {
182+
alert('操作成功');
183+
}
184+
}, 'json');
185+
})
186+
});
187+
</script>
188+
<% } %>

0 commit comments

Comments
 (0)