access_denied unless logged_in?
require_parameters :id
- to_clone = find_filter(params[:id])
- @filter = MeasureFilter.new
- @filter.name = params[:name]
- @filter.description = params[:description]
- @filter.user_id = current_user.id
- @filter.shared = to_clone.shared
- @filter.data = to_clone.data
- @filter.shared = false
- if @filter.save
- current_user.favourited_measure_filters << @filter
- render :text => @filter.id.to_s, :status => 200
+ source = find_filter(params[:id])
+ target = MeasureFilter.new
+ target.name = params[:name]
+ target.description = params[:description]
+ target.user_id = current_user.id
+ target.shared = source.shared
+ target.data = source.data
+ target.shared = false
+ if target.save
+ current_user.favourited_measure_filters << target
+ render :text => target.id.to_s, :status => 200
else
+ # keep the id (from source) and errors (from target) in the copy form
+ target.id= source.id
+ @filter = target
render :partial => 'measures/copy_form', :status => 400
end
end
<input type="hidden" name="id" value="<%= @filter.id -%>">
<fieldset>
<div class="form-head">
- <h2>Copy Filter: <%= h @filter.name -%></h2>
+ <h2>Copy Filter</h2>
</div>
<div class="form-body">
<% @filter.errors.each do |attr, msg| %>
<p class="error"><%= h msg -%></p>
<% end %>
+ <div class="form-field">
+ <label>Copy</label>
+ <input type="text" size="50" maxlength="100" value="<%= h @filter.name -%>" disabled="disabled"/>
+ </div>
<div class="form-field">
<label for="name">Name <em class="mandatory">*</em></label>
- <input id="name" name="name" type="text" size="50" maxlength="100" value="<%= h @filter.name -%>"/>
+ <input id="name" name="name" type="text" size="50" maxlength="100" value=""/>
</div>
<div class="form-field">
<label for="description">Description</label>
</fieldset>
</form>
<script>
- $j("#copy-filter-form").modalForm({success:function (data) {
- window.location = baseUrl + '/measures/filter/' + data;
- }});
+ $j("#copy-filter-form").modalForm({success: function (data) {
+ window.location = baseUrl + '/measures/filter/' + data;
+ }});
$j('#name').select();
</script>
\ No newline at end of file