Class: Caboose::StackableGroupsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Caboose::StackableGroupsController
- Defined in:
- app/controllers/caboose/stackable_groups_controller.rb
Instance Method Summary collapse
-
#admin_add ⇒ Object
POST /admin/stackable-groups.
-
#admin_bulk_delete ⇒ Object
DELETE /admin/stackable-groups/bulk.
-
#admin_delete ⇒ Object
DELETE /admin/stackable-groups/:id.
-
#admin_index ⇒ Object
GET /admin/stackable-groups.
-
#admin_json ⇒ Object
GET /admin/stackable-groups/json.
-
#admin_json_single ⇒ Object
GET /admin/stackable-groups/:id/json.
-
#admin_options ⇒ Object
GET /admin/stackable-groups/options.
-
#admin_update ⇒ Object
PUT /admin/stackable-groups/:id.
Methods inherited from ApplicationController
#admin_bulk_add, #admin_bulk_update, #admin_edit, #before_action, #before_before_action, #hashify_query_string, #init_cart, #logged_in?, #logged_in_user, #login_user, #logout_user, #parse_url_params, #reject_param, #user_is_allowed, #user_is_allowed_to, #validate_cookie, #validate_token, #var, #verify_logged_in
Instance Method Details
#admin_add ⇒ Object
POST /admin/stackable-groups
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/controllers/caboose/stackable_groups_controller.rb', line 60 def admin_add return if !user_is_allowed('products', 'add') resp = Caboose::StdClass.new name = params[:name] if name.length == 0 resp.error = "The title cannot be empty." elsif StackableGroup.where(:name => name).exists? resp.error = "A stackable group with that name already exists." else sg = StackableGroup.new(:name => name) sg.save resp.refresh = true end render :json => resp end |
#admin_bulk_delete ⇒ Object
DELETE /admin/stackable-groups/bulk
86 87 88 89 90 91 92 93 |
# File 'app/controllers/caboose/stackable_groups_controller.rb', line 86 def admin_bulk_delete return if !user_is_allowed('products', 'delete') params[:model_ids].each do |sg_id| sg = StackableGroup.where(:id => sg_id).first sg.destroy if sg end render :json => { :success => true } end |
#admin_delete ⇒ Object
DELETE /admin/stackable-groups/:id
79 80 81 82 83 |
# File 'app/controllers/caboose/stackable_groups_controller.rb', line 79 def admin_delete return if !user_is_allowed('products', 'delete') StackableGroup.find(params[:id]).destroy render :json => true end |
#admin_index ⇒ Object
GET /admin/stackable-groups
5 6 7 8 |
# File 'app/controllers/caboose/stackable_groups_controller.rb', line 5 def admin_index return if !user_is_allowed('products', 'view') render :layout => 'caboose/admin' end |
#admin_json ⇒ Object
GET /admin/stackable-groups/json
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/caboose/stackable_groups_controller.rb', line 11 def admin_json return if !user_is_allowed('products', 'view') pager = Caboose::PageBarGenerator.new(params, { 'name' => '' }, { 'model' => 'Caboose::StackableGroup', 'sort' => 'name', 'desc' => false, 'base_url' => '/admin/stackable-groups', 'items_per_page' => 25, 'use_url_params' => false }) render :json => { :pager => pager, :models => pager.items } end |
#admin_json_single ⇒ Object
GET /admin/stackable-groups/:id/json
31 32 33 34 |
# File 'app/controllers/caboose/stackable_groups_controller.rb', line 31 def admin_json_single sg = StackableGroup.find(params[:id]) render :json => sg end |
#admin_options ⇒ Object
GET /admin/stackable-groups/options
96 97 98 99 100 101 102 103 104 |
# File 'app/controllers/caboose/stackable_groups_controller.rb', line 96 def = StackableGroup.reorder(:name).all.collect do |sg| { :value => sg.id, :text => sg.name } end render :json => end |
#admin_update ⇒ Object
PUT /admin/stackable-groups/:id
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/caboose/stackable_groups_controller.rb', line 37 def admin_update return if !user_is_allowed('products', 'edit') resp = Caboose::StdClass.new sg = StackableGroup.find(params[:id]) save = true params.each do |name,value| case name when 'name' then sg.name = value when 'extra_length' then sg.extra_length = value.to_f when 'extra_width' then sg.extra_width = value.to_f when 'extra_height' then sg.extra_height = value.to_f when 'max_length' then sg.max_length = value.to_f when 'max_width' then sg.max_width = value.to_f when 'max_height' then sg.max_height = value.to_f end end resp.success = save && sg.save render :json => resp end |