mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-28 00:04:05 +02:00
FormExtensibleSet/js: improve behaviour
This commit is contained in:
parent
04f16008fe
commit
c1343131fb
@ -164,7 +164,7 @@ class Zend_View_Helper_FormExtensibleSet extends Zend_View_Helper_FormElement
|
|||||||
{
|
{
|
||||||
$v = $this->view;
|
$v = $this->view;
|
||||||
|
|
||||||
return '<input type="submit" class="related-action"'
|
return '<input type="submit" class="related-action action-add"'
|
||||||
. ' name="' . $name . '_ADD"'
|
. ' name="' . $name . '_ADD"'
|
||||||
. ' value=""'
|
. ' value=""'
|
||||||
. ' title="' . $v->translate('Remove this entry') . '"'
|
. ' title="' . $v->translate('Remove this entry') . '"'
|
||||||
@ -176,7 +176,7 @@ class Zend_View_Helper_FormExtensibleSet extends Zend_View_Helper_FormElement
|
|||||||
{
|
{
|
||||||
$v = $this->view;
|
$v = $this->view;
|
||||||
|
|
||||||
return '<input type="submit" class="related-action"'
|
return '<input type="submit" class="related-action action-remove"'
|
||||||
. ' name="' . $name . '_' . $cnt . '__REMOVE' . '"'
|
. ' name="' . $name . '_' . $cnt . '__REMOVE' . '"'
|
||||||
. ' value=""'
|
. ' value=""'
|
||||||
. ' title="' . $v->translate('Remove this entry') . '"'
|
. ' title="' . $v->translate('Remove this entry') . '"'
|
||||||
@ -188,7 +188,7 @@ class Zend_View_Helper_FormExtensibleSet extends Zend_View_Helper_FormElement
|
|||||||
{
|
{
|
||||||
$v = $this->view;
|
$v = $this->view;
|
||||||
|
|
||||||
return '<input type="submit" class="related-action"'
|
return '<input type="submit" class="related-action action-move-up"'
|
||||||
. ' name="' . $name . '_' . $cnt . '__MOVE_UP"'
|
. ' name="' . $name . '_' . $cnt . '__MOVE_UP"'
|
||||||
. ' value=""'
|
. ' value=""'
|
||||||
. ' title="' . $v->translate('Move up') . '"'
|
. ' title="' . $v->translate('Move up') . '"'
|
||||||
@ -200,7 +200,7 @@ class Zend_View_Helper_FormExtensibleSet extends Zend_View_Helper_FormElement
|
|||||||
{
|
{
|
||||||
$v = $this->view;
|
$v = $this->view;
|
||||||
|
|
||||||
return '<input type="submit" class="related-action"'
|
return '<input type="submit" class="related-action action-move-down"'
|
||||||
. ' name="' . $name . '_' . $cnt . '__MOVE_DOWN"'
|
. ' name="' . $name . '_' . $cnt . '__MOVE_DOWN"'
|
||||||
. ' value=""'
|
. ' value=""'
|
||||||
. ' title="' . $v->translate('Move down') . '"'
|
. ' title="' . $v->translate('Move down') . '"'
|
||||||
|
@ -20,11 +20,72 @@
|
|||||||
*/
|
*/
|
||||||
this.module.on('rendered', this.rendered);
|
this.module.on('rendered', this.rendered);
|
||||||
this.module.on('click', 'fieldset > legend', this.toggleFieldset);
|
this.module.on('click', 'fieldset > legend', this.toggleFieldset);
|
||||||
|
this.module.on('click', 'input.related-action', this.extensibleSetAction);
|
||||||
this.module.on('focus', 'form input', this.formElementFocus);
|
this.module.on('focus', 'form input', this.formElementFocus);
|
||||||
this.module.on('focus', 'form select', this.formElementFocus);
|
this.module.on('focus', 'form select', this.formElementFocus);
|
||||||
this.module.icinga.logger.debug('Director module initialized');
|
this.module.icinga.logger.debug('Director module initialized');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
extensibleSetAction: function(ev)
|
||||||
|
{
|
||||||
|
var el = ev.currentTarget;
|
||||||
|
|
||||||
|
if (el.name.match(/__MOVE_UP$/)) {
|
||||||
|
var $li = $(el).closest('li');
|
||||||
|
var $prev = $li.prev()
|
||||||
|
if ($prev.length) {
|
||||||
|
$prev.before($li.detach());
|
||||||
|
this.fixRelatedActions($li.closest('ul'));
|
||||||
|
}
|
||||||
|
ev.preventDefault();
|
||||||
|
ev.stopPropagation();
|
||||||
|
return false;
|
||||||
|
} else if (el.name.match(/__MOVE_DOWN$/)) {
|
||||||
|
var $li = $(el).closest('li');
|
||||||
|
var $next = $li.next()
|
||||||
|
if ($next.length && ! $next.find('.extend-set').length) {
|
||||||
|
$next.after($li.detach());
|
||||||
|
this.fixRelatedActions($li.closest('ul'));
|
||||||
|
}
|
||||||
|
ev.preventDefault();
|
||||||
|
ev.stopPropagation();
|
||||||
|
return false;
|
||||||
|
} else if (el.name.match(/__MOVE_REMOVE$/)) {
|
||||||
|
// TODO: skipping for now, wasn't able to prevent web2 form
|
||||||
|
// submission once removed
|
||||||
|
return;
|
||||||
|
|
||||||
|
var $li = $(el).closest('li').remove();
|
||||||
|
this.fixRelatedActions($li.closest('ul'));
|
||||||
|
ev.preventDefault();
|
||||||
|
ev.stopPropagation();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
fixRelatedActions: function($ul)
|
||||||
|
{
|
||||||
|
var $uls = $ul.find('li');
|
||||||
|
var last = $uls.length -2;
|
||||||
|
$uls.each(function (idx, li) {
|
||||||
|
var $li = $(li);
|
||||||
|
if (idx === 0) {
|
||||||
|
$li.find('.action-move-up').attr('disabled', 'disabled');
|
||||||
|
if (last === 0) {
|
||||||
|
$li.find('.action-move-down').attr('disabled', 'disabled');
|
||||||
|
} else {
|
||||||
|
$li.find('.action-move-down').removeAttr('disabled');
|
||||||
|
}
|
||||||
|
} else if (idx === last) {
|
||||||
|
$li.find('.action-move-up').removeAttr('disabled');
|
||||||
|
$li.find('.action-move-down').attr('disabled', 'disabled');
|
||||||
|
} else {
|
||||||
|
$li.find('.action-move-up').removeAttr('disabled');
|
||||||
|
$li.find('.action-move-down').removeAttr('disabled');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
formElementFocus: function(ev)
|
formElementFocus: function(ev)
|
||||||
{
|
{
|
||||||
var $input = $(ev.currentTarget);
|
var $input = $(ev.currentTarget);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user