<%
helperObj = Object.new.extend(WksurveyHelper)

unless controller_name == "wksurvey"
    @all_surveys = helperObj.surveyList(params)
end

if params[:isIssue]
    style = "list issues odd-even"
else
    style = "list time-entries"
end
%>
<table class="<%= style %>">
    <tr>
        <th>#</th>
        <% if ["index", "user_survey"].include? action_name %>
            <%= sort_header_tag('survey', :caption => l(:label_survey), class: "lbl-txt-align") %>
            <%= sort_header_tag('status', :caption => l(:field_status)) %>
        <% else %>
            <th class="lbl-txt-align"><%= l(:label_survey) %></th>
            <th><%= l(:field_status) %></th>
        <% end %>
        <th></th>
    </tr>
    <% @all_surveys.each_with_index do |entry, index| %>
        <% urlhash = { :survey_id => entry.id, :surveyForType => entry.survey_for_type, :surveyForID => entry.survey_for_id, id: entry.id} %>
        <% surveyLink = helperObj.get_survey_with_userGroup(entry.id, false) %>
        <tr>
            <td><%=h index+1 %></td>
            <td class="lbl-txt-align">
                <% if surveyLink.blank? || (@surveyForID.blank? && !@surveyForType.blank?) %>
                    <%=h entry.name %>
                <% else %>
                    <%=h link_to entry.name, url_for(helperObj.get_survey_url(urlhash, params, "survey")) %>
                <% end %>
            </td>
            <td><%=h helperObj.getSurveyStatus.invert[entry.status] %></td>
            <td class="lbl-txt-align">
                <% if !entry.hide_response && (["O","C"].include? entry.status) %>
                    <%= link_to image_tag("withoutcommant.png", :plugin => "redmine_wktime"),
                        url_for(helperObj.get_survey_url(urlhash, params, "survey_response")), :title => l(:label_survey_response) %>&emsp;
                <% else %>&emsp;&emsp;&nbsp;
                <% end %>
                <% if (entry.status == "O" && helperObj.validateERPPermission("E_SUR")) || entry.status == "C" || helperObj.getResponseGroup(entry.id).present? %>
                    <%= link_to image_tag("stats.png"), url_for(helperObj.get_survey_url(urlhash, params, "survey_result")),
                        :title => l(:label_survey_result) %>&emsp;
                <% else %>&emsp;&emsp;&nbsp;
                <% end %>
                <% if helperObj.checkEditSurveyPermission && params[:isIssue].blank? %>
                    <%= link_to image_tag('edit.png'), url_for(helperObj.get_survey_url(urlhash, params, "edit")),
                        :title => l(:button_edit) %>&emsp;
                    <%= link_to image_tag('delete.png'), url_for(helperObj.get_survey_url(urlhash, params, "destroy")),
                        :data => {:confirm => l(:text_are_you_sure)}, method: "delete", :title => l(:button_delete) %>
                <% end %>
            </td>
        </tr>
    <% end %>
</table>