(function() { var __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }, __slice = [].slice; (function(root, factory) { if (typeof define === 'function' && define.amd) { return define(['_'], factory(root)); } else if (typeof module !== "undefined" && module !== null ? module.exports : void 0) { return module.exports = factory(); } })(this, function() { var RESULT; RESULT = { CONST: { MAXRANGE: 999999999 }, enumerate: { eventLog: { providerInquiryMail: 1 }, adminRole: { finance: 1, salesDirector: 2, purchasingDirector: 3, webMaster: 4, salesman: 5, purchaser: 6, root: 99 }, memberType: { provider: 1, purchaser: 2 }, paymentTargetType: { provider: 1, purchaser: 2 }, orderAdditionalType: { order: 1, category: 2, product: 3 }, dictionaryType: { ship_from: 1, ship_to: 2, delivery_by: 3 }, orderStatus: { created: 1, inquiring: 10, confirmed: 2, doing: 3, ready: 4, delivery: 5, done: 6, canceled: 7, basket: 99 }, systemRole: { admin: 99, financial: 1, sales: 2 }, orderProviderStatus: { created: 1, contract: 3, delivering: 4, delivered: 5, success: 10, canceled: 99 }, orderInquiryStatus: { created: 1, confirmed: 2, providerUpdate: 3, providerConfirmed: 4, contract: 5, canceled: 99 }, contractStatus: { created: 1, confirmed: 2, delivering: 3, delivered: 4, success: 10, canceled: 99 } }, orderEditable: function(status, isAdmin) { var allowStatus, e; e = this.enumerate.orderStatus; allowStatus = isAdmin ? [e.created, e.basket, e.inquiring, e.confirmed] : [e.created, e.confirmed, e.doing, e.inquiring]; return __indexOf.call(allowStatus, status) >= 0; }, pagination: function(pageIndex, pageSize, maxPageSize) { if (pageIndex == null) { pageIndex = 1; } if (pageSize == null) { pageSize = 10; } if (maxPageSize == null) { maxPageSize = 50; } pageIndex = parseInt(pageIndex); if (isNaN(pageIndex)) { pageIndex = 1; } if (isNaN(pageSize)) { pageSize = 10; } pageSize = Math.min(pageSize, maxPageSize); return { pageSize: pageSize, offset: Math.max(pageIndex * pageSize - pageSize, 0), limit: pageSize, pageIndex: pageIndex }; }, pageItems: function(pag, max) { var end, index, items, start, _i; if (max == null) { max = 5; } start = Math.max(1, pag.pageIndex - max); end = Math.min(start + max * 2, pag.pageCount); items = pag.items = []; if (start === end || end === 0) { return items; } for (index = _i = start; start <= end ? _i <= end : _i >= end; index = start <= end ? ++_i : --_i) { items.push({ index: index, current: index === pag.pageIndex }); } return items; }, prefixZero: function(num, length) { var str; str = String(num); return new Array(length - str.length + 1).join("0") + str; }, gteZero: function(value) { value = parseFloat(value); if (isNaN(value)) { return false; } return value > 0; }, format: function() { var args, text; text = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; if (args[0] instanceof Array) { args = args[0]; } return text.replace(/\{(\d+)\}/g, function(m, i) { var value; value = args[parseInt(i)]; if (value === void 0) { value = m; } return value; }); }, exchangePrice: function(price, currency, exchange_rate) { if (currency == null) { currency = 'CN'; } if (/rmb/i.test(currency) || this.isChinese(currency)) { return price; } exchange_rate = exchange_rate || 1; return price / exchange_rate; }, unitOfQuantity: function(productUnit, modelUnit, includeCurrency, lang) { var currency, isChinese, k, unit; if (!productUnit) { return ''; } isChinese = /cn/i.test(lang); unit = productUnit; productUnit = productUnit.split('/'); if (productUnit.length === 2) { unit = productUnit[~~!isChinese]; } k = modelUnit === 1000 ? ["k", "千"][~~isChinese] : ''; currency = includeCurrency ? ['USD', '元'][~~isChinese] + "/" : ''; return "" + currency + k + unit; }, isChinese: function(country) { return /^cn$/i.test(country); }, ensureLanguage: function(lang) { if (this.isChinese(lang)) { return 'cn'; } else { return 'en'; } }, getCurrency: function(lang) { if (this.isChinese(lang)) { return 'rmb'; } else { return 'usd'; } }, toCurrency: function(value) { if (!value) { return 0; } return value.toFixed(Math.abs(value) > 1 ? 2 : 3); }, xPathMapValue: function(xPath, data) { var value; value = data; xPath.split('.').forEach(function(key) { if (!value || !(value = value[key])) { } }); return value; } }; RESULT.statusList = { orderConfirmed: (function() { var all; all = RESULT.enumerate.orderStatus; return [all.confirmed, all.doing, all.ready, all.delivery, all.done]; })() }; return RESULT; }); }).call(this);