def create
@dashboard=Dashboard.new()
+ @dashboard.user_id=current_user.id
load_dashboard_from_params(@dashboard)
active_dashboard = current_user.active_dashboards.to_a.find { |ad| ad.name==@dashboard.name }
if active_dashboard
flash[:error]=Api::Utils.message('dashboard.error_create_existing_name')
- redirect_to :controller => 'dashboards', :action => 'index', :resource => params[:resource]
+ redirect_to :action => 'index', :resource => params[:resource]
elsif @dashboard.save
add_default_dashboards_if_first_user_dashboard
last_active_dashboard=current_user.active_dashboards.max_by(&:order_index)
redirect_to :controller => 'dashboard', :action => 'configure', :did => @dashboard.id, :id => (params[:resource] unless @dashboard.global)
else
flash[:error]=@dashboard.errors.full_messages.join('<br/>')
- redirect_to :controller => 'dashboards', :action => 'index', :resource => params[:resource]
+ redirect_to :action => 'index', :resource => params[:resource]
end
end
def edit
@dashboard=Dashboard.find(params[:id])
- if @dashboard.owner?(current_user)
+ if @dashboard.editable_by?(current_user)
render :partial => 'edit'
else
- redirect_to :controller => 'dashboards', :action => 'index', :resource => params[:resource]
+ redirect_to :action => 'index', :resource => params[:resource]
end
end
def update
dashboard=Dashboard.find(params[:id])
- if dashboard.owner?(current_user)
+ if dashboard.editable_by?(current_user)
load_dashboard_from_params(dashboard)
if dashboard.save
def delete
dashboard=Dashboard.find(params[:id])
bad_request('Unknown dashboard') unless dashboard
- access_denied unless dashboard.owner?(current_user)
+ access_denied unless dashboard.editable_by?(current_user)
if dashboard.destroy
- flash[:error]=Api::Utils.message('dashboard.default_restored') if ActiveDashboard.count(:conditions => ['user_id=?', current_user.id])==0
+ flash[:warning]=Api::Utils.message('dashboard.default_restored') if ActiveDashboard.count(:conditions => ['user_id=?', current_user.id])==0
else
flash[:error]=Api::Utils.message('dashboard.error_delete_default')
end
else
bad_request('Unknown dashboard')
end
- redirect_to :action => :index, :resource => params[:resource]
+ redirect_to :action => 'index', :resource => params[:resource]
end
def unfollow
if ActiveDashboard.count(:conditions => ['user_id=?', current_user.id])==0
flash[:notice]=Api::Utils.message('dashboard.default_restored')
end
- redirect_to :action => :index, :resource => params[:resource]
+ redirect_to :action => 'index', :resource => params[:resource]
end
private
dashboard.description=params[:description]
dashboard.is_global=(params[:global].present?)
dashboard.shared=(params[:shared].present? && is_admin?)
- dashboard.user_id=current_user.id
dashboard.column_layout=Dashboard::DEFAULT_LAYOUT if !dashboard.column_layout
end
</td>
<td class="thin nowrap right">
<% if active_dashboards.size() > 1 %>
- <%= link_to 'Remove from defaults', {:action => 'remove', :id => active.id}, {:confirm => 'Are you sure to remove it from default dashboards ?', :method => :post, :id => "remove-#{u active.name}", :class => 'link-action'} %>
+ <%= link_to 'Remove from defaults', {:action => :remove, :id => active.id}, {:confirm => 'Are you sure to remove it from default dashboards ?', :method => :post, :id => "remove-#{u active.name}", :class => 'link-action'} %>
<% end %>
</td>
</tr>
</td>
<td class="thin nowrap right">
<%= link_to 'Add to defaults', {:action => 'add', :id => dashboard.id}, {:method => :post, :id => "add-#{u dashboard.name}", :class => 'link-action'} %>
- <% if dashboard.provided_programmatically? %>
- |
- <%= link_to 'Delete', {:action => 'delete', :id => dashboard.id}, {:confirm => "Do you want to delete the dashboard #{dashboard.name(true)}?", :method => :post, :id => "delete-#{u dashboard.name}", :class => 'link-action'} %>
- <% end %>
</td>
</tr>
<% end %>
<%= link_to_remote message('edit'), {:update => "create_dashboard", :url => {:action => :edit, :id => active.dashboard_id, :resource => params[:resource]}},
{:id => "edit-#{u active.name}", :method => :get, :class => 'link-action'} %>
<% if @actives.size() > 1 %>
- |
- <% if active.owner?(current_user) %>
- <%= link_to message('delete'), {:action => :delete, :id => active.dashboard_id, :resource => params[:resource]}, :method => :post,
- :confirm => message('dashboard.do_you_want_to_delete_dashboard'), :id => "delete-#{u active.name}", :class => 'link-action' %>
- <% else %>
- <%= link_to message('unfollow'), {:action => :unfollow, :id => active.dashboard_id, :resource => params[:resource]}, :method => :post,
- :id => "unfollow-#{u active.name}", :class => 'link-action' %>
- <% end %>
+ |
+ <%= link_to message('delete'), {:action => :delete, :id => active.dashboard_id, :resource => params[:resource]}, :method => :post,
+ :confirm => message('dashboard.do_you_want_to_delete_dashboard'), :id => "delete-#{u active.name}", :class => 'link-action' %>
<% end %>
- <% elsif !active.owner?(current_user) && (@actives.size() > 1) %>
+ <% end %>
+ <% if @actives.size() > 1 %>
+ |
<%= link_to message('unfollow'), {:action => :unfollow, :id => active.dashboard_id, :resource => params[:resource]}, :method => :post,
:id => "unfollow-#{u active.name}", :class => 'link-action' %>
<% end %>
<%= dashboard.user_name -%>
</td>
<td class="thin nowrap right">
- <%= link_to message('follow'), {:action => 'follow', :id => dashboard.id, :resource => params[:resource]}, :method => :post, :id => "follow-#{u dashboard.name}", :class => 'link-action' %>
+ <% if dashboard.editable_by?(current_user) %>
+ <%= link_to_remote message('edit'), {:update => "create_dashboard", :url => {:action => :edit, :id => dashboard.id, :resource => params[:resource]}},
+ {:id => "edit-#{u dashboard.name}", :method => :get, :class => 'link-action'} %>
+ |
+ <%= link_to message('delete'), {:action => :delete, :id => dashboard.id, :resource => params[:resource]}, :method => :post,
+ :confirm => message('dashboard.do_you_want_to_delete_dashboard'), :id => "delete-#{u dashboard.name}", :class => 'link-action' %>
+ |
+ <% end %>
+ <%= link_to message('follow'), {:action => :follow, :id => dashboard.id, :resource => params[:resource]}, :method => :post, :id => "follow-#{u dashboard.name}", :class => 'link-action' %>
</td>
</tr>
<% end