peopleBody.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. const orgsPerPage = 25;
  2. const teamsPerPage = 25;
  3. const usersPerPage = 25;
  4. BlazeComponent.extendComponent({
  5. mixins() {
  6. return [Mixins.InfiniteScrolling];
  7. },
  8. onCreated() {
  9. this.error = new ReactiveVar('');
  10. this.loading = new ReactiveVar(false);
  11. this.orgSetting = new ReactiveVar(true);
  12. this.teamSetting = new ReactiveVar(true);
  13. this.peopleSetting = new ReactiveVar(true);
  14. this.findOrgsOptions = new ReactiveVar({});
  15. this.findTeamsOptions = new ReactiveVar({});
  16. this.findUsersOptions = new ReactiveVar({});
  17. this.numberOrgs = new ReactiveVar(0);
  18. this.numberTeams = new ReactiveVar(0);
  19. this.numberPeople = new ReactiveVar(0);
  20. this.page = new ReactiveVar(1);
  21. this.loadNextPageLocked = false;
  22. this.callFirstWith(null, 'resetNextPeak');
  23. this.autorun(() => {
  24. const limitOrgs = this.page.get() * orgsPerPage;
  25. const limitTeams = this.page.get() * teamsPerPage;
  26. const limitUsers = this.page.get() * usersPerPage;
  27. this.subscribe('org', this.findOrgsOptions.get(), limitOrgs, () => {
  28. this.loadNextPageLocked = false;
  29. const nextPeakBefore = this.callFirstWith(null, 'getNextPeak');
  30. this.calculateNextPeak();
  31. const nextPeakAfter = this.callFirstWith(null, 'getNextPeak');
  32. if (nextPeakBefore === nextPeakAfter) {
  33. this.callFirstWith(null, 'resetNextPeak');
  34. }
  35. });
  36. this.subscribe('team', this.findTeamsOptions.get(), limitTeams, () => {
  37. this.loadNextPageLocked = false;
  38. const nextPeakBefore = this.callFirstWith(null, 'getNextPeak');
  39. this.calculateNextPeak();
  40. const nextPeakAfter = this.callFirstWith(null, 'getNextPeak');
  41. if (nextPeakBefore === nextPeakAfter) {
  42. this.callFirstWith(null, 'resetNextPeak');
  43. }
  44. });
  45. this.subscribe('people', this.findUsersOptions.get(), limitUsers, () => {
  46. this.loadNextPageLocked = false;
  47. const nextPeakBefore = this.callFirstWith(null, 'getNextPeak');
  48. this.calculateNextPeak();
  49. const nextPeakAfter = this.callFirstWith(null, 'getNextPeak');
  50. if (nextPeakBefore === nextPeakAfter) {
  51. this.callFirstWith(null, 'resetNextPeak');
  52. }
  53. });
  54. });
  55. },
  56. events() {
  57. return [
  58. {
  59. 'click #searchOrgButton'() {
  60. this.filterOrg();
  61. },
  62. 'keydown #searchOrgInput'(event) {
  63. if (event.keyCode === 13 && !event.shiftKey) {
  64. this.filterOrg();
  65. }
  66. },
  67. 'click #searchTeamButton'() {
  68. this.filterTeam();
  69. },
  70. 'keydown #searchTeamInput'(event) {
  71. if (event.keyCode === 13 && !event.shiftKey) {
  72. this.filterTeam();
  73. }
  74. },
  75. 'click #searchButton'() {
  76. this.filterPeople();
  77. },
  78. 'keydown #searchInput'(event) {
  79. if (event.keyCode === 13 && !event.shiftKey) {
  80. this.filterPeople();
  81. }
  82. },
  83. 'click #newOrgButton'() {
  84. Popup.open('newOrg');
  85. },
  86. 'click #newTeamButton'() {
  87. Popup.open('newTeam');
  88. },
  89. 'click #newUserButton'() {
  90. Popup.open('newUser');
  91. },
  92. 'click a.js-org-menu': this.switchMenu,
  93. 'click a.js-team-menu': this.switchMenu,
  94. 'click a.js-people-menu': this.switchMenu,
  95. },
  96. ];
  97. },
  98. filterPeople() {
  99. const value = $('#searchInput').first().val();
  100. if (value === '') {
  101. this.findUsersOptions.set({});
  102. } else {
  103. const regex = new RegExp(value, 'i');
  104. this.findUsersOptions.set({
  105. $or: [
  106. { username: regex },
  107. { 'profile.fullname': regex },
  108. { 'emails.address': regex },
  109. ],
  110. });
  111. }
  112. },
  113. loadNextPage() {
  114. if (this.loadNextPageLocked === false) {
  115. this.page.set(this.page.get() + 1);
  116. this.loadNextPageLocked = true;
  117. }
  118. },
  119. calculateNextPeak() {
  120. const element = this.find('.main-body');
  121. if (element) {
  122. const altitude = element.scrollHeight;
  123. this.callFirstWith(this, 'setNextPeak', altitude);
  124. }
  125. },
  126. reachNextPeak() {
  127. this.loadNextPage();
  128. },
  129. setError(error) {
  130. this.error.set(error);
  131. },
  132. setLoading(w) {
  133. this.loading.set(w);
  134. },
  135. orgList() {
  136. const orgs = Org.find(this.findOrgsOptions.get(), {
  137. fields: { _id: true },
  138. });
  139. this.numberOrgs.set(orgs.count(false));
  140. return orgs;
  141. },
  142. teamList() {
  143. const teams = Team.find(this.findTeamsOptions.get(), {
  144. fields: { _id: true },
  145. });
  146. this.numberTeams.set(teams.count(false));
  147. return teams;
  148. },
  149. peopleList() {
  150. const users = Users.find(this.findUsersOptions.get(), {
  151. fields: { _id: true },
  152. });
  153. this.numberPeople.set(users.count(false));
  154. return users;
  155. },
  156. orgNumber() {
  157. return this.numberOrgs.get();
  158. },
  159. teamNumber() {
  160. return this.numberTeams.get();
  161. },
  162. peopleNumber() {
  163. return this.numberPeople.get();
  164. },
  165. switchMenu(event) {
  166. const target = $(event.target);
  167. if (!target.hasClass('active')) {
  168. $('.side-menu li.active').removeClass('active');
  169. target.parent().addClass('active');
  170. const targetID = target.data('id');
  171. this.orgSetting.set('org-setting' === targetID);
  172. this.teamSetting.set('team-setting' === targetID);
  173. this.peopleSetting.set('people-setting' === targetID);
  174. }
  175. },
  176. }).register('people');
  177. Template.orgRow.helpers({
  178. orgData() {
  179. const orgCollection = this.esSearch ? ESSearchResults : Org;
  180. return orgCollection.findOne(this.orgId);
  181. },
  182. });
  183. Template.teamRow.helpers({
  184. teamData() {
  185. const teamCollection = this.esSearch ? ESSearchResults : Team;
  186. return teamCollection.findOne(this.teamId);
  187. },
  188. });
  189. Template.peopleRow.helpers({
  190. userData() {
  191. const userCollection = this.esSearch ? ESSearchResults : Users;
  192. return userCollection.findOne(this.userId);
  193. },
  194. });
  195. Template.editUserPopup.onCreated(function () {
  196. this.authenticationMethods = new ReactiveVar([]);
  197. this.errorMessage = new ReactiveVar('');
  198. Meteor.call('getAuthenticationsEnabled', (_, result) => {
  199. if (result) {
  200. // TODO : add a management of different languages
  201. // (ex {value: ldap, text: TAPi18n.__('ldap', {}, T9n.getLanguage() || 'en')})
  202. this.authenticationMethods.set([
  203. { value: 'password' },
  204. // Gets only the authentication methods availables
  205. ...Object.entries(result)
  206. .filter((e) => e[1])
  207. .map((e) => ({ value: e[0] })),
  208. ]);
  209. }
  210. });
  211. });
  212. Template.editOrgPopup.helpers({
  213. org() {
  214. return Org.findOne(this.orgId);
  215. },
  216. errorMessage() {
  217. return Template.instance().errorMessage.get();
  218. },
  219. });
  220. Template.editTeamPopup.helpers({
  221. team() {
  222. return Team.findOne(this.teamId);
  223. },
  224. errorMessage() {
  225. return Template.instance().errorMessage.get();
  226. },
  227. });
  228. Template.editUserPopup.helpers({
  229. user() {
  230. return Users.findOne(this.userId);
  231. },
  232. authentications() {
  233. return Template.instance().authenticationMethods.get();
  234. },
  235. isSelected(match) {
  236. const userId = Template.instance().data.userId;
  237. const selected = Users.findOne(userId).authenticationMethod;
  238. return selected === match;
  239. },
  240. isLdap() {
  241. const userId = Template.instance().data.userId;
  242. const selected = Users.findOne(userId).authenticationMethod;
  243. return selected === 'ldap';
  244. },
  245. errorMessage() {
  246. return Template.instance().errorMessage.get();
  247. },
  248. });
  249. Template.newOrgPopup.onCreated(function () {
  250. this.errorMessage = new ReactiveVar('');
  251. });
  252. Template.newTeamPopup.onCreated(function () {
  253. this.errorMessage = new ReactiveVar('');
  254. });
  255. Template.newUserPopup.onCreated(function () {
  256. this.authenticationMethods = new ReactiveVar([]);
  257. this.errorMessage = new ReactiveVar('');
  258. Meteor.call('getAuthenticationsEnabled', (_, result) => {
  259. if (result) {
  260. // TODO : add a management of different languages
  261. // (ex {value: ldap, text: TAPi18n.__('ldap', {}, T9n.getLanguage() || 'en')})
  262. this.authenticationMethods.set([
  263. { value: 'password' },
  264. // Gets only the authentication methods availables
  265. ...Object.entries(result)
  266. .filter((e) => e[1])
  267. .map((e) => ({ value: e[0] })),
  268. ]);
  269. }
  270. });
  271. });
  272. Template.newOrgPopup.helpers({
  273. org() {
  274. return Org.findOne(this.orgId);
  275. },
  276. errorMessage() {
  277. return Template.instance().errorMessage.get();
  278. },
  279. });
  280. Template.newTeamPopup.helpers({
  281. team() {
  282. return Team.findOne(this.teamId);
  283. },
  284. errorMessage() {
  285. return Template.instance().errorMessage.get();
  286. },
  287. });
  288. Template.newUserPopup.helpers({
  289. user() {
  290. return Users.findOne(this.userId);
  291. },
  292. authentications() {
  293. return Template.instance().authenticationMethods.get();
  294. },
  295. isSelected(match) {
  296. const userId = Template.instance().data.userId;
  297. const selected = Users.findOne(userId).authenticationMethod;
  298. return selected === match;
  299. },
  300. isLdap() {
  301. const userId = Template.instance().data.userId;
  302. const selected = Users.findOne(userId).authenticationMethod;
  303. return selected === 'ldap';
  304. },
  305. errorMessage() {
  306. return Template.instance().errorMessage.get();
  307. },
  308. });
  309. BlazeComponent.extendComponent({
  310. onCreated() {},
  311. org() {
  312. return Org.findOne(this.orgId);
  313. },
  314. events() {
  315. return [
  316. {
  317. 'click a.edit-org': Popup.open('editOrg'),
  318. 'click a.more-settings-org': Popup.open('settingsOrg'),
  319. },
  320. ];
  321. },
  322. }).register('orgRow');
  323. BlazeComponent.extendComponent({
  324. onCreated() {},
  325. team() {
  326. return Team.findOne(this.teamId);
  327. },
  328. events() {
  329. return [
  330. {
  331. 'click a.edit-team': Popup.open('editTeam'),
  332. 'click a.more-settings-team': Popup.open('settingsTeam'),
  333. },
  334. ];
  335. },
  336. }).register('teamRow');
  337. BlazeComponent.extendComponent({
  338. onCreated() {},
  339. user() {
  340. return Users.findOne(this.userId);
  341. },
  342. events() {
  343. return [
  344. {
  345. 'click a.edit-user': Popup.open('editUser'),
  346. 'click a.more-settings-user': Popup.open('settingsUser'),
  347. },
  348. ];
  349. },
  350. }).register('peopleRow');
  351. BlazeComponent.extendComponent({
  352. events() {
  353. return [
  354. {
  355. 'click a.new-org': Popup.open('newOrg'),
  356. },
  357. ];
  358. },
  359. }).register('newOrgRow');
  360. BlazeComponent.extendComponent({
  361. events() {
  362. return [
  363. {
  364. 'click a.new-team': Popup.open('newTeam'),
  365. },
  366. ];
  367. },
  368. }).register('newTeamRow');
  369. BlazeComponent.extendComponent({
  370. events() {
  371. return [
  372. {
  373. 'click a.new-user': Popup.open('newUser'),
  374. },
  375. ];
  376. },
  377. }).register('newUserRow');
  378. Template.editOrgPopup.events({
  379. submit(event, templateInstance) {
  380. event.preventDefault();
  381. const org = Org.findOne(this.orgId);
  382. const orgDisplayName = templateInstance
  383. .find('.js-orgDisplayName')
  384. .value.trim();
  385. const orgDesc = templateInstance.find('.js-orgDesc').value.trim();
  386. const orgShortName = templateInstance.find('.js-orgShortName').value.trim();
  387. const orgWebsite = templateInstance.find('.js-orgWebsite').value.trim();
  388. const orgIsActive =
  389. templateInstance.find('.js-org-isactive').value.trim() == 'true';
  390. const isChangeOrgDisplayName = orgDisplayName !== org.orgDisplayName;
  391. const isChangeOrgDesc = orgDesc !== org.orgDesc;
  392. const isChangeOrgShortName = orgShortName !== org.orgShortName;
  393. const isChangeOrgWebsite = orgWebsite !== org.orgWebsite;
  394. const isChangeOrgIsActive = orgIsActive !== org.orgIsActive;
  395. if (
  396. isChangeOrgDisplayName ||
  397. isChangeOrgDesc ||
  398. isChangeOrgShortName ||
  399. isChangeOrgWebsite ||
  400. isChangeOrgIsActive
  401. ) {
  402. Meteor.call(
  403. 'setOrgAllFields',
  404. org,
  405. orgDisplayName,
  406. orgDesc,
  407. orgShortName,
  408. orgWebsite,
  409. orgIsActive,
  410. );
  411. }
  412. Popup.close();
  413. },
  414. });
  415. Template.editTeamPopup.events({
  416. submit(event, templateInstance) {
  417. event.preventDefault();
  418. const team = Team.findOne(this.teamId);
  419. const teamDisplayName = templateInstance
  420. .find('.js-teamDisplayName')
  421. .value.trim();
  422. const teamDesc = templateInstance.find('.js-teamDesc').value.trim();
  423. const teamShortName = templateInstance
  424. .find('.js-teamShortName')
  425. .value.trim();
  426. const teamWebsite = templateInstance.find('.js-teamWebsite').value.trim();
  427. const teamIsActive =
  428. templateInstance.find('.js-team-isactive').value.trim() == 'true';
  429. const isChangeTeamDisplayName = teamDisplayName !== team.teamDisplayName;
  430. const isChangeTeamDesc = teamDesc !== team.teamDesc;
  431. const isChangeTeamShortName = teamShortName !== team.teamShortName;
  432. const isChangeTeamWebsite = teamWebsite !== team.teamWebsite;
  433. const isChangeTeamIsActive = teamIsActive !== team.teamIsActive;
  434. if (
  435. isChangeTeamDisplayName ||
  436. isChangeTeamDesc ||
  437. isChangeTeamShortName ||
  438. isChangeTeamWebsite ||
  439. isChangeTeamIsActive
  440. ) {
  441. Meteor.call(
  442. 'setTeamAllFields',
  443. team,
  444. teamDisplayName,
  445. teamDesc,
  446. teamShortName,
  447. teamWebsite,
  448. teamIsActive,
  449. );
  450. }
  451. Popup.close();
  452. },
  453. });
  454. Template.editUserPopup.events({
  455. submit(event, templateInstance) {
  456. event.preventDefault();
  457. const user = Users.findOne(this.userId);
  458. const username = templateInstance.find('.js-profile-username').value.trim();
  459. const fullname = templateInstance.find('.js-profile-fullname').value.trim();
  460. const initials = templateInstance.find('.js-profile-initials').value.trim();
  461. const password = templateInstance.find('.js-profile-password').value;
  462. const isAdmin = templateInstance.find('.js-profile-isadmin').value.trim();
  463. const isActive = templateInstance.find('.js-profile-isactive').value.trim();
  464. const email = templateInstance.find('.js-profile-email').value.trim();
  465. const verified = templateInstance
  466. .find('.js-profile-email-verified')
  467. .value.trim();
  468. const authentication = templateInstance
  469. .find('.js-authenticationMethod')
  470. .value.trim();
  471. const importUsernames = templateInstance
  472. .find('.js-import-usernames')
  473. .value.trim();
  474. const isChangePassword = password.length > 0;
  475. const isChangeUserName = username !== user.username;
  476. const isChangeInitials = initials.length > 0;
  477. const isChangeEmailVerified = verified !== user.emails[0].verified;
  478. // If previously email address has not been set, it is undefined,
  479. // check for undefined, and allow adding email address.
  480. const isChangeEmail =
  481. email.toLowerCase() !==
  482. (typeof user.emails !== 'undefined'
  483. ? user.emails[0].address.toLowerCase()
  484. : false);
  485. Users.update(this.userId, {
  486. $set: {
  487. 'profile.fullname': fullname,
  488. isAdmin: isAdmin === 'true',
  489. loginDisabled: isActive === 'true',
  490. authenticationMethod: authentication,
  491. importUsernames: Users.parseImportUsernames(importUsernames),
  492. },
  493. });
  494. if (isChangePassword) {
  495. Meteor.call('setPassword', password, this.userId);
  496. }
  497. if (isChangeEmailVerified) {
  498. Meteor.call('setEmailVerified', email, verified === 'true', this.userId);
  499. }
  500. if (isChangeInitials) {
  501. Meteor.call('setInitials', initials, this.userId);
  502. }
  503. if (isChangeUserName && isChangeEmail) {
  504. Meteor.call(
  505. 'setUsernameAndEmail',
  506. username,
  507. email.toLowerCase(),
  508. this.userId,
  509. function (error) {
  510. const usernameMessageElement = templateInstance.$('.username-taken');
  511. const emailMessageElement = templateInstance.$('.email-taken');
  512. if (error) {
  513. const errorElement = error.error;
  514. if (errorElement === 'username-already-taken') {
  515. usernameMessageElement.show();
  516. emailMessageElement.hide();
  517. } else if (errorElement === 'email-already-taken') {
  518. usernameMessageElement.hide();
  519. emailMessageElement.show();
  520. }
  521. } else {
  522. usernameMessageElement.hide();
  523. emailMessageElement.hide();
  524. Popup.close();
  525. }
  526. },
  527. );
  528. } else if (isChangeUserName) {
  529. Meteor.call('setUsername', username, this.userId, function (error) {
  530. const usernameMessageElement = templateInstance.$('.username-taken');
  531. if (error) {
  532. const errorElement = error.error;
  533. if (errorElement === 'username-already-taken') {
  534. usernameMessageElement.show();
  535. }
  536. } else {
  537. usernameMessageElement.hide();
  538. Popup.close();
  539. }
  540. });
  541. } else if (isChangeEmail) {
  542. Meteor.call(
  543. 'setEmail',
  544. email.toLowerCase(),
  545. this.userId,
  546. function (error) {
  547. const emailMessageElement = templateInstance.$('.email-taken');
  548. if (error) {
  549. const errorElement = error.error;
  550. if (errorElement === 'email-already-taken') {
  551. emailMessageElement.show();
  552. }
  553. } else {
  554. emailMessageElement.hide();
  555. Popup.close();
  556. }
  557. },
  558. );
  559. } else Popup.close();
  560. },
  561. });
  562. Template.newOrgPopup.events({
  563. submit(event, templateInstance) {
  564. event.preventDefault();
  565. const orgDisplayName = templateInstance
  566. .find('.js-orgDisplayName')
  567. .value.trim();
  568. const orgDesc = templateInstance.find('.js-orgDesc').value.trim();
  569. const orgShortName = templateInstance.find('.js-orgShortName').value.trim();
  570. const orgWebsite = templateInstance.find('.js-orgWebsite').value.trim();
  571. const orgIsActive =
  572. templateInstance.find('.js-org-isactive').value.trim() == 'true';
  573. Meteor.call(
  574. 'setCreateOrg',
  575. orgDisplayName,
  576. orgDesc,
  577. orgShortName,
  578. orgWebsite,
  579. orgIsActive,
  580. );
  581. Popup.close();
  582. },
  583. });
  584. Template.newTeamPopup.events({
  585. submit(event, templateInstance) {
  586. event.preventDefault();
  587. const teamDisplayName = templateInstance
  588. .find('.js-teamDisplayName')
  589. .value.trim();
  590. const teamDesc = templateInstance.find('.js-teamDesc').value.trim();
  591. const teamShortName = templateInstance
  592. .find('.js-teamShortName')
  593. .value.trim();
  594. const teamWebsite = templateInstance.find('.js-teamWebsite').value.trim();
  595. const teamIsActive =
  596. templateInstance.find('.js-team-isactive').value.trim() == 'true';
  597. Meteor.call(
  598. 'setCreateTeam',
  599. teamDisplayName,
  600. teamDesc,
  601. teamShortName,
  602. teamWebsite,
  603. teamIsActive,
  604. );
  605. Popup.close();
  606. },
  607. });
  608. Template.newUserPopup.events({
  609. submit(event, templateInstance) {
  610. event.preventDefault();
  611. const fullname = templateInstance.find('.js-profile-fullname').value.trim();
  612. const username = templateInstance.find('.js-profile-username').value.trim();
  613. const initials = templateInstance.find('.js-profile-initials').value.trim();
  614. const password = templateInstance.find('.js-profile-password').value;
  615. const isAdmin = templateInstance.find('.js-profile-isadmin').value.trim();
  616. const isActive = templateInstance.find('.js-profile-isactive').value.trim();
  617. const email = templateInstance.find('.js-profile-email').value.trim();
  618. const importUsernames = Users.parseImportUsernames(
  619. templateInstance.find('.js-import-usernames').value,
  620. );
  621. Meteor.call(
  622. 'setCreateUser',
  623. fullname,
  624. username,
  625. initials,
  626. password,
  627. isAdmin,
  628. isActive,
  629. email.toLowerCase(),
  630. importUsernames,
  631. function (error) {
  632. const usernameMessageElement = templateInstance.$('.username-taken');
  633. const emailMessageElement = templateInstance.$('.email-taken');
  634. if (error) {
  635. const errorElement = error.error;
  636. if (errorElement === 'username-already-taken') {
  637. usernameMessageElement.show();
  638. emailMessageElement.hide();
  639. } else if (errorElement === 'email-already-taken') {
  640. usernameMessageElement.hide();
  641. emailMessageElement.show();
  642. }
  643. } else {
  644. usernameMessageElement.hide();
  645. emailMessageElement.hide();
  646. Popup.close();
  647. }
  648. },
  649. );
  650. Popup.close();
  651. },
  652. });
  653. Template.settingsOrgPopup.events({
  654. 'click #deleteButton'(event) {
  655. event.preventDefault();
  656. Org.remove(this.orgId);
  657. Popup.close();
  658. }
  659. });
  660. Template.settingsTeamPopup.events({
  661. 'click #deleteButton'(event) {
  662. event.preventDefault();
  663. Team.remove(this.teamId);
  664. Popup.close();
  665. }
  666. });
  667. Template.settingsUserPopup.events({
  668. 'click .impersonate-user'(event) {
  669. event.preventDefault();
  670. Meteor.call('impersonate', this.userId, (err) => {
  671. if (!err) {
  672. FlowRouter.go('/');
  673. Meteor.connection.setUserId(this.userId);
  674. }
  675. });
  676. },
  677. 'click #deleteButton'(event) {
  678. event.preventDefault();
  679. /*
  680. // Delete is not enabled yet, because it does leave empty user avatars
  681. // to boards: boards members, card members and assignees have
  682. // empty users. See:
  683. // - wekan/client/components/settings/peopleBody.jade deleteButton
  684. // - wekan/client/components/settings/peopleBody.js deleteButton
  685. // - wekan/client/components/sidebar/sidebar.js Popup.afterConfirm('removeMember'
  686. // that does now remove member from board, card members and assignees correctly,
  687. // but that should be used to remove user from all boards similarly
  688. // - wekan/models/users.js Delete is not enabled
  689. //
  690. //Users.remove(this.userId);
  691. */
  692. Popup.close();
  693. },
  694. });
  695. Template.settingsUserPopup.helpers({
  696. user() {
  697. return Users.findOne(this.userId);
  698. },
  699. authentications() {
  700. return Template.instance().authenticationMethods.get();
  701. },
  702. isSelected(match) {
  703. const userId = Template.instance().data.userId;
  704. const selected = Users.findOne(userId).authenticationMethod;
  705. return selected === match;
  706. },
  707. isLdap() {
  708. const userId = Template.instance().data.userId;
  709. const selected = Users.findOne(userId).authenticationMethod;
  710. return selected === 'ldap';
  711. },
  712. errorMessage() {
  713. return Template.instance().errorMessage.get();
  714. },
  715. });