From: Coleman Watts Date: Wed, 3 Sep 2014 08:02:15 +0000 (+0100) Subject: CRM-13863 - Show form buttons as part of the dialog X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=298f69da39168d5168bd0f7c0fea605dd383ea0a;p=civicrm-core.git CRM-13863 - Show form buttons as part of the dialog --- 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();