[NFC] Release Notes 5.53 first pass
[civicrm-core.git] / js / crm.insert-shortcode.js
index af285dd5b692b9fc12fad64523a4f48e09a60817..dc17fd1c451244bd27a46a1b01216b5f1df67d54 100644 (file)
@@ -1,52 +1,60 @@
 // https://civicrm.org/licensing
 
 CRM.$(function($) {
-  var $form = $('form.CRM_Core_Form_ShortCode');
-
-  function changeComponent() {
-    var component = $(this).val(),
-      entities = $(this).data('entities');
-
-    $('.shortcode-param[data-components]', $form).each(function() {
-      $(this).toggle($.inArray(component, $(this).data('components')) > -1);
-
-      if (entities[component]) {
-        $('input[name=entity]')
-          .val('')
-          .data('key', entities[component].key)
-          .data('select-params', null)
-          .data('api-params', null)
-          .crmEntityRef(entities[component]);
-      }
-    });
-  }
+  $('.crm-shortcode-button').click(function(e) {
+    e.preventDefault();
+    CRM.loadPage($(this).attr('href'), {dialog: {width: '50%', height: '50%'}}).on('crmLoad', loadForm);
+  });
+
+  function loadForm() {
+    var $form = $('form.CRM_Core_Form_ShortCode');
+
+    function changeComponent() {
+      var component = $(this).val(),
+        entities = $(this).data('entities');
+
+      $('.shortcode-param[data-components]', $form).each(function() {
+        $(this).toggle($.inArray(component, $(this).data('components')) > -1);
+
+        if (entities[component]) {
+          $('input[name=entity]')
+            .val('')
+            .data('key', entities[component].key)
+            .data('select-params', null)
+            .data('api-params', null)
+            .crmEntityRef(entities[component]);
+        }
+      });
+    }
 
-  function close() {
-    $form.closest('.ui-dialog-content').dialog('close');
-  }
+    function close() {
+      $form.closest('.ui-dialog-content').dialog('close');
+    }
 
-  function insert() {
-    var code = '[civicrm';
-    $('.shortcode-param:visible', $form).each(function() {
-      var $el = $('input:checked, select, input.crm-form-entityref', this);
-      code += ' ' + $el.data('key') + '="' + $el.val() + '"';
-    });
-    window.send_to_editor(code + ']');
-    close();
+    function insert() {
+      var code = '[civicrm';
+      $('.shortcode-param:visible', $form).each(function() {
+        var $el = $('input:checked, select, input.crm-form-entityref', this);
+        code += ' ' + $el.data('key') + '="' + $el.val() + '"';
+      });
+      window.send_to_editor(code + ']');
+      close();
+    }
+
+    $('select[name=component]', $form).each(changeComponent).change(changeComponent);
+
+    $(this).dialog('option', 'buttons', [
+      {
+        text: ts("Insert"),
+        icons: {primary: "fa-check"},
+        click: insert
+      },
+      {
+        text: ts("Cancel"),
+        icons: {primary: "fa-times"},
+        click: close
+      }
+    ]);
   }
 
-  $('select[name=component]', $form).each(changeComponent).change(changeComponent);
-
-  $form.closest('.ui-dialog-content').dialog('option', 'buttons', [
-    {
-      text: ts("Insert"),
-      icons: {primary: "fa-check"},
-      click: insert
-    },
-    {
-      text: ts("Cancel"),
-      icons: {primary: "fa-times"},
-      click: close
-    }
-  ]);
 });