2017-07-06 18:03:35 +08:00
|
|
|
(function () {
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
angular
|
|
|
|
|
.module('forums')
|
|
|
|
|
.controller('ForumsPostController', ForumsPostController);
|
|
|
|
|
|
2017-12-09 23:16:34 +08:00
|
|
|
ForumsPostController.$inject = ['$scope', '$state', '$window', 'Authentication', 'MeanTorrentConfig', 'ForumsService', 'Upload', '$timeout', 'NotifycationService',
|
2018-05-05 00:17:48 +08:00
|
|
|
'marked', '$stateParams', 'TopicsService', '$translate'];
|
2017-07-06 18:03:35 +08:00
|
|
|
|
2017-12-09 23:16:34 +08:00
|
|
|
function ForumsPostController($scope, $state, $window, Authentication, MeanTorrentConfig, ForumsService, Upload, $timeout, NotifycationService,
|
2018-05-05 00:17:48 +08:00
|
|
|
marked, $stateParams, TopicsService, $translate) {
|
2017-07-06 18:03:35 +08:00
|
|
|
var vm = this;
|
|
|
|
|
vm.forumsConfig = MeanTorrentConfig.meanTorrentConfig.forumsConfig;
|
2017-12-14 10:35:36 +08:00
|
|
|
vm.inputLengthConfig = MeanTorrentConfig.meanTorrentConfig.inputLength;
|
2017-07-06 18:03:35 +08:00
|
|
|
vm.user = Authentication.user;
|
2017-07-08 01:40:20 +08:00
|
|
|
vm.forumPath = [];
|
2017-07-06 18:03:35 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* init
|
|
|
|
|
*/
|
|
|
|
|
vm.init = function () {
|
|
|
|
|
// get forum info by state params
|
|
|
|
|
ForumsService.get({
|
|
|
|
|
forumId: $stateParams.forumId
|
|
|
|
|
}, function (item) {
|
|
|
|
|
vm.forum = item;
|
|
|
|
|
|
2017-07-09 12:32:20 +08:00
|
|
|
vm.forumPath.splice(0, 0, {name: vm.forum.name, state: 'forums.view', params: {forumId: vm.forum._id}});
|
2018-05-05 00:17:48 +08:00
|
|
|
vm.forumPath.push({name: $translate.instant('FORUMS.BTN_POST_NEW_TOPIC'), state: undefined});
|
2017-07-06 18:03:35 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
};
|
2017-07-07 17:19:42 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* postTopic
|
|
|
|
|
* @param isValid
|
|
|
|
|
* @returns {boolean}
|
|
|
|
|
*/
|
|
|
|
|
vm.postTopic = function (isValid) {
|
|
|
|
|
if (!isValid) {
|
|
|
|
|
$scope.$broadcast('show-errors-check-validity', 'vm.postForm');
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-14 12:30:42 +08:00
|
|
|
var uf = [];
|
|
|
|
|
angular.forEach($scope.uFiles, function (f) {
|
|
|
|
|
uf.push({
|
|
|
|
|
filename: f.name,
|
|
|
|
|
filesize: f.size
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var uimg = [];
|
|
|
|
|
angular.forEach($scope.uImages, function (f) {
|
|
|
|
|
uimg.push({
|
|
|
|
|
filename: f.name
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-07-07 17:19:42 +08:00
|
|
|
var post = new TopicsService(vm.postFields);
|
2017-07-08 20:22:38 +08:00
|
|
|
post.forum = vm.forum._id;
|
2017-07-14 12:30:42 +08:00
|
|
|
post._attach = uf;
|
|
|
|
|
post._uImage = uimg;
|
2017-07-07 17:19:42 +08:00
|
|
|
|
|
|
|
|
post.$save(function (response) {
|
|
|
|
|
successCallback(response);
|
|
|
|
|
}, function (errorResponse) {
|
|
|
|
|
errorCallback(errorResponse);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function successCallback(res) {
|
|
|
|
|
vm.postFields = {};
|
2017-07-14 12:30:42 +08:00
|
|
|
$scope.uFiles = [];
|
|
|
|
|
$scope.uImages = [];
|
|
|
|
|
|
2017-07-07 17:19:42 +08:00
|
|
|
$scope.$broadcast('show-errors-reset', 'vm.postForm');
|
2017-07-09 16:29:35 +08:00
|
|
|
NotifycationService.showSuccessNotify('FORUMS.POST_TOPIC_SUCCESSFULLY');
|
2017-07-09 21:32:16 +08:00
|
|
|
$state.go('forums.topic', {forumId: vm.forum._id, topicId: res._id});
|
2017-07-07 17:19:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function errorCallback(res) {
|
2017-07-09 16:29:35 +08:00
|
|
|
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.POST_TOPIC_FAILED');
|
2017-07-07 17:19:42 +08:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-07-14 12:30:42 +08:00
|
|
|
/**
|
|
|
|
|
* uploadAttach
|
|
|
|
|
* @param editor
|
|
|
|
|
* @param ufile
|
|
|
|
|
* @param callback
|
|
|
|
|
*/
|
|
|
|
|
vm.uploadAttach = function (editor, ufile, progressback, callback, errback) {
|
|
|
|
|
Upload.upload({
|
|
|
|
|
url: '/api/attach/upload',
|
|
|
|
|
data: {
|
|
|
|
|
newAttachFile: ufile
|
|
|
|
|
}
|
|
|
|
|
}).then(function (res) {
|
|
|
|
|
if (callback) {
|
|
|
|
|
callback(res.data.filename);
|
|
|
|
|
}
|
|
|
|
|
}, function (res) {
|
|
|
|
|
if (errback && res.status > 0) {
|
|
|
|
|
errback(res);
|
|
|
|
|
}
|
|
|
|
|
}, function (evt) {
|
|
|
|
|
if (progressback) {
|
|
|
|
|
progressback(parseInt(100.0 * evt.loaded / evt.total, 10));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
2017-07-06 18:03:35 +08:00
|
|
|
}
|
|
|
|
|
}());
|