summaryrefslogtreecommitdiff
path: root/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/js
diff options
context:
space:
mode:
Diffstat (limited to 'www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/js')
-rw-r--r--www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/js/api4.js43
-rw-r--r--www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/js/load-bootstrap.js7
2 files changed, 50 insertions, 0 deletions
diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/js/api4.js b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/js/api4.js
new file mode 100644
index 00000000..7306168a
--- /dev/null
+++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/js/api4.js
@@ -0,0 +1,43 @@
+(function($, _) {
+
+ // result is an array, but in js, an array is also an object
+ // Assign all the metadata properties to it, mirroring the results arrayObject in php
+ function arrayObject(data) {
+ var result = data.values || [];
+ if (_.isArray(result)) {
+ delete(data.values);
+ _.assign(result, data);
+ }
+ return result;
+ }
+
+ CRM.api4 = function(entity, action, params, index) {
+ return new Promise(function(resolve, reject) {
+ if (typeof entity === 'string') {
+ $.post(CRM.url('civicrm/ajax/api4/' + entity + '/' + action), {
+ params: JSON.stringify(params),
+ index: index
+ })
+ .done(function (data) {
+ resolve(arrayObject(data));
+ })
+ .fail(function (data) {
+ reject(data.responseJSON);
+ });
+ } else {
+ $.post(CRM.url('civicrm/ajax/api4'), {
+ calls: JSON.stringify(entity)
+ })
+ .done(function(data) {
+ _.each(data, function(item, key) {
+ data[key] = arrayObject(item);
+ });
+ resolve(data);
+ })
+ .fail(function (data) {
+ reject(data.responseJSON);
+ });
+ }
+ });
+ };
+})(CRM.$, CRM._); \ No newline at end of file
diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/js/load-bootstrap.js b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/js/load-bootstrap.js
new file mode 100644
index 00000000..aff280a0
--- /dev/null
+++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/js/load-bootstrap.js
@@ -0,0 +1,7 @@
+// Loads a copy of shoreditch's bootstrap if bootstrap is missing
+CRM.$(function($) {
+ if (!$.isFunction($.fn.dropdown)) {
+ CRM.loadScript(CRM.vars.api4.basePath + 'lib/shoreditch/dropdown.js');
+ $('head').append('<link type="text/css" rel="stylesheet" href="' + CRM.vars.api4.basePath + 'lib/shoreditch/bootstrap.css" />');
+ }
+}); \ No newline at end of file