current_user.favourited_measure_filters<<@filter if add_to_favourites
render :text => @filter.id.to_s, :status => 200
else
- render :partial => 'measures/save_as_form', :status => 400
+ render_measures_error(@filter)
end
end
render :text => @filter.id.to_s, :status => 200
else
- render :partial => 'measures/edit_form', :status => 400
+ render_measures_error(@filter)
end
end
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
+ render_measures_error(target)
end
end
def criteria_params
params.merge({:controller => nil, :action => nil, :search => nil, :widget_id => nil, :edit => nil})
end
+
+ def render_measures_error(filter)
+ errors = []
+ filter.errors.full_messages.each{|msg| errors<<msg + '<br/>'}
+ render :text => errors, :status => 400
+ end
end
display_owner = false
end %>
<div class="modal-body">
- <% @filter.errors.full_messages.each do |msg| %>
- <p class="error"><%= h msg -%></p>
- <% end %>
+ <div class="modal-error"/>
<div class="modal-field">
<label for="name"><%= h message('name') -%> <em class="mandatory">*</em></label>
<input id="name" name="name" type="text" size="50" maxlength="100" value="<%= h @filter.name -%>" autofocus="autofocus"/>
window.location.reload();
},
error: function (xhr, textStatus, errorThrown) {
- $j("#modal").html(xhr.responseText);
+ // If the modal window has defined a modal-error element, then returned text must be displayed in it
+ var errorElt = obj.find(".modal-error");
+ if (errorElt.length) {
+ $j('input[type=submit]', obj).removeAttr('disabled');
+ errorElt.show();
+ errorElt.html(xhr.responseText);
+ // otherwise replace modal window by the returned text
+ } else {
+ $j("#modal").html(xhr.responseText);
+ }
}
}, ajax_options));
return false;