binda 0.1.5 → 0.1.6
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.
- checksums.yaml +4 -4
- data/README.md +42 -26
- data/Rakefile +4 -0
- data/app/assets/javascripts/binda/application.js +3 -0
- data/app/assets/javascripts/binda/components/field_setting_choices.js +5 -5
- data/app/assets/javascripts/binda/components/fileupload.js +1 -1
- data/app/assets/javascripts/binda/components/form_item_collapsable.js +245 -0
- data/app/assets/javascripts/binda/components/form_item_image.js +1 -1
- data/app/assets/javascripts/binda/components/login-shader.js +1 -1
- data/app/assets/javascripts/binda/components/login_form.js +1 -1
- data/app/assets/javascripts/binda/components/sortable.js +21 -30
- data/app/assets/javascripts/binda/dist/binda.bundle.js +299 -377
- data/app/assets/javascripts/binda/index.js +9 -17
- data/app/assets/stylesheets/binda/components/field_setting_choices.scss +5 -3
- data/app/assets/stylesheets/binda/components/form_item.scss +23 -70
- data/app/assets/stylesheets/binda/components/standard-form.scss +56 -1
- data/app/assets/stylesheets/binda/settings/tiny_mce_overrides.scss +8 -0
- data/app/controllers/binda/application_controller.rb +6 -0
- data/app/controllers/binda/boards_controller.rb +18 -12
- data/app/controllers/binda/components_controller.rb +21 -16
- data/app/controllers/binda/field_groups_controller.rb +57 -16
- data/app/controllers/binda/field_settings_controller.rb +14 -2
- data/app/controllers/binda/repeaters_controller.rb +2 -2
- data/app/controllers/binda/structures_controller.rb +32 -16
- data/app/controllers/concerns/binda/fieldable_helpers.rb +2 -2
- data/app/helpers/binda/components_helper.rb +16 -4
- data/app/helpers/binda/field_groups_helper.rb +4 -1
- data/app/models/binda/asset.rb +1 -3
- data/app/models/binda/component.rb +17 -10
- data/app/models/binda/date.rb +2 -6
- data/app/models/binda/field_group.rb +7 -5
- data/app/models/binda/field_setting.rb +69 -8
- data/app/models/binda/gallery.rb +2 -3
- data/app/models/binda/image.rb +7 -1
- data/app/models/binda/relation.rb +2 -5
- data/app/models/binda/repeater.rb +10 -14
- data/app/models/binda/selection.rb +3 -3
- data/app/models/binda/structure.rb +9 -5
- data/app/models/binda/text.rb +2 -6
- data/app/models/binda/user.rb +10 -0
- data/app/models/concerns/binda/field_uniqueness.rb +31 -0
- data/app/models/concerns/binda/fieldable_association_helpers.rb +31 -11
- data/app/models/concerns/binda/fieldable_associations.rb +2 -3
- data/app/models/concerns/binda/fields.rb +21 -0
- data/app/views/binda/boards/edit.html.erb +2 -1
- data/app/views/binda/components/edit.html.erb +2 -1
- data/app/views/binda/field_groups/_form_body.html.erb +4 -42
- data/app/views/binda/field_groups/_form_header.html.erb +11 -0
- data/app/views/binda/field_groups/_form_item.html.erb +4 -6
- data/app/views/binda/field_groups/_form_new_item.html.erb +8 -0
- data/app/views/binda/field_groups/_form_section.html.erb +17 -27
- data/app/views/binda/field_groups/_form_section_repeater.html.erb +17 -18
- data/app/views/binda/field_groups/_form_sidebar.html.erb +13 -0
- data/app/views/binda/field_groups/form_item/_form_item_editor.html.erb +9 -5
- data/app/views/binda/field_groups/form_item/{_form_item_persisted_editor.html.erb → _form_item_editor_existing_item.html.erb} +1 -4
- data/app/views/binda/field_groups/form_item/_form_item_editor_new_item.html.erb +3 -0
- data/app/views/binda/field_groups/form_item/_form_item_header.html.erb +23 -24
- data/app/views/binda/field_groups/form_section/_form_section_header.html.erb +45 -0
- data/app/views/binda/field_groups/form_section/_form_section_list.html.erb +9 -0
- data/app/views/binda/fieldable/_form_body.html.erb +6 -1
- data/app/views/binda/fieldable/_form_item_date.html.erb +1 -1
- data/app/views/binda/fieldable/_form_item_image.html.erb +1 -1
- data/app/views/binda/fieldable/_form_item_new_repeater.html.erb +7 -21
- data/app/views/binda/fieldable/_form_item_relation.html.erb +7 -7
- data/app/views/binda/fieldable/_form_item_repeater.html.erb +9 -99
- data/app/views/binda/fieldable/_form_item_selections.html.erb +1 -1
- data/app/views/binda/fieldable/_form_item_string.html.erb +5 -12
- data/app/views/binda/fieldable/_form_item_text.html.erb +5 -13
- data/app/views/binda/fieldable/_form_item_video.html.erb +1 -1
- data/app/views/binda/fieldable/_form_section.html.erb +11 -10
- data/app/views/binda/fieldable/_form_section_repeater.html.erb +2 -3
- data/app/views/binda/fieldable/form_item_repeater/_form_item_repeater_header.html.erb +32 -0
- data/app/views/binda/fieldable/form_item_repeater/_form_item_repeater_list.html.erb +19 -0
- data/app/views/binda/fieldable/form_item_repeater/_form_item_repeater_list_item.html.erb +42 -0
- data/app/views/binda/structures/_form_field_group_item.html.erb +5 -0
- data/app/views/binda/structures/_form_new_field_group_item.html.erb +8 -0
- data/app/views/binda/structures/_form_section.html.erb +16 -78
- data/app/views/binda/structures/_form_sidebar.html.erb +9 -8
- data/app/views/binda/structures/form_field_group_item/_form_field_group_item_editor.html.erb +18 -0
- data/app/views/binda/structures/form_field_group_item/_form_field_group_item_field_setting_form.html.erb +12 -0
- data/app/views/binda/structures/form_field_group_item/_form_field_group_item_field_settings.html.erb +18 -0
- data/app/views/binda/structures/form_field_group_item/_form_field_group_item_header.html.erb +29 -0
- data/app/views/binda/structures/form_section/_form_section_header.html.erb +26 -0
- data/app/views/binda/structures/form_section/_form_section_list.html.erb +8 -0
- data/config/initializers/simple_form__fileupload.rb +3 -4
- data/config/locales/en.yml +9 -4
- data/config/routes.rb +4 -0
- data/lib/binda/version.rb +1 -1
- data/lib/generators/binda/install/install_generator.rb +17 -6
- data/lib/generators/binda/maintenance/maintenance_generator.rb +12 -8
- data/lib/generators/binda/setup/setup_generator.rb +23 -27
- data/lib/tasks/create_missing_field_instances_task.rake +10 -0
- data/lib/tasks/remove_orphan_fields_task.rake +1 -7
- data/lib/tasks/user_tasks.rake +1 -7
- data/vendor/assets/javascripts/lodash.js +17097 -0
- metadata +39 -7
- data/app/assets/javascripts/binda/components/form_item.js +0 -113
- data/app/assets/javascripts/binda/components/form_item_editor.js +0 -39
- data/app/assets/javascripts/binda/components/form_item_repeater.js +0 -127
- data/app/views/binda/field_groups/form_item/_form_item_new_editor.html.erb +0 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 380a6ee6ba0e7fad66075ccd4f6d35f79b7946d3
|
|
4
|
+
data.tar.gz: 04d50e53a323cff2202b6ea28fc422eed13d625c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 668e07be1cf3f3c424b79d48c0dbd17698a6f7919870dd0121b8efde2cb9e327f01517f4b5702284dfb31f6fc8960bcef1f4e160be96bd832d046f86199d6f52
|
|
7
|
+
data.tar.gz: c5d557f08401dd999c81162bc7cad8f375b75f079d0ff22c75d824ca6e9840de555d51e0a58661ab6415435919f1dbde3dcb072aaa74e651e9bf0bd877632904
|
data/README.md
CHANGED
|
@@ -3,7 +3,6 @@ A modular CMS for Ruby on Rails 5.1.
|
|
|
3
3
|
|
|
4
4
|
[](https://badge.fury.io/rb/binda)
|
|
5
5
|
[](https://codeclimate.com/github/lacolonia/binda)
|
|
6
|
-
[](https://travis-ci.org/lacolonia/binda)
|
|
7
6
|
[](https://codeclimate.com/github/lacolonia/binda/test_coverage)
|
|
8
7
|
[](https://gemnasium.com/github.com/lacolonia/binda)
|
|
9
8
|
[](http://inch-ci.org/github/lacolonia/binda)
|
|
@@ -430,30 +429,30 @@ You can retrieve field content from a instance of `Binda::Component`, `Binda::Bo
|
|
|
430
429
|
|
|
431
430
|
| Helper |||
|
|
432
431
|
|---|---|---|
|
|
433
|
-
| `has_text`| Returns `true/false` | [source](http://www.rubydoc.info/gems/binda/Binda/
|
|
434
|
-
| `get_text`| Returns the text. Use [`simple_format`](https://apidock.com/rails/ActionView/Helpers/TextHelper/simple_format) to maintain HTML tags. | [source](http://www.rubydoc.info/gems/binda/Binda/
|
|
435
|
-
| `has_string`| Returns `true/false`. | [source](http://www.rubydoc.info/gems/binda/Binda/
|
|
436
|
-
| `get_string`| Returns the text. Use [`simple_format`](https://apidock.com/rails/ActionView/Helpers/TextHelper/simple_format) to maintain HTML tags. | [source](http://www.rubydoc.info/gems/binda/Binda/
|
|
437
|
-
|`has_image`| Returns `true/false`.| [source](http://www.rubydoc.info/gems/binda/Binda/
|
|
438
|
-
|`get_image_url(size)`| Returns the url of the image. A thumbnail version (200x200) by specifying `thumb` size. If no size is provided the method will return the original image size. | [source](http://www.rubydoc.info/gems/binda/Binda/
|
|
439
|
-
|`get_image_path(size)`| Returns the path of the image. A thumbnail version (200x200) by specifying `thumb` size. If no size is provided the method will return the original image size. | [source](http://www.rubydoc.info/gems/binda/Binda/
|
|
440
|
-
|`get_image_size`| Returns the image size in MB. | [source](http://www.rubydoc.info/gems/binda/Binda/
|
|
441
|
-
|`get_image_dimension`| Returns a hash { width: xxx, height: xxx } with image dimension. | [source](http://www.rubydoc.info/gems/binda/Binda/
|
|
442
|
-
|`get_image_mime_type`| Returns the mime type of the image. | [source](http://www.rubydoc.info/gems/binda/Binda/
|
|
443
|
-
|`has_video`| Returns `true/false`.| [source](http://www.rubydoc.info/gems/binda/Binda/
|
|
444
|
-
|`get_video_url`| Returns the url of the video. | [source](http://www.rubydoc.info/gems/binda/Binda/
|
|
445
|
-
|`get_video_path`| Returns the path of the video. | [source](http://www.rubydoc.info/gems/binda/Binda/
|
|
446
|
-
|`has_date`| Returns `true/false` | [source](http://www.rubydoc.info/gems/binda/Binda/
|
|
447
|
-
|`get_date`| Returns the date in `datetime` format. Use [`strftime`](https://apidock.com/rails/ActiveSupport/TimeWithZone/strftime) to change date format. | [source](http://www.rubydoc.info/gems/binda/Binda/
|
|
448
|
-
|`has_repeaters`| Returns `true/false`| [source](http://www.rubydoc.info/gems/binda/Binda/
|
|
449
|
-
|`get_repeaters`| Returns an array of repeaters. See next session for more details. | [source](http://www.rubydoc.info/gems/binda/Binda/
|
|
450
|
-
|`get_selection_choices`| Returns an hash with label and value of the selected choice. | [source](http://www.rubydoc.info/gems/binda/Binda/
|
|
451
|
-
|`get_radio_choice`| Returns an hash with label and value of the selected choice. | [source](http://www.rubydoc.info/gems/binda/Binda/
|
|
452
|
-
|`get_checkbox_choices`| Returns an array of label/value pairs of all the selected choices. | [source](http://www.rubydoc.info/gems/binda/Binda/
|
|
453
|
-
|`has_related_components`| Check if has related components. | [source](http://www.rubydoc.info/gems/binda/Binda/
|
|
454
|
-
|`get_related_components`| Retrieve related components. | [source](http://www.rubydoc.info/gems/binda/Binda/
|
|
455
|
-
|`has_related_boards`| Check if has related boards. | [source](http://www.rubydoc.info/gems/binda/Binda/
|
|
456
|
-
|`get_related_boards`| Retrieve related boards. | [source](http://www.rubydoc.info/gems/binda/Binda/
|
|
432
|
+
| `has_text`| Returns `true/false` | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:has_text) |
|
|
433
|
+
| `get_text`| Returns the text. Use [`simple_format`](https://apidock.com/rails/ActionView/Helpers/TextHelper/simple_format) to maintain HTML tags. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_text) |
|
|
434
|
+
| `has_string`| Returns `true/false`. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:has_string) |
|
|
435
|
+
| `get_string`| Returns the text. Use [`simple_format`](https://apidock.com/rails/ActionView/Helpers/TextHelper/simple_format) to maintain HTML tags. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_string) |
|
|
436
|
+
|`has_image`| Returns `true/false`.| [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:has_image) |
|
|
437
|
+
|`get_image_url(size)`| Returns the url of the image. A thumbnail version (200x200) by specifying `thumb` size. If no size is provided the method will return the original image size. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_image_url) |
|
|
438
|
+
|`get_image_path(size)`| Returns the path of the image. A thumbnail version (200x200) by specifying `thumb` size. If no size is provided the method will return the original image size. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_image_path) |
|
|
439
|
+
|`get_image_size`| Returns the image size in MB. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_image_size) |
|
|
440
|
+
|`get_image_dimension`| Returns a hash { width: xxx, height: xxx } with image dimension. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_image_dimension) |
|
|
441
|
+
|`get_image_mime_type`| Returns the mime type of the image. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_image_mime_type) |
|
|
442
|
+
|`has_video`| Returns `true/false`.| [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:has_video) |
|
|
443
|
+
|`get_video_url`| Returns the url of the video. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_video_url) |
|
|
444
|
+
|`get_video_path`| Returns the path of the video. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_image_path) |
|
|
445
|
+
|`has_date`| Returns `true/false` | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:has_date) |
|
|
446
|
+
|`get_date`| Returns the date in `datetime` format. Use [`strftime`](https://apidock.com/rails/ActiveSupport/TimeWithZone/strftime) to change date format. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_date) |
|
|
447
|
+
|`has_repeaters`| Returns `true/false`| [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:has_repeaters) |
|
|
448
|
+
|`get_repeaters`| Returns an array of repeaters. See next session for more details. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_repeaters) |
|
|
449
|
+
|`get_selection_choices`| Returns an hash with label and value of the selected choice. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_selection_choices) |
|
|
450
|
+
|`get_radio_choice`| Returns an hash with label and value of the selected choice. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_radio_choice) |
|
|
451
|
+
|`get_checkbox_choices`| Returns an array of label/value pairs of all the selected choices. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:get_checkbox_choices) |
|
|
452
|
+
|`has_related_components`| Check if has related components. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:has_related_components) |
|
|
453
|
+
|`get_related_components`| Retrieve related components. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:has_related_components) |
|
|
454
|
+
|`has_related_boards`| Check if has related boards. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:has_related_boards) |
|
|
455
|
+
|`get_related_boards`| Retrieve related boards. | [source](http://www.rubydoc.info/gems/binda/Binda/FieldableAssociationHelpers:has_related_boards) |
|
|
457
456
|
|
|
458
457
|
If you need to get each dependent of all relations with a specified slug (or slugs) you can use `B.get_relation_dependents` helper. This is very useful to retrieve only the instances which have a owner (and therefore are 'dependents').
|
|
459
458
|
|
|
@@ -934,9 +933,26 @@ Same thing can be done on linux usign another binary code (see [documentation](h
|
|
|
934
933
|
|
|
935
934
|
|
|
936
935
|
|
|
936
|
+
# Binda versioning
|
|
937
|
+
|
|
938
|
+
It's possible to test edge versions of Binda on real projects. Edge versions can be found only in the github repository and can be referenced by tag.
|
|
939
|
+
|
|
940
|
+
For example once `v0.1.0` is published any new edge release which can be considered stable enough for a real project is tagged with alpha or beta (`v0.1.1.alpha`, `v0.1.1.alpha.1`, `v0.1.1.beta`, etc). These tags won't change and won't be removed so you can safely add them to you gemfile like so:
|
|
941
|
+
|
|
942
|
+
```ruby
|
|
943
|
+
gem 'binda', github: 'lacolonia/binda', ref: 'v0.1.1.alpha.1'
|
|
944
|
+
```
|
|
945
|
+
|
|
946
|
+
The same tag is listed as the gem version, but it's not published to Rubygems.
|
|
947
|
+
|
|
948
|
+
More info can be found at the [semantic versioning documentation](https://semver.org/spec/v2.0.0-rc.1.html).
|
|
949
|
+
---
|
|
950
|
+
|
|
951
|
+
|
|
952
|
+
|
|
937
953
|
### Bug reporting
|
|
938
954
|
Please refer to this [guide](http://yourbugreportneedsmore.info).
|
|
939
|
-
If you need direct help you can join [Binda Slack
|
|
955
|
+
If you need direct help you can join [Binda Slack Channel](https://bindacms.slack.com).
|
|
940
956
|
|
|
941
957
|
|
|
942
958
|
### License
|
data/Rakefile
CHANGED
|
@@ -14,6 +14,10 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
|
14
14
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
+
# https://www.viget.com/articles/rails-engine-testing-with-rspec-capybara-and-factorygirl/
|
|
18
|
+
# Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
|
|
19
|
+
# require 'rspec/core'
|
|
20
|
+
|
|
17
21
|
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
|
18
22
|
load 'rails/tasks/engine.rake'
|
|
19
23
|
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
* FORM ITEM CHOICE
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { resizeCollapsableStacks } from "./form_item_collapsable";
|
|
6
6
|
|
|
7
7
|
class FieldSettingChoices {
|
|
8
8
|
constructor() {
|
|
9
9
|
this.target = ".field-setting-choices--choice";
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
isPresent() {
|
|
13
13
|
if ($(this.target).length > 0) {
|
|
14
14
|
return true;
|
|
15
15
|
} else {
|
|
@@ -39,7 +39,7 @@ class FieldSettingChoices {
|
|
|
39
39
|
.closest(".field-setting-choices--choice")
|
|
40
40
|
.remove();
|
|
41
41
|
// Update form item editor size
|
|
42
|
-
|
|
42
|
+
resizeCollapsableStacks();
|
|
43
43
|
}
|
|
44
44
|
);
|
|
45
45
|
}
|
|
@@ -65,7 +65,7 @@ function addChoice(event) {
|
|
|
65
65
|
// Append the clone right after
|
|
66
66
|
choices.prepend(clone);
|
|
67
67
|
// Update form item editor size
|
|
68
|
-
|
|
68
|
+
resizeCollapsableStacks();
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
function deleteChoice(event) {
|
|
@@ -81,7 +81,7 @@ function deleteChoice(event) {
|
|
|
81
81
|
}).done(function() {
|
|
82
82
|
choice.remove();
|
|
83
83
|
// Update form item editor size
|
|
84
|
-
|
|
84
|
+
resizeCollapsableStacks();
|
|
85
85
|
}).fail(function(data){
|
|
86
86
|
alert(data.responseJSON.errors);
|
|
87
87
|
});
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FORM ITEM
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { setupSelect2 } from "./select2";
|
|
6
|
+
|
|
7
|
+
// Component Global Variables
|
|
8
|
+
let newFormItemId = 1;
|
|
9
|
+
|
|
10
|
+
class FormItemCollapsable {
|
|
11
|
+
constructor() {}
|
|
12
|
+
|
|
13
|
+
isPresent() {
|
|
14
|
+
if ($(".form--list").length > 0) {
|
|
15
|
+
return true;
|
|
16
|
+
} else {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
setEvents() {
|
|
22
|
+
$(document).on("click", ".form--add-list-item", addNewItem);
|
|
23
|
+
$(document).on("click", ".form--delete-list-item", deleteItem);
|
|
24
|
+
$(document).on("click", ".form-item--collapse-btn", collapseToggle);
|
|
25
|
+
$(window).resize(resizeCollapsableStacks);
|
|
26
|
+
// Make sure all collapsable items are resized already at every page load
|
|
27
|
+
resizeCollapsableStacks();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export let _FormItemCollapsable = new FormItemCollapsable();
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* COMPONENT HELPER FUNCTIONS
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Adds a new item.
|
|
39
|
+
*
|
|
40
|
+
* @param {event} event The event
|
|
41
|
+
*/
|
|
42
|
+
function addNewItem(event) {
|
|
43
|
+
// Stop default behaviour
|
|
44
|
+
event.preventDefault();
|
|
45
|
+
// Get the child to clone
|
|
46
|
+
let id = $(this).data("id");
|
|
47
|
+
let $list = $("#form--list-" + id);
|
|
48
|
+
let url = $(this).data("url");
|
|
49
|
+
let data = $list.sortable("serialize");
|
|
50
|
+
let params = $(this).data("params");
|
|
51
|
+
if (params) {
|
|
52
|
+
data = data.concat(`&${params}`);
|
|
53
|
+
}
|
|
54
|
+
$.ajax({
|
|
55
|
+
url: url,
|
|
56
|
+
data: data,
|
|
57
|
+
method: "POST"
|
|
58
|
+
}).done(function(data) {
|
|
59
|
+
// Get repaeter code from Rails
|
|
60
|
+
// Due to the Rails way of creating nested forms it's necessary to
|
|
61
|
+
// create the nested item inside a different new form, then get just
|
|
62
|
+
// the code contained between the two SPLIT comments
|
|
63
|
+
let parts = data.split("<!-- SPLIT -->");
|
|
64
|
+
let newItem = parts[1];
|
|
65
|
+
setupAndAppend(newItem, $list);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Setup and append new item
|
|
71
|
+
*
|
|
72
|
+
* @param {string} newItem The new item
|
|
73
|
+
* @param {object} $list The list
|
|
74
|
+
*/
|
|
75
|
+
function setupAndAppend(newItem, $list) {
|
|
76
|
+
// Append the item
|
|
77
|
+
$list.prepend(newItem);
|
|
78
|
+
let collapsable = $list.find(".form-item--collapsable").get(0);
|
|
79
|
+
|
|
80
|
+
// Update select input for Select2 plugin
|
|
81
|
+
setupSelect2($list.find("select"));
|
|
82
|
+
|
|
83
|
+
setupTinyMCE($list.find("textarea"));
|
|
84
|
+
|
|
85
|
+
// Prepare collapsable animation
|
|
86
|
+
collapsable.style.maxHeight = "0px";
|
|
87
|
+
|
|
88
|
+
// Prepare collapsable stack animation
|
|
89
|
+
openCollapsableStacks(collapsable);
|
|
90
|
+
|
|
91
|
+
// Refresh Sortable to update the added item with Sortable features
|
|
92
|
+
$list.sortable("refresh");
|
|
93
|
+
|
|
94
|
+
// Run animation 500ms after previous style declaration (see above) otherwise animation doesn't get triggered
|
|
95
|
+
setTimeout(function() {
|
|
96
|
+
collapsable.style.maxHeight = collapsable.scrollHeight + "px";
|
|
97
|
+
}, 50);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Close collapsable stacks
|
|
102
|
+
*
|
|
103
|
+
* It closes all collapsable stacks inside the collapsable item passed as argument
|
|
104
|
+
*
|
|
105
|
+
* @param {object, string} target The target
|
|
106
|
+
*/
|
|
107
|
+
export function closeCollapsableStacks(obj) {
|
|
108
|
+
$(obj)
|
|
109
|
+
.addClass("form-item--collapsed")
|
|
110
|
+
.find(".form-item--collapsable-stack")
|
|
111
|
+
.each(function() {
|
|
112
|
+
this.style.maxHeight = "0px";
|
|
113
|
+
this.style.pointerEvents = "none";
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Open collapsable stacks
|
|
119
|
+
*
|
|
120
|
+
* It opens all collapsable stacks inside the collapsable item passed as argument
|
|
121
|
+
*
|
|
122
|
+
* @param {object, string} target The target
|
|
123
|
+
*/
|
|
124
|
+
export function openCollapsableStacks(obj) {
|
|
125
|
+
// Don't execute this if sortable is enabled
|
|
126
|
+
if (
|
|
127
|
+
$(obj)
|
|
128
|
+
.closest(".sortable")
|
|
129
|
+
.hasClass("sortable--enabled")
|
|
130
|
+
) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
$(obj)
|
|
134
|
+
.removeClass("form-item--collapsed")
|
|
135
|
+
.find(".form-item--collapsable-stack")
|
|
136
|
+
.each(function() {
|
|
137
|
+
this.style.maxHeight = this.scrollHeight + "px";
|
|
138
|
+
this.style.pointerEvents = "auto";
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Toggle a collapsable item
|
|
144
|
+
*
|
|
145
|
+
* Basically it opens it or closes it based on its state
|
|
146
|
+
*
|
|
147
|
+
* @param {event} event The event
|
|
148
|
+
*/
|
|
149
|
+
function collapseToggle(event) {
|
|
150
|
+
// Stop default behaviour
|
|
151
|
+
event.preventDefault();
|
|
152
|
+
let $collapsable = $(this).closest(".form-item--collapsable");
|
|
153
|
+
if ($collapsable.hasClass("form-item--collapsed")) {
|
|
154
|
+
$collapsable.each(function() {
|
|
155
|
+
openCollapsableStacks(this);
|
|
156
|
+
});
|
|
157
|
+
} else {
|
|
158
|
+
$collapsable.each(function() {
|
|
159
|
+
closeCollapsableStacks(this);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Delete collapsable item and hide it
|
|
166
|
+
*
|
|
167
|
+
* @param {event} event The event
|
|
168
|
+
*/
|
|
169
|
+
function deleteItem(event) {
|
|
170
|
+
// Stop default behaviour
|
|
171
|
+
event.preventDefault();
|
|
172
|
+
let record_id = $(this).data("id");
|
|
173
|
+
let targetId = `#form--list-item-${record_id}`;
|
|
174
|
+
let target = $(targetId).get(0);
|
|
175
|
+
// As max-height isn't set you need to set it manually before changing it,
|
|
176
|
+
// otherwise the animation doesn't get triggered
|
|
177
|
+
target.style.maxHeight = target.scrollHeight + "px";
|
|
178
|
+
// Change max-height after 50ms to trigger css animation
|
|
179
|
+
setTimeout(function() {
|
|
180
|
+
target.style.maxHeight = "0px";
|
|
181
|
+
target.style.pointerEvents = "none";
|
|
182
|
+
}, 50);
|
|
183
|
+
$.ajax({
|
|
184
|
+
url: $(this).attr("href"),
|
|
185
|
+
data: { id: record_id, target_id: targetId, isAjax: true },
|
|
186
|
+
method: "DELETE"
|
|
187
|
+
}).done(function(data) {
|
|
188
|
+
// Make sure the animation completes before removing the item (it should last 600ms + 50ms)
|
|
189
|
+
setTimeout(function() {
|
|
190
|
+
$(data.target_id).remove();
|
|
191
|
+
}, 700);
|
|
192
|
+
});
|
|
193
|
+
// TODO add a fallback if request fails
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Resize all collapsable item
|
|
198
|
+
*
|
|
199
|
+
* If a target is passed as a argument the function will resize only that target and its children.
|
|
200
|
+
*
|
|
201
|
+
* @param {object, string} target The target.
|
|
202
|
+
*/
|
|
203
|
+
export function resizeCollapsableStacks(target) {
|
|
204
|
+
target = _.isUndefined(target) ? document.getElementsByClassName("form-item--collapsable-stack") : target;
|
|
205
|
+
// target CANNOT BE a jquery object because it leads to the following error
|
|
206
|
+
// TypeError: undefined is not an object (evaluating 't.ownerDocument.defaultView')
|
|
207
|
+
$(target).each(function() {
|
|
208
|
+
// If the collapsable item is closed don't go any further
|
|
209
|
+
if (
|
|
210
|
+
$(this).height() === 0 ||
|
|
211
|
+
$(this)
|
|
212
|
+
.closest(".form-item--collapsable")
|
|
213
|
+
.hasClass("form-item--collapsed")
|
|
214
|
+
) {
|
|
215
|
+
this.style.maxHeight = "0px";
|
|
216
|
+
this.style.pointerEvents = "none";
|
|
217
|
+
} else {
|
|
218
|
+
// otherwise update the max-height which is needed for the CSS transition
|
|
219
|
+
// NOTE you need to remove the max-height (inside 'style' attribute) to get the real height
|
|
220
|
+
this.style.height = "auto";
|
|
221
|
+
this.style.maxHeight = this.scrollHeight + "px";
|
|
222
|
+
this.style.pointerEvents = "auto";
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Setup TinyMCE
|
|
229
|
+
*
|
|
230
|
+
* @param {jQuery object} $textareas The textareas
|
|
231
|
+
*/
|
|
232
|
+
function setupTinyMCE($textareas) {
|
|
233
|
+
let editor_ids = _.map(tinyMCE.editors, editor => {
|
|
234
|
+
return editor.id;
|
|
235
|
+
})
|
|
236
|
+
// console.log({editors});
|
|
237
|
+
$textareas.each(function() {
|
|
238
|
+
if (_.includes(editor_ids, this.getAttribute('id'))){
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
tinyMCE.init({
|
|
242
|
+
selector: `#${this.getAttribute("id")}`
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
}
|