modal_logic 0.0.1 → 0.0.2
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 +8 -8
- data/README.md +21 -1
- data/app/assets/javascripts/modal_logic.coffee +12 -29
- data/app/assets/javascripts/modal_logic.js +15 -24
- data/app/assets/javascripts/templates/modal/crud.hbs +12 -0
- data/lib/modal_logic/helpers.rb +10 -10
- data/lib/modal_logic/version.rb +1 -1
- metadata +16 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NjRhZWYxMTUwZjM4ZmIxYWFiYzljNWEwNjk3MDVjYzZjMzEzNDhkNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDgyYjBhZjdlOTRjZjJiOWNlZDM4ZTQzNmFlYTBjMTNjMjI0NzhlNQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MWQ0MmIzZTRkMTJmMDNlZTVkYTljNDUzZjVlYWVmNDZkMTNmNjA3NjVhZTIy
|
10
|
+
ZmQ4OWEwMmE3YjcyNjg0NjdmNmIzOGMxMDRjNjFkMjg0ODcyZjYxYjIyYjFj
|
11
|
+
MzZmMWMwMzg2MzdiMGNhY2MwZWEwNDMwMTBhMTU2NDExM2YyZjc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YzllZDEwMTZkN2VmNTI2OGU2M2RkMzk3MThjOGVkZjA5MGNmMmM1N2QwZDM1
|
14
|
+
N2EzZWEzOWI0YzJlMjVhMWFhNWEyZmZhZDU0NzVhZTkwMzczNjFiM2Q4YWI1
|
15
|
+
ODk3ZGEyODlhY2M3NzkyZGFlNDY3NjJkYTkwMTkxOTQzNzRjMmU=
|
data/README.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
1
|
= ModalLogic
|
2
2
|
|
3
|
-
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
===Install
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
# Gemfile
|
10
|
+
|
11
|
+
gem 'modal_logic'
|
12
|
+
|
13
|
+
group :assets do
|
14
|
+
gem 'handlebars_assets'
|
15
|
+
end
|
16
|
+
```
|
17
|
+
|
18
|
+
```javascript
|
19
|
+
/* app/assets/javascripts/application.js */
|
20
|
+
//= require modal_logic
|
21
|
+
//= require handlebars.runtime
|
22
|
+
//= require templates/modal/crud
|
23
|
+
```
|
@@ -3,42 +3,25 @@ class ModalLogic
|
|
3
3
|
that = @
|
4
4
|
$('a[data-remote][modal],form[data-remote][modal]').live 'ajax:complete', (jq_event, xhr) ->
|
5
5
|
response = JSON.parse(xhr.responseText)
|
6
|
-
if response
|
7
|
-
if response.
|
8
|
-
window.location = response.redirect_location
|
6
|
+
if response?
|
7
|
+
if response.close?
|
8
|
+
window.location = if response.redirect_location? then response.redirect_location else window.location
|
9
9
|
else
|
10
|
-
|
11
|
-
else
|
10
|
+
that.createOrUpdateModalContent(response)
|
11
|
+
else
|
12
12
|
that.createOrUpdateModalContent
|
13
13
|
title: 'Error'
|
14
|
-
|
15
|
-
|
16
|
-
that.createOrUpdateModalContent(response)
|
14
|
+
body: 'There was an error. Please reload the page and try again'
|
15
|
+
|
17
16
|
createOrUpdateModalContent: (context) =>
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
body: context.html
|
23
|
-
$('body').append html
|
17
|
+
html = HandlebarsTemplates['modal/crud']( modal: context )
|
18
|
+
$modal = $('.modal.modal-logic')
|
19
|
+
if $modal.length > 0
|
20
|
+
$modal.modal('hide').replaceWith html
|
24
21
|
else
|
25
|
-
|
26
|
-
modal.find('.modal-header > .modal-title').empty().append context.title
|
27
|
-
|
22
|
+
$('body').append html
|
28
23
|
@showModal()
|
29
24
|
|
30
25
|
showModal: =>
|
31
26
|
$('.modal.modal-logic').modal('show')
|
32
27
|
|
33
|
-
renderTemplate: (context) =>
|
34
|
-
"""
|
35
|
-
<div class="modal modal-logic hide fade">
|
36
|
-
<div class="modal-header">
|
37
|
-
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
38
|
-
<h3 class='modal-title'>#{context.title}</h3>
|
39
|
-
</div>
|
40
|
-
<div class="modal-body">
|
41
|
-
#{context.body}
|
42
|
-
</div>
|
43
|
-
</div>
|
44
|
-
"""
|
@@ -4,7 +4,6 @@ var ModalLogic,
|
|
4
4
|
|
5
5
|
ModalLogic = (function() {
|
6
6
|
function ModalLogic() {
|
7
|
-
this.renderTemplate = __bind(this.renderTemplate, this);
|
8
7
|
this.showModal = __bind(this.showModal, this);
|
9
8
|
this.createOrUpdateModalContent = __bind(this.createOrUpdateModalContent, this);
|
10
9
|
var that;
|
@@ -14,36 +13,32 @@ ModalLogic = (function() {
|
|
14
13
|
var response;
|
15
14
|
|
16
15
|
response = JSON.parse(xhr.responseText);
|
17
|
-
if (response
|
18
|
-
if (response.
|
19
|
-
return window.location = response.redirect_location;
|
16
|
+
if (response != null) {
|
17
|
+
if (response.close != null) {
|
18
|
+
return window.location = response.redirect_location != null ? response.redirect_location : window.location;
|
20
19
|
} else {
|
21
|
-
return
|
20
|
+
return that.createOrUpdateModalContent(response);
|
22
21
|
}
|
23
|
-
} else
|
22
|
+
} else {
|
24
23
|
return that.createOrUpdateModalContent({
|
25
24
|
title: 'Error',
|
26
|
-
|
25
|
+
body: 'There was an error. Please reload the page and try again'
|
27
26
|
});
|
28
|
-
} else {
|
29
|
-
return that.createOrUpdateModalContent(response);
|
30
27
|
}
|
31
28
|
});
|
32
29
|
}
|
33
30
|
|
34
31
|
ModalLogic.prototype.createOrUpdateModalContent = function(context) {
|
35
|
-
var
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
$('body').append(html);
|
32
|
+
var $modal, html;
|
33
|
+
|
34
|
+
html = HandlebarsTemplates['modal/crud']({
|
35
|
+
modal: context
|
36
|
+
});
|
37
|
+
$modal = $('.modal.modal-logic');
|
38
|
+
if ($modal.length > 0) {
|
39
|
+
$modal.modal('hide').replaceWith(html);
|
44
40
|
} else {
|
45
|
-
|
46
|
-
modal.find('.modal-header > .modal-title').empty().append(context.title);
|
41
|
+
$('body').append(html);
|
47
42
|
}
|
48
43
|
return this.showModal();
|
49
44
|
};
|
@@ -52,10 +47,6 @@ ModalLogic = (function() {
|
|
52
47
|
return $('.modal.modal-logic').modal('show');
|
53
48
|
};
|
54
49
|
|
55
|
-
ModalLogic.prototype.renderTemplate = function(context) {
|
56
|
-
return "<div class=\"modal modal-logic hide fade\">\n <div class=\"modal-header\">\n <button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-hidden=\"true\">×</button>\n <h3 class='modal-title'>" + context.title + "</h3>\n </div>\n <div class=\"modal-body\">\n " + context.body + "\n </div>\n</div>";
|
57
|
-
};
|
58
|
-
|
59
50
|
return ModalLogic;
|
60
51
|
|
61
52
|
})();
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<div class="modal modal-logic hide">
|
2
|
+
<div class="modal-header">
|
3
|
+
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
4
|
+
<h3 class='modal-title'>{{modal.title}}</h3>
|
5
|
+
</div>
|
6
|
+
<div class="modal-body">
|
7
|
+
{{#if modal.errors.base}}
|
8
|
+
<div class='alert alert-error'>{{{modal.errors.base}}}</div>
|
9
|
+
{{/if}}
|
10
|
+
{{{modal.body}}}
|
11
|
+
</div>
|
12
|
+
</div>
|
data/lib/modal_logic/helpers.rb
CHANGED
@@ -3,20 +3,22 @@ module ModalLogic
|
|
3
3
|
def modal_form_response( model, opts = {})
|
4
4
|
response = {}
|
5
5
|
case params[:action]
|
6
|
-
when '
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
when 'new', 'edit'
|
7
|
+
response[:body] = render_to_string path_to_current_controller_form, layout: false
|
8
|
+
response[:title] = opts[:title] || modal_title(model)
|
9
|
+
|
10
|
+
when 'create', 'update'
|
11
|
+
if ! model.valid? || ! model.persisted? || opts[:errors].present?
|
12
|
+
response[:body] = render_to_string path_to_current_controller_form
|
13
|
+
response[:errors] = opts[:errors] || model.errors
|
10
14
|
response[:flash] = flash
|
11
15
|
response[:title] = opts[:title] || modal_title(model)
|
12
16
|
else
|
13
17
|
response[:redirect_location] = opts[:redirect_location] if opts[:redirect_location]
|
14
18
|
response[:close] = true
|
15
19
|
end
|
16
|
-
when 'new'
|
17
|
-
response[:html] = render_to_string path_to_current_controller_form, layout: false
|
18
|
-
response[:title] = opts[:title] || modal_title(model)
|
19
20
|
end
|
21
|
+
|
20
22
|
response
|
21
23
|
end
|
22
24
|
|
@@ -26,9 +28,7 @@ module ModalLogic
|
|
26
28
|
end
|
27
29
|
|
28
30
|
def path_to_current_controller_form( opts = {} )
|
29
|
-
|
30
|
-
request_base_path = request.path.split(params[:action].to_s).last
|
31
|
-
File.join(Rails.root, 'app/views', request_base_path, filename )
|
31
|
+
File.join(Rails.root, 'app/views', params[:controller], opts[:filename] || '_form')
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
data/lib/modal_logic/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: modal_logic
|
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
|
- Adam Hallett
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 3.2.13
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: handlebars_assets
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.14.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.14.1
|
27
41
|
description: The simplicity of Rails forms coupled with Bootstrap modal
|
28
42
|
email:
|
29
43
|
- adam.t.hallett@gmail.com
|
@@ -33,6 +47,7 @@ extra_rdoc_files: []
|
|
33
47
|
files:
|
34
48
|
- app/assets/javascripts/modal_logic.coffee
|
35
49
|
- app/assets/javascripts/modal_logic.js
|
50
|
+
- app/assets/javascripts/templates/modal/crud.hbs
|
36
51
|
- lib/modal_logic/engine.rb
|
37
52
|
- lib/modal_logic/helpers.rb
|
38
53
|
- lib/modal_logic/version.rb
|