<!doctype html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>Document</title>
		<link rel="stylesheet" href="../../../../../css/base.css">
		<style type="text/css" >
			fieldset{ padding: 20px; font-family: 'Microsoft Yahei';}
			.control-group{ margin-bottom: 10px; }
			.xcr { color: #E26F50; }
		</style>
	</head>
	<body>
		<fieldset>
			<form class="form-horizontal">
				<div class="control-group">
					<label for="control_date_title"><var id="lang_control_title"></var> <span class="xcr">*</span></label>
					<input type="text" id="control_date_title">
				</div>
				<div class="control-group">
					<label for="control_date_width"><var id="lang_control_style"></var></label>
					<div class="input-group">
						<input type="text" id="control_date_width">
						<span class="input-group-addon"><var id="lang_control_width"></var></span>
					</div>
				</div>
				<div class="control-group">
					<label for="control_date_format"><var id="lang_date_format"></var>:</label>
					<select id="control_date_format">
						<option value="yyyy-mm-dd hh:ii:ss"></option>
						<option value="yyyy-mm-dd hh:ii"></option>
						<option value="yyyy-mm-dd hh"></option>
						<option value="yyyy-mm-dd"></option>
						<option value="yyyy-mm"></option>
						<option value="yyyy"></option>
					</select>
				</div>
			</form>
		</fieldset>
		<script src="../../../../src/core.js"></script>
		<script src="../../../../src/base.js"></script>
		<script src="../../../../src/common.js"></script>
		<script src="../fc.js"></script>
		<script src="../internal_controls.js"></script>
		<script>
			var G = parent.G;
			(function() {
				var tpl = '<ic data-id="<%=id%>" data-type="date" data-title="<%=title%>" data-date-format="<%=format%>" data-width="<%=width%>" contenteditable="false" >' +
						'<span class="fake-date" style="width: <%=width%>px" title="<%=title%>"><%=formatText%></span></ic>',
						fc = new Fc(editor, tpl),
						editing = UE.plugins['formcontrols'].editing,
						oldData;

				// 编辑时， 需要还原各控件的值
				if (editing) {
					// 从节点获取之前的值
					oldData = fc.getControlData(editing);
					$G('control_date_title').value = oldData.title;
					$G('control_date_format').value = oldData.dateFormat;
					$G('control_date_width').value = oldData.width;
				}

				dialog.onok = function() {
					var data, title = $G('control_date_title').value;
					if ($.trim(title) === "") {
						alert(editor.getLang("fc.noNameTip"));
						return false;
					}
					data = {
						title: title,
						format: $G('control_date_format').value,
						formatText: $G('control_date_format').options[$G('control_date_format').selectedIndex].text || "",
						width: Number($G('control_date_width').value) || 200
					};
					// 如果是编辑状态，则更新数据与视图，否则新增控件
					if (editing) {
						data.id = oldData.id;
						fc.updateContorl(editing, data);
						delete UE.plugins['formcontrols'].editing
						dialog.close();
					} else {
						$('body').waitingC();
						$.get(Ibos.app.url('workflow/api/getNextItemID', {id: parent.Ibos.app.g('formid')}), function(res) {
							$('body').stopWaiting();
							if (res.isSuccess) {
								data.id = res.id;
								fc.addControl(data);
								dialog.close();
							} else {
								alert(editor.getLang("fc.addError"));
							}
						}, 'json');
					}
					return false;
				};
			})();
		</script>
	</body>
</html>