CRM-15705 - Set ui dialog defaults in Angular
authorColeman Watts <coleman@civicrm.org>
Sun, 15 Feb 2015 00:08:02 +0000 (19:08 -0500)
committerColeman Watts <coleman@civicrm.org>
Sun, 15 Feb 2015 00:10:06 +0000 (19:10 -0500)
js/Common.js
js/angular-crmMailing.js
js/angular-crmMailing/services.js
js/angular-crmMailingAB.js
js/crm.ajax.js

index ca2d5ea8a8bd4e2de49bc55318e0f3c97f13832f..f97025645899c0408c74174eab7cd1e7dc6c62ff 100644 (file)
@@ -324,7 +324,34 @@ CRM.strings = CRM.strings || {};
     });
     return isDirty;
   };
-
+  
+  /**
+   * This provides defaults for ui.dialog which either need to be calculated or are different from global defaults
+   *
+   * @param settings
+   * @returns {*}
+   */
+  CRM.utils.adjustDialogDefaults = function(settings) {
+    settings = $.extend({width: '65%', height: '65%', modal: true}, settings || {});
+    // Support relative height
+    if (typeof settings.height === 'string' && settings.height.indexOf('%') > 0) {
+      settings.height = parseInt($(window).height() * (parseFloat(settings.height)/100), 10);
+    }
+    // Responsive adjustment - increase percent width on small screens
+    if (typeof settings.width === 'string' && settings.width.indexOf('%') > 0) {
+      var screenWidth = $(window).width(),
+        percentage = parseInt(settings.width.replace('%', ''), 10),
+        gap = 100-percentage;
+      if (screenWidth < 701) {
+        settings.width = '100%';
+      }
+      else if (screenWidth < 1400) {
+        settings.width = '' + parseInt(percentage+gap-((screenWidth - 700)/7*(gap)/100), 10) + '%';
+      }
+    }
+    return settings;
+  };
+  
   /**
    * Wrapper for select2 initialization function; supplies defaults
    * @param options object
index fa103049c9bff72666dadbb6732c8af55198c64b..cb6e6449d013c7c1e3235f3918cd43a98d5deda9 100644 (file)
       var model = {
         recipients: $scope.recipients
       };
-      var options = {
+      var options = CRM.utils.adjustDialogDefaults({
         autoOpen: false,
-        modal: true,
         title: ts('Preview (%1)', {
           1: $scope.getRecipientsEstimate()
         })
-      };
+      });
       dialogService.open('recipDialog', '~/crmMailing/dialog/recipients.html', model, options);
     };
 
     // Open a dialog for editing the advanced recipient options.
     $scope.editOptions = function editOptions(mailing) {
-      var options = {
+      var options = CRM.utils.adjustDialogDefaults({
         autoOpen: false,
-        modal: true,
         title: ts('Edit Options')
-      };
+      });
       $q.when(crmMetadata.getFields('Mailing')).then(function(fields) {
         var model = {
           fields: fields,
         }));
         return;
       }
-      var options = {
+      var options = CRM.utils.adjustDialogDefaults({
         autoOpen: false,
-        modal: true,
         title: title // component[0].name
-      };
+      });
       dialogService.open('previewComponentDialog', '~/crmMailing/dialog/previewComponent.html', component[0], options);
     };
   });
           msg_html: mailing.body_html
         }
       };
-      var options = {
+      var options = CRM.utils.adjustDialogDefaults({
         autoOpen: false,
-        modal: true,
         title: ts('Save Template')
-      };
+      });
       return dialogService.open('saveTemplateDialog', '~/crmMailing/dialog/saveTemplate.html', model, options)
         .then(function (item) {
           mailing.msg_template_id = item.id;
index 08efca1fb478ae798b286fa5f828dd794f70c3ba..1ee3c893787f73dbcd02a8a4c6621a55381ea4af 100644 (file)
         var p = crmMailingMgr
           .preview(mailing)
           .then(function (content) {
-            var options = {
+            var options = CRM.utils.adjustDialogDefaults({
               autoOpen: false,
-              modal: true,
               title: ts('Subject: %1', {
                 1: content.subject
               })
-            };
+            });
             result = dialogService.open('previewDialog', templates[mode], content, options);
           });
         crmStatus({start: ts('Previewing'), success: ''}, p);
index 227b7c57208a226a939a268a4c6b6ce9019032ab..e1b822a5e09f5fb1f981a4ee95631b32edc128b6 100644 (file)
         abtest: abtest,
         mailingName: mailingName
       };
-      var options = {
+      var options = CRM.utils.adjustDialogDefaults({
         autoOpen: false,
-        modal: true,
         title: ts('Select Winner (%1)', {
           1: mailingName.toUpperCase()
         })
-      };
+      });
       return dialogService.open('selectWinnerDialog', '~/crmMailingAB/selectWinner.html', model, options);
     };
   });
index 6a2c1a593e1acb4eb7689634e075e6bbc1a47a77..8a8e74cc49e60a72bbb73228a208c57f74369386 100644 (file)
   CRM.loadPage = function(url, options) {
     var settings = {
       target: '#crm-ajax-dialog-' + (dialogCount++),
-      dialog: false
+      dialog: (options && options.target) ? false : {}
     };
-    if (!options || !options.target) {
-      settings.dialog = {
-        modal: true,
-        width: '65%',
-        height: '75%'
-      };
-    }
     if (options) $.extend(true, settings, options);
     settings.url = url;
     // Create new dialog
     if (settings.dialog) {
-      // HACK: jQuery UI doesn't support relative height
-      if (typeof settings.dialog.height === 'string' && settings.dialog.height.indexOf('%') > 0) {
-        settings.dialog.height = parseInt($(window).height() * (parseFloat(settings.dialog.height)/100), 10);
-      }
-      // Increase percent width on small screens
-      if (typeof settings.dialog.width === 'string' && settings.dialog.width.indexOf('%') > 0) {
-        var screenWidth = $(window).width(),
-          percentage = parseInt(settings.dialog.width.replace('%', ''), 10),
-          gap = 100-percentage;
-        if (screenWidth < 701) {
-          settings.dialog.width = '100%';
-        }
-        else if (screenWidth < 1400) {
-          settings.dialog.width = '' + parseInt(percentage+gap-((screenWidth - 700)/7*(gap)/100), 10) + '%';
-        }
-      }
+      settings.dialog = CRM.utils.adjustDialogDefaults(settings.dialog);
       $('<div id="'+ settings.target.substring(1) +'"><div class="crm-loading-element">' + ts('Loading') + '...</div></div>').dialog(settings.dialog);
       $(settings.target)
         .on('dialogclose', function() {
         $('.ui-dialog-content.crm-ajax-container:hidden[data-unsaved-changes=true]').crmSnippet('destroy').dialog('destroy').remove();
       })
       // Auto-resize dialogs when loading content
-      .on('crmLoad', 'div.ui-dialog.ui-resizable.crm-container', function(e) {
+      .on('crmLoad dialogopen', 'div.ui-dialog.ui-resizable.crm-container', function(e) {
         var
           $wrapper = $(this),
           $dialog = $wrapper.children('.ui-dialog-content');