-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
move.js
102 lines (81 loc) · 2.54 KB
/
move.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
'use strict';
define('forum/topic/move', ['categorySelector', 'alerts'], function (categorySelector, alerts) {
var Move = {};
var modal;
var selectedCategory;
Move.init = function (tids, currentCid, onComplete) {
Move.tids = tids;
Move.currentCid = currentCid;
Move.onComplete = onComplete;
Move.moveAll = !tids;
socket.emit('categories.getMoveCategories', onCategoriesLoaded);
};
function onCategoriesLoaded(err, categories) {
if (err) {
return app.alertError(err.message);
}
app.parseAndTranslate('partials/move_thread_modal', {
categories: categories,
}, function (html) {
modal = $(html);
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]]');
}
categorySelector.init(modal.find('[component="category-selector"]'), onCategorySelected);
modal.find('#move_thread_commit').on('click', onCommitClicked);
modal.modal('show');
});
}
function onCategorySelected(category) {
selectedCategory = category;
modal.find('#move_thread_commit').prop('disabled', false);
}
function onCommitClicked() {
var commitEl = modal.find('#move_thread_commit');
if (!commitEl.prop('disabled') && selectedCategory && selectedCategory.cid) {
commitEl.prop('disabled', true);
modal.modal('hide');
var message = '[[topic:topic_move_success, ' + selectedCategory.name + ']]';
if (Move.tids && Move.tids.length > 1) {
message = '[[topic:topic_move_multiple_success, ' + selectedCategory.name + ']]';
} else if (!Move.tids) {
message = '[[topic:topic_move_all_success, ' + selectedCategory.name + ']]';
}
alerts.alert({
alert_id: 'tids_move_' + (Move.tids ? Move.tids.join('-') : 'all'),
title: '[[topic:thread_tools.move]]',
message: message,
type: 'success',
timeout: 10000,
timeoutfn: function () {
moveTopics();
},
clickfn: function (alert, params) {
delete params.timeoutfn;
app.alertSuccess('[[topic:topic_move_undone]]');
},
});
}
}
function moveTopics() {
var data = {
tids: Move.tids,
cid: selectedCategory.cid,
currentCid: Move.currentCid,
};
$(window).trigger('action:topic.move', data);
socket.emit(Move.moveAll ? 'topics.moveAll' : 'topics.move', data, function (err) {
if (err) {
return app.alertError(err.message);
}
if (typeof Move.onComplete === 'function') {
Move.onComplete();
}
});
}
return Move;
});