Sha256: 50d5454917bc79db69c7220693da14f115706c64b16c2556771302f178d1c1d1

Contents?: true

Size: 1.54 KB

Versions: 11

Compression:

Stored size: 1.54 KB

Contents

module Spider; module Components
    
    class Confirm < Spider::Widget
        tag 'confirm'
        is_attr_accessor :actions
        is_attribute :cancel_param
        is_attribute :ok_param
        is_attribute :cancel_text, :default => Proc.new{ _('Cancel') }
        is_attribute :ok_text, :default => Proc.new{ _('Ok') }

        
        def prepare
            @scene.params = collapse_params(@request.params)
            unless @actions
                @cancel_param ||= '_w'+param_name(self)+'[cancel]'
                @ok_param ||= '_w'+param_name(self)+'[ok]'
                add_action(@cancel_param, @cancel_text)
                add_action(@ok_param, @ok_text)
             end
        end
        
        def add_action(name, value, type=nil)
            @actions ||= []
            @actions << [name, value, type]
        end
        
        def collapse_params(h, first=true)
            res = []
            h.each do |k, v|
                res_key = first ? k : "[#{k}]"
                case v
                when Hash
                    collapse_params(v, false).each do |v_k, v_v|
                        res << ["#{res_key}#{v_k}", v_v]
                    end
                when Array
                    # NOTE: doesn't handle arrays of Hashes and arrays of Arrays
                    v.each do |v_v|
                        res << ["#{res_key}[]", v_v]
                    end
                else
                    res << [res_key, v]
                end
            end
            return res
        end
        
    end
    
end; end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
spiderfw-1.0.1 apps/core/components/widgets/confirm/confirm.rb
spiderfw-1.0.0 apps/core/components/widgets/confirm/confirm.rb
spiderfw-0.6.39 apps/core/components/widgets/confirm/confirm.rb
spiderfw-0.6.38 apps/core/components/widgets/confirm/confirm.rb
spiderfw-0.6.37 apps/core/components/widgets/confirm/confirm.rb
spiderfw-0.6.35 apps/core/components/widgets/confirm/confirm.rb
spiderfw-0.6.34 apps/core/components/widgets/confirm/confirm.rb
spiderfw-0.6.33 apps/core/components/widgets/confirm/confirm.rb
spiderfw-0.6.32 apps/core/components/widgets/confirm/confirm.rb
spiderfw-0.6.31 apps/core/components/widgets/confirm/confirm.rb
spiderfw-0.6.30 apps/core/components/widgets/confirm/confirm.rb