modularity-rails 0.16.0 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/assets/javascripts/modularity/data/ajax_loader.coffee +3 -3
- data/app/assets/javascripts/modularity/data/cache.coffee +3 -1
- data/app/assets/javascripts/modularity/data/indexed_cache.coffee +2 -2
- data/app/assets/javascripts/modularity/data/persistence_manager.coffee +6 -4
- data/app/assets/javascripts/modularity/mixins/clickable.coffee +2 -7
- data/app/assets/javascripts/modularity/mixins/closable.coffee +3 -8
- data/app/assets/javascripts/modularity/modularity.coffee +6 -26
- data/app/assets/javascripts/modularity/modules/autogrow_textarea.coffee +1 -1
- data/app/assets/javascripts/modularity/modules/button.coffee +2 -2
- data/app/assets/javascripts/modularity/tools/array_tools.coffee +1 -1
- data/config/initializers/konacha.rb +0 -1
- data/lib/modularity-rails/version.rb +1 -1
- metadata +2 -2
@@ -8,7 +8,7 @@
|
|
8
8
|
#
|
9
9
|
# Warning: Caches the responses, so once a request is cached,
|
10
10
|
# any new content on the same URL will not be visible!
|
11
|
-
class
|
11
|
+
class modularity.AjaxLoader
|
12
12
|
|
13
13
|
constructor: (params = {}) ->
|
14
14
|
|
@@ -55,7 +55,7 @@ class window.modularity.AjaxLoader
|
|
55
55
|
# Fire 'loading' event if this is the start of a loading operation.
|
56
56
|
@loader_count++
|
57
57
|
if @loader_count == 1
|
58
|
-
|
58
|
+
modularity.fire_global_event modularity.AjaxLoader.events.AJAX_LOADING
|
59
59
|
|
60
60
|
# Perform the request.
|
61
61
|
jQuery.get url, (data) =>
|
@@ -73,5 +73,5 @@ class window.modularity.AjaxLoader
|
|
73
73
|
# Fire 'loaded' event.
|
74
74
|
@loader_count--
|
75
75
|
if @loader_count == 0
|
76
|
-
|
76
|
+
modularity.fire_global_event modularity.AjaxLoader.events.AJAX_LOADED
|
77
77
|
|
@@ -4,7 +4,7 @@
|
|
4
4
|
# by indexing them on a given key column.
|
5
5
|
class modularity.IndexedCache
|
6
6
|
|
7
|
-
constructor: (@key) ->
|
7
|
+
constructor: (@key = 'id') ->
|
8
8
|
@cache = new modularity.Cache
|
9
9
|
|
10
10
|
|
@@ -21,7 +21,7 @@ class modularity.IndexedCache
|
|
21
21
|
|
22
22
|
|
23
23
|
remove_many: (entries) ->
|
24
|
-
@cache.remove_many entries
|
24
|
+
@cache.remove_many (entry[@key] for entry in entries)
|
25
25
|
|
26
26
|
|
27
27
|
get: (key) ->
|
@@ -8,10 +8,10 @@ class modularity.PersistenceManager
|
|
8
8
|
constructor: (params) ->
|
9
9
|
|
10
10
|
# Copy of the data as it is on the server.
|
11
|
-
@server_data = new modularity.IndexedCache
|
11
|
+
@server_data = new modularity.IndexedCache
|
12
12
|
|
13
13
|
# Copy of the data as it is on the client.
|
14
|
-
@client_data = new modularity.IndexedCache
|
14
|
+
@client_data = new modularity.IndexedCache
|
15
15
|
|
16
16
|
# The base url on the server. Expected to be a fully RESTful API.
|
17
17
|
@base_url = params.url
|
@@ -43,6 +43,7 @@ class modularity.PersistenceManager
|
|
43
43
|
callback server_obj
|
44
44
|
|
45
45
|
|
46
|
+
# Deletes the given object from the server.
|
46
47
|
delete: (obj, callback) ->
|
47
48
|
@client_data.remove obj
|
48
49
|
@server_data.remove obj
|
@@ -53,9 +54,10 @@ class modularity.PersistenceManager
|
|
53
54
|
callback() if callback?
|
54
55
|
|
55
56
|
|
57
|
+
# Deletes the given objects from the server.
|
56
58
|
delete_many: (objects, callback) ->
|
57
|
-
@client_data.remove_many
|
58
|
-
@server_data.remove_many
|
59
|
+
@client_data.remove_many objects
|
60
|
+
@server_data.remove_many objects
|
59
61
|
jQuery.ajax
|
60
62
|
url: @base_url
|
61
63
|
type: 'DELETE'
|
@@ -1,21 +1,16 @@
|
|
1
1
|
# This mixin adds a 'clickable' aspect to modules.
|
2
2
|
# This means clicking anywhere on the module fires the 'clicked' event.
|
3
|
-
|
3
|
+
modularity.clickable =
|
4
4
|
|
5
5
|
constructor: ->
|
6
6
|
@container.click @container_clicked
|
7
7
|
|
8
8
|
|
9
|
-
# Events that are fired by this mixin.
|
10
|
-
events:
|
11
|
-
clicked: 'clicked'
|
12
|
-
|
13
|
-
|
14
9
|
# Programmatically click this clickable element.
|
15
10
|
# For testing and scripting.
|
16
11
|
click: -> @container.click()
|
17
12
|
|
18
13
|
|
19
14
|
# Event handler for clicks on this clickable element.
|
20
|
-
container_clicked: -> @
|
15
|
+
container_clicked: -> @fire 'clicked'
|
21
16
|
|
@@ -1,21 +1,16 @@
|
|
1
|
-
|
1
|
+
modularity.closable =
|
2
2
|
|
3
3
|
constructor: (container) ->
|
4
4
|
close_button = @container.find('.CloseButton')
|
5
5
|
unless close_button?.length > 0
|
6
|
-
|
6
|
+
alert 'Error: Close button not found'
|
7
7
|
close_button.click => @close_button_clicked()
|
8
8
|
|
9
9
|
|
10
|
-
# The events that can be fired by closable objects.
|
11
|
-
events:
|
12
|
-
closed: 'closed'
|
13
|
-
|
14
|
-
|
15
10
|
# Called when the button got clicked by the user or programmatically.
|
16
11
|
close_button_clicked: ->
|
17
12
|
if @closable_closing
|
18
13
|
return unless @closable_closing()
|
19
|
-
@
|
14
|
+
@fire 'closed'
|
20
15
|
@container.remove()
|
21
16
|
@closable_closed() if @closable_closed
|
@@ -8,7 +8,7 @@
|
|
8
8
|
# and https://github.com/kevgo/modularity-rails for Rails integration.
|
9
9
|
|
10
10
|
|
11
|
-
|
11
|
+
@modularity = {
|
12
12
|
|
13
13
|
# Checks whether the given condition is true.
|
14
14
|
# Shows an alert with the given message if not.
|
@@ -37,11 +37,11 @@ window.modularity = {
|
|
37
37
|
# Returns the DOM object that is used to fire global events on.
|
38
38
|
global_event_container: -> modularity.global_event_container_cache or= $(window)
|
39
39
|
}
|
40
|
-
|
41
|
-
|
40
|
+
@modularity.bindGlobalEvent = @modularity.bind_global_event
|
41
|
+
@modularity.fireGlobalEvent = @modularity.fire_global_event
|
42
42
|
|
43
43
|
|
44
|
-
class
|
44
|
+
class @modularity.Module
|
45
45
|
|
46
46
|
# The container variable is required. Provide 'testing' in tests.
|
47
47
|
constructor: (container) ->
|
@@ -81,6 +81,7 @@ class window.modularity.Module
|
|
81
81
|
return alert "Module.bind_event: parameter 'callback' must be a function, #{callback} (#{typeof callback}) given." unless typeof callback == 'function'
|
82
82
|
@container.bind event_type, callback
|
83
83
|
bindEvent: Module::bind_event
|
84
|
+
on: Module::bind_event
|
84
85
|
|
85
86
|
# Fires the given local event with the given data payload.
|
86
87
|
fire_event: (event_type, data) =>
|
@@ -88,6 +89,7 @@ class window.modularity.Module
|
|
88
89
|
return alert("Module.fire_event: Event type must be a string, #{event_type} (#{typeof event_type}) given.") unless typeof event_type == 'string'
|
89
90
|
@container.trigger event_type, data ?= {}
|
90
91
|
fireEvent: Module::fire_event
|
92
|
+
fire: Module::fire_event
|
91
93
|
|
92
94
|
|
93
95
|
# Hides this module.
|
@@ -106,25 +108,3 @@ class window.modularity.Module
|
|
106
108
|
# Shows this module.
|
107
109
|
show: ->
|
108
110
|
@container.show()
|
109
|
-
|
110
|
-
|
111
|
-
# jQuery integration for creating Modules.
|
112
|
-
#
|
113
|
-
# Call like this: myModule = $('...').module(MyModuleClass)
|
114
|
-
#
|
115
|
-
# Parameters:
|
116
|
-
# * klass: the class of the Module to instantiate
|
117
|
-
# * any additional parameters are forwarded to the Module constructor.
|
118
|
-
# Returns the created module instance.
|
119
|
-
#
|
120
|
-
# Messages errors in alert boxes.
|
121
|
-
#
|
122
|
-
jQuery.fn.module = (klass, args...) ->
|
123
|
-
|
124
|
-
# Check parameters.
|
125
|
-
if typeof klass != 'function'
|
126
|
-
return alert "ERROR!\n\nYou must provide the Module class when calling $.module().\n\nExample: $('...').module(MyModuleClass)\n\nYou provided: #{klass} (#{typeof klass})"
|
127
|
-
|
128
|
-
# Instantiate the class and return the instance.
|
129
|
-
new klass(this, args...)
|
130
|
-
|
@@ -3,6 +3,6 @@
|
|
3
3
|
# A button module.
|
4
4
|
# Responds to clicks on the container element.
|
5
5
|
# The container element is expected to already be populated.
|
6
|
-
class
|
7
|
-
@mixin
|
6
|
+
class modularity.Button extends modularity.Module
|
7
|
+
@mixin modularity.clickable
|
8
8
|
|
metadata
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
name: modularity-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.17.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Kevin Goslar
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
prerelease: false
|