Skip to content

Commit

Permalink
Support processing attachments (#519)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjaros committed Mar 17, 2024
1 parent c1ac2fa commit 4291d5a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ import io.kvision.panel.SimplePanel
* @param name the name attribute of the generated HTML input element
* @param label label text bound to the input element
* @param rich determines if [label] can contain HTML code
* @param allowFileUploads determines if file uploads are allowed (default false)
* @param init an initializer extension function
*/
open class RichText(
value: String? = null, name: String? = null,
label: String? = null, rich: Boolean = false,
allowFileUploads: Boolean = false,
init: (RichText.() -> Unit)? = null
) : AbstractText(label, rich) {

Expand All @@ -50,7 +52,7 @@ open class RichText(
input.height = value
}

final override val input: RichTextInput = RichTextInput(value).apply {
final override val input: RichTextInput = RichTextInput(value, allowFileUploads).apply {
this.id = this@RichText.idc
this.name = name
}
Expand Down Expand Up @@ -90,9 +92,10 @@ fun Container.richText(
name: String? = null,
label: String? = null,
rich: Boolean = false,
allowFileUploads: Boolean = false,
init: (RichText.() -> Unit)? = null
): RichText {
val richText = RichText(value, name, label, rich, init)
val richText = RichText(value, name, label, rich, allowFileUploads, init)
this.add(richText)
return richText
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ import org.w3c.dom.Element
*
* @constructor
* @param value text input value
* @param allowFileUploads determines if file uploads are allowed (default false)
* @param className CSS class names
* @param init an initializer extension function
*/
open class RichTextInput(
value: String? = null,
protected val allowFileUploads: Boolean = false,
className: String? = null,
init: (RichTextInput.() -> Unit)? = null
) : AbstractTextInput(value, null, (className?.let { "$it " } ?: "") + "form-control trix-control") {
Expand Down Expand Up @@ -107,7 +109,7 @@ open class RichTextInput(
}
}
})
this.getElement()?.addEventListener("trix-file-accept", { e -> e.preventDefault() })
if (!allowFileUploads) this.getElement()?.addEventListener("trix-file-accept", { e -> e.preventDefault() })
}

override fun afterDestroy() {
Expand Down Expand Up @@ -149,10 +151,11 @@ open class RichTextInput(
*/
fun Container.richTextInput(
value: String? = null,
allowFileUploads: Boolean = false,
className: String? = null,
init: (RichTextInput.() -> Unit)? = null
): RichTextInput {
val richTextInput = RichTextInput(value, className, init)
val richTextInput = RichTextInput(value, allowFileUploads, className, init)
this.add(richTextInput)
return richTextInput
}

0 comments on commit 4291d5a

Please sign in to comment.