2017-07-08 01:40:20 +08:00
|
|
|
(function () {
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
angular
|
|
|
|
|
.module('forums')
|
|
|
|
|
.controller('ForumsTopicController', ForumsTopicController);
|
|
|
|
|
|
2017-07-09 16:29:35 +08:00
|
|
|
ForumsTopicController.$inject = ['$scope', '$state', '$translate', 'Authentication', 'MeanTorrentConfig', 'ForumsService', 'ScoreLevelService', '$timeout', 'NotifycationService',
|
2017-09-13 13:27:34 +08:00
|
|
|
'marked', 'ModalConfirmService', '$stateParams', 'TopicsService', 'localStorageService', '$compile', 'RepliesService', '$filter', 'Upload', 'DownloadService',
|
2017-11-17 15:55:57 +08:00
|
|
|
'DebugConsoleService', '$window'];
|
2017-07-08 01:40:20 +08:00
|
|
|
|
2017-07-09 16:29:35 +08:00
|
|
|
function ForumsTopicController($scope, $state, $translate, Authentication, MeanTorrentConfig, ForumsService, ScoreLevelService, $timeout, NotifycationService,
|
2017-09-13 13:27:34 +08:00
|
|
|
marked, ModalConfirmService, $stateParams, TopicsService, localStorageService, $compile, RepliesService, $filter, Upload, DownloadService,
|
2017-11-17 15:55:57 +08:00
|
|
|
mtDebug, $window) {
|
2017-07-08 01:40:20 +08:00
|
|
|
var vm = this;
|
2017-10-16 11:52:29 +08:00
|
|
|
vm.DLS = DownloadService;
|
2017-07-08 01:40:20 +08:00
|
|
|
vm.forumsConfig = MeanTorrentConfig.meanTorrentConfig.forumsConfig;
|
2017-12-14 10:35:36 +08:00
|
|
|
vm.inputLengthConfig = MeanTorrentConfig.meanTorrentConfig.inputLength;
|
2017-08-14 12:46:55 +08:00
|
|
|
vm.announce = MeanTorrentConfig.meanTorrentConfig.announce;
|
2017-07-21 16:52:04 +08:00
|
|
|
vm.scoreConfig = MeanTorrentConfig.meanTorrentConfig.score;
|
2017-07-18 17:02:25 +08:00
|
|
|
vm.itemsPerPageConfig = MeanTorrentConfig.meanTorrentConfig.itemsPerPage;
|
2017-07-14 12:30:42 +08:00
|
|
|
vm.appConfig = MeanTorrentConfig.meanTorrentConfig.app;
|
2017-07-08 01:40:20 +08:00
|
|
|
vm.user = Authentication.user;
|
|
|
|
|
vm.forumPath = [];
|
2017-07-09 19:37:12 +08:00
|
|
|
vm.postReplyFields = {};
|
2017-07-08 01:40:20 +08:00
|
|
|
|
2017-11-17 15:55:57 +08:00
|
|
|
angular.element($window).bind('scroll', function (e) {
|
|
|
|
|
var scTop = angular.element('#top_of_reply_list').prop('offsetTop') - 60;
|
|
|
|
|
if ($(window).scrollTop() > scTop) {
|
|
|
|
|
//alert('boom');up-to-top
|
|
|
|
|
angular.element('.up-to-top').css('display', 'block');
|
|
|
|
|
} else {
|
|
|
|
|
angular.element('.up-to-top').css('display', 'none');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* upToTop
|
|
|
|
|
*/
|
|
|
|
|
vm.upToTop = function () {
|
|
|
|
|
var element = angular.element('#top_of_reply_list');
|
|
|
|
|
$timeout(function () {
|
|
|
|
|
$('html,body').animate({scrollTop: element[0].offsetTop - 60}, 200);
|
|
|
|
|
}, 10);
|
|
|
|
|
};
|
|
|
|
|
|
2017-07-18 17:02:25 +08:00
|
|
|
/**
|
|
|
|
|
* buildPager
|
|
|
|
|
* pagination init
|
|
|
|
|
*/
|
|
|
|
|
vm.buildPager = function () {
|
2017-07-18 17:08:33 +08:00
|
|
|
vm.pagedItems = [];
|
2017-09-01 11:34:00 +08:00
|
|
|
vm.itemsPerPage = vm.itemsPerPageConfig.repliesPerPage;
|
2017-07-18 17:08:33 +08:00
|
|
|
vm.currentPage = 1;
|
2017-07-18 17:02:25 +08:00
|
|
|
vm.figureOutItemsToDisplay();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* figureOutItemsToDisplay
|
|
|
|
|
* @param callback
|
|
|
|
|
*/
|
|
|
|
|
vm.figureOutItemsToDisplay = function (callback) {
|
|
|
|
|
vm.filterLength = vm.topic._replies.length;
|
|
|
|
|
var begin = ((vm.currentPage - 1) * vm.itemsPerPage);
|
|
|
|
|
var end = begin + vm.itemsPerPage;
|
|
|
|
|
vm.pagedItems = vm.topic._replies.slice(begin, end);
|
|
|
|
|
|
|
|
|
|
if (callback) callback();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* pageChanged
|
|
|
|
|
*/
|
|
|
|
|
vm.pageChanged = function () {
|
|
|
|
|
var element = angular.element('#top_of_reply_list');
|
|
|
|
|
|
|
|
|
|
vm.figureOutItemsToDisplay(function () {
|
|
|
|
|
$timeout(function () {
|
|
|
|
|
$('html,body').animate({scrollTop: element[0].offsetTop - 60}, 200);
|
|
|
|
|
}, 10);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2017-07-08 01:40:20 +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}});
|
2017-07-08 01:40:20 +08:00
|
|
|
|
2017-12-04 16:39:37 +08:00
|
|
|
// get topics
|
|
|
|
|
TopicsService.get({
|
|
|
|
|
forumId: $stateParams.forumId,
|
|
|
|
|
topicId: $stateParams.topicId
|
|
|
|
|
}, function (topic) {
|
|
|
|
|
mtDebug.info(topic);
|
2018-05-05 20:05:47 +08:00
|
|
|
vm.topic = topic;
|
2017-12-04 16:39:37 +08:00
|
|
|
vm.buildPager();
|
|
|
|
|
|
|
|
|
|
vm.forumPath.push({name: topic.title, state: undefined});
|
|
|
|
|
});
|
|
|
|
|
}, function (res) {
|
|
|
|
|
if (typeof res.data.redirect == 'string') {
|
|
|
|
|
$state.go(res.data.redirect);
|
|
|
|
|
}
|
2017-07-08 01:40:20 +08:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2017-07-08 10:17:20 +08:00
|
|
|
/**
|
|
|
|
|
* getTopicContent
|
|
|
|
|
* @param t
|
|
|
|
|
* @returns {*}
|
|
|
|
|
*/
|
|
|
|
|
vm.getTopicContent = function (t) {
|
|
|
|
|
if (t) {
|
|
|
|
|
return marked(t.content, {sanitize: true});
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-07-08 10:26:22 +08:00
|
|
|
|
2017-11-08 16:45:31 +08:00
|
|
|
/**
|
|
|
|
|
* getUserSignatureMarked
|
|
|
|
|
* @param u
|
|
|
|
|
* @returns {*}
|
|
|
|
|
*/
|
|
|
|
|
vm.getUserSignatureMarked = function (u) {
|
|
|
|
|
if (u) {
|
|
|
|
|
return marked(u.signature, {sanitize: true});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-07-08 10:26:22 +08:00
|
|
|
/**
|
|
|
|
|
* getUserScoreLevel
|
|
|
|
|
* @param u
|
|
|
|
|
* @returns {*|l}
|
|
|
|
|
*/
|
|
|
|
|
vm.getUserScoreLevel = function (u) {
|
|
|
|
|
var s = ScoreLevelService.getScoreLevelJson(vm.user.score);
|
|
|
|
|
return s.currLevel;
|
|
|
|
|
};
|
2017-07-08 18:52:21 +08:00
|
|
|
|
|
|
|
|
/**
|
2017-07-16 15:45:52 +08:00
|
|
|
* isOwner
|
|
|
|
|
* @param o, topic or reply
|
2017-07-08 18:52:21 +08:00
|
|
|
* @returns {boolean}
|
|
|
|
|
*/
|
2017-07-16 15:45:52 +08:00
|
|
|
vm.isOwner = function (o) {
|
|
|
|
|
if (o) {
|
2017-11-16 18:26:51 +08:00
|
|
|
if (o.user._id === vm.user._id) {
|
2017-07-09 16:29:35 +08:00
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-07-16 15:45:52 +08:00
|
|
|
} else {
|
|
|
|
|
return false;
|
2017-07-08 18:52:21 +08:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-07-09 21:22:26 +08:00
|
|
|
/**
|
|
|
|
|
* isModerator
|
|
|
|
|
* @returns {boolean}
|
|
|
|
|
*/
|
|
|
|
|
vm.isModerator = function () {
|
|
|
|
|
var isM = false;
|
|
|
|
|
|
2017-07-10 15:49:47 +08:00
|
|
|
if (vm.forum) {
|
2017-07-10 15:48:43 +08:00
|
|
|
angular.forEach(vm.forum.moderators, function (m) {
|
|
|
|
|
if (m._id === vm.user._id) {
|
|
|
|
|
isM = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-07-09 21:22:26 +08:00
|
|
|
return isM;
|
|
|
|
|
};
|
|
|
|
|
|
2017-07-08 18:52:21 +08:00
|
|
|
/**
|
2017-07-16 15:45:52 +08:00
|
|
|
* canEdit
|
2017-07-08 18:52:21 +08:00
|
|
|
* @returns {boolean}
|
|
|
|
|
*/
|
2017-07-16 15:45:52 +08:00
|
|
|
vm.canEdit = function () {
|
|
|
|
|
if (vm.user.isOper) {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (vm.isModerator()) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
2017-07-08 18:52:21 +08:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-12-07 17:47:05 +08:00
|
|
|
/**
|
|
|
|
|
* onTopicTitleEdited
|
|
|
|
|
*/
|
|
|
|
|
$scope.onTopicTitleEdited = function (modifyed) {
|
|
|
|
|
if (vm.topic && modifyed) {
|
|
|
|
|
vm.topic.$update(function (res) {
|
2018-05-05 20:05:47 +08:00
|
|
|
vm.topic = res;
|
2017-12-07 17:47:05 +08:00
|
|
|
NotifycationService.showSuccessNotify('FORUMS.TOPIC_EDIT_SUCCESSFULLY');
|
|
|
|
|
}, function (res) {
|
|
|
|
|
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.TOPIC_EDIT_FAILED');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-07-08 18:52:21 +08:00
|
|
|
/**
|
2017-07-08 20:22:38 +08:00
|
|
|
* beginEditTopic
|
2017-07-08 18:52:21 +08:00
|
|
|
* @param t
|
|
|
|
|
*/
|
2017-07-08 20:22:38 +08:00
|
|
|
vm.beginEditTopic = function (t) {
|
2017-07-08 18:52:21 +08:00
|
|
|
var el = $('#' + t._id);
|
|
|
|
|
|
|
|
|
|
el.markdown({
|
|
|
|
|
autofocus: true,
|
|
|
|
|
savable: true,
|
|
|
|
|
hideable: true,
|
|
|
|
|
iconlibrary: 'fa',
|
|
|
|
|
resize: 'vertical',
|
|
|
|
|
language: localStorageService.get('storage_user_lang'),
|
|
|
|
|
fullscreen: {enable: false},
|
|
|
|
|
onSave: function (e) {
|
|
|
|
|
if (e.isDirty()) {
|
|
|
|
|
//save content
|
|
|
|
|
t.content = e.getContent();
|
|
|
|
|
t.$update(function (res) {
|
2018-05-05 20:05:47 +08:00
|
|
|
vm.topic = res;
|
2017-10-13 17:52:05 +08:00
|
|
|
vm.figureOutItemsToDisplay();
|
2017-07-09 17:29:12 +08:00
|
|
|
NotifycationService.showSuccessNotify('FORUMS.TOPIC_EDIT_SUCCESSFULLY');
|
2017-07-08 18:52:21 +08:00
|
|
|
}, function (res) {
|
2017-07-09 17:29:12 +08:00
|
|
|
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.TOPIC_EDIT_FAILED');
|
2017-07-08 18:52:21 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
e.$options.hideable = true;
|
|
|
|
|
e.blur();
|
|
|
|
|
} else {
|
|
|
|
|
e.$options.hideable = true;
|
|
|
|
|
e.blur();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
onChange: function (e) {
|
|
|
|
|
e.$options.hideable = false;
|
|
|
|
|
},
|
|
|
|
|
onShow: function (e) {
|
2017-12-14 13:32:38 +08:00
|
|
|
$('#' + e.$editor.attr('id') + ' .md-input').textcomplete([
|
2017-12-09 23:16:34 +08:00
|
|
|
{ // emoji strategy
|
|
|
|
|
match: /\B:([\-+\w]*)$/,
|
|
|
|
|
search: function (term, callback) {
|
|
|
|
|
callback($.map(window.emojies, function (emoji) {
|
|
|
|
|
return emoji.indexOf(term) === 0 ? emoji : null;
|
|
|
|
|
}));
|
|
|
|
|
},
|
|
|
|
|
template: function (value) {
|
|
|
|
|
return '<img class="ac-emoji" src="/graphics/emojis/' + value + '.png" />' + '<span class="ac-emoji-text">' + value + '</span>';
|
|
|
|
|
},
|
|
|
|
|
replace: function (value) {
|
|
|
|
|
return ':' + value + ': ';
|
|
|
|
|
},
|
|
|
|
|
index: 1
|
|
|
|
|
}
|
|
|
|
|
]);
|
|
|
|
|
|
2017-07-08 18:52:21 +08:00
|
|
|
e.setContent(t.content);
|
2017-12-14 13:32:38 +08:00
|
|
|
$('#' + e.$editor.attr('id') + ' .md-input').attr('maxlength', vm.inputLengthConfig.forumTopicContentLength);
|
|
|
|
|
|
|
|
|
|
var inputInfo = angular.element('<span></span>');
|
|
|
|
|
inputInfo.addClass('pull-right');
|
|
|
|
|
inputInfo.addClass('input-length');
|
|
|
|
|
inputInfo.text(e.getContent().length + '/' + vm.inputLengthConfig.forumTopicContentLength);
|
|
|
|
|
$('#' + e.$editor.attr('id') + ' .md-header').append(inputInfo);
|
|
|
|
|
$('#' + e.$editor.attr('id') + ' .md-input').on('input propertychange', function (evt) {
|
|
|
|
|
inputInfo.text(e.getContent().length + '/' + vm.inputLengthConfig.forumTopicContentLength);
|
|
|
|
|
});
|
2017-07-08 18:52:21 +08:00
|
|
|
|
2017-12-14 13:32:38 +08:00
|
|
|
var ele = $('#' + e.$editor.attr('id') + ' .md-footer');
|
|
|
|
|
angular.element(ele).addClass('text-right');
|
2018-06-18 20:32:11 +08:00
|
|
|
angular.element(ele[0].childNodes[0]).addClass('btn-min-width-80');
|
2017-12-14 13:32:38 +08:00
|
|
|
ele[0].childNodes[0].innerText = $translate.instant('FORUMS.BTN_SAVE');
|
2017-07-08 18:52:21 +08:00
|
|
|
|
2018-06-18 20:32:11 +08:00
|
|
|
var cbtn = angular.element('<button class="btn btn-default btn-min-width-80 margin-left-10">' + $translate.instant('FORUMS.BTN_CANCEL') + '</button>');
|
2017-07-09 17:54:31 +08:00
|
|
|
cbtn.bind('click', function (evt) {
|
2017-07-09 19:37:12 +08:00
|
|
|
e.setContent(t.content);
|
2017-07-09 17:54:31 +08:00
|
|
|
e.$options.hideable = true;
|
|
|
|
|
e.blur();
|
|
|
|
|
});
|
2017-12-14 13:32:38 +08:00
|
|
|
|
|
|
|
|
ele.append(cbtn);
|
|
|
|
|
$compile(e.$editor.contents())($scope);
|
2017-12-10 16:18:29 +08:00
|
|
|
},
|
|
|
|
|
onPreview: function (e) {
|
2017-12-14 13:32:38 +08:00
|
|
|
$('#' + e.$editor.attr('id') + ' .md-footer').css('display', 'none');
|
2017-12-10 16:18:29 +08:00
|
|
|
},
|
|
|
|
|
onPreviewEnd: function (e) {
|
2017-12-14 13:32:38 +08:00
|
|
|
$('#' + e.$editor.attr('id') + ' .md-footer').css('display', 'block');
|
2017-07-09 17:54:31 +08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* beginEditReply
|
|
|
|
|
* @param r
|
|
|
|
|
*/
|
|
|
|
|
vm.beginEditReply = function (r) {
|
|
|
|
|
var el = $('#' + r._id);
|
|
|
|
|
|
|
|
|
|
el.markdown({
|
|
|
|
|
autofocus: true,
|
|
|
|
|
savable: true,
|
|
|
|
|
hideable: true,
|
|
|
|
|
iconlibrary: 'fa',
|
|
|
|
|
resize: 'vertical',
|
|
|
|
|
language: localStorageService.get('storage_user_lang'),
|
|
|
|
|
fullscreen: {enable: false},
|
|
|
|
|
onSave: function (e) {
|
|
|
|
|
if (e.isDirty()) {
|
|
|
|
|
//save content
|
|
|
|
|
var rep = new RepliesService({
|
|
|
|
|
forum: vm.forum._id,
|
|
|
|
|
topic: vm.topic._id,
|
|
|
|
|
_id: r._id,
|
|
|
|
|
content: e.getContent()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
rep.$update(function (res) {
|
2018-05-05 20:05:47 +08:00
|
|
|
vm.topic = res;
|
2017-10-13 17:52:05 +08:00
|
|
|
vm.figureOutItemsToDisplay();
|
2017-07-09 17:54:31 +08:00
|
|
|
NotifycationService.showSuccessNotify('FORUMS.REPLY_EDIT_SUCCESSFULLY');
|
|
|
|
|
}, function (res) {
|
2018-04-16 18:20:22 +08:00
|
|
|
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.REPLY_EDIT_FAILED');
|
2017-07-09 17:54:31 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
e.$options.hideable = true;
|
|
|
|
|
e.blur();
|
|
|
|
|
} else {
|
|
|
|
|
e.$options.hideable = true;
|
|
|
|
|
e.blur();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
onChange: function (e) {
|
|
|
|
|
e.$options.hideable = false;
|
|
|
|
|
},
|
|
|
|
|
onShow: function (e) {
|
2017-12-14 13:32:38 +08:00
|
|
|
$('#' + e.$editor.attr('id') + ' .md-input').textcomplete([
|
2017-12-09 23:16:34 +08:00
|
|
|
{ // emoji strategy
|
|
|
|
|
match: /\B:([\-+\w]*)$/,
|
|
|
|
|
search: function (term, callback) {
|
|
|
|
|
callback($.map(window.emojies, function (emoji) {
|
|
|
|
|
return emoji.indexOf(term) === 0 ? emoji : null;
|
|
|
|
|
}));
|
|
|
|
|
},
|
|
|
|
|
template: function (value) {
|
|
|
|
|
return '<img class="ac-emoji" src="/graphics/emojis/' + value + '.png" />' + '<span class="ac-emoji-text">' + value + '</span>';
|
|
|
|
|
},
|
|
|
|
|
replace: function (value) {
|
|
|
|
|
return ':' + value + ': ';
|
|
|
|
|
},
|
|
|
|
|
index: 1
|
|
|
|
|
}
|
|
|
|
|
]);
|
|
|
|
|
|
2017-07-09 17:54:31 +08:00
|
|
|
e.setContent(r.content);
|
2017-12-14 13:32:38 +08:00
|
|
|
$('#' + e.$editor.attr('id') + ' .md-input').attr('maxlength', vm.inputLengthConfig.forumReplyContentLength);
|
|
|
|
|
|
|
|
|
|
var inputInfo = angular.element('<span></span>');
|
|
|
|
|
inputInfo.addClass('pull-right');
|
|
|
|
|
inputInfo.addClass('input-length');
|
|
|
|
|
inputInfo.text(e.getContent().length + '/' + vm.inputLengthConfig.forumReplyContentLength);
|
|
|
|
|
$('#' + e.$editor.attr('id') + ' .md-header').append(inputInfo);
|
|
|
|
|
$('#' + e.$editor.attr('id') + ' .md-input').on('input propertychange', function (evt) {
|
|
|
|
|
inputInfo.text(e.getContent().length + '/' + vm.inputLengthConfig.forumReplyContentLength);
|
|
|
|
|
});
|
2017-07-09 17:54:31 +08:00
|
|
|
|
2017-12-14 13:32:38 +08:00
|
|
|
var ele = $('#' + e.$editor.attr('id') + ' .md-footer');
|
2017-07-11 10:05:48 +08:00
|
|
|
angular.element(ele).addClass('text-right');
|
2018-06-18 20:32:11 +08:00
|
|
|
angular.element(ele[0].childNodes[0]).addClass('btn-min-width-80');
|
2017-07-11 10:05:48 +08:00
|
|
|
ele[0].childNodes[0].innerText = $translate.instant('FORUMS.BTN_SAVE');
|
2017-07-09 17:54:31 +08:00
|
|
|
|
2018-06-18 20:32:11 +08:00
|
|
|
var cbtn = angular.element('<button class="btn btn-default btn-min-width-80 margin-left-10">' + $translate.instant('FORUMS.BTN_CANCEL') + '</button>');
|
2017-07-08 18:52:21 +08:00
|
|
|
cbtn.bind('click', function (evt) {
|
2017-07-09 19:37:12 +08:00
|
|
|
e.setContent(r.content);
|
2017-07-08 18:52:21 +08:00
|
|
|
e.$options.hideable = true;
|
|
|
|
|
e.blur();
|
|
|
|
|
});
|
2017-12-14 13:32:38 +08:00
|
|
|
|
2017-07-11 10:05:48 +08:00
|
|
|
ele.append(cbtn);
|
2017-12-14 13:32:38 +08:00
|
|
|
$compile(e.$editor.contents())($scope);
|
2017-12-10 16:18:29 +08:00
|
|
|
},
|
|
|
|
|
onPreview: function (e) {
|
2017-12-14 13:32:38 +08:00
|
|
|
$('#' + e.$editor.attr('id') + ' .md-footer').css('display', 'none');
|
2017-12-10 16:18:29 +08:00
|
|
|
},
|
|
|
|
|
onPreviewEnd: function (e) {
|
2017-12-14 13:32:38 +08:00
|
|
|
$('#' + e.$editor.attr('id') + ' .md-footer').css('display', 'block');
|
2017-07-08 18:52:21 +08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
2017-07-08 20:22:38 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* beginDeleteTopic
|
|
|
|
|
* @param t
|
|
|
|
|
*/
|
|
|
|
|
vm.beginDeleteTopic = function (t) {
|
|
|
|
|
var modalOptions = {
|
|
|
|
|
closeButtonText: $translate.instant('FORUMS.DELETE_TOPIC_CONFIRM_CANCEL'),
|
|
|
|
|
actionButtonText: $translate.instant('FORUMS.DELETE_TOPIC_CONFIRM_OK'),
|
|
|
|
|
headerText: $translate.instant('FORUMS.DELETE_TOPIC_CONFIRM_HEADER_TEXT'),
|
|
|
|
|
bodyText: $translate.instant('FORUMS.DELETE_TOPIC_CONFIRM_BODY_TEXT')
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ModalConfirmService.showModal({}, modalOptions)
|
|
|
|
|
.then(function (result) {
|
|
|
|
|
vm.topic.$remove(function (res) {
|
|
|
|
|
NotifycationService.showSuccessNotify('FORUMS.DELETE_TOPIC_SUCCESSFULLY');
|
|
|
|
|
$state.go('forums.view', {forumId: vm.forum._id});
|
|
|
|
|
}, function (res) {
|
|
|
|
|
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.DELETE_TOPIC_FAILED');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
2017-07-09 16:29:35 +08:00
|
|
|
|
2017-07-15 13:38:26 +08:00
|
|
|
/**
|
|
|
|
|
* beginTopTopic
|
|
|
|
|
* @param t
|
|
|
|
|
*/
|
|
|
|
|
vm.beginTopTopic = function (t) {
|
|
|
|
|
var topic = new TopicsService({
|
|
|
|
|
forum: vm.forum._id,
|
|
|
|
|
_id: t._id
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
topic.$toggleTopicTopStatus(function (res) {
|
2018-05-05 20:05:47 +08:00
|
|
|
vm.topic = res;
|
2017-07-15 13:38:26 +08:00
|
|
|
NotifycationService.showSuccessNotify('FORUMS.TOPIC_TOGGLE_TOP_SUCCESSFULLY');
|
|
|
|
|
}, function (res) {
|
|
|
|
|
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.TOPIC_TOGGLE_TOP_FAILED');
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2017-07-15 14:23:00 +08:00
|
|
|
/**
|
|
|
|
|
* beginGlobalTopic
|
|
|
|
|
* @param t
|
|
|
|
|
*/
|
|
|
|
|
vm.beginGlobalTopic = function (t) {
|
|
|
|
|
var topic = new TopicsService({
|
|
|
|
|
forum: vm.forum._id,
|
|
|
|
|
_id: t._id
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
topic.$toggleTopicGlobalStatus(function (res) {
|
2018-05-05 20:05:47 +08:00
|
|
|
vm.topic = res;
|
2017-07-15 14:23:00 +08:00
|
|
|
NotifycationService.showSuccessNotify('FORUMS.TOPIC_TOGGLE_GLOBAL_SUCCESSFULLY');
|
|
|
|
|
}, function (res) {
|
|
|
|
|
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.TOPIC_TOGGLE_GLOBAL_FAILED');
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2018-01-23 11:37:01 +08:00
|
|
|
/**
|
|
|
|
|
* beginHomeHelpTopic
|
|
|
|
|
* @param t
|
|
|
|
|
*/
|
|
|
|
|
vm.beginHomeHelpTopic = function (t) {
|
|
|
|
|
var topic = new TopicsService({
|
|
|
|
|
forum: vm.forum._id,
|
|
|
|
|
_id: t._id
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
topic.$toggleTopicHomeHelpStatus(function (res) {
|
2018-05-05 20:05:47 +08:00
|
|
|
vm.topic = res;
|
2018-01-23 11:37:01 +08:00
|
|
|
NotifycationService.showSuccessNotify('FORUMS.TOPIC_TOGGLE_HOME_HELP_SUCCESSFULLY');
|
|
|
|
|
}, function (res) {
|
|
|
|
|
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.TOPIC_TOGGLE_HOME_HELP_FAILED');
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* beginHomeNoticeTopic
|
|
|
|
|
* @param t
|
|
|
|
|
*/
|
|
|
|
|
vm.beginHomeNoticeTopic = function (t) {
|
|
|
|
|
var topic = new TopicsService({
|
|
|
|
|
forum: vm.forum._id,
|
|
|
|
|
_id: t._id
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
topic.$toggleTopicHomeNoticeStatus(function (res) {
|
2018-05-05 20:05:47 +08:00
|
|
|
vm.topic = res;
|
2018-01-23 11:37:01 +08:00
|
|
|
NotifycationService.showSuccessNotify('FORUMS.TOPIC_TOGGLE_HOME_NOTICE_SUCCESSFULLY');
|
|
|
|
|
}, function (res) {
|
|
|
|
|
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.TOPIC_TOGGLE_HOME_NOTICE_FAILED');
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2017-07-09 17:29:12 +08:00
|
|
|
/**
|
|
|
|
|
* beginDeleteReply
|
|
|
|
|
* @param reply
|
|
|
|
|
*/
|
|
|
|
|
vm.beginDeleteReply = function (reply) {
|
|
|
|
|
var modalOptions = {
|
|
|
|
|
closeButtonText: $translate.instant('FORUMS.DELETE_TOPIC_CONFIRM_CANCEL'),
|
|
|
|
|
actionButtonText: $translate.instant('FORUMS.DELETE_TOPIC_CONFIRM_OK'),
|
|
|
|
|
headerText: $translate.instant('FORUMS.DELETE_REPLY_CONFIRM_HEADER_TEXT'),
|
|
|
|
|
bodyText: $translate.instant('FORUMS.DELETE_REPLY_CONFIRM_BODY_TEXT')
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ModalConfirmService.showModal({}, modalOptions)
|
|
|
|
|
.then(function (result) {
|
|
|
|
|
RepliesService.remove({
|
|
|
|
|
forumId: vm.forum._id,
|
|
|
|
|
topicId: vm.topic._id,
|
|
|
|
|
replyId: reply._id
|
|
|
|
|
}, function (res) {
|
2018-05-05 20:05:47 +08:00
|
|
|
vm.topic = res;
|
2017-07-18 19:00:30 +08:00
|
|
|
vm.figureOutItemsToDisplay();
|
2017-07-09 17:29:12 +08:00
|
|
|
NotifycationService.showSuccessNotify('FORUMS.DELETE_REPLY_SUCCESSFULLY');
|
|
|
|
|
}, function (res) {
|
|
|
|
|
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.DELETE_REPLY_FAILED');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2017-07-09 16:29:35 +08:00
|
|
|
/**
|
|
|
|
|
* beginPostReply
|
|
|
|
|
*/
|
|
|
|
|
vm.beginPostReply = function () {
|
|
|
|
|
$('#postReplyContent').focus();
|
2017-07-09 19:37:12 +08:00
|
|
|
$timeout(function () {
|
2017-12-14 10:35:36 +08:00
|
|
|
$('html,body').animate({scrollTop: $('#post-new-reply-table')[0].offsetTop - 60}, 200);
|
|
|
|
|
}, 10);
|
2017-07-09 16:29:35 +08:00
|
|
|
};
|
|
|
|
|
|
2017-07-11 11:48:28 +08:00
|
|
|
/**
|
|
|
|
|
* toggleReadonly
|
|
|
|
|
* @param t
|
|
|
|
|
*/
|
|
|
|
|
vm.toggleReadonly = function (t) {
|
|
|
|
|
var topic = new TopicsService({
|
|
|
|
|
forum: vm.forum._id,
|
|
|
|
|
_id: t._id
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
topic.$toggleTopicReadonly(function (res) {
|
2018-05-05 20:05:47 +08:00
|
|
|
vm.topic = res;
|
2017-07-11 11:48:28 +08:00
|
|
|
NotifycationService.showSuccessNotify('FORUMS.TOPIC_TOGGLE_READONLY_SUCCESSFULLY');
|
|
|
|
|
}, function (res) {
|
|
|
|
|
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.TOPIC_TOGGLE_READONLY_FAILED');
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2017-07-09 16:29:35 +08:00
|
|
|
/**
|
|
|
|
|
* postReply
|
|
|
|
|
* @param isValid
|
|
|
|
|
* @returns {boolean}
|
|
|
|
|
*/
|
|
|
|
|
vm.postReply = function (isValid) {
|
|
|
|
|
if (!isValid) {
|
|
|
|
|
$scope.$broadcast('show-errors-check-validity', 'vm.replyForm');
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-28 18:31:49 +08:00
|
|
|
mtDebug.info($scope.uFiles);
|
2017-07-14 12:30:42 +08:00
|
|
|
var uf = [];
|
|
|
|
|
angular.forEach($scope.uFiles, function (f) {
|
|
|
|
|
uf.push({
|
|
|
|
|
filename: f.name,
|
|
|
|
|
filesize: f.size
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-09-28 18:31:49 +08:00
|
|
|
mtDebug.info($scope.uImages);
|
2017-07-14 12:30:42 +08:00
|
|
|
var uimg = [];
|
|
|
|
|
angular.forEach($scope.uImages, function (f) {
|
|
|
|
|
uimg.push({
|
|
|
|
|
filename: f.name
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-07-09 16:29:35 +08:00
|
|
|
var reply = new RepliesService(vm.postReplyFields);
|
|
|
|
|
reply.forum = vm.forum._id;
|
|
|
|
|
reply.topic = vm.topic._id;
|
2017-07-14 12:30:42 +08:00
|
|
|
reply._attach = uf;
|
|
|
|
|
reply._uImage = uimg;
|
2017-07-09 16:29:35 +08:00
|
|
|
|
|
|
|
|
reply.$save(function (response) {
|
|
|
|
|
successCallback(response);
|
|
|
|
|
}, function (errorResponse) {
|
|
|
|
|
errorCallback(errorResponse);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function successCallback(res) {
|
|
|
|
|
vm.postReplyFields = {};
|
2017-07-18 18:26:14 +08:00
|
|
|
vm.currentPage = Math.ceil(res._replies.length / vm.itemsPerPage);
|
2018-05-05 20:05:47 +08:00
|
|
|
vm.topic = res;
|
2017-07-18 19:00:30 +08:00
|
|
|
vm.pageChanged();
|
2017-07-14 12:30:42 +08:00
|
|
|
|
2017-07-09 16:29:35 +08:00
|
|
|
$scope.$broadcast('show-errors-reset', 'vm.replyForm');
|
2018-05-30 19:11:36 +08:00
|
|
|
$scope.clearAttach();
|
2018-01-21 16:02:02 +08:00
|
|
|
$scope.hidePreview();
|
2017-07-09 16:29:35 +08:00
|
|
|
NotifycationService.showSuccessNotify('FORUMS.POST_REPLY_SUCCESSFULLY');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function errorCallback(res) {
|
|
|
|
|
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.POST_REPLY_FAILED');
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-07-09 19:37:12 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* quoteAndReply
|
|
|
|
|
* @param obj, topic or reply object, need the content field
|
|
|
|
|
*/
|
|
|
|
|
vm.quoteAndReply = function (obj) {
|
2017-12-10 15:37:21 +08:00
|
|
|
var by = obj.user.displayName + ' at ' + $filter('date')((obj.updatedAt ? obj.updatedAt : obj.createdAt), 'yyyy-MM-dd HH:mm');
|
2017-07-09 19:37:12 +08:00
|
|
|
by = '_' + by + '_' + '\n\n';
|
|
|
|
|
var list = [];
|
|
|
|
|
|
|
|
|
|
list = obj.content.split('\n');
|
|
|
|
|
list.push(by);
|
|
|
|
|
|
|
|
|
|
$.each(list, function (k, v) {
|
|
|
|
|
list[k] = '> ' + v;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
vm.postReplyFields.content = list.join('\n');
|
|
|
|
|
vm.beginPostReply();
|
|
|
|
|
};
|
2017-07-12 12:12:13 +08:00
|
|
|
|
|
|
|
|
/**
|
2017-07-14 18:36:09 +08:00
|
|
|
* function
|
|
|
|
|
* @param evt
|
|
|
|
|
* @param t
|
|
|
|
|
* @param r
|
2017-07-12 12:12:13 +08:00
|
|
|
*/
|
2017-07-14 18:36:09 +08:00
|
|
|
vm.beginThumbsUp = function (evt, t, r) {
|
2017-07-12 12:12:13 +08:00
|
|
|
var topic = new TopicsService({
|
|
|
|
|
forum: vm.forum._id,
|
|
|
|
|
_id: t._id,
|
|
|
|
|
_replyId: r ? r._id : undefined
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
topic.$thumbsUp(function (res) {
|
2018-05-05 20:05:47 +08:00
|
|
|
vm.topic = res;
|
2017-07-18 19:00:30 +08:00
|
|
|
vm.figureOutItemsToDisplay();
|
2017-07-14 18:36:09 +08:00
|
|
|
|
|
|
|
|
$timeout(function () {
|
|
|
|
|
var ele = angular.element($('#thumbs_' + (r ? r._id : t._id)));
|
|
|
|
|
ele.attr('mt-scale-start', true);
|
|
|
|
|
$compile(ele)($scope);
|
|
|
|
|
}, 10);
|
|
|
|
|
}, function (res) {
|
2017-11-18 10:57:39 +08:00
|
|
|
NotifycationService.showErrorNotify($translate.instant(res.data.message), 'ERROR');
|
2017-07-12 12:12:13 +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-08 01:40:20 +08:00
|
|
|
}
|
|
|
|
|
}());
|