index.html.erb 7.03 KB
<%= stylesheet_link_tag 'tasks' %>

<h1><%= _("%s's pending tasks") % profile.name %></h1>
<p>

<%
  type_collection = [[nil, _('All')]] + @task_types
%>

<% if !@failed.blank? %>
  <div id="errorExplanation">
    <% @failed.each do |error, tasks_descriptions|%>
      <h2> <%= error %></h2>
      <p><%=_("This error happened with the following tasks: ")%></p>
      <ul>
        <% tasks_descriptions.each do |description| %>
            <li> <%= description %> </li>
        <% end %>
      </ul>
    <% end %>
  </div>
<% end %>

<% unless @view_only %>
  <%= form_tag '#', :method => 'get' do %>
    <%= field_set_tag _('Filter'), :class => 'filter_fields' do %>
      <p>
        <%= labelled_select(_('Type of task')+': ', :filter_type, :first, :last, @filter_type,  type_collection, {:id => 'filter-type'}) %>
      </p>
      <p>
        <%= labelled_text_field(_("Text filter")+': ', :filter_text, nil, {:id => 'filter-text',:value => @filter_text}) %>
      </p>
      <% if profile.organization? %>
        <p>
          <%= labelled_select(_('Assigned to')+': ', :filter_responsible, :id, :name, @filter_responsible, [OpenStruct.new(:name => _('All'), :id => nil), OpenStruct.new(:name => _('Unassigned'), :id => -1)] + @responsible_candidates, :class => 'filter_responsible') %>
        </p>
      <% end %>
      <p>
        <%= labelled_select(_('Status')+': ', :filter_status, :id, :name, @filter_status, @task_statuses, {:id => 'filter-statuses'}) %>
      </p>

      <p>
        <%= submit_button(:search, _('Search')) %>
      </p>
    <% end %>
  <% end %>
<% end %>
<% if @tasks.empty? %>
  <p>
    <em><%= _('No pending tasks for %s') % profile.name %></em>
  </p>
<% else %>
  <%= form_tag :action => 'close' do%>
    <% button_bar(:class => 'task-actions') do %>
      <%# FiXME button(:edit, _('View my requests'), :action => 'list_requested') %>
      <%# FIXME button('menu-mail',  _('Send request'), :action => 'new') %>
      <%= submit_button :save, _("Apply!") %>
      <%= button(:edit, _('View processed tasks'), :action => 'processed') %>
      <%= button(:back, _('Back to control panel'), :controller => 'profile_editor') %>
    <% end unless @view_only %>

    <ul class='task-list'>
      <% unless @view_only %>
        <p>
        <%= labelled_select(_("Set all to: "), 'set-decisions', 'first', 'last', nil, [['',""],['accept',_("Accept")],['reject',_("Reject")],['skip',_("Skip")]], :id => "up-set-all-tasks-to") %>
        </p>
      <% end %>

      <div class="task_boxes">
        <%= render :partial => 'task', :collection => @tasks %>
      </div>

      <% unless @view_only %>
        <p>
        <%= labelled_select(_("Set all to: "), 'set-decisions', 'first', 'last', nil, [['',""],['accept',_("Accept")],['reject',_("Reject")],['skip',_("Skip")]], :id => "down-set-all-tasks-to") %>
        </p>
      <% end %>
    </ul>

    <script>
      jQuery('.tag-list').inputosaurus({
        autoCompleteSource: <%= "'/myprofile/#{profile.identifier}/cms/search_tags'," %>
        activateFinalResult : true
      })
    </script>

    <%= pagination_links(@tasks)%>

    <% button_bar(:class => 'task-actions') do %>
      <%# FiXME button(:edit, _('View my requests'), :action => 'list_requested') %>
      <%# FIXME button('menu-mail',  _('Send request'), :action => 'new') %>
      <%= submit_button :save, _("Apply!") %>
      <%= button(:edit, _('View processed tasks'), :action => 'processed') %>
      <%= button(:back, _('Back to control panel'), :controller => 'profile_editor') %>
    <% end unless @view_only %>
  <% end %>
<% end %>
</p>


<%= javascript_include_tag 'tasks' %>

<script type="text/javascript">
  Task.showTags({
    profileIdentifier: <%= "'#{profile.identifier}'" %>
  })

  $('div.evaluation_button').on('click', null, function(){
    toggleEvaluation(this);
  });


  $('div.confirm_evaluation_button a').on('click', null, function(){
    evaluate_task(this);
  });

  function toggleEvaluation(el){
    var task_id = $(el).data('task-id');
    var taskElement = $('#task-' + task_id);
    //var status_id = $(el).data('status-id')
    //taskElement.data('status_evaluated', status_id);

    taskElement.find('div.evaluation_button').removeClass('checked');

    taskElement.find('div.confirm_evaluation_button a').removeClass('disabled');

    var checkedButton =   $(el);
    checkedButton.addClass("checked");

    var flag_action = checkedButton.data('flag-action');
    var animation_options = {duration:'fast', queue: true};
    if(flag_action == 'approve_proposal'){
      $('#on-reject-information-' + task_id).hide(animation_options);
      $('#on-skip-information-'   + task_id).hide(animation_options);
      $('#on-accept-information-' + task_id).show(animation_options);

    } else if(flag_action == 'reprove_proposal') {
      $('#on-skip-information-' + task_id).hide(animation_options);
      $('#on-accept-information-'   + task_id)
        .hide(
          {
            duration:'fast',
            complete: function() {
                $('#on-reject-information-' + task_id).show('fast');
            }
          });

    }
  }


  function evaluate_task(el) {

    if($(el).hasClass('disabled')) {
      return false;
    }

    var url = $(el).data('href');

    var task_id = $(el).data('task-id');

    var taskElement = $('#task-' + task_id);

    var checkedButton = taskElement.find("div.evaluation_button.checked");

    var flag_action = checkedButton.data('flag-action');

    var form = $(el).closest("form");

    var tag_list = form.find("input.tag-list[type='text']").val();

    var params = {
      task_id: task_id,
      tag_list: tag_list
    };

    if(flag_action == 'approve_proposal'){
      params['article_parent_id'] = form.find('#tasks_' + task_id + '_task_article_parent_id').val();
      params['email_template_id'] = form.find('#on-accept-information-'+task_id+' #tasks_' + task_id + '_task_email_template_id').val();
    } else if(flag_action == 'reprove_proposal') {
      params['email_template_id'] = form.find('#on-reject-information-'+task_id+' #tasks_' + task_id + '_task_email_template_id').val();
    }

    jQuery.post(url + "/" + flag_action, params  ,
      function(data) {
        if (data.success) {
          $(el).effect("highlight");
          taskElement.fadeOut();
        } else {
          $(el).effect("highlight", {color: 'red'});
        }
        if (data.message) {
          display_notice(data.message);
        }
    });
  }

  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());
    }
  });
</script>