@dejwcake/craftable 0.0.1

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 (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +10 -0
  3. package/dist/admin/Admin.js +42 -0
  4. package/dist/auth/Form.js +15 -0
  5. package/dist/base-components/Form/BaseForm.js +392 -0
  6. package/dist/base-components/Form/BaseUpload.js +188 -0
  7. package/dist/base-components/Form/bootstrap.js +21 -0
  8. package/dist/base-components/Listing/BaseListing.js +454 -0
  9. package/dist/base-components/Listing/components/Pagination.js +105 -0
  10. package/dist/base-components/Listing/components/Sortable.js +48 -0
  11. package/dist/base-components/Listing/components/UserDetailTooltip.js +55 -0
  12. package/dist/index.js +70 -0
  13. package/dist/overrides/trumbowyg.edit-embed-template.js +72 -0
  14. package/dist/overrides/trumbowyg.reupload.js +146 -0
  15. package/dist/overrides/trumbowyg.template.js +67 -0
  16. package/dist/translation/Form.js +15 -0
  17. package/dist/translation/Listing.js +283 -0
  18. package/dist/ui/index.js +33 -0
  19. package/img/favicon.png +0 -0
  20. package/img/logo.png +0 -0
  21. package/package.json +64 -0
  22. package/scss/_images.scss +18 -0
  23. package/scss/_variables.scss +17 -0
  24. package/scss/app.scss +9 -0
  25. package/scss/overrides/_alerts.scss +19 -0
  26. package/scss/overrides/_badges.scss +15 -0
  27. package/scss/overrides/_buttons.scss +62 -0
  28. package/scss/overrides/_cards.scss +72 -0
  29. package/scss/overrides/_checkboxes.scss +84 -0
  30. package/scss/overrides/_forms.scss +231 -0
  31. package/scss/overrides/_index.scss +19 -0
  32. package/scss/overrides/_keyframes.scss +23 -0
  33. package/scss/overrides/_layout.scss +47 -0
  34. package/scss/overrides/_media-wysiwyg.scss +111 -0
  35. package/scss/overrides/_modal.scss +26 -0
  36. package/scss/overrides/_multiselect.scss +39 -0
  37. package/scss/overrides/_nav.scss +87 -0
  38. package/scss/overrides/_notifications.scss +7 -0
  39. package/scss/overrides/_pagination.scss +38 -0
  40. package/scss/overrides/_switches.scss +23 -0
  41. package/scss/overrides/_tables.scss +64 -0
  42. package/scss/overrides/_text.scss +15 -0
  43. package/scss/overrides/_wysiwyg.scss +62 -0
  44. package/scss/styles/_auth.scss +92 -0
  45. package/scss/styles/_custom.scss +1 -0
  46. package/scss/styles/_index.scss +5 -0
  47. package/scss/styles/_legacy.scss +87 -0
  48. package/scss/styles/_others.scss +604 -0
  49. package/scss/vendor/_index.scss +4 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 BRACKETS
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # craftable-frontend
2
+ This is a frontend dependency of [Craftable](https://github.com/BRACKETS-by-TRIAD/craftable). Craftable is a Laravel-based open-source toolkit for building administration interfaces.
3
+
4
+ ![Craftable administration area example](https://www.getcraftable.com/docs/5.0/images/posts-crud.png)
5
+
6
+ Find out more here: https://www.getcraftable.com/
7
+
8
+ ## Issues
9
+ Where do I report issues?
10
+ If something is not working as expected, please open an issue in the main repository https://github.com/BRACKETS-by-TRIAD/craftable.
@@ -0,0 +1,42 @@
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;
@@ -0,0 +1,15 @@
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
+ });
@@ -0,0 +1,392 @@
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;
@@ -0,0 +1,188 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _vue2Dropzone = require('vue2-dropzone');
8
+
9
+ var _vue2Dropzone2 = _interopRequireDefault(_vue2Dropzone);
10
+
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+
13
+ var BaseUpload = {
14
+ components: {
15
+ Dropzone: _vue2Dropzone2.default
16
+ },
17
+ props: {
18
+ url: {
19
+ type: String,
20
+ required: true
21
+ },
22
+ collection: {
23
+ type: String,
24
+ required: true
25
+ },
26
+ maxNumberOfFiles: {
27
+ type: Number,
28
+ required: false,
29
+ default: 1
30
+ },
31
+ maxFileSizeInMb: {
32
+ type: Number,
33
+ required: false,
34
+ default: 2
35
+ },
36
+ acceptedFileTypes: {
37
+ type: String,
38
+ required: false
39
+ },
40
+ thumbnailWidth: {
41
+ type: Number,
42
+ required: false,
43
+ default: 200
44
+ },
45
+ uploadedImages: {
46
+ type: Array,
47
+ required: false,
48
+ default: function _default() {
49
+ return [];
50
+ }
51
+ }
52
+ },
53
+ data: function data() {
54
+ return {
55
+ mutableUploadedImages: this.uploadedImages,
56
+ headers: {
57
+ 'X-CSRF-TOKEN': document.head.querySelector('meta[name="csrf-token"]').getAttribute('content')
58
+ }
59
+ };
60
+ },
61
+ template: '<dropzone :id="collection" \n :url="url" \n v-bind:preview-template="template"\n v-on:vdropzone-success="onSuccess"\n v-on:vdropzone-error="onUploadError"\n v-on:vdropzone-removed-file="onFileDelete"\n v-on:vdropzone-file-added="onFileAdded"\n :useFontAwesome="true" \n :ref="collection"\n :maxNumberOfFiles="maxNumberOfFiles"\n :maxFileSizeInMB="maxFileSizeInMb"\n :acceptedFileTypes="acceptedFileTypes"\n :thumbnailWidth="thumbnailWidth"\n :headers="headers">\n \n <input type="hidden" name="collection" :value="collection">\n </dropzone>',
62
+ mounted: function mounted() {
63
+ this.attachAlreadyUploadedMedia();
64
+ },
65
+ methods: {
66
+ onSuccess: function onSuccess(file, response) {
67
+ if (!file.type.includes('image')) {
68
+ setTimeout(function () {
69
+ //FIXME jquery
70
+ $(file.previewElement).removeClass('dz-file-preview');
71
+ }, 3000);
72
+ }
73
+ },
74
+
75
+ onUploadError: function onUploadError(file, error) {
76
+ var errorMessage = typeof error == 'string' ? error : error.message;
77
+ this.$notify({ type: 'error', title: 'Error!', text: errorMessage });
78
+ $(file.previewElement).find('.dz-error-message span').text(errorMessage);
79
+ },
80
+
81
+ onFileAdded: function onFileAdded(file) {
82
+ this.placeIcon(file);
83
+ },
84
+
85
+ onFileDelete: function onFileDelete(file, error, xhr) {
86
+ var deletedFileIndex = _.findIndex(this.mutableUploadedImages, { url: file.url });
87
+ if (this.mutableUploadedImages[deletedFileIndex]) {
88
+ this.mutableUploadedImages[deletedFileIndex]['deleted'] = true;
89
+
90
+ //dontSubstractMaxFiles fix
91
+ var currentMax = this.$refs[this.collection].dropzone.options.maxFiles;
92
+ this.$refs[this.collection].setOption('maxFiles', currentMax + 1);
93
+ }
94
+ },
95
+
96
+ attachAlreadyUploadedMedia: function attachAlreadyUploadedMedia() {
97
+ var _this = this;
98
+
99
+ this.$nextTick(function () {
100
+ if (_this.mutableUploadedImages) {
101
+ _.each(_this.mutableUploadedImages, function (file, key) {
102
+
103
+ _this.$refs[_this.collection].manuallyAddFile({ name: file['name'],
104
+ size: file['size'],
105
+ type: file['type'],
106
+ url: file['url']
107
+ }, file['thumb_url'], false, false, {
108
+ dontSubstractMaxFiles: false,
109
+ addToFiles: true
110
+ });
111
+ });
112
+ }
113
+ });
114
+ },
115
+
116
+ getFiles: function getFiles() {
117
+ var _this2 = this;
118
+
119
+ var files = [];
120
+
121
+ _.each(this.mutableUploadedImages, function (file, key) {
122
+ if (file.deleted) {
123
+ files.push({
124
+ id: file.id,
125
+ collection_name: _this2.collection,
126
+ action: 'delete'
127
+ });
128
+ }
129
+ });
130
+
131
+ _.each(this.$refs[this.collection].getAcceptedFiles(), function (file, key) {
132
+ var response = JSON.parse(file.xhr.response);
133
+
134
+ if (response.path) {
135
+ files.push({
136
+ id: file.id,
137
+ collection_name: _this2.collection,
138
+ path: response.path,
139
+ action: file.deleted ? 'delete' : 'add', //TODO: update ie. meta_data.name
140
+ meta_data: {
141
+ name: file.name, //TODO: editable in the future
142
+ file_name: file.name,
143
+ width: file.width,
144
+ height: file.height
145
+ }
146
+ });
147
+ }
148
+ });
149
+
150
+ return files;
151
+ },
152
+
153
+ placeIcon: function placeIcon(file) {
154
+ //FIXME cele to je jqueryoidne, asi si budeme musiet spravit vlastny vue wrapper, tento je zbugovany
155
+ var $previewElement = $(file.previewElement);
156
+
157
+ if (file.url) {
158
+ $previewElement.find('.dz-filename').html('<a href="' + file.url + '" target="_BLANK" class="dz-btn dz-custom-download">' + file.name + '</a>');
159
+ }
160
+
161
+ if (file.type.includes('image')) {
162
+ //nothing, default thumb
163
+ } else if (file.type.includes('pdf')) {
164
+ $previewElement.find('.dz-image').html('<i class="fa fa-file-pdf-o"></i><p>' + file.name + '</p>');
165
+ } else if (file.type.includes('word')) {
166
+ $previewElement.find('.dz-image').html('<i class="fa fa-file-word-o"></i><p>' + file.name + '</p>');
167
+ } else if (file.type.includes('spreadsheet') || file.type.includes('csv')) {
168
+ $previewElement.find('.dz-image').html('<i class="fa fa-file-excel-o"></i><p>' + file.name + '</p>');
169
+ } else if (file.type.includes('presentation')) {
170
+ $previewElement.find('.dz-image').html('<i class="fa fa-file-powerpoint-o"></i><p>' + file.name + '</p>');
171
+ } else if (file.type.includes('video')) {
172
+ $previewElement.find('.dz-image').html('<i class="fa fa-file-video-o"></i><p>' + file.name + '</p>');
173
+ } else if (file.type.includes('text')) {
174
+ $previewElement.find('.dz-image').html('<i class="fa fa-file-text-o"></i><p>' + file.name + '</p>');
175
+ } else if (file.type.includes('zip') || file.type.includes('rar')) {
176
+ $previewElement.find('.dz-image').html('<i class="fa fa-file-archive-o"></i><p>' + file.name + '</p>');
177
+ } else {
178
+ $previewElement.find('.dz-image').html('<i class="fa fa-file-o"></i><p>' + file.name + '</p>');
179
+ }
180
+ },
181
+
182
+ template: function template() {
183
+ return '\n <div class="dz-preview dz-file-preview">\n <div class="dz-image">\n <img data-dz-thumbnail />\n </div>\n <div class="dz-details">\n <div class="dz-size"><span data-dz-size></span></div>\n <div class="dz-filename"></div>\n </div>\n <div class="dz-progress"><span class="dz-upload" data-dz-uploadprogress></span></div>\n <div class="dz-error-message"><span data-dz-errormessage></span></div>\n <div class="dz-success-mark"><i class="fa fa-check"></i></div>\n <div class="dz-error-mark"><i class="fa fa-close"></i></div>\n </div>\n ';
184
+ }
185
+ }
186
+ };
187
+
188
+ exports.default = BaseUpload;
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ var _vue = require('vue');
4
+
5
+ var _vue2 = _interopRequireDefault(_vue);
6
+
7
+ var _jquery = require('jquery');
8
+
9
+ var _jquery2 = _interopRequireDefault(_jquery);
10
+
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+
13
+ // This file is here only to ensure backwards compatibility
14
+
15
+ window.$ = window.jQuery = _jquery2.default;
16
+ window.Vue = _vue2.default;
17
+
18
+ var token = document.head.querySelector('meta[name="csrf-token"]');
19
+ if (token) {
20
+ $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': token.content } });
21
+ }