Skip to content

Commit

Permalink
Fix fields in user segment. Display the arguments name.
Browse files Browse the repository at this point in the history
  • Loading branch information
Doug Youch committed May 24, 2010
1 parent 5b5ade5 commit a02eb0c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 29 deletions.
3 changes: 2 additions & 1 deletion app/controllers/members_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,9 @@ def builder

if request.post? && params[:builder]
@builder.build(params[:builder])
render :inline => @builder.to_expr
end

render :action => 'builder', :layout => 'manage_window'
end

def update_builder
Expand Down
9 changes: 4 additions & 5 deletions app/models/user_segment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ class UserSegment < DomainModel
validates_presence_of :name
validates_presence_of :segment_options

def initialize(opts={})
super
self.fields = [] unless self.fields
end

def ready?; self.status == 'finished'; end

def fields
self.read_attribute(:fields) || []
end

def validate
self.errors.add(:segment_options_text, 'is invalid') if self.segment_options_text && self.segment_options.nil?
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/user_segment/operation_builder.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

class UserSegment::OperationBuilder < HashModel
attributes :operator => nil, :field => 'created', :operation => 'since', :arguments => []
attributes :operator => nil, :field => 'created', :operation => 'since', :arguments => [], :child => nil

def operator_options
[['Not', 'not'], ['', nil]]
Expand Down
25 changes: 13 additions & 12 deletions app/views/members/_operation_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,32 @@ OperationBuilder = {
}
</script>

<fieldset id="operation_builder">
<fieldset id="operation_builder" style="padding:5px;">
<legend>User Segment Syntax Helper</legend>
<% cms_unstyled_form_for :builder, @builder, :html => {:id => 'builder', :onsubmit => 'OperationBuilder.updateExpression(); return false;'} do |f| -%>
<ul>
<li>
<lable><%= 'I am'.t %></label>
<%= f.check_boxes :operator, [['not', 'not']], :single => true %>
<ul style="list-style:none;">
<li style="display:inline;">
<%= 'I am'.t %>
(<%= f.check_boxes :operator, [['not', 'not']], :single => true, :separator => '' %>)
</li>
<li>
<label><%= 'looking for'.t %></label>

<li style="display:inline;">
<%= 'looking for'.t %>
<%= f.select :field, @builder.field_options, {}, :onchange => 'OperationBuilder.updateOperations();' %>
</li>

<div id="operation" class="operation">
<div id="operation" class="operation" style="padding: 5px;">
<%= render :partial => 'operation_form_operation' %>
</div>

<li class="submit">
<%= f.submit_tag 'Build' %>
</li>

<li id="expression">
<%= render :partial => 'operation_form_expression' %>
</li>

<li class="submit" style="padding-top:5px;">
<%= f.submit_tag 'Build' %>
</li>

<% end -%>

</fieldset>
Expand Down
17 changes: 9 additions & 8 deletions app/views/members/_operation_form_arguments.html.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<% cms_unstyled_fields_for :builder, @builder do |f| %>
<ul>
<table style="padding:5px;">
<% @builder.operation_arguments.each_with_index do |arg, idx| -%>
<li>
<label><%= "Argument #{idx+1}" %></label>
<tr>
<td class="label"><%= @builder.operation_argument_names[idx] %></td>
<td class="argument">
<% arg_options = @builder.operation_argument_options[idx]
label = @builder.operation_argument_names[idx]
if arg_options[:options] -%>
<%= f.select "argument#{idx}", arg_options[:options], :label => label %>
<%= f.select "argument#{idx}", arg_options[:options] %>
<% else -%>
<%= f.text_field "argument#{idx}", :label => label %>
<%= f.text_field "argument#{idx}" %>
<% end -%>
</li>
</td>
</tr>
<% end -%>
</ul>
</table>
<% end %>
4 changes: 2 additions & 2 deletions app/views/members/_operation_form_operation.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% cms_unstyled_fields_for :builder, @builder do |f| %>
<li>
<%= f.select :operation, @builder.operation_options, {}, :onchange => 'OperationBuilder.updateArguments();' %>
<li style="padding-left: 5px;">
<%= f.select :operation, @builder.operation_options, {}, :onchange => 'OperationBuilder.updateArguments();', :style => 'width:250px;' %>
</li>

<li id="arguments" class="arguments">
Expand Down

0 comments on commit a02eb0c

Please sign in to comment.