kolo 0.2.3 → 0.2.4
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.
- data/lib/assets/javascripts/data-access.js.coffee +12 -2
- data/lib/kolo/version.rb +1 -1
- metadata +4 -4
@@ -18,6 +18,8 @@ class ClientViewModel extends ViewModel
|
|
18
18
|
class AdminViewModel extends ViewModel
|
19
19
|
|
20
20
|
# Construct passing in a name (which is used in notifications) and a URL (eg /api/v1/people.json) that is used to load items (GET) and create them (POST)
|
21
|
+
# Plus an optional pushStateURI; if supplied (for example as /path/to/object) then the pushState is updated to selected().name() with the URI set to /path/to/object/#{selected().id}
|
22
|
+
#
|
21
23
|
# Subclasses are expected to implement
|
22
24
|
# newItem(id) - return an instance of a new model with the given ID (data will be filled in later by the Db)
|
23
25
|
# itemDataFrom(data) - return an array of JSON instances; for example if your people.json call returns data.people [ person1, person2 ] you would return data.people
|
@@ -25,6 +27,8 @@ class AdminViewModel extends ViewModel
|
|
25
27
|
# urlFor(item) - the URL for updates (PUT) or deletes (DELETE)
|
26
28
|
# doUpdate - update the given item in the database; on success, call @load()
|
27
29
|
# doDelete - delete the given item from the database; on success call @items.remove(item) and then @load()
|
30
|
+
# name - used for setting push-state
|
31
|
+
#
|
28
32
|
# It expects models to have an updateAttributes(data) method and a valid method
|
29
33
|
# After instantiation you can also set the following hooks:
|
30
34
|
# db.sortFunction = function(a, b) { ... }
|
@@ -32,13 +36,19 @@ class AdminViewModel extends ViewModel
|
|
32
36
|
# db.onAfterLoad = function() { ... }
|
33
37
|
|
34
38
|
class Db
|
35
|
-
constructor: (@name, @url)->
|
39
|
+
constructor: (@name, @url, @pushStateUri)->
|
36
40
|
@items = ko.observableArray []
|
37
41
|
@selected = ko.observable null
|
38
42
|
@plural = "#{@name}s"
|
39
43
|
@sortFunction = null
|
40
44
|
@onBeforeLoad = null
|
41
45
|
@onAfterLoad = null
|
46
|
+
if @pushStateUri? && history.pushState?
|
47
|
+
@selected.subscribe (newValue)=>
|
48
|
+
if newValue?
|
49
|
+
history.pushState @selected().name(), @selected().name(), "#{@pushStateUri}/#{@selected().id}"
|
50
|
+
else
|
51
|
+
history.pushState '', '', @pushStateUri
|
42
52
|
|
43
53
|
find: (id)=>
|
44
54
|
for item in @items()
|
@@ -67,7 +77,7 @@ class Db
|
|
67
77
|
if autoReload
|
68
78
|
setTimeout =>
|
69
79
|
@load(true)
|
70
|
-
,
|
80
|
+
, 30000
|
71
81
|
return false
|
72
82
|
|
73
83
|
add: =>
|
data/lib/kolo/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kolo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -92,7 +92,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
92
|
version: '0'
|
93
93
|
segments:
|
94
94
|
- 0
|
95
|
-
hash: -
|
95
|
+
hash: -592120131
|
96
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
97
|
none: false
|
98
98
|
requirements:
|
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
101
|
version: '0'
|
102
102
|
segments:
|
103
103
|
- 0
|
104
|
-
hash: -
|
104
|
+
hash: -592120131
|
105
105
|
requirements: []
|
106
106
|
rubyforge_project:
|
107
107
|
rubygems_version: 1.8.24
|