cm-admin 1.5.45 → 1.5.46
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/.yardopts +4 -0
- data/Gemfile.lock +1 -1
- data/docs/ListingSelectTwoAjax.md +100 -0
- data/docs/ListingSelectTwoItems.md +71 -0
- data/docs/ShowHideContent.md +70 -0
- data/lib/cm_admin/models/filter.rb +1 -1
- data/lib/cm_admin/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 378d66935a7066199a4eeadb51b8b7a585c8e4dd0babec1ecb19638657fa3f22
|
4
|
+
data.tar.gz: 847b3efed1840bdca5a69778f009a80be5fa4a66c0c19d88ed5a214f79f71c25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2826196f546388631dd501f71efd8c2ab2ba82e28c156ae7689c9b8334f53e51a7e50379cfbb9ca168ff2beb7c23da4b2a8b6e18a63745021a2b68f823cc7734
|
7
|
+
data.tar.gz: 657210656f5b832832fb26603768220fd4e09def454c969c41dff0025546ef1ac03d2efce531698205412327db965446e5a2b33eb1f8e683d20f4dd8a63deeaa
|
data/.yardopts
CHANGED
data/Gemfile.lock
CHANGED
@@ -0,0 +1,100 @@
|
|
1
|
+
# Lisiting of Select Two using Ajax 🅰️
|
2
|
+
|
3
|
+
## Method 1: Using Ajax URL for Form Field
|
4
|
+
|
5
|
+
This method demonstrates how to create a form field with a single select input that uses an Ajax URL to fetch data.
|
6
|
+
|
7
|
+
### Adding Ajax URL Parameter
|
8
|
+
|
9
|
+
The below form field creates a single select input for optional languages. It uses an Ajax URL to fetch the language options dynamically.
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
form_field :optional_language_id, input_type: :single_select, label: 'Optional Language', ajax_url: :fetch_optional_language
|
13
|
+
```
|
14
|
+
|
15
|
+
|
16
|
+
### Custom Action for Fetching Data
|
17
|
+
|
18
|
+
This custom action retrieves data from the database and returns it as a JSON response. Example below, is specifically designed to fetch optional language data based on a search parameter.
|
19
|
+
|
20
|
+
**Location**: Define this custom action in the index section of your configuration.
|
21
|
+
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
custom_action name: 'fetch_optional_language', route_type: :collection, verb: 'get', path: '/fetch_optional_languages',
|
25
|
+
display_type: :route do
|
26
|
+
@optional_language = ::Constant.search_constant_by_name(params[:search],"optional_language")
|
27
|
+
{
|
28
|
+
results: @optional_language.map { |language| { id: language.id, text: language.name.titleize } },
|
29
|
+
pagination: { more: false }
|
30
|
+
}
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
This custom action is used to fetch optional languages based on a search parameter. It returns a JSON response with the language results and pagination information.
|
35
|
+
|
36
|
+
## Method 2: Using HTML Attributes and JavaScript for Form Field
|
37
|
+
|
38
|
+
This method shows how to create a form field with custom HTML attributes and use JavaScript to implement the select functionality.
|
39
|
+
|
40
|
+
### Adding Custom HTML Attributes
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
form_field :optional_language_id, input_type: :single_select, label: 'Optional Language', html_attrs: { 'data-behaviour': 'optional_language-select' }
|
44
|
+
```
|
45
|
+
|
46
|
+
This form field creates a single select input for optional languages with a custom data attribute for JavaScript targeting.
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
### Custom Action for Fetching Data
|
51
|
+
|
52
|
+
This custom action retrieves data from the database and returns it as a JSON response. Example below, is specifically designed to fetch optional language data based on a search parameter.
|
53
|
+
|
54
|
+
**Location**: Define this custom action in the index section of your configuration.
|
55
|
+
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
custom_action name: 'fetch_optional_language', route_type: :collection, verb: 'get', path: '/fetch_optional_languages',
|
59
|
+
display_type: :route do
|
60
|
+
@optional_language = ::Constant.search_constant(params[:search], params[:class],"optional_language")
|
61
|
+
{
|
62
|
+
results: @optional_language.map { |language| { id: language.id, text: language.name.titleize } },
|
63
|
+
pagination: { more: false }
|
64
|
+
}
|
65
|
+
end
|
66
|
+
```
|
67
|
+
|
68
|
+
### JavaScript Function for Select2 Implementation
|
69
|
+
|
70
|
+
This JavaScript function initializes a Select2 dropdown for the optional language select field. It configures Ajax loading of options, result processing, and pagination. We can also pass additional parameters to the server using the `data` attribute.
|
71
|
+
|
72
|
+
**Location**: Define this JavaScript function in your application's JavaScript file.
|
73
|
+
|
74
|
+
```javascript
|
75
|
+
function selectTwoAjaxCaller(){
|
76
|
+
const $event = $('select[data-behaviour="optional_language-select"]');
|
77
|
+
$event.select2({
|
78
|
+
theme: "bootstrap-5",
|
79
|
+
ajax: {
|
80
|
+
url: "fetch_optional_languages",
|
81
|
+
dataType: 'json',
|
82
|
+
delay: 250,
|
83
|
+
data: function (params) {
|
84
|
+
return {
|
85
|
+
search: params.term,
|
86
|
+
class: 12
|
87
|
+
};
|
88
|
+
},
|
89
|
+
processResults: function (data, params) {
|
90
|
+
return {
|
91
|
+
results: data.results
|
92
|
+
};
|
93
|
+
},
|
94
|
+
},
|
95
|
+
minimumInputLength: 0,
|
96
|
+
});
|
97
|
+
}
|
98
|
+
```
|
99
|
+
|
100
|
+
This JavaScript function initializes a Select2 dropdown for the optional language select field. It configures Ajax loading of options, result processing, and pagination.
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# Population of items in drop-downs 🔽
|
2
|
+
|
3
|
+
This document provides details on various methods used in our project. Each method is explained with its purpose and usage examples.
|
4
|
+
|
5
|
+
## Method 1: Using Collection / Helper Method for Transport Type
|
6
|
+
|
7
|
+
The example below demonstrates how to create a section with a single-select field using collection.
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
cm_section 'Mode Of Transport' do
|
11
|
+
form_field :transport_type_id, input_type: :single_select,
|
12
|
+
collection: :mode_of_transport
|
13
|
+
end
|
14
|
+
```
|
15
|
+
|
16
|
+
💡Note: You need to set mode_transport array like this:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
mode_of_transport = [['Vehicle','vehicle'],['Bike', 'bike']]
|
20
|
+
```
|
21
|
+
|
22
|
+
Or you can use a helper method to fetch the data:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
cm_section 'Mode Of Transport' do
|
26
|
+
form_field :transport_type_id, input_type: :single_select,
|
27
|
+
helper_method: :mode_of_transport_method
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
💡Note: This should be defined in the helper module:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
def mode_of_transport_method
|
35
|
+
Constant.where(type:"transport_type").all.map { |item| [item.full_name, item.id] }
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
## Method 2: Custom Action for Transport Type
|
40
|
+
|
41
|
+
The example below demonstrates how to create a section with a single-select field using a custom action.
|
42
|
+
|
43
|
+
This custom action is designed to fetch transport type data from the database and automatically populate the dropdown with the appropriate values when triggered.
|
44
|
+
|
45
|
+
💡 Note: The retrieved data is used to populate the target_value field.
|
46
|
+
|
47
|
+
**Location**: This custom action should be defined in the index section of your configuration.
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
custom_action name: 'transport_type', route_type: :collection, verb: 'get', path: '/transport_type', display_type: :route do
|
51
|
+
transport_type = Constant.where(type: :transport_type).all.map { |item| [item.full_name, item.id] }
|
52
|
+
{
|
53
|
+
fields: [
|
54
|
+
{
|
55
|
+
target_type: :select,
|
56
|
+
target_value: {
|
57
|
+
table: 'student',
|
58
|
+
field_name: 'transport_type_id',
|
59
|
+
field_value: transport_type
|
60
|
+
}
|
61
|
+
}
|
62
|
+
]
|
63
|
+
}
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
67
|
+
💡Note: This needs to be added as a trigger variable for populating the fields:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
form_field :route_id, input_type: :single_select, target: { action_name: :fetch_transport_type }
|
71
|
+
```
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# Hide or Show Section and Fields 🦹
|
2
|
+
|
3
|
+
This module provides methods for hiding form sections and fields with HTML attributes.
|
4
|
+
|
5
|
+
## Method 1: Using HTML Attributes and JavaScript for Form Section
|
6
|
+
|
7
|
+
### Adding Custom HTML Attributes
|
8
|
+
|
9
|
+
Define the html_attrs attribute in a section / field to add custom HTML attributes.
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
cm_section 'Private Van', html_attrs: { "data-behaviour": "private_van-section"} do
|
13
|
+
form_field :transport_vehicle_number, input_type: :string, label: 'Vehicle Number'
|
14
|
+
form_field :transport_vehicle_in_charge, input_type: :string, label: 'Vehicle In Charge'
|
15
|
+
form_field :transport_vehicle_in_charge_phone, input_type: :integer, label: 'Vehicle In Charge Phone'
|
16
|
+
end
|
17
|
+
```
|
18
|
+
|
19
|
+
The below JavaScript code manages the visibility of the "Private Van" section based on a condition.
|
20
|
+
|
21
|
+
**Location**: Define this JavaScript function in your application's JavaScript file.
|
22
|
+
|
23
|
+
```javascript
|
24
|
+
$(document).on("turbo:load", function() {
|
25
|
+
$(document).on('change', 'select[data-behaviour="transport_type-select"]', handleTransportTypeChange);
|
26
|
+
});
|
27
|
+
|
28
|
+
function handleTransportTypeChange(event) {
|
29
|
+
// Get the section element by its data attribute
|
30
|
+
var section = $('div[data-behaviour="private_van-section"]');
|
31
|
+
|
32
|
+
// Get the selected value
|
33
|
+
var selectedValue = $(event.target).val();
|
34
|
+
|
35
|
+
// Toggle the visibility based on the condition
|
36
|
+
if (selectedValue !== "private_van") {
|
37
|
+
section.addClass('hidden');
|
38
|
+
} else {
|
39
|
+
section.removeClass('hidden');
|
40
|
+
}
|
41
|
+
}
|
42
|
+
```
|
43
|
+
|
44
|
+
## Method 2: Using `display_if` Attribute for Form Section
|
45
|
+
|
46
|
+
### Adding `display_if` Attribute for Form Section
|
47
|
+
|
48
|
+
Define the `display_if` attribute in a section to conditionally display the section based on a condition.
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
cm_section 'Private Van', display_if:->(trip){trip.transport_type== "private_van" } do
|
52
|
+
form_field :transport_vehicle_number, input_type: :string, label: 'Vehicle Number'
|
53
|
+
form_field :transport_vehicle_in_charge, input_type: :string, label: 'Vehicle In Charge'
|
54
|
+
form_field :transport_vehicle_in_charge_phone, input_type: :integer, label: 'Vehicle In Charge Phone'
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
### Adding `display_if` Attribute for Form Field
|
59
|
+
|
60
|
+
Define the `display_if` attribute in a field to conditionally display the field based on a condition.
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
form_field :transport_vehicle_number, input_type: :single_select,collection: :mode_of_transport, display_if:->(trip){
|
64
|
+
trip.transport_type=="private_van" }
|
65
|
+
```
|
66
|
+
|
67
|
+
You can also use the `display_if` attribute in any field to conditionally display the field based on a condition.
|
68
|
+
|
69
|
+
|
70
|
+
💡Note: The `display_if` attribute is used to conditionally display the section based on the value of `trip.transport_type`. It doesn't updated in real time like the JavaScript method.
|
data/lib/cm_admin/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cm-admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.46
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael
|
@@ -14,7 +14,7 @@ authors:
|
|
14
14
|
autorequire:
|
15
15
|
bindir: exe
|
16
16
|
cert_chain: []
|
17
|
-
date: 2024-08-
|
17
|
+
date: 2024-08-26 00:00:00.000000000 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: caxlsx_rails
|
@@ -418,6 +418,9 @@ files:
|
|
418
418
|
- config/webpack/production.js
|
419
419
|
- config/webpack/test.js
|
420
420
|
- config/webpacker.yml
|
421
|
+
- docs/ListingSelectTwoAjax.md
|
422
|
+
- docs/ListingSelectTwoItems.md
|
423
|
+
- docs/ShowHideContent.md
|
421
424
|
- lib/.DS_Store
|
422
425
|
- lib/cm-admin.rb
|
423
426
|
- lib/cm_admin.rb
|