<% layout('/layouts/default.html', {title: '问卷调查选项表管理', libs: ['validate','dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i> ${text(adminQuestionOption.isNewRecord ? '新增问卷调查选项' : '编辑问卷调查选项')}
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${adminQuestionOption}" action="${ctx}/admin/adminQuestionOption/save" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
				<#form:hidden path="questionoptionId"/>
				<div class="row">
					<!--<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('问卷调查项ID')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="questionitemId" class="form-control required digits"/>
							</div>
						</div>
					</div>-->
					<!--<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('标题')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="title" maxlength="255" class="form-control"/>
							</div>
						</div>
					</div>-->
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide" readonly="true">*</span> ${text('调查问卷项标题')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="itemTitle" maxlength="255" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required hide">*</span> ${text('问卷调查项ID')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:input path="questionitemId.questionitemId" maxlength="255" class="form-control"/>
						</div>
					</div>
				</div>
				<!--<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('内容')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:textarea path="content" rows="4" class="form-control"/>
							</div>
						</div>
					</div>
				</div>-->
				<!--<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('是否为输入框')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:radio path="isInput" dictType="admin_questionnaire_option_input" class="form-control" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('单选/多选')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:radio path="maxSelected" dictType="admin_questionnaire_option" class="form-control digits" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('是否问答题')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:radio path="isEssay" dictType="admin_questionnaire_answers" class="form-control" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('得票数')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="count" class="form-control digits"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('排序')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="seq" class="form-control digits"/>
							</div>
						</div>
					</div>
				</div>-->
				<!--<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('备注')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:textarea path="remarks" rows="4" maxlength="255" class="form-control"/>
							</div>
						</div>
					</div>
				</div>-->

				<h4 class="form-unit">${text('问卷调查选项')}</h4>
				<div class="ml10 mr10 table-form">
					<table id="adminQuestionOptionDataGrid"></table>
					<a href="#" id="adminQuestionOptionDataGridAddRowBtn" class="btn btn-primary btn-sm mt10 mb10"><i
							class="fa fa-plus"></i> ${text('增行')}</a>
				</div>
			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
							<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
$("#inputForm").validate({
	submitHandler: function(form){
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.page();
				});
			}
		}, "json");
    }
});

//初始化问卷调查选择项表DataGrid对象
$("#adminQuestionOptionDataGrid").dataGrid({

	data: ${toJson(adminQuestionOption)},
	datatype: "local", // 设置本地数据
	autoGridHeight: function () {
		return 'auto'
	}, // 设置自动高度

	// 设置数据表格列
	columnModel: [
		{header: '主键', name: 'questionoptionId', editable: true, hidden: true},
		{header: '外键', name: 'questionitemId.id', editable: true, hidden: true },
		{header: '${text("问卷调查项ID")}', name: 'questionitemId.id', editable: true, hidden: true},
		{header: '${text("标题")}', name: 'title', editable: true, hidden: false},
		{
            header: '${text("选项")}', name: 'maxSelected', width: 100,
            editable: true, edittype: 'radio', editoptions: {
                'class': 'form-control digits icheck required',
                items: $.merge([], ${@DictUtils.getDictListJson('admin_questionnaire_option')}),
                itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function (element) {
                    js.iCheck(element).on("ifChanged", function () {
                        $(this).resetValid()
                    });
                }
            }
        },
		{
            header: '${text("是否问答题")}', name: 'isEssay', width: 100,
            editable: true, edittype: 'radio', editoptions: {
                'class': 'form-control icheck required',
                items: $.merge([], ${@DictUtils.getDictListJson('admin_questionnaire_answers')}),
                itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function (element) {
                    js.iCheck(element).on("ifChanged", function () {
                        $(this).resetValid()
                    });
                }
            }
        },
		{
			header: '${text("排序")}',
			name: 'seq',
			width: 150,
			editable: true,
			edittype: 'text',
			editoptions: {'class': 'form-control digits'}
		},
		{
			header: '${text("备注")}',
			name: 'remarks',
			width: 150,
			editable: true,
			edittype: 'textarea',
			editoptions: {'maxlength': '255', 'class': 'form-control', 'rows': '1'}
		},
		{
			header: '${text("操作")}',
			name: 'actions',
			width: 80,
			align: 'center',
			formatter: function (val, obj, row, act) {
				var actions = [];
				if (val == 'new') {
					actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#adminQuestionOptionDataGrid\').dataGrid(\'delRowData\',\'' + obj.rowId + '\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
				} else {
					actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？王龙超")}\', function(){$(\'#adminQuestionOptionDataGrid\').dataGrid(\'setRowData\',\''+obj.rowId+'\',null,{display:\'none\'});$(\'#'+obj.rowId+'_status\').val(\''+Global.STATUS_DELETE+'\');});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
				}
				return actions.join('');
			},
			editoptions: {defaultValue: 'new'}
		}
	],
	// 编辑表格参数
	editGrid: true,				// 是否是编辑表格
	editGridInitRowNum: 1,		// 编辑表格的初始化新增行数
	editGridAddRowBtn: $('#adminQuestionOptionDataGridAddRowBtn'),	// 子表增行按钮
	editGridAddRowBtnToHeader: true,	// 子表增行按钮是否显示到表头上
	editGridAddRowInitData: {questionoptionId: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据
	// 编辑表格的提交数据参数
	editGridInputFormListName: 'adminQuestionOption', // 提交的数据列表名
	editGridInputFormListAttrs: 'questionoptionId,questionitemId.questionitemId,maxSelected,isEssay,seq,', // 提交数据列表的属性字段

	// 加载成功后执行事件
	ajaxSuccess: function (data) {

	}
});
</script>