ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilAsyncPropertyFormGUI.php
Go to the documentation of this file.
1<?php
2require_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
3
11{
15 protected static $js_path = "./Modules/StudyProgramme/templates/js/";
16
20 protected static $default_from_name = "async_form";
21
25 protected static $js_on_load_added = array();
26
30 protected $has_errors = false;
31
35 protected $is_async = true;
36
37 public function __construct(array $config = array(), $is_async = true)
38 {
40
41 foreach ($config as $key => $value) {
42 $setterMethod = "set" . ucfirst($key);
43 if (method_exists($this, $setterMethod)) {
44 $setterMethod($value);
45 }
46 }
47
48 $this->setAsync($is_async);
49 $this->setName(self::$default_from_name);
50 }
51
52
60 public static function addJavaScript($add_form_loader = false, $js_base_path = null)
61 {
62 global $DIC;
63 $tpl = $DIC['tpl'];
64
65 $js_path = (isset($js_base_path))? $js_base_path : self::$js_path;
66
67 $tpl->addJavaScript($js_path . 'ilAsyncPropertyFormGUI.js');
68
69 $global_config = "$.ilAsyncPropertyForm.global_config.error_message_template = '" . self::getErrorMessageTemplate() . "'; $.ilAsyncPropertyForm.global_config.async_form_name = '" . self::$default_from_name . "';";
70 self::addOnLoadCode('global_config', $global_config);
71
72 if ($add_form_loader) {
73 self::addOnLoadCode('form_loader', '$("body").ilAsyncPropertyForm();');
74 }
75 }
76
77
83 public function checkInput()
84 {
85 $result = parent::checkInput();
86 $this->has_errors = $result;
87
88 return $result;
89 }
90
96 public function getErrors()
97 {
98 if (!$this->check_input_called) {
99 $this->checkInput();
100 }
101
102 $errors = array();
103 foreach ($this->getItems() as $item) {
104 // We call method exists as there are items in the form (ilFormSectionHeaderGUI)
105 // that do not have alerts. (#16956)
106 if (method_exists($item, "getAlert") && $item->getAlert() != "") {
107 $errors[] = array('key' => $item->getFieldId(), 'message' => $item->getAlert());
108 }
109 }
110 return $errors;
111 }
112
118 public function hasErrors()
119 {
120 return $this->has_errors;
121 }
122
123
129 public static function getErrorMessageTemplate()
130 {
131 global $DIC;
132 $lng = $DIC['lng'];
133
134 $tpl = new ilTemplate("tpl.property_form.html", true, true, "Services/Form");
135
136 $tpl->setCurrentBlock("alert");
137 $tpl->setVariable("IMG_ALERT", ilUtil::getImagePath("icon_alert.svg"));
138 $tpl->setVariable("ALT_ALERT", $lng->txt("alert"));
139 $tpl->setVariable("TXT_ALERT", "[TXT_ALERT]");
140 $tpl->parseCurrentBlock();
141 $content = trim($tpl->get("alert"));
142
143 return $content;
144 }
145
154 public function cloneForm(ilPropertyFormGUI $form_to_clone)
155 {
156 if (count($this->getItems()) > 0) {
157 throw new ilException("You cannot clone into a already filled form!");
158 }
159
160 $reflect = new ReflectionClass($this);
161 $properties = $reflect->getProperties(ReflectionProperty::IS_PUBLIC);
162
163 foreach ($properties as $property) {
164 $this->{$property->getName()} = $property->getValue($form_to_clone);
165 }
166
167 foreach ($form_to_clone->getItems() as $item) {
168 $this->addItem($item);
169 }
170
171 foreach ($form_to_clone->getCommandButtons() as $button) {
172 $this->addCommandButton($button['cmd'], $button['text']);
173 }
174
175 return $this;
176 }
177
178
185 protected static function addOnLoadCode($id, $content)
186 {
187 global $DIC;
188 $tpl = $DIC['tpl'];
189
190 if (!isset(self::$js_on_load_added[$id])) {
191 $tpl->addOnLoadCode($content);
192 self::$js_on_load_added[$id] = $content;
193 }
194 }
195
201 public function getHTML()
202 {
204
205 return parent::getHTML();
206 }
207
213 public function isSubmitted()
214 {
215 if (isset($_POST['cmd'])) {
216 return true;
217 }
218 return false;
219 }
220
221
228 public function setFormAction($a_formaction)
229 {
230 if ($this->isAsync()) {
231 $a_formaction .= "&cmdMode=asynch";
232 }
233
234 $this->formaction = $a_formaction;
235 }
236
240 public function getJsPath()
241 {
242 return $this->js_path;
243 }
244
248 public function setJsPath($js_path)
249 {
250 $this->js_path = $js_path;
251 }
252
256 public function getDefaultFormName()
257 {
259 }
260
264 public function isAsync()
265 {
266 return $this->is_async;
267 }
268
269
273 public function setAsync($is_async)
274 {
275 $this->is_async = $is_async;
276 }
277
278
282 public function setName($a_name)
283 {
284 self::$default_from_name = $a_name;
285
286 parent::setName($a_name);
287 }
288}
$result
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Class ilAsyncPropertyFormGUI.
isSubmitted()
Checks if the form was submitted.
checkInput()
Saves the change input result into a property.
static addOnLoadCode($id, $content)
Adds onload code to the template.
__construct(array $config=array(), $is_async=true)
setFormAction($a_formaction)
Sets the form action If the form is set to async, the cmdMode=asynch is added to the url.
cloneForm(ilPropertyFormGUI $form_to_clone)
Copies form items, buttons and properties from another form.
hasErrors()
Return if there were errors on the last checkInput call.
getHTML()
Returns the rendered form content.
static getErrorMessageTemplate()
Returns the error-message template for the client-side validation.
static addJavaScript($add_form_loader=false, $js_base_path=null)
Adds all needed js By default is called by ilAsyncPropertyFormGUI::getHTML()
getErrors()
Return errors of the form as array.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
addCommandButton($a_cmd, $a_text, $a_id="")
Add Command button.
getCommandButtons()
Return all Command buttons.
special template class to simplify handling of ITX/PEAR
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
global $DIC
Definition: goto.php:24
$errors
Definition: imgupload.php:49
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc