simple_form_bs5_file_input 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/LICENSE +1 -1
- data/README.md +11 -0
- data/assets/javascripts/simple_form_bs5_file_input.js +13 -2
- data/assets/stylesheets/simple_form_bs5_file_input.sass +2 -0
- data/config/locales/en.yml +1 -0
- data/config/locales/fr.yml +1 -0
- data/lib/has_one_attached_deletable.rb +8 -4
- data/lib/simple_form_bs5_file_input/single_deletable_file_input.rb +12 -3
- data/lib/simple_form_bs5_file_input/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3e8fedf5f192642394251e54de774c6eee4a3d0bd8aaf1743fe5764fdd08894
|
4
|
+
data.tar.gz: bcf4c4237b630ea3eda4c0aaa469e5f555c85c1003e5580272df34d77460989d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f72252369cf36f53ac1f5380e3140aff36e0bcc11bef09ab2f2bfc3442916d2eb48e307ecc148ca8e186fea587120009326137e8980f666b3c35a79fb8535ae8
|
7
|
+
data.tar.gz: f83dd485981568672cde5863750ef4623df3e5d729f9dc4af9a1b7c06fba4ce84187cae5481c003341a727f57b41f9e4ab9fe8fce55cd89a59db68b60085a257
|
data/Gemfile.lock
CHANGED
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -139,6 +139,17 @@ end
|
|
139
139
|
|
140
140
|
**Simple Form Bootstrap 5 File Input** uses the I18n API to manage the texts displayed. Feel free to overwrite the keys or add languages.
|
141
141
|
|
142
|
+
## Notes
|
143
|
+
|
144
|
+
### Callbacks
|
145
|
+
|
146
|
+
When the resize feature is activated **Simple Form Bootstrap 5 File Input** uses an `after_commit` hook to resize the image. The model linked to the attachment will then be touched.
|
147
|
+
It might cause a problem because messing with others `after_commit` hooks. For example it messes with the Devise `confirmable` module, where the confirmation email is also send on after_commit.
|
148
|
+
Before Rails 7.1 after_commit is the only hook executed backward. So if you add after_commit :function1, then after_commit :function2, function2 will be executed BEFORE function1.
|
149
|
+
After Rails 7.1 after_commit follows the regular order, so function1 will be executed before function2.
|
150
|
+
So for Devise Confirmable, it must be declared AFTER the `has_one_attached_deletable` declaration if Rails version < 7.1, and declared BEFORE the `has_one_attached_deletable` declaration if Rails version >= 7.1
|
151
|
+
|
152
|
+
|
142
153
|
## Information
|
143
154
|
|
144
155
|
### Supported Ruby / Rails versions
|
@@ -49,6 +49,7 @@ window.inputSingleDeletableFile = {
|
|
49
49
|
};
|
50
50
|
} else {
|
51
51
|
// Previewable images
|
52
|
+
$('.js-sdfi-deletable-file__infos-field', $scope).val('');
|
52
53
|
$scope.addClass('sdfi-deletable-file--with-file');
|
53
54
|
$('.js-sdfi-deletable-file__label', $scope).html(file.name);
|
54
55
|
$('.js-sdfi-deletable-file__delete-field', $scope).val('');
|
@@ -60,6 +61,7 @@ window.inputSingleDeletableFile = {
|
|
60
61
|
}
|
61
62
|
} else {
|
62
63
|
// Non-resizable and non-previewable files
|
64
|
+
$('.js-sdfi-deletable-file__infos-field', $scope).val('');
|
63
65
|
$scope.addClass('sdfi-deletable-file--with-file');
|
64
66
|
$('.js-sdfi-deletable-file__label', $scope).html(file.name);
|
65
67
|
$('.js-sdfi-deletable-file__delete-field', $scope).val('');
|
@@ -76,7 +78,7 @@ window.inputSingleDeletableFile = {
|
|
76
78
|
image = $modal.attr('data-image-result'),
|
77
79
|
ratio = $imgContainer.attr('data-ratio');
|
78
80
|
|
79
|
-
$imgContainer.html('<img class="js-" src="' + image + '">');
|
81
|
+
$imgContainer.html('<img class="js-image" src="' + image + '">');
|
80
82
|
|
81
83
|
$image = $('img', $imgContainer);
|
82
84
|
$image.css('opacity', 0);
|
@@ -98,6 +100,14 @@ window.inputSingleDeletableFile = {
|
|
98
100
|
}, 100);
|
99
101
|
},
|
100
102
|
|
103
|
+
onResizeModalRotate: function (e) {
|
104
|
+
'use strict';
|
105
|
+
var $scope = $(e.target).parents('.js-sdfi-deletable-file'),
|
106
|
+
$imgContainer = $('.js-sdfi-sdfi-deletable-file__resize-image', $scope),
|
107
|
+
$image = $('.js-image', $imgContainer);
|
108
|
+
$image.cropper('rotate', 90);
|
109
|
+
},
|
110
|
+
|
101
111
|
onResizeModalCancel: function (e) {
|
102
112
|
'use strict';
|
103
113
|
var $scope = $(e.target).parents('.js-sdfi-deletable-file');
|
@@ -145,8 +155,9 @@ window.inputSingleDeletableFile = {
|
|
145
155
|
});
|
146
156
|
$('.js-sdfi-deletable-file__delete-btn', $(field)).on('click', this.onFileDelete);
|
147
157
|
$('input[type="file"]', $(field)).on('change', this.onFileSelected);
|
148
|
-
|
158
|
+
|
149
159
|
$('.js-sdfi-deletable-file__resize', field).on('shown.bs.modal', this.onResizeModalShown);
|
160
|
+
$('.js-sdfi-deletable-file__resize-rotate', field).on('click', this.onResizeModalRotate);
|
150
161
|
$('.js-sdfi-deletable-file__resize-cancel', field).on('click', this.onResizeModalCancel);
|
151
162
|
$('.js-sdfi-deletable-file__resize-validate', field).on('click', this.onResizeModalValidate);
|
152
163
|
}
|
data/config/locales/en.yml
CHANGED
data/config/locales/fr.yml
CHANGED
@@ -21,12 +21,16 @@ class ActiveRecord::Base
|
|
21
21
|
|
22
22
|
# From Rails 6, ImageProcessing uses an 'auto-orient' by default to interpret the EXIF Orientation metadata.
|
23
23
|
# We declare it in the transformations hash for Rails 5
|
24
|
-
transformations = {
|
25
|
-
|
26
|
-
|
24
|
+
transformations = { :'auto-orient' => true }
|
25
|
+
# Handle rotation
|
26
|
+
transformations[:rotate] = params['rotate'] if params['rotate'].present?
|
27
|
+
# Handle cropping
|
28
|
+
transformations[:crop] = "#{params['width'].round}x#{params['height'].round}+#{params['x'].round}+#{params['y'].round}"
|
29
|
+
# Finalize by repaging
|
30
|
+
transformations.merge!({
|
27
31
|
repage: true,
|
28
32
|
:'+' => true
|
29
|
-
}
|
33
|
+
})
|
30
34
|
|
31
35
|
variant = Rails::VERSION::MAJOR >= 6 ? send(name).variant(**transformations)
|
32
36
|
: send(name).variant(combine_options: transformations)
|
@@ -92,12 +92,17 @@ class SingleDeletableFileInput < SimpleForm::Inputs::Base
|
|
92
92
|
</div>
|
93
93
|
</div>
|
94
94
|
<div class="modal-footer">
|
95
|
-
<button type="button" class="btn btn-sm
|
96
|
-
<
|
95
|
+
<button type="button" class="btn btn-sm js-sdfi-deletable-file__resize-rotate" aria-label="%s">
|
96
|
+
<i class="bi bi-arrow-clockwise"></i>
|
97
|
+
</button>
|
98
|
+
<div>
|
99
|
+
<button type="button" class="btn btn-sm btn-secondary js-sdfi-deletable-file__resize-cancel" data-bs-dismiss="modal">%s</button>
|
100
|
+
<button type="button" class="btn btn-sm btn-primary js-sdfi-deletable-file__resize-validate">%s</button>
|
101
|
+
</div>
|
97
102
|
</div>
|
98
103
|
</div>
|
99
104
|
</div>
|
100
|
-
</div>', modal_title, close_btn_text, resize_ratio, close_btn_text, validate_btn_text)
|
105
|
+
</div>', modal_title, close_btn_text, resize_ratio, rotate_btn_text, close_btn_text, validate_btn_text)
|
101
106
|
end
|
102
107
|
end
|
103
108
|
|
@@ -141,6 +146,10 @@ class SingleDeletableFileInput < SimpleForm::Inputs::Base
|
|
141
146
|
I18n.t('simple_form_bs5_file_input.modal_close')
|
142
147
|
end
|
143
148
|
|
149
|
+
def rotate_btn_text
|
150
|
+
I18n.t('simple_form_bs5_file_input.modal_rotate')
|
151
|
+
end
|
152
|
+
|
144
153
|
def validate_btn_text
|
145
154
|
I18n.t('simple_form_bs5_file_input.modal_validate')
|
146
155
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_form_bs5_file_input
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pierre-andré Boissinot
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -94,7 +94,7 @@ homepage: https://github.com/noesya/simple_form_bs5_file_input
|
|
94
94
|
licenses:
|
95
95
|
- MIT
|
96
96
|
metadata: {}
|
97
|
-
post_install_message:
|
97
|
+
post_install_message:
|
98
98
|
rdoc_options: []
|
99
99
|
require_paths:
|
100
100
|
- lib
|
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
112
|
rubygems_version: 3.1.4
|
113
|
-
signing_key:
|
113
|
+
signing_key:
|
114
114
|
specification_version: 4
|
115
115
|
summary: Simple Form BS5 File Input
|
116
116
|
test_files: []
|