Add move operation for documents plugin

This commit is contained in:
Patrick Gansterer 2020-03-06 14:30:27 +01:00
parent 3fb3fa409b
commit 3a4519757e
10 changed files with 41 additions and 0 deletions

View file

@ -1714,6 +1714,7 @@ de:
delete: Löschen
download: Herunterladen
edit: Bearbeiten
move: Verschieben
or_cancel: oder abbrechen
please_wait: Bitte warten...
restore: Wiederherstellen

View file

@ -1772,6 +1772,7 @@ en:
marks:
close: "×"
success: <i class="icon icon-ok"></i>
move: Move
or_cancel: or cancel
please_wait: Please wait...
restore: Restore

View file

@ -43,6 +43,14 @@ class DocumentsController < ApplicationController
redirect_to @document.parent || documents_path, alert: t('.error', error: error.message)
end
def update
@document = Document.find(params[:id])
@document.update_attribute(:parent_id, params[:parent_id])
redirect_to @document.parent || documents_path, notice: t('.notice')
rescue => error
redirect_to @document.parent || documents_path, alert: t('errors.general_msg', msg: error.message)
end
def destroy
@document = Document.find(params[:id])
if @document.created_by == current_user or current_user.role_admin?
@ -65,6 +73,10 @@ class DocumentsController < ApplicationController
end
end
def move
@document = Document.find(params[:document_id])
end
def allowed_mime?(mime)
whitelist = FoodsoftConfig[:documents_allowed_extension].split
MIME::Types.type_for(whitelist).each do |type|

View file

@ -1,5 +1,6 @@
class Document < ApplicationRecord
include ActsAsTree
extend ActsAsTree::TreeWalker
belongs_to :created_by, class_name: 'User', foreign_key: 'created_by_user_id'

View file

@ -16,5 +16,6 @@
%td= h show_user(document.created_by)
%td
- if document.created_by == current_user or current_user.role_admin?
= link_to t('ui.move'), document_move_path(document), remote: true, class: 'btn btn-mini'
= link_to t('ui.delete'), document, :method => :delete, :data => {:confirm => t('ui.confirm_delete', name: document.name)},
class: 'btn btn-mini btn-danger'

View file

@ -0,0 +1,12 @@
.modal-header
= close_button :modal
%h3= t('.title')
.modal-body
= link_to t('.root_folder'), document_path(@document, parent_id: nil), method: :patch
- Document.walk_tree do |document, level|
- if document.folder?
%br
= ('&nbsp;' * 2 * (level + 1)).html_safe
= link_to document.name, document_path(@document, parent_id: document.id), method: :patch
.modal-footer
= link_to t('ui.close'), '#', class: 'btn', data: {dismiss: 'modal'}

View file

@ -0,0 +1,2 @@
$('#modalContainer').html('#{j(render("move"))}');
$('#modalContainer').modal();

View file

@ -32,3 +32,8 @@ de:
new: Neues Dokument anlegen
new_folder: Neuen Ordner anlegen
title: Dokumente
move:
root_folder: Start
title: Verschieben
update:
notice: Dokument oder Ordner wurde verschoben

View file

@ -33,3 +33,8 @@ en:
new: Upload new document
new_folder: Create new folder
title: Documents
move:
root_folder: Start
title: Move
update:
notice: Document or folder was moved

View file

@ -3,6 +3,7 @@ Rails.application.routes.draw do
scope '/:foodcoop' do
resources :documents do
get :move
get :new
get :new_folder
end