<%= pairs = if for_query_string query_params.to_a else hiddens = case fields when '*', nil # TODO: Need a better (i.e. extensible) way to eleminate certain fields this.class.column_names - ['type', 'created_at', 'updated_at'] else comma_split(fields) end hiddens.map do |field| val = this.send(field) param_name = param_name_for(form_field_path + [field]) [param_name, val] unless val.nil? || field.to_sym.in?(this.class.attr_protected) || (this.new_record? && val == this.class.column(field).default) end.compact end skip = comma_split skip pairs.reject! { |p| p.first.in?(skip) } pairs.map { |n, v| hidden_field_tag(n, v.to_s) if v && n.not_in?(scope.form_field_names) }.compact.safe_join("\n".html_safe) %> <%= ajax_attrs, html_attrs = attributes.partition_hash(Hobo::Rapid::Helper::AJAX_ATTRS) html_attrs[:enctype] ||= "multipart/form-data" if multipart new_record = this.try.new_record? method = if method.nil? (action || web_method || new_record) ? "post" : "put" else method.downcase end html_attrs[:action] = action || begin target = if owner collection_name = this.class.reverse_reflection(owner).name this.send(owner).send(collection_name) else this end action = web_method || lifecycle object_url(target, action, :method => method) end if action.nil? && (html_attrs[:action].nil? || (lifecycle.nil? && new_record && !this.creatable_by?(current_user)) || (lifecycle.nil? && !new_record && !can_edit?)) Dryml.last_if = false "" else if method == "put" # browsers don't support put -- use post and add the Rails _method hack http_method_hidden = hidden_field_tag("_method", "PUT") html_attrs[:method] = "post" else http_method_hidden = "" html_attrs[:method] = method end if update || !ajax_attrs.empty? # add an onsubmit to convert to an ajax form if `update` is given function = ajax_updater(:post_form, update, ajax_attrs) html_attrs[:onsubmit] = [html_attrs[:onsubmit], "#{function}; return false;"].compact.safe_join("; ".html_safe) end hiddens = "" body = with_form_context do # It is important to evaluate parameters.default first, in order to populate scope.form_field_names b = parameters.default hiddens = self.hidden_fields(:fields => hidden_fields) if new_record b end auth_token = if method.nil? || method == 'get' || !protect_against_forgery? '' else element(:input, {:type => "hidden", :name => request_forgery_protection_token.to_s, :value => form_authenticity_token}, nil, true, true) end unless method == "get" page_path = if (request.post? || request.put?) && params[:page_path] params[:page_path] else request.fullpath end page_path_hidden = hidden_field_tag("page_path", page_path) end hiddens_div = element(:div, {:class => "hidden-fields"}, [http_method_hidden, page_path_hidden, auth_token, hiddens].safe_join) body = [hiddens_div, body].safe_join if action.nil? # don't add automatic css classes if the action was specified if web_method add_classes!(html_attrs, "#{type_id.dasherize}-#{web_method}-form") else add_classes!(html_attrs, "#{'new ' if new_record}#{type_id.dasherize}") end end Dryml.last_if = true element("form", html_attrs, body) end %> <%= if attributes[:type] element :input, attributes, nil, true, true else no_edit ||= :view no_edit = no_edit.to_sym no_edit_permission = !can_edit? unless no_edit == :ignore if no_edit_permission && no_edit == :view view elsif no_edit_permission && no_edit == :skip "" else attrs = add_classes(attributes, type_id.dasherize, type_and_field.dasherize) attrs[:name] ||= param_name_for_this attrs[:disabled] = true if no_edit_permission && no_edit == :disable the_input = if (refl = this_field_reflection) if refl.macro == :belongs_to call_polymorphic_tag('input', attrs) or select_one(attrs) elsif refl.macro == :has_many if refl.options[:through] collection_input(attrs) else input_many(attrs) end end else call_polymorphic_tag('input', attrs) or (call_polymorphic_tag('input', HoboFields.to_class(this_type::COLUMN_TYPE), attrs) if defined?(this_type::COLUMN_TYPE)) or raise Hobo::Error, ("No input tag for #{this_field}:#{this_type} (this=#{this.inspect})") end unless this_parent.errors[this_field].empty? "#{the_input}".html_safe else the_input end end end %> <%= text_area_tag(name, this, attributes) %> <%= unless attributes[:disabled] cb_tag = check_box_tag(name, '1', this, attributes) cb_hidden_tag = hidden_field_tag(name, '0', :id => nil) cb_hidden_tag + cb_tag end %> <%= password_field_tag(name, this, attributes) %> <% order = order.nil? ? [:year, :month, :day] : comma_split(order).*.to_sym -%> <%= select_date(this || current_time, attributes.merge(:prefix => param_name_for_this, :order => order)) %> <% order = order.nil? ? [:year, :month, :day, :hour, :minute, :second] : comma_split(order).*.to_sym -%> <%= select_date(this || current_time, attributes.merge(:prefix => param_name_for_this, :order => order)) %> <% if ! order.nil? order = comma_split(order).*.to_sym attributes.merge!(:order => order) end -%> <%= select_datetime(this || current_time, attributes.merge(:prefix => param_name_for_this)) %> <%= text_field_tag(name, this, attributes) %> <%= text_field_tag(name, this, attributes) %> <%= text_field_tag(name, this, attributes) %> <%= text_field_tag(name, this, attributes) %> <% labels ||= {} labels = HashWithIndifferentAccess.new(labels) titleize = true if titleize.nil? options = this_type.values.map {|v| [labels.fetch(v, titleize ? this_type.translated_values[v].titleize : this_type.translated_values[v]), v] } %> <%= ajax_attributes, html_attributes = attributes.partition_hash(Hobo::Rapid::Helper::AJAX_ATTRS) url ||= object_url(this, method.to_s.gsub('-', '_'), :method => :post) raise ArgumentError, "no such web method '#{method}' on #{this.typed_id}" unless url add_classes!(html_attributes, "button remote-method-button #{method}-button") label ||= method.titleize if update || !ajax_attributes.empty? ajax_attributes[:message] ||= label func = ajax_updater(url, update, ajax_attributes.merge(:confirm => confirm)) html_attributes.update(:onclick => "var e = this; " + func, :type =>'button', :value => label) element(:input, html_attributes, nil, true, true) else button_to(label, url, html_attributes.merge(:confirm => confirm)) end %> <%= raise Hobo::Error.new("no update specified") unless update ajax_attributes, html_attributes = attributes.partition_hash(Hobo::Rapid::Helper::AJAX_ATTRS) params = (params || {}).merge(this.class.name.underscore => fields) ajax_attributes.reverse_merge!(:message => label, :params => params, :method => :put) func = ajax_updater(object_url(this), update, ajax_attributes) html_attributes.reverse_merge!(:type =>'button', :onclick => func, :value => label) element :input, add_classes(html_attributes, "button update-button update-#{this.class.name.underscore}-button"), nil, true, true %> <%= in_place = false if in_place.nil? && this == @this && request.method == :get url = object_url(this, :method => :delete, :subsite => subsite) if (Dryml.last_if = url && can_delete?) attributes = attributes.merge(if image { :type => "image", :src => "#{base_url}/images/#{image}" } else { :type => "button" } end) label ||= I18n.t("hobo.actions.remove", :default=>"Remove") confirm = I18n.t("hobo.messages.confirm", :default=>"Are you sure?") if confirm.nil? add_classes!(attributes, image ? "image-button" : "button", "delete-button delete-#{this.class.name.underscore.dasherize}-button") if url if in_place == false attributes[:confirm] = confirm if confirm attributes[:method] = :delete button_to(label, url, attributes) else fade = true if fade.nil? attributes[:value] = label attributes[:onclick] = "Hobo.removeButton(this, '#{url}', #{js_updates(update)}, {fade:#{fade}, confirm: #{confirm.inspect}})" element(:input, attributes, nil, true, true) end end else "" end %> <%= raise Hobo::Error.new("no update specified") unless update fields ||= {} class_or_assoc = if model model.is_a?(String) ? model.constantize : model elsif Hobo.simple_has_many_association?(this) fields[this_field_reflection.primary_key_name] = this.proxy_owner.id this else raise Hobo::Error.new("invalid context for ") end new = class_or_assoc.new(fields) new.set_creator(current_user) if can_create?(new) label ||= ht("#{new.class.name.tableize}.actions.new", :default=>"New #{new.class.model_name.human}") ajax_attributes = { :message => message } class_name = new.class.name.underscore ajax_attributes[:params] = { class_name => fields } unless fields.empty? func = ajax_updater(object_url(new.class, :method => :post), update, ajax_attributes) element :input, add_classes(attributes.merge(:type =>'button', :onclick => func, :value => label), "button create-button create-#{class_name}-button"), nil, true, true end %> <% raise Hobo::PermissionDeniedError.new("Not allowed to edit #{this_field}") if !attributes[:disabled] && !can_edit? blank_message ||= ht("#{this_type.name.tableize}.message.no", :default=>"(No #{this_type.model_name.human})") limit ||= 100 options ||= begin conditions = ActiveRecord::Associations::BelongsToAssociation.new(this_parent, this_field_reflection).send(:conditions) this_field_reflection.klass.all(:conditions => conditions, :limit => limit).select {|x| can_view?(x)} end if text_method.nil? select_options = options.map { |x| [x.to_s, x.id] } else select_options = options.map do |x| [ text_method.split(".").inject(x) { |v, method| v.send(method) }, x.id ] end end select_options = select_options.sort if sort select_options.insert(0, [blank_message, ""]) if include_none || (this.nil? && include_none != false) attributes = add_classes(attributes, "input", "belongs_to", type_and_field) -%> <% complete_target ||= this_field_reflection.klass completer ||= (complete_target.is_a?(Class) ? complete_target : complete_target.class).name_attribute min_chars ||= 1 value = name(:no_wrapper => true, :if_present => true) -%>

<% prompt ||= ht("#{this_field.tableize}.form.select_many.prompt", :default=>"Add #{this_field.titleize.singularize}") options ||= this_field_reflection.klass.all(:conditions =>this.send(:conditions)).select {|x| can_view?(x)} name ||= param_name_for_this values = this remove_label ||= I18n.t("hobo.actions.remove", :default=>'Remove') -%>
<%= h this.to_s %>
<% uri = "stay-here" if stay_here uri = session[:previous_uri] if go_back -%> <% key ||= 'default' %w[options first_option first_value].each do |a| str = I18n.t("tags.select_menu.#{key}.#{a}", :default=>'') eval "#{a} = str unless str.blank?" end -%> <% collection = this param_name = param_name_for_this options ||= begin conditions = ActiveRecord::Associations::BelongsToAssociation.new(this_parent, this_field_reflection).send(:conditions) this_field_reflection.klass.all(:conditions => conditions, :limit => 100).select {|x| can_view?(x)} end -%> <% # helper function to create id's on buttons to facilitate testing def underize(s) s.gsub(/\[/,"_").gsub(/\]/,"") end %> <% template ||= this.try.new_candidate || this.member_class.new %> <% minimum ||= 0 ; minimum = minimum.to_i %> <% skip ||= this.proxy_reflection.klass.reflect_on_all_associations.detect {|p| p.primary_key_name==this.proxy_reflection.primary_key_name}.try.name.to_s if this.respond_to? :proxy_reflection %> <% skip += ",#{more_skip}" if more_skip -%> <% association_fkey = this_field_reflection.primary_key_name -%> <% this_id = this_parent.id || rand(100000) -%> <% id ||= "sortable-input-many-#{this_parent.class.name.underscore.dasherize}-#{this_id}-#{this_field_reflection.name}" -%> <% template ||= this.try.new_candidate || this.member_class.new %> <% position_column ||= template.try.position_column -%>

or Cancel or Cancel