Commit c288638a authored by o's avatar o

support for deleting resources

parent 7eb52b93
Pipeline #4765 passed with stages
in 17 minutes and 8 seconds
......@@ -370,8 +370,8 @@ module ApiBackend
post(['resource', 'undelete'], {uid: uid})
end
def resource_delete(uid)
post(['resource', 'delete'], {uid: uid})
def resource_delete(uid, pw=nil)
post(['resource', 'delete'], {uid: uid, password: pw})
end
def resource_add_owner(uid, user)
......
......@@ -51,4 +51,20 @@ class ResourcesController < ApplicationController
flash[:danger] = e.api_msg
redirect_to new_resource_path
end
def update
uid = params[:uid]
pw = params[:password]
if params[:delete].present?
@res = api.resource_delete(uid, pw)
flash[:success] = :success
end
redirect_to resources_path
rescue ApiError => e
flash[:danger] = e.api_msg
redirect_to resources_path
end
end
<h3> <%= t(:new_resource) %></h3>
<nav>
<div class="nav nav-tabs" id="nav-tab" role="tablist">
<% @resource_names.each do |pane| %>
......
<pre>
<%= @resources.to_yaml %>
</pre>
<h3> <%= t(:my_resources) %></h3>
<p>
<% @resources.each do |res| %>
<% resource_ui_id = SecureRandom.hex(32) %>
<%= form_tag do %>
<%= hidden_field_tag 'uid', res %>
<%= res %>
<button type="button" class="btn btn-warning" onclick="
style.display='none';
document.getElementById('delete_<%= resource_ui_id %>').style.display='inline';
"><%= t :delete %></button>
<div id="delete_<%= resource_ui_id %>" style="display:none">
<p>
<div class="form-group">
<%= label_tag :password, t(:your_main_pw) %>
<%= password_field_tag 'password' %>
</div>
<%= submit_tag(t(:delete),
name: "delete",
class: "btn btn-danger") %>
</p>
</div>
<% end %>
<hr />
<% end %>
</p>
......@@ -3,7 +3,7 @@
<% @resource_schema.each do |n,v| %>
<div class="form-group">
<%= label_tag n %>
<%= label_tag 'data_'+n, n %>
<%= case v
when 'text'
text_field_tag('data_'+n, "", class: 'form-control')
......
......@@ -66,6 +66,7 @@ Rails.application.routes.draw do
get '/msg', to: 'application#msg'
get '/resources', to: 'resources#show'
post '/resources', to: 'resources#update'
get '/new_resource', to: 'resources#create'
post '/new_resource', to: 'resources#do_create'
else
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment