ref
This commit is contained in:
@@ -28,12 +28,13 @@
|
||||
|
||||
/** @module broadcast-channel */
|
||||
|
||||
export default class {
|
||||
class BroadcastChannel {
|
||||
|
||||
constructor() {
|
||||
this.object = null;
|
||||
|
||||
if (window.BroadcastChannel) {
|
||||
this.object = new BroadcastChannel('app');
|
||||
this.object = new window.BroadcastChannel('app');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,3 +70,5 @@ export default class {
|
||||
this.object.addEventListener('message', callback);
|
||||
}
|
||||
}
|
||||
|
||||
export default BroadcastChannel;
|
||||
|
||||
+69
-74
@@ -32,149 +32,143 @@ import moment from 'lib!moment';
|
||||
|
||||
/**
|
||||
* A date-time util.
|
||||
*
|
||||
* @class
|
||||
*/
|
||||
const DateTime = function () {};
|
||||
class DateTime {
|
||||
|
||||
_.extend(DateTime.prototype, /** @lends DateTime# */{
|
||||
constructor() {}
|
||||
|
||||
/**
|
||||
* A system date format.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
internalDateFormat: 'YYYY-MM-DD',
|
||||
internalDateFormat = 'YYYY-MM-DD'
|
||||
|
||||
/**
|
||||
* A system date-time format.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
internalDateTimeFormat: 'YYYY-MM-DD HH:mm',
|
||||
internalDateTimeFormat = 'YYYY-MM-DD HH:mm'
|
||||
|
||||
/**
|
||||
* A system date-time format including seconds.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
internalDateTimeFullFormat: 'YYYY-MM-DD HH:mm:ss',
|
||||
internalDateTimeFullFormat = 'YYYY-MM-DD HH:mm:ss'
|
||||
|
||||
/**
|
||||
* A date format for a current user.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
dateFormat: 'MM/DD/YYYY',
|
||||
dateFormat = 'MM/DD/YYYY'
|
||||
|
||||
/**
|
||||
* A time format for a current user.
|
||||
*
|
||||
* @type {string}
|
||||
*/
|
||||
timeFormat: 'HH:mm',
|
||||
timeFormat = 'HH:mm'
|
||||
|
||||
/**
|
||||
* A time zone for a current user.
|
||||
*
|
||||
* @type {string|null}
|
||||
*/
|
||||
timeZone: null,
|
||||
timeZone = null
|
||||
|
||||
/**
|
||||
* A week start for a current user.
|
||||
*
|
||||
* @type {Number}
|
||||
*/
|
||||
weekStart: 1,
|
||||
weekStart = 1
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
readableDateFormatMap: {
|
||||
/** @private */
|
||||
readableDateFormatMap = {
|
||||
'DD.MM.YYYY': 'DD MMM',
|
||||
'DD/MM/YYYY': 'DD MMM',
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
readableShortDateFormatMap: {
|
||||
/** @private */
|
||||
readableShortDateFormatMap = {
|
||||
'DD.MM.YYYY': 'D MMM',
|
||||
'DD/MM/YYYY': 'D MMM',
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a time format has a meridian (am/pm).
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
hasMeridian: function () {
|
||||
hasMeridian() {
|
||||
return (new RegExp('A', 'i')).test(this.timeFormat);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a date format.
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
getDateFormat: function () {
|
||||
getDateFormat() {
|
||||
return this.dateFormat;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a time format.
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
getTimeFormat: function () {
|
||||
getTimeFormat() {
|
||||
return this.timeFormat;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a date-time format.
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
getDateTimeFormat: function () {
|
||||
getDateTimeFormat() {
|
||||
return this.dateFormat + ' ' + this.timeFormat;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a readable date format.
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
getReadableDateFormat: function () {
|
||||
getReadableDateFormat() {
|
||||
return this.readableDateFormatMap[this.getDateFormat()] || 'MMM DD';
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a readable short date format.
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
getReadableShortDateFormat: function () {
|
||||
getReadableShortDateFormat() {
|
||||
return this.readableShortDateFormatMap[this.getDateFormat()] || 'MMM D';
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a readable date-time format.
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
getReadableDateTimeFormat: function () {
|
||||
getReadableDateTimeFormat() {
|
||||
return this.getReadableDateFormat() + ' ' + this.timeFormat;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a readable short date-time format.
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
getReadableShortDateTimeFormat: function () {
|
||||
getReadableShortDateTimeFormat() {
|
||||
return this.getReadableShortDateFormat() + ' ' + this.timeFormat;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date from a display representation to system.
|
||||
@@ -182,7 +176,7 @@ _.extend(DateTime.prototype, /** @lends DateTime# */{
|
||||
* @param {string} string A date value.
|
||||
* @returns {string|-1} A system date value.
|
||||
*/
|
||||
fromDisplayDate: function (string) {
|
||||
fromDisplayDate(string) {
|
||||
if (!string) {
|
||||
return null;
|
||||
}
|
||||
@@ -194,16 +188,16 @@ _.extend(DateTime.prototype, /** @lends DateTime# */{
|
||||
}
|
||||
|
||||
return m.format(this.internalDateFormat);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a time-zone.
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
getTimeZone: function () {
|
||||
getTimeZone() {
|
||||
return this.timeZone ? this.timeZone : 'UTC';
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date from system to a display representation.
|
||||
@@ -211,7 +205,7 @@ _.extend(DateTime.prototype, /** @lends DateTime# */{
|
||||
* @param {string} string A system date value.
|
||||
* @returns {string} A display date value.
|
||||
*/
|
||||
toDisplayDate: function (string) {
|
||||
toDisplayDate(string) {
|
||||
if (!string || (typeof string !== 'string')) {
|
||||
return '';
|
||||
}
|
||||
@@ -223,7 +217,7 @@ _.extend(DateTime.prototype, /** @lends DateTime# */{
|
||||
}
|
||||
|
||||
return m.format(this.dateFormat);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date-time from system to a display representation.
|
||||
@@ -231,7 +225,7 @@ _.extend(DateTime.prototype, /** @lends DateTime# */{
|
||||
* @param {string} string A system date-tyime value.
|
||||
* @returns {string|-1} A display date-time value.
|
||||
*/
|
||||
fromDisplay: function (string) {
|
||||
fromDisplay(string) {
|
||||
if (!string) {
|
||||
return null;
|
||||
}
|
||||
@@ -250,7 +244,7 @@ _.extend(DateTime.prototype, /** @lends DateTime# */{
|
||||
}
|
||||
|
||||
return m.format(this.internalDateTimeFormat) + ':00';
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date-time from system to a display representation.
|
||||
@@ -258,36 +252,36 @@ _.extend(DateTime.prototype, /** @lends DateTime# */{
|
||||
* @param {string} string A system date value.
|
||||
* @returns {string} A display date-time value.
|
||||
*/
|
||||
toDisplay: function (string) {
|
||||
toDisplay(string) {
|
||||
if (!string) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return this.toMoment(string).format(this.getDateTimeFormat());
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `fromDisplay`.
|
||||
*/
|
||||
fromDisplayDateTime: function (string) {
|
||||
fromDisplayDateTime(string) {
|
||||
return this.fromDisplay(string);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `toDisplay`.
|
||||
*/
|
||||
toDisplayDateTime: function (string) {
|
||||
toDisplayDateTime(string) {
|
||||
return this.toDisplay(string);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a now moment.
|
||||
*
|
||||
* @returns {moment.Moment}
|
||||
*/
|
||||
getNowMoment: function () {
|
||||
getNowMoment() {
|
||||
return moment().tz(this.getTimeZone())
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date to a moment.
|
||||
@@ -295,9 +289,9 @@ _.extend(DateTime.prototype, /** @lends DateTime# */{
|
||||
* @param {string} string A date value in a system representation.
|
||||
* @returns {moment.Moment}
|
||||
*/
|
||||
toMomentDate: function (string) {
|
||||
toMomentDate(string) {
|
||||
return moment.utc(string, this.internalDateFormat);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date-time to a moment.
|
||||
@@ -305,7 +299,7 @@ _.extend(DateTime.prototype, /** @lends DateTime# */{
|
||||
* @param {string} string A date-time value in a system representation.
|
||||
* @returns {moment.Moment}
|
||||
*/
|
||||
toMoment: function (string) {
|
||||
toMoment(string) {
|
||||
let m = moment.utc(string, this.internalDateTimeFullFormat);
|
||||
|
||||
if (this.timeZone) {
|
||||
@@ -313,7 +307,7 @@ _.extend(DateTime.prototype, /** @lends DateTime# */{
|
||||
}
|
||||
|
||||
return m;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date-time value from ISO to a system representation.
|
||||
@@ -321,7 +315,7 @@ _.extend(DateTime.prototype, /** @lends DateTime# */{
|
||||
* @param {string} string
|
||||
* @returns {string} A date-time value in a system representation.
|
||||
*/
|
||||
fromIso: function (string) {
|
||||
fromIso(string) {
|
||||
if (!string) {
|
||||
return '';
|
||||
}
|
||||
@@ -329,7 +323,7 @@ _.extend(DateTime.prototype, /** @lends DateTime# */{
|
||||
let m = moment(string).utc();
|
||||
|
||||
return m.format(this.internalDateTimeFormat);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date-time value from system to an ISO representation.
|
||||
@@ -337,22 +331,22 @@ _.extend(DateTime.prototype, /** @lends DateTime# */{
|
||||
* @param string A date-time value in a system representation.
|
||||
* @returns {string} An ISO date-time value.
|
||||
*/
|
||||
toIso: function (string) {
|
||||
toIso(string) {
|
||||
if (!string) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.toMoment(string).format();
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a today date value in a system representation.
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
getToday: function () {
|
||||
getToday() {
|
||||
return moment().tz(this.getTimeZone()).format(this.internalDateFormat);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a date-time value in a system representation, shifted from now.
|
||||
@@ -362,7 +356,7 @@ _.extend(DateTime.prototype, /** @lends DateTime# */{
|
||||
* @param {Number} [multiplicity] A number of minutes a value will be aliquot to.
|
||||
* @returns {string} A date-time value in a system representation
|
||||
*/
|
||||
getDateTimeShiftedFromNow: function (shift, type, multiplicity) {
|
||||
getDateTimeShiftedFromNow(shift, type, multiplicity) {
|
||||
if (!multiplicity) {
|
||||
return moment.utc().add(shift, type).format(this.internalDateTimeFormat);
|
||||
}
|
||||
@@ -372,7 +366,7 @@ _.extend(DateTime.prototype, /** @lends DateTime# */{
|
||||
unix = unix - (unix % (multiplicity * 60));
|
||||
|
||||
return moment.unix(unix).utc().add(shift, type).format(this.internalDateTimeFormat);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a date value in a system representation, shifted from today.
|
||||
@@ -381,9 +375,9 @@ _.extend(DateTime.prototype, /** @lends DateTime# */{
|
||||
* @param {'days'|'weeks'|'months'|'years'} type A shift unit.
|
||||
* @returns {string} A date value in a system representation
|
||||
*/
|
||||
getDateShiftedFromToday: function (shift, type) {
|
||||
getDateShiftedFromToday(shift, type) {
|
||||
return moment.tz(this.getTimeZone()).add(shift, type).format(this.internalDateFormat);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a now date-time value in a system representation.
|
||||
@@ -391,7 +385,7 @@ _.extend(DateTime.prototype, /** @lends DateTime# */{
|
||||
* @param {Number} [multiplicity] A number of minutes a value will be aliquot to.
|
||||
* @returns {string}
|
||||
*/
|
||||
getNow: function (multiplicity) {
|
||||
getNow(multiplicity) {
|
||||
if (!multiplicity) {
|
||||
return moment.utc().format(this.internalDateTimeFormat);
|
||||
}
|
||||
@@ -401,7 +395,7 @@ _.extend(DateTime.prototype, /** @lends DateTime# */{
|
||||
unix = unix - (unix % (multiplicity * 60));
|
||||
|
||||
return moment.unix(unix).utc().format(this.internalDateTimeFormat);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Set settings and preferences.
|
||||
@@ -410,7 +404,7 @@ _.extend(DateTime.prototype, /** @lends DateTime# */{
|
||||
* @param {module:models/preferences} preferences Preferences.
|
||||
* @internal
|
||||
*/
|
||||
setSettingsAndPreferences: function (settings, preferences) {
|
||||
setSettingsAndPreferences(settings, preferences) {
|
||||
if (settings.has('dateFormat')) {
|
||||
this.dateFormat = settings.get('dateFormat');
|
||||
}
|
||||
@@ -444,6 +438,7 @@ _.extend(DateTime.prototype, /** @lends DateTime# */{
|
||||
|
||||
this.timeZone = model.get('timeZone');
|
||||
}
|
||||
|
||||
if (model.has('weekStart') && model.get('weekStart') !== -1) {
|
||||
this.weekStart = model.get('weekStart');
|
||||
}
|
||||
@@ -452,7 +447,7 @@ _.extend(DateTime.prototype, /** @lends DateTime# */{
|
||||
this.timeZone = null;
|
||||
}
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a language.
|
||||
@@ -460,7 +455,7 @@ _.extend(DateTime.prototype, /** @lends DateTime# */{
|
||||
* @param {module:language} language A language.
|
||||
* @internal
|
||||
*/
|
||||
setLanguage: function (language) {
|
||||
setLanguage(language) {
|
||||
moment.updateLocale('en', {
|
||||
months: language.translate('monthNames', 'lists'),
|
||||
monthsShort: language.translate('monthNamesShort', 'lists'),
|
||||
@@ -470,7 +465,7 @@ _.extend(DateTime.prototype, /** @lends DateTime# */{
|
||||
});
|
||||
|
||||
moment.locale('en');
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default DateTime;
|
||||
|
||||
+67
-66
@@ -30,38 +30,39 @@
|
||||
|
||||
/**
|
||||
* Utility for getting field related meta information.
|
||||
*
|
||||
* @class
|
||||
*
|
||||
* @param {Object} [defs] Field type definitions (metadata > fields).
|
||||
* @param {module:metadata} [metadata] Metadata.
|
||||
* @param {modules:acl-manager} [acl] An ACL.
|
||||
*/
|
||||
const FieldManager = function (defs, metadata, acl) {
|
||||
class FieldManager {
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @internal
|
||||
* @type {Object}
|
||||
* Utility for getting field related meta information.
|
||||
*
|
||||
* @param {Object} [defs] Field type definitions (metadata > fields).
|
||||
* @param {module:metadata} [metadata] Metadata.
|
||||
* @param {modules:acl-manager} [acl] An ACL.
|
||||
*/
|
||||
this.defs = defs || {};
|
||||
constructor(defs, metadata, acl) {
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @internal
|
||||
* @type {module:metadata}
|
||||
*/
|
||||
this.metadata = metadata;
|
||||
/**
|
||||
* @public
|
||||
* @internal
|
||||
* @type {Object}
|
||||
*/
|
||||
this.defs = defs || {};
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @internal
|
||||
* @type {module:acl-manager}
|
||||
*/
|
||||
this.acl = acl;
|
||||
};
|
||||
/**
|
||||
* @public
|
||||
* @internal
|
||||
* @type {module:metadata}
|
||||
*/
|
||||
this.metadata = metadata;
|
||||
|
||||
_.extend(FieldManager.prototype, /** @lends FieldManager# */{
|
||||
/**
|
||||
* @public
|
||||
* @internal
|
||||
* @type {module:acl-manager}
|
||||
*/
|
||||
this.acl = acl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of parameters for a specific field type.
|
||||
@@ -69,13 +70,13 @@ _.extend(FieldManager.prototype, /** @lends FieldManager# */{
|
||||
* @param {string} fieldType A field type.
|
||||
* @returns {string[]}
|
||||
*/
|
||||
getParamList: function (fieldType) {
|
||||
getParamList(fieldType) {
|
||||
if (fieldType in this.defs) {
|
||||
return this.defs[fieldType].params || [];
|
||||
}
|
||||
|
||||
return [];
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether search filters are allowed for a field type.
|
||||
@@ -83,7 +84,7 @@ _.extend(FieldManager.prototype, /** @lends FieldManager# */{
|
||||
* @param {string} fieldType A field type.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
checkFilter: function (fieldType) {
|
||||
checkFilter(fieldType) {
|
||||
if (fieldType in this.defs) {
|
||||
if ('filter' in this.defs[fieldType]) {
|
||||
return this.defs[fieldType].filter;
|
||||
@@ -93,7 +94,7 @@ _.extend(FieldManager.prototype, /** @lends FieldManager# */{
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a merge operation is allowed for a field type.
|
||||
@@ -101,13 +102,13 @@ _.extend(FieldManager.prototype, /** @lends FieldManager# */{
|
||||
* @param {string} fieldType A field type.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isMergeable: function (fieldType) {
|
||||
isMergeable(fieldType) {
|
||||
if (fieldType in this.defs) {
|
||||
return !this.defs[fieldType].notMergeable;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of attributes of an entity type.
|
||||
@@ -115,7 +116,7 @@ _.extend(FieldManager.prototype, /** @lends FieldManager# */{
|
||||
* @param {string} entityType An entity type.
|
||||
* @returns {string[]}
|
||||
*/
|
||||
getEntityTypeAttributeList: function (entityType) {
|
||||
getEntityTypeAttributeList(entityType) {
|
||||
let list = [];
|
||||
|
||||
let defs = this.metadata.get('entityDefs.' + entityType + '.fields') || {};
|
||||
@@ -129,7 +130,7 @@ _.extend(FieldManager.prototype, /** @lends FieldManager# */{
|
||||
});
|
||||
|
||||
return list;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of actual attributes by a given field type and field name.
|
||||
@@ -140,7 +141,7 @@ _.extend(FieldManager.prototype, /** @lends FieldManager# */{
|
||||
* @param {string} fieldName A field name.
|
||||
* @returns {string[]}
|
||||
*/
|
||||
getActualAttributeList: function (fieldType, fieldName) {
|
||||
getActualAttributeList(fieldType, fieldName) {
|
||||
let fieldNames = [];
|
||||
|
||||
if (fieldType in this.defs) {
|
||||
@@ -170,7 +171,7 @@ _.extend(FieldManager.prototype, /** @lends FieldManager# */{
|
||||
}
|
||||
|
||||
return fieldNames;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of non-actual attributes by a given field type and field name.
|
||||
@@ -181,7 +182,7 @@ _.extend(FieldManager.prototype, /** @lends FieldManager# */{
|
||||
* @param {string} fieldName A field name.
|
||||
* @returns {string[]}
|
||||
*/
|
||||
getNotActualAttributeList: function (fieldType, fieldName) {
|
||||
getNotActualAttributeList(fieldType, fieldName) {
|
||||
let fieldNames = [];
|
||||
|
||||
if (fieldType in this.defs) {
|
||||
@@ -213,7 +214,7 @@ _.extend(FieldManager.prototype, /** @lends FieldManager# */{
|
||||
}
|
||||
|
||||
return fieldNames;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an attribute list of a specific field.
|
||||
@@ -222,7 +223,7 @@ _.extend(FieldManager.prototype, /** @lends FieldManager# */{
|
||||
* @param {string} field A field.
|
||||
* @returns {string[]}
|
||||
*/
|
||||
getEntityTypeFieldAttributeList: function (entityType, field) {
|
||||
getEntityTypeFieldAttributeList(entityType, field) {
|
||||
let type = this.metadata.get(['entityDefs', entityType, 'fields', field, 'type']);
|
||||
|
||||
if (!type) {
|
||||
@@ -233,7 +234,7 @@ _.extend(FieldManager.prototype, /** @lends FieldManager# */{
|
||||
this.getAttributeList(type, field),
|
||||
this._getEntityTypeFieldAdditionalAttributeList(entityType, field)
|
||||
);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an actual attribute list of a specific field.
|
||||
@@ -242,7 +243,7 @@ _.extend(FieldManager.prototype, /** @lends FieldManager# */{
|
||||
* @param {string} field A field.
|
||||
* @returns {string[]}
|
||||
*/
|
||||
getEntityTypeFieldActualAttributeList: function (entityType, field) {
|
||||
getEntityTypeFieldActualAttributeList(entityType, field) {
|
||||
let type = this.metadata.get(['entityDefs', entityType, 'fields', field, 'type']);
|
||||
|
||||
if (!type) {
|
||||
@@ -253,12 +254,12 @@ _.extend(FieldManager.prototype, /** @lends FieldManager# */{
|
||||
this.getActualAttributeList(type, field),
|
||||
this._getEntityTypeFieldAdditionalAttributeList(entityType, field)
|
||||
);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_getEntityTypeFieldAdditionalAttributeList: function (entityType, field) {
|
||||
_getEntityTypeFieldAdditionalAttributeList(entityType, field) {
|
||||
let type = this.metadata.get(['entityDefs', entityType, 'fields', field, 'type']);
|
||||
|
||||
if (!type) {
|
||||
@@ -287,7 +288,7 @@ _.extend(FieldManager.prototype, /** @lends FieldManager# */{
|
||||
});
|
||||
|
||||
return list;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of attributes by a given field type and field name.
|
||||
@@ -296,12 +297,12 @@ _.extend(FieldManager.prototype, /** @lends FieldManager# */{
|
||||
* @param {string} fieldName A field name.
|
||||
* @returns {string[]}
|
||||
*/
|
||||
getAttributeList: function (fieldType, fieldName) {
|
||||
getAttributeList(fieldType, fieldName) {
|
||||
return _.union(
|
||||
this.getActualAttributeList(fieldType, fieldName),
|
||||
this.getNotActualAttributeList(fieldType, fieldName)
|
||||
);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Object} module:field-manager~FieldFilters
|
||||
@@ -320,7 +321,7 @@ _.extend(FieldManager.prototype, /** @lends FieldManager# */{
|
||||
* @param {module:field-manager~FieldFilters} [o] Filters.
|
||||
* @returns {string[]}
|
||||
*/
|
||||
getEntityTypeFieldList: function (entityType, o) {
|
||||
getEntityTypeFieldList(entityType, o) {
|
||||
let list = Object.keys(this.metadata.get(['entityDefs', entityType, 'fields']) || {});
|
||||
|
||||
o = o || {};
|
||||
@@ -356,14 +357,14 @@ _.extend(FieldManager.prototype, /** @lends FieldManager# */{
|
||||
}
|
||||
|
||||
return list;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Since v5.7.
|
||||
*/
|
||||
getScopeFieldList: function (entityType) {
|
||||
getScopeFieldList(entityType) {
|
||||
return this.getEntityTypeFieldList(entityType);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a field parameter value.
|
||||
@@ -373,9 +374,9 @@ _.extend(FieldManager.prototype, /** @lends FieldManager# */{
|
||||
* @param {string} param A parameter name.
|
||||
* @returns {*}
|
||||
*/
|
||||
getEntityTypeFieldParam: function (entityType, field, param) {
|
||||
getEntityTypeFieldParam(entityType, field, param) {
|
||||
return this.metadata.get(['entityDefs', entityType, 'fields', field, param]);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a view name/path for a specific field type.
|
||||
@@ -383,7 +384,7 @@ _.extend(FieldManager.prototype, /** @lends FieldManager# */{
|
||||
* @param {string} fieldType A field type.
|
||||
* @returns {string}
|
||||
*/
|
||||
getViewName: function (fieldType) {
|
||||
getViewName(fieldType) {
|
||||
if (fieldType in this.defs) {
|
||||
if ('view' in this.defs[fieldType]) {
|
||||
return this.defs[fieldType].view;
|
||||
@@ -391,35 +392,35 @@ _.extend(FieldManager.prototype, /** @lends FieldManager# */{
|
||||
}
|
||||
|
||||
return 'views/fields/' + Espo.Utils.camelCaseToHyphen(fieldType);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `getParamList`.
|
||||
*/
|
||||
getParams: function (fieldType) {
|
||||
getParams(fieldType) {
|
||||
return this.getParamList(fieldType);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `getAttributeList`.
|
||||
*/
|
||||
getAttributes: function (fieldType, fieldName) {
|
||||
getAttributes(fieldType, fieldName) {
|
||||
return this.getAttributeList(fieldType, fieldName);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `getActualAttributeList`.
|
||||
*/
|
||||
getActualAttributes: function (fieldType, fieldName) {
|
||||
getActualAttributes(fieldType, fieldName) {
|
||||
return this.getActualAttributeList(fieldType, fieldName);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `getNotActualAttributeList`.
|
||||
*/
|
||||
getNotActualAttributes: function (fieldType, fieldName) {
|
||||
getNotActualAttributes(fieldType, fieldName) {
|
||||
return this.getNotActualAttributeList(fieldType, fieldName);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a field is not disabled, not only-admin, not forbidden and not internal.
|
||||
@@ -428,7 +429,7 @@ _.extend(FieldManager.prototype, /** @lends FieldManager# */{
|
||||
* @param {string} field A field name.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isEntityTypeFieldAvailable: function (entityType, field) {
|
||||
isEntityTypeFieldAvailable(entityType, field) {
|
||||
if (this.metadata.get(['entityDefs', entityType, 'fields', field, 'disabled'])) {
|
||||
return false;
|
||||
}
|
||||
@@ -442,14 +443,14 @@ _.extend(FieldManager.prototype, /** @lends FieldManager# */{
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `isEntityTypeFieldAvailable`.
|
||||
*/
|
||||
isScopeFieldAvailable: function (entityType, field) {
|
||||
isScopeFieldAvailable(entityType, field) {
|
||||
return this.isEntityTypeFieldAvailable(entityType, field);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default FieldManager;
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
/** @module field-language */
|
||||
/** @module helpers/misc/field-language */
|
||||
|
||||
/**
|
||||
* A field-language util.
|
||||
+29
-26
@@ -28,63 +28,66 @@
|
||||
|
||||
/** @module page-title */
|
||||
|
||||
import $ from 'lib!jquery';
|
||||
|
||||
/**
|
||||
* A page-title util.
|
||||
*
|
||||
* @class
|
||||
* @param {module:models/settings} config A config.
|
||||
*/
|
||||
const PageTitle = function (config) {
|
||||
class PageTitle {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
* @class
|
||||
* @param {module:models/settings} config A config.
|
||||
*/
|
||||
this.displayNotificationNumber = config.get('newNotificationCountInTitle') || false;
|
||||
constructor(config) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
this.title = $('head title').text() || '';
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.displayNotificationNumber = config.get('newNotificationCountInTitle') || false;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.notificationNumber = 0;
|
||||
};
|
||||
/**
|
||||
* @private
|
||||
* @type {string}
|
||||
*/
|
||||
this.title = $('head title').text() || '';
|
||||
|
||||
_.extend(PageTitle.prototype, /** @lends PageTitle# */{
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.notificationNumber = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a title.
|
||||
*
|
||||
* @param {string} title A title.
|
||||
*/
|
||||
setTitle: function (title) {
|
||||
setTitle(title) {
|
||||
this.title = title;
|
||||
|
||||
this.update();
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a notification number.
|
||||
*
|
||||
* @param {number} notificationNumber A number.
|
||||
*/
|
||||
setNotificationNumber: function (notificationNumber) {
|
||||
setNotificationNumber(notificationNumber) {
|
||||
this.notificationNumber = notificationNumber;
|
||||
|
||||
if (this.displayNotificationNumber) {
|
||||
this.update();
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a page title.
|
||||
*/
|
||||
update: function () {
|
||||
update() {
|
||||
let value = '';
|
||||
|
||||
if (this.displayNotificationNumber && this.notificationNumber) {
|
||||
@@ -98,7 +101,7 @@ _.extend(PageTitle.prototype, /** @lends PageTitle# */{
|
||||
value += this.title;
|
||||
|
||||
$('head title').text(value);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default PageTitle;
|
||||
|
||||
+54
-52
@@ -30,54 +30,56 @@
|
||||
|
||||
/**
|
||||
* A theme manager.
|
||||
*
|
||||
* @class
|
||||
* @param {module:models/settings} config A config.
|
||||
* @param {module:models/preferences} preferences Preferences.
|
||||
* @param {module:metadata} metadata Metadata.
|
||||
* @param {?string} [name] A name. If not set, then will be obtained from config and preferences.
|
||||
*/
|
||||
const ThemeManager = function (config, preferences, metadata, name) {
|
||||
/**
|
||||
* @private
|
||||
* @type {module:models/settings}
|
||||
*/
|
||||
this.config = config;
|
||||
/**
|
||||
* @private
|
||||
* @type {module:models/preferences}
|
||||
*/
|
||||
this.preferences = preferences;
|
||||
/**
|
||||
* @private
|
||||
* @type {module:metadata}
|
||||
*/
|
||||
this.metadata = metadata;
|
||||
class ThemeManager {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {?string}
|
||||
* @param {module:models/settings} config A config.
|
||||
* @param {module:models/preferences} preferences Preferences.
|
||||
* @param {module:metadata} metadata Metadata.
|
||||
* @param {?string} [name] A name. If not set, then will be obtained from config and preferences.
|
||||
*/
|
||||
this.name = name || null;
|
||||
};
|
||||
constructor(config, preferences, metadata, name) {
|
||||
/**
|
||||
* @private
|
||||
* @type {module:models/settings}
|
||||
*/
|
||||
this.config = config;
|
||||
|
||||
_.extend(ThemeManager.prototype, /** ThemeManager# */{
|
||||
/**
|
||||
* @private
|
||||
* @type {module:models/preferences}
|
||||
*/
|
||||
this.preferences = preferences;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {module:metadata}
|
||||
*/
|
||||
this.metadata = metadata;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {?string}
|
||||
*/
|
||||
this.name = name || null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
defaultParams: {
|
||||
defaultParams = {
|
||||
screenWidthXs: 768,
|
||||
dashboardCellHeight: 155,
|
||||
dashboardCellMargin: 19,
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a theme name for the current user.
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
getName: function () {
|
||||
getName() {
|
||||
if (this.name) {
|
||||
return this.name;
|
||||
}
|
||||
@@ -91,14 +93,14 @@ _.extend(ThemeManager.prototype, /** ThemeManager# */{
|
||||
}
|
||||
|
||||
return this.config.get('theme');
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a theme name currently applied to the DOM.
|
||||
*
|
||||
* @returns {string|null} Null if not applied.
|
||||
*/
|
||||
getAppliedName: function () {
|
||||
getAppliedName() {
|
||||
let name = window.getComputedStyle(document.body).getPropertyValue('--theme-name');
|
||||
|
||||
if (!name) {
|
||||
@@ -106,14 +108,14 @@ _.extend(ThemeManager.prototype, /** ThemeManager# */{
|
||||
}
|
||||
|
||||
return name.trim();
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a current theme is applied to the DOM.
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isApplied: function () {
|
||||
isApplied() {
|
||||
let appliedName = this.getAppliedName();
|
||||
|
||||
if (!appliedName) {
|
||||
@@ -121,14 +123,14 @@ _.extend(ThemeManager.prototype, /** ThemeManager# */{
|
||||
}
|
||||
|
||||
return this.getName() === appliedName;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a stylesheet path for a current theme.
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
getStylesheet: function () {
|
||||
getStylesheet() {
|
||||
let link = this.getParam('stylesheet') || 'client/css/espo/espo.css';
|
||||
|
||||
if (this.config.get('cacheTimestamp')) {
|
||||
@@ -136,14 +138,14 @@ _.extend(ThemeManager.prototype, /** ThemeManager# */{
|
||||
}
|
||||
|
||||
return link;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an iframe stylesheet path for a current theme.
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
getIframeStylesheet: function () {
|
||||
getIframeStylesheet() {
|
||||
let link = this.getParam('stylesheetIframe') || 'client/css/espo/espo-iframe.css';
|
||||
|
||||
if (this.config.get('cacheTimestamp')) {
|
||||
@@ -151,14 +153,14 @@ _.extend(ThemeManager.prototype, /** ThemeManager# */{
|
||||
}
|
||||
|
||||
return link;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an iframe-fallback stylesheet path for a current theme.
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
getIframeFallbackStylesheet: function () {
|
||||
getIframeFallbackStylesheet() {
|
||||
let link = this.getParam('stylesheetIframeFallback') || 'client/css/espo/espo-iframe.css'
|
||||
|
||||
if (this.config.get('cacheTimestamp')) {
|
||||
@@ -166,7 +168,7 @@ _.extend(ThemeManager.prototype, /** ThemeManager# */{
|
||||
}
|
||||
|
||||
return link;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a theme parameter.
|
||||
@@ -174,7 +176,7 @@ _.extend(ThemeManager.prototype, /** ThemeManager# */{
|
||||
* @param {string} name A parameter name.
|
||||
* @returns {*} Null if not set.
|
||||
*/
|
||||
getParam: function (name) {
|
||||
getParam(name) {
|
||||
if (name !== 'params' && name !== 'mappedParams') {
|
||||
let varValue = this.getVarParam(name);
|
||||
|
||||
@@ -202,14 +204,14 @@ _.extend(ThemeManager.prototype, /** ThemeManager# */{
|
||||
}
|
||||
|
||||
return this.defaultParams[name] || null;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {string} name
|
||||
* @returns {*}
|
||||
*/
|
||||
getVarParam: function (name) {
|
||||
getVarParam(name) {
|
||||
let params = this.getParam('params') || {};
|
||||
|
||||
if (!(name in params)) {
|
||||
@@ -235,14 +237,14 @@ _.extend(ThemeManager.prototype, /** ThemeManager# */{
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {string} name
|
||||
* @returns {*}
|
||||
*/
|
||||
getMappedParam: function (name) {
|
||||
getMappedParam(name) {
|
||||
let mappedParams = this.getParam('mappedParams') || {};
|
||||
|
||||
if (!(name in mappedParams)) {
|
||||
@@ -259,22 +261,22 @@ _.extend(ThemeManager.prototype, /** ThemeManager# */{
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @returns {string}
|
||||
*/
|
||||
getParentName: function () {
|
||||
getParentName() {
|
||||
return this.metadata.get(['themes', this.getName(), 'parent']) || 'Espo';
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a current theme is different from a system default theme.
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isUserTheme: function () {
|
||||
isUserTheme() {
|
||||
if (this.config.get('userThemesDisabled')) {
|
||||
return false;
|
||||
}
|
||||
@@ -286,7 +288,7 @@ _.extend(ThemeManager.prototype, /** ThemeManager# */{
|
||||
}
|
||||
|
||||
return name !== this.config.get('theme');
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default ThemeManager;
|
||||
|
||||
@@ -26,7 +26,8 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
define('views/email/modals/insert-field', ['views/modal', 'field-language'], function (Dep, FieldLanguage) {
|
||||
define('views/email/modals/insert-field',
|
||||
['views/modal', 'helpers/misc/field-language'], function (Dep, FieldLanguage) {
|
||||
|
||||
return Dep.extend({
|
||||
|
||||
|
||||
Reference in New Issue
Block a user