diff --git a/application/views/helpers/FormExtensibleSet.php b/application/views/helpers/FormExtensibleSet.php index ec0c4c08..0ba58d63 100644 --- a/application/views/helpers/FormExtensibleSet.php +++ b/application/views/helpers/FormExtensibleSet.php @@ -164,7 +164,7 @@ class Zend_View_Helper_FormExtensibleSet extends Zend_View_Helper_FormElement { $v = $this->view; - return 'view; - return 'view; - return 'view; - return ' 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 select', this.formElementFocus); 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) { var $input = $(ev.currentTarget);