@luomus/laji-form 15.1.10 → 15.1.11

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/lib/ApiClient.js CHANGED
@@ -47,6 +47,9 @@ class ApiClient {
47
47
  if (!failSilently && response.status >= 400) {
48
48
  throw new Error("Request failed");
49
49
  }
50
+ if (response.status === 204) {
51
+ return undefined;
52
+ }
50
53
  return response.json();
51
54
  }).catch(() => {
52
55
  if (this.cache[path])
@@ -118,7 +118,7 @@ function MediaArrayField(ComposedComponent) {
118
118
  if (!medias || !medias[item])
119
119
  return null;
120
120
  return (React.createElement("div", { key: i, className: "media-container" },
121
- React.createElement("a", null, this.renderLoadingMedia(medias[item]))));
121
+ React.createElement("div", { className: "media-container-link" }, this.renderLoadingMedia(medias[item]))));
122
122
  });
123
123
  };
124
124
  this.openModalFor = (i) => () => {
@@ -14,7 +14,7 @@ export default class PdfArrayField extends React.Component<FieldProps, MediaArra
14
14
  CONTAINER_CLASS: string;
15
15
  METADATA_FORM_ID: string;
16
16
  renderMedia: (id: string) => JSX.Element;
17
- renderLoadingMedia: (id: string) => JSX.Element;
17
+ renderLoadingMedia: () => JSX.Element;
18
18
  onMediaClick: () => null;
19
19
  formatValue(value: string[], options: any, props: FieldProps): string | null;
20
20
  }
@@ -23,7 +23,7 @@ let PdfArrayField = class PdfArrayField extends React.Component {
23
23
  this.CONTAINER_CLASS = "pdf-container";
24
24
  this.METADATA_FORM_ID = "";
25
25
  this.renderMedia = (id) => React.createElement(ImageArrayField_1.Thumbnail, { id: id, apiClient: this.props.formContext.apiClient, apiEndpoint: this.ENDPOINT, downloadLink: true });
26
- this.renderLoadingMedia = (id) => React.createElement(ImageArrayField_1.Thumbnail, { dataURL: id, loading: true, apiClient: this.props.formContext.apiClient, apiEndpoint: this.ENDPOINT, downloadLink: true });
26
+ this.renderLoadingMedia = () => React.createElement(ImageArrayField_1.Thumbnail, { loading: true, apiClient: this.props.formContext.apiClient, apiEndpoint: this.ENDPOINT, downloadLink: true });
27
27
  this.onMediaClick = () => null;
28
28
  }
29
29
  formatValue(value, options, props) {
@@ -56,7 +56,11 @@ export default class DateTimeWidget extends React.Component<any, any, any> {
56
56
  setToday: () => void;
57
57
  setYesterday: () => void;
58
58
  setSameAsToday: () => void;
59
+ setPlusSixMonths: () => void;
60
+ setPlusYear: () => void;
59
61
  formatValue(value: any, options: any, props: any): any;
62
+ getCurrentDateOrNow(): moment.Moment;
60
63
  }
61
64
  import * as React from "react";
65
+ import * as moment from "moment";
62
66
  import * as PropTypes from "prop-types";
@@ -102,6 +102,12 @@ let DateTimeWidget = DateTimeWidget_1 = class DateTimeWidget extends React.Compo
102
102
  this.onChange(today);
103
103
  }
104
104
  };
105
+ this.setPlusSixMonths = () => {
106
+ this.onChange(this.getCurrentDateOrNow().add(6, "M").format("YYYY-MM-DD"));
107
+ };
108
+ this.setPlusYear = () => {
109
+ this.onChange(this.getCurrentDateOrNow().add(1, "y").format("YYYY-MM-DD"));
110
+ };
105
111
  momentLocalizer(moment);
106
112
  }
107
113
  componentDidMount() {
@@ -192,6 +198,16 @@ let DateTimeWidget = DateTimeWidget_1 = class DateTimeWidget extends React.Compo
192
198
  className: "same",
193
199
  label: translations.Same,
194
200
  onClick: this.setSameAsToday
201
+ },
202
+ plusSixMonths: {
203
+ className: "plus-six-months",
204
+ label: translations.plusSixMonths,
205
+ onClick: this.setPlusSixMonths
206
+ },
207
+ plusYear: {
208
+ className: "plus-year",
209
+ label: translations.plusYear,
210
+ onClick: this.setPlusYear
195
211
  }
196
212
  };
197
213
  const options = showButtons === true
@@ -209,6 +225,13 @@ let DateTimeWidget = DateTimeWidget_1 = class DateTimeWidget extends React.Compo
209
225
  const { inputFormat: format } = DateTimeWidget_1.prototype.getStateFromProps(Object.assign(Object.assign({}, props), { date: true, time: true, value }));
210
226
  return localizers_1.date.format(value, format, props.formContext.lang);
211
227
  }
228
+ getCurrentDateOrNow() {
229
+ const date = moment(this.props.value);
230
+ if (date.isValid()) {
231
+ return date;
232
+ }
233
+ return moment();
234
+ }
212
235
  };
213
236
  DateTimeWidget.contextType = ReactContext_1.default;
214
237
  DateTimeWidget.propTypes = {
@@ -19,6 +19,16 @@
19
19
  "en": "Yesterday",
20
20
  "sv": "Igår"
21
21
  },
22
+ "plusSixMonths": {
23
+ "fi": "+6k",
24
+ "en": "+6m",
25
+ "sv": "+6m"
26
+ },
27
+ "plusYear": {
28
+ "fi": "+1v",
29
+ "en": "+1y",
30
+ "sv": "+1å"
31
+ },
22
32
  "dd/mm/yyyy": {
23
33
  "fi": "pp/kk/vvvv",
24
34
  "en": "dd/mm/yyyy",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luomus/laji-form",
3
- "version": "15.1.10",
3
+ "version": "15.1.11",
4
4
  "description": "React module capable of building dynamic forms from Laji form json schemas",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -21,6 +21,8 @@ export interface DateWidgetPO {
21
21
  $same: Locator;
22
22
  $date: Locator;
23
23
  $time: Locator;
24
+ $plusSixMonths: Locator;
25
+ $plusYear: Locator;
24
26
  };
25
27
  calendar: {
26
28
  $today: Locator;
@@ -118,6 +120,8 @@ export declare class Form {
118
120
  $same: Locator;
119
121
  $date: Locator;
120
122
  $time: Locator;
123
+ $plusSixMonths: Locator;
124
+ $plusYear: Locator;
121
125
  };
122
126
  calendar: {
123
127
  $today: Locator;
@@ -223,7 +223,9 @@ class Form {
223
223
  $yesterday: $widget.locator(".yesterday"),
224
224
  $same: $widget.locator(".same"),
225
225
  $date: $widget.locator(".rw-i-calendar"),
226
- $time: $widget.locator(".rw-i-clock-o")
226
+ $time: $widget.locator(".rw-i-clock-o"),
227
+ $plusSixMonths: $widget.locator(".plus-six-months"),
228
+ $plusYear: $widget.locator(".plus-year"),
227
229
  },
228
230
  calendar: {
229
231
  $today: $widget.locator(".rw-calendar-footer button"),