if @dashboard.editable_by?(current_user)
render :partial => 'delete_form', :resource => params[:resource]
else
- redirect_to :action => 'index', :resource => params[:resource]
+ access_denied
end
end
def delete
verify_post_request
- dashboard=Dashboard.find(params[:id])
+ @dashboard=Dashboard.find(params[:id])
- access_denied unless dashboard.editable_by?(current_user)
+ access_denied unless @dashboard.editable_by?(current_user)
- if dashboard.destroy
+ if @dashboard.destroy
flash[:warning]=Api::Utils.message('dashboard.default_restored') if ActiveDashboard.count(:conditions => {:user_id => current_user.id})==0
+ render :text => params[:resource], :status => 200
else
- flash[:error]=Api::Utils.message('dashboard.error_delete_default')
+ @dashboard.errors.add(message('dashboard.error_delete_default'), ' ')
+ render :partial => 'dashboards/delete_form', :status => 400, :resource => params[:resource]
end
-
- redirect_to :action => 'index', :resource => params[:resource]
end
def down
end
def user_rights_consistency
- if shared? && !user.has_role?(:sharedashboard)
+ if shared? && user && !user.has_role?(:sharedashboard)
errors.add(:user, "cannot own this dashboard because it has insufficient rights")
end
end
<form id="delete-dashboard-form" method="post" action="<%= ApplicationController.root_context -%>/dashboards/delete">
- <input type="hidden" name="id" value="<%= params[:id] -%>">
+ <input type="hidden" name="id" value="<%= @dashboard.id -%>">
+ <% if @dashboard.global %>
+ <input type="hidden" name="global" value="true" />
+ <% else %>
+ <input type="hidden" name="resource" value="<%= params[:resource] %>"/>
+ <% end %>
<fieldset>
<div class="modal-head">
<h2><%= message 'dashboard.delete_confirm_title' -%></h2>
</div>
</fieldset>
</form>
+
+<script>
+ $j("#delete-dashboard-form").modalForm({success: function (data) {
+ var contextParams = data.trim().length > 0 ? '?resource=' + data.trim() : '';
+ window.location = baseUrl + '/dashboards' + contextParams;
+ }});
+</script>