| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428 | import { ReactiveCache } from '/imports/reactiveCache';import { TAPi18n } from '/imports/i18n';Template.headerUserBar.events({  'click .js-open-header-member-menu': Popup.open('memberMenu'),  'click .js-change-avatar': Popup.open('changeAvatar'),});BlazeComponent.extendComponent({  onCreated() {    Meteor.subscribe('setting');  },}).register('memberMenuPopup');Template.memberMenuPopup.helpers({  templatesBoardId() {    const currentUser = ReactiveCache.getCurrentUser();    if (currentUser) {      return currentUser.getTemplatesBoardId();    } else {      // No need to getTemplatesBoardId on public board      return false;    }  },  templatesBoardSlug() {    const currentUser = ReactiveCache.getCurrentUser();    if (currentUser) {      return currentUser.getTemplatesBoardSlug();    } else {      // No need to getTemplatesBoardSlug() on public board      return false;    }  },  isSameDomainNameSettingValue(){    const currSett = ReactiveCache.getCurrentSetting();    if(currSett && currSett != undefined && currSett.disableRegistration && currSett.mailDomainName !== undefined && currSett.mailDomainName != ""){      currentUser = ReactiveCache.getCurrentUser();      if (currentUser) {        let found = false;        for(let i = 0; i < currentUser.emails.length; i++) {          if(currentUser.emails[i].address.endsWith(currSett.mailDomainName)){            found = true;            break;          }        }        return found;      } else {        return true;      }    }    else      return false;  },  isNotOAuth2AuthenticationMethod(){    const currentUser = ReactiveCache.getCurrentUser();    if (currentUser) {      return currentUser.authenticationMethod.toLowerCase() != 'oauth2';    } else {      return true;    }  }});Template.memberMenuPopup.events({  'click .js-open-bookmarks'(e) {    e.preventDefault();    if (Utils.isMiniScreen()) {      FlowRouter.go('bookmarks');      Popup.back();    } else {      Popup.open('bookmarksPopup')(e);    }  },  'click .js-my-cards'() {    Popup.back();  },  'click .js-due-cards'() {    Popup.back();  },  'click .js-open-archived-board'() {    Modal.open('archivedBoards');  },  'click .js-invite-people': Popup.open('invitePeople'),  'click .js-edit-profile': Popup.open('editProfile'),  'click .js-change-settings': Popup.open('changeSettings'),  'click .js-change-avatar': Popup.open('changeAvatar'),  'click .js-change-password': Popup.open('changePassword'),  'click .js-change-language': Popup.open('changeLanguage'),  'click .js-support': Popup.open('support'),  'click .js-notifications-drawer-toggle'() {    Session.set('showNotificationsDrawer', !Session.get('showNotificationsDrawer'));  },  'click .js-logout'(event) {    event.preventDefault();    AccountsTemplates.logout();  },  'click .js-go-setting'() {    Popup.back();  },});BlazeComponent.extendComponent({  onCreated() {    Meteor.subscribe('setting');  },}).register('editProfilePopup');Template.invitePeoplePopup.events({  'click a.js-toggle-board-choose'(event){    let target = $(event.target);    if (!target.hasClass('js-toggle-board-choose')) {      target = target.parent();    }    const checkboxId = target.attr('id');    $(`#${checkboxId} .materialCheckBox`).toggleClass('is-checked');    $(`#${checkboxId}`).toggleClass('is-checked');  },  'click button.js-email-invite'(event){    const emails = $('#email-to-invite')      .val()      .toLowerCase()      .trim()      .split('\n')      .join(',')      .split(',');    const boardsToInvite = [];    $('.js-toggle-board-choose .materialCheckBox.is-checked').each(function() {      boardsToInvite.push($(this).data('id'));    });    const validEmails = [];    emails.forEach(email => {      if (email && SimpleSchema.RegEx.Email.test(email.trim())) {        validEmails.push(email.trim());      }    });    if (validEmails.length) {      Meteor.call('sendInvitation', validEmails, boardsToInvite, (_, rc) => {        if (rc == 0) {          let divInfos = document.getElementById("invite-people-infos");          if(divInfos && divInfos !== undefined){            divInfos.innerHTML = "<span style='color: green'>" + TAPi18n.__('invite-people-success') + "</span>";          }        }        else{          let divInfos = document.getElementById("invite-people-infos");          if(divInfos && divInfos !== undefined){            divInfos.innerHTML = "<span style='color: red'>" + TAPi18n.__('invite-people-error') + "</span>";          }        }        // Popup.close();      });    }  },});Template.editProfilePopup.helpers({  allowEmailChange() {    Meteor.call('AccountSettings.allowEmailChange', (_, result) => {      if (result) {        return true;      } else {        return false;      }    });  },  allowUserNameChange() {    Meteor.call('AccountSettings.allowUserNameChange', (_, result) => {      if (result) {        return true;      } else {        return false;      }    });  },  allowUserDelete() {    Meteor.call('AccountSettings.allowUserDelete', (_, result) => {      if (result) {        return true;      } else {        return false;      }    });  },});Template.editProfilePopup.events({  submit(event, templateInstance) {    event.preventDefault();    const fullname = templateInstance.find('.js-profile-fullname').value.trim();    const username = templateInstance.find('.js-profile-username').value.trim();    const initials = templateInstance.find('.js-profile-initials').value.trim();    const email = templateInstance.find('.js-profile-email').value.trim();    let isChangeUserName = false;    let isChangeEmail = false;    Users.update(Meteor.userId(), {      $set: {        'profile.fullname': fullname,        'profile.initials': initials,      },    });    isChangeUserName = username !== ReactiveCache.getCurrentUser().username;    isChangeEmail =      email.toLowerCase() !== ReactiveCache.getCurrentUser().emails[0].address.toLowerCase();    if (isChangeUserName && isChangeEmail) {      Meteor.call(        'setUsernameAndEmail',        username,        email.toLowerCase(),        Meteor.userId(),        function(error) {          const usernameMessageElement = templateInstance.$('.username-taken');          const emailMessageElement = templateInstance.$('.email-taken');          if (error) {            const errorElement = error.error;            if (errorElement === 'username-already-taken') {              usernameMessageElement.show();              emailMessageElement.hide();            } else if (errorElement === 'email-already-taken') {              usernameMessageElement.hide();              emailMessageElement.show();            }          } else {            usernameMessageElement.hide();            emailMessageElement.hide();            Popup.back();          }        },      );    } else if (isChangeUserName) {      Meteor.call('setUsername', username, Meteor.userId(), function(error) {        const messageElement = templateInstance.$('.username-taken');        if (error) {          messageElement.show();        } else {          messageElement.hide();          Popup.back();        }      });    } else if (isChangeEmail) {      Meteor.call('setEmail', email.toLowerCase(), Meteor.userId(), function(        error,      ) {        const messageElement = templateInstance.$('.email-taken');        if (error) {          messageElement.show();        } else {          messageElement.hide();          Popup.back();        }      });    } else Popup.back();  },  'click #deleteButton': Popup.afterConfirm('userDelete', function() {    Popup.back();    // Use secure server method for self-deletion    Meteor.call('removeUser', Meteor.userId(), (error, result) => {      if (error) {        if (process.env.DEBUG === 'true') {          console.error('Error removing user:', error);        }        alert('Error deleting account: ' + error.reason);      } else {        if (process.env.DEBUG === 'true') {          console.log('User deleted successfully:', result);        }        AccountsTemplates.logout();      }    });  }),});// XXX For some reason the useraccounts autofocus isnt working in this case.// See https://github.com/meteor-useraccounts/core/issues/384Template.changePasswordPopup.onRendered(function() {  $('.at-pwd-form').show();  this.find('#at-field-current_password').focus();});Template.changeLanguagePopup.helpers({  languages() {    return TAPi18n.getSupportedLanguages()      .map(({ tag, name }) => ({ tag: tag, name }))      .sort((a, b) => {        if (a.name === b.name) {          return 0;        } else {          return a.name > b.name ? 1 : -1;        }      });  },  isCurrentLanguage() {    return this.tag === TAPi18n.getLanguage();  },  languageFlag() {    const flagMap = {      'en': '๐บ๐ธ', 'es': '๐ช๐ธ', 'fr': '๐ซ๐ท', 'de': '๐ฉ๐ช', 'it': '๐ฎ๐น', 'pt': '๐ต๐น', 'ru': '๐ท๐บ',      'ja': '๐ฏ๐ต', 'ko': '๐ฐ๐ท', 'zh': '๐จ๐ณ', 'ar': '๐ธ๐ฆ', 'hi': '๐ฎ๐ณ', 'th': '๐น๐ญ', 'vi': '๐ป๐ณ',      'tr': '๐น๐ท', 'pl': '๐ต๐ฑ', 'nl': '๐ณ๐ฑ', 'sv': '๐ธ๐ช', 'da': '๐ฉ๐ฐ', 'no': '๐ณ๐ด', 'fi': '๐ซ๐ฎ',      'cs': '๐จ๐ฟ', 'hu': '๐ญ๐บ', 'ro': '๐ท๐ด', 'bg': '๐ง๐ฌ', 'hr': '๐ญ๐ท', 'sk': '๐ธ๐ฐ', 'sl': '๐ธ๐ฎ',      'et': '๐ช๐ช', 'lv': '๐ฑ๐ป', 'lt': '๐ฑ๐น', 'el': '๐ฌ๐ท', 'he': '๐ฎ๐ฑ', 'uk': '๐บ๐ฆ', 'be': '๐ง๐พ',      'ca': '๐ช๐ธ', 'eu': '๐ช๐ธ', 'gl': '๐ช๐ธ', 'cy': '๐ฌ๐ง', 'ga': '๐ฎ๐ช', 'mt': '๐ฒ๐น', 'is': '๐ฎ๐ธ',      'mk': '๐ฒ๐ฐ', 'sq': '๐ฆ๐ฑ', 'sr': '๐ท๐ธ', 'bs': '๐ง๐ฆ', 'me': '๐ฒ๐ช', 'fa': '๐ฎ๐ท', 'ur': '๐ต๐ฐ',      'bn': '๐ง๐ฉ', 'ta': '๐ฎ๐ณ', 'te': '๐ฎ๐ณ', 'ml': '๐ฎ๐ณ', 'kn': '๐ฎ๐ณ', 'gu': '๐ฎ๐ณ', 'pa': '๐ฎ๐ณ',      'or': '๐ฎ๐ณ', 'as': '๐ฎ๐ณ', 'ne': '๐ณ๐ต', 'si': '๐ฑ๐ฐ', 'my': '๐ฒ๐ฒ', 'km': '๐ฐ๐ญ', 'lo': '๐ฑ๐ฆ',      'ka': '๐ฌ๐ช', 'hy': '๐ฆ๐ฒ', 'az': '๐ฆ๐ฟ', 'kk': '๐ฐ๐ฟ', 'ky': '๐ฐ๐ฌ', 'uz': '๐บ๐ฟ', 'mn': '๐ฒ๐ณ',      'bo': '๐จ๐ณ', 'dz': '๐ง๐น', 'ug': '๐จ๐ณ', 'ii': '๐จ๐ณ', 'za': '๐จ๐ณ', 'yue': '๐ญ๐ฐ', 'zh-HK': '๐ญ๐ฐ',      'zh-TW': '๐น๐ผ', 'zh-CN': '๐จ๐ณ', 'id': '๐ฎ๐ฉ', 'ms': '๐ฒ๐พ', 'tl': '๐ต๐ญ', 'ceb': '๐ต๐ญ',      'haw': '๐บ๐ธ', 'mi': '๐ณ๐ฟ', 'sm': '๐ผ๐ธ', 'to': '๐น๐ด', 'fj': '๐ซ๐ฏ', 'ty': '๐ต๐ซ', 'mg': '๐ฒ๐ฌ',      'sw': '๐น๐ฟ', 'am': '๐ช๐น', 'om': '๐ช๐น', 'so': '๐ธ๐ด', 'ti': '๐ช๐ท', 'ha': '๐ณ๐ฌ', 'yo': '๐ณ๐ฌ',      'ig': '๐ณ๐ฌ', 'zu': '๐ฟ๐ฆ', 'xh': '๐ฟ๐ฆ', 'af': '๐ฟ๐ฆ', 'st': '๐ฟ๐ฆ', 'tn': '๐ฟ๐ฆ', 'ss': '๐ฟ๐ฆ',      've': '๐ฟ๐ฆ', 'ts': '๐ฟ๐ฆ', 'nr': '๐ฟ๐ฆ', 'nso': '๐ฟ๐ฆ', 'wo': '๐ธ๐ณ', 'ff': '๐ธ๐ณ', 'dy': '๐ฒ๐ฑ',      'bm': '๐ฒ๐ฑ', 'tw': '๐ฌ๐ญ', 'ak': '๐ฌ๐ญ', 'lg': '๐บ๐ฌ', 'rw': '๐ท๐ผ', 'rn': '๐ง๐ฎ', 'ny': '๐ฒ๐ผ',      'sn': '๐ฟ๐ผ', 'nd': '๐ฟ๐ผ'    };    return flagMap[this.tag] || '๐';  },});Template.changeLanguagePopup.events({  'click .js-set-language'(event) {    Users.update(Meteor.userId(), {      $set: {        'profile.language': this.tag,      },    });    TAPi18n.setLanguage(this.tag);    event.preventDefault();  },});Template.changeSettingsPopup.helpers({  rescueCardDescription() {    const currentUser = ReactiveCache.getCurrentUser();    if (currentUser) {      return (currentUser.profile || {}).rescueCardDescription;    } else if (window.localStorage.getItem('rescueCardDescription')) {      return true;    } else {      return false;    }  },  showCardsCountAt() {    const currentUser = ReactiveCache.getCurrentUser();    if (currentUser) {      return currentUser.getLimitToShowCardsCount();    } else {      return window.localStorage.getItem('limitToShowCardsCount');    }  },  weekDays(startDay) {    return [      TAPi18n.__('sunday'),      TAPi18n.__('monday'),      TAPi18n.__('tuesday'),      TAPi18n.__('wednesday'),      TAPi18n.__('thursday'),      TAPi18n.__('friday'),      TAPi18n.__('saturday'),    ].map(function(day, index) {      return { name: day, value: index, isSelected: index === startDay };    });  },  startDayOfWeek() {    currentUser = ReactiveCache.getCurrentUser();    if (currentUser) {      return currentUser.getStartDayOfWeek();    } else {      return window.localStorage.getItem('startDayOfWeek');    }  },});Template.changeSettingsPopup.events({  'keypress/paste #show-cards-count-at'() {    let keyCode = event.keyCode;    let charCode = String.fromCharCode(keyCode);    let regex = new RegExp('[-0-9]');    let ret = regex.test(charCode);    return ret;  },  'click .js-toggle-desktop-drag-handles'() {    const currentUser = ReactiveCache.getCurrentUser();    if (currentUser) {      Meteor.call('toggleDesktopDragHandles');    } else if (window.localStorage.getItem('showDesktopDragHandles')) {      window.localStorage.removeItem('showDesktopDragHandles');    } else {      window.localStorage.setItem('showDesktopDragHandles', 'true');    }  },  'click .js-rescue-card-description'() {    Meteor.call('toggleRescueCardDescription')    },  'click .js-apply-user-settings'(event, templateInstance) {    event.preventDefault();    let minLimit = parseInt(      templateInstance.$('#show-cards-count-at').val(),      10,    );    const startDay = parseInt(      templateInstance.$('#start-day-of-week').val(),      10,    );    const currentUser = ReactiveCache.getCurrentUser();    if (isNaN(minLimit) || minLimit < -1) {      minLimit = -1;    }    if (!isNaN(minLimit)) {      if (currentUser) {        Meteor.call('changeLimitToShowCardsCount', minLimit);      } else {        window.localStorage.setItem('limitToShowCardsCount', minLimit);      }    }    if (!isNaN(startDay)) {      if (currentUser) {        Meteor.call('changeStartDayOfWeek', startDay);      } else {        window.localStorage.setItem('startDayOfWeek', startDay);      }    }    Popup.back();  },});
 |