hydra-batch-edit 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,8 +7,8 @@ module BatchEditHelper
7
7
  end
8
8
 
9
9
  # Returns true if user has activated batch edit mode in session
10
- def batch_edit_active?
11
- session[:batch_edit_state] == 'on'
10
+ def batch_edit_state
11
+ session[:batch_edit_state] ||= 'off'
12
12
  end
13
13
 
14
14
  # Displays the batch edit tools. Put this in your search result page template. We recommend putting it in catalog/_sort_and_per_page.html.erb
@@ -4,7 +4,7 @@
4
4
  <span class="caret"></span>
5
5
  </button>
6
6
  <ul class="dropdown-menu">
7
- <li data-behavior="batch-edit-activate" data-state="off"><a href="#"><i class=""></i> Batch edit</a></li>
7
+ <li data-behavior="batch-edit-activate" data-state="<%= batch_edit_state %>"><a href="#"><i class=""></i> Batch edit</a></li>
8
8
  </ul>
9
9
  </div>
10
10
 
@@ -10,7 +10,6 @@ module Hydra
10
10
 
11
11
  def draw
12
12
  add_routes do |options|
13
- match 'batch_edits/:id' => 'batch_edits#add', :via=>:put
14
13
  resources :batch_edits, :only=>[:index] do
15
14
  member do
16
15
  delete :destroy
@@ -19,8 +18,10 @@ module Hydra
19
18
  get :edit
20
19
  put :update
21
20
  delete :clear
21
+ put :state
22
22
  end
23
23
  end
24
+ match 'batch_edits/:id' => 'batch_edits#add', :via=>:put
24
25
  end
25
26
  end
26
27
 
@@ -1,5 +1,5 @@
1
1
  module Hydra
2
2
  module BatchEdit
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -7,17 +7,39 @@ $ ->
7
7
  css_class: "batch_toggle"
8
8
  })
9
9
 
10
- $("[data-behavior='batch-edit-activate']").click (e) ->
11
- e.preventDefault()
12
- if $(this).attr("data-state") == 'off'
13
- $(this).attr("data-state", 'on')
14
- $(this).find('a i').addClass('icon-ok')
10
+ setState = (obj) ->
11
+ activate = ->
12
+ obj.find('a i').addClass('icon-ok')
15
13
  $("[data-behavior='batch-edit']").removeClass('hidden')
16
14
  $("[data-behavior='batch-add-button']").removeClass('hidden')
17
- else
18
- $(this).attr("data-state", 'off')
19
- $(this).find('a i').removeClass('icon-ok')
15
+
16
+ deactivate = ->
17
+ obj.find('a i').removeClass('icon-ok')
20
18
  $("[data-behavior='batch-edit']").addClass('hidden')
21
19
  $("[data-behavior='batch-add-button']").addClass('hidden')
20
+
21
+ if obj.attr("data-state") == 'off'
22
+ deactivate(obj)
23
+ else
24
+ activate(obj)
25
+
26
+ toggleState = (obj) ->
27
+ if obj.attr('data-state') == 'off'
28
+ obj.attr("data-state", 'on')
29
+ else
30
+ obj.attr("data-state", 'off')
31
+ setState(obj)
32
+
33
+ #set initial state
34
+ setState($("[data-behavior='batch-edit-activate']"))
35
+
36
+ $("[data-behavior='batch-edit-activate']").click (e) ->
37
+ e.preventDefault()
38
+ toggleState($(this))
39
+ $.ajax({
40
+ type: 'POST',
41
+ url: '/batch_edits/state',
42
+ data: {_method:'PUT', state: $(this).attr('data-state')},
43
+ });
22
44
  # TODO check-all
23
45
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-batch-edit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: