mirror of
https://github.com/twisterarmy/cloud-server.git
synced 2025-09-12 13:52:01 +00:00
fix post sending
This commit is contained in:
parent
f3747ab3a3
commit
f0765f9ea2
@ -1,8 +1,5 @@
|
|||||||
var ModulePost = {
|
var ModulePost = {
|
||||||
init: function(element) {
|
loadAvatar: function() {
|
||||||
ModulePost.loadAvatar(element);
|
|
||||||
},
|
|
||||||
loadAvatar: function(element) {
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'api/user/avatar',
|
url: 'api/user/avatar',
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
@ -11,7 +8,7 @@ var ModulePost = {
|
|||||||
if (response.success) {
|
if (response.success) {
|
||||||
|
|
||||||
if (response.avatar) {
|
if (response.avatar) {
|
||||||
$(element).find('img').attr('src', response.avatar).show();
|
$('#modulePostAvatar').attr('src', response.avatar).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -25,27 +22,27 @@ var ModulePost = {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
add: function() {
|
send: function() {
|
||||||
|
|
||||||
var input = $('#modulePost .message textarea');
|
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'api/post/add',
|
url: 'api/post/add',
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
data: {
|
data: {
|
||||||
message: input.val()
|
message: $('#modulePostMessage').val()
|
||||||
},
|
},
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
|
|
||||||
input.val('');
|
$('#modulePostMessage').val('');
|
||||||
|
$('#modulePostPreview').hide();
|
||||||
|
$('#modulePostPreview .text').html('');
|
||||||
|
|
||||||
$(document).trigger('ModulePost.add:success', [response]);
|
$(document).trigger('ModulePost.add:success', [response]);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
alert(response.message);
|
console.log(response.message);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function(jqXHR, textStatus, errorThrown) {
|
error: function(jqXHR, textStatus, errorThrown) {
|
||||||
@ -53,4 +50,53 @@ var ModulePost = {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
}
|
preview: function() {
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: 'api/post/preview',
|
||||||
|
type: 'POST',
|
||||||
|
data: {
|
||||||
|
message: $('#modulePostMessage').val()
|
||||||
|
},
|
||||||
|
success: function (response) {
|
||||||
|
|
||||||
|
if (response.success) {
|
||||||
|
|
||||||
|
if (response.format == '') {
|
||||||
|
$('#modulePostPreview').hide();
|
||||||
|
$('#modulePostPreview .text').html('');
|
||||||
|
} else {
|
||||||
|
$('#modulePostPreview').show();
|
||||||
|
$('#modulePostPreview .text').html(response.format);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
console.log(response.message);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(jqXHR, textStatus, errorThrown) {
|
||||||
|
console.log(textStatus, errorThrown);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
|
||||||
|
// Init module
|
||||||
|
ModulePost.loadAvatar();
|
||||||
|
|
||||||
|
// Event listeners
|
||||||
|
$(document).on('ModulePost.add:success', function(/*event, response*/) {
|
||||||
|
ModuleFeed.load('#moduleFeed', true);
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#modulePostMessage').on('keyup', function() {
|
||||||
|
ModulePost.preview();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#modulePostSend').on('click', function() {
|
||||||
|
ModulePost.send();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user