@dejwcake/craftable 0.1.9 → 2.0.0

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.
Files changed (126) hide show
  1. package/README.md +117 -3
  2. package/dist/buildMatchPatternFn-BV4I8r8j.js +63 -0
  3. package/dist/buildMatchPatternFn-T5KjFTBQ.cjs +1 -0
  4. package/dist/craftable.css +2 -0
  5. package/dist/cs-B5QMxFrl.js +682 -0
  6. package/dist/cs-MAoetkhe.cjs +1 -0
  7. package/dist/de-BlQ2ZKmc.js +526 -0
  8. package/dist/de-BoVLAn6U.cjs +1 -0
  9. package/dist/en-US-BLvEnhs4.js +443 -0
  10. package/dist/en-US-Dz8vkDZ_.cjs +1 -0
  11. package/dist/en-US-X9gX759i.cjs +1 -0
  12. package/dist/es-DBHDeXHI.cjs +1 -0
  13. package/dist/es-YEqfkBY2.js +437 -0
  14. package/dist/fr-B7MHC2AN.js +407 -0
  15. package/dist/fr-DLs3QoNB.cjs +1 -0
  16. package/dist/hu-BKZPI9jH.cjs +1 -0
  17. package/dist/hu-reoJgNxD.js +425 -0
  18. package/dist/index.cjs +1 -0
  19. package/dist/index.mjs +3866 -0
  20. package/dist/isSameWeek-CC6GX_zp.js +40 -0
  21. package/dist/isSameWeek-Mctj6Tdj.cjs +1 -0
  22. package/dist/pl-B5A0Rjp7.js +628 -0
  23. package/dist/pl-BMyrOO-Q.cjs +1 -0
  24. package/dist/sk-B7JF2MoV.cjs +1 -0
  25. package/dist/sk-Btro3W4S.js +602 -0
  26. package/package.json +68 -40
  27. package/scripts/publish-components.js +118 -0
  28. package/scss/_images.scss +1 -1
  29. package/scss/_variables.scss +13 -6
  30. package/scss/app.scss +4 -4
  31. package/scss/overrides/_alerts.scss +0 -2
  32. package/scss/overrides/_badges.scss +1 -17
  33. package/scss/overrides/_buttons.scss +64 -7
  34. package/scss/overrides/_cards.scss +4 -51
  35. package/scss/overrides/_checkboxes.scss +54 -59
  36. package/scss/overrides/_forms.scss +270 -176
  37. package/scss/overrides/_index.scss +18 -18
  38. package/scss/overrides/_keyframes.scss +6 -4
  39. package/scss/overrides/_layout.scss +24 -30
  40. package/scss/overrides/_media-wysiwyg.scss +9 -111
  41. package/scss/overrides/_modal.scss +0 -18
  42. package/scss/overrides/_multiselect.scss +63 -7
  43. package/scss/overrides/_nav.scss +55 -33
  44. package/scss/overrides/_notifications.scss +6 -1
  45. package/scss/overrides/_pagination.scss +3 -3
  46. package/scss/overrides/_sidebar.scss +84 -0
  47. package/scss/overrides/_tables.scss +52 -37
  48. package/scss/overrides/_text.scss +1 -3
  49. package/scss/overrides/_wysiwyg.scss +151 -48
  50. package/scss/styles/_auth.scss +32 -37
  51. package/scss/styles/_custom.scss +44 -1
  52. package/scss/styles/_index.scss +4 -4
  53. package/scss/styles/_legacy.scss +5 -81
  54. package/scss/styles/_others.scss +232 -337
  55. package/scss/vendor/_index.scss +5 -4
  56. package/src/auth/ActivationError.vue +23 -0
  57. package/src/auth/ActivationForm.vue +69 -0
  58. package/src/auth/ForgotPasswordForm.vue +74 -0
  59. package/src/auth/LoginForm.vue +107 -0
  60. package/src/auth/ResetPasswordForm.vue +122 -0
  61. package/src/components/ConfirmModal.vue +65 -0
  62. package/src/components/UserDetailTooltip.vue +88 -0
  63. package/src/components/form/CkeditorEditor.vue +205 -0
  64. package/src/components/form/FormCheckbox.vue +29 -0
  65. package/src/components/form/FormDatePicker.vue +52 -0
  66. package/src/components/form/FormEmail.vue +17 -0
  67. package/src/components/form/FormInput.vue +31 -0
  68. package/src/components/form/FormLocalizedInput.vue +47 -0
  69. package/src/components/form/FormLocalizedWysiwyg.vue +55 -0
  70. package/src/components/form/FormLocalizedWysiwygSimple.vue +55 -0
  71. package/src/components/form/FormMultiSelect.vue +36 -0
  72. package/src/components/form/FormPasswordConfirm.vue +49 -0
  73. package/src/components/form/FormSelect.vue +35 -0
  74. package/src/components/form/FormSubmit.vue +13 -0
  75. package/src/components/form/FormTextarea.vue +31 -0
  76. package/src/components/form/FormWysiwyg.vue +31 -0
  77. package/src/components/form/FormWysiwygSimple.vue +31 -0
  78. package/src/components/form/LocalizationBar.vue +90 -0
  79. package/src/components/form/MediaUpload.vue +317 -0
  80. package/src/components/form/TiptapEditor.vue +238 -0
  81. package/src/components/listing/BulkCheckboxHeader.vue +18 -0
  82. package/src/components/listing/BulkCheckboxRow.vue +21 -0
  83. package/src/components/listing/BulkOperationsBar.vue +41 -0
  84. package/src/components/listing/DeleteButton.vue +46 -0
  85. package/src/components/listing/EditButton.vue +17 -0
  86. package/src/components/listing/EmptyState.vue +25 -0
  87. package/src/components/listing/ListingHeader.vue +24 -0
  88. package/src/components/listing/Pagination.vue +158 -0
  89. package/src/components/listing/PerPage.vue +15 -0
  90. package/src/components/listing/PublishedAtColumn.vue +226 -0
  91. package/src/components/listing/Search.vue +81 -0
  92. package/src/components/listing/Sortable.vue +28 -0
  93. package/src/components/listing/ToggleSwitch.vue +47 -0
  94. package/src/composables/useAdmin.js +39 -0
  95. package/src/composables/useBaseAuth.js +81 -0
  96. package/src/composables/useBaseForm.js +265 -0
  97. package/src/composables/useBaseListing.js +316 -0
  98. package/src/composables/useResponsiveColumns.js +62 -0
  99. package/src/index.js +62 -0
  100. package/src/translation/TranslationListing.vue +230 -0
  101. package/src/translation/modals/TranslationEditModal.vue +86 -0
  102. package/src/translation/modals/TranslationExportModal.vue +74 -0
  103. package/src/translation/modals/TranslationImportModal.vue +255 -0
  104. package/src/ui/index.js +99 -0
  105. package/src/utils/ckeditorHelpers.js +36 -0
  106. package/src/utils/dateFnsLocale.js +24 -0
  107. package/src/utils/dateFormatters.js +30 -0
  108. package/src/utils/mediaProps.js +14 -0
  109. package/src/utils/notify.js +22 -0
  110. package/dist/admin/Admin.js +0 -42
  111. package/dist/auth/Form.js +0 -15
  112. package/dist/base-components/Form/BaseForm.js +0 -392
  113. package/dist/base-components/Form/BaseUpload.js +0 -188
  114. package/dist/base-components/Form/bootstrap.js +0 -21
  115. package/dist/base-components/Listing/BaseListing.js +0 -454
  116. package/dist/base-components/Listing/components/Pagination.js +0 -105
  117. package/dist/base-components/Listing/components/Sortable.js +0 -48
  118. package/dist/base-components/Listing/components/UserDetailTooltip.js +0 -55
  119. package/dist/index.js +0 -70
  120. package/dist/overrides/trumbowyg.edit-embed-template.js +0 -72
  121. package/dist/overrides/trumbowyg.reupload.js +0 -146
  122. package/dist/overrides/trumbowyg.template.js +0 -67
  123. package/dist/translation/Form.js +0 -15
  124. package/dist/translation/Listing.js +0 -283
  125. package/dist/ui/index.js +0 -33
  126. package/scss/overrides/_switches.scss +0 -25
@@ -0,0 +1,99 @@
1
+ export function initUI() {
2
+ if (document.readyState === 'loading') {
3
+ document.addEventListener('DOMContentLoaded', initUIHandlers);
4
+ } else {
5
+ initUIHandlers();
6
+ }
7
+ }
8
+
9
+ function initUIHandlers() {
10
+ const sidebar = document.getElementById('sidebar');
11
+ let backdrop = null;
12
+
13
+ // Spinner buttons
14
+ document.querySelectorAll('.btn-spinner').forEach((btn) => {
15
+ btn.addEventListener('click', (e) => {
16
+ if (!(e.shiftKey || e.ctrlKey || e.metaKey)) {
17
+ btn.style.pointerEvents = 'none';
18
+ const icon = btn.querySelector('i');
19
+ if (icon) {
20
+ icon.className = 'fa-solid fa-spinner fa-spin';
21
+ }
22
+ }
23
+ });
24
+ });
25
+
26
+ // Remove empty nav titles when no children there
27
+ document.querySelectorAll('.nav-title').forEach((title) => {
28
+ const next = title.nextElementSibling;
29
+ if (!next || !next.classList.contains('nav-item')) {
30
+ title.style.display = 'none';
31
+ }
32
+ });
33
+
34
+ // Sidebar: mobile show/hide toggle
35
+ function closeSidebar() {
36
+ if (!sidebar) return;
37
+ sidebar.classList.add('hide');
38
+ if (backdrop) {
39
+ backdrop.remove();
40
+ backdrop = null;
41
+ }
42
+ }
43
+
44
+ document.querySelectorAll('[data-coreui-toggle="sidebar"]').forEach((btn) => {
45
+ btn.addEventListener('click', () => {
46
+ if (!sidebar) return;
47
+ const isHidden = sidebar.classList.contains('hide');
48
+ if (isHidden) {
49
+ sidebar.classList.remove('hide');
50
+ // Create backdrop for mobile
51
+ backdrop = document.createElement('div');
52
+ backdrop.className = 'sidebar-backdrop fade show';
53
+ backdrop.addEventListener('click', closeSidebar);
54
+ document.body.appendChild(backdrop);
55
+ } else {
56
+ closeSidebar();
57
+ }
58
+ });
59
+ });
60
+
61
+ // Sidebar: desktop unfoldable (narrow) toggle
62
+ document.querySelectorAll('[data-coreui-toggle="unfoldable"]').forEach((btn) => {
63
+ btn.addEventListener('click', () => {
64
+ if (!sidebar) return;
65
+ sidebar.classList.toggle('sidebar-narrow-unfoldable');
66
+ });
67
+ });
68
+
69
+ // Dropdowns
70
+ document.querySelectorAll('[data-coreui-toggle="dropdown"]').forEach((toggle) => {
71
+ toggle.addEventListener('click', (e) => {
72
+ e.preventDefault();
73
+ const dropdown = toggle.closest('.dropdown');
74
+ if (!dropdown) return;
75
+ const menu = dropdown.querySelector('.dropdown-menu');
76
+ if (!menu) return;
77
+ const isOpen = menu.classList.contains('show');
78
+
79
+ // Close all other open dropdowns
80
+ document.querySelectorAll('.dropdown-menu.show').forEach((m) => m.classList.remove('show'));
81
+
82
+ if (!isOpen) {
83
+ menu.classList.add('show');
84
+ }
85
+ });
86
+ });
87
+
88
+ // Close dropdowns when clicking outside
89
+ document.addEventListener('click', (e) => {
90
+ if (!e.target.closest('.dropdown')) {
91
+ document.querySelectorAll('.dropdown-menu.show').forEach((m) => m.classList.remove('show'));
92
+ }
93
+ });
94
+
95
+ // On mobile, sidebar starts hidden
96
+ if (sidebar && window.innerWidth < 992) {
97
+ sidebar.classList.add('hide');
98
+ }
99
+ }
@@ -0,0 +1,36 @@
1
+ export function propagateImageWidths(html) {
2
+ if (!html) return html;
3
+ const parser = new DOMParser();
4
+ const doc = parser.parseFromString(html, 'text/html');
5
+ let changed = false;
6
+ doc.querySelectorAll('figure').forEach((figure) => {
7
+ const width = figure.style.width;
8
+ if (!width) return;
9
+ const img = figure.querySelector('img');
10
+ if (img) {
11
+ img.style.width = width;
12
+ img.style.height = 'auto';
13
+ changed = true;
14
+ }
15
+ });
16
+ return changed ? doc.body.innerHTML : html;
17
+ }
18
+
19
+ export function deepMerge(target, source) {
20
+ const result = { ...target };
21
+ for (const key of Object.keys(source)) {
22
+ if (
23
+ source[key] &&
24
+ typeof source[key] === 'object' &&
25
+ !Array.isArray(source[key]) &&
26
+ target[key] &&
27
+ typeof target[key] === 'object' &&
28
+ !Array.isArray(target[key])
29
+ ) {
30
+ result[key] = deepMerge(target[key], source[key]);
31
+ } else {
32
+ result[key] = source[key];
33
+ }
34
+ }
35
+ return result;
36
+ }
@@ -0,0 +1,24 @@
1
+ import { enUS } from 'date-fns/locale/en-US';
2
+
3
+ let resolvedLocale = enUS;
4
+
5
+ export function getDateFnsLocale() {
6
+ return resolvedLocale;
7
+ }
8
+
9
+ export async function initDateFnsLocale() {
10
+ const lang = document.documentElement.lang || 'en';
11
+ const map = {
12
+ sk: () => import('date-fns/locale/sk'),
13
+ cs: () => import('date-fns/locale/cs'),
14
+ en: () => import('date-fns/locale/en-US'),
15
+ de: () => import('date-fns/locale/de'),
16
+ fr: () => import('date-fns/locale/fr'),
17
+ es: () => import('date-fns/locale/es'),
18
+ pl: () => import('date-fns/locale/pl'),
19
+ hu: () => import('date-fns/locale/hu'),
20
+ };
21
+ const loader = map[lang] || map['en'];
22
+ const mod = await loader();
23
+ resolvedLocale = mod.default || mod[Object.keys(mod)[0]];
24
+ }
@@ -0,0 +1,30 @@
1
+ import dayjs from 'dayjs';
2
+ import customParseFormat from 'dayjs/plugin/customParseFormat.js';
3
+ import utc from 'dayjs/plugin/utc.js';
4
+ import timezone from 'dayjs/plugin/timezone.js';
5
+
6
+ dayjs.extend(customParseFormat);
7
+ dayjs.extend(utc);
8
+ dayjs.extend(timezone);
9
+
10
+ export function formatDate(date, format = 'DD.MM.YYYY') {
11
+ const d = dayjs(date);
12
+ return d.isValid() ? d.format(format) : '';
13
+ }
14
+
15
+ export function formatDatetime(datetime, format = 'DD.MM.YYYY HH:mm') {
16
+ const d = dayjs(datetime);
17
+ return d.isValid() ? d.format(format) : '';
18
+ }
19
+
20
+ export function formatTime(time, format = 'HH:mm') {
21
+ // '2000-01-01' is here just because dayjs needs a date
22
+ const d = dayjs('2000-01-01 ' + time);
23
+ return d.isValid() ? d.format(format) : '';
24
+ }
25
+
26
+ export function nowInTimezone(tz = 'UTC', format = 'YYYY-MM-DD HH:mm:ss') {
27
+ return dayjs().tz(tz).format(format);
28
+ }
29
+
30
+ export { dayjs };
@@ -0,0 +1,14 @@
1
+ export const mediaCollectionDefaults = {
2
+ url: '',
3
+ collection: '',
4
+ maxNumberOfFiles: 1,
5
+ maxFileSizeInMb: 2,
6
+ acceptedFileTypes: undefined,
7
+ thumbnailWidth: 200,
8
+ uploadedMedia: [],
9
+ };
10
+
11
+ export const mediaCollectionProp = {
12
+ type: Object,
13
+ default: () => ({ ...mediaCollectionDefaults }),
14
+ };
@@ -0,0 +1,22 @@
1
+ import { notify } from '@kyvg/vue3-notification';
2
+
3
+ const DEFAULT_SUCCESS_TITLE = 'Success!';
4
+ const DEFAULT_SUCCESS_MESSAGE = 'Operation succeeded.';
5
+ const DEFAULT_ERROR_TITLE = 'Error!';
6
+ const DEFAULT_ERROR_MESSAGE = 'An error has occurred.';
7
+
8
+ export function notifySuccess(message) {
9
+ notify({
10
+ type: 'success',
11
+ title: DEFAULT_SUCCESS_TITLE,
12
+ text: message || DEFAULT_SUCCESS_MESSAGE,
13
+ });
14
+ }
15
+
16
+ export function notifyError(message) {
17
+ notify({
18
+ type: 'error',
19
+ title: DEFAULT_ERROR_TITLE,
20
+ text: message || DEFAULT_ERROR_MESSAGE,
21
+ });
22
+ }
@@ -1,42 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var Admin = {
7
- el: '#app',
8
- data: function data() {
9
- return {
10
- loading: false
11
- };
12
- },
13
- mounted: function mounted() {
14
- var _this = this;
15
-
16
- // Add a loader request interceptor
17
- axios.interceptors.request.use(function (config) {
18
- _this.setLoading(true);
19
- return config;
20
- }, function (error) {
21
- _this.setLoading(false);
22
- return Promise.reject(error);
23
- });
24
-
25
- // Add a loader response interceptor
26
- axios.interceptors.response.use(function (response) {
27
- _this.setLoading(false);
28
- return response;
29
- }, function (error) {
30
- _this.setLoading(false);
31
- return Promise.reject(error);
32
- });
33
- },
34
-
35
- methods: {
36
- setLoading: function setLoading(value) {
37
- this.loading = !!value;
38
- }
39
- }
40
- };
41
-
42
- exports.default = Admin;
package/dist/auth/Form.js DELETED
@@ -1,15 +0,0 @@
1
- 'use strict';
2
-
3
- var _vue = require('vue');
4
-
5
- var _vue2 = _interopRequireDefault(_vue);
6
-
7
- var _BaseForm = require('../base-components/Form/BaseForm');
8
-
9
- var _BaseForm2 = _interopRequireDefault(_BaseForm);
10
-
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
-
13
- _vue2.default.component('auth-form', {
14
- mixins: [_BaseForm2.default]
15
- });
@@ -1,392 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
8
-
9
- require('./bootstrap');
10
-
11
- var _moment = require('moment');
12
-
13
- var _moment2 = _interopRequireDefault(_moment);
14
-
15
- var _vueTrumbowyg = require('vue-trumbowyg');
16
-
17
- var _vueTrumbowyg2 = _interopRequireDefault(_vueTrumbowyg);
18
-
19
- require('trumbowyg/dist/ui/trumbowyg.css');
20
-
21
- require('trumbowyg/dist/plugins/colors/trumbowyg.colors');
22
-
23
- require('trumbowyg/dist/plugins/colors/ui/trumbowyg.colors.css');
24
-
25
- require('trumbowyg/dist/plugins/base64/trumbowyg.base64.min.js');
26
-
27
- require('trumbowyg/dist/plugins/upload/trumbowyg.upload.js');
28
-
29
- require('trumbowyg/dist/plugins/noembed/trumbowyg.noembed.js');
30
-
31
- require('trumbowyg/dist/plugins/pasteembed/trumbowyg.pasteembed.js');
32
-
33
- require('trumbowyg/dist/plugins/table/ui/trumbowyg.table.css');
34
-
35
- require('trumbowyg/dist/plugins/table/trumbowyg.table.js');
36
-
37
- require('../../overrides/trumbowyg.template');
38
-
39
- require('../../overrides/trumbowyg.reupload');
40
-
41
- require('../../overrides/trumbowyg.edit-embed-template');
42
-
43
- var _UserDetailTooltip = require('../Listing/components/UserDetailTooltip');
44
-
45
- var _UserDetailTooltip2 = _interopRequireDefault(_UserDetailTooltip);
46
-
47
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
48
-
49
- Vue.component('wysiwyg', _vueTrumbowyg2.default);
50
-
51
- var BaseForm = {
52
- props: {
53
- action: {
54
- type: String,
55
- required: true
56
- },
57
- locales: {
58
- type: Array
59
- },
60
- defaultLocale: {
61
- type: String,
62
- default: function _default() {
63
- return this.locales instanceof Array && this.locales.length > 0 ? this.locales[0] : '';
64
- }
65
- },
66
- sendEmptyLocales: {
67
- type: Boolean,
68
- default: function _default() {
69
- return true;
70
- }
71
- },
72
- data: {
73
- type: Object,
74
- default: function _default() {
75
- return {};
76
- }
77
- },
78
- responsiveBreakpoint: {
79
- type: Number,
80
- default: 850
81
- }
82
- },
83
- components: {
84
- 'user-detail-tooltip': _UserDetailTooltip2.default
85
- },
86
-
87
- created: function created() {
88
- if (!!this.locales && this.locales.length > 0) {
89
- var form = this.form;
90
- // this.locales.map(function(l) {
91
- // if (!_.has(form, l)) {
92
- // _.set(form, l, {})
93
- // }
94
- // })
95
- this.currentLocale = this.defaultLocale;
96
- }
97
-
98
- //FIXME: now we can't add dynamic input in update type of form
99
- if (!_.isEmpty(this.data)) {
100
- this.form = this.data;
101
- }
102
-
103
- window.addEventListener('resize', this.onResize);
104
- },
105
-
106
- data: function data() {
107
- var that = this;
108
-
109
- return {
110
- form: {},
111
- wysiwygMedia: [],
112
- mediaCollections: [],
113
- isFormLocalized: false,
114
- currentLocale: '',
115
- submiting: false,
116
- onSmallScreen: window.innerWidth < this.responsiveBreakpoint,
117
- datePickerConfig: {
118
- dateFormat: 'Y-m-d H:i:S',
119
- altInput: true,
120
- altFormat: 'd.m.Y',
121
- locale: null
122
- },
123
- timePickerConfig: {
124
- enableTime: true,
125
- noCalendar: true,
126
- time_24hr: true,
127
- enableSeconds: true,
128
- dateFormat: 'H:i:S',
129
- altInput: true,
130
- altFormat: 'H:i:S',
131
- locale: null
132
- },
133
- datetimePickerConfig: {
134
- enableTime: true,
135
- time_24hr: true,
136
- enableSeconds: true,
137
- dateFormat: 'Y-m-d H:i:S',
138
- altInput: true,
139
- altFormat: 'd.m.Y H:i:S',
140
- locale: null
141
- },
142
- wysiwygConfig: {
143
- placeholder: 'Type a text here',
144
- modules: {
145
- toolbar: {
146
- container: [[{ header: [1, 2, 3, 4, 5, 6, false] }], ['bold', 'italic', 'underline', 'strike'], [{ list: 'ordered' }, { list: 'bullet' }], [{ color: [] }, { background: [] }], [{ align: [] }], ['link', 'image'], ['clean']]
147
- }
148
- }
149
- },
150
- mediaWysiwygConfig: {
151
- autogrow: true,
152
- imageWidthModalEdit: true,
153
- btnsDef: {
154
- image: {
155
- dropdown: ['insertImage', 'upload', 'base64'],
156
- ico: 'insertImage'
157
- },
158
- align: {
159
- dropdown: ['justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull'],
160
- ico: 'justifyLeft'
161
- }
162
- },
163
- btns: [['formatting'], ['strong', 'em', 'del'], ['align'], ['unorderedList', 'orderedList', 'table'], ['foreColor', 'backColor'], ['link', 'noembed', 'image'], ['template'], ['fullscreen', 'viewHTML']],
164
- plugins: {
165
- upload: {
166
- // https://alex-d.github.io/Trumbowyg/documentation/plugins/#plugin-upload
167
- serverPath: '/admin/wysiwyg-media',
168
- imageWidthModalEdit: true,
169
- success: function success(data, trumbowyg, $modal, values) {
170
- that.wysiwygMedia.push(data.mediaId);
171
-
172
- function getDeep(object, propertyParts) {
173
- var mainProperty = propertyParts.shift(),
174
- otherProperties = propertyParts;
175
-
176
- if (object !== null) {
177
- if (otherProperties.length === 0) {
178
- return object[mainProperty];
179
- }
180
-
181
- if ((typeof object === 'undefined' ? 'undefined' : _typeof(object)) === 'object') {
182
- return getDeep(object[mainProperty], otherProperties);
183
- }
184
- }
185
- return object;
186
- }
187
-
188
- if (!!getDeep(data, trumbowyg.o.plugins.upload.statusPropertyName.split('.'))) {
189
- var url = getDeep(data, trumbowyg.o.plugins.upload.urlPropertyName.split('.'));
190
- trumbowyg.execCmd('insertImage', url, false, true);
191
- var $img = $('img[src="' + url + '"]:not([alt])', trumbowyg.$box);
192
- $img.attr('alt', values.alt);
193
- if (trumbowyg.o.imageWidthModalEdit && parseInt(values.width) > 0) {
194
- $img.attr({
195
- width: values.width
196
- });
197
- }
198
- setTimeout(function () {
199
- trumbowyg.closeModal();
200
- }, 250);
201
- trumbowyg.$c.trigger('tbwuploadsuccess', [trumbowyg, data, url]);
202
- } else {
203
- trumbowyg.addErrorOnModalField($('input[type=file]', $modal), trumbowyg.lang[data.message]);
204
- trumbowyg.$c.trigger('tbwuploaderror', [trumbowyg, data]);
205
- }
206
- }
207
- },
208
- reupload: {
209
- success: function success(data, trumbowyg, $modal, values, $img) {
210
- that.wysiwygMedia.push(data.mediaId);
211
-
212
- $img.attr({
213
- src: data.file
214
- });
215
- trumbowyg.execCmd('insertHTML');
216
- setTimeout(function () {
217
- trumbowyg.closeModal();
218
- }, 250);
219
- var url = getDeep(data, trumbowyg.o.plugins.upload.urlPropertyName.split('.'));
220
- trumbowyg.$c.trigger('tbwuploadsuccess', [trumbowyg, data, url]);
221
- }
222
- }
223
- }
224
- }
225
- };
226
- },
227
-
228
- computed: {
229
- otherLocales: function otherLocales() {
230
- var _this = this;
231
-
232
- return this.locales.filter(function (x) {
233
- return x != _this.defaultLocale;
234
- });
235
- },
236
- showLocalizedValidationError: function showLocalizedValidationError() {
237
- var _this2 = this;
238
-
239
- // TODO ked sme neni na mobile, tak pozerat zo vsetkych
240
- return this.otherLocales.some(function (lang) {
241
- return _this2.errors.items.some(function (item) {
242
- return item.field.endsWith('_' + lang) || item.field.startsWith(lang + '_');
243
- });
244
- });
245
- }
246
- },
247
- filters: {
248
- date: function date(date) {
249
- var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'YYYY-MM-DD';
250
-
251
- var date = (0, _moment2.default)(date);
252
- return date.isValid() ? date.format(format) : "";
253
- },
254
- datetime: function datetime(_datetime) {
255
- var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'YYYY-MM-DD HH:mm:ss';
256
-
257
- var date = (0, _moment2.default)(_datetime);
258
- return date.isValid() ? date.format(format) : "";
259
- },
260
- time: function time(_time) {
261
- var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'HH:mm:ss';
262
-
263
- // '2000-01-01' is here just because momentjs needs a date
264
- var date = (0, _moment2.default)('2000-01-01 ' + _time);
265
- return date.isValid() ? date.format(format) : "";
266
- }
267
- },
268
- methods: {
269
- getPostData: function getPostData() {
270
- var _this3 = this;
271
-
272
- if (this.mediaCollections) {
273
- this.mediaCollections.forEach(function (collection, index, arr) {
274
- if (_this3.form[collection]) {
275
- console.warn("MediaUploader warning: Media input must have a unique name, '" + collection + "' is already defined in regular inputs.");
276
- }
277
-
278
- if (_this3.$refs[collection + '_uploader']) {
279
- _this3.form[collection] = _this3.$refs[collection + '_uploader'].getFiles();
280
- }
281
- });
282
- }
283
- this.form['wysiwygMedia'] = this.wysiwygMedia;
284
-
285
- return this.form;
286
- },
287
- onSubmit: function onSubmit() {
288
- var _this4 = this;
289
-
290
- return this.$validator.validateAll().then(function (result) {
291
- if (!result) {
292
- _this4.$notify({
293
- type: 'error',
294
- title: 'Error!',
295
- text: 'The form contains invalid fields.'
296
- });
297
- return false;
298
- }
299
-
300
- var data = _this4.form;
301
- if (!_this4.sendEmptyLocales) {
302
- data = _.omit(_this4.form, _this4.locales.filter(function (locale) {
303
- return _.isEmpty(_this4.form[locale]);
304
- }));
305
- }
306
-
307
- _this4.submiting = true;
308
-
309
- axios.post(_this4.action, _this4.getPostData()).then(function (response) {
310
- return _this4.onSuccess(response.data);
311
- }).catch(function (errors) {
312
- return _this4.onFail(errors.response.data);
313
- });
314
- });
315
- },
316
- onSuccess: function onSuccess(data) {
317
- this.submiting = false;
318
- if (data.redirect) {
319
- window.location.replace(data.redirect);
320
- }
321
- },
322
- onFail: function onFail(data) {
323
- this.submiting = false;
324
- if (_typeof(data.errors) !== (typeof undefined === 'undefined' ? 'undefined' : _typeof(undefined))) {
325
- var bag = this.$validator.errors;
326
- bag.clear();
327
- Object.keys(data.errors).map(function (key) {
328
- var splitted = key.split('.', 2);
329
- // we assume that first dot divides column and locale (TODO maybe refactor this and make it more general)
330
- if (splitted.length > 1) {
331
- bag.add({
332
- field: splitted[0] + '_' + splitted[1],
333
- msg: data.errors[key][0]
334
- });
335
- } else {
336
- bag.add({
337
- field: key,
338
- msg: data.errors[key][0]
339
- });
340
- }
341
- });
342
- if (_typeof(data.message) === (typeof undefined === 'undefined' ? 'undefined' : _typeof(undefined))) {
343
- this.$notify({
344
- type: 'error',
345
- title: 'Error!',
346
- text: 'The form contains invalid fields.'
347
- });
348
- }
349
- }
350
- if (_typeof(data.message) !== (typeof undefined === 'undefined' ? 'undefined' : _typeof(undefined))) {
351
- this.$notify({
352
- type: 'error',
353
- title: 'Error!',
354
- text: data.message
355
- });
356
- }
357
- },
358
- getLocalizedFormDefaults: function getLocalizedFormDefaults() {
359
- var object = {};
360
- this.locales.forEach(function (currentValue, index, arr) {
361
- object[currentValue] = null;
362
- });
363
- return object;
364
- },
365
- showLocalization: function showLocalization() {
366
- this.isFormLocalized = true;
367
- this.currentLocale = this.otherLocales[0];
368
- $('.container-xl').addClass('width-auto');
369
- },
370
- hideLocalization: function hideLocalization() {
371
- this.isFormLocalized = false;
372
- $('.container-xl').removeClass('width-auto');
373
- },
374
- validate: function validate(event) {
375
- this.$validator.errors.remove(event.target.name);
376
- },
377
- shouldShowLangGroup: function shouldShowLangGroup(locale) {
378
- if (!this.onSmallScreen) {
379
- if (this.defaultLocale == locale) return true;
380
-
381
- return this.isFormLocalized && this.currentLocale == locale;
382
- } else {
383
- return this.currentLocale == locale;
384
- }
385
- },
386
- onResize: function onResize() {
387
- this.onSmallScreen = window.innerWidth < this.responsiveBreakpoint;
388
- }
389
- }
390
- };
391
-
392
- exports.default = BaseForm;