feat(forums): topic owner or oper can edit topic content now

This commit is contained in:
OldHawk
2017-07-08 18:52:21 +08:00
parent 8122a2c539
commit 3366ce0e8e
11 changed files with 173 additions and 22 deletions

View File

@@ -6,10 +6,10 @@
.controller('ForumsTopicController', ForumsTopicController);
ForumsTopicController.$inject = ['$scope', '$state', '$translate', 'Authentication', 'MeanTorrentConfig', 'ForumsService', 'ScoreLevelService', '$filter', 'NotifycationService',
'marked', 'ModalConfirmService', '$stateParams', 'TopicsService'];
'marked', 'ModalConfirmService', '$stateParams', 'TopicsService', 'localStorageService', '$compile'];
function ForumsTopicController($scope, $state, $translate, Authentication, MeanTorrentConfig, ForumsService, ScoreLevelService, $filter, NotifycationService,
marked, ModalConfirmService, $stateParams, TopicsService) {
marked, ModalConfirmService, $stateParams, TopicsService, localStorageService, $compile) {
var vm = this;
vm.forumsConfig = MeanTorrentConfig.meanTorrentConfig.forumsConfig;
vm.user = Authentication.user;
@@ -68,5 +68,84 @@
var s = ScoreLevelService.getScoreLevelJson(vm.user.score);
return s.currLevel;
};
/**
* isTopicOwner
* @param t
* @returns {boolean}
*/
vm.isTopicOwner = function (t) {
if (t.user._id.str === vm.user._id) {
return true;
} else {
return false;
}
};
/**
* canEditTopic
* @param t
* @returns {boolean}
*/
vm.canEditTopic = function (t) {
if (vm.isTopicOwner(t) || vm.user.isOper) {
return true;
} else {
return false;
}
};
/**
* beginEditReply
* @param t
*/
vm.beginEditReply = function (t) {
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) {
vm.topic = res;
NotifycationService.showSuccessNotify('FORUMS.REPLY_EDIT_SUCCESSFULLY');
}, function (res) {
NotifycationService.showErrorNotify(res.data.message, 'FORUMS.REPLY_EDIT_FAILED');
});
e.$options.hideable = true;
e.blur();
} else {
e.$options.hideable = true;
e.blur();
}
},
onChange: function (e) {
e.$options.hideable = false;
},
onShow: function (e) {
e.setContent(t.content);
$('.md-footer').addClass('text-right');
$('.md-footer')[0].childNodes[0].innerText = $translate.instant('FORUMS.BTN_SAVE');
var cbtn = angular.element('<button class="btn btn-success margin-left-10">' + $translate.instant('FORUMS.BTN_CANCEL') + '</button>');
cbtn.bind('click', function (evt) {
e.$options.hideable = true;
e.blur();
});
$('.md-footer').append(cbtn);
$compile($('.md-footer').contents())($scope);
}
});
};
}
}());