<%= javascript_include_tag 'survey', :plugin => "redmine_wktime" %>
<%= stylesheet_link_tag 'wk-time', :plugin => "redmine_wktime" %>

<% 	@isBlankSurvey = @survey.blank?
	survey_name = @isBlankSurvey ? nil : @survey.name
	status = @isBlankSurvey ? nil : @survey.status
	survey_id = @isBlankSurvey ? nil : @survey.id
	group_id = @isBlankSurvey ? '' : @survey.group_id
	isDisable = @isBlankSurvey ? false : @survey.status != 'N'
	recur = @isBlankSurvey ? false : @survey.recur
	recur_every = @isBlankSurvey ? nil : @survey.recur_every
	survey_for = @isBlankSurvey ? @surveyForType : @survey.survey_for_type
	survey_for_id = @isBlankSurvey ? @surveyForID : @survey.survey_for_id
	is_review =  @isBlankSurvey ? false : @survey.is_review
%>
<% if @survey.blank?%>
	<%= title l(:label_new_survey) %>
<% else %>
	<%= title l(:label_edit_survey) %>
<% end %>

<%= form_tag({:controller => 'wksurvey', :action => 'save_survey'}, :method => :post, :id => 'survey_form') do %>
	<%=h hidden_field_tag('project_id', params[:project_id]) %>
	<%=h hidden_field_tag('survey_id', survey_id) %>
	<%=h hidden_field_tag('delete_question_ids', "") %>

	<fieldset class="box tabular">
	<table>
		<tr>
		<th align="left"><%= l(:label_survey_name) %><span style="color:red;">*</span></th>
		<td align="left">
			<%=h text_field_tag("survey_name", survey_name, :disabled => isDisable, :size => "40%", :maxlength => 100) %>
		</td>
		<tr>
		<th align="left"><%= l(:label_survey_for) %></th>
		<td>
			<%=h select_tag("survey_for", options_for_select(getSurveyFor, survey_for), :disabled => isDisable) %>
			<%=h text_field_tag("survey_for_id", survey_for_id, :disabled => isDisable, :size => 3, :maxlength => 30) %>
			<span id="SurveyFor"></span>
			<%=h hidden_field_tag('IsSurveyForValid', false) %>
		</td>
				</tr>
				<tr>
						<th align="left"><%= l(:field_status) %></th>
						<td align="left">
							<%=h select_tag("survey_status", options_for_select(getSurveyStatus.drop(1), status)) %>
						</td>
				</tr>
		<tr>
			<th align="left"><%= l(:label_user_group) %></th>
			<td>
				<%=h select_tag('group_id', options_for_select(getUserGroup, :selected => group_id), :disabled => isDisable) %>
				<%=h hidden_field_tag('user_group', group_id) %>
			</td>
			<td></td>
		</tr>
		<tr>
			<th align="left"><%= l(:label_recur) %></th>
			<td>
				<%= check_box_tag 'recur', true, recur, :disabled => isDisable  %>
				<span id="tr_recur_every">
					<b><%= l(:label_recur_every) %></b>
					<%=h text_field_tag("recur_every", recur_every, :size => "3", :maxlength => 10, :disabled => isDisable) %>&nbsp;<b><%= l(:label_day_plural) %></b> &nbsp;
          <% if @isBlankSurvey ? false : @survey.status == 'O'%>
						<%= link_to l(:label_clos_curr_resp), "javascript:addGrpName();" %>
					<% end %>
				</span>
			</td>
		</tr>
		<tr>
		<th align="left"><%= l(:label_review) %></th>
		<td><%= check_box_tag 'review', true, is_review, :disabled => isDisable %></td>
		</tr>
		<tr>
			<th align="left"><%= l(:label_save_allowed) %></th>
			<td>
				<%= check_box_tag 'save_allowed', true, @survey.try(:save_allowed), :disabled => isDisable  %>
			</td>
		</tr>
		<tr>
			<th align="left"><%= l(:label_hide_response) %></th>
			<td>
				<%= check_box_tag 'hide_response', true, @survey.try(:hide_response), :disabled => isDisable  %>
			</td>
		</tr>
	</table>
	</fieldset>

	<div id="accordion">
		<%= render :partial => "question_accordion_section", :locals => {:isDisable => isDisable} %>
	</div>

	<div>
		<%= submit_tag l(:button_save), :id => 'wksurvey_save' %>
		<%= link_to l(:button_email_user), "javascript:showConfirmationDlg();", :class => 'icon icon-email-add'%>
	</div>
<% end %>

<%= render :partial => 'question_section_template' %>

<% userGroupName = group_id.blank? ? l(:all_users_for_select) : getUserGroup.invert[group_id] + " Group" %>
<div id="reminder-email-dlg" title="<%=l(:label_email_users) %>">
	<fieldset>
		<p> <label><%= l(:field_notes) %></label>
			<textarea name="email_notes" id="email_notes" value="" style="width: 300px;min-height: 35px;"> </textarea>
		</p>
		<p>
			<%=h check_box_tag("includeUserGroup", 1, true) %>
			<%=h l(:label_include_user_group) %> <label for="includeUserGroup"><%=h userGroupName %></label>
		</p>
		<p> <label><%= l(:label_additional_emails) %></label>
			<textarea name="additional_emails" id="additional_emails" value="" style="width: 300px;min-height: 35px;"> </textarea>
		</p>
	</fieldset>
	<div id="dialog-confirm">
  		<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0px 10px 0px 10px;"></span>Do you want to continue?</p>
	</div>
</div>

<div id="add-grp-name" title="<%=l(:label_alert)%>">
	<%= form_tag({action: 'close_current_response'}, method: :post, id: 'closedResp_form') do %>
	<%= hidden_field_tag('survey_id', survey_id) %>
		<fieldset>
			<p> <label><%= l(:label_grp_name) %></label>
				<input type="text" name="grp_name" id="grp_name" value="" maxlength="255">
			</p>
		</fieldset>
		<div id="dialog-confirm">
			<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0px 10px 0px 10px;"></span><%= l(:label_warning_clos_responses) %></p>
		</div>
	<% end %>
</div>
