@kaspernj/api-maker 1.0.239 → 1.0.241

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  ]
17
17
  },
18
18
  "name": "@kaspernj/api-maker",
19
- "version": "1.0.239",
19
+ "version": "1.0.241",
20
20
  "type": "module",
21
21
  "description": "",
22
22
  "main": "index.js",
@@ -0,0 +1,74 @@
1
+ import {Input as ApiMakerInput} from "@kaspernj/api-maker/src/inputs/input"
2
+ import {Checkbox} from "components/inputs/checkbox"
3
+
4
+ export default class ApiMakerInputsAttachment extends BaseComponent {
5
+ static propTypes = {
6
+ className: PropTypes.string,
7
+ model: PropTypes.object.isRequired
8
+ }
9
+
10
+ render() {
11
+ const {className, inputProps, model, wrapperOpts, ...restProps} = this.props
12
+
13
+ inputProps.type = "file"
14
+
15
+ return (
16
+ <div className={classNames("api-maker--inputs--attachment", "components--inputs--input", className)} {...restProps}>
17
+ {this.isImage() &&
18
+ <a href={this.getUrl()} target="_blank">
19
+ <img src={this.getUrl()} style={{maxWidth: "200px", maxHeight: "200px"}} />
20
+ </a>
21
+ }
22
+ {this.getUrl() &&
23
+ <div className="input-checkbox" style={{paddingTop: "15px", paddingBottom: "15px"}}>
24
+ <Checkbox inputProps={{id: this.getPurgeInputId(), name: this.getPurgeInputName(), value: 1}} {...restProps} />
25
+ <label className="checkbox-label" htmlFor={this.getPurgeInputId()}>
26
+ {I18n.t("js.shared.delete")}
27
+ </label>
28
+ </div>
29
+ }
30
+ <ApiMakerInput
31
+ defaultValue={null}
32
+ inputProps={inputProps}
33
+ model={model}
34
+ />
35
+ </div>
36
+ )
37
+ }
38
+
39
+ getContentType() {
40
+ const {attribute, model} = digs(this.props, "attribute", "model")
41
+ const attributeName = `${attribute}ContentType`
42
+
43
+ if (!(attributeName in model)) throw new Error(`No such method on ${model.modelClassData().name}: ${attributeName}`)
44
+
45
+ return model[attributeName]()
46
+ }
47
+
48
+ getPurgeInputId() {
49
+ const {inputProps} = digs(this.props, "inputProps")
50
+
51
+ return `${inputProps.id}_purge`
52
+ }
53
+
54
+ getPurgeInputName() {
55
+ const {inputProps} = digs(this.props, "inputProps")
56
+ const match = inputProps.name.match(/^(.+)\[(.+?)\]$/)
57
+ const purgeInputName = `${match[1]}[${match[2]}_purge]`
58
+
59
+ return purgeInputName
60
+ }
61
+
62
+ getUrl() {
63
+ const {attribute, model} = digs(this.props, "attribute", "model")
64
+ const attributeName = `${attribute}Url`
65
+
66
+ if (!(attributeName in model)) throw new Error(`No such method on ${model.modelClassData().name}: ${attributeName}`)
67
+
68
+ return model[attributeName]()
69
+ }
70
+
71
+ isImage() {
72
+ return this.getContentType()?.startsWith("image/")
73
+ }
74
+ }
@@ -165,7 +165,7 @@ export default class ApiMakerInputsMoney extends React.PureComponent {
165
165
  let cents = parseInt(whole * 100, 10)
166
166
  let oldCents = parseInt(inputElement.value, 10)
167
167
 
168
- if (cents) {
168
+ if (typeof cents == "number") {
169
169
  inputElement.value = cents
170
170
  } else {
171
171
  inputElement.value = ''