Merge pull request #4452 from yashodha/CRM-15445
[civicrm-core.git] / js / Common.js
index db365f3bb9913741f599defe5adc3589a8b024e9..26ae4cfaf18c5e2be58409bc7dcadb59ee368c97 100644 (file)
@@ -533,7 +533,6 @@ CRM.strings = CRM.strings || {};
         $el.addClass('modal-dialog');
         $('body').css({overflow: 'hidden'});
       }
-      $el.parent().find('.ui-dialog-titlebar-close').attr('title', ts('Close'));
       // Add resize button
       if ($el.parent().hasClass('crm-container') && $el.dialog('option', 'resizable')) {
         $el.parent().find('.ui-dialog-titlebar').append($('<button class="crm-dialog-titlebar-resize ui-dialog-titlebar-close" title="'+ts('Toggle fullscreen')+'" style="right:2em;"/>').button({icons: {primary: 'ui-icon-newwin'}, text: false}));
@@ -553,15 +552,11 @@ CRM.strings = CRM.strings || {};
           e.preventDefault();
         });
       }
-      // FIXME: D7 hack to get the toolbar out of the way (CRM-15341)
-      if (CRM.config.userFramework === 'Drupal') $('#toolbar').css('z-index', '100');
     })
     .on('dialogclose', function(e) {
       // Restore scrollbars when closing modal
       if ($('.ui-dialog .modal-dialog:visible').not(e.target).length < 1) {
         $('body').css({overflow: ''});
-        // FIXME: D7 hack, restore toolbar (CRM-15341)
-        if (CRM.config.userFramework === 'Drupal') $('#toolbar').css('z-index', '');
       }
     })
     .on('submit', function(e) {
@@ -777,7 +772,7 @@ CRM.strings = CRM.strings || {};
    * @see https://wiki.civicrm.org/confluence/display/CRMDOC/Notification+Reference
    */
   CRM.confirm = function (options) {
-    var dialog, url, msg, settings = {
+    var dialog, url, msg, buttons = [], settings = {
       title: ts('Confirm'),
       message: ts('Are you sure you want to continue?'),
       url: null,
@@ -795,13 +790,13 @@ CRM.strings = CRM.strings || {};
     };
     $.extend(settings, ($.isFunction(options) ? arguments[1] : options) || {});
     if (!settings.buttons && $.isPlainObject(settings.options)) {
-      settings.buttons = [];
-      $.each(settings.options, function(key, label) {
-        settings.buttons.push({
+      $.each(settings.options, function(op, label) {
+        buttons.push({
           text: label,
-          icons: {primary: key === 'no' ? 'ui-icon-close' : 'ui-icon-check'},
+          'data-op': op,
+          icons: {primary: op === 'no' ? 'ui-icon-close' : 'ui-icon-check'},
           click: function() {
-            var event = $.Event('crmConfirm:' + key);
+            var event = $.Event('crmConfirm:' + op);
             $(this).trigger(event);
             if (!event.isDefaultPrevented()) {
               dialog.dialog('close');
@@ -809,21 +804,23 @@ CRM.strings = CRM.strings || {};
           }
         });
       });
+      // Order buttons so that "no" goes on the right-hand side
+      settings.buttons = _.sortBy(buttons, 'data-op').reverse();
     }
     url = settings.url;
-    msg = settings.message;
+    msg = url ? '' : settings.message;
     delete settings.options;
     delete settings.message;
     delete settings.url;
-    dialog = $('<div class="crm-confirm-dialog"></div>').dialog(settings);
+    dialog = $('<div class="crm-confirm-dialog"></div>').html(msg || '').dialog(settings);
     if ($.isFunction(options)) {
       dialog.on('crmConfirm:yes', options);
     }
     if (url) {
       CRM.loadPage(url, {target: dialog});
     }
-    else if (msg && msg.length) {
-      dialog.html(msg).trigger('crmLoad');
+    else {
+      dialog.trigger('crmLoad');
     }
     return dialog;
   };
@@ -910,6 +907,9 @@ CRM.strings = CRM.strings || {};
     });
   }
 
+  /**
+   * Improve blockUI when used with jQuery dialog
+   */
   var originalBlock = $.fn.block,
     originalUnblock = $.fn.unblock;
 
@@ -919,17 +919,16 @@ CRM.strings = CRM.strings || {};
       return $(this);
     }
     return originalBlock.call(this, opts);
-  }
-
+  };
   $.fn.unblock = function(opts) {
     if ($(this).is('.ui-dialog-content')) {
       originalUnblock.call($(this).parents('.ui-dialog'), opts);
       return $(this);
     }
     return originalUnblock.call(this, opts);
-  }
+  };
 
-  // Preprocess all cj ajax calls to display messages
+  // Preprocess all CRM ajax calls to display messages
   $(document).ajaxSuccess(function(event, xhr, settings) {
     try {
       if ((!settings.dataType || settings.dataType == 'json') && xhr.responseText) {
@@ -942,9 +941,12 @@ CRM.strings = CRM.strings || {};
         if (response.backtrace) {
           CRM.console('log', response.backtrace);
         }
+        if (typeof response.deprecated === 'string') {
+          CRM.console('warn', response.deprecated);
+        }
       }
     }
-    // Suppress errors
+    // Ignore errors thrown by parseJSON
     catch (e) {}
   });
 
@@ -971,7 +973,7 @@ CRM.strings = CRM.strings || {};
         CRM.confirm({
           title: ts('Preview'),
           resizable: true,
-          message: '<div class="crm-custom-image-popup"><img src=' + $(this).attr('href') + '></div>',
+          message: '<div class="crm-custom-image-popup"><img style="max-width: 100%" src="' + $(this).attr('href') + '"></div>',
           options: null
         });
         e.preventDefault();
@@ -1034,10 +1036,9 @@ CRM.strings = CRM.strings || {};
 
   /**
    * Clientside currency formatting
-   * @param value
-   * @param format - currency representation of the number 1234.56
+   * @param number value
+   * @param [optional] string format - currency representation of the number 1234.56
    * @return string
-   * @see CRM_Core_Resources::addCoreResources
    */
   var currencyTemplate;
   CRM.formatMoney = function(value, format) {
@@ -1070,5 +1071,5 @@ CRM.strings = CRM.strings || {};
         return console[method](title, msg);
       }
     }
-  }
+  };
 })(jQuery, _);