CRM-13863 - Show form buttons as part of the dialog
authorColeman Watts <coleman@civicrm.org>
Wed, 3 Sep 2014 08:02:15 +0000 (09:02 +0100)
committerColeman Watts <coleman@civicrm.org>
Wed, 3 Sep 2014 08:03:00 +0000 (09:03 +0100)
js/crm.ajax.js

index e808621ee349f6c2a131c1350ed62559193e2b8a..9b8ecb1f8596e8c3827c88e749e6a67b1e16f3fe 100644 (file)
     });
 
     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);
           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();