CRM-15352 Add CRM.console wrapper function
authorColeman Watts <coleman@civicrm.org>
Mon, 22 Sep 2014 15:59:10 +0000 (11:59 -0400)
committerColeman Watts <coleman@civicrm.org>
Mon, 22 Sep 2014 21:52:22 +0000 (17:52 -0400)
Not all browsers (ahem, IE) support the js console and will crash if it doesn't exist.
CRM.console adds a safe way to access console methods.

js/Common.js
js/angular-crmCaseType.js
js/crm.ajax.js

index abd4bf0994b15e876b6b31eefb037a9780bed50d..55eeca3d978cc912d8ae5679b734625d4fc00752 100644 (file)
@@ -937,6 +937,9 @@ CRM.strings = CRM.strings || {};
             CRM.alert(msg.text, msg.title, msg.type, msg.options);
           })
         }
+        if (response.backtrace) {
+          CRM.console('log', response.backtrace);
+        }
       }
     }
     // Suppress errors
@@ -1055,4 +1058,15 @@ CRM.strings = CRM.strings || {};
     result = sign + (j ? i.substr(0, j) + separator : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + separator) + (2 ? decimal + Math.abs(value - i).toFixed(2).slice(2) : '');
     return format.replace(/1.*234.*56/, result);
   };
+
+  CRM.console = function(method, title, msg) {
+    if (window.console) {
+      method = $.isFunction(console[method]) ? method : 'log';
+      if (msg === undefined) {
+        return console[method](title);
+      } else {
+        return console[method](title, msg);
+      }
+    }
+  }
 })(jQuery, _);
index ea2ca50d48740ca70393d3534a642bf7b76ba7be..c7cfd6570e7fc53f02820168510ee921705eb801 100644 (file)
         case 'sequence':
           return 0 == _.where($scope.caseType.definition.activitySets, {sequence: '1'}).length;
         default:
-          if (console && console.log) console.log('Denied access to unrecognized workflow: (' + workflow + ')');
+          CRM.console('warn', 'Denied access to unrecognized workflow: (' + workflow + ')');
           return false;
       }
     };
     };
   });
 
-})(angular, CRM.$, CRM._);
\ No newline at end of file
+})(angular, CRM.$, CRM._);
index 29b011530e10963382a8b369a5c14b270fe4304d..a5b4e8c87e406fcec73ca9232ed3bd48c3949deb 100644 (file)
@@ -15,7 +15,7 @@
       return tplURL = path;
     }
     if (!tplURL) {
-      console && console.log && console.log('Warning: CRM.url called before initialization');
+      CRM.console('error', 'Error: CRM.url called before initialization');
     }
     if (!mode) {
       mode = CRM.config && CRM.config.isFrontend ? 'front' : 'back';
     return url;
   };
 
-  // Backwards compatible with jQuery fn
+  // @deprecated
   $.extend ({'crmURL':
     function (p, params) {
-      console && console.log && console.log('Calling crmURL from jQuery is deprecated. Please use CRM.url() instead.');
+      CRM.console('warn', 'Calling crmURL from jQuery is deprecated. Please use CRM.url() instead.');
       return CRM.url(p, params);
     }
   });
    * @deprecated
    */
   $.fn.crmAPI = function(entity, action, params, options) {
-    console && console.log && console.log('Calling crmAPI from jQuery is deprecated. Please use CRM.api() instead.');
+    CRM.console('warn', 'Calling crmAPI from jQuery is deprecated. Please use CRM.api3() instead.');
     return CRM.api.call(this, entity, action, params, options);
   };