From 298f69da39168d5168bd0f7c0fea605dd383ea0a Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 3 Sep 2014 09:02:15 +0100 Subject: [PATCH] CRM-13863 - Show form buttons as part of the dialog --- js/crm.ajax.js | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/js/crm.ajax.js b/js/crm.ajax.js index e808621ee3..9b8ecb1f85 100644 --- a/js/crm.ajax.js +++ b/js/crm.ajax.js @@ -375,9 +375,8 @@ }); widget.on('crmFormLoad.crmForm', function(event, data) { - var $el = $(this) - .attr('data-unsaved-changes', 'false'); - var settings = $el.crmSnippet('option', 'crmForm'); + var $el = $(this).attr('data-unsaved-changes', 'false'), + settings = $el.crmSnippet('option', 'crmForm'); settings.cancelButton && $(settings.cancelButton, this).click(function(e) { e.preventDefault(); var returnVal = settings.onCancel.call($el, e); @@ -450,6 +449,32 @@ return false; }); } + // Show form buttons as part of the dialog + if ($el.data('uiDialog')) { + var buttons = [], added = []; + $('input.crm-form-submit, a.button', $el).each(function() { + var $el = $(this), + label = $el.is('input') ? $el.attr('value') : $el.text(), + identifier = $el.attr('name') || $el.attr('href'); + if (!identifier || identifier === '#' || $.inArray(identifier, added) < 0) { + var button = {text: label, click: function () { + $el.click(); + }}; + if ($el.find('.icon').length) { + button.icons = {primary: $el.find('.icon').attr('class')}; + } else { + button.icons = {primary: $el.hasClass('cancel') ? 'ui-icon-close' : 'ui-icon-check'}; + if (identifier.substr(identifier.length-4) === '_new') { + button.icons.secondary = 'ui-icon-plus'; + } + } + buttons.push(button); + added.push(identifier); + } + $el.hide().parents('.crm-button, .crm-submit-buttons, .action-link').hide(); + }); + $el.dialog('option', 'buttons', buttons); + } // Allow a button to prevent ajax submit $('input[data-no-ajax-submit=true]').click(function() { $(this).closest('form').ajaxFormUnbind(); -- 2.25.1