Merge pull request #2326 from eileenmcnaughton/CRM-14069
[civicrm-core.git] / js / view / crm.profile-selector.js
index f36c8f2313bf9a06179842dc943f4c60d7d34e45..befceec4cebc30407d65c5169d9f028d073eb5f1 100644 (file)
@@ -44,6 +44,7 @@
       'click .crm-profile-selector-edit': 'doEdit',
       'click .crm-profile-selector-copy': 'doCopy',
       'click .crm-profile-selector-create': 'doCreate',
+      'click .crm-profile-selector-preview': 'doShowPreview',
       // prevent interaction with preview form
       'click .crm-profile-selector-preview-pane': false,
       'crmLoad .crm-profile-selector-preview-pane': 'disableForm'
@@ -57,6 +58,8 @@
       this.selectRegion.show(view);
       this.setUfGroupId(this.options.ufGroupId, {silent: true});
       this.toggleButtons();
+      this.$('.crm-profile-selector-select select').css('width', '25em').crmSelect2();
+      this.doShowPreview();
     },
     onChangeUfGroupId: function(event) {
       this.options.ufGroupId = $(event.target).val();
@@ -73,9 +76,7 @@
     setUfGroupId: function(value, options) {
       this.options.ufGroupId = value;
       this.$('.crm-profile-selector-select select').val(value);
-      if (!options || !options.silent) {
-        this.$('.crm-profile-selector-select select').change();
-      }
+      this.$('.crm-profile-selector-select select').select2('val', value, (!options || !options.silent));
     },
     getUfGroupId: function() {
       return this.options.ufGroupId;
         CRM.loadPage(CRM.url("civicrm/ajax/inline", {class_name: 'CRM_UF_Form_Inline_PreviewById', id: this.getUfGroupId()}), {target: $pane});
       }
     },
+    doShowPreview: function() {
+      var $preview = this.$('.crm-profile-selector-preview');
+      var $pane = this.$('.crm-profile-selector-preview-pane');
+      if ($preview.hasClass('crm-profile-selector-preview-show')) {
+        $preview.removeClass('crm-profile-selector-preview-show');
+        $pane.show();
+      } else {
+        $preview.addClass('crm-profile-selector-preview-show');
+        $pane.hide();
+      }
+    },
     disableForm: function() {
       this.$(':input', '.crm-profile-selector-preview-pane').prop('readOnly', true);
     },