Merge remote-tracking branch 'upstream/4.6' into 4.6-master-2015-11-16-01-17-32
[civicrm-core.git] / js / Common.js
index e69025c3adabd2a5e6bf18bcfdcb24cc7e7b3dc5..ed6f9d32d6225fa765e195ce3f96dd8ec5d1d714 100644 (file)
@@ -385,10 +385,17 @@ if (!CRM.vars) CRM.vars = {};
       // add disabled property for option values
       $('option[value^=crm_disabled_opt]', this).attr('disabled', 'disabled');
 
-      // Placeholder icon
+      // Placeholder icon - total hack hikacking the escapeMarkup function but select2 3.5 dosn't have any other callbacks for this :(
       if ($el.is('[class*=fa-]')) {
-        iconClass = $el.attr('class').match(/(fa-\S*)/)[1];
-        $el.removeClass(iconClass);
+        settings.escapeMarkup = function (m) {
+          var out = _.escape(m),
+            placeholder = settings.placeholder || $el.data('placeholder') || $el.attr('placeholder') || $('option[value=""]', $el).text();
+          if (m.length && placeholder === m) {
+            iconClass = $el.attr('class').match(/(fa-\S*)/)[1];
+            out = '<i class="crm-i ' + iconClass + '"></i> ' + out;
+          }
+          return out;
+        };
       }
 
       // Defaults for single-selects
@@ -403,11 +410,6 @@ if (!CRM.vars) CRM.vars = {};
         $el.addClass('crm-ajax-select');
       }
       $el.select2(settings);
-      if (iconClass) {
-        window.setTimeout(function() {
-          $el.select2('container').find('span.select2-chosen').prepend('<i class="crm-i ' + iconClass + '"></i>&nbsp;');
-        }, 10);
-      }
     });
   };
 
@@ -434,7 +436,7 @@ if (!CRM.vars) CRM.vars = {};
         selectParams = {};
       $el.data('api-entity', entity);
       $el.data('select-params', $.extend({}, $el.data('select-params') || {}, options.select));
-      $el.data('api-params', $.extend({}, $el.data('api-params') || {}, options.api));
+      $el.data('api-params', $.extend(true, {}, $el.data('api-params') || {}, options.api));
       $el.data('create-links', options.create || $el.data('create-links'));
       $el.addClass('crm-form-entityref crm-' + entity.toLowerCase() + '-ref');
       var settings = {
@@ -556,11 +558,12 @@ if (!CRM.vars) CRM.vars = {};
                 // Once a filter has been chosen, rerender create links and refocus the search box
                 $el.select2('close');
                 $el.select2('open');
+              } else {
+                $('.crm-entityref-links', '#select2-drop').replaceWith(renderEntityRefCreateLinks($el));
               }
             })
             .on('change.crmEntity', 'select.crm-entityref-filter-key', function() {
-              var filter = $el.data('user-filter') || {};
-              filter.key = $(this).val();
+              var filter = {key: $(this).val()};
               $(this).toggleClass('active', !!filter.key);
               $el.data('user-filter', filter);
               loadEntityRefFilterOptions($el);
@@ -852,7 +855,7 @@ if (!CRM.vars) CRM.vars = {};
           });
       }
     } else {
-      $valField.hide();
+      $valField.hide().val('').change();
     }
   }
 
@@ -926,16 +929,13 @@ if (!CRM.vars) CRM.vars = {};
       $('form[data-warn-changes] :input', e.target).each(function() {
         $(this).data('crm-initial-value', $(this).is(':checkbox, :radio') ? $(this).prop('checked') : $(this).val());
       });
-      $('textarea.crm-form-wysiwyg', e.target)
-        .not('.crm-wysiwyg-enabled')
-        .addClass('crm-wysiwyg-enabled')
-        .each(function() {
-          if ($(this).hasClass("collapsed")) {
-            CRM.wysiwyg.createCollapsed(this);
-          } else {
-            CRM.wysiwyg.create(this);
-          }
-        });
+      $('textarea.crm-form-wysiwyg', e.target).each(function() {
+        if ($(this).hasClass("collapsed")) {
+          CRM.wysiwyg.createCollapsed(this);
+        } else {
+          CRM.wysiwyg.create(this);
+        }
+      });
     })
     .on('dialogopen', function(e) {
       var $el = $(e.target);