# frozen_string_literal: true # = form Lux.page.var.user do |f| # = f.hidden :company_id # = f.row :name # = f.row :counrty_id, :as=>:country # .custom= f.input :email # = f.submit 'Save' class Lux::Html::Form def initialize(action, form_opts={}) form_opts[:method] = 'get' if form_opts.delete(:get) form_opts[:method] ||= 'get' unless action form_opts[:method] ||= 'post' form_opts[:method] = form_opts[:method].upcase @action = action @object = action if action.respond_to?(:update) @form_opts = form_opts end def encrypt data return unless data '[protected]:%s' % Crypt.encrypt(data) end def hidden(name, opts={}) fname = @object.class.name.tableize.singularize rescue nil if name.respond_to?(:update) oname = name.class.name.tableize.singularize if @object && @object.respond_to?("#{oname}_id") # grp Lux::Page::EncryptParams.hidden_input "#{fname}[#{oname}_id]", name.id else [ Lux::Page::EncryptParams.hidden_input("#{fname}[model_id]", name.id), Lux::Page::EncryptParams.hidden_input("#{fname}[model_type]", name.class.name), ].join('') end else name = '%s[%s]' % [fname, name] if fname && name.is_a?(Symbol) Lux::Page::EncryptParams.hidden_input(name, opts[:value]) end end def input(name, opts={}) @name = name opts[:id] ||= Lux.uid opts[:value] ||= Lux.page.params[name] if @form_opts[:method] == 'GET' input_object = Lux::Html::Input.new(@object) data = input_object.render(name, opts) @type = input_object.type data end def data=(body) @data = body end def render render_form @form_opts.tag(:form, @data) end def render_form @data = %[] @form_opts[:class] = 'custom-class' end def submit(name=nil) name ||= 'Submit' %[] end def row(name, opts={}) node = input(name, opts) label = %[] %[

#{label}#{node}

] end end