#BLOCK("NewLineReplace","") function(evt){ var $input = $(this), $form = $(this.form), mandatoryElements = '#MandatoryElements'.split(/ *, */), defaultChangeActionInput = document.getElementById('defaultChangeActionId'), handleClick, addRoutine = function () { if (mandatoryElements.length===1 && mandatoryElements[0]==='') { mandatoryElements.length = 0; } var index = 0, $mandatoryElement, newInput, isValid = mandatoryElements.every(function(item) { var elem = document.getElementById(item), valid = (elem && elem.value) ? elem.value.length > 0 : false; if (valid) { index++; } return valid; }); if (isValid) { newInput = document.createElement('input'); newInput.value = '#DialogChangeAction'; newInput.name = 'ChangeAction'; newInput.classList.add('HideElementSoft'); $form.append(newInput); $input.attr('disabled', 'disabled'); $form.uiForm({showSaveWarn:false}); if (defaultChangeActionInput) { defaultChangeActionInput.disabled = true; } $form.trigger('submit'); } else { $mandatoryElement = ep('#' + mandatoryElements[index]); if ($mandatoryElement.length) { $mandatoryElement.trigger('focus'); window.setTimeout(function () { $mandatoryElement.trigger('blur'); if ($mandatoryElement.data('uiUiValidate') && $mandatoryElement.data('uiUiValidate').tooltip) { $mandatoryElement.data('uiUiValidate').tooltip.uiTooltip('show'); } }, 1); } } }; if ($form.find('.ep-AddAccountDialog').length === 0) { handleClick = function(evt) { require([ 'jquery', 'ep/ui/dialog', 'ep/ui/validate', 'jquery/metaparse', '$ready!' ], function ($, ep) { var renderedTmpl = $form.find('#ep-add-new-item-tmpl').tmpl(), dialog; dialog = ep(renderedTmpl).uiDialog({ modal: true, autoOpen: true, appendTo: $form, width: 500, title: '#LanguageTag', close: function() { if (defaultChangeActionInput) { defaultChangeActionInput.removeAttribute('disabled'); } }, buttons: [{ text: '#IF(NOT #DEFINED(#AddButtonTag)){Add[js]}#ELSE#AddButtonTag#ENDIF', click: function() { /* add needed ChangeAction (Batch Actions disable ChangeActions in the form-element)*/ addRoutine(); } }, { text: '{Cancel[js]}', click: function() { dialog.off('keydown.enterAddNew'); $(this).dialog('close'); } }] }); dialog.find('*').metaparse(); /* handle enter button */ dialog.on('keydown.enterAddNew', function(evt) { if (evt.keyCode === 13) { evt.preventDefault(); evt.stopPropagation(); addRoutine(); } }); $input.on('click', function (evt) { $form.find('.ep-AddAccountDialog').uiDialog('open'); }); }); }; handleClick(evt); } } #ENDBLOCK