UNPKG

ns2-front-module-common

Version:
86 lines 3.38 kB
import { Injectable } from "@angular/core"; import { CurrentUserService } from "./current-user.service"; var HelperService = (function () { function HelperService(currentUser) { this.currentUser = currentUser; } /** * Plural forms * * Use: * * declOfNum(count, ['найдена', 'найдено', 'найдены']); * * @see https://gist.github.com/realmyst/1262561#gistcomment-2032406 * * @param n * @param titles * @returns {string} */ HelperService.prototype.declOfNum = function (n, titles) { var cases = [2, 0, 1, 1, 1, 2]; return titles[(n % 100 > 4 && n % 100 < 20) ? 2 : cases[(n % 10 < 5) ? n % 10 : 5]]; }; /** * Возвращает выделенный текст * * @returns {string} */ HelperService.prototype.getSelectedText = function () { var result = ""; if (window.getSelection) { result = window.getSelection().toString(); } return result; }; /** * Форматирует телефонный номер * @param prefix Префикс * @param phone Номер телефона * @returns {string} */ HelperService.prototype.maskPhone = function (prefix, phone) { return prefix + ' ' + phone.substr(0, 3) + ' ' + phone.substr(3, 3) + '-' + phone.substr(6, 2) + '-' + phone.substr(8, 2); }; /** * Возвращает количество опубликованных объявлений риелтором в текущем городе * @param {RealtorModel} realtorInfo Модель риелтора * @returns {Number} */ HelperService.prototype.getPublishedRealty = function (realtorInfo) { var realtyInfo = this.getRealtyInfo(realtorInfo); return realtyInfo.hasOwnProperty('published') ? Number(realtyInfo['published']) : 0; }; /** * Возвращает количество опубликованных эксклюзивных объявлений риелтором в текущем городе * @param {RealtorModel} realtorInfo Модель риелтора * @returns {Number} */ HelperService.prototype.getExclusiveRealty = function (realtorInfo) { var realtyInfo = this.getRealtyInfo(realtorInfo); return realtyInfo.hasOwnProperty('exclusive') ? Number(realtyInfo['exclusive']) : 0; }; /** * Возвращает информацию о количестве объявлений риелтора в текущем городе * @param {RealtorModel} realtorInfo Модель риелтора * @returns {{}} */ HelperService.prototype.getRealtyInfo = function (realtorInfo) { var userInfo = this.currentUser.getInfo(), sessionInfo = userInfo ? userInfo.session : null, geoGuid = sessionInfo ? sessionInfo.geo_guid : ''; return realtorInfo.realty_count && realtorInfo.realty_count.hasOwnProperty(geoGuid) ? realtorInfo.realty_count[geoGuid] : {}; }; return HelperService; }()); export { HelperService }; HelperService.decorators = [ { type: Injectable }, ]; /** @nocollapse */ HelperService.ctorParameters = function () { return [ { type: CurrentUserService, }, ]; }; //# sourceMappingURL=helper.service.js.map