kolo 0.2.2 → 0.2.3

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.
@@ -0,0 +1,49 @@
1
+ ko.bindingHandlers.appearif =
2
+ init: (element, valueAccessor)->
3
+ value = ko.utils.unwrapObservable valueAccessor()
4
+ $(element).toggle(value)
5
+ update: (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext)->
6
+ appear = ko.utils.unwrapObservable valueAccessor()
7
+ duration = allBindingsAccessor().duration || 400
8
+ if appear
9
+ $(element).fadeIn(duration)
10
+ else
11
+ $(element).fadeOut(duration)
12
+
13
+ ko.bindingHandlers.appearifnot =
14
+ init: (element, valueAccessor)->
15
+ value = ko.utils.unwrapObservable valueAccessor()
16
+ $(element).toggle(!value)
17
+ update: (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext)->
18
+ appear = ko.utils.unwrapObservable valueAccessor()
19
+ duration = allBindingsAccessor().duration || 400
20
+ if !appear
21
+ $(element).fadeIn(duration)
22
+ else
23
+ $(element).fadeOut(duration)
24
+
25
+ ko.bindingHandlers.slidedownif =
26
+ init: (element, valueAccessor)->
27
+ value = ko.utils.unwrapObservable valueAccessor()
28
+ $(element).toggle(value)
29
+ update: (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext)->
30
+ appear = ko.utils.unwrapObservable valueAccessor()
31
+ duration = allBindingsAccessor().duration || 1000
32
+ if appear
33
+ $(element).slideDown(duration)
34
+ else
35
+ $(element).slideUp(duration)
36
+
37
+ ko.bindingHandlers.slidedownifnot =
38
+ init: (element, valueAccessor)->
39
+ value = ko.utils.unwrapObservable valueAccessor()
40
+ $(element).toggle(!value)
41
+ update: (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext)->
42
+ appear = ko.utils.unwrapObservable valueAccessor()
43
+ duration = allBindingsAccessor().duration || 1000
44
+ if !appear
45
+ $(element).slideDown(duration)
46
+ else
47
+ $(element).slideUp(duration)
48
+
49
+
@@ -26,12 +26,19 @@ class AdminViewModel extends ViewModel
26
26
  # doUpdate - update the given item in the database; on success, call @load()
27
27
  # doDelete - delete the given item from the database; on success call @items.remove(item) and then @load()
28
28
  # It expects models to have an updateAttributes(data) method and a valid method
29
+ # After instantiation you can also set the following hooks:
30
+ # db.sortFunction = function(a, b) { ... }
31
+ # db.onBeforeLoad = function() { ... }
32
+ # db.onAfterLoad = function() { ... }
29
33
 
30
34
  class Db
31
35
  constructor: (@name, @url)->
32
36
  @items = ko.observableArray []
33
37
  @selected = ko.observable null
34
38
  @plural = "#{@name}s"
39
+ @sortFunction = null
40
+ @onBeforeLoad = null
41
+ @onAfterLoad = null
35
42
 
36
43
  find: (id)=>
37
44
  for item in @items()
@@ -48,10 +55,14 @@ class Db
48
55
  load: (autoReload = false)=>
49
56
  if !@selected()
50
57
  viewModel.systemNotification @plural, 'loading'
58
+ @onBeforeLoad() if @onBeforeLoad?
51
59
  $.get @url, (data)=>
52
60
  for itemData in @itemDataFrom(data)
53
61
  item = @findOrCreate itemData.id
54
62
  item.updateAttributes itemData
63
+ if @sortFunction?
64
+ @items.sort @sortFunction
65
+ @onAfterLoad() if @onAfterLoad?
55
66
  viewModel.systemNotification @plural, 'loaded'
56
67
  if autoReload
57
68
  setTimeout =>
data/lib/kolo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kolo
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
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.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -63,6 +63,7 @@ files:
63
63
  - lib/assets/images/fontawesome-webfont.woff
64
64
  - lib/assets/images/glyphicons-halflings-white.png
65
65
  - lib/assets/images/glyphicons-halflings.png
66
+ - lib/assets/javascripts/bindings.js.coffee
66
67
  - lib/assets/javascripts/bootstrap.min.js
67
68
  - lib/assets/javascripts/data-access.js.coffee
68
69
  - lib/assets/javascripts/jquery.hammer.js
@@ -91,7 +92,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
91
92
  version: '0'
92
93
  segments:
93
94
  - 0
94
- hash: 412510675
95
+ hash: -782801809
95
96
  required_rubygems_version: !ruby/object:Gem::Requirement
96
97
  none: false
97
98
  requirements:
@@ -100,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
101
  version: '0'
101
102
  segments:
102
103
  - 0
103
- hash: 412510675
104
+ hash: -782801809
104
105
  requirements: []
105
106
  rubyforge_project:
106
107
  rubygems_version: 1.8.24