APIExplorer.js comment cleanup
authorColeman Watts <coleman@civicrm.org>
Mon, 26 Jan 2015 16:36:44 +0000 (11:36 -0500)
committerColeman Watts <coleman@civicrm.org>
Mon, 26 Jan 2015 16:36:44 +0000 (11:36 -0500)
templates/CRM/Admin/Page/APIExplorer.js

index e65411033516894c1b7fed7f50da94090e5a7365..04f144322f6002dd395f68bbcbca3e5d64c7e01b 100644 (file)
     }
   }
 
+  /**
+   * Test whether an action is deprecated
+   * @param action
+   * @returns {boolean}
+   */
   function isActionDeprecated(action) {
     return !!(typeof actions.deprecated === 'object' && actions.deprecated[action]);
   }
 
+  /**
+   * Render action text depending on deprecation status
+   * @param option
+   * @returns {string}
+   */
   function renderAction(option) {
     return isActionDeprecated(option.id) ? '<span class="strikethrough">' + option.text + '</span>' : option.text;
   }
     }
   }
 
+  /**
+   * Check for and display action-specific deprecation notices
+   * @param action
+   */
   function onChangeAction(action) {
     if (isActionDeprecated(action)) {
       CRM.alert(actions.deprecated[action], action + ' deprecated');
       if ((first === '"' || first === "'") && last === first) {
         return val.slice(1, -1);
       }
-      // Parse json
+      // Parse json - use eval rather than $.parseJSON because it's less strict about formatting
       if ((first === '[' && last === ']') || (first === '{' && last === '}')) {
         return eval('(' + val + ')');
       }
         });
         return result;
       }
-      // Integers - quote any number that starts with 0 to avoid oddities
+      // Integers - skip any multidigit number that starts with 0 to avoid oddities (it will be treated as a string below)
       if (!isNaN(val) && val.search(/[^\d]/) < 0 && (val.length === 1 || first !== '0')) {
         return parseInt(val, 10);
       }
     }
   }
 
+  /**
+   * Display error message on incorrectly-formatted params
+   * @param el
+   */
   function setError(el) {
     if (!$(el).hasClass('crm-error')) {
       var msg = ts('Syntax error: input should be valid JSON or a quoted string.');
     }
   }
 
+  /**
+   * Remove error message
+   * @param el
+   */
   function clearError(el) {
     $(el)
       .removeClass('crm-error')
       .siblings('.ui-icon-alert').remove();
   }
 
+  /**
+   * Render the api request in various formats
+   */
   function formatQuery() {
     var i = 0, q = {
       smarty: "{crmAPI var='result' entity='" + entity + "' action='" + action + "'",
     prettyPrint();
   }
 
+  /**
+   * Submit button handler
+   * @param e
+   */
   function submit(e) {
     e.preventDefault();
     if (!entity || !action) {