|
|
@ -552,7 +552,53 @@ define([
|
|
|
|
var $div = $(h('div.cp-support-container')).appendTo($container);
|
|
|
|
var $div = $(h('div.cp-support-container')).appendTo($container);
|
|
|
|
|
|
|
|
|
|
|
|
var catContainer = h('div.cp-dropdown-container');
|
|
|
|
var catContainer = h('div.cp-dropdown-container');
|
|
|
|
$div.append(catContainer);
|
|
|
|
Messages.admin_support_premium = "Premium tickets:"; // XXX
|
|
|
|
|
|
|
|
Messages.admin_support_normal = "Unanswered tickets:";
|
|
|
|
|
|
|
|
Messages.admin_support_answered = "Answered tickets:";
|
|
|
|
|
|
|
|
Messages.admin_support_closed = "Closed tickets:";
|
|
|
|
|
|
|
|
Messages.admin_support_open = "Show";
|
|
|
|
|
|
|
|
Messages.admin_support_collapse = "Collapse";
|
|
|
|
|
|
|
|
Messages.admin_support_first = "Created on: ";
|
|
|
|
|
|
|
|
Messages.admin_support_last = "Updated on: ";
|
|
|
|
|
|
|
|
var col1 = h('div.cp-support-column', h('h1', [
|
|
|
|
|
|
|
|
h('span', Messages.admin_support_premium),
|
|
|
|
|
|
|
|
h('span.cp-support-count'),
|
|
|
|
|
|
|
|
h('button.btn.cp-support-column-button', Messages.admin_support_collapse)
|
|
|
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
var col2 = h('div.cp-support-column', h('h1', [
|
|
|
|
|
|
|
|
h('span', Messages.admin_support_normal),
|
|
|
|
|
|
|
|
h('span.cp-support-count'),
|
|
|
|
|
|
|
|
h('button.btn.cp-support-column-button', Messages.admin_support_collapse)
|
|
|
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
var col3 = h('div.cp-support-column', h('h1', [
|
|
|
|
|
|
|
|
h('span', Messages.admin_support_answered),
|
|
|
|
|
|
|
|
h('span.cp-support-count'),
|
|
|
|
|
|
|
|
h('button.btn.cp-support-column-button', Messages.admin_support_collapse)
|
|
|
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
var col4 = h('div.cp-support-column', h('h1', [
|
|
|
|
|
|
|
|
h('span', Messages.admin_support_closed),
|
|
|
|
|
|
|
|
h('span.cp-support-count'),
|
|
|
|
|
|
|
|
h('button.btn.cp-support-column-button', Messages.admin_support_collapse)
|
|
|
|
|
|
|
|
]));
|
|
|
|
|
|
|
|
var $col1 = $(col1), $col2 = $(col2), $col3 = $(col3), $col4 = $(col4);
|
|
|
|
|
|
|
|
$div.append([
|
|
|
|
|
|
|
|
//catContainer
|
|
|
|
|
|
|
|
col1,
|
|
|
|
|
|
|
|
col2,
|
|
|
|
|
|
|
|
col3,
|
|
|
|
|
|
|
|
col4
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
$div.find('.cp-support-column-button').click(function () {
|
|
|
|
|
|
|
|
var $col = $(this).closest('.cp-support-column');
|
|
|
|
|
|
|
|
$col.toggleClass('cp-support-column-collapsed');
|
|
|
|
|
|
|
|
if ($col.hasClass('cp-support-column-collapsed')) {
|
|
|
|
|
|
|
|
$(this).text(Messages.admin_support_open);
|
|
|
|
|
|
|
|
$(this).toggleClass('btn-primary');
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$(this).text(Messages.admin_support_collapse);
|
|
|
|
|
|
|
|
$(this).toggleClass('btn-primary');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
var category = 'all';
|
|
|
|
var category = 'all';
|
|
|
|
var $drop = APP.support.makeCategoryDropdown(catContainer, function (key) {
|
|
|
|
var $drop = APP.support.makeCategoryDropdown(catContainer, function (key) {
|
|
|
|
category = key;
|
|
|
|
category = key;
|
|
|
@ -572,37 +618,128 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
var hashesById = {};
|
|
|
|
var hashesById = {};
|
|
|
|
|
|
|
|
|
|
|
|
var reorder = function () {
|
|
|
|
var getTicketData = function (id) {
|
|
|
|
var order = Object.keys(hashesById);
|
|
|
|
var t = hashesById[id];
|
|
|
|
order.sort(function (id1, id2) {
|
|
|
|
if (!Array.isArray(t) || !t.length) { return; }
|
|
|
|
var t1 = hashesById[id1];
|
|
|
|
var ed = Util.find(t[0], ['content', 'msg', 'content', 'sender', 'edPublic']);
|
|
|
|
var t2 = hashesById[id2];
|
|
|
|
// If one of their ticket was sent as a premium user, mark them as premium
|
|
|
|
if (!Array.isArray(t1)) { return 1; }
|
|
|
|
var premium = t.some(function (msg) {
|
|
|
|
if (!Array.isArray(t2)) { return -1; }
|
|
|
|
var _ed = Util.find(msg, ['content', 'msg', 'content', 'sender', 'edPublic']);
|
|
|
|
var lastMsg1 = t1[t1.length - 1];
|
|
|
|
if (ed !== _ed) { return; }
|
|
|
|
var lastMsg2 = t2[t2.length - 1];
|
|
|
|
return Util.find(t[0], ['content', 'msg', 'content', 'sender', 'plan']);
|
|
|
|
var time1 = Util.find(lastMsg1, ['content', 'msg', 'content', 'time']);
|
|
|
|
});
|
|
|
|
var time2 = Util.find(lastMsg2, ['content', 'msg', 'content', 'time']);
|
|
|
|
var lastMsg = t[t.length - 1];
|
|
|
|
var authorEd1 = Util.find(lastMsg1, ['content', 'msg', 'content', 'sender', 'edPublic']);
|
|
|
|
var lastMsgEd = Util.find(lastMsg, ['content', 'msg', 'content', 'sender', 'edPublic']);
|
|
|
|
var authorEd2 = Util.find(lastMsg2, ['content', 'msg', 'content', 'sender', 'edPublic']);
|
|
|
|
return {
|
|
|
|
var admin1 = ApiConfig.adminKeys.indexOf(authorEd1) !== -1;
|
|
|
|
lastMsg: lastMsg,
|
|
|
|
var admin2 = ApiConfig.adminKeys.indexOf(authorEd2) !== -1;
|
|
|
|
time: Util.find(lastMsg, ['content', 'msg', 'content', 'time']),
|
|
|
|
// If one is answered and not the other, put the unanswered first
|
|
|
|
lastMsgEd: lastMsgEd,
|
|
|
|
if (admin1 && !admin2) { return 1; }
|
|
|
|
lastAdmin: lastMsgEd !== ed && ApiConfig.adminKeys.indexOf(lastMsgEd) !== -1,
|
|
|
|
if (!admin1 && admin2) { return -1; }
|
|
|
|
premium: premium,
|
|
|
|
// Otherwise, sort them by time
|
|
|
|
authorEd: ed,
|
|
|
|
return time2 - time1;
|
|
|
|
closed: Util.find(lastMsg, ['content', 'msg', 'type']) === 'CLOSE'
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var addClickHandler = function ($ticket) {
|
|
|
|
|
|
|
|
$ticket.on('click', function () {
|
|
|
|
|
|
|
|
$ticket.toggleClass('cp-support-open', true);
|
|
|
|
|
|
|
|
$ticket.off('click');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
order.forEach(function (id, i) {
|
|
|
|
};
|
|
|
|
$div.find('[data-id="'+id+'"]').css('order', i);
|
|
|
|
var makeOpenButton = function ($ticket) {
|
|
|
|
|
|
|
|
var button = h('button.btn.btn-primary.cp-support-expand', Messages.admin_support_open);
|
|
|
|
|
|
|
|
var collapse = h('button.btn.cp-support-collapse', Messages.admin_support_collapse);
|
|
|
|
|
|
|
|
$(button).click(function () {
|
|
|
|
|
|
|
|
$ticket.toggleClass('cp-support-open', true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
addClickHandler($ticket);
|
|
|
|
|
|
|
|
$(collapse).click(function (e) {
|
|
|
|
|
|
|
|
$ticket.toggleClass('cp-support-open', false);
|
|
|
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
|
|
|
|
addClickHandler($ticket);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
$ticket.find('.cp-support-title-buttons').prepend([button, collapse]);
|
|
|
|
|
|
|
|
$ticket.append(h('div.cp-support-collapsed'));
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
var updateTicketDetails = function ($ticket, isPremium) {
|
|
|
|
|
|
|
|
var $first = $ticket.find('.cp-support-message-from').first();
|
|
|
|
|
|
|
|
var user = $first.find('span').first().html();
|
|
|
|
|
|
|
|
var time = $first.find('.cp-support-message-time').text();
|
|
|
|
|
|
|
|
var last = $ticket.find('.cp-support-message-from').last().find('.cp-support-message-time').text();
|
|
|
|
|
|
|
|
var $c = $ticket.find('.cp-support-collapsed');
|
|
|
|
|
|
|
|
var txtClass = isPremium ? ".cp-support-ispremium" : "";
|
|
|
|
|
|
|
|
$c.html('').append([
|
|
|
|
|
|
|
|
UI.setHTML(h('span'+ txtClass), user),
|
|
|
|
|
|
|
|
h('span', [
|
|
|
|
|
|
|
|
h('b', Messages.admin_support_first),
|
|
|
|
|
|
|
|
h('span', time)
|
|
|
|
|
|
|
|
]),
|
|
|
|
|
|
|
|
h('span', [
|
|
|
|
|
|
|
|
h('b', Messages.admin_support_last),
|
|
|
|
|
|
|
|
h('span', last)
|
|
|
|
|
|
|
|
])
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var sort = function (id1, id2) {
|
|
|
|
|
|
|
|
var t1 = getTicketData(id1);
|
|
|
|
|
|
|
|
var t2 = getTicketData(id2);
|
|
|
|
|
|
|
|
if (!t1) { return 1; }
|
|
|
|
|
|
|
|
if (!t2) { return -1; }
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
// If one is answered and not the other, put the unanswered first
|
|
|
|
|
|
|
|
if (t1.lastAdmin && !t2.lastAdmin) { return 1; }
|
|
|
|
|
|
|
|
if (!t1.lastAdmin && t2.lastAdmin) { return -1; }
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Otherwise, sort them by time
|
|
|
|
|
|
|
|
return t1.time - t2.time;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var _reorder = function () {
|
|
|
|
|
|
|
|
var orderAnswered = Object.keys(hashesById).filter(function (id) {
|
|
|
|
|
|
|
|
var d = getTicketData(id);
|
|
|
|
|
|
|
|
return d && d.lastAdmin && !d.closed;
|
|
|
|
|
|
|
|
}).sort(sort);
|
|
|
|
|
|
|
|
var orderPremium = Object.keys(hashesById).filter(function (id) {
|
|
|
|
|
|
|
|
var d = getTicketData(id);
|
|
|
|
|
|
|
|
return d && d.premium && !d.lastAdmin && !d.closed;
|
|
|
|
|
|
|
|
}).sort(sort);
|
|
|
|
|
|
|
|
var orderNormal = Object.keys(hashesById).filter(function (id) {
|
|
|
|
|
|
|
|
var d = getTicketData(id);
|
|
|
|
|
|
|
|
return d && !d.premium && !d.lastAdmin && !d.closed;
|
|
|
|
|
|
|
|
}).sort(sort);
|
|
|
|
|
|
|
|
var orderClosed = Object.keys(hashesById).filter(function (id) {
|
|
|
|
|
|
|
|
var d = getTicketData(id);
|
|
|
|
|
|
|
|
return d && d.closed;
|
|
|
|
|
|
|
|
}).sort(sort);
|
|
|
|
|
|
|
|
var cols = [$col1, $col2, $col3, $col4];
|
|
|
|
|
|
|
|
[orderPremium, orderNormal, orderAnswered, orderClosed].forEach(function (list, j) {
|
|
|
|
|
|
|
|
list.forEach(function (id, i) {
|
|
|
|
|
|
|
|
var $t = $div.find('[data-id="'+id+'"]');
|
|
|
|
|
|
|
|
var d = getTicketData(id);
|
|
|
|
|
|
|
|
$t.css('order', i).appendTo(cols[j]);
|
|
|
|
|
|
|
|
updateTicketDetails($t, d.premium);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!list.length) {
|
|
|
|
|
|
|
|
cols[j].hide();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
cols[j].show();
|
|
|
|
|
|
|
|
cols[j].find('.cp-support-count').text(list.length);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
var reorder = Util.throttle(_reorder, 150);
|
|
|
|
|
|
|
|
|
|
|
|
var to = Util.throttle(function () {
|
|
|
|
var to = Util.throttle(function () {
|
|
|
|
var $ticket = $div.find('.cp-support-list-ticket[data-id="'+linkedId+'"]');
|
|
|
|
var $ticket = $div.find('.cp-support-list-ticket[data-id="'+linkedId+'"]');
|
|
|
|
|
|
|
|
$ticket.addClass('cp-support-open');
|
|
|
|
$ticket[0].scrollIntoView();
|
|
|
|
$ticket[0].scrollIntoView();
|
|
|
|
linkedId = undefined;
|
|
|
|
linkedId = undefined;
|
|
|
|
}, 100);
|
|
|
|
}, 200);
|
|
|
|
|
|
|
|
|
|
|
|
// Register to the "support" mailbox
|
|
|
|
// Register to the "support" mailbox
|
|
|
|
common.mailbox.subscribe(['supportadmin'], {
|
|
|
|
common.mailbox.subscribe(['supportadmin'], {
|
|
|
@ -630,6 +767,7 @@ define([
|
|
|
|
if (!$ticket.length) { return; }
|
|
|
|
if (!$ticket.length) { return; }
|
|
|
|
$ticket.addClass('cp-support-list-closed');
|
|
|
|
$ticket.addClass('cp-support-list-closed');
|
|
|
|
$ticket.append(APP.support.makeCloseMessage(content, hash));
|
|
|
|
$ticket.append(APP.support.makeCloseMessage(content, hash));
|
|
|
|
|
|
|
|
reorder();
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (msg.type !== 'TICKET') { return; }
|
|
|
|
if (msg.type !== 'TICKET') { return; }
|
|
|
@ -650,13 +788,19 @@ define([
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}).nThen(function () {
|
|
|
|
}).nThen(function () {
|
|
|
|
if (!error) { return void $ticket.remove(); }
|
|
|
|
if (!error) {
|
|
|
|
|
|
|
|
$ticket.remove();
|
|
|
|
|
|
|
|
delete hashesById[id];
|
|
|
|
|
|
|
|
reorder();
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
// if deletion failed then reactivate the button and warn
|
|
|
|
// if deletion failed then reactivate the button and warn
|
|
|
|
hideButton.removeAttribute('disabled');
|
|
|
|
hideButton.removeAttribute('disabled');
|
|
|
|
// and show a generic error message
|
|
|
|
// and show a generic error message
|
|
|
|
UI.alert(Messages.error);
|
|
|
|
UI.alert(Messages.error);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
makeOpenButton($ticket);
|
|
|
|
if (category !== 'all' && $ticket.attr('data-cat') !== category) {
|
|
|
|
if (category !== 'all' && $ticket.attr('data-cat') !== category) {
|
|
|
|
$ticket.hide();
|
|
|
|
$ticket.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|