|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
/* globals define, app, socket, templates */
|
|
|
|
|
/* globals define, app, socket, templates, translator */
|
|
|
|
|
|
|
|
|
|
define('forum/topic/move', function() {
|
|
|
|
|
|
|
|
|
@ -10,57 +10,59 @@ define('forum/topic/move', function() {
|
|
|
|
|
targetCategoryLabel;
|
|
|
|
|
|
|
|
|
|
Move.init = function(tids, currentCid, onComplete) {
|
|
|
|
|
modal = $('#move_thread_modal');
|
|
|
|
|
|
|
|
|
|
Move.tids = tids;
|
|
|
|
|
Move.currentCid = currentCid;
|
|
|
|
|
Move.onComplete = onComplete;
|
|
|
|
|
Move.moveAll = tids ? false : true;
|
|
|
|
|
|
|
|
|
|
modal.on('shown.bs.modal', onMoveModalShown);
|
|
|
|
|
$('#move-confirm').addClass('hide');
|
|
|
|
|
|
|
|
|
|
if (Move.moveAll || (tids && tids.length > 1)) {
|
|
|
|
|
modal.find('.modal-header h3').translateText('[[topic:move_topics]]');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
modal.modal('show');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function onMoveModalShown() {
|
|
|
|
|
var loadingEl = $('#categories-loading');
|
|
|
|
|
if (!loadingEl.length) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
socket.emit('categories.get', onCategoriesLoaded);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function onCategoriesLoaded(err, categories) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return app.alertError(err.message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderCategories(categories);
|
|
|
|
|
parseModal(categories, function(html) {
|
|
|
|
|
modal = $(html);
|
|
|
|
|
|
|
|
|
|
modal.on('click', '.category-list li[data-cid]', function(e) {
|
|
|
|
|
selectCategory($(this));
|
|
|
|
|
modal.on('hidden.bs.modal', function() {
|
|
|
|
|
modal.remove();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
modal.find('#move-confirm').addClass('hide');
|
|
|
|
|
|
|
|
|
|
if (Move.moveAll || (Move.tids && Move.tids.length > 1)) {
|
|
|
|
|
modal.find('.modal-header h3').translateText('[[topic:move_topics]]');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
modal.on('click', '.category-list li[data-cid]', function(e) {
|
|
|
|
|
selectCategory($(this));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
modal.find('#move_thread_commit').on('click', onCommitClicked);
|
|
|
|
|
|
|
|
|
|
modal.modal('show');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('#move_thread_commit').on('click', onCommitClicked);
|
|
|
|
|
function parseModal(categories, callback) {
|
|
|
|
|
templates.parse('partials/move_thread_modal', {categories: categories}, function(html) {
|
|
|
|
|
translator.translate(html, callback);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function selectCategory(category) {
|
|
|
|
|
modal.find('#confirm-category-name').html(category.html());
|
|
|
|
|
$('#move-confirm').removeClass('hide');
|
|
|
|
|
modal.find('#move-confirm').removeClass('hide');
|
|
|
|
|
|
|
|
|
|
targetCid = category.attr('data-cid');
|
|
|
|
|
targetCategoryLabel = category.html();
|
|
|
|
|
$('#move_thread_commit').prop('disabled', false);
|
|
|
|
|
modal.find('#move_thread_commit').prop('disabled', false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onCommitClicked() {
|
|
|
|
|
var commitEl = $('#move_thread_commit');
|
|
|
|
|
var commitEl = modal.find('#move_thread_commit');
|
|
|
|
|
|
|
|
|
|
if (!commitEl.prop('disabled') && targetCid) {
|
|
|
|
|
commitEl.prop('disabled', true);
|
|
|
|
@ -76,7 +78,6 @@ define('forum/topic/move', function() {
|
|
|
|
|
currentCid: Move.currentCid
|
|
|
|
|
}, function(err) {
|
|
|
|
|
modal.modal('hide');
|
|
|
|
|
$('#move_thread_commit').prop('disabled', false);
|
|
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
return app.alertError(err.message);
|
|
|
|
@ -89,12 +90,6 @@ define('forum/topic/move', function() {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderCategories(categories) {
|
|
|
|
|
templates.parse('partials/category_list', {categories: categories}, function(html) {
|
|
|
|
|
modal.find('.modal-body').prepend(html);
|
|
|
|
|
$('#categories-loading').remove();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Move;
|
|
|
|
|
});
|
|
|
|
|