Class: TranslationCenter::TranslationKeysController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- TranslationCenter::TranslationKeysController
- Defined in:
- app/controllers/translation_center/translation_keys_controller.rb
Instance Method Summary collapse
-
#destroy ⇒ Object
DELETE /translation_keys/1 DELETE /translation_keys/1.json.
-
#search ⇒ Object
GET /translation_keys/search.json.
-
#show ⇒ Object
GET /translation_keys/1.
-
#translations ⇒ Object
GET /translation_keys/translations.
-
#update ⇒ Object
PUT /translation_keys/1 PUT /translation_keys/1.json.
-
#update_translation ⇒ Object
POST /translation_keys/1/update_translation.js.
Methods inherited from ApplicationController
Instance Method Details
#destroy ⇒ Object
DELETE /translation_keys/1 DELETE /translation_keys/1.json
55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/controllers/translation_center/translation_keys_controller.rb', line 55 def destroy @category = @translation_key.category @translation_key_id = @translation_key.id @key_status = @translation_key.status(session[:lang_to]) @translation_key.destroy respond_to do |format| format.js format.html {redirect_to @category, notice: I18n.t('translation_center.translation_keys.destroyed_successfully')} end end |
#search ⇒ Object
GET /translation_keys/search.json
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/translation_center/translation_keys_controller.rb', line 68 def search # if full name provided then get the key and redirect to it, otherwise return similar in json if trans_params[:search_key_name].present? @translation_key = TranslationKey.find_by_name(trans_params[:search_key_name]) else @key_names = TranslationKey.where('name LIKE ?', "%#{trans_params[:query]}%") end respond_to do |format| format.html { redirect_to @translation_key} format.json { render json: @key_names.map(&:name) } end end |
#show ⇒ Object
GET /translation_keys/1
36 37 |
# File 'app/controllers/translation_center/translation_keys_controller.rb', line 36 def show end |
#translations ⇒ Object
GET /translation_keys/translations
27 28 29 30 31 32 33 |
# File 'app/controllers/translation_center/translation_keys_controller.rb', line 27 def translations @translations = @translation_key.translations.in(session[:lang_to]).order('created_at DESC') respond_to do |format| format.js end end |
#update ⇒ Object
PUT /translation_keys/1 PUT /translation_keys/1.json
41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/translation_center/translation_keys_controller.rb', line 41 def update trans_params[:value].strip! @old_value = @translation_key.category.name respond_to do |format| if !trans_params[:value].blank? && @translation_key.update_attribute(:name, trans_params[:value]) format.json { render json: { new_value: @translation_key.name, new_category: @translation_key.category.name, old_category: @old_value, key_id: @translation_key.id } } else format.json { render json: @translation_key.errors, status: :unprocessable_entity } end end end |
#update_translation ⇒ Object
POST /translation_keys/1/update_translation.js
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/controllers/translation_center/translation_keys_controller.rb', line 9 def update_translation @translation = current_user.translation_for @translation_key, session[:lang_to] @key_before_status = @translation_key.status(session[:lang_to]) respond_to do |format| # only admin can edit accepted translations if (current_user.can_admin_translations? || !@translation.accepted?) && !trans_params[:value].strip.blank? # use yaml.load to handle arrays @translation.update_attributes(value: YAML.load(trans_params[:value].strip), status: 'pending') # translation added by admin is considered the accepted one as it is trusted @translation.accept if current_user.can_admin_translations? && CONFIG['accept_admin_translations'] format.json {render json: { value: @translation.value, status: @translation.key.status(@translation.lang), key_before_status: @key_before_status } } else render nothing: true end end end |