easy_modal_window 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +51 -2
- data/app/views/easy_modal_window/base_dialog.js.erb +9 -2
- data/lib/easy_modal_window/version.rb +1 -1
- data/lib/easy_modal_window.rb +7 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0f1edecbf457f9ac4ab4003d9f14cf68ff03180
|
4
|
+
data.tar.gz: 4669f37fba2c805592af32f9caeaaf2e2305b876
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b88551d6a2fed1f6b6dae6e7645b69a0fc6832c0af9a0d0f9f1c1c54ce88277147e29c9087d0f724aa60283481d023f2c690dc273e63f3eb0ba2403010b6cca3
|
7
|
+
data.tar.gz: 0bfb336f4c4d37054101dd486d24df8312f1f9cdbf8b7f749eccca02a2307ef5bdcf337c81421b7b1c9cd7c868428e570457e58219b58a286beb9fb58d44e11c
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ This is wrapper for jQuery-UI Dialog. Additionaly it contain several templates f
|
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
gem 'easy_modal_window'
|
9
|
+
gem 'easy_modal_window'
|
10
10
|
|
11
11
|
And then execute:
|
12
12
|
|
@@ -18,7 +18,56 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
Gem provide several helpers for easy render jQuery-UI dialog and list with ActiveRecord errors.
|
22
|
+
|
23
|
+
### jQuery-UI dialog
|
24
|
+
|
25
|
+
Helper `render_base_dialog`. It take parameters like a `dialog`, but in more easy way and with less required parameters.
|
26
|
+
|
27
|
+
render_base_dialog(
|
28
|
+
render_template: 'example_template',
|
29
|
+
resizable: false,
|
30
|
+
height: 'auto',
|
31
|
+
width: 'auto',
|
32
|
+
before_close: {
|
33
|
+
condition: true,
|
34
|
+
action: 'return true;'
|
35
|
+
},
|
36
|
+
buttons: {
|
37
|
+
load_button: {
|
38
|
+
name: l(:load_button),
|
39
|
+
action: "$('#modal-window-ajax-form').submit();"
|
40
|
+
},
|
41
|
+
close_button: {
|
42
|
+
name: l(:close_button),
|
43
|
+
action: "$(this).dialog('close');"
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
Here we can skip any parameters except `render_template`.
|
48
|
+
|
49
|
+
**NOTE:** by default modal window puts in `#ajax-modal` element; you can specify other selector in `window_selector` option.
|
50
|
+
|
51
|
+
### ActiveRecord errors
|
52
|
+
|
53
|
+
Helper `render_active_record_result` provide easy way to render list with several AR errors.
|
54
|
+
|
55
|
+
render_active_record_result(object: object,
|
56
|
+
success_message: l(:success_message))
|
57
|
+
|
58
|
+
If `object.errors.blank?` you see value of `success_message`.
|
59
|
+
|
60
|
+
### ErrorsContainer errors
|
61
|
+
|
62
|
+
Helper `render_errors_container_result` provide easy way to render nested lists with messages from [ErrorsContainer](https://github.com/Loriowar/error_messages_container).
|
63
|
+
|
64
|
+
render_errors_container_result(object: object,
|
65
|
+
success_message: l(:success_message),
|
66
|
+
container_class: 'upper-ul-class', # class for upper ul element
|
67
|
+
element_class: 'first-li-class', # class for li elements which contain group name
|
68
|
+
errors_group_class: 'div-in-li-class') # class for div with errors group name
|
69
|
+
|
70
|
+
CSS-class parameters are optional.
|
22
71
|
|
23
72
|
## Contributing
|
24
73
|
|
@@ -2,8 +2,15 @@
|
|
2
2
|
|
3
3
|
var $modalWindow = $('<%= modal_options.window_selector %>');
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
<% render_options = {formats: modal_options.formats,
|
6
|
+
locals: modal_options.locals} %>
|
7
|
+
|
8
|
+
<% if modal_options.render_template.present? %>
|
9
|
+
$modalWindow.html("<%= j render render_options.merge(template: modal_options.render_template) %>");
|
10
|
+
<% elsif modal_options.render_partial.present? %>
|
11
|
+
$modalWindow.html("<%= j render render_options.merge(partial: modal_options.render_partial) %>");
|
12
|
+
<% end %>
|
13
|
+
|
7
14
|
var $titleElement = $modalWindow.find('<%= modal_options.title_selector %>');
|
8
15
|
var title = $titleElement.text();
|
9
16
|
$titleElement.hide();
|
data/lib/easy_modal_window.rb
CHANGED
@@ -6,15 +6,17 @@ module EasyModalWindow
|
|
6
6
|
|
7
7
|
attr_reader :modal_options
|
8
8
|
|
9
|
-
|
10
|
-
:resizable, :height, :width, :buttons, :before_close, :success_message,
|
9
|
+
ALLOWED_OPTIONS = [:window_selector, :title_selector, :render_template, :render_partial, :formats,
|
10
|
+
:locals, :resizable, :height, :width, :buttons, :before_close, :success_message,
|
11
11
|
:object, :container_class, :element_class, :errors_group_class].freeze
|
12
12
|
|
13
13
|
def initialize(args)
|
14
14
|
@modal_options = {}
|
15
15
|
@modal_options[:window_selector] = '#ajax-modal'
|
16
16
|
@modal_options[:title_selector] = 'h3.title'
|
17
|
-
@modal_options[:render_template] =
|
17
|
+
@modal_options[:render_template] = nil
|
18
|
+
@modal_options[:render_partial] = nil
|
19
|
+
@modal_options[:locals] = {}
|
18
20
|
@modal_options[:formats] = [:html]
|
19
21
|
@modal_options[:resizable] = true
|
20
22
|
@modal_options[:height] = 'auto'
|
@@ -35,10 +37,10 @@ module EasyModalWindow
|
|
35
37
|
@modal_options[:element_class] = ''
|
36
38
|
@modal_options[:errors_group_class] = ''
|
37
39
|
|
38
|
-
@modal_options.merge!(args.slice(*EasyModalWindow::Dialog::
|
40
|
+
@modal_options.merge!(args.slice(*EasyModalWindow::Dialog::ALLOWED_OPTIONS))
|
39
41
|
end
|
40
42
|
|
41
|
-
(
|
43
|
+
(ALLOWED_OPTIONS - [:before_close, :buttons]).each do |method|
|
42
44
|
class_eval <<-EOT, __FILE__, __LINE__ + 1
|
43
45
|
def #{method}
|
44
46
|
@modal_options[:#{method}]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_modal_window
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Zabrovskiy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|