Sha256: 6a9907cfd6e0e6e2a5c1f96ad5a636a80b5f43329405f48be85cd0fc0ffbe4e5

Contents?: true

Size: 1.42 KB

Versions: 55

Compression:

Stored size: 1.42 KB

Contents

module Caboose
  class AbOptionsController < ApplicationController
    layout 'caboose/admin'

    # @route GET /admin/ab_variants/:variant_id/options
    def admin_index
      return unless user_is_allowed_to 'view', 'ab_variants'
      v = AbVariant.find(params[:variant_id])
      render :json => v.ab_options
    end

    # @route POST admin/ab-variants/:variant_id/options'
    def admin_create
      return unless user_is_allowed_to 'edit','ab_variants'
      
      resp = StdClass.new({
        'error' => nil,
        'redirect' => nil
      })
      
      opt = AbOption.create(
        :ab_variant_id => params[:variant_id],
        :text => params[:text]
      )      
      resp.redirect = "/admin/ab-variants/#{params[:variant_id]}"      
      render :json => resp
    end

    # @route PUT /admin/ab_options/:id
    def admin_update
      return unless user_is_allowed_to 'edit', 'ab_variants'

      resp = StdClass.new
      opt = AbOption.find(params[:id])

      save = true
      params.each do |k,v|
        case k
          when 'value'
            opt.value = v
            break
        end
      end      

      resp.success = save && opt.save      
      render :json => resp
    end

    # @route DELETE /admin/ab_options/:id
    def admin_delete
      return unless user_is_allowed_to 'delete', 'ab_variants'      
      AbOption.find(params[:id]).destroy                  
      render :json => true
    end

  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
caboose-cms-0.7.85 app/controllers/caboose/ab_options_controller.rb
caboose-cms-0.7.84 app/controllers/caboose/ab_options_controller.rb
caboose-cms-0.7.83 app/controllers/caboose/ab_options_controller.rb
caboose-cms-0.7.82 app/controllers/caboose/ab_options_controller.rb
caboose-cms-0.7.81 app/controllers/caboose/ab_options_controller.rb
caboose-cms-0.7.80 app/controllers/caboose/ab_options_controller.rb
caboose-cms-0.7.79 app/controllers/caboose/ab_options_controller.rb
caboose-cms-0.7.78 app/controllers/caboose/ab_options_controller.rb
caboose-cms-0.7.77 app/controllers/caboose/ab_options_controller.rb
caboose-cms-0.7.76 app/controllers/caboose/ab_options_controller.rb
caboose-cms-0.7.75 app/controllers/caboose/ab_options_controller.rb
caboose-cms-0.7.74 app/controllers/caboose/ab_options_controller.rb
caboose-cms-0.7.73 app/controllers/caboose/ab_options_controller.rb
caboose-cms-0.7.72 app/controllers/caboose/ab_options_controller.rb
caboose-cms-0.7.71 app/controllers/caboose/ab_options_controller.rb
caboose-cms-0.7.70 app/controllers/caboose/ab_options_controller.rb
caboose-cms-0.7.69 app/controllers/caboose/ab_options_controller.rb
caboose-cms-0.7.68 app/controllers/caboose/ab_options_controller.rb
caboose-cms-0.7.67 app/controllers/caboose/ab_options_controller.rb
caboose-cms-0.7.66 app/controllers/caboose/ab_options_controller.rb