pages_core 3.7.0 → 3.8.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -2
- data/Rakefile +37 -0
- data/app/assets/builds/pages_core/admin-dist.js +55 -0
- data/app/assets/stylesheets/pages/admin/components/image_editor.scss +1 -0
- data/app/assets/stylesheets/pages/admin/components/image_grid.scss +33 -5
- data/app/assets/stylesheets/pages/admin/components/layout.scss +2 -1
- data/app/assets/stylesheets/pages/admin/components/login.scss +6 -0
- data/app/assets/stylesheets/pages/admin/components/tabs.scss +5 -0
- data/app/assets/stylesheets/pages/admin/components/tag_editor.scss +13 -7
- data/app/assets/stylesheets/pages/admin/controllers/pages.scss +13 -5
- data/app/assets/stylesheets/pages/admin.scss +0 -1
- data/app/controller_dummies/admin/admin_controller.rb +1 -1
- data/app/controller_dummies/application_controller.rb +1 -1
- data/app/controller_dummies/attachments_controller.rb +1 -1
- data/app/controller_dummies/frontend_controller.rb +1 -1
- data/app/controller_dummies/images_controller.rb +1 -1
- data/app/controller_dummies/page_files_controller.rb +1 -1
- data/app/controller_dummies/pages_controller.rb +1 -1
- data/app/controller_dummies/sitemaps_controller.rb +1 -1
- data/app/controllers/admin/attachments_controller.rb +1 -1
- data/app/controllers/admin/images_controller.rb +11 -8
- data/app/controllers/concerns/pages_core/authentication.rb +9 -4
- data/app/controllers/concerns/pages_core/preview_pages_controller.rb +5 -0
- data/app/controllers/pages_core/frontend/pages_controller.rb +5 -2
- data/app/controllers/sessions_controller.rb +1 -1
- data/app/formatters/pages_core/link_renderer.rb +2 -2
- data/app/helpers/application_helper.rb +1 -1
- data/app/helpers/frontend_helper.rb +1 -1
- data/app/helpers/pages_core/admin/content_tabs_helper.rb +5 -2
- data/app/helpers/pages_core/admin/image_uploads_helper.rb +2 -3
- data/app/helpers/pages_core/admin/tag_editor_helper.rb +9 -39
- data/app/helpers/pages_core/head_tags_helper.rb +11 -20
- data/app/helpers/pages_core/open_graph_tags_helper.rb +1 -1
- data/app/javascript/admin-dist.js +2 -0
- data/app/javascript/components/Attachments/Attachment.jsx +121 -0
- data/app/javascript/components/Attachments/AttachmentEditor.jsx +116 -0
- data/app/javascript/components/Attachments/Placeholder.jsx +10 -0
- data/app/javascript/components/Attachments.jsx +165 -0
- data/app/{assets/javascripts/pages/admin/components/date_range_select.jsx → javascript/components/DateRangeSelect.jsx} +16 -5
- data/app/javascript/components/EditableImage.jsx +61 -0
- data/app/javascript/components/FileUploadButton.jsx +47 -0
- data/app/{assets/javascripts/pages/admin/components/focal_point.jsx → javascript/components/ImageCropper/FocalPoint.jsx} +12 -1
- data/app/javascript/components/ImageCropper/Image.jsx +65 -0
- data/app/javascript/components/ImageCropper/Toolbar.jsx +73 -0
- data/app/javascript/components/ImageCropper/useCrop.js +199 -0
- data/app/javascript/components/ImageCropper.jsx +90 -0
- data/app/javascript/components/ImageEditor/Form.jsx +98 -0
- data/app/javascript/components/ImageEditor.jsx +62 -0
- data/app/javascript/components/ImageGrid/DragElement.jsx +30 -0
- data/app/javascript/components/ImageGrid/FilePlaceholder.jsx +9 -0
- data/app/javascript/components/ImageGrid/GridImage.jsx +103 -0
- data/app/javascript/components/ImageGrid/Placeholder.jsx +23 -0
- data/app/javascript/components/ImageGrid.jsx +257 -0
- data/app/javascript/components/ImageUploader.jsx +171 -0
- data/app/{assets/javascripts/pages/admin/components/modal.jsx → javascript/components/Modal.jsx} +13 -2
- data/app/{assets/javascripts/pages/admin/components/page_dates.jsx → javascript/components/PageDates.jsx} +11 -1
- data/app/{assets/javascripts/pages/admin/components/page_files.jsx → javascript/components/PageFiles.jsx} +11 -2
- data/app/{assets/javascripts/pages/admin/components/page_images.jsx → javascript/components/PageImages.jsx} +11 -2
- data/app/{assets/javascripts/pages/admin/components/page_tree_store.jsx → javascript/components/PageTree.jsx} +127 -137
- data/app/{assets/javascripts/pages/admin/components/page_tree.jsx → javascript/components/PageTreeDraggable.jsx} +35 -29
- data/app/{assets/javascripts/pages/admin/components/page_tree_node.jsx → javascript/components/PageTreeNode.jsx} +35 -20
- data/app/javascript/components/RichTextArea.jsx +213 -0
- data/app/javascript/components/RichTextToolbarButton.jsx +20 -0
- data/app/javascript/components/TagEditor/AddTagForm.jsx +42 -0
- data/app/javascript/components/TagEditor/Tag.jsx +32 -0
- data/app/javascript/components/TagEditor.jsx +61 -0
- data/app/javascript/components/Toast.jsx +72 -0
- data/app/javascript/components/drag/draggedOrder.js +51 -0
- data/app/javascript/components/drag/useDragCollection.js +84 -0
- data/app/javascript/components/drag/useDragUploader.js +112 -0
- data/app/javascript/components/drag/useDraggable.js +17 -0
- data/app/javascript/components/drag.js +6 -0
- data/app/javascript/components.js +15 -0
- data/app/javascript/controllers/EditPageController.js +20 -0
- data/app/javascript/controllers/LoginController.js +29 -0
- data/app/javascript/controllers/MainController.js +65 -0
- data/app/javascript/controllers/PageOptionsController.js +62 -0
- data/app/javascript/features/RichText.jsx +34 -0
- data/app/javascript/hooks.js +2 -0
- data/app/javascript/index.js +38 -0
- data/app/{assets/javascripts/pages/admin/lib/tree.jsx → javascript/lib/Tree.js} +55 -54
- data/app/javascript/lib/copyToClipboard.js +13 -0
- data/app/javascript/lib/readyHandler.js +22 -0
- data/app/javascript/lib/request.js +36 -0
- data/app/javascript/stores/ModalStore.jsx +12 -0
- data/app/javascript/stores/ToastStore.jsx +14 -0
- data/app/javascript/stores.js +2 -0
- data/app/models/concerns/pages_core/page_model/images.rb +3 -1
- data/app/models/concerns/pages_core/page_model/searchable.rb +19 -0
- data/app/models/concerns/pages_core/searchable_document.rb +71 -0
- data/app/models/concerns/pages_core/taggable.rb +27 -12
- data/app/models/page.rb +2 -0
- data/app/models/page_exporter.rb +2 -2
- data/app/models/page_image.rb +0 -2
- data/app/models/role.rb +1 -1
- data/app/models/search_document.rb +72 -0
- data/app/models/tag.rb +1 -0
- data/app/models/user.rb +1 -1
- data/app/{serializers/admin/attachment_serializer.rb → resources/admin/attachment_resource.rb} +6 -5
- data/app/{serializers/admin/image_serializer.rb → resources/admin/image_resource.rb} +9 -9
- data/app/resources/admin/page_file_resource.rb +10 -0
- data/app/{serializers/admin/page_image_serializer.rb → resources/admin/page_image_resource.rb} +4 -2
- data/app/resources/export/attachment_resource.rb +10 -0
- data/app/resources/export/page_image_resource.rb +45 -0
- data/app/resources/export/page_resource.rb +42 -0
- data/app/{serializers/page_image_serializer.rb → resources/page_image_resource.rb} +8 -16
- data/app/resources/page_resource.rb +33 -0
- data/app/services/pages_core/destroy_invite_service.rb +2 -2
- data/app/services/pages_core/invite_service.rb +2 -2
- data/app/views/admin/pages/_edit_content.html.erb +1 -1
- data/app/views/admin/pages/_edit_files.html.erb +1 -5
- data/app/views/admin/pages/_edit_images.html.erb +1 -5
- data/app/views/admin/pages/_edit_options.html.erb +74 -55
- data/app/views/admin/pages/_form.html.erb +19 -0
- data/app/views/admin/pages/edit.html.erb +35 -61
- data/app/views/admin/pages/index.html.erb +0 -1
- data/app/views/admin/pages/new.html.erb +32 -32
- data/app/views/admin/users/_access_control.html.erb +5 -1
- data/app/views/admin/users/login.html.erb +12 -4
- data/app/views/feeds/pages.rss.builder +1 -2
- data/app/views/layouts/admin/_header.html.erb +1 -1
- data/app/views/layouts/admin/_page_header.html.erb +33 -0
- data/app/views/layouts/admin.html.erb +23 -42
- data/app/views/pages_core/_google_analytics.html.erb +8 -0
- data/db/migrate/20180625154059_enable_search_extensions.rb +10 -0
- data/db/migrate/20210209151400_create_search_configurations.rb +35 -0
- data/db/migrate/20210210235200_create_search_documents.rb +74 -0
- data/lib/pages_core/engine.rb +1 -5
- data/lib/pages_core/templates/block_configuration.rb +1 -1
- data/lib/pages_core/templates/configuration_handler.rb +1 -1
- data/lib/pages_core/version.rb +3 -1
- data/lib/pages_core.rb +3 -5
- data/lib/rails/generators/pages_core/frontend/frontend_generator.rb +0 -7
- data/lib/rails/generators/pages_core/install/templates/page_templates_initializer.rb +2 -2
- metadata +116 -115
- data/app/assets/javascripts/pages/admin/components/attachment.jsx +0 -130
- data/app/assets/javascripts/pages/admin/components/attachment_editor.jsx +0 -131
- data/app/assets/javascripts/pages/admin/components/attachments.jsx +0 -211
- data/app/assets/javascripts/pages/admin/components/drag_uploader.jsx +0 -174
- data/app/assets/javascripts/pages/admin/components/editable_image.jsx +0 -57
- data/app/assets/javascripts/pages/admin/components/file_upload_button.jsx +0 -44
- data/app/assets/javascripts/pages/admin/components/grid_image.jsx +0 -124
- data/app/assets/javascripts/pages/admin/components/image_editor.jsx +0 -496
- data/app/assets/javascripts/pages/admin/components/image_grid.jsx +0 -306
- data/app/assets/javascripts/pages/admin/components/image_uploader.jsx +0 -176
- data/app/assets/javascripts/pages/admin/components/modal_store.jsx +0 -20
- data/app/assets/javascripts/pages/admin/components/rich_text_area.jsx +0 -64
- data/app/assets/javascripts/pages/admin/components/rich_text_toolbar.jsx +0 -91
- data/app/assets/javascripts/pages/admin/components/toast.jsx +0 -34
- data/app/assets/javascripts/pages/admin/components/toast_store.jsx +0 -52
- data/app/assets/javascripts/pages/admin/components.jsx +0 -2
- data/app/assets/javascripts/pages/admin/features/content_tabs.jsx +0 -72
- data/app/assets/javascripts/pages/admin/features/edit_page.jsx +0 -97
- data/app/assets/javascripts/pages/admin/features/rich_text.jsx +0 -14
- data/app/assets/javascripts/pages/admin/features/tag_editor.jsx +0 -160
- data/app/assets/javascripts/pages/admin.jsx +0 -17
- data/app/assets/javascripts/pages/login_form.jsx +0 -21
- data/app/serializers/admin/page_file_serializer.rb +0 -8
- data/app/serializers/page_export_serializer.rb +0 -32
- data/app/serializers/page_file_export_serializer.rb +0 -6
- data/app/serializers/page_image_export_serializer.rb +0 -42
- data/app/serializers/page_serializer.rb +0 -23
- data/app/views/layouts/admin/_analytics.html.erb +0 -16
- data/lib/rails/generators/pages_core/frontend/templates/application.js.erb +0 -15
- data/vendor/assets/javascripts/ReactCrop.min.js +0 -1
- data/vendor/assets/javascripts/reflux.min.js +0 -1
@@ -1,306 +0,0 @@
|
|
1
|
-
class ImageGrid extends DragUploader {
|
2
|
-
constructor(props) {
|
3
|
-
super(props);
|
4
|
-
|
5
|
-
this.validMimeTypes = ["image/gif",
|
6
|
-
"image/jpeg",
|
7
|
-
"image/pjpeg",
|
8
|
-
"image/png",
|
9
|
-
"image/tiff"];
|
10
|
-
|
11
|
-
let records = props.records.map(
|
12
|
-
r => ({ ...r, ref: React.createRef(), handle: this.getHandle() })
|
13
|
-
);
|
14
|
-
|
15
|
-
this.state = { ...this.state,
|
16
|
-
primary: null,
|
17
|
-
images: records,
|
18
|
-
deleted: [] };
|
19
|
-
|
20
|
-
if (props.enablePrimary) {
|
21
|
-
this.state = { ...this.state,
|
22
|
-
primary: records.filter(r => r.primary)[0] || null,
|
23
|
-
images: records.filter(r => !r.primary) };
|
24
|
-
}
|
25
|
-
|
26
|
-
this.container = React.createRef();
|
27
|
-
this.imagesContainer = React.createRef();
|
28
|
-
this.primaryContainer = React.createRef();
|
29
|
-
|
30
|
-
this.deleteImage = this.deleteImage.bind(this);
|
31
|
-
this.uploadAdditional = this.uploadAdditional.bind(this);
|
32
|
-
this.uploadPrimary = this.uploadPrimary.bind(this);
|
33
|
-
}
|
34
|
-
|
35
|
-
attributeName(record) {
|
36
|
-
return `${this.props.attribute}[${this.index(record) + 1}]`;
|
37
|
-
}
|
38
|
-
|
39
|
-
draggables() {
|
40
|
-
return this.state.images;
|
41
|
-
}
|
42
|
-
|
43
|
-
deleteImage(record) {
|
44
|
-
let { primary, images, deleted } = this.state;
|
45
|
-
if (record == this.state.primary) {
|
46
|
-
primary = null;
|
47
|
-
} else {
|
48
|
-
images = images.filter(i => i != record);
|
49
|
-
}
|
50
|
-
if (record.id) {
|
51
|
-
deleted = [...deleted, record];
|
52
|
-
}
|
53
|
-
this.setState({ primary: primary, images: images, deleted: deleted });
|
54
|
-
}
|
55
|
-
|
56
|
-
injectUploads(files, primary, images) {
|
57
|
-
let queue = files.slice();
|
58
|
-
if (primary === "Files") {
|
59
|
-
primary = queue.shift();
|
60
|
-
images = [...queue, ...images];
|
61
|
-
} else {
|
62
|
-
let source = images;
|
63
|
-
images = [];
|
64
|
-
source.forEach(function (img) {
|
65
|
-
if (img === "Files") {
|
66
|
-
images = [...images, ...queue];
|
67
|
-
} else {
|
68
|
-
images.push(img);
|
69
|
-
}
|
70
|
-
});
|
71
|
-
}
|
72
|
-
return { primary: primary, images: images };
|
73
|
-
}
|
74
|
-
|
75
|
-
receiveFiles(files, newState) {
|
76
|
-
var { primary, images } = this.getDraggedOrder();
|
77
|
-
|
78
|
-
if (files.length > 0) {
|
79
|
-
var { primary, images } = this.injectUploads(
|
80
|
-
files.map(f => this.uploadImage(f)), primary, images
|
81
|
-
);
|
82
|
-
}
|
83
|
-
|
84
|
-
this.setState({...newState, primary: primary, images: images});
|
85
|
-
}
|
86
|
-
|
87
|
-
index(record) {
|
88
|
-
let { primary, images, deleted } = this.state;
|
89
|
-
var ordered = [...images, ...deleted];
|
90
|
-
if (primary) {
|
91
|
-
ordered = [primary, ...ordered];
|
92
|
-
}
|
93
|
-
return ordered.indexOf(record);
|
94
|
-
}
|
95
|
-
|
96
|
-
renderDrag() {
|
97
|
-
let record = this.state.dragging;
|
98
|
-
if (record === "Files") {
|
99
|
-
return "";
|
100
|
-
} else {
|
101
|
-
let containerSize = this.container.current.getBoundingClientRect();
|
102
|
-
let x = this.state.x - (containerSize.x || containerSize.left);
|
103
|
-
let y = this.state.y - (containerSize.y || containerSize.top);
|
104
|
-
let translateStyle = {
|
105
|
-
transform: `translate3d(${x}px, ${y}px, 0)`
|
106
|
-
};
|
107
|
-
return (
|
108
|
-
<div className="drag-image" style={translateStyle}>
|
109
|
-
{record.image && (
|
110
|
-
<img src={record.src || record.image.thumbnail_url} />
|
111
|
-
)}
|
112
|
-
</div>
|
113
|
-
);
|
114
|
-
}
|
115
|
-
}
|
116
|
-
|
117
|
-
getDraggedOrder() {
|
118
|
-
let dragging = this.state.dragging;
|
119
|
-
var primary = this.state.primary;
|
120
|
-
var images = this.state.images;
|
121
|
-
if (dragging) {
|
122
|
-
if (this.hovering(this.primaryContainer)) {
|
123
|
-
images = [primary, ...images].filter(
|
124
|
-
r => r !== null && r !== dragging
|
125
|
-
);
|
126
|
-
primary = dragging;
|
127
|
-
} else if (this.hovering(this.imagesContainer)) {
|
128
|
-
images = [];
|
129
|
-
if (dragging === primary) {
|
130
|
-
primary = null;
|
131
|
-
}
|
132
|
-
this.state.images.filter(r => r !== dragging).forEach(r => {
|
133
|
-
if (this.hovering(r) && images.indexOf(dragging) === -1) {
|
134
|
-
images.push(dragging);
|
135
|
-
}
|
136
|
-
images.push(r);
|
137
|
-
});
|
138
|
-
if (images.indexOf(dragging) === -1) {
|
139
|
-
images.push(dragging);
|
140
|
-
}
|
141
|
-
} else {
|
142
|
-
if (dragging === primary) {
|
143
|
-
primary = null;
|
144
|
-
}
|
145
|
-
images = this.state.images.filter(r => r !== dragging);
|
146
|
-
if (this.state.y < this.imagesContainer.current.getBoundingClientRect().top) {
|
147
|
-
images = [dragging, ...images];
|
148
|
-
} else {
|
149
|
-
images.push(dragging);
|
150
|
-
}
|
151
|
-
}
|
152
|
-
}
|
153
|
-
return { primary: primary, images: images };
|
154
|
-
}
|
155
|
-
|
156
|
-
renderImage(record, primary) {
|
157
|
-
let dragging = this.state.dragging;
|
158
|
-
if (record === "Files") {
|
159
|
-
return (
|
160
|
-
<div className="grid-image" key="file-placeholder">
|
161
|
-
<div className="file-placeholder" />
|
162
|
-
</div>
|
163
|
-
);
|
164
|
-
}
|
165
|
-
|
166
|
-
let onUpdate = (image, src) => {
|
167
|
-
this.updateImage(record, { image: image, src: src });
|
168
|
-
};
|
169
|
-
|
170
|
-
return (
|
171
|
-
<GridImage key={record.handle}
|
172
|
-
record={record}
|
173
|
-
locale={this.props.locale}
|
174
|
-
locales={this.props.locales}
|
175
|
-
csrf_token={this.props.csrf_token}
|
176
|
-
showEmbed={this.props.showEmbed}
|
177
|
-
startDrag={this.startDrag}
|
178
|
-
position={this.index(record) + 1}
|
179
|
-
primary={primary}
|
180
|
-
onUpdate={onUpdate}
|
181
|
-
enablePrimary={this.props.enablePrimary}
|
182
|
-
deleteImage={this.deleteImage}
|
183
|
-
attributeName={this.attributeName(record)}
|
184
|
-
placeholder={dragging && dragging == record} />
|
185
|
-
);
|
186
|
-
}
|
187
|
-
|
188
|
-
render() {
|
189
|
-
let { dragging, deleted } = this.state;
|
190
|
-
let { primary, images } = this.getDraggedOrder();
|
191
|
-
return (
|
192
|
-
<div className="image-grid"
|
193
|
-
ref={this.container}
|
194
|
-
onDragOver={this.drag}
|
195
|
-
onDrop={this.dragEnd}>
|
196
|
-
{dragging && this.renderDrag()}
|
197
|
-
{this.props.enablePrimary && (
|
198
|
-
<div className="primary-image" ref={this.primaryContainer}>
|
199
|
-
<h3>
|
200
|
-
Main image
|
201
|
-
</h3>
|
202
|
-
{primary && this.renderImage(primary, true)}
|
203
|
-
{!primary && (
|
204
|
-
<div className="drop-target">
|
205
|
-
<FileUploadButton multiple={true}
|
206
|
-
type="image"
|
207
|
-
multiline={true}
|
208
|
-
callback={this.uploadPrimary} />
|
209
|
-
</div>
|
210
|
-
)}
|
211
|
-
{this.props.primaryAttribute && (
|
212
|
-
<input type="hidden" name={this.props.primaryAttribute}
|
213
|
-
value={(primary && primary.image && primary.image.id) || ""} />
|
214
|
-
)}
|
215
|
-
</div>
|
216
|
-
)}
|
217
|
-
<div className="grid" ref={this.imagesContainer}>
|
218
|
-
<h3>
|
219
|
-
{this.props.enablePrimary ? "More images" : "Images"}
|
220
|
-
</h3>
|
221
|
-
<div className="drop-target">
|
222
|
-
<FileUploadButton multiple={true}
|
223
|
-
type="image"
|
224
|
-
callback={this.uploadAdditional} />
|
225
|
-
</div>
|
226
|
-
<div className="images">
|
227
|
-
{images.map(r => this.renderImage(r, false))}
|
228
|
-
</div>
|
229
|
-
</div>
|
230
|
-
<div className="deleted">
|
231
|
-
{deleted.map(r => this.renderDeletedImage(r))}
|
232
|
-
</div>
|
233
|
-
</div>
|
234
|
-
);
|
235
|
-
}
|
236
|
-
|
237
|
-
renderDeletedImage(record) {
|
238
|
-
let image = record.image;
|
239
|
-
let attrName = this.attributeName(record);
|
240
|
-
return (
|
241
|
-
<span className="deleted-image" key={`deleted-${record.id}`}>
|
242
|
-
<input name={`${attrName}[id]`}
|
243
|
-
type="hidden" value={record.id} />
|
244
|
-
<input name={`${attrName}[image_id]`}
|
245
|
-
type="hidden" value={(image && image.id) || ""} />
|
246
|
-
<input name={`${attrName}[_destroy]`}
|
247
|
-
type="hidden" value={true} />
|
248
|
-
</span>
|
249
|
-
);
|
250
|
-
}
|
251
|
-
|
252
|
-
updateImage(record, attrs) {
|
253
|
-
if (this.state.primary === record) {
|
254
|
-
this.setState({ primary: { ...record, ...attrs } });
|
255
|
-
} else {
|
256
|
-
let images = this.state.images.slice();
|
257
|
-
images[images.indexOf(record)] = { ...record, ...attrs };
|
258
|
-
this.setState({ images: images });
|
259
|
-
}
|
260
|
-
}
|
261
|
-
|
262
|
-
uploadImage(file) {
|
263
|
-
let component = this;
|
264
|
-
var obj = { image: null, file: file, ref: React.createRef(),
|
265
|
-
handle: this.getHandle() };
|
266
|
-
|
267
|
-
let data = new FormData();
|
268
|
-
|
269
|
-
data.append("image[file]", file);
|
270
|
-
this.postFile("/admin/images.json", data, function (json) {
|
271
|
-
if (json.status === "error") {
|
272
|
-
ToastActions.error("Error uploading image: " + json.error.join(" "));
|
273
|
-
component.deleteImage(obj);
|
274
|
-
} else {
|
275
|
-
let preloader = new Image();
|
276
|
-
obj.file = null;
|
277
|
-
obj.image = json;
|
278
|
-
preloader.onload = () => component.setState({});
|
279
|
-
preloader.src = obj.image.thumbnail_url;
|
280
|
-
}
|
281
|
-
});
|
282
|
-
|
283
|
-
return obj;
|
284
|
-
}
|
285
|
-
|
286
|
-
uploadAdditional(files) {
|
287
|
-
this.setState({
|
288
|
-
images: [...this.state.images,
|
289
|
-
...files.map(f => this.uploadImage(f))]
|
290
|
-
});
|
291
|
-
}
|
292
|
-
|
293
|
-
uploadPrimary(files) {
|
294
|
-
let uploadedFiles = files.map(f => this.uploadImage(f));
|
295
|
-
var primary = this.state.primary;
|
296
|
-
var images = this.state.images;
|
297
|
-
if (primary) {
|
298
|
-
images = [primary, ...images];
|
299
|
-
}
|
300
|
-
primary = uploadedFiles[0];
|
301
|
-
if (uploadedFiles.length > 1) {
|
302
|
-
images = [...uploadedFiles.slice(1), ...images];
|
303
|
-
}
|
304
|
-
this.setState({ primary: primary, images: images });
|
305
|
-
}
|
306
|
-
}
|
@@ -1,176 +0,0 @@
|
|
1
|
-
class ImageUploader extends React.Component {
|
2
|
-
constructor(props) {
|
3
|
-
super(props);
|
4
|
-
this.state = { dragover: false,
|
5
|
-
uploading: false,
|
6
|
-
image: props.image,
|
7
|
-
src: props.src };
|
8
|
-
this.receiveFiles = this.receiveFiles.bind(this);
|
9
|
-
this.removeImage = this.removeImage.bind(this);
|
10
|
-
this.dragOver = this.dragOver.bind(this);
|
11
|
-
this.dragLeave = this.dragLeave.bind(this);
|
12
|
-
this.dragEnd = this.dragEnd.bind(this);
|
13
|
-
this.drop = this.drop.bind(this);
|
14
|
-
}
|
15
|
-
|
16
|
-
receiveFiles(files) {
|
17
|
-
if (files.length > 0) {
|
18
|
-
this.uploadImage(files[0]);
|
19
|
-
}
|
20
|
-
}
|
21
|
-
|
22
|
-
clearItems(dt) {
|
23
|
-
if (dt.items) {
|
24
|
-
for (var i = 0; i < dt.items.length; i++) {
|
25
|
-
dt.items.remove(i);
|
26
|
-
}
|
27
|
-
} else {
|
28
|
-
dt.clearData();
|
29
|
-
}
|
30
|
-
}
|
31
|
-
|
32
|
-
dragOver(evt) {
|
33
|
-
evt.preventDefault();
|
34
|
-
this.setState({ dragover: true });
|
35
|
-
}
|
36
|
-
|
37
|
-
dragLeave() {
|
38
|
-
this.setState({ dragover: false });
|
39
|
-
}
|
40
|
-
|
41
|
-
dragEnd(evt) {
|
42
|
-
clearItems(evt.dataTransfer);
|
43
|
-
this.setState({ dragover: false });
|
44
|
-
}
|
45
|
-
|
46
|
-
drop(evt) {
|
47
|
-
let files = this.getFiles(evt.dataTransfer);
|
48
|
-
evt.preventDefault();
|
49
|
-
if (files.length > 0) {
|
50
|
-
this.uploadImage(files[0]);
|
51
|
-
}
|
52
|
-
}
|
53
|
-
|
54
|
-
editableImage() {
|
55
|
-
let image = this.state.image;
|
56
|
-
if (!image) { return; }
|
57
|
-
return (
|
58
|
-
<div className="image">
|
59
|
-
<EditableImage image={image}
|
60
|
-
src={this.state.src}
|
61
|
-
width={this.props.width}
|
62
|
-
caption={this.props.caption}
|
63
|
-
locale={this.props.locale}
|
64
|
-
locales={this.props.locales}
|
65
|
-
csrf_token={this.props.csrf_token} />
|
66
|
-
</div>
|
67
|
-
);
|
68
|
-
}
|
69
|
-
|
70
|
-
getFiles(dt) {
|
71
|
-
var files = [];
|
72
|
-
if (dt.items) {
|
73
|
-
for (var i = 0; i < dt.items.length; i++) {
|
74
|
-
if (dt.items[i].kind == "file") {
|
75
|
-
files.push(dt.items[i].getAsFile());
|
76
|
-
}
|
77
|
-
}
|
78
|
-
} else {
|
79
|
-
for (var i = 0; i < dt.files.length; i++) {
|
80
|
-
files.push(dt.files[i]);
|
81
|
-
}
|
82
|
-
}
|
83
|
-
return files;
|
84
|
-
}
|
85
|
-
|
86
|
-
render() {
|
87
|
-
let image = this.state.image;
|
88
|
-
let id = image ? image.id : "";
|
89
|
-
let classes = ["image-uploader"];
|
90
|
-
if (this.state.uploading) {
|
91
|
-
classes.push("uploading");
|
92
|
-
} else if (this.state.dragover) {
|
93
|
-
classes.push("dragover");
|
94
|
-
}
|
95
|
-
return (
|
96
|
-
<div className={classes.join(" ")}
|
97
|
-
onDragOver={this.dragOver}
|
98
|
-
onDragLeave={this.dragLeave}
|
99
|
-
onDragEnd={this.dragEnd}
|
100
|
-
onDrop={this.drop}>
|
101
|
-
<input type="hidden"
|
102
|
-
name={this.props.attr}
|
103
|
-
value={id} />
|
104
|
-
{this.editableImage()}
|
105
|
-
<div className="ui-wrapper">
|
106
|
-
{this.state.uploading && (
|
107
|
-
<div className="ui">
|
108
|
-
Uploading image...
|
109
|
-
</div>
|
110
|
-
)}
|
111
|
-
{!this.state.uploading && (
|
112
|
-
<div className="ui">
|
113
|
-
<FileUploadButton type="image"
|
114
|
-
multiline={true}
|
115
|
-
callback={this.receiveFiles} />
|
116
|
-
{image && (
|
117
|
-
<a className="delete remove-image"
|
118
|
-
href="#"
|
119
|
-
onClick={this.removeImage}>
|
120
|
-
Remove image
|
121
|
-
</a>
|
122
|
-
)}
|
123
|
-
</div>
|
124
|
-
)}
|
125
|
-
</div>
|
126
|
-
</div>
|
127
|
-
);
|
128
|
-
}
|
129
|
-
|
130
|
-
removeImage(evt) {
|
131
|
-
evt.preventDefault();
|
132
|
-
this.setState({image: null, src: null});
|
133
|
-
}
|
134
|
-
|
135
|
-
uploadImage(file) {
|
136
|
-
let validTypes = ["image/gif",
|
137
|
-
"image/jpeg",
|
138
|
-
"image/pjpeg",
|
139
|
-
"image/png",
|
140
|
-
"image/tiff"];
|
141
|
-
|
142
|
-
if (validTypes.indexOf(file.type) == -1) {
|
143
|
-
alert("Invalid file type, only images in JPEG, PNG or GIF " +
|
144
|
-
"formats are supported");
|
145
|
-
return;
|
146
|
-
}
|
147
|
-
|
148
|
-
let locale = this.props.locale;
|
149
|
-
let locales = this.props.locales ? Object.keys(this.props.locales) : [locale];
|
150
|
-
|
151
|
-
let component = this;
|
152
|
-
let xhr = new XMLHttpRequest();
|
153
|
-
let data = new FormData();
|
154
|
-
this.setState({ image: null, src: null, dragover: false, uploading: true });
|
155
|
-
data.append("image[file]", file);
|
156
|
-
locales.forEach((l) => {
|
157
|
-
data.append(`image[alternative][${l}]`, (this.props.alternative || ""));
|
158
|
-
});
|
159
|
-
xhr.open("POST", "/admin/images.json");
|
160
|
-
xhr.setRequestHeader("X-CSRF-Token", this.props.csrf_token);
|
161
|
-
xhr.addEventListener("load", function (evt) {
|
162
|
-
if (xhr.readyState == 4 && xhr.status == "200") {
|
163
|
-
let response = JSON.parse(xhr.responseText);
|
164
|
-
if (response.status === "error") {
|
165
|
-
ToastActions.error("Error uploading image: " + response.error.join(" "));
|
166
|
-
component.setState({ uploading: false });
|
167
|
-
} else {
|
168
|
-
component.setState({ uploading: false,
|
169
|
-
image: response,
|
170
|
-
src: response.thumbnail_url });
|
171
|
-
}
|
172
|
-
}
|
173
|
-
});
|
174
|
-
xhr.send(data);
|
175
|
-
}
|
176
|
-
}
|
@@ -1,20 +0,0 @@
|
|
1
|
-
var ModalActions = Reflux.createActions([
|
2
|
-
"open",
|
3
|
-
"close"
|
4
|
-
]);
|
5
|
-
|
6
|
-
class ModalStore extends Reflux.Store {
|
7
|
-
constructor() {
|
8
|
-
super();
|
9
|
-
this.state = { component: null };
|
10
|
-
this.listenToMany(ModalActions);
|
11
|
-
}
|
12
|
-
|
13
|
-
onOpen(component) {
|
14
|
-
this.setState({component: component});
|
15
|
-
}
|
16
|
-
|
17
|
-
onClose() {
|
18
|
-
this.setState({component: null});
|
19
|
-
}
|
20
|
-
}
|
@@ -1,64 +0,0 @@
|
|
1
|
-
class RichTextArea extends React.Component {
|
2
|
-
constructor(props) {
|
3
|
-
super(props);
|
4
|
-
this.state = {
|
5
|
-
value: props.value || "",
|
6
|
-
rows: props.rows || 5
|
7
|
-
};
|
8
|
-
this.inputRef = React.createRef();
|
9
|
-
this.handleChange = this.handleChange.bind(this);
|
10
|
-
this.getSelection = this.getSelection.bind(this);
|
11
|
-
this.replaceSelection = this.replaceSelection.bind(this);
|
12
|
-
}
|
13
|
-
|
14
|
-
getSelection() {
|
15
|
-
let { selectionStart,
|
16
|
-
selectionEnd,
|
17
|
-
value } = this.inputRef.current;
|
18
|
-
return value.substr(selectionStart, (selectionEnd - selectionStart));
|
19
|
-
}
|
20
|
-
|
21
|
-
replaceSelection(prefix, replacement, postfix) {
|
22
|
-
let textarea = this.inputRef.current;
|
23
|
-
let { selectionStart, selectionEnd, value } = textarea;
|
24
|
-
|
25
|
-
textarea.value =
|
26
|
-
value.substr(0, selectionStart) +
|
27
|
-
prefix + replacement + postfix +
|
28
|
-
value.substr(selectionEnd, value.length);
|
29
|
-
|
30
|
-
textarea.focus({ preventScroll: true });
|
31
|
-
textarea.setSelectionRange(
|
32
|
-
selectionStart + prefix.length,
|
33
|
-
selectionStart + prefix.length + replacement.length
|
34
|
-
);
|
35
|
-
this.setValue(textarea.value);
|
36
|
-
}
|
37
|
-
|
38
|
-
handleChange(evt) {
|
39
|
-
this.setValue(evt.target.value);
|
40
|
-
}
|
41
|
-
|
42
|
-
render() {
|
43
|
-
let { value, rows } = this.state;
|
44
|
-
let { id, name, simple } = this.props;
|
45
|
-
return (
|
46
|
-
<div className="rich-text-area">
|
47
|
-
<RichTextToolbar simple={simple}
|
48
|
-
getSelection={this.getSelection}
|
49
|
-
replaceSelection={this.replaceSelection} />
|
50
|
-
<textarea className="rich"
|
51
|
-
ref={this.inputRef}
|
52
|
-
id={id}
|
53
|
-
name={name}
|
54
|
-
value={value}
|
55
|
-
rows={rows}
|
56
|
-
onChange={this.handleChange} />
|
57
|
-
</div>
|
58
|
-
);
|
59
|
-
}
|
60
|
-
|
61
|
-
setValue(value) {
|
62
|
-
this.setState({ value: value });
|
63
|
-
}
|
64
|
-
}
|
@@ -1,91 +0,0 @@
|
|
1
|
-
class RichTextToolbar extends React.Component {
|
2
|
-
constructor(props) {
|
3
|
-
super(props);
|
4
|
-
this.link = this.link.bind(this);
|
5
|
-
}
|
6
|
-
|
7
|
-
relativeUrl(str) {
|
8
|
-
let url = null;
|
9
|
-
|
10
|
-
if (!str.match(/^https:\/\//) || !document || !document.location) {
|
11
|
-
return str;
|
12
|
-
}
|
13
|
-
|
14
|
-
try {
|
15
|
-
url = new URL(str);
|
16
|
-
} catch (error) {
|
17
|
-
console.log("Error parsing URL: ", error);
|
18
|
-
}
|
19
|
-
|
20
|
-
if (url &&
|
21
|
-
url.hostname == document.location.hostname &&
|
22
|
-
(document.location.port || "80") == (url.port || "80")) {
|
23
|
-
return url.pathname;
|
24
|
-
}
|
25
|
-
return str;
|
26
|
-
}
|
27
|
-
|
28
|
-
link(selection) {
|
29
|
-
let name = selection.length > 0 ? selection : "Link text";
|
30
|
-
var url = prompt("Enter link URL", "");
|
31
|
-
if (url) {
|
32
|
-
return ["\"", name, `":${this.relativeUrl(url)}`];
|
33
|
-
} else {
|
34
|
-
return ["", name, ""];
|
35
|
-
}
|
36
|
-
}
|
37
|
-
|
38
|
-
emailLink(selection) {
|
39
|
-
var address = prompt("Enter email address", "");
|
40
|
-
let name = selection.length > 0 ? selection : address;
|
41
|
-
return ["\"", name, `":mailto:${address}`];
|
42
|
-
}
|
43
|
-
|
44
|
-
strToList(str, prefix) {
|
45
|
-
return str.split("\n").map(l => prefix + " " + l).join("\n");
|
46
|
-
}
|
47
|
-
|
48
|
-
button(name, className, handler) {
|
49
|
-
let clickHandler = (evt) => {
|
50
|
-
evt.preventDefault();
|
51
|
-
let [prefix, replacement, postfix] = handler(this.props.getSelection());
|
52
|
-
this.props.replaceSelection(prefix, replacement, postfix);
|
53
|
-
};
|
54
|
-
|
55
|
-
return (
|
56
|
-
<a title={name}
|
57
|
-
className={"button " + className}
|
58
|
-
onClick={clickHandler}>
|
59
|
-
<i className={"fa fa-" + className} />
|
60
|
-
</a>
|
61
|
-
);
|
62
|
-
}
|
63
|
-
|
64
|
-
render() {
|
65
|
-
if (this.props.simple) {
|
66
|
-
return (
|
67
|
-
<div className="rich-text toolbar">
|
68
|
-
{this.button("Bold", "bold", (str) => ["<b>", str, "</b>"])}
|
69
|
-
{this.button("Italics", "italic", (str) => ["<i>", str, "</i>"])}
|
70
|
-
</div>
|
71
|
-
);
|
72
|
-
} else {
|
73
|
-
return (
|
74
|
-
<div className="rich-text toolbar">
|
75
|
-
{this.button("Bold", "bold", (str) => ["<b>", str, "</b>"])}
|
76
|
-
{this.button("Italics", "italic", (str) => ["<i>", str, "</i>"])}
|
77
|
-
{this.button("Heading 2", "header h2", (str) => ["h2. ", str, ""])}
|
78
|
-
{this.button("Heading 3", "header h3", (str) => ["h3. ", str, ""])}
|
79
|
-
{this.button("Heading 4", "header h4", (str) => ["h4. ", str, ""])}
|
80
|
-
{this.button("Blockquote", "quote-left", (str) => ["bq. ", str, ""])}
|
81
|
-
{this.button("List", "list-ul",
|
82
|
-
(str) => ["", this.strToList(str, "*"), ""])}
|
83
|
-
{this.button("Ordered list", "list-ol",
|
84
|
-
(str) => ["", this.strToList(str, "#"), ""])}
|
85
|
-
{this.button("Link", "link", this.link)}
|
86
|
-
{this.button("Email link", "envelope", this.emailLink)}
|
87
|
-
</div>
|
88
|
-
);
|
89
|
-
}
|
90
|
-
}
|
91
|
-
}
|
@@ -1,34 +0,0 @@
|
|
1
|
-
class Toast extends Reflux.Component {
|
2
|
-
constructor(props) {
|
3
|
-
super(props);
|
4
|
-
this.store = ToastStore;
|
5
|
-
}
|
6
|
-
|
7
|
-
componentDidMount() {
|
8
|
-
if (this.props.notice) {
|
9
|
-
ToastActions.notice(this.props.notice);
|
10
|
-
}
|
11
|
-
}
|
12
|
-
|
13
|
-
render() {
|
14
|
-
let toast = this.state.current;
|
15
|
-
let classNames = ["toast"];
|
16
|
-
|
17
|
-
if (toast) {
|
18
|
-
classNames.push(toast.type);
|
19
|
-
if (this.state.fadeout) {
|
20
|
-
classNames.push("fadeout");
|
21
|
-
}
|
22
|
-
}
|
23
|
-
|
24
|
-
return (
|
25
|
-
<div className="toast-wrapper">
|
26
|
-
{toast && (
|
27
|
-
<div className={classNames.join(" ")}>
|
28
|
-
{toast.message}
|
29
|
-
</div>
|
30
|
-
)}
|
31
|
-
</div>
|
32
|
-
);
|
33
|
-
}
|
34
|
-
}
|