EbayTemplateEditHandler = Class.create(CommonHandler, { templateNick: null, //---------------------------------- initialize: function() { Validation.add('validate-title-uniqueness', M2ePro.translator.translate('Policy title is not unique.'), function(value, el) { var unique = false; new Ajax.Request( M2ePro.url.get('adminhtml_ebay_template/isTitleUnique') , { method: 'get', asynchronous : false, parameters : { title : $('title').value }, onSuccess: function (transport) { unique = transport.responseText.evalJSON()['unique']; } }); return unique; }); }, //---------------------------------- loadTemplateData: function() { var marketplaceId = $('marketplace_id') ? $('marketplace_id').value : null; new Ajax.Request(M2ePro.url.get('adminhtml_ebay_template/getTemplateHtml'), { method: 'get', asynchronous : true, parameters : { marketplace_id: marketplaceId }, onSuccess: function (transport) { var editFormData = $('edit_form_data'); if (!editFormData) { editFormData = document.createElement('div'); editFormData.id = 'edit_form_data'; $('edit_form').appendChild(editFormData); } editFormData.update(transport.responseText); var titleInput = $$('input[name="'+this.templateNick+'[title]"]')[0]; var marketplaceIdInput = $$('input[name="'+this.templateNick+'[marketplace_id]"]')[0]; if ($('title').value.trim() == '') { $('title').value = titleInput.value; } if (marketplaceIdInput) { marketplaceIdInput.value = marketplaceId; } }.bind(this) }); }, //---------------------------------- validateForm: function() { var validationResult = true; validationResult &= editForm.validate(); validationResult &= Validation.validate($('title')); if ($('marketplace_id')) { validationResult &= Validation.validate($('marketplace_id')); } if ($('ebay_template_synchronization_edit_form_container')) { EbayTemplateSynchronizationHandlerObj.checkVirtualTabValidation(); } $$('input[name="'+EbayTemplateEditHandlerObj.templateNick+'[title]"]')[0].value = $('title').value; return validationResult; }, //---------------------------------- confirm: function(templateNick, confirmText, okCallback) { var skipConfirmation = getCookie('ebay_template_'+templateNick+'_skip_save_confirmation'); if (!confirmText || skipConfirmation) { okCallback(); return; } var template = $('dialog_confirm_container'); template.down('.dialog_confirm_content').innerHTML = '
' + '