Skip to content
Snippets Groups Projects
Commit 894ca600 authored by srosse's avatar srosse
Browse files

OO-2196: 2 steps to add an invitation

parent 61339e41
No related branches found
No related tags found
No related merge requests found
......@@ -84,7 +84,8 @@ public class InvitationEditRightsController extends FormBasicController {
private TextElement firstNameEl, lastNameEl, mailEl;
private int counter;
private String email;
private Binder binder;
private Identity invitee;
private Invitation invitation;
......@@ -101,10 +102,17 @@ public class InvitationEditRightsController extends FormBasicController {
@Autowired
private PortfolioService portfolioService;
public InvitationEditRightsController(UserRequest ureq, WindowControl wControl, Binder binder) {
public InvitationEditRightsController(UserRequest ureq, WindowControl wControl, Binder binder, String email) {
super(ureq, wControl, "invitee_access_rights");
this.email = email;
this.binder = binder;
invitation = invitationDao.createInvitation();
List<Identity> identities = userManager.findIdentitiesByEmail(Collections.singletonList(email));
if(identities.size() == 1) {
invitee = identities.get(0);
invitation = invitationDao.findInvitation(binder.getBaseGroup(), invitee);
} else {
invitation = invitationDao.createInvitation();
}
initForm(ureq);
loadModel();
}
......@@ -130,7 +138,8 @@ public class InvitationEditRightsController extends FormBasicController {
lastNameEl = uifactory.addTextElement("lastName", "lastName", 64, invitation.getLastName(), inviteeCont);
lastNameEl.setMandatory(true);
mailEl = uifactory.addTextElement("mail", "mail", 128, invitation.getMail(), inviteeCont);
String invitationEmail = email != null ? email : invitation.getMail();
mailEl = uifactory.addTextElement("mail", "mail", 128, invitationEmail, inviteeCont);
mailEl.setMandatory(true);
mailEl.setNotEmptyCheck("map.share.empty.warn");
mailEl.setEnabled(invitation.getKey() == null);
......
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.modules.portfolio.ui;
import org.olat.basesecurity.BaseSecurity;
import org.olat.basesecurity.Constants;
import org.olat.basesecurity.SecurityGroup;
import org.olat.core.gui.UserRequest;
import org.olat.core.gui.components.form.flexible.FormItemContainer;
import org.olat.core.gui.components.form.flexible.elements.TextElement;
import org.olat.core.gui.components.form.flexible.impl.FormBasicController;
import org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer;
import org.olat.core.gui.control.Controller;
import org.olat.core.gui.control.Event;
import org.olat.core.gui.control.WindowControl;
import org.olat.core.id.Identity;
import org.olat.core.util.StringHelper;
import org.olat.core.util.mail.MailHelper;
import org.olat.modules.portfolio.Binder;
import org.olat.user.UserManager;
import org.springframework.beans.factory.annotation.Autowired;
/**
*
* Initial date: 29.06.2016<br>
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*
*/
public class InvitationEmailController extends FormBasicController {
private TextElement mailEl;
private Binder binder;
@Autowired
private UserManager userManager;
@Autowired
private BaseSecurity securityManager;
public InvitationEmailController(UserRequest ureq, WindowControl wControl, Binder binder) {
super(ureq, wControl);
this.binder = binder;
initForm(ureq);
}
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
mailEl = uifactory.addTextElement("mail", "mail", 128, "", formLayout);
mailEl.setMandatory(true);
mailEl.setNotEmptyCheck("map.share.empty.warn");
FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
formLayout.add(buttonsCont);
buttonsCont.setRootForm(mainForm);
uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
uifactory.addFormSubmitButton("save", buttonsCont);
}
@Override
protected void doDispose() {
//
}
public Binder getBinder() {
return binder;
}
public String getEmail() {
return mailEl.getValue();
}
@Override
protected boolean validateFormLogic(UserRequest ureq) {
boolean allOk = true;
if (mailEl != null) {
String mail = mailEl.getValue();
if (StringHelper.containsNonWhitespace(mail)) {
if (MailHelper.isValidEmailAddress(mail)) {
SecurityGroup allUsers = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
Identity currentIdentity = userManager.findIdentityByEmail(mail);
if (currentIdentity != null && securityManager.isIdentityInSecurityGroup(currentIdentity, allUsers)) {
mailEl.setErrorKey("map.share.with.mail.error.olatUser", new String[] { mail });
allOk &= false;
}
} else {
mailEl.setErrorKey("error.mail.invalid", null);
allOk &= false;
}
} else {
mailEl.setErrorKey("form.legende.mandatory", null);
allOk &= false;
}
}
return allOk & super.validateFormLogic(ureq);
}
@Override
protected void formOK(UserRequest ureq) {
fireEvent(ureq, Event.DONE_EVENT);
}
@Override
protected void formCancelled(UserRequest ureq) {
fireEvent(ureq, Event.CANCELLED_EVENT);
}
}
\ No newline at end of file
......@@ -88,9 +88,10 @@ public class PublishController extends BasicController implements TooledControll
private final TooledStackedPanel stackPanel;
private CloseableModalController cmc;
private InvitationEditRightsController addInvitationCtrl;
private AccessRightsEditController editAccessRightsCtrl;
private StepsMainRunController addMembersWizard;
private AccessRightsEditController editAccessRightsCtrl;
private InvitationEditRightsController addInvitationCtrl;
private InvitationEmailController addInvitationEmailCtrl;
private int counter;
private Binder binder;
......@@ -224,7 +225,7 @@ public class PublishController extends BasicController implements TooledControll
if(addAccessRightsLink == source) {
doAddAccessRights(ureq);
} else if(addInvitationLink == source) {
doAddInvitation(ureq);
doAddInvitationEmail(ureq);
} else if(source instanceof Link) {
Link link = (Link)source;
String cmd = link.getCommand();
......@@ -250,6 +251,16 @@ public class PublishController extends BasicController implements TooledControll
}
cleanUp();
}
} else if(addInvitationEmailCtrl == source) {
if(event == Event.CANCELLED_EVENT || event == Event.DONE_EVENT || event == Event.CHANGED_EVENT) {
String email = addInvitationEmailCtrl.getEmail();
cmc.deactivate();
cleanUp();
if(event == Event.DONE_EVENT) {
doAddInvitation(ureq, email);
}
}
} else if(addInvitationCtrl == source) {
if(event == Event.CANCELLED_EVENT || event == Event.DONE_EVENT || event == Event.CHANGED_EVENT) {
getWindowControl().pop();
......@@ -277,20 +288,34 @@ public class PublishController extends BasicController implements TooledControll
}
private void cleanUp() {
removeAsListenerAndDispose(addInvitationEmailCtrl);
removeAsListenerAndDispose(editAccessRightsCtrl);
removeAsListenerAndDispose(addInvitationCtrl);
removeAsListenerAndDispose(addMembersWizard);
removeAsListenerAndDispose(cmc);
addInvitationEmailCtrl = null;
editAccessRightsCtrl = null;
addInvitationCtrl = null;
addMembersWizard = null;
cmc = null;
}
private void doAddInvitation(UserRequest ureq) {
private void doAddInvitationEmail(UserRequest ureq) {
if(addInvitationEmailCtrl != null) return;
addInvitationEmailCtrl = new InvitationEmailController(ureq, getWindowControl(), binder);
listenTo(addInvitationEmailCtrl);
String title = translate("add.invitation");
cmc = new CloseableModalController(getWindowControl(), null, addInvitationEmailCtrl.getInitialComponent(), true, title, true);
listenTo(cmc);
cmc.activate();
}
private void doAddInvitation(UserRequest ureq, String email) {
if(addInvitationCtrl != null) return;
addInvitationCtrl = new InvitationEditRightsController(ureq, getWindowControl(), binder);
addInvitationCtrl = new InvitationEditRightsController(ureq, getWindowControl(), binder, email);
listenTo(addInvitationCtrl);
String title = translate("add.invitation");
......
......@@ -4,25 +4,21 @@ $r.render("inviteeInfos")
<thead><tr>
<th>$r.translate("access.rights.element")</th>
<th>$r.translate("access.rights.invitee")</th>
<th>$r.translate("access.rights.date")</th>
</tr></thead>
<tbody>
<tr class="o_portfolio_binder">
<td>$r.escapeHtml(${binderRow.title})</td>
<td>$r.render($binderRow.access)</td>
<td></td>
</tr>
#foreach($sectionRow in $binderRow.sections)
<tr class="o_portfolio_section">
<td>${foreach.count}. $r.escapeHtml(${sectionRow.title})</td>
<td>$r.render(${sectionRow.access})</td>
<td></td>
</tr>
#foreach($pageRow in $sectionRow.pages)
<tr class="o_portfolio_page">
<td>$r.escapeHtml(${pageRow.title})</td>
<td>$r.render(${pageRow.access})</td>
<td></td>
</tr>
#end
#end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment