use of org.olat.core.commons.services.license.ui.LicenseSelectionConfig in project OpenOLAT by OpenOLAT.
the class MetaInfoFormController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
if (isSubform) {
setFormTitle("mf.metadata.title");
}
setFormContextHelp("Folders#_metadata");
MetaInfo meta = item instanceof OlatRelPathImpl ? metaInfoFactory.createMetaInfoFor((OlatRelPathImpl) item) : null;
// title
String titleVal = (meta != null ? meta.getTitle() : null);
title = uifactory.addTextElement("title", "mf.title", -1, titleVal, formLayout);
// filename
initialFilename = (item == null ? null : item.getName());
filename = uifactory.addTextElement("filename", "mf.filename", -1, initialFilename, formLayout);
filename.setEnabled(item == null || item.canRename() == VFSConstants.YES);
filename.setNotEmptyCheck("mf.error.empty");
filename.setMandatory(true);
// comment/description
String commentVal = (meta != null ? meta.getComment() : null);
comment = uifactory.addTextAreaElement("comment", "mf.comment", -1, 3, 1, true, commentVal, formLayout);
// license
if (licenseModule.isEnabled(licenseHandler)) {
License license = metaInfoFactory.getOrCreateLicense(meta, getIdentity());
LicenseSelectionConfig licenseSelectionConfig = LicenseUIFactory.createLicenseSelectionConfig(licenseHandler, license.getLicenseType());
licenseEl = uifactory.addDropdownSingleselect("mf.license", formLayout, licenseSelectionConfig.getLicenseTypeKeys(), licenseSelectionConfig.getLicenseTypeValues(getLocale()));
licenseEl.setMandatory(licenseSelectionConfig.isLicenseMandatory());
if (licenseSelectionConfig.getSelectionLicenseTypeKey() != null) {
licenseEl.select(licenseSelectionConfig.getSelectionLicenseTypeKey(), true);
}
licenseEl.addActionListener(FormEvent.ONCHANGE);
licensorEl = uifactory.addTextElement("mf.licensor", 1000, license.getLicensor(), formLayout);
String freetext = licenseService.isFreetext(license.getLicenseType()) ? license.getFreetext() : "";
licenseFreetextEl = uifactory.addTextAreaElement("mf.freetext", 4, 72, freetext, formLayout);
LicenseUIFactory.updateVisibility(licenseEl, licensorEl, licenseFreetextEl);
}
// creator
String creatorVal = (meta != null ? meta.getCreator() : null);
creator = uifactory.addTextElement("creator", "mf.creator", -1, creatorVal, formLayout);
// publisher
String publisherVal = (meta != null ? meta.getPublisher() : null);
publisher = uifactory.addTextElement("publisher", "mf.publisher", -1, publisherVal, formLayout);
// source/origin
String sourceVal = (meta != null ? meta.getSource() : null);
sourceEl = uifactory.addTextElement("source", "mf.source", -1, sourceVal, formLayout);
// city
String cityVal = (meta != null ? meta.getCity() : null);
city = uifactory.addTextElement("city", "mf.city", -1, cityVal, formLayout);
// publish date
String datePage = velocity_root + "/date.html";
FormLayoutContainer publicationDate = FormLayoutContainer.createCustomFormLayout("publicationDateLayout", getTranslator(), datePage);
publicationDate.setLabel("mf.publishDate", null);
formLayout.add(publicationDate);
String[] pubDate = (meta != null ? meta.getPublicationDate() : new String[] { "", "" });
publicationMonth = uifactory.addTextElement("publicationMonth", "mf.month", 2, StringHelper.escapeHtml(pubDate[1]), publicationDate);
publicationMonth.setDomReplacementWrapperRequired(false);
publicationMonth.setMaxLength(2);
publicationMonth.setDisplaySize(2);
publicationYear = uifactory.addTextElement("publicationYear", "mf.year", 4, StringHelper.escapeHtml(pubDate[0]), publicationDate);
publicationYear.setDomReplacementWrapperRequired(false);
publicationYear.setMaxLength(4);
publicationYear.setDisplaySize(4);
// number of pages
String pageVal = (meta != null ? meta.getPages() : null);
pages = uifactory.addTextElement("pages", "mf.pages", -1, pageVal, formLayout);
// language
String langVal = (meta != null ? meta.getLanguage() : null);
language = uifactory.addTextElement("language", "mf.language", -1, langVal, formLayout);
// url/link
String urlVal = (meta != null ? meta.getUrl() : null);
url = uifactory.addTextElement("url", "mf.url", -1, urlVal, formLayout);
/* static fields */
String sizeText, typeText;
if (item instanceof VFSLeaf) {
sizeText = Formatter.formatBytes(((VFSLeaf) item).getSize());
typeText = FolderHelper.extractFileType(item.getName(), getLocale());
} else {
sizeText = "-";
typeText = translate("mf.type.directory");
}
// Targets to hide
metaFields = new HashSet<>();
metaFields.add(creator);
metaFields.add(publisher);
metaFields.add(sourceEl);
metaFields.add(city);
metaFields.add(publicationDate);
metaFields.add(pages);
metaFields.add(language);
metaFields.add(url);
if (!hasMetadata(meta)) {
moreMetaDataLink = uifactory.addFormLink("mf.more.meta.link", formLayout, Link.LINK_CUSTOM_CSS);
setMetaFieldsVisible(false);
}
if (!isSubform) {
if (meta != null && !meta.isDirectory()) {
LockInfo lock = vfsLockManager.getLock(item);
// locked
String lockedTitle = getTranslator().translate("mf.locked");
String unlockedTitle = getTranslator().translate("mf.unlocked");
locked = uifactory.addRadiosHorizontal("locked", "mf.locked", formLayout, new String[] { "lock", "unlock" }, new String[] { lockedTitle, unlockedTitle });
locked.setHelpText(getTranslator().translate("mf.locked.help"));
if (vfsLockManager.isLocked(item)) {
locked.select("lock", true);
} else {
locked.select("unlock", true);
}
boolean lockForMe = vfsLockManager.isLockedForMe(item, getIdentity(), roles);
locked.setEnabled(!lockForMe);
// locked by
String lockedDetails = "";
if (lock != null) {
String user = userManager.getUserDisplayName(lock.getLockedBy());
user = StringHelper.escapeHtml(user);
String date = "";
if (lock.getCreationDate() != null) {
date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, getLocale()).format(lock.getCreationDate());
}
lockedDetails = getTranslator().translate("mf.locked.description", new String[] { user, date });
} else {
lockedDetails = getTranslator().translate("mf.unlocked.description");
}
uifactory.addStaticTextElement("mf.lockedBy", lockedDetails, formLayout);
}
// username
String author = StringHelper.escapeHtml(meta == null ? "" : meta.getHTMLFormattedAuthor());
uifactory.addStaticTextElement("mf.author", author, formLayout);
// filesize
uifactory.addStaticTextElement("mf.size", StringHelper.escapeHtml(sizeText), formLayout);
// last modified date
String lastModified = meta == null ? "" : StringHelper.formatLocaleDate(meta.getLastModified(), getLocale());
uifactory.addStaticTextElement("mf.lastModified", lastModified, formLayout);
// file type
uifactory.addStaticTextElement("mf.type", StringHelper.escapeHtml(typeText), formLayout);
String downloads = meta == null ? "" : String.valueOf(meta.getDownloadCount());
uifactory.addStaticTextElement("mf.downloads", downloads, formLayout);
}
boolean xssErrors = false;
if (item != null) {
xssErrors = StringHelper.xssScanForErrors(item.getName());
}
if (StringHelper.containsNonWhitespace(resourceUrl) && !xssErrors) {
String externalUrlPage = velocity_root + "/external_url.html";
FormLayoutContainer extUrlCont = FormLayoutContainer.createCustomFormLayout("external.url", getTranslator(), externalUrlPage);
extUrlCont.setLabel("external.url", null);
extUrlCont.contextPut("resourceUrl", resourceUrl);
extUrlCont.setRootForm(mainForm);
formLayout.add(extUrlCont);
}
if (!isSubform && meta != null && meta.isDirectory()) {
// Don't show any meta data except title and comment if the item is
// a directory.
// Hide the metadata.
setMetaFieldsVisible(false);
if (moreMetaDataLink != null)
moreMetaDataLink.setVisible(false);
}
// save and cancel buttons
if (!isSubform) {
final FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("buttonLayout", getTranslator());
formLayout.add(buttonLayout);
if (meta != null) {
uifactory.addFormSubmitButton("submit", buttonLayout);
}
uifactory.addFormCancelButton("cancel", buttonLayout, ureq, getWindowControl());
}
}
use of org.olat.core.commons.services.license.ui.LicenseSelectionConfig in project OpenOLAT by OpenOLAT.
the class MetadataBulkChangeController method initRightsForm.
private void initRightsForm(FormItemContainer formLayout) {
FormLayoutContainer rightsCont = FormLayoutContainer.createDefaultFormLayout("rights", getTranslator());
rightsCont.setRootForm(mainForm);
if (licenseModule.isEnabled(licenseHandler)) {
formLayout.add(rightsCont);
}
LicenseSelectionConfig licenseSelectionConfig = LicenseUIFactory.createLicenseSelectionConfig(licenseHandler);
licensorEl = uifactory.addTextElement("rights.licensor", 1000, "", rightsCont);
decorate(licensorEl, rightsCont);
licenseWrapperCont = FormLayoutContainer.createDefaultFormLayout("rights.license", getTranslator());
licenseWrapperCont.setRootForm(mainForm);
rightsCont.add(licenseWrapperCont);
decorate(licenseWrapperCont, rightsCont);
if (licenseSelectionConfig.getLicenseTypeKeys().length > 0) {
licenseEl = uifactory.addDropdownSingleselect("rights.license.sel", "rights.license", licenseWrapperCont, licenseSelectionConfig.getLicenseTypeKeys(), licenseSelectionConfig.getLicenseTypeValues(getLocale()), null);
licenseEl.addActionListener(FormEvent.ONCHANGE);
licenseEl.select(licenseSelectionConfig.getLicenseTypeKeys()[0], true);
licenseFreetextEl = uifactory.addTextAreaElement("rights.freetext", 4, 72, "", licenseWrapperCont);
licenseFreetextEl.setVisible(false);
}
}
use of org.olat.core.commons.services.license.ui.LicenseSelectionConfig in project openolat by klemens.
the class RepositoryEditDescriptionController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
setFormContextHelp("Info Page: Add Meta Data");
formLayout.setElementCssClass("o_sel_edit_repositoryentry");
String id = repositoryEntry.getResourceableId() == null ? "-" : repositoryEntry.getResourceableId().toString();
uifactory.addStaticTextElement("cif.id", id, formLayout);
String externalId = repositoryEntry.getExternalId();
if (StringHelper.containsNonWhitespace(externalId)) {
uifactory.addStaticTextElement("cif.externalid", externalId, formLayout);
}
String extRef = repositoryEntry.getExternalRef();
if (StringHelper.containsNonWhitespace(repositoryEntry.getManagedFlagsString())) {
if (StringHelper.containsNonWhitespace(extRef)) {
uifactory.addStaticTextElement("cif.externalref", extRef, formLayout);
}
} else {
externalRef = uifactory.addTextElement("cif.externalref", "cif.externalref", 100, extRef, formLayout);
externalRef.setHelpText(translate("cif.externalref.hover"));
externalRef.setHelpUrlForManualPage("Info Page#_identification");
externalRef.setDisplaySize(30);
}
String initalAuthor = repositoryEntry.getInitialAuthor() == null ? "-" : repositoryEntry.getInitialAuthor();
if (repositoryEntry.getInitialAuthor() != null) {
initalAuthor = userManager.getUserDisplayName(initalAuthor);
}
initalAuthor = StringHelper.escapeHtml(initalAuthor);
uifactory.addStaticTextElement("cif.initialAuthor", initalAuthor, formLayout);
// Add resource type
String typeName = null;
OLATResource res = repositoryEntry.getOlatResource();
if (res != null) {
typeName = res.getResourceableTypeName();
}
String typeDisplay;
if (typeName != null) {
// add image and typename code
typeDisplay = NewControllerFactory.translateResourceableTypeName(typeName, getLocale());
} else {
typeDisplay = translate("cif.type.na");
}
uifactory.addStaticTextElement("cif.type", typeDisplay, formLayout);
uifactory.addSpacerElement("spacer1", formLayout, false);
displayName = uifactory.addTextElement("cif.displayname", "cif.displayname", 100, repositoryEntry.getDisplayname(), formLayout);
displayName.setDisplaySize(30);
displayName.setMandatory(true);
displayName.setEnabled(!RepositoryEntryManagedFlag.isManaged(repositoryEntry, RepositoryEntryManagedFlag.title));
authors = uifactory.addTextElement("cif.authors", "cif.authors", 255, repositoryEntry.getAuthors(), formLayout);
authors.setDisplaySize(60);
if (licenseModule.isEnabled(licenseHandler)) {
license = licenseService.loadOrCreateLicense(res);
LicenseSelectionConfig licenseSelectionConfig = LicenseUIFactory.createLicenseSelectionConfig(licenseHandler, license.getLicenseType());
licenseEl = uifactory.addDropdownSingleselect("cif.license", formLayout, licenseSelectionConfig.getLicenseTypeKeys(), licenseSelectionConfig.getLicenseTypeValues(getLocale()));
licenseEl.setElementCssClass("o_sel_repo_license");
licenseEl.setMandatory(licenseSelectionConfig.isLicenseMandatory());
if (licenseSelectionConfig.getSelectionLicenseTypeKey() != null) {
licenseEl.select(licenseSelectionConfig.getSelectionLicenseTypeKey(), true);
}
licenseEl.addActionListener(FormEvent.ONCHANGE);
licensorEl = uifactory.addTextElement("cif.licensor", 1000, license.getLicensor(), formLayout);
String freetext = licenseService.isFreetext(license.getLicenseType()) ? license.getFreetext() : "";
licenseFreetextEl = uifactory.addTextAreaElement("cif.freetext", 4, 72, freetext, formLayout);
LicenseUIFactory.updateVisibility(licenseEl, licensorEl, licenseFreetextEl);
}
language = uifactory.addTextElement("cif.mainLanguage", "cif.mainLanguage", 16, repositoryEntry.getMainLanguage(), formLayout);
location = uifactory.addTextElement("cif.location", "cif.location", 255, repositoryEntry.getLocation(), formLayout);
location.setEnabled(!RepositoryEntryManagedFlag.isManaged(repositoryEntry, RepositoryEntryManagedFlag.location));
RepositoryHandler handler = repositoryHandlerFactory.getRepositoryHandler(repositoryEntry);
mediaContainer = handler.getMediaContainer(repositoryEntry);
if (mediaContainer != null && mediaContainer.getName().equals("media")) {
mediaContainer = mediaContainer.getParentContainer();
mediaContainer.setDefaultItemFilter(new MediaContainerFilter(mediaContainer));
}
String desc = (repositoryEntry.getDescription() != null ? repositoryEntry.getDescription() : " ");
description = uifactory.addRichTextElementForStringData("cif.description", "cif.description", desc, 10, -1, false, mediaContainer, null, formLayout, ureq.getUserSession(), getWindowControl());
description.setEnabled(!RepositoryEntryManagedFlag.isManaged(repositoryEntry, RepositoryEntryManagedFlag.description));
description.getEditorConfiguration().setFileBrowserUploadRelPath("media");
uifactory.addSpacerElement("spacer2", formLayout, false);
if (CourseModule.getCourseTypeName().equals(repoEntryType)) {
String[] dateValues = new String[] { translate("cif.dates.none"), translate("cif.dates.private"), translate("cif.dates.public") };
dateTypesEl = uifactory.addRadiosVertical("cif.dates", formLayout, dateKeys, dateValues);
dateTypesEl.setElementCssClass("o_sel_repo_lifecycle_type");
if (repositoryEntry.getLifecycle() == null) {
dateTypesEl.select("none", true);
} else if (repositoryEntry.getLifecycle().isPrivateCycle()) {
dateTypesEl.select("private", true);
} else {
dateTypesEl.select("public", true);
}
dateTypesEl.addActionListener(FormEvent.ONCHANGE);
List<RepositoryEntryLifecycle> cycles = lifecycleDao.loadPublicLifecycle();
List<RepositoryEntryLifecycle> filteredCycles = new ArrayList<>();
// just make the upcomming and acutual running cycles or the pre-selected visible in the UI
LocalDateTime now = LocalDateTime.now();
for (RepositoryEntryLifecycle cycle : cycles) {
if (cycle.getValidTo() == null || now.isBefore(LocalDateTime.ofInstant(cycle.getValidTo().toInstant(), ZoneId.systemDefault())) || (repositoryEntry.getLifecycle() != null && repositoryEntry.getLifecycle().equals(cycle))) {
filteredCycles.add(cycle);
}
}
String[] publicKeys = new String[filteredCycles.size()];
String[] publicValues = new String[filteredCycles.size()];
int count = 0;
for (RepositoryEntryLifecycle cycle : filteredCycles) {
publicKeys[count] = cycle.getKey().toString();
StringBuilder sb = new StringBuilder(32);
boolean labelAvailable = StringHelper.containsNonWhitespace(cycle.getLabel());
if (labelAvailable) {
sb.append(cycle.getLabel());
}
if (StringHelper.containsNonWhitespace(cycle.getSoftKey())) {
if (labelAvailable)
sb.append(" - ");
sb.append(cycle.getSoftKey());
}
publicValues[count++] = sb.toString();
}
publicDatesEl = uifactory.addDropdownSingleselect("cif.public.dates", formLayout, publicKeys, publicValues, null);
String privateDatePage = velocity_root + "/cycle_dates.html";
privateDatesCont = FormLayoutContainer.createCustomFormLayout("private.date", getTranslator(), privateDatePage);
privateDatesCont.setRootForm(mainForm);
privateDatesCont.setLabel("cif.private.dates", null);
formLayout.add("private.date", privateDatesCont);
startDateEl = uifactory.addDateChooser("date.start", "cif.date.start", null, privateDatesCont);
startDateEl.setElementCssClass("o_sel_repo_lifecycle_validfrom");
endDateEl = uifactory.addDateChooser("date.end", "cif.date.end", null, privateDatesCont);
endDateEl.setElementCssClass("o_sel_repo_lifecycle_validto");
if (repositoryEntry.getLifecycle() != null) {
RepositoryEntryLifecycle lifecycle = repositoryEntry.getLifecycle();
if (lifecycle.isPrivateCycle()) {
startDateEl.setDate(lifecycle.getValidFrom());
endDateEl.setDate(lifecycle.getValidTo());
} else {
String key = lifecycle.getKey().toString();
for (String publicKey : publicKeys) {
if (key.equals(publicKey)) {
publicDatesEl.select(key, true);
break;
}
}
}
}
updateDatesVisibility();
uifactory.addSpacerElement("spacer3", formLayout, false);
expenditureOfWork = uifactory.addTextElement("cif.expenditureOfWork", "cif.expenditureOfWork", 100, repositoryEntry.getExpenditureOfWork(), formLayout);
expenditureOfWork.setExampleKey("details.expenditureOfWork.example", null);
String obj = (repositoryEntry.getObjectives() != null ? repositoryEntry.getObjectives() : " ");
objectives = uifactory.addRichTextElementForStringData("cif.objectives", "cif.objectives", obj, 10, -1, false, mediaContainer, null, formLayout, ureq.getUserSession(), getWindowControl());
objectives.setEnabled(!RepositoryEntryManagedFlag.isManaged(repositoryEntry, RepositoryEntryManagedFlag.objectives));
objectives.getEditorConfiguration().setFileBrowserUploadRelPath("media");
String req = (repositoryEntry.getRequirements() != null ? repositoryEntry.getRequirements() : " ");
requirements = uifactory.addRichTextElementForStringData("cif.requirements", "cif.requirements", req, 10, -1, false, mediaContainer, null, formLayout, ureq.getUserSession(), getWindowControl());
requirements.setEnabled(!RepositoryEntryManagedFlag.isManaged(repositoryEntry, RepositoryEntryManagedFlag.requirements));
requirements.getEditorConfiguration().setFileBrowserUploadRelPath("media");
requirements.setMaxLength(2000);
String cred = (repositoryEntry.getCredits() != null ? repositoryEntry.getCredits() : " ");
credits = uifactory.addRichTextElementForStringData("cif.credits", "cif.credits", cred, 10, -1, false, mediaContainer, null, formLayout, ureq.getUserSession(), getWindowControl());
credits.setEnabled(!RepositoryEntryManagedFlag.isManaged(repositoryEntry, RepositoryEntryManagedFlag.credits));
credits.getEditorConfiguration().setFileBrowserUploadRelPath("media");
credits.setMaxLength(2000);
uifactory.addSpacerElement("spacer4", formLayout, false);
}
boolean managed = RepositoryEntryManagedFlag.isManaged(repositoryEntry, RepositoryEntryManagedFlag.details);
VFSLeaf img = repositoryManager.getImage(repositoryEntry);
fileUpload = uifactory.addFileElement(getWindowControl(), "rentry.pic", "rentry.pic", formLayout);
fileUpload.setExampleKey("rentry.pic.example", new String[] { RepositoryManager.PICTURE_WIDTH + "x" + (RepositoryManager.PICTURE_HEIGHT) });
fileUpload.setMaxUploadSizeKB(picUploadlimitKB, null, null);
fileUpload.setPreview(ureq.getUserSession(), true);
fileUpload.addActionListener(FormEvent.ONCHANGE);
fileUpload.setDeleteEnabled(!managed);
if (img instanceof LocalFileImpl) {
fileUpload.setPreview(ureq.getUserSession(), true);
fileUpload.setInitialFile(((LocalFileImpl) img).getBasefile());
}
fileUpload.setVisible(!managed);
fileUpload.limitToMimeType(imageMimeTypes, "cif.error.mimetype", new String[] { imageMimeTypes.toString() });
VFSLeaf movie = repositoryService.getIntroductionMovie(repositoryEntry);
movieUpload = uifactory.addFileElement(getWindowControl(), "rentry.movie", "rentry.movie", formLayout);
movieUpload.setExampleKey("rentry.movie.example", new String[] { "3:2" });
movieUpload.setMaxUploadSizeKB(movieUploadlimitKB, null, null);
movieUpload.setPreview(ureq.getUserSession(), true);
movieUpload.addActionListener(FormEvent.ONCHANGE);
movieUpload.setDeleteEnabled(!managed);
if (movie instanceof LocalFileImpl) {
movieUpload.setPreview(ureq.getUserSession(), true);
movieUpload.setInitialFile(((LocalFileImpl) movie).getBasefile());
}
movieUpload.setVisible(!managed);
FormLayoutContainer buttonContainer = FormLayoutContainer.createButtonLayout("buttonContainer", getTranslator());
formLayout.add("buttonContainer", buttonContainer);
buttonContainer.setElementCssClass("o_sel_repo_save_details");
submit = uifactory.addFormSubmitButton("submit", buttonContainer);
submit.setVisible(!managed);
uifactory.addFormCancelButton("cancel", buttonContainer, ureq, getWindowControl());
}
use of org.olat.core.commons.services.license.ui.LicenseSelectionConfig in project OpenOLAT by OpenOLAT.
the class RightsMetadataEditController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
String authorListPage = velocity_root + "/author_list.html";
authorCont = FormLayoutContainer.createCustomFormLayout("owners", getTranslator(), authorListPage);
authorCont.setLabel("rights.owners", null);
formLayout.add(authorCont);
authorCont.setRootForm(mainForm);
reloadAuthors();
VelocityContainer vc = authorCont.getFormItemComponent();
managerOwners = LinkFactory.createButton("manage.owners", vc, this);
authorCont.put("manage.owners", managerOwners);
if (licenseModule.isEnabled(licenseHandler)) {
license = licenseService.loadOrCreateLicense(item);
LicenseSelectionConfig licenseSelectionConfig = LicenseUIFactory.createLicenseSelectionConfig(licenseHandler, license.getLicenseType());
licenseEl = uifactory.addDropdownSingleselect("rights.license", formLayout, licenseSelectionConfig.getLicenseTypeKeys(), licenseSelectionConfig.getLicenseTypeValues(getLocale()));
licenseEl.setElementCssClass("o_sel_repo_license");
licenseEl.setMandatory(licenseSelectionConfig.isLicenseMandatory());
if (licenseSelectionConfig.getSelectionLicenseTypeKey() != null) {
licenseEl.select(licenseSelectionConfig.getSelectionLicenseTypeKey(), true);
}
licenseEl.addActionListener(FormEvent.ONCHANGE);
licensorEl = uifactory.addTextElement("rights.licensor", 1000, license.getLicensor(), formLayout);
String freetext = licenseService.isFreetext(license.getLicenseType()) ? license.getFreetext() : "";
licenseFreetextEl = uifactory.addTextAreaElement("rights.freetext", 4, 72, freetext, formLayout);
LicenseUIFactory.updateVisibility(licenseEl, licensorEl, licenseFreetextEl);
licenseTextEl = uifactory.addStaticTextElement("rights.licenseText", "", "", formLayout);
updateLicenseText();
buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
buttonsCont.setRootForm(mainForm);
formLayout.add(buttonsCont);
okButton = uifactory.addFormSubmitButton("ok", "ok", buttonsCont);
uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
}
}
use of org.olat.core.commons.services.license.ui.LicenseSelectionConfig in project OpenOLAT by OpenOLAT.
the class RepositoryEditDescriptionController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
setFormContextHelp("Info Page: Add Meta Data");
formLayout.setElementCssClass("o_sel_edit_repositoryentry");
String id = repositoryEntry.getResourceableId() == null ? "-" : repositoryEntry.getResourceableId().toString();
uifactory.addStaticTextElement("cif.id", id, formLayout);
String externalId = repositoryEntry.getExternalId();
if (StringHelper.containsNonWhitespace(externalId)) {
uifactory.addStaticTextElement("cif.externalid", externalId, formLayout);
}
String extRef = repositoryEntry.getExternalRef();
if (StringHelper.containsNonWhitespace(repositoryEntry.getManagedFlagsString())) {
if (StringHelper.containsNonWhitespace(extRef)) {
uifactory.addStaticTextElement("cif.externalref", extRef, formLayout);
}
} else {
externalRef = uifactory.addTextElement("cif.externalref", "cif.externalref", 100, extRef, formLayout);
externalRef.setHelpText(translate("cif.externalref.hover"));
externalRef.setHelpUrlForManualPage("Info Page#_identification");
externalRef.setDisplaySize(30);
}
String initalAuthor = repositoryEntry.getInitialAuthor() == null ? "-" : repositoryEntry.getInitialAuthor();
if (repositoryEntry.getInitialAuthor() != null) {
initalAuthor = userManager.getUserDisplayName(initalAuthor);
}
initalAuthor = StringHelper.escapeHtml(initalAuthor);
uifactory.addStaticTextElement("cif.initialAuthor", initalAuthor, formLayout);
// Add resource type
String typeName = null;
OLATResource res = repositoryEntry.getOlatResource();
if (res != null) {
typeName = res.getResourceableTypeName();
}
String typeDisplay;
if (typeName != null) {
// add image and typename code
typeDisplay = NewControllerFactory.translateResourceableTypeName(typeName, getLocale());
} else {
typeDisplay = translate("cif.type.na");
}
uifactory.addStaticTextElement("cif.type", typeDisplay, formLayout);
uifactory.addSpacerElement("spacer1", formLayout, false);
displayName = uifactory.addTextElement("cif.displayname", "cif.displayname", 100, repositoryEntry.getDisplayname(), formLayout);
displayName.setDisplaySize(30);
displayName.setMandatory(true);
displayName.setEnabled(!RepositoryEntryManagedFlag.isManaged(repositoryEntry, RepositoryEntryManagedFlag.title));
authors = uifactory.addTextElement("cif.authors", "cif.authors", 255, repositoryEntry.getAuthors(), formLayout);
authors.setDisplaySize(60);
if (licenseModule.isEnabled(licenseHandler)) {
license = licenseService.loadOrCreateLicense(res);
LicenseSelectionConfig licenseSelectionConfig = LicenseUIFactory.createLicenseSelectionConfig(licenseHandler, license.getLicenseType());
licenseEl = uifactory.addDropdownSingleselect("cif.license", formLayout, licenseSelectionConfig.getLicenseTypeKeys(), licenseSelectionConfig.getLicenseTypeValues(getLocale()));
licenseEl.setElementCssClass("o_sel_repo_license");
licenseEl.setMandatory(licenseSelectionConfig.isLicenseMandatory());
if (licenseSelectionConfig.getSelectionLicenseTypeKey() != null) {
licenseEl.select(licenseSelectionConfig.getSelectionLicenseTypeKey(), true);
}
licenseEl.addActionListener(FormEvent.ONCHANGE);
licensorEl = uifactory.addTextElement("cif.licensor", 1000, license.getLicensor(), formLayout);
String freetext = licenseService.isFreetext(license.getLicenseType()) ? license.getFreetext() : "";
licenseFreetextEl = uifactory.addTextAreaElement("cif.freetext", 4, 72, freetext, formLayout);
LicenseUIFactory.updateVisibility(licenseEl, licensorEl, licenseFreetextEl);
}
language = uifactory.addTextElement("cif.mainLanguage", "cif.mainLanguage", 16, repositoryEntry.getMainLanguage(), formLayout);
location = uifactory.addTextElement("cif.location", "cif.location", 255, repositoryEntry.getLocation(), formLayout);
location.setEnabled(!RepositoryEntryManagedFlag.isManaged(repositoryEntry, RepositoryEntryManagedFlag.location));
RepositoryHandler handler = repositoryHandlerFactory.getRepositoryHandler(repositoryEntry);
mediaContainer = handler.getMediaContainer(repositoryEntry);
if (mediaContainer != null && mediaContainer.getName().equals("media")) {
mediaContainer = mediaContainer.getParentContainer();
mediaContainer.setDefaultItemFilter(new MediaContainerFilter(mediaContainer));
}
String desc = (repositoryEntry.getDescription() != null ? repositoryEntry.getDescription() : " ");
description = uifactory.addRichTextElementForStringData("cif.description", "cif.description", desc, 10, -1, false, mediaContainer, null, formLayout, ureq.getUserSession(), getWindowControl());
description.setEnabled(!RepositoryEntryManagedFlag.isManaged(repositoryEntry, RepositoryEntryManagedFlag.description));
description.getEditorConfiguration().setFileBrowserUploadRelPath("media");
uifactory.addSpacerElement("spacer2", formLayout, false);
if (CourseModule.getCourseTypeName().equals(repoEntryType)) {
String[] dateValues = new String[] { translate("cif.dates.none"), translate("cif.dates.private"), translate("cif.dates.public") };
dateTypesEl = uifactory.addRadiosVertical("cif.dates", formLayout, dateKeys, dateValues);
dateTypesEl.setElementCssClass("o_sel_repo_lifecycle_type");
if (repositoryEntry.getLifecycle() == null) {
dateTypesEl.select("none", true);
} else if (repositoryEntry.getLifecycle().isPrivateCycle()) {
dateTypesEl.select("private", true);
} else {
dateTypesEl.select("public", true);
}
dateTypesEl.addActionListener(FormEvent.ONCHANGE);
List<RepositoryEntryLifecycle> cycles = lifecycleDao.loadPublicLifecycle();
List<RepositoryEntryLifecycle> filteredCycles = new ArrayList<>();
// just make the upcomming and acutual running cycles or the pre-selected visible in the UI
LocalDateTime now = LocalDateTime.now();
for (RepositoryEntryLifecycle cycle : cycles) {
if (cycle.getValidTo() == null || now.isBefore(LocalDateTime.ofInstant(cycle.getValidTo().toInstant(), ZoneId.systemDefault())) || (repositoryEntry.getLifecycle() != null && repositoryEntry.getLifecycle().equals(cycle))) {
filteredCycles.add(cycle);
}
}
String[] publicKeys = new String[filteredCycles.size()];
String[] publicValues = new String[filteredCycles.size()];
int count = 0;
for (RepositoryEntryLifecycle cycle : filteredCycles) {
publicKeys[count] = cycle.getKey().toString();
StringBuilder sb = new StringBuilder(32);
boolean labelAvailable = StringHelper.containsNonWhitespace(cycle.getLabel());
if (labelAvailable) {
sb.append(cycle.getLabel());
}
if (StringHelper.containsNonWhitespace(cycle.getSoftKey())) {
if (labelAvailable)
sb.append(" - ");
sb.append(cycle.getSoftKey());
}
publicValues[count++] = sb.toString();
}
publicDatesEl = uifactory.addDropdownSingleselect("cif.public.dates", formLayout, publicKeys, publicValues, null);
String privateDatePage = velocity_root + "/cycle_dates.html";
privateDatesCont = FormLayoutContainer.createCustomFormLayout("private.date", getTranslator(), privateDatePage);
privateDatesCont.setRootForm(mainForm);
privateDatesCont.setLabel("cif.private.dates", null);
formLayout.add("private.date", privateDatesCont);
startDateEl = uifactory.addDateChooser("date.start", "cif.date.start", null, privateDatesCont);
startDateEl.setElementCssClass("o_sel_repo_lifecycle_validfrom");
endDateEl = uifactory.addDateChooser("date.end", "cif.date.end", null, privateDatesCont);
endDateEl.setElementCssClass("o_sel_repo_lifecycle_validto");
if (repositoryEntry.getLifecycle() != null) {
RepositoryEntryLifecycle lifecycle = repositoryEntry.getLifecycle();
if (lifecycle.isPrivateCycle()) {
startDateEl.setDate(lifecycle.getValidFrom());
endDateEl.setDate(lifecycle.getValidTo());
} else {
String key = lifecycle.getKey().toString();
for (String publicKey : publicKeys) {
if (key.equals(publicKey)) {
publicDatesEl.select(key, true);
break;
}
}
}
}
updateDatesVisibility();
uifactory.addSpacerElement("spacer3", formLayout, false);
expenditureOfWork = uifactory.addTextElement("cif.expenditureOfWork", "cif.expenditureOfWork", 100, repositoryEntry.getExpenditureOfWork(), formLayout);
expenditureOfWork.setExampleKey("details.expenditureOfWork.example", null);
String obj = (repositoryEntry.getObjectives() != null ? repositoryEntry.getObjectives() : " ");
objectives = uifactory.addRichTextElementForStringData("cif.objectives", "cif.objectives", obj, 10, -1, false, mediaContainer, null, formLayout, ureq.getUserSession(), getWindowControl());
objectives.setEnabled(!RepositoryEntryManagedFlag.isManaged(repositoryEntry, RepositoryEntryManagedFlag.objectives));
objectives.getEditorConfiguration().setFileBrowserUploadRelPath("media");
String req = (repositoryEntry.getRequirements() != null ? repositoryEntry.getRequirements() : " ");
requirements = uifactory.addRichTextElementForStringData("cif.requirements", "cif.requirements", req, 10, -1, false, mediaContainer, null, formLayout, ureq.getUserSession(), getWindowControl());
requirements.setEnabled(!RepositoryEntryManagedFlag.isManaged(repositoryEntry, RepositoryEntryManagedFlag.requirements));
requirements.getEditorConfiguration().setFileBrowserUploadRelPath("media");
requirements.setMaxLength(2000);
String cred = (repositoryEntry.getCredits() != null ? repositoryEntry.getCredits() : " ");
credits = uifactory.addRichTextElementForStringData("cif.credits", "cif.credits", cred, 10, -1, false, mediaContainer, null, formLayout, ureq.getUserSession(), getWindowControl());
credits.setEnabled(!RepositoryEntryManagedFlag.isManaged(repositoryEntry, RepositoryEntryManagedFlag.credits));
credits.getEditorConfiguration().setFileBrowserUploadRelPath("media");
credits.setMaxLength(2000);
uifactory.addSpacerElement("spacer4", formLayout, false);
}
boolean managed = RepositoryEntryManagedFlag.isManaged(repositoryEntry, RepositoryEntryManagedFlag.details);
VFSLeaf img = repositoryManager.getImage(repositoryEntry);
fileUpload = uifactory.addFileElement(getWindowControl(), "rentry.pic", "rentry.pic", formLayout);
fileUpload.setExampleKey("rentry.pic.example", new String[] { RepositoryManager.PICTURE_WIDTH + "x" + (RepositoryManager.PICTURE_HEIGHT) });
fileUpload.setMaxUploadSizeKB(picUploadlimitKB, null, null);
fileUpload.setPreview(ureq.getUserSession(), true);
fileUpload.addActionListener(FormEvent.ONCHANGE);
fileUpload.setDeleteEnabled(!managed);
if (img instanceof LocalFileImpl) {
fileUpload.setPreview(ureq.getUserSession(), true);
fileUpload.setInitialFile(((LocalFileImpl) img).getBasefile());
}
fileUpload.setVisible(!managed);
fileUpload.limitToMimeType(imageMimeTypes, "cif.error.mimetype", new String[] { imageMimeTypes.toString() });
VFSLeaf movie = repositoryService.getIntroductionMovie(repositoryEntry);
movieUpload = uifactory.addFileElement(getWindowControl(), "rentry.movie", "rentry.movie", formLayout);
movieUpload.setExampleKey("rentry.movie.example", new String[] { "3:2" });
movieUpload.setMaxUploadSizeKB(movieUploadlimitKB, null, null);
movieUpload.setPreview(ureq.getUserSession(), true);
movieUpload.addActionListener(FormEvent.ONCHANGE);
movieUpload.setDeleteEnabled(!managed);
if (movie instanceof LocalFileImpl) {
movieUpload.setPreview(ureq.getUserSession(), true);
movieUpload.setInitialFile(((LocalFileImpl) movie).getBasefile());
}
movieUpload.setVisible(!managed);
FormLayoutContainer buttonContainer = FormLayoutContainer.createButtonLayout("buttonContainer", getTranslator());
formLayout.add("buttonContainer", buttonContainer);
buttonContainer.setElementCssClass("o_sel_repo_save_details");
submit = uifactory.addFormSubmitButton("submit", buttonContainer);
submit.setVisible(!managed);
uifactory.addFormCancelButton("cancel", buttonContainer, ureq, getWindowControl());
}
Aggregations