Merge branch 'master' into devel-1.6.1
This commit is contained in:
commit
d545f018a9
@ -37,6 +37,7 @@ require 'redmine_dmsf/patches/role_patch'
|
||||
if defined?(EasyExtensions)
|
||||
require 'redmine_dmsf/patches/easy_crm_case_patch'
|
||||
require 'redmine_dmsf/patches/attachable_patch'
|
||||
require 'redmine_dmsf/patches/easy_crm_cases_controller_patch.rb'
|
||||
end
|
||||
|
||||
# Load up classes that make up our WebDAV solution ontop of DAV4Rack
|
||||
@ -69,9 +70,5 @@ require 'redmine_dmsf/hooks/views/search_view_hooks'
|
||||
require 'redmine_dmsf/hooks/helpers/issues_helper_hooks'
|
||||
require 'redmine_dmsf/hooks/helpers/search_helper_hooks'
|
||||
|
||||
if defined?(EasyExtensions)
|
||||
require 'redmine_dmsf/hooks/controllers/easy_crm_cases_controller_hooks'
|
||||
end
|
||||
|
||||
# Macros
|
||||
require 'redmine_dmsf/macros'
|
||||
|
||||
@ -1,119 +0,0 @@
|
||||
# encoding: utf-8
|
||||
#
|
||||
# Redmine plugin for Document Management System "Features"
|
||||
#
|
||||
# Copyright (C) 2011-17 Karel Pičman <karel.picman@kontron.com>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
module RedmineDmsf
|
||||
module Hooks
|
||||
include Redmine::Hook
|
||||
|
||||
class ControllerEasyCrmCasesHook < RedmineDmsf::Hooks::Listener
|
||||
|
||||
def controller_easy_crm_cases_before_save(context={})
|
||||
if context.is_a?(Hash)
|
||||
easy_crm_case = context[:easy_crm_case]
|
||||
params = context[:params]
|
||||
easy_crm_case.save_dmsf_attachments(params[:dmsf_attachments])
|
||||
easy_crm_case.save_dmsf_links(params[:dmsf_links])
|
||||
easy_crm_case.save_dmsf_attachments_wfs(params[:dmsf_attachments_wfs], params[:dmsf_attachments])
|
||||
easy_crm_case.save_dmsf_links_wfs(params[:dmsf_links_wfs])
|
||||
end
|
||||
end
|
||||
|
||||
def controller_easy_crm_cases_after_save(context={})
|
||||
easy_crm_cases_after_save(context)
|
||||
# Copy documents from the source issue
|
||||
if context.is_a?(Hash)
|
||||
easy_crm_case = context[:easy_crm_case]
|
||||
params = context[:params]
|
||||
copied_from = EasyCrmCase.find_by_id(params[:copy_from]) if params[:copy_from].present?
|
||||
# Save documents
|
||||
if copied_from
|
||||
copied_from.dmsf_files.each do |dmsf_file|
|
||||
dmsf_file.copy_to(easy_crm_case.project, easy_crm_cases.system_folder(true))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def easy_crm_cases_after_save(context)
|
||||
if context.is_a?(Hash)
|
||||
easy_crm_case = context[:easy_crm_case]
|
||||
params = context[:params]
|
||||
# Attach DMS documents
|
||||
uploaded_files = params[:dmsf_attachments]
|
||||
if uploaded_files && uploaded_files.is_a?(Hash)
|
||||
system_folder = easy_crm_case.system_folder(true)
|
||||
uploaded_files.each do |key, uploaded_file|
|
||||
upload = DmsfUpload.create_from_uploaded_attachment(easy_crm_case.project, system_folder, uploaded_file)
|
||||
if upload
|
||||
uploaded_file[:disk_filename] = upload.disk_filename
|
||||
uploaded_file[:name] = upload.name
|
||||
uploaded_file[:title] = upload.title
|
||||
uploaded_file[:version] = 1
|
||||
uploaded_file[:size] = upload.size
|
||||
uploaded_file[:mime_type] = upload.mime_type
|
||||
uploaded_file[:tempfile_path] = upload.tempfile_path
|
||||
if params[:dmsf_attachments_wfs].present? && params[:dmsf_attachments_wfs][key].present?
|
||||
uploaded_file[:workflow_id] = params[:dmsf_attachments_wfs][key].to_i
|
||||
end
|
||||
end
|
||||
end
|
||||
DmsfUploadHelper.commit_files_internal uploaded_files, easy_crm_case.project, system_folder,
|
||||
context[:controller]
|
||||
end
|
||||
# Attach DMS links
|
||||
easy_crm_case.saved_dmsf_links.each do |l|
|
||||
file = l.target_file
|
||||
revision = file.last_revision
|
||||
system_folder = easy_crm_case.system_folder(true)
|
||||
if system_folder
|
||||
l.project_id = system_folder.project_id
|
||||
l.dmsf_folder_id = system_folder.id
|
||||
if l.save
|
||||
easy_crm_case.dmsf_file_added file
|
||||
end
|
||||
wf = easy_crm_case.saved_dmsf_links_wfs[l.id]
|
||||
if wf
|
||||
# Assign the workflow
|
||||
revision.set_workflow(wf.id, 'assign')
|
||||
revision.assign_workflow(wf.id)
|
||||
# Start the workflow
|
||||
revision.set_workflow(wf.id, 'start')
|
||||
if revision.save
|
||||
wf.notify_users(easy_crm_case.project, revision, context[:controller])
|
||||
begin
|
||||
file.lock!
|
||||
rescue DmsfLockError => e
|
||||
Rails.logger.warn e.message
|
||||
end
|
||||
else
|
||||
Rails.logger.error l(:error_workflow_assign)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
@ -30,7 +30,7 @@ module RedmineDmsf
|
||||
attach_documents_form(context)
|
||||
end
|
||||
|
||||
def view_issues_edit_notes_bottom(context={})
|
||||
def view_attachments_form_top(context={})
|
||||
html = ''
|
||||
# Radio buttons
|
||||
if allowed_to_attach_documents(context[:container])
|
||||
@ -48,6 +48,7 @@ module RedmineDmsf
|
||||
html << l(:label_dmsf_attachments)
|
||||
html << '</label>'
|
||||
html << '</p>'
|
||||
html << "<script>$( document ).ready(function() {$('.attachments-container:not(.dmsf_uploader)').parent().hide();})</script>" if User.current.pref.dmsf_attachments_upload_choice == 'DMSF'
|
||||
end
|
||||
# Upload form
|
||||
html.html_safe + attach_documents_form(context, false,
|
||||
@ -59,7 +60,7 @@ module RedmineDmsf
|
||||
show_attached_documents(context[:issue], context[:controller])
|
||||
end
|
||||
|
||||
def view_issues_show_attachments_bottom(context={})
|
||||
def view_issues_show_attachments_table_bottom(context={})
|
||||
unless context[:options][:only_mails].present?
|
||||
show_attached_documents(context[:container], context[:controller], context[:attachments])
|
||||
end
|
||||
@ -138,7 +139,8 @@ module RedmineDmsf
|
||||
# Add Dmsf upload form
|
||||
container = context[:container]
|
||||
if allowed_to_attach_documents(container)
|
||||
html = "<p style=\"#{(User.current.pref[:dmsf_attachments_upload_choice] == 'Attachments') ? 'display: none;' : ''}\">"
|
||||
html = (description ? '<p' : '<div')
|
||||
html << " style=\"#{(User.current.pref[:dmsf_attachments_upload_choice] == 'Attachments') ? 'display: none;' : ''}\">"
|
||||
if label
|
||||
html << "<label>#{l(:label_document_plural)}</label>"
|
||||
html << "<span class=\"attachments-container dmsf_uploader\">"
|
||||
@ -149,7 +151,7 @@ module RedmineDmsf
|
||||
{ :partial => 'dmsf_upload/form',
|
||||
:locals => { :container => container, :multiple => true, :description => description, :awf => true }})
|
||||
html << '</span>'
|
||||
html << '</p>'
|
||||
html << (description ? '</p>' : '</div>')
|
||||
html.html_safe
|
||||
end
|
||||
end
|
||||
@ -256,7 +258,7 @@ module RedmineDmsf
|
||||
:locals => {:file => dmsf_file,
|
||||
:file_approval_allowed => User.current.allowed_to?(:file_approval, dmsf_file.project),
|
||||
:workflows_available => DmsfWorkflow.where(['project_id = ? OR project_id IS NULL', dmsf_file.project.id]).exists?,
|
||||
:project => dmsf_file.project, :wf => wf, :dmsf_link_id => nil }})
|
||||
:project => dmsf_file.project, :wf => wf, :dmsf_link_id => nil }})
|
||||
html << '</td>'
|
||||
html << '</tr>'
|
||||
html
|
||||
|
||||
103
lib/redmine_dmsf/patches/easy_crm_cases_controller_patch.rb
Normal file
103
lib/redmine_dmsf/patches/easy_crm_cases_controller_patch.rb
Normal file
@ -0,0 +1,103 @@
|
||||
module RedmineDmsf
|
||||
module EasyCrmCasesControllerPatch
|
||||
|
||||
def self.included(base)
|
||||
base.send(:include, InstanceMethods)
|
||||
|
||||
base.class_eval do
|
||||
|
||||
before_action :controller_easy_crm_cases_before_save, only: [:create, :update, :bulk_update]
|
||||
after_action :controller_easy_crm_cases_after_save, only: [:create, :update, :bulk_update]
|
||||
|
||||
|
||||
private
|
||||
|
||||
def controller_easy_crm_cases_before_save
|
||||
easy_crm_cases = @easy_crm_cases
|
||||
easy_crm_cases ||= [@easy_crm_case]
|
||||
easy_crm_cases.each do |easy_crm_case|
|
||||
easy_crm_case.save_dmsf_attachments(params[:dmsf_attachments])
|
||||
easy_crm_case.save_dmsf_links(params[:dmsf_links])
|
||||
easy_crm_case.save_dmsf_attachments_wfs(params[:dmsf_attachments_wfs], params[:dmsf_attachments])
|
||||
easy_crm_case.save_dmsf_links_wfs(params[:dmsf_links_wfs])
|
||||
end
|
||||
end
|
||||
|
||||
def controller_easy_crm_cases_after_save
|
||||
easy_crm_cases = @easy_crm_cases
|
||||
easy_crm_cases ||= [@easy_crm_case]
|
||||
easy_crm_cases.each do |easy_crm_case|
|
||||
# Attach DMS documents
|
||||
uploaded_files = params[:dmsf_attachments]
|
||||
if uploaded_files && uploaded_files.is_a?(Hash)
|
||||
system_folder = easy_crm_case.system_folder(true)
|
||||
uploaded_files.each do |key, uploaded_file|
|
||||
upload = DmsfUpload.create_from_uploaded_attachment(easy_crm_case.project, system_folder, uploaded_file)
|
||||
if upload
|
||||
uploaded_file[:disk_filename] = upload.disk_filename
|
||||
uploaded_file[:name] = upload.name
|
||||
uploaded_file[:title] = upload.title
|
||||
uploaded_file[:version] = 1
|
||||
uploaded_file[:size] = upload.size
|
||||
uploaded_file[:mime_type] = upload.mime_type
|
||||
uploaded_file[:tempfile_path] = upload.tempfile_path
|
||||
if params[:dmsf_attachments_wfs].present? && params[:dmsf_attachments_wfs][key].present?
|
||||
uploaded_file[:workflow_id] = params[:dmsf_attachments_wfs][key].to_i
|
||||
end
|
||||
end
|
||||
end
|
||||
DmsfUploadHelper.commit_files_internal uploaded_files, easy_crm_case.project, system_folder, self
|
||||
end
|
||||
# Attach DMS links
|
||||
easy_crm_case.saved_dmsf_links.each do |l|
|
||||
file = l.target_file
|
||||
revision = file.last_revision
|
||||
system_folder = easy_crm_case.system_folder(true)
|
||||
if system_folder
|
||||
l.project_id = system_folder.project_id
|
||||
l.dmsf_folder_id = system_folder.id
|
||||
if l.save
|
||||
easy_crm_case.dmsf_file_added file
|
||||
end
|
||||
wf = easy_crm_case.saved_dmsf_links_wfs[l.id]
|
||||
if wf
|
||||
# Assign the workflow
|
||||
revision.set_workflow(wf.id, 'assign')
|
||||
revision.assign_workflow(wf.id)
|
||||
# Start the workflow
|
||||
revision.set_workflow(wf.id, 'start')
|
||||
if revision.save
|
||||
wf.notify_users(easy_crm_case.project, revision, self)
|
||||
begin
|
||||
file.lock!
|
||||
rescue DmsfLockError => e
|
||||
Rails.logger.warn e.message
|
||||
end
|
||||
else
|
||||
Rails.logger.error l(:error_workflow_assign)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
copied_from = EasyCrmCase.find_by_id(params[:copy_from]) if params[:copy_from].present?
|
||||
# Save documents
|
||||
if copied_from
|
||||
copied_from.dmsf_files.each do |dmsf_file|
|
||||
dmsf_file.copy_to(easy_crm_case.project, easy_crm_cases.system_folder(true))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
end
|
||||
end
|
||||
end
|
||||
Rails.configuration.to_prepare do
|
||||
unless EasyCrmCasesController.included_modules.include?(RedmineDmsf::EasyCrmCasesControllerPatch)
|
||||
EasyCrmCasesController.send(:include, RedmineDmsf::EasyCrmCasesControllerPatch)
|
||||
end
|
||||
end
|
||||
@ -25,9 +25,8 @@ module RedmineDmsf
|
||||
def self.included(base)
|
||||
base.send(:include, InstanceMethods)
|
||||
base.class_eval do
|
||||
safe_attributes 'dmsf_tree_view',
|
||||
'dmsf_attachments_upload_choice'
|
||||
end
|
||||
safe_attributes 'dmsf_tree_view', 'dmsf_attachments_upload_choice' if self.included_modules.include?(Redmine::SafeAttributes)
|
||||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user