Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Util.js 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* global $ */
  2. var ConfigUtil = {
  3. /**
  4. * Method overrides JSON properties in <tt>config</tt> and
  5. * <tt>interfaceConfig</tt> Objects with the values from <tt>newConfig</tt>
  6. * @param config the config object for which we'll be overriding properties
  7. * @param interfaceConfig the interfaceConfig object for which we'll be
  8. * overriding properties.
  9. * @param newConfig object containing configuration properties. Destination
  10. * object is selected based on root property name:
  11. * {
  12. * config: {
  13. * // config.js properties to be
  14. * },
  15. * interfaceConfig: {
  16. * // interfaceConfig.js properties here
  17. * }
  18. * }
  19. */
  20. overrideConfigJSON: function (config, interfaceConfig, newConfig) {
  21. var configRoot, key, value, confObj;
  22. for (configRoot in newConfig) {
  23. confObj = null;
  24. if (configRoot == "config") {
  25. confObj = config;
  26. } else if (configRoot == "interfaceConfig") {
  27. confObj = interfaceConfig;
  28. } else {
  29. continue;
  30. }
  31. for (key in newConfig[configRoot]) {
  32. value = newConfig[configRoot][key];
  33. if (confObj[key] && typeof confObj[key] !== typeof value) {
  34. console.log("Overriding a " + configRoot +
  35. " property with a property of different type.");
  36. }
  37. console.info("Overriding " + key + " with: " + value);
  38. confObj[key] = value;
  39. }
  40. }
  41. }
  42. };
  43. module.exports = ConfigUtil;