Class: TranslationCenter::CategoriesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/translation_center/categories_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#translation_langs_filters

Instance Method Details

#category_paramsObject



67
68
69
# File 'app/controllers/translation_center/categories_controller.rb', line 67

def category_params
  params.permit!
end

#destroyObject

DELETE /categories/1 DELETE /categories/1.json



57
58
59
60
61
62
63
64
65
# File 'app/controllers/translation_center/categories_controller.rb', line 57

def destroy
  @category = Category.find(category_params[:id])
  @category.destroy
  
  respond_to do |format|
    format.html { redirect_to categories_url }
    format.json { head :no_content }
  end
end

#indexObject

GET /categories GET /categories.json



10
11
12
13
14
15
16
17
# File 'app/controllers/translation_center/categories_controller.rb', line 10

def index
  @categories = Category.all
  
  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @categories }
  end
end

#more_keysObject

GET /categories/1/more_keys.js



46
47
48
49
50
51
52
# File 'app/controllers/translation_center/categories_controller.rb', line 46

def more_keys
  @category = Category.find(category_params[:category_id])
  @keys = @category.send("#{session[:current_filter]}_keys", session[:lang_to]).offset(@page - 1).limit(TranslationKey::PER_PAGE)
  respond_to do |format|
    format.js { render 'keys' }
  end
end

#pagesObject



40
41
42
43
# File 'app/controllers/translation_center/categories_controller.rb', line 40

def pages
  @category = Category.find(category_params[:id])
  @keys = @category.keys.where("name LIKE ? ", "%#{page_name}%")
end

#showObject

GET /categories/1 GET /categories/1.json



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/translation_center/categories_controller.rb', line 21

def show
  @category = Category.find(category_params[:id])
  @page_name = params[:page_name]
  session[:current_filter] = category_params[:filter] || session[:current_filter]
  if params[:page].blank?
    @keys = @category.send("#{session[:current_filter]}_keys", session[:lang_to]).offset(@page - 1).limit(TranslationKey::PER_PAGE)
  else
    @keys = @category.keys.where("name LIKE ? ", "%#{@page_name}%")
  end
  @untranslated_keys_count = @category.untranslated_keys(session[:lang_to]).count
  @translated_keys_count = @category.translated_keys(session[:lang_to]).count
  @pending_keys_count = @category.pending_keys(session[:lang_to]).count
  @all_keys_count = @untranslated_keys_count + @translated_keys_count + @pending_keys_count
  respond_to do |format|
    format.html # show.html.erb
    format.js
  end
end