-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathQuestionEditHelper.php
More file actions
156 lines (147 loc) · 4.72 KB
/
QuestionEditHelper.php
File metadata and controls
156 lines (147 loc) · 4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/**
* Question Edit Helper
*
* @author Noriko Arai <arai@nii.ac.jp>
* @author Allcreator Co., Ltd. <info@allcreator.net>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/
App::uses('AppHelper', 'View/Helper');
/**
* Question edit Helper
*
* @author Allcreator Co., Ltd. <info@allcreator.net>
* @package NetCommons\Registrations\View\Helper
*/
class QuestionEditHelper extends AppHelper {
/**
* Other helpers used by FormHelper
*
* @var array
*/
public $helpers = array(
'NetCommonsForm',
'Form'
);
/**
* 質問属性設定作成
*
* @param string $fieldName フィールド名
* @param string $title 見出しラベル
* @param array $options INPUT要素に与えるオプション属性
* @param string $label checkboxの時のラベル
* @return string HTML
*/
public function questionInput($fieldName, $title, $options, $label = '') {
$ret = '<div class="row form-group"><label class="col-sm-2 control-label">' . $title;
if (isset($options['required']) && $options['required'] == true) {
$ret .= $this->_View->element('NetCommons.required');
}
$ret .= '</label><div class="col-sm-10">';
$type = $options['type'];
if ($this->_View->viewVars['isPublished']) {
$disabled = 'disabled';
$options = Hash::remove($options, 'ui-tinymce');
} else {
$disabled = '';
}
if ($type == 'checkbox') {
$ret .= '<div class="checkbox ' . $disabled . '"><label>';
}
//if ($type == 'wysiwyg') {
// $ret .= '<div class="nc-wysiwyg-alert">';
//}
$options = Hash::merge($options, array('div' => false, 'label' => false));
//$ret .= $this->NetCommonsForm->input($fieldName, $options);
if ($type == 'wysiwyg') {
$ret .= $this->NetCommonsForm->wysiwyg($fieldName, $options);
} else {
$ret .= $this->NetCommonsForm->input($fieldName, $options);
}
if ($type == 'checkbox') {
$ret .= $label . '</label></div>';
}
//if ($type == 'wysiwyg') {
// $ret .= '</div>';
//}
$ret .= '</div></div>';
return $ret;
}
/**
* 登録フォーム属性設定作成
*
* @param string $fieldName フィールド名
* @param string $label checkboxの時のラベル
* @param array $options INPUT要素に与えるオプション属性
* @param string $help 追加説明文
* @return string HTML
*/
public function registrationAttributeCheckbox($fieldName, $label, $options = array(), $help = '') {
$ngModel = 'registrations.registration.' . Inflector::variable($fieldName);
$ret = '<div class=" checkbox"><label>';
$options = Hash::merge(array(
'type' => 'checkbox',
'div' => false,
'label' => false,
'class' => '',
'error' => false,
'ng-model' => $ngModel,
//'ng-checked' => $ngModel . '==' . RegistrationsComponent::USES_USE,
'ng-false-value' => '"0"', // この記述でないと チェックON,OFFが正常に動作しない。
'ng-true-value' => '"1"'
),
$options
);
$ret .= $this->NetCommonsForm->input($fieldName, $options);
$ret .= $label;
if (!empty($help)) {
$ret .= '<span class="help-block">' . $help . '</span>';
}
$ret .= '</label>';
$ret .= '<div class="has-error">' . $this->NetCommonsForm->error($fieldName, null, array('class' => 'help-block')) . '</div>';
$ret .= '</div>';
return $ret;
}
/**
* 登録フォーム期間設定作成
*
* @param string $fieldName フィールド名
* @param string $label checkboxの時のラベル
* @param array $minMax 日時指定の範囲がある場合のmin, max
* @param string $help 追加説明文
* @return string HTML
*/
public function registrationAttributeDatetime($fieldName, $label, $minMax = array(), $help = '') {
$ngModel = 'registrations.registration.' . Inflector::variable($fieldName);
$options = array('type' => 'text',
'id' => $fieldName,
'class' => 'form-control',
'placeholder' => 'yyyy-mm-dd',
'show-weeks' => 'false',
'ng-model' => $ngModel,
'datetimepicker',
'datetimepicker-options' => "{format:'YYYY-MM-DD HH:mm'}",
'show-meridian' => 'false',
'label' => $label,
'div' => false);
if (! empty($minMax)) {
$min = $minMax['min'];
$max = $minMax['max'];
$options = Hash::merge($options, array(
'min' => $min,
'max' => $max,
'ng-focus' => 'setMinMaxDate($event, \'' . $min . '\', \'' . $max . '\')',
));
}
$ret = $this->_View->element('NetCommons.datetimepicker');
$ret .= '<div class="form-group "><div class="input-group">';
$ret .= $this->NetCommonsForm->input($fieldName, $options);
if (!empty($help)) {
$ret .= '<span class="help-block">' . $help . '</span>';
}
$ret .= '<div class="input-group-addon"><i class="glyphicon glyphicon-calendar"></i></div></div></div>';
return $ret;
}
}