Browse Source

Teams/Organizations to Admin Panel. In Progress. Part 2.

Thanks to xet7 !

Related #802
Lauri Ojansivu 4 years ago
parent
commit
ad482d5cfb
3 changed files with 139 additions and 82 deletions
  1. 13 10
      client/components/settings/peopleBody.jade
  2. 122 72
      client/components/settings/peopleBody.js
  3. 4 0
      i18n/en.i18n.json

+ 13 - 10
client/components/settings/peopleBody.jade

@@ -296,7 +296,7 @@ template(name="editTeamPopup")
       span.error.hide.teamname-taken
         | {{_ 'error-teamname-taken'}}
     label
-      | {{_ 'desc'}}
+      | {{_ 'description'}}
       input.js-orgDesc(type="text" value=org.desc required)
     label
       | {{_ 'name'}}
@@ -372,17 +372,20 @@ template(name="newOrgPopup")
   form
     //label.hide.userId(type="text" value=user._id)
     label
-      | {{_ 'orgDisplayName'}}
-      input.js-orgDisplayName(type="text" value="" required)
+      | {{_ 'displayName'}}
+      input.js-displayName(type="text" value="" required)
     label
-      | {{_ 'orgDesc'}}
-      input.js-orgDesc(type="text" value="" required)
+      | {{_ 'description'}}
+      input.js-desc(type="text" value="" required)
     label
-      | {{_ 'orgName'}}
-      input.js-orgName(type="text" value="")
+      | {{_ 'shortName'}}
+      input.js-name(type="text" value="")
     label
-      | {{_ 'orgWebsite'}}
-      input.js-orgWebsite(type="text" value="")
+      | {{_ 'teams'}}
+      input.js-teams(type="text" value="")
+    label
+      | {{_ 'website'}}
+      input.js-website(type="text" value="")
     label
       | {{_ 'active'}}
       select.select-active.js-profile-isactive
@@ -399,7 +402,7 @@ template(name="newTeamPopup")
       | {{_ 'displayName'}}
       input.js-teamDisplayName(type="text" value="" required)
     label
-      | {{_ 'desc'}}
+      | {{_ 'description'}}
       input.js-teamDesc(type="text" value="" required)
     label
       | {{_ 'shortName'}}

+ 122 - 72
client/components/settings/peopleBody.js

@@ -226,18 +226,6 @@ Template.editOrgPopup.helpers({
   org() {
     return Org.findOne(this.orgId);
   },
-  /*
-  isSelected(match) {
-    const orgId = Template.instance().data.orgId;
-    const selected = Org.findOne(orgId).authenticationMethod;
-    return selected === match;
-  },
-  isLdap() {
-    const userId = Template.instance().data.userId;
-    const selected = Users.findOne(userId).authenticationMethod;
-    return selected === 'ldap';
-  },
-  */
   errorMessage() {
     return Template.instance().errorMessage.get();
   },
@@ -247,21 +235,6 @@ Template.editTeamPopup.helpers({
   team() {
     return Team.findOne(this.teamId);
   },
-  /*
-  authentications() {
-    return Template.instance().authenticationMethods.get();
-  },
-  isSelected(match) {
-    const userId = Template.instance().data.userId;
-    const selected = Users.findOne(userId).authenticationMethod;
-    return selected === match;
-  },
-  isLdap() {
-    const userId = Template.instance().data.userId;
-    const selected = Users.findOne(userId).authenticationMethod;
-    return selected === 'ldap';
-  },
-  */
   errorMessage() {
     return Template.instance().errorMessage.get();
   },
@@ -290,43 +263,11 @@ Template.editUserPopup.helpers({
 });
 
 Template.newOrgPopup.onCreated(function() {
-  //this.authenticationMethods = new ReactiveVar([]);
   this.errorMessage = new ReactiveVar('');
-  /*
-  Meteor.call('getAuthenticationsEnabled', (_, result) => {
-    if (result) {
-      // TODO : add a management of different languages
-      // (ex {value: ldap, text: TAPi18n.__('ldap', {}, T9n.getLanguage() || 'en')})
-      this.authenticationMethods.set([
-        { value: 'password' },
-        // Gets only the authentication methods availables
-        ...Object.entries(result)
-          .filter(e => e[1])
-          .map(e => ({ value: e[0] })),
-      ]);
-    }
-  });
-*/
 });
 
 Template.newTeamPopup.onCreated(function() {
-  //this.authenticationMethods = new ReactiveVar([]);
   this.errorMessage = new ReactiveVar('');
-  /*
-  Meteor.call('getAuthenticationsEnabled', (_, result) => {
-    if (result) {
-      // TODO : add a management of different languages
-      // (ex {value: ldap, text: TAPi18n.__('ldap', {}, T9n.getLanguage() || 'en')})
-      this.authenticationMethods.set([
-        { value: 'password' },
-        // Gets only the authentication methods availables
-        ...Object.entries(result)
-          .filter(e => e[1])
-          .map(e => ({ value: e[0] })),
-      ]);
-    }
-  });
-*/
 });
 
 Template.newUserPopup.onCreated(function() {
@@ -348,28 +289,76 @@ Template.newUserPopup.onCreated(function() {
   });
 });
 
+Template.newOrgPopup.helpers({
+  org() {
+    return Org.findOne(this.orgId);
+  },
+  errorMessage() {
+    return Template.instance().errorMessage.get();
+  },
+});
+
+Template.newTeamPopup.helpers({
+  team() {
+    return Team.findOne(this.teamId);
+  },
+  errorMessage() {
+    return Template.instance().errorMessage.get();
+  },
+});
+
 Template.newUserPopup.helpers({
-  //user() {
-  //  return Users.findOne(this.userId);
-  //},
+  user() {
+    return Users.findOne(this.userId);
+  },
   authentications() {
     return Template.instance().authenticationMethods.get();
   },
-  //isSelected(match) {
-  //  const userId = Template.instance().data.userId;
-  //  const selected = Users.findOne(userId).authenticationMethod;
-  //  return selected === match;
-  //},
-  //isLdap() {
-  //  const userId = Template.instance().data.userId;
-  //  const selected = Users.findOne(userId).authenticationMethod;
-  //  return selected === 'ldap';
-  //},
+  isSelected(match) {
+    const userId = Template.instance().data.userId;
+    const selected = Users.findOne(userId).authenticationMethod;
+    return selected === match;
+  },
+  isLdap() {
+    const userId = Template.instance().data.userId;
+    const selected = Users.findOne(userId).authenticationMethod;
+    return selected === 'ldap';
+  },
   errorMessage() {
     return Template.instance().errorMessage.get();
   },
 });
 
+BlazeComponent.extendComponent({
+  onCreated() {},
+  org() {
+    return Org.findOne(this.orgId);
+  },
+  events() {
+    return [
+      {
+        'click a.edit-org': Popup.open('editOrg'),
+        'click a.more-settings-org': Popup.open('settingsOrg'),
+      },
+    ];
+  },
+}).register('orgRow');
+
+BlazeComponent.extendComponent({
+  onCreated() {},
+  team() {
+    return Team.findOne(this.teamId);
+  },
+  events() {
+    return [
+      {
+        'click a.edit-team': Popup.open('editTeam'),
+        'click a.more-settings-team': Popup.open('settingsTeam'),
+      },
+    ];
+  },
+}).register('teamRow');
+
 BlazeComponent.extendComponent({
   onCreated() {},
   user() {
@@ -385,6 +374,26 @@ BlazeComponent.extendComponent({
   },
 }).register('peopleRow');
 
+BlazeComponent.extendComponent({
+  events() {
+    return [
+      {
+        'click a.new-org': Popup.open('newOrg'),
+      },
+    ];
+  },
+}).register('newOrgRow');
+
+BlazeComponent.extendComponent({
+  events() {
+    return [
+      {
+        'click a.new-team': Popup.open('newTeam'),
+      },
+    ];
+  },
+}).register('newTeamRow');
+
 BlazeComponent.extendComponent({
   events() {
     return [
@@ -504,6 +513,47 @@ Template.editUserPopup.events({
   },
 });
 
+Template.newOrgPopup.events({
+  submit(event, templateInstance) {
+    event.preventDefault();
+    const displayName = templateInstance.find('.js-displayName').value.trim();
+    const desc = templateInstance.find('.js-desc').value.trim();
+    const name = templateInstance.find('.js-name').value.trim();
+    const teams = templateInstance.find('.js-teams').value.trim();
+    const website = templateInstance.find('.js-website').value.trim();
+    const isActive = templateInstance.find('.js-profile-isactive').value.trim();
+
+    Meteor.call(
+      'setCreateOrg',
+      displayName,
+      desc,
+      name,
+      teams,
+      website,
+      isActive,
+      email.toLowerCase(),
+      function(error) {
+        const nameMessageElement = templateInstance.$('.name-taken');
+        if (error) {
+          const errorElement = error.error;
+          if (errorElement === 'name-already-taken') {
+            nameMessageElement.show();
+            emailMessageElement.hide();
+          } else if (errorElement === 'email-already-taken') {
+            usernameMessageElement.hide();
+            emailMessageElement.show();
+          }
+        } else {
+          usernameMessageElement.hide();
+          emailMessageElement.hide();
+          Popup.close();
+        }
+      },
+    );
+    Popup.close();
+  },
+});
+
 Template.newUserPopup.events({
   submit(event, templateInstance) {
     event.preventDefault();

+ 4 - 0
i18n/en.i18n.json

@@ -809,6 +809,10 @@
   "addmore-detail": "Add a more detailed description",
   "show-on-card": "Show on Card",
   "new": "New",
+  "editOrgPopup-title": "Edit Organization",
+  "newOrgPopup-title": "New Organization",
+  "editTeamPopup-title": "Edit Team",
+  "newTeamPopup-title": "New Team",
   "editUserPopup-title": "Edit User",
   "newUserPopup-title": "New User",
   "notifications": "Notifications",