unserver-unify
Version:
142 lines (141 loc) • 4.27 kB
JavaScript
;
angular.module('bamboo.topic').controller('ClassTopicCtrl', function($scope, $rootScope, TopicApi, ApiService, loginService, CommonService, $state, smoothScroll, $stateParams) {
this.id = $stateParams.id;
this._userdata = {};
var _self = this;
this.publicUrl = ApiService.SHOST + "/public/images/";
this.r_content = "";
this.scrollToEdit = function() {
smoothScroll(document.getElementById('reply_comments'));
}
function getInfo() {
console.log("--- bbs detail ---");
var result = loginService.user;
if (result) {
_self._userdata.name = result.name;
_self._userdata.userurl = result.userurl;
_self._userdata.fullname = result.fullname;
_self._userdata.is_admin = result.is_admin;
$scope.login_user = true;
$scope.current_user = _self._userdata;
}
ApiService.get('/fullgrouptopic/' + _self.id).then(function(_result) {
// console.log(_result);
if (_result.data.success) {
$scope.topic = _result.data.data;
$rootScope.detailName = $scope.topic.title;
console.log($scope.topic);
var user = {
id: $scope.topic.author_id,
avatar: $scope.topic.author.avatar,
}
console.log(user);
$scope.topic.author_url = CommonService.getAvatarSrc(user);
angular.forEach($scope.topic.replies, function(reply, index) {
console.log(reply);
var author = {
id: reply.author._id,
avatar: reply.author.avatar,
}
reply.avatar_url = CommonService.getAvatarSrc(author);
})
} else {
$scope.error = _result.data.error;
}
});
}
getInfo();
this.top = function(flag) {
console.log("-- top --");
var params = {
id: _self.id,
is_top: flag,
action: "top",
};
console.log(params);
TopicApi.BBSApi(params, function(result) {
$state.reload();
});
};
this.delete = function() {
CommonService.confirm({
message: 'Are you sure you want to delete it?'
}).then(function() {
var params = {
id: _self.id,
action: "delete",
};
TopicApi.GroupApi(params, function(result) {
$state.go("^");
});
});
};
this.deleteReplay = function(reply) {
CommonService.confirm({
message: 'Are you sure you want to delete it?'
}).then(function() {
var params = {
reply_id: reply._id
};
ApiService.post('/deletegroupreply', params).then(function(result) {
if (result.data.success) {
$state.reload();
} else {
$scope.error = result.data.error;
}
});
});
};
this.good = function(id, flag) {
var params = {
id: id,
is_good: flag,
action: "good",
};
TopicApi.GroupApi(params, function(result) {
$state.reload();
});
};
this.addReply = function(id) {
if (_self.r_content.length < 10) {
$scope.rerror = "Reply length can not less than 10.";
return;
}
var params = {
r_content: _self.r_content,
topic_id: id,
};
console.log(params);
ApiService.put('/groupreplies', params).then(function(result) {
if (result.data.success) {
$state.reload();
} else {
$scope.error = result.data.error;
}
});
};
var wikiImgSetting = {
image: true,
promise: true,
s3: true,
title: "Image",
maxheight: 400,
maxwidth: 400,
randomFlag: true,
resPath: "public/" + ApiService.RES + "/reply/" + _self.id || 'new' + "/",
};
var forumurl = ApiService.PSURL + '/reply/' + _self.id || 'new' + "/";
this.uploadFile = function() {
// initImageUrl(uploadSetting, index);
CommonService.uploadFile(wikiImgSetting).then(function(data) {
if (data.result) {
console.log(data.fileName);
var imgstr = '<img src="' + forumurl + data.fileName + '" width="50%"/>';
//console.log(imgstr);
_self.r_content += imgstr;
} else {
CommonService.showError("Update failed: " + data.message);
}
});
};
});