#BLOCK("NewLineReplace","") function(evt){ var _this = this; require([ 'jquery', 'ep/ui/dialog', 'ep/ui/validate', 'jquery/metaparse', '$ready!' ], function($, ep) { #IF(#DEFINED(#AdditionalVariables))#AdditionalVariables[0]#ENDIF var $input = $(_this), $label = $input.closest('label'), $form = $(_this.form), mandatoryElements = '#IF(#DEFINED(#MandatoryElements))#MandatoryElements#ENDIF'.split(/ *, */), mandatoryDialogElements = '#MandatoryDialogElements'.split(/ *, */), defaultChangeActionInput = document.getElementById('defaultChangeActionId'), handleClick, dialog, addRoutine = function () { if (mandatoryElements.length===1 && mandatoryElements[0]==='') { mandatoryElements.length = 0; } var index = 0, $mandatoryElement, $mandatoryDialogElements = $(mandatoryDialogElements.join(',')), $mandatoryInvalidDialogElements, newInput, isNotEmpty = mandatoryElements.every(function(item) { var elem = document.getElementById(item), valid = (elem && elem.value) ? elem.value.length > 0 : false; if (valid) { index++; } return valid; }), isValid = dialog.find('input.ui-invalid:not([disabled=disabled])').length === 0; if (isNotEmpty && $mandatoryDialogElements.length) { $mandatoryInvalidDialogElements = $mandatoryDialogElements.filter(function(index, elem) { return (elem && (elem.value !== undefined)) ? elem.value.length === 0 : false; }); isNotEmpty = !$mandatoryInvalidDialogElements.length; } if (isNotEmpty && isValid && (typeof onBeforeSubmit === 'undefined' || onBeforeSubmit())) { /* check if an input with the DialogChangeAction already exists in the form */ newInput = $form.find('.ep-addnewdialog-changeactioninput'); if (newInput.length === 0) { newInput = document.createElement('input'); newInput.value = '#DialogChangeAction'; newInput.name = 'ChangeAction'; newInput.classList.add('HideElementSoft', 'ep-addnewdialog-changeactioninput'); $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 === 0) && $mandatoryInvalidDialogElements.length) { $mandatoryElement = $mandatoryInvalidDialogElements.eq(0); } 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) { var renderedTmpl = $form.find('#ep-add-new-item-tmpl').tmpl(); dialog = ep(renderedTmpl).uiDialog({ modal: true, autoOpen: true, appendTo: $form, width: 500, title: '#LanguageTag', close: function() { ep(this).find('input').prop('disabled', true); if (defaultChangeActionInput) { defaultChangeActionInput.removeAttribute('disabled'); } $form.trigger('closed:addNewDialog'); }, create: function() { $form.trigger('initialized:addNewDialog'); }, open: function() { ep(this).find('input').prop('disabled', false); $form.trigger('opened:addNewDialog'); }, buttons: [{ cssClass: 'ep-button ep-button-add', text: '#IF(NOT #DEFINED(#AddButtonTag)){Add[js]}#ELSE#AddButtonTag#ENDIF', click: function() { /* add needed ChangeAction (Batch Actions disable ChangeActions in the form-element)*/ addRoutine(); } }, { cssClass: 'ep-button ep-button-cancel', 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.one('click', function (evt) { if (!$label.hasClass('BatchActionDisabled')) { if ($form.find('.ep-AddAccountDialog').length === 0){ handleClick(evt); } else { $form.find('.ep-AddAccountDialog').uiDialog('open'); } } }); }; handleClick(evt); } }); } #ENDBLOCK