()
| 1388 | var inRefresh = false; |
| 1389 | |
| 1390 | function refreshInvite() { |
| 1391 | if (inRefresh) { |
| 1392 | return; |
| 1393 | } |
| 1394 | inRefresh = true; |
| 1395 | require(["who"], function (who) { |
| 1396 | var def = who.getList(inviteHubUrl()); |
| 1397 | function addUser(user, before) { |
| 1398 | var item = templating.sub("invite-user-item", {peer: user}); |
| 1399 | item.attr("data-clientid", user.id); |
| 1400 | if (before) { |
| 1401 | item.insertBefore(before); |
| 1402 | } else { |
| 1403 | $("#togetherjs-invite-users").append(item); |
| 1404 | } |
| 1405 | item.click(function() { |
| 1406 | invite(user.clientId); |
| 1407 | }); |
| 1408 | } |
| 1409 | function refresh(users, finished) { |
| 1410 | var sorted = []; |
| 1411 | for (var id in users) { |
| 1412 | if (users.hasOwnProperty(id)) { |
| 1413 | sorted.push(users[id]); |
| 1414 | } |
| 1415 | } |
| 1416 | sorted.sort(function (a, b) { |
| 1417 | return a.name < b.name ? -1 : 1; |
| 1418 | }); |
| 1419 | var pos = 0; |
| 1420 | ui.container.find("#togetherjs-invite-users .togetherjs-menu-item").each(function () { |
| 1421 | var $this = $(this); |
| 1422 | if (finished && ! users[$this.attr("data-clientid")]) { |
| 1423 | $this.remove(); |
| 1424 | return; |
| 1425 | } |
| 1426 | if (pos >= sorted.length) { |
| 1427 | return; |
| 1428 | } |
| 1429 | while (pos < sorted.length && $this.attr("data-clientid") !== sorted[pos].id) { |
| 1430 | addUser(sorted[pos], $this); |
| 1431 | pos++; |
| 1432 | } |
| 1433 | while (pos < sorted.length && $this.attr("data-clientid") == sorted[pos].id) { |
| 1434 | pos++; |
| 1435 | } |
| 1436 | }); |
| 1437 | for (var i=pos; i<sorted.length; i++) { |
| 1438 | addUser(sorted[pos]); |
| 1439 | } |
| 1440 | } |
| 1441 | def.then(function (users) { |
| 1442 | refresh(users, true); |
| 1443 | inRefresh = false; |
| 1444 | }); |
| 1445 | def.progress(refresh); |
| 1446 | }); |
| 1447 | } |
nothing calls this directly
no test coverage detected