diff --git a/after_init.rb b/after_init.rb index 05bd4faf..1630ad13 100644 --- a/after_init.rb +++ b/after_init.rb @@ -26,7 +26,8 @@ def init pmap.permission :user_preferences, {:dmsf_state => [:user_pref_save]} pmap.permission :view_dmsf_files, - {:dmsf => [:entries_operation, :entries_email, :download_email_entries, :tag_changed], + {:dmsf => [:entries_operation, :entries_email, :download_email_entries, :tag_changed, :add_email, + :append_email, :autocomplete_for_user], :dmsf_files => [:show, :view, :thumbnail], :dmsf_workflows => [:log]}, :read => true diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb index 01cb01af..8d4d6520 100644 --- a/app/controllers/dmsf_controller.rb +++ b/app/controllers/dmsf_controller.rb @@ -24,7 +24,8 @@ class DmsfController < ApplicationController before_action :find_project before_action :authorize, :except => [:expand_folder] - before_action :find_folder, :except => [:new, :create, :edit_root, :save_root] + before_action :find_folder, :except => [:new, :create, :edit_root, :save_root, :add_email, :append_email, + :autocomplete_for_user] before_action :find_parent, :only => [:new, :create] before_action :tree_view, :only => [:delete, :show] before_action :permissions @@ -335,8 +336,31 @@ class DmsfController < ApplicationController redirect_to :back end + def add_email + @principals = users_for_new_users + # respond_to do |format| + # format.js + # end + end + + def append_email + @principals = Principal.where(:id => params[:user_ids]).to_a + head 200 if @principals.blank? + end + + def autocomplete_for_user + @principals = users_for_new_users + respond_to do |format| + format.js + end + end + private + def users_for_new_users + Principal.active.visible.member_of(@project).like(params[:q]).order(:type, :lastname).to_a + end + def email_entries(selected_folders, selected_files) begin zip = DmsfZip.new @@ -564,8 +588,6 @@ class DmsfController < ApplicationController copy end - private - def get_display_params @system_folder = @folder && @folder.system @folder_manipulation_allowed = User.current.allowed_to?(:folder_manipulation, @project) @@ -667,4 +689,3 @@ class DmsfController < ApplicationController end end - diff --git a/app/helpers/dmsf_helper.rb b/app/helpers/dmsf_helper.rb index ff64161e..f85a522f 100644 --- a/app/helpers/dmsf_helper.rb +++ b/app/helpers/dmsf_helper.rb @@ -182,4 +182,8 @@ module DmsfHelper end end + def render_principals_for_new_email(users) + principals_check_box_tags 'user_ids[]', users + end + end diff --git a/app/views/dmsf/_add_email.html.erb b/app/views/dmsf/_add_email.html.erb new file mode 100644 index 00000000..1f28a32f --- /dev/null +++ b/app/views/dmsf/_add_email.html.erb @@ -0,0 +1,43 @@ +<% + # encoding: utf-8 + # + # Redmine plugin for Document Management System "Features" + # + # Copyright © 2011-18 Karel Pičman + # + # 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. +%> + +

<%= l(:label_email_address_add) %>

+ +<%= form_tag(append_email_dmsf_path, + :remote => true, + :method => :post, + :id => 'new-user-form') do %> + <%= hidden_field_tag :project_id, @project.id %> + +

<%= label_tag 'user_search', l(:label_user_search) %><%= text_field_tag 'user_search', nil %>

+ <%= late_javascript_tag "observeSearchfield('user_search', 'users_for_users', '#{ escape_javascript url_for( + :controller => 'dmsf', :action => 'autocomplete_for_user', :project_id => @project) }')" %> + +
+ <%= render_principals_for_new_email(@principals) %> +
+ +

+ <%= submit_tag l(:button_add), :name => nil, :onclick => "hideModal(this);" %> + <%= submit_tag l(:button_cancel), :name => nil, :onclick => "hideModal(this);", :type => 'button' %> +

+<% end %> diff --git a/app/views/dmsf/add_email.js.erb b/app/views/dmsf/add_email.js.erb new file mode 100644 index 00000000..57b24026 --- /dev/null +++ b/app/views/dmsf/add_email.js.erb @@ -0,0 +1,25 @@ +<% +# encoding: utf-8 +# +# Redmine plugin for Document Management System "Features" +# +# Copyright © 2011-18 Karel Pičman +# +# 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. +%> + +$('#ajax-modal').html("<%= escape_javascript(render :partial => 'dmsf/add_email', :locals => { :emails => 'xxx'}) %>"); +showModal('ajax-modal', '400px'); +$('#ajax-modal').addClass('new-user'); diff --git a/app/views/dmsf/append_email.js.erb b/app/views/dmsf/append_email.js.erb new file mode 100644 index 00000000..2455cc56 --- /dev/null +++ b/app/views/dmsf/append_email.js.erb @@ -0,0 +1,33 @@ +<% +# encoding: utf-8 +# +# Redmine plugin for Document Management System "Features" +# +# Copyright © 2011-18 Karel Pičman +# +# 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. +%> + +var to = $('#email_to'); +var text = to.val(); +<% @principals.each do |p| %> + if(text.indexOf("<%= p.mail %>") < 0){ + if(text.length > 0){ + text += ', ' + } + text += "<%= p.mail %>" + } +<% end %> +to.val(text); diff --git a/app/views/dmsf/autocomplete_for_user.js.erb b/app/views/dmsf/autocomplete_for_user.js.erb new file mode 100644 index 00000000..68433729 --- /dev/null +++ b/app/views/dmsf/autocomplete_for_user.js.erb @@ -0,0 +1,23 @@ +<% +# encoding: utf-8 +# +# Redmine plugin for Document Management System "Features" +# +# Copyright © 2011-18 Karel Pičman +# +# 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. +%> + +$('#users_for_watcher').html('<%= escape_javascript(render_principals_for_new_email(@principals)) %>'); diff --git a/app/views/dmsf/email_entries.html.erb b/app/views/dmsf/email_entries.html.erb index 0ae1bcbe..7b4a85b1 100644 --- a/app/views/dmsf/email_entries.html.erb +++ b/app/views/dmsf/email_entries.html.erb @@ -41,7 +41,11 @@

<%= label_tag('email[to]', l(:label_email_to)) %> - <%= text_field_tag('email[to]', @email_params[:to], :style => 'width: 90%;', :required => true) %> + + <%= text_field_tag('email[to]', @email_params[:to], :style => 'width: 90%;', :required => true) %> + <%= link_to l(:button_add), add_email_dmsf_path(:project_id => @project), + :title => l(:label_email_address_add), :class => 'icon icon-add', :remote => true %> +

<%= label_tag('email[cc]', l(:label_email_cc)) %> diff --git a/app/views/dmsf_folder_permissions/_new.html.erb b/app/views/dmsf_folder_permissions/_new.html.erb index efac3dc9..dc639fc7 100644 --- a/app/views/dmsf_folder_permissions/_new.html.erb +++ b/app/views/dmsf_folder_permissions/_new.html.erb @@ -1,3 +1,25 @@ +<% + # encoding: utf-8 + # + # Redmine plugin for Document Management System "Features" + # + # Copyright © 2011-18 Karel Pičman + # + # 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. +%> +

<%= l(:label_user_search) %>

<%= form_tag(append_dmsf_folder_permissions_path, diff --git a/app/views/dmsf_folder_permissions/append.js.erb b/app/views/dmsf_folder_permissions/append.js.erb index 7496339a..357d8ba6 100644 --- a/app/views/dmsf_folder_permissions/append.js.erb +++ b/app/views/dmsf_folder_permissions/append.js.erb @@ -1,3 +1,26 @@ +<% +# encoding: utf-8 +# +# Redmine plugin for Document Management System "Features" +# +# Copyright © 2011-18 Karel Pičman +# +# 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. +%> + +$('#users_for_watcher').html('<%= escape_javascript(render_principals_for_new_email(@principals)) %>'); <% @principals.each do |principal| %> $("#user_permission_ids_<%= principal.id %>").remove(); <% end %> diff --git a/app/views/dmsf_folder_permissions/autocomplete_for_user.js.erb b/app/views/dmsf_folder_permissions/autocomplete_for_user.js.erb index c288b4e3..25c76513 100644 --- a/app/views/dmsf_folder_permissions/autocomplete_for_user.js.erb +++ b/app/views/dmsf_folder_permissions/autocomplete_for_user.js.erb @@ -1,2 +1,25 @@ +<% +# encoding: utf-8 +# +# Redmine plugin for Document Management System "Features" +# +# Copyright © 2011-18 Karel Pičman +# +# 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. +%> + +$('#users_for_watcher').html('<%= escape_javascript(render_principals_for_new_email(@principals)) %>'); $('#users_for_watcher').html('<%= escape_javascript( render_principals_for_new_folder_permissions(@principals)) %>'); diff --git a/app/views/dmsf_folder_permissions/new.js.erb b/app/views/dmsf_folder_permissions/new.js.erb index abda4d5f..8be92ac9 100644 --- a/app/views/dmsf_folder_permissions/new.js.erb +++ b/app/views/dmsf_folder_permissions/new.js.erb @@ -1,3 +1,26 @@ +<% +# encoding: utf-8 +# +# Redmine plugin for Document Management System "Features" +# +# Copyright © 2011-18 Karel Pičman +# +# 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. +%> + +$('#users_for_watcher').html('<%= escape_javascript(render_principals_for_new_email(@principals)) %>'); $('#ajax-modal').html('<%= escape_javascript(render :partial => 'dmsf_folder_permissions/new') %>'); showModal('ajax-modal', '400px'); $('#ajax-modal').addClass('new-user'); diff --git a/config/routes.rb b/config/routes.rb index 7aca8660..85b173cb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -49,6 +49,9 @@ if Redmine::Plugin.installed? :redmine_dmsf get '/projects/:id/dmsf/trash', :controller => 'dmsf', :action => 'trash', :as => 'trash_dmsf' get '/projects/:id/dmsf/restore', :controller => 'dmsf', :action => 'restore', :as => 'restore_dmsf' post '/projects/:id/dmsf/expand_folder', :controller => 'dmsf', :action => 'expand_folder', :as => 'expand_folder_dmsf' + get '/projects/:id/dmsf/add_email', :controller => 'dmsf', :action => 'add_email', :as => 'add_email_dmsf' + post '/projects/:id/dmsf/append_email', :controller => 'dmsf', :action => 'append_email', :as => 'append_email_dmsf' + get '/projects/:id/dmsf/autocomplete_for_user', :controller => 'dmsf', :action => 'autocomplete_for_user' # # dmsf_state controller