@luomus/laji-form 15.1.9 → 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/dist/styles.css CHANGED
@@ -2420,7 +2420,7 @@ min-height: 20px;
2420
2420
  height: 120px;
2421
2421
  float: left;
2422
2422
  }
2423
- .laji-form .laji-form-medias a > img, .laji-form .audios-container a {
2423
+ .laji-form .laji-form-medias .media-container-link > img, .laji-form .audios-container .media-container-link {
2424
2424
  cursor: pointer;
2425
2425
  }
2426
2426
  .laji-form .laji-form-medias img, .laji-form .media-loading {
@@ -2463,10 +2463,6 @@ min-height: 20px;
2463
2463
  background-color: #d8fbc6;
2464
2464
  border-color: #a7d490;
2465
2465
  }
2466
- .laji-form .laji-form-medias a:hover, .laji-form .laji-form-medias a:active {
2467
- text-decoration: none;
2468
- color: #337ab7;
2469
- }
2470
2466
  .laji-form .laji-form-drop-zone:hover:not(.disabled) span, .laji-form .laji-form-drop-zone.dragging:not(.disabled) span {
2471
2467
  color: #a7d490;
2472
2468
  }
@@ -2474,13 +2470,16 @@ min-height: 20px;
2474
2470
  cursor: not-allowed;
2475
2471
  }
2476
2472
 
2477
- .laji-form .laji-form-medias a {
2473
+ .laji-form .laji-form-medias .media-container-link, .laji-form .laji-form-medias .media-container-link a {
2478
2474
  text-align: center;
2479
2475
  vertical-align: middle;
2480
2476
  width: 100%;
2481
2477
  height: 100%;
2482
2478
  }
2483
- .laji-form .laji-form-medias .media-container > a > div > .glyphicon, .laji-form .laji-form-medias .laji-form-drop-zone .glyphicon {
2479
+ .laji-form .laji-form-medias .media-container-link a:focus {
2480
+ outline: none;
2481
+ }
2482
+ .laji-form .laji-form-medias .media-container > .media-container-link > div > .glyphicon, .laji-form .laji-form-medias .laji-form-drop-zone .glyphicon {
2484
2483
  font-size: 78px;
2485
2484
  color: #dedede;
2486
2485
  display: table-cell;
@@ -2494,12 +2493,12 @@ min-height: 20px;
2494
2493
  padding-left: 12px;
2495
2494
  padding-top: 19px;
2496
2495
  }
2497
- .laji-form .audios-container .media-container > a > div > .glyphicon {
2496
+ .laji-form .audios-container .media-container > .media-container-link > div > .glyphicon {
2498
2497
  padding-left: 2px;
2499
2498
  padding-top: 0px;
2500
2499
  color: #868686;
2501
2500
  }
2502
- .laji-form .audios-container .media-container > a > div > .glyphicon-pause {
2501
+ .laji-form .audios-container .media-container > .media-container-link > div > .glyphicon-pause {
2503
2502
  padding-left: 6px;
2504
2503
  }
2505
2504
  .laji-form .audio-container {
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])
@@ -156,9 +156,11 @@ interface ThumbnailProps {
156
156
  apiEndpoint?: string;
157
157
  dataURL?: string;
158
158
  loading?: boolean;
159
+ downloadLink?: boolean;
159
160
  }
160
161
  interface ThumbnailState {
161
162
  url?: string;
163
+ linkUrl?: string;
162
164
  }
163
165
  export declare class Thumbnail extends React.PureComponent<ThumbnailProps, ThumbnailState> {
164
166
  mounted: boolean;
@@ -108,7 +108,7 @@ function MediaArrayField(ComposedComponent) {
108
108
  const { disabled, readonly } = this.props;
109
109
  const { deleteConfirmPlacement = "top" } = utils_1.getUiOptions(this.props.uiSchema);
110
110
  return (this.props.formData || []).map((item, i) => (React.createElement("div", { key: i, className: "media-container" },
111
- React.createElement("a", { onClick: this.onMediaClick(i) }, this.renderMedia(item, i)),
111
+ React.createElement("div", { className: "media-container-link", onClick: this.onMediaClick(i) }, this.renderMedia(item, i)),
112
112
  React.createElement(components_1.DeleteButton, { corner: true, confirm: true, confirmPlacement: deleteConfirmPlacement, translations: this.props.formContext.translations, onClick: this.onMediaRmClick(i), disabled: disabled || readonly, id: `${this.props.idSchema.$id}_${i}` }))));
113
113
  };
114
114
  this.renderLoadingMedias = () => {
@@ -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) => () => {
@@ -671,7 +671,7 @@ class Thumbnail extends React.PureComponent {
671
671
  apiClient.fetchCached(`/${apiEndpoint}/${id}`, undefined, { failSilently: true }).then((response) => {
672
672
  if (!this.mounted)
673
673
  return;
674
- this.setState({ url: response.squareThumbnailURL });
674
+ this.setState({ url: response.squareThumbnailURL, linkUrl: response.originalURL });
675
675
  });
676
676
  };
677
677
  this.state = {};
@@ -688,7 +688,10 @@ class Thumbnail extends React.PureComponent {
688
688
  }
689
689
  render() {
690
690
  const url = this.state.url || this.props.dataURL;
691
- const img = url ? React.createElement("img", { src: url }) : null;
691
+ const linkUrl = this.state.linkUrl;
692
+ const addLink = this.props.downloadLink && linkUrl;
693
+ let img = url ? React.createElement("img", { src: url }) : null;
694
+ img = addLink ? React.createElement("a", { href: linkUrl, target: "_blank", rel: "noopener noreferrer", download: true }, img) : img;
692
695
  return (!url || this.props.loading)
693
696
  ? React.createElement("div", { className: "media-loading" },
694
697
  img,
@@ -14,8 +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;
18
- onMediaClick: (i: number) => any;
19
- renderModalMedia: () => JSX.Element;
17
+ renderLoadingMedia: () => JSX.Element;
18
+ onMediaClick: () => null;
20
19
  formatValue(value: string[], options: any, props: FieldProps): string | null;
21
20
  }
@@ -21,11 +21,10 @@ let PdfArrayField = class PdfArrayField extends React.Component {
21
21
  this.TRANSLATION_SELECT_FILE = "";
22
22
  this.TRANSLATION_NO_MEDIA = "";
23
23
  this.CONTAINER_CLASS = "pdf-container";
24
- this.METADATA_FORM_ID = "MHL.1070";
25
- this.renderMedia = (id) => React.createElement(ImageArrayField_1.Thumbnail, { id: id, apiClient: this.props.formContext.apiClient, apiEndpoint: this.ENDPOINT });
26
- this.renderLoadingMedia = (id) => React.createElement(ImageArrayField_1.Thumbnail, { dataURL: id, loading: true, apiClient: this.props.formContext.apiClient, apiEndpoint: this.ENDPOINT });
27
- this.onMediaClick = (i) => this.openModalFor(i);
28
- this.renderModalMedia = () => React.createElement("img", { src: this.state.modalMediaSrc });
24
+ this.METADATA_FORM_ID = "";
25
+ this.renderMedia = (id) => React.createElement(ImageArrayField_1.Thumbnail, { id: id, 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
+ this.onMediaClick = () => null;
29
28
  }
30
29
  formatValue(value, options, props) {
31
30
  const { translations } = props.formContext;
@@ -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.9",
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"),