user-profile-commons.ftl 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <#macro userProfileFormFields>
  2. <#assign currentGroup="">
  3. <#list profile.attributes as attribute>
  4. <#assign groupName = attribute.group!"">
  5. <#if groupName != currentGroup>
  6. <#assign currentGroup=groupName>
  7. <#if currentGroup != "" >
  8. <div class="${properties.kcFormGroupClass!}">
  9. <#assign groupDisplayHeader=attribute.groupDisplayHeader!"">
  10. <#if groupDisplayHeader != "">
  11. <#assign groupHeaderText=advancedMsg(attribute.groupDisplayHeader)!groupName>
  12. <#else>
  13. <#assign groupHeaderText=groupName>
  14. </#if>
  15. <div class="${properties.kcContentWrapperClass!}">
  16. <label id="header-${groupName}" class="${kcFormGroupHeader!}">${groupHeaderText}</label>
  17. </div>
  18. <#assign groupDisplayDescription=attribute.groupDisplayDescription!"">
  19. <#if groupDisplayDescription != "">
  20. <#assign groupDescriptionText=advancedMsg(attribute.groupDisplayDescription)!"">
  21. <div class="${properties.kcLabelWrapperClass!}">
  22. <label id="description-${groupName}" class="${properties.kcLabelClass!}">${groupDescriptionText}</label>
  23. </div>
  24. </#if>
  25. </div>
  26. </#if>
  27. </#if>
  28. <#nested "beforeField" attribute>
  29. <div class="${properties.kcFormGroupClass!}">
  30. <div class="${properties.kcLabelWrapperClass!}">
  31. <label for="${attribute.name}" class="${properties.kcLabelClass!}">${advancedMsg(attribute.displayName!'')}</label>
  32. <#if attribute.required>*</#if>
  33. </div>
  34. <div class="${properties.kcInputWrapperClass!}">
  35. <#if attribute.annotations.inputHelperTextBefore??>
  36. <div class="${properties.kcInputHelperTextBeforeClass!}" id="form-help-text-before-${attribute.name}" aria-live="polite">${kcSanitize(advancedMsg(attribute.annotations.inputHelperTextBefore))?no_esc}</div>
  37. </#if>
  38. <@inputFieldByType attribute=attribute/>
  39. <#if messagesPerField.existsError('${attribute.name}')>
  40. <span id="input-error-${attribute.name}" class="${properties.kcInputErrorMessageClass!}" aria-live="polite">
  41. ${kcSanitize(messagesPerField.get('${attribute.name}'))?no_esc}
  42. </span>
  43. </#if>
  44. <#if attribute.annotations.inputHelperTextAfter??>
  45. <div class="${properties.kcInputHelperTextAfterClass!}" id="form-help-text-after-${attribute.name}" aria-live="polite">${kcSanitize(advancedMsg(attribute.annotations.inputHelperTextAfter))?no_esc}</div>
  46. </#if>
  47. </div>
  48. </div>
  49. <#nested "afterField" attribute>
  50. </#list>
  51. </#macro>
  52. <#macro inputFieldByType attribute>
  53. <#switch attribute.annotations.inputType!''>
  54. <#case 'textarea'>
  55. <@textareaTag attribute=attribute/>
  56. <#break>
  57. <#case 'select'>
  58. <#case 'multiselect'>
  59. <@selectTag attribute=attribute/>
  60. <#break>
  61. <#case 'select-radiobuttons'>
  62. <#case 'multiselect-checkboxes'>
  63. <@inputTagSelects attribute=attribute/>
  64. <#break>
  65. <#default>
  66. <@inputTag attribute=attribute/>
  67. </#switch>
  68. </#macro>
  69. <#macro inputTag attribute>
  70. <input type="<@inputTagType attribute=attribute/>" id="${attribute.name}" name="${attribute.name}" value="${(attribute.value!'')}" class="${properties.kcInputClass!}"
  71. aria-invalid="<#if messagesPerField.existsError('${attribute.name}')>true</#if>"
  72. <#if attribute.readOnly>disabled</#if>
  73. <#if attribute.autocomplete??>autocomplete="${attribute.autocomplete}"</#if>
  74. <#if attribute.annotations.inputTypePlaceholder??>placeholder="${attribute.annotations.inputTypePlaceholder}"</#if>
  75. <#if attribute.annotations.inputTypePattern??>pattern="${attribute.annotations.inputTypePattern}"</#if>
  76. <#if attribute.annotations.inputTypeSize??>size="${attribute.annotations.inputTypeSize}"</#if>
  77. <#if attribute.annotations.inputTypeMaxlength??>maxlength="${attribute.annotations.inputTypeMaxlength}"</#if>
  78. <#if attribute.annotations.inputTypeMinlength??>minlength="${attribute.annotations.inputTypeMinlength}"</#if>
  79. <#if attribute.annotations.inputTypeMax??>max="${attribute.annotations.inputTypeMax}"</#if>
  80. <#if attribute.annotations.inputTypeMin??>min="${attribute.annotations.inputTypeMin}"</#if>
  81. <#if attribute.annotations.inputTypeStep??>step="${attribute.annotations.inputTypeStep}"</#if>
  82. />
  83. </#macro>
  84. <#macro inputTagType attribute>
  85. <#compress>
  86. <#if attribute.annotations.inputType??>
  87. <#if attribute.annotations.inputType?starts_with("html5-")>
  88. ${attribute.annotations.inputType[6..]}
  89. <#else>
  90. ${attribute.annotations.inputType}
  91. </#if>
  92. <#else>
  93. text
  94. </#if>
  95. </#compress>
  96. </#macro>
  97. <#macro textareaTag attribute>
  98. <textarea id="${attribute.name}" name="${attribute.name}" class="${properties.kcInputClass!}"
  99. aria-invalid="<#if messagesPerField.existsError('${attribute.name}')>true</#if>"
  100. <#if attribute.readOnly>disabled</#if>
  101. <#if attribute.annotations.inputTypeCols??>cols="${attribute.annotations.inputTypeCols}"</#if>
  102. <#if attribute.annotations.inputTypeRows??>rows="${attribute.annotations.inputTypeRows}"</#if>
  103. <#if attribute.annotations.inputTypeMaxlength??>maxlength="${attribute.annotations.inputTypeMaxlength}"</#if>
  104. >${(attribute.value!'')}</textarea>
  105. </#macro>
  106. <#macro selectTag attribute>
  107. <select id="${attribute.name}" name="${attribute.name}" class="${properties.kcInputClass!}"
  108. aria-invalid="<#if messagesPerField.existsError('${attribute.name}')>true</#if>"
  109. <#if attribute.readOnly>disabled</#if>
  110. <#if attribute.annotations.inputType=='multiselect'>multiple</#if>
  111. <#if attribute.annotations.inputTypeSize??>size="${attribute.annotations.inputTypeSize}"</#if>
  112. >
  113. <#if attribute.annotations.inputType=='select'>
  114. <option value=""></option>
  115. </#if>
  116. <#if attribute.annotations.inputOptionsFromValidation?? && attribute.validators[attribute.annotations.inputOptionsFromValidation]?? && attribute.validators[attribute.annotations.inputOptionsFromValidation].options??>
  117. <#assign options=attribute.validators[attribute.annotations.inputOptionsFromValidation].options>
  118. <#elseif attribute.validators.options?? && attribute.validators.options.options??>
  119. <#assign options=attribute.validators.options.options>
  120. </#if>
  121. <#if options??>
  122. <#list options as option>
  123. <option value="${option}" <#if attribute.values?seq_contains(option)>selected</#if>><@selectOptionLabelText attribute=attribute option=option/></option>
  124. </#list>
  125. </#if>
  126. </select>
  127. </#macro>
  128. <#macro inputTagSelects attribute>
  129. <#if attribute.annotations.inputType=='select-radiobuttons'>
  130. <#assign inputType='radio'>
  131. <#assign classDiv=properties.kcInputClassRadio!>
  132. <#assign classInput=properties.kcInputClassRadioInput!>
  133. <#assign classLabel=properties.kcInputClassRadioLabel!>
  134. <#else>
  135. <#assign inputType='checkbox'>
  136. <#assign classDiv=properties.kcInputClassCheckbox!>
  137. <#assign classInput=properties.kcInputClassCheckboxInput!>
  138. <#assign classLabel=properties.kcInputClassCheckboxLabel!>
  139. </#if>
  140. <#if attribute.annotations.inputOptionsFromValidation?? && attribute.validators[attribute.annotations.inputOptionsFromValidation]?? && attribute.validators[attribute.annotations.inputOptionsFromValidation].options??>
  141. <#assign options=attribute.validators[attribute.annotations.inputOptionsFromValidation].options>
  142. <#elseif attribute.validators.options?? && attribute.validators.options.options??>
  143. <#assign options=attribute.validators.options.options>
  144. </#if>
  145. <#if options??>
  146. <#list options as option>
  147. <div class="${classDiv}">
  148. <input type="${inputType}" id="${attribute.name}-${option}" name="${attribute.name}" value="${option}" class="${classInput}"
  149. aria-invalid="<#if messagesPerField.existsError('${attribute.name}')>true</#if>"
  150. <#if attribute.readOnly>disabled</#if>
  151. <#if attribute.values?seq_contains(option)>checked</#if>
  152. />
  153. <label for="${attribute.name}-${option}" class="${classLabel}<#if attribute.readOnly> ${properties.kcInputClassRadioCheckboxLabelDisabled!}</#if>"><@selectOptionLabelText attribute=attribute option=option/></label>
  154. </div>
  155. </#list>
  156. </#if>
  157. </select>
  158. </#macro>
  159. <#macro selectOptionLabelText attribute option>
  160. <#compress>
  161. <#if attribute.annotations.inputOptionLabels??>
  162. ${advancedMsg(attribute.annotations.inputOptionLabels[option]!option)}
  163. <#else>
  164. <#if attribute.annotations.inputOptionLabelsI18nPrefix??>
  165. ${msg(attribute.annotations.inputOptionLabelsI18nPrefix + '.' + option)}
  166. <#else>
  167. ${option}
  168. </#if>
  169. </#if>
  170. </#compress>
  171. </#macro>