diff --git a/controllers/myprofile/proposals_discussion_plugin_confirm_tasks_controller.rb b/controllers/myprofile/proposals_discussion_plugin_confirm_tasks_controller.rb index 6fd8bbc..717690d 100644 --- a/controllers/myprofile/proposals_discussion_plugin_confirm_tasks_controller.rb +++ b/controllers/myprofile/proposals_discussion_plugin_confirm_tasks_controller.rb @@ -27,7 +27,7 @@ private if params[:task_id] and request.post? begin task = profile.find_in_all_tasks(params[:task_id]) - task.tag_list = params[:tag_list] + task.tag_list = params[:tag_list] if params[:tag_list].presence task.article_parent_id = params[:article_parent_id] if decision.to_s == 'finish' task.email_template_id = params[:email_template_id] task.send(decision, current_person) diff --git a/controllers/myprofile/proposals_discussion_plugin_evaluate_tasks_controller.rb b/controllers/myprofile/proposals_discussion_plugin_evaluate_tasks_controller.rb index 9562e85..6fbc0ee 100644 --- a/controllers/myprofile/proposals_discussion_plugin_evaluate_tasks_controller.rb +++ b/controllers/myprofile/proposals_discussion_plugin_evaluate_tasks_controller.rb @@ -11,10 +11,19 @@ class ProposalsDiscussionPluginEvaluateTasksController < MyProfileController task = Task.to(profile).find_by_id params[:task_id] - save = task.flag_accept_proposal(current_person) - if save - result = {:success => true } + begin + + save = task.flag_accept_proposal(current_person) + + if save + result = {:success => true } + end + rescue ActiveRecord::RecordInvalid => e + result = { + :success => false, + :message => e.message + } end end @@ -30,10 +39,18 @@ class ProposalsDiscussionPluginEvaluateTasksController < MyProfileController } task = Task.to(profile).find_by_id params[:task_id] - save = task.flag_reject_proposal(current_person) - if save - result = {:success => true } + begin + save = task.flag_reject_proposal(current_person) + + if save + result = {:success => true } + end + rescue ActiveRecord::RecordInvalid => e + result = { + :success => false, + :message => e.message + } end end diff --git a/controllers/myprofile/proposals_discussion_plugin_tasks_controller.rb b/controllers/myprofile/proposals_discussion_plugin_tasks_controller.rb index 0bb8d73..31b9641 100644 --- a/controllers/myprofile/proposals_discussion_plugin_tasks_controller.rb +++ b/controllers/myprofile/proposals_discussion_plugin_tasks_controller.rb @@ -6,13 +6,13 @@ class ProposalsDiscussionPluginTasksController < TasksController @filter_type = params[:filter_type].presence @filter_text = params[:filter_text].presence @filter_responsible = params[:filter_responsible] - @filter_tags = params[:filter_tags] + @filter_categories = params[:filter_categories] @filter_status = params[:filter_status] @view_only = !current_person.has_permission?(:perform_task, profile) || params[:view_only] - @task_tags = [OpenStruct.new(:name => _('All'), :id => nil) ] + Task.all_tags + @task_categories = [OpenStruct.new(:name => _('All'), :id => nil) ] + ProposalsDiscussionPlugin::TaskCategory.all @task_types = Task.pending_types_for(profile) # maps statuses which would be used in status filter @@ -33,8 +33,6 @@ class ProposalsDiscussionPluginTasksController < TasksController @tasks = @tasks.where(:responsible_id => @filter_responsible.to_i != -1 ? @filter_responsible : nil) if @filter_responsible.present? - @tasks = @tasks.tagged_with(@filter_tags, any: true) if @filter_tags.present? - end @tasks = @tasks.paginate(:per_page => Task.per_page, :page => params[:page]) @@ -44,4 +42,35 @@ class ProposalsDiscussionPluginTasksController < TasksController @responsible_candidates = profile.members.by_role(profile.roles.reject {|r| !r.has_permission?('perform_task')}) if profile.organization? end + def save_categories + + if request.post? && params[:tag_list].presence + result = { + success: false, + message: _('Error to save categories. Please, contact the system admin') + } + + categories_list = params[:tag_list].split(',') + task = Task.to(profile).find_by_id params[:task_id] + + categories_data = [] + categories_list.each do |category_name| + category = ProposalsDiscussionPlugin::TaskCategory.find_by_name(category_name) + categories_data << category + end + task.categories = categories_data + save = task.save! + + if save + result = { + success: true, + message: _('Saved with success!') + } + end + end + + render json: result + + end + end diff --git a/lib/proposals_discussion_plugin/proposal_task.rb b/lib/proposals_discussion_plugin/proposal_task.rb index 76f5b9e..4e6112a 100644 --- a/lib/proposals_discussion_plugin/proposal_task.rb +++ b/lib/proposals_discussion_plugin/proposal_task.rb @@ -285,11 +285,15 @@ class ProposalsDiscussionPlugin::ProposalTask < Task self.delay.marked_as_ham end + def categories_list(field = :name) + categories.pluck(field).join(',') if categories.count > 0 + end + protected def require_category if categories.count == 0 && flagged? - errors.add :categories, _( 'Please, select at least one') + errors.add :categories, _('Please, select at least one') end end end diff --git a/views/proposals_discussion_plugin_tasks/_task.html.erb b/views/proposals_discussion_plugin_tasks/_task.html.erb index 10deb9c..48be169 100644 --- a/views/proposals_discussion_plugin_tasks/_task.html.erb +++ b/views/proposals_discussion_plugin_tasks/_task.html.erb @@ -61,7 +61,10 @@
<%= labelled_select(_('Status')+': ', :filter_status, :id, :name, @filter_status, @task_statuses, {:id => 'filter-statuses'}) %>
-- <%= labelled_select(_('Tags')+': ', :filter_tags, :id, :name, @filter_tags, @task_tags, {:id => 'filter-add-tag'}) %> - <%= text_field_tag( :filter_tags, @filter_tags, :size => 36, :class => 'filter-tags' ) %> -
<%= submit_button(:search, _('Search')) %> @@ -197,4 +193,31 @@ } }); } + + jQuery('.task-categories').inputosaurus({ + hideInput: true, + submitTags: { + url: '/myprofile/'+<%= "'#{profile.identifier}'" %>+'/plugin/proposals_discussion/tasks/save_categories', + beforeSend: function(){ + + $('.ok').parent().remove(); + + this.element.parents('.task_box') + .prev('.fg-state-error') + .remove(); + + Task.addIcon(this,'loading'); + + //Add loading here! + }, + success: Task.onAddTag + } + }); + + $('.add-category').change(function(){ + + if($(this).val() != ''){ + $(this).next('ul').find('.task-categories').inputosaurus('addTags',$(this).children(':selected').text()); + } + }); -- libgit2 0.21.2