Skip to content

Commit 351d65e

Browse files
committed
Opravy formulare editace. Hlavne js autosave a nakladani s hodnotou NULL
1 parent bab79ab commit 351d65e

10 files changed

Lines changed: 84 additions & 83 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vitexsoftware/icinga-editor",
33
"description": "Editor of Icinga Configuration files",
4-
"version": "0.201",
4+
"version": "0.202",
55
"authors": [
66
{
77
"name": "vitex",

debian/changelog

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
icinga-editor (0.201-31) UNRELEASED; urgency=medium
1+
icinga-editor (0.202-2) UNRELEASED; urgency=medium
22

33
[ dvorak ]
44
* Initial release. (Closes: #XXXXXX)
@@ -76,5 +76,7 @@ icinga-editor (0.201-31) UNRELEASED; urgency=medium
7676
* HotfFix Invalid max_check_attempts, check_interval, retry_interval,
7777
or notification_interval value for services & other misc fixes
7878
* Scripts file upload Many fixes and improvements
79+
* typo fixes
80+
* typo fixes
7981

80-
-- vitex <vitex@developer.kancl.brevnov.czf> Wed, 20 Jul 2016 18:58:43 +0200
82+
-- vitex <vitex@developer.kancl.brevnov.czf> Wed, 20 Jul 2016 19:50:37 +0200

debian/conf/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vitexsoftware/icinga-editor",
33
"description": "Editor of Icinga Configuration files (debian version)",
4-
"version": "0.201.31",
4+
"version": "0.202.2",
55
"authors": [
66
{
77
"name": "vitex",

debian/lastversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.201
1+
0.202

src/classes/UI/CfgEditor.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class CfgEditor extends \Ease\Container
2424
/**
2525
* Vytvoří editační formulář podle CFG objektu
2626
*
27-
* @param IEcfg $this->ObjectEdited
27+
* @param \Icinga\Editor\Engine\Configurator $this->ObjectEdited
2828
* @param string $onlyColumn Vrací editační pole jen pro sloupec daného jména
2929
*/
3030
public function __construct($cfgObject, $onlyColumn = null)
@@ -51,6 +51,7 @@ public function __construct($cfgObject, $onlyColumn = null)
5151
$this->addItem(new \Ease\Html\InputHiddenTag('class',
5252
get_class($cfgObject)));
5353
}
54+
\Ease\Shared::webPage()->includeJavaScript('js/datasaver.js');
5455
}
5556

5657
/**
@@ -122,7 +123,6 @@ public function insertWidget($fieldBlock, $fieldName, $value)
122123
null, true);
123124
}
124125

125-
126126
switch ($fType) {
127127
case 'INT':
128128
case 'STRING':
@@ -133,13 +133,14 @@ public function insertWidget($fieldBlock, $fieldName, $value)
133133
if ($required) {
134134
$fieldBlock->addItem(new \Ease\TWB\FormGroup($fieldName,
135135
new \Ease\Html\InputTextTag($fieldName, $value,
136-
['class' => 'required form-control', 'title' => $fieldName]),
137-
$hint, $keywordInfo['title']));
136+
['class' => 'required form-control', 'title' => $fieldName,
137+
'OnChange' => $this->onChangeCode($fieldName)]), $hint,
138+
$keywordInfo['title']));
138139
// $fieldBlock->addItem(new \Ease\Html\Div( new EaseLabeledTextInput($fieldName, $value, $keywordInfo['title'], array('class' => 'required form-control', 'title' => $fieldName))));
139140
} else {
140141
$fieldBlock->addItem(new \Ease\TWB\FormGroup($fieldName,
141142
new \Ease\Html\InputTextTag($fieldName, $value,
142-
['title' => $fieldName, 'class' => 'form-control']),
143+
['title' => $fieldName, 'class' => 'form-control', 'OnChange' => $this->onChangeCode($fieldName)]),
143144
$hint, $keywordInfo['title']));
144145
// $fieldBlock->addItem(new EaseLabeledTextInput($fieldName, $value, $keywordInfo['title'], array('title' => $fieldName, 'class' => 'form-control')));
145146
}
@@ -196,15 +197,16 @@ public function insertWidget($fieldBlock, $fieldName, $value)
196197
case 'TEXT':
197198
$fieldBlock->addItem(new \Ease\TWB\FormGroup($keywordInfo['title'],
198199
new \Ease\TWB\Textarea($fieldName, $value,
199-
['style' => 'width:100%'])));
200+
['style' => 'width:100%', 'OnChange' => $this->onChangeCode($fieldName)])));
200201
break;
201202
case 'ENUM':
202203
$flags = explode(',',
203204
str_replace([$fType, "'", '(', ')'], '', $fieldType));
204205
$selector = $fieldBlock->addItem(
205206
new \Ease\TWB\FormGroup($keywordInfo['title'],
206207
new \Ease\Html\Select($fieldName,
207-
array_combine($flags, $flags)))
208+
array_combine($flags, $flags), null, null,
209+
['OnChange' => $this->onChangeCode($fieldName)]))
208210
);
209211
break;
210212
case 'PLATFORM':
@@ -250,7 +252,8 @@ public function insertWidget($fieldBlock, $fieldName, $value)
250252
'ORDER BY '.$nameColumn, $IDColumn);
251253

252254
$selector = $fieldBlock->addItem(new \Ease\Html\Select($fieldName,
253-
$value, $keywordInfo['title']));
255+
$value, $keywordInfo['title'],
256+
['OnChange' => $this->onChangeCode($fieldName)]));
254257

255258
if (!$required) {
256259
$selector->addItems(['NULL' => _('Výchozí')]);
@@ -363,7 +366,7 @@ public function insertWidget($fieldBlock, $fieldName, $value)
363366
case 'USER':
364367
$fieldBlock->addItem(new UserSelect($fieldName, null,
365368
$this->objectEdited->getDataValue($fieldName), null,
366-
['style' => 'width: 100%']));
369+
['style' => 'width: 100%', 'OnChange' => $this->onChangeCode($fieldName)]));
367370
break;
368371
default:
369372
$fieldBlock->addItem(new EaseLabeledTextInput($fieldName,
@@ -713,4 +716,10 @@ public function optionEnabler($name)
713716
return new \Ease\Html\CheckboxTag(null, false, 1,
714717
['id' => 'useTpl'.$name]);
715718
}
719+
720+
public function onChangeCode($fieldName)
721+
{
722+
return 'saveColumnData(\''.str_replace('\\', '-',
723+
get_class($this->objectEdited)).'\', \''.$this->objectEdited->getMyKey().'\', \''.$fieldName.'\')';
724+
}
716725
}

src/classes/UI/TextInputSaver.php

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -54,59 +54,7 @@ public function __construct($name, $value = NULL, $engine = null,
5454
*/
5555
public function finalize()
5656
{
57-
$this->setTagProperties(['OnChange' => '$.post(\'datasaver.php\', { SaverClass: \''.addslashes(get_class($this->engine)).'\', Field: \''.$this->getTagProperty('name').'\', Value: this.value, Key: '.$this->engine->getMyKey().' } )']);
57+
$this->setTagProperties(['OnChange' => '$.post(\'datasaver.php\', { SaverClass: \''.addslashes(get_class($this->engine)).'\', Field: \''.$this->getTagProperty('name').'\', Value: this.value, Key: '.$this->engine->getMyKey().', success : function () { alert (this); } } )']);
5858
// $this->enclosedElement->SetTagProperties(array('OnChange' => '$.ajax( { type: \"POST\", url: \"DataSaver.php\", data: \"SaverClass=' . get_class($this) . '&amp;Field=' . $this->enclosedElement->GetTagProperty('name') . '&amp;Value=\" + this.value , async: false, success : function () { alert (this); }, statusCode: { 404: function () { alert(\'page not found\');} } }); '));
5959
}
60-
61-
/**
62-
* Uloží data, pokud se to nepovede, pokusí se vytvořit chybějící sloupečky
63-
* a vrátí vysledek dalšího uložení
64-
* @param array $data
65-
* @param boolean $SearchForID
66-
* @return int
67-
*/
68-
public function saveToSQL($data = NULL, $SearchForID = false)
69-
{
70-
if (is_null($data)) {
71-
$data = $this->GetData();
72-
}
73-
$SaveResult = parent::SaveToSQL($data, $SearchForID);
74-
if (is_null($SaveResult)) {
75-
if ($this->CreateMissingColumns($data) > 0) {
76-
$SaveResult = parent::SaveToSQL($data, $SearchForID);
77-
}
78-
}
79-
80-
return $SaveResult;
81-
}
82-
83-
/**
84-
* Vytvoří v databázi sloupeček pro uložení hodnoty widgetu
85-
* @param array $data
86-
* @return int
87-
*/
88-
public function createMissingColumns($data = NULL)
89-
{
90-
if (is_null($data)) {
91-
$this->GetData();
92-
}
93-
unset($data[$this->GetmyKeyColumn()]);
94-
$KeyName = current(array_keys($data));
95-
96-
return EaseDbMySqli::CreateMissingColumns($this,
97-
[$KeyName => str_repeat(' ', 1000)]);
98-
}
99-
100-
/**
101-
* Přiřadí objektu uživatele a nastaví DB
102-
* @param EaseUser $user
103-
* @param object|mixed $TargetObject
104-
* @return boolen
105-
*/
106-
public function setUpUser(&$user, &$TargetObject = NULL)
107-
{
108-
$this->SetMyKey($user->GetUserID());
109-
110-
return parent::SetUpUser($user, $TargetObject);
111-
}
11260
}

src/classes/UI/UsedServiceSelector.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function __construct($host)
114114

115115
if (count($servicesAssigned)) {
116116
$saveAsTemplateButton = new \Ease\TWB\LinkButton('stemplate.php?action=copyhost&host_id='.$host->getId(),
117-
_('Uložit jako předlohu'), 'success');
117+
_('Uložit zvolene jako sadu sledovanych sluzeb'), 'success');
118118
$initialContent->footer($saveAsTemplateButton);
119119

120120
$initialContent->addItem('</br>');
@@ -138,18 +138,17 @@ public function __construct($host)
138138
)
139139
);
140140
}
141-
} else {
142-
$presetSelForm = new \Ease\TWB\Form('presetSelForm');
143-
$presetSelForm->addItem(new \Ease\Html\InputHiddenTag($host->getmyKeyColumn(),
144-
$host->getId()));
145-
$presetSelForm->addItem(new \Ease\Html\InputHiddenTag('action',
146-
'applystemplate'));
147-
$presetSelForm->addItem(new StemplateSelect('stemplate_id'));
148-
$presetSelForm->addItem(new \Ease\TWB\SubmitButton(_('Aplikovat předlohu'),
149-
'success'));
150-
$presetSelForm->setTagClass('form-inline');
151-
$initialContent->footer($presetSelForm);
152141
}
142+
$presetSelForm = new \Ease\TWB\Form('presetSelForm');
143+
$presetSelForm->addItem(new \Ease\Html\InputHiddenTag($host->getmyKeyColumn(),
144+
$host->getId()));
145+
$presetSelForm->addItem(new \Ease\Html\InputHiddenTag('action',
146+
'applystemplate'));
147+
$presetSelForm->addItem(new StemplateSelect('stemplate_id'));
148+
$presetSelForm->addItem(new \Ease\TWB\SubmitButton(_('Aplikovat sadu sluzeb'),
149+
'success'));
150+
$presetSelForm->setTagClass('form-inline');
151+
$initialContent->footer($presetSelForm);
153152
}
154153
$this->addItem($initialContent);
155154
}

src/classes/engine/Configurator.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,13 +723,30 @@ public function saveToSQL($data = null, $searchForID = false)
723723
$data = $this->getData();
724724
}
725725
foreach ($this->useKeywords as $keyWord => $columnType) {
726-
if (!isset($data[$keyWord])) {
726+
if (!array_key_exists($keyWord, $data)) {
727727
continue;
728728
}
729729
// if (isset($data[$keyWord]) && !is_null($data[$keyWord]) && !is_array($data[$keyWord]) && !strlen($data[$keyWord]) && is_bool($data[$keyWord])) {
730730
// $data[$keyWord] = null;
731731
// }
732732
switch ($columnType) {
733+
case 'BOOL':
734+
switch ($data[$keyWord]) {
735+
case 'true':
736+
case '1':
737+
$value = true;
738+
break;
739+
case 'false':
740+
case '':
741+
$value = false;
742+
break;
743+
case 'null' :
744+
case 'NULL' :
745+
default :
746+
$value = null;
747+
}
748+
break;
749+
733750
case 'ARRAY':
734751
case 'IDLIST':
735752
if (isset($data[$keyWord]) && is_array($data[$keyWord])) {

src/datasaver.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
$valueId = $oPage->getRequestValue('ValueID');
3737
if (is_null($saverClass) || is_null($field) || is_null($value) || is_null($key)
3838
|| is_null($value) || is_null($valueId)) {
39-
header('HTTP/1.0 400 Bad Request', 400);
39+
header('HTTP/1.1 400 Bad Request', 400);
4040
die(_('Chybné volání'));
4141
}
4242

@@ -54,21 +54,27 @@
5454
break;
5555
default:
5656
if (is_null($saverClass) || is_null($field) || is_null($value) || is_null($key)) {
57-
header('HTTP/1.0 400 Bad Request', 400);
57+
header('HTTP/1.1 400 Bad Request', 400);
5858
die(_('Chybné volání'));
5959
}
60+
if (strtolower($value) == 'null') {
61+
$value = null;
62+
}
63+
6064
$saver->takeData([$field => $value]);
6165
break;
6266
}
6367

6468
if (is_null($saver->saveToSQL())) {
65-
header('HTTP/1.0 501 Not Implemented', 501);
69+
header('HTTP/1.1 501 Not Implemented', 501);
6670
$oUser->addStatusMessage(_('Chyba ukládání do databáze: ').' '.$saver->dblink->ErrorText.': '.
6771
_('Třída').': <strong>'.$saverClass.'</strong> '.
6872
_('Tabulka').': <strong>'.$saver->myTable.'</strong> '.
6973
_('Pole').': <strong>'.$field.'</strong> '.
7074
_('Hodnota').': <strong>'.$value.'</strong> <tt>'.$saver->dblink->LastQuery.'</tt>',
7175
'error');
76+
} else {
77+
header("HTTP/1.1 200 OK");
7278
}
7379

7480

src/js/datasaver.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function saveColumnData(saverClass, key, field) {
2+
var input = $("[name='" + field + "']");
3+
4+
$.post('datasaver.php', {
5+
SaverClass: saverClass,
6+
Field: field,
7+
Value: $("[name='" + field + "']").val(),
8+
Key: key,
9+
success: function () {
10+
input.css({borderColor: "#0f0", borderStyle: "solid"}).animate({borderWidth: '5px'}, 'slow', 'linear');
11+
input.animate({borderColor: 'gray', borderWidth: '1px'});
12+
}
13+
}
14+
).fail(function () {
15+
input.css({borderColor: "#f00", borderStyle: "solid"}).animate({borderWidth: '5px'}, 'slow', 'linear');
16+
input.animate({borderColor: 'gray', borderWidth: '1px'});
17+
});
18+
}
19+
;
20+

0 commit comments

Comments
 (0)