UNPKG

product-admin

Version:

EA admin screens

88 lines (71 loc) 1.95 kB
<script> /** * @namespace {object} bms */ window.bms = (function () { "use strict"; // Avoiding getters because…, // https://github.com/petkaantonov/bluebird/wiki/Optimization-killers return { behaviors: { util: { properties: { BASE_PATH: { type: String, readOnly: true, value: getBasePath(), notify: false } }, isObjValid: isObjValid, SECOND: 1000, MINUTE: 60000, HOUR: 360000, DAY: 8640000, convertHrMinToCycleTime: convertHrMinToCycleTime, convertCycleTimeToHrMin: convertCycleTimeToHrMin, getLabel: getLabel } } }; function getLabel (key) { // TODO: This condition should go away once reason-modal is written correctly if (!window.localeData) return ""; return window.localeData[key]; } function convertHrMinToCycleTime(hr, min){ return (parseInt(hr) * 60 + parseInt(min)); } function convertCycleTimeToHrMin(cycleTime){ return { mins: cycleTime % 60, hrs: Math.floor(cycleTime / 60) } } function getBasePath () { var bmsBasePath = isObjValid(window, "nav.paths.bmsconfig")? window.nav.paths.bmsconfig: ""; return bmsBasePath || ""; // 0, false, null, undefined as well as "" } /** * Determine whether a provided object contains a key * @param {object} - Dictionary on which to perform validation * @param {string} - Pattern to search object's heirarchy * @returns {bool} - Indicates whether object matches provided schema */ function isObjValid (obj, schema) { if (!obj) return false; var expectedKeyArr = schema.split("."); while (expectedKeyArr.length) { var currentKey = expectedKeyArr.shift(); if (obj[currentKey]) { obj = obj[currentKey]; continue; } else return false; } return true; } function created () { // do stuff on created lifecycle callback } }()); </script>