Class: Tr8n::Admin::TranslationKeyController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/tr8n/admin/translation_key_controller.rb

Overview

– Copyright © 2010-2011 Michael Berkovich, tr8n.net

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ++

Instance Method Summary collapse

Instance Method Details

#commentsObject



109
110
111
# File 'app/controllers/tr8n/admin/translation_key_controller.rb', line 109

def comments
  @comments = Tr8n::TranslationKeyComment.filter(:params => params, :filter => Tr8n::TranslationKeyCommentFilter)
end

#deleteObject



35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/tr8n/admin/translation_key_controller.rb', line 35

def delete
  params[:keys] = [params[:key_id]] if params[:key_id]
  if params[:keys]
    params[:keys].each do |key_id|
      key = Tr8n::TranslationKey.find_by_id(key_id)
      key.destroy if key
    end  
  end
  redirect_to_source
end

#delete_commentObject



117
118
119
120
121
122
123
124
125
126
# File 'app/controllers/tr8n/admin/translation_key_controller.rb', line 117

def delete_comment
  params[:comments] = [params[:comment_id]] if params[:comment_id]
  if params[:comments]
    params[:comments].each do |comment_id|
      comment = Tr8n::TranslationKeyComment.find_by_id(comment_id)
      comment.destroy if comment
    end  
  end
  redirect_to_source
end

#delete_lockObject



132
133
134
135
136
137
138
139
140
141
# File 'app/controllers/tr8n/admin/translation_key_controller.rb', line 132

def delete_lock
  params[:locks] = [params[:lock_id]] if params[:lock_id]
  if params[:locks]
    params[:locks].each do |lock_id|
      lock = Tr8n::TranslationKeyLock.find_by_id(lock_id)
      lock.destroy if lock
    end  
  end
  redirect_to_source
end

#delete_unverified_keysObject



148
149
150
151
152
153
154
# File 'app/controllers/tr8n/admin/translation_key_controller.rb', line 148

def delete_unverified_keys
  Tr8n::TranslationKey.find(:all, :conditions => "verified_at is null").each do |key|
    next if key.translations.any?
    key.destroy
  end
  redirect_to_source
end

#indexObject



26
27
28
# File 'app/controllers/tr8n/admin/translation_key_controller.rb', line 26

def index
  @keys = Tr8n::TranslationKey.filter(:params => params, :filter => Tr8n::TranslationKeyFilter)
end

#lb_mergeObject



67
68
69
70
71
72
73
74
# File 'app/controllers/tr8n/admin/translation_key_controller.rb', line 67

def lb_merge
  @keys = params[:keys] || ''
  @keys = @keys.split(',')
  @keys = Tr8n::TranslationKey.find(:all, :conditions => ["id in (?)", @keys])
  @key = @keys.first
  
  render :layout => false
end

#lb_updateObject



46
47
48
49
50
51
# File 'app/controllers/tr8n/admin/translation_key_controller.rb', line 46

def lb_update
  @key = Tr8n::TranslationKey.find_by_id(params[:key_id]) unless params[:key_id].blank?
  @key = Tr8n::TranslationKey.new unless @key
  
  render :layout => false
end

#locksObject



128
129
130
# File 'app/controllers/tr8n/admin/translation_key_controller.rb', line 128

def locks
  @locks = Tr8n::TranslationKeyLock.filter(:params => params, :filter => Tr8n::TranslationKeyLockFilter)
end

#mergeObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/controllers/tr8n/admin/translation_key_controller.rb', line 76

def merge
  master_key = Tr8n::TranslationKey.find_by_id(params[:translation_key].delete(:id))
  
  keys = params[:keys] || ''
  keys = keys.split(',')
  keys = Tr8n::TranslationKey.find(:all, :conditions => ["id in (?)", keys])
  keys.each do |key|
    next if key.id == master_key.id
    key.translations.each do |translation|
      translation.clear_cache
      translation.update_attributes(:translation_key => master_key)
    end
    key.translation_key_comments.each do |comment|
      comment.update_attributes(:translation_key => master_key)
    end
    key.translation_key_sources.each do |source|
      source.update_attributes(:translation_key => master_key)
    end
    
    key.reload
    key.destroy
  end
  
  params[:translation_key][:label].strip!
  params[:translation_key][:description].strip!
  master_key.update_attributes(params[:translation_key])
  master_key.reset_key!
  master_key.update_translation_count!
  master_key.unlock_all!
  
  redirect_to_source
end

#reset_verification_flagsObject



143
144
145
146
# File 'app/controllers/tr8n/admin/translation_key_controller.rb', line 143

def reset_verification_flags
  Tr8n::TranslationKey.connection.execute("update tr8n_translation_keys set verified_at = null")
  redirect_to_source
end

#sync_logsObject



113
114
115
# File 'app/controllers/tr8n/admin/translation_key_controller.rb', line 113

def sync_logs
  @logs = Tr8n::SyncLog.filter(:params => params, :filter => Tr8n::SyncLogFilter)
end

#updateObject



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/tr8n/admin/translation_key_controller.rb', line 53

def update
  key = Tr8n::TranslationKey.find_by_id(params[:translation_key][:id]) unless params[:translation_key][:id].blank?
  
  if key
    key.update_attributes(params[:translation_key])
  else
    key = Tr8n::TranslationKey.create(params[:translation_key])
  end

  key.reset_key!

  redirect_to_source
end

#update_translation_countsObject



156
157
158
159
# File 'app/controllers/tr8n/admin/translation_key_controller.rb', line 156

def update_translation_counts
  Tr8n::TranslationKey.connection.execute("update tr8n_translation_keys set translation_count = (select count(id) from tr8n_translations where tr8n_translations.translation_key_id = tr8n_translation_keys.id)")
  redirect_to_source
end

#viewObject



30
31
32
33
# File 'app/controllers/tr8n/admin/translation_key_controller.rb', line 30

def view
  @key = Tr8n::TranslationKey.find_by_id(params[:key_id])
  redirect_to(:action => :index) unless @key
end