diff --git a/tests/js/jest/Array.test.js b/tests/js/jest/Array.test.js index 2ae5492329b..a9ef041f3c6 100644 --- a/tests/js/jest/Array.test.js +++ b/tests/js/jest/Array.test.js @@ -1,4 +1,5 @@ -const sum = require('ux/Array.js'); +// grr this pollutes global array object! how to cope whith it? +require('ux/Array.js'); const testArr = ["green", "red", "blue", "red"]; diff --git a/tests/js/jest/Readme.md b/tests/js/jest/Readme.md new file mode 100644 index 00000000000..d0fd5defd18 --- /dev/null +++ b/tests/js/jest/Readme.md @@ -0,0 +1,27 @@ +# jest tests + +## run tests +run all tests (using npm command) + + ./console src:npm 'test' + +run one test file only + + ./console src:npm 'test -- Array.test.js' + +run on test only + + ./console src:npm 'test -- Array.test.js --testNamePattern "Array.diff"' + +## debuging tests +run tests in dbg mode + + ./console src:npm 'run test-dbg' + +and attach a debugger, use [phpstorm](https://www.jetbrains.com/help/phpstorm/running-and-debugging-node-js.html#ws_node_debug_remote_chrome) or [chrome](chrome://inspect) + +## core concepts +* pure logic tests, no DOM interaction / testing +* no globals pollution (e.g. Tine, Ext, _, ...) + * neither in tests nor in program code to be tested + * you might need to rewrite / split your code so it stick to this rule \ No newline at end of file diff --git a/tests/js/jest/common.test.js b/tests/js/jest/common.test.js new file mode 100644 index 00000000000..f4d1f7d0c7f --- /dev/null +++ b/tests/js/jest/common.test.js @@ -0,0 +1,22 @@ +import common from "common"; + + +describe('common functions', () => { + describe('html2text', () => { + it('ignores empty divs', () => { + expect(common.html2text( '
')) + .toEqual("\nHello,\n\n...") + }) + + it('copes with styled div tags', () => { + expect(common.html2text( 'Dipl.-Phys. Cornelius WeissHello,...
'; -if (Tine.Tinebase.common.html2text(s) != "\nHello,\n\n...") console.error('ignore empty div: "' + Tine.Tinebase.common.html2text(s) + '"'); - -var s = 'Dipl.-Phys. Cornelius WeissHello,...
-var TopicRecord = Tine.Tinebase.data.Record.create([
+var TopicRecord = Record.create([
{name: 'summary', mapping: 'topic_title'},
{name: 'details', mapping: 'username'}
], {
@@ -345,11 +359,11 @@ var TopicRecord = Tine.Tinebase.data.Record.create([
* @static
*/
-Tine.Tinebase.data.Record.create = function(o, meta) {
- var f = Ext.extend(Tine.Tinebase.data.Record, {});
+Record.create = function(o, meta) {
+ var f = extend(Record, {});
var p = f.prototype;
- Ext.apply(p, meta);
- p.fields = new Ext.util.MixedCollection(false, function(field) {
+ apply(p, meta);
+ p.fields = new MixedCollection(false, function(field) {
return field.name;
});
p.fields.get = function(name) {
@@ -360,14 +374,14 @@ Tine.Tinebase.data.Record.create = function(o, meta) {
sortDir: 'DESC'
};
} else {
- return Ext.util.MixedCollection.prototype.get.apply(this, arguments);
+ return MixedCollection.prototype.get.apply(this, arguments);
}
};
for(var i = 0, len = o.length; i < len; i++) {
if (o[i]['name'] == meta.containerProperty && meta.allowBlankContainer === false) {
o[i]['allowBlank'] = false;
}
- p.fields.add(new Ext.data.Field(o[i]));
+ p.fields.add(new Field(o[i]));
}
f.getField = function(name) {
return p.fields.get(name);
@@ -392,7 +406,7 @@ Tine.Tinebase.data.Record.create = function(o, meta) {
f.getFieldNames = function() {
if (! p.fieldsarray) {
var arr = p.fieldsarray = [];
- Ext.each(p.fields.items, function(item) {arr.push(item.name);});
+ forEach(p.fields.items, function(item) {arr.push(item.name);});
}
return p.fieldsarray;
};
@@ -400,11 +414,11 @@ Tine.Tinebase.data.Record.create = function(o, meta) {
return p.fields.indexOfKey(n) >= 0;
};
f.getDataFields = function() {
- const systemFields = _.map(Tine.Tinebase.Model.genericFields, 'name')
+ const systemFields = map(Record.genericFields, 'name')
.concat(f.getMeta('idProperty'))
.concat(p.modelConfiguration?.hasNotes ? [] : 'notes')
.concat(p.modelConfiguration?.delegateAclField && p.grantsPath ? String(p.grantsPath).replace(/^data\./, '') : []);
- return _.difference(p.modelConfiguration?.fieldKeys, systemFields);
+ return difference(p.modelConfiguration?.fieldKeys, systemFields);
};
f.getRecordName = function() {
var app = Tine.Tinebase.appMgr.get(p.appName),
@@ -477,18 +491,18 @@ Tine.Tinebase.data.Record.create = function(o, meta) {
return f.getMeta('phpClassName');
}
// if var app is a record class, the getMeta method is called
- if (Ext.isFunction(app.getMeta)) {
+ if (isFunction(app.getMeta)) {
return app.getMeta('phpClassName');
}
- var appName = (Ext.isObject(app) && app.hasOwnProperty('name')) ? app.name : app;
+ var appName = (isObject(app) && app.hasOwnProperty('name')) ? app.name : app;
return appName + '_Model_' + model;
};
f.getModelConfiguration = function() {
return p.modelConfiguration;
};
f.getProxy = function() {
- return _.get(window, `Tine.${p.appName}.${p.modelName.toLowerCase()}Backend`);
+ return get(window, `Tine.${p.appName}.${p.modelName.toLowerCase()}Backend`);
}
// sanitize containerProperty label
@@ -502,11 +516,11 @@ Tine.Tinebase.data.Record.create = function(o, meta) {
if (!p.grantsPath) {
p.grantsPath = 'data' + (containerProperty ? ('.' + containerProperty) : '') + '.account_grants';
}
- Tine.Tinebase.data.RecordMgr.add(f);
+ recordMgr.add(f);
return f;
};
-Tine.Tinebase.data.Record.generateUID = function(length) {
+Record.generateUID = function(length) {
length = length || 40;
var s = '0123456789abcdef',
@@ -517,17 +531,17 @@ Tine.Tinebase.data.Record.generateUID = function(length) {
return uuid.join('');
};
-Tine.Tinebase.data.Record.getDefaultData = function(recordClass, defaults) {
+Record.getDefaultData = function(recordClass, defaults) {
var modelConfig = recordClass.getModelConfiguration(),
appName = modelConfig.appName,
modelName = modelConfig.modelName;
// if default data is empty, it will be resolved to an array
- if (Ext.isArray(modelConfig.defaultData)) {
+ if (isArray(modelConfig.defaultData)) {
modelConfig.defaultData = {};
}
- const dd = Ext.decode(Ext.encode(modelConfig.defaultData));
+ const dd = JSON.parse(JSON.stringify(modelConfig.defaultData));
// find container by selection or use defaultContainer by registry
if (modelConfig.containerProperty) {
@@ -536,7 +550,7 @@ Tine.Tinebase.data.Record.getDefaultData = function(recordClass, defaults) {
registry = app.getRegistry(),
ctp = app.getMainScreen().getWestPanel().getContainerTreePanel();
- var container = (ctp && Ext.isFunction(ctp.getDefaultContainer) ? ctp.getDefaultContainer() : null)
+ var container = (ctp && isFunction(ctp.getDefaultContainer) ? ctp.getDefaultContainer() : null)
|| (registry ? registry.get("default" + modelName + "Container") : null);
if (container) {
@@ -549,8 +563,8 @@ Tine.Tinebase.data.Record.getDefaultData = function(recordClass, defaults) {
dd['account_grants'] = {'adminGrant': true};
// NOTE: ui config overwrites db config
- _.forEach(modelConfig.fields, (config, name) => {
- const fieldDefault = _.get(config, 'uiconfig.default', this);
+ forEach(modelConfig.fields, (config, name) => {
+ const fieldDefault = get(config, 'uiconfig.default', this);
if (fieldDefault !== this) {
dd[name] = fieldDefault;
}
@@ -559,76 +573,17 @@ Tine.Tinebase.data.Record.getDefaultData = function(recordClass, defaults) {
return Object.assign(dd, defaults);
};
-Tine.Tinebase.data.RecordManager = Ext.extend(Ext.util.MixedCollection, {
- add: function(record) {
- if (! Ext.isFunction(record.getMeta)) {
- throw new Ext.Error('only records of type Tinebase.data.Record could be added');
- }
- var appName = record.getMeta('appName'),
- modelName = record.getMeta('modelName');
-
- if (! appName && modelName) {
- throw new Ext.Error('appName and modelName must be in the metadatas');
- }
-
- Tine.Tinebase.data.RecordManager.superclass.add.call(this, appName + '.' + modelName, record);
- },
-
- get: function(appName, modelName) {
- if (! appName && _.isFunction(_.get(modelName, 'getMeta'))) {
- return modelName;
- }
- if (! appName) return;
- if (Ext.isFunction(appName.getField)) {
- return appName;
- }
- if (! modelName && appName.modelName) {
- modelName = appName.modelName;
- }
- if (appName.appName) {
- appName = appName.appName;
- }
-
- if (_.isString(appName) && !modelName) {
- appName = appName.replace(/^Tine[._]/, '')
- .replace(/[._]Model[._]/, '.');
-
- let appPart = appName.match(/^.+\./);
- if (appPart) {
- modelName = appName.replace(appPart[0], '')
- appName = appPart[0].replace(/\.$/, '');
- }
- }
-
- if (! Ext.isString(appName)) {
- throw new Ext.Error('appName must be a string');
- }
-
- Ext.each([appName, modelName], function(what) {
- if (! Ext.isString(what)) return;
- var parts = what.split(/(?:_Model_)|(?:\.)/);
- if (parts.length > 1) {
- appName = parts[0];
- modelName = parts[1];
- }
- });
-
- return Tine.Tinebase.data.RecordManager.superclass.get.call(this, appName + '.' + modelName);
- }
-});
-Tine.Tinebase.data.RecordMgr = new Tine.Tinebase.data.RecordManager(true);
-
/**
* create record from json string
*
* @param {String} json
- * @param {Tine.Tinebase.data.Record} recordClass
- * @returns {Tine.Tinebase.data.Record}
+ * @param {Record} recordClass
+ * @returns {Record}
*/
-Tine.Tinebase.data.Record.setFromJson = function(json, recordClass) {
- recordClass = Tine.Tinebase.data.RecordMgr.get(recordClass);
+Record.setFromJson = function(json, recordClass) {
+ recordClass = recordMgr.get(recordClass);
if (!recordClass) return null;
- var jsonReader = new Ext.data.JsonReader({
+ var jsonReader = new JsonReader({
id: recordClass.idProperty,
root: 'results',
totalProperty: 'totalcount'
@@ -636,20 +591,20 @@ Tine.Tinebase.data.Record.setFromJson = function(json, recordClass) {
try {
var recordData = {
- results: _.compact([
- Ext.isString(json) ? Ext.decode(json) : json
+ results: compact([
+ isString(json) ? JSON.parse(json) : json
])
},
data = jsonReader.readRecords(recordData),
record = data.records[0];
} catch (e) {
- Tine.log.warn('Exception in setFromJson:');
- Tine.log.warn(e);
+ log.warn('Exception in setFromJson:');
+ log.warn(e);
}
- let recordId = _.get(record, 'data.' + _.get(record, 'idProperty'));
+ let recordId = get(record, 'data.' + get(record, 'idProperty'));
if (!recordId && [0, '0'].indexOf(recordId) < 0 ) {
- recordId = Tine.Tinebase.data.Record.generateUID();
+ recordId = Record.generateUID();
}
if (! record) {
@@ -660,3 +615,31 @@ Tine.Tinebase.data.Record.setFromJson = function(json, recordClass) {
return record;
};
+
+/**
+ * @type {Array}
+ *
+ * modlog Fields
+ */
+
+Record.modlogFields = [
+ { name: 'creation_time', type: 'date', dateFormat: "Y-m-d H:i:s", omitDuplicateResolving: true },
+ { name: 'created_by', omitDuplicateResolving: true },
+ { name: 'last_modified_time', type: 'date', dateFormat: "Y-m-d H:i:s", omitDuplicateResolving: true },
+ { name: 'last_modified_by', omitDuplicateResolving: true },
+ { name: 'is_deleted', type: 'boolean', omitDuplicateResolving: true },
+ { name: 'deleted_time', type: 'date', dateFormat: "Y-m-d H:i:s", omitDuplicateResolving: true },
+ { name: 'deleted_by', omitDuplicateResolving: true },
+ { name: 'seq', omitDuplicateResolving: true }
+];
+
+/**
+ * @type {Array}
+ * generic Record fields
+ */
+Record.genericFields = Record.modlogFields.concat([
+ { name: 'container_id', header: 'Container', omitDuplicateResolving: false}
+]);
+
+
+export default Record
diff --git a/tine20/Tinebase/js/data/RecordMgr.js b/tine20/Tinebase/js/data/RecordMgr.js
new file mode 100644
index 00000000000..9f508e072ba
--- /dev/null
+++ b/tine20/Tinebase/js/data/RecordMgr.js
@@ -0,0 +1,73 @@
+/*
+ * Tine 2.0
+ *
+ * @package Tine
+ * @subpackage Tinebase
+ * @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
+ * @author Cornelius Weiss This class encapsulates the field definition information specified in the field definition objects @@ -11,17 +16,17 @@ *
Developers do not need to instantiate this class. Instances are created by {@link Ext.data.Record.create} * and cached in the {@link Ext.data.Record#fields fields} property of the created Record constructor's prototype.
*/ -Ext.data.Field = function(config){ +const Field = function(config){ if(typeof config == "string"){ config = {name: config}; } - Ext.apply(this, config); + apply(this, config); if(!this.type){ this.type = "auto"; } - var st = Ext.data.SortTypes; + var st = SortTypes; // named sortTypes are supported, here we look them up if(typeof this.sortType == "string"){ this.sortType = st[this.sortType]; @@ -55,7 +60,7 @@ Ext.data.Field = function(config){ cv = function(v){ return v; }; break; case "string": - cv = function(v){ return (v === undefined || v === null) ? '' : (_.isObject(v) ? JSON.stringify(v) : String(v)); }; + cv = function(v){ return (v === undefined || v === null) ? '' : (isObject(v) ? JSON.stringify(v) : String(v)); }; break; case "int": cv = function(v){ @@ -73,7 +78,7 @@ Ext.data.Field = function(config){ cv = function(v){ return v === true || v === "true" || v == 1; }; break; case "date": - cv = function(v){ + var c1 = function(v){ if(!v){ return ''; } @@ -83,7 +88,7 @@ Ext.data.Field = function(config){ if (v === 'CURRENT_TIME') { return new Date().clearTime(); } - if(Ext.isDate(v)){ + if(isDate(v)){ return v; } if(dateFormat){ @@ -98,6 +103,15 @@ Ext.data.Field = function(config){ var parsed = Date.parse(v); return parsed ? new Date(parsed) : null; }; + cv = function(v) { + var d = c1(v); + if (isDate(d)) { + d.toJSON = function() { + return this.format(config.dateFormat); + } + } + return d; + }; break; default: cv = function(v){ return v; }; @@ -108,7 +122,7 @@ Ext.data.Field = function(config){ } }; -Ext.data.Field.prototype = { +Field.prototype = { /** * @cfg {String} name * The name by which the field is referenced within the Record. This is referenced by, for example, @@ -255,3 +269,5 @@ sortType: function(value) { */ allowBlank : true }; + +module.exports = Field; \ No newline at end of file diff --git a/tine20/library/ExtJS/src/data/DataReader.js b/tine20/library/ExtJS/src/data/DataReader.js index ec08cec6748..6ef571fe088 100644 --- a/tine20/library/ExtJS/src/data/DataReader.js +++ b/tine20/library/ExtJS/src/data/DataReader.js @@ -4,8 +4,14 @@ * licensing@extjs.com * http://www.extjs.com/license */ + +const { extend, isObject, isEmpty, isArray, apply } = require("Ext/core/core/Ext"); +const Record = require("Ext/data/Record"); +const ExtError = require('Ext/core/Error'); +const emptyFn = () => {}; + /** - * @class Ext.data.DataReader + * @class DataReader * Abstract base class for reading structured data from a data source and converting * it into an object containing {@link Ext.data.Record} objects and metadata for use * by an {@link Ext.data.Store}. This class is intended to be extended and should not @@ -18,7 +24,7 @@ * will be passed to {@link Ext.data.Record#create}, or a {@link Ext.data.Record Record} * constructor created using {@link Ext.data.Record#create}. */ -Ext.data.DataReader = function(meta, recordType){ +const DataReader = function(meta, recordType){ /** * This DataReader's configured metadata as passed to the constructor. * @type Mixed @@ -31,8 +37,8 @@ Ext.data.DataReader = function(meta, recordType){ * will be passed to {@link Ext.data.Record#create}, or a {@link Ext.data.Record Record} * constructor created from {@link Ext.data.Record#create}. */ - this.recordType = Ext.isArray(recordType) ? - Ext.data.Record.create(recordType) : recordType; + this.recordType = isArray(recordType) ? + Record.create(recordType) : recordType; // if recordType defined make sure extraction functions are defined if (this.recordType){ @@ -42,42 +48,43 @@ Ext.data.DataReader = function(meta, recordType){ } }; -Ext.data.DataReader.prototype = { +DataReader.prototype = { + readerType: 'json', /** * @cfg {String} messageProperty [undefined] Optional name of a property within a server-response that represents a user-feedback message. */ /** * Abstract method created in extension's buildExtractors impl. */ - getTotal: Ext.emptyFn, + getTotal: emptyFn, /** * Abstract method created in extension's buildExtractors impl. */ - getRoot: Ext.emptyFn, + getRoot: emptyFn, /** * Abstract method created in extension's buildExtractors impl. */ - getMessage: Ext.emptyFn, + getMessage: emptyFn, /** * Abstract method created in extension's buildExtractors impl. */ - getSuccess: Ext.emptyFn, + getSuccess: emptyFn, /** * Abstract method created in extension's buildExtractors impl. */ - getId: Ext.emptyFn, + getId: emptyFn, /** * Abstract method, overridden in DataReader extensions such as {@link Ext.data.JsonReader} and {@link Ext.data.XmlReader} */ - buildExtractors : Ext.emptyFn, + buildExtractors : emptyFn, /** * Abstract method overridden in DataReader extensions such as {@link Ext.data.JsonReader} and {@link Ext.data.XmlReader} */ - extractData : Ext.emptyFn, + extractData : emptyFn, /** * Abstract method overridden in DataReader extensions such as {@link Ext.data.JsonReader} and {@link Ext.data.XmlReader} */ - extractValues : Ext.emptyFn, + extractValues : emptyFn, /** * Used for un-phantoming a record after a successful database insert. Sets the records pk along with new data from server. @@ -89,10 +96,10 @@ Ext.data.DataReader.prototype = { * @param {Object/Object[]} data The new record data to apply. Must include the primary-key from database defined in idProperty field. */ realize: function(rs, data){ - if (Ext.isArray(rs)) { + if (isArray(rs)) { for (var i = rs.length - 1; i >= 0; i--) { // recurse - if (Ext.isArray(data)) { + if (isArray(data)) { this.realize(rs.splice(i,1).shift(), data.splice(i,1).shift()); } else { @@ -104,13 +111,13 @@ Ext.data.DataReader.prototype = { } else { // If rs is NOT an array but data IS, see if data contains just 1 record. If so extract it and carry on. - if (Ext.isArray(data) && data.length == 1) { + if (isArray(data) && data.length == 1) { data = data.shift(); } if (!this.isData(data)) { // TODO: Let exception-handler choose to commit or not rather than blindly rs.commit() here. //rs.commit(); - throw new Ext.data.DataReader.Error('realize', rs); + throw new DataReader.Error('realize', rs); } rs.phantom = false; // <-- That's what it's all about rs._phid = rs.id; // <-- copy phantom-id -> _phid, so we can remap in Store#onCreateRecords @@ -134,9 +141,9 @@ Ext.data.DataReader.prototype = { * @param {Object/Object[]} data */ update : function(rs, data) { - if (Ext.isArray(rs)) { + if (isArray(rs)) { for (var i=rs.length-1; i >= 0; i--) { - if (Ext.isArray(data)) { + if (isArray(data)) { this.update(rs.splice(i,1).shift(), data.splice(i,1).shift()); } else { @@ -148,7 +155,7 @@ Ext.data.DataReader.prototype = { } else { // If rs is NOT an array but data IS, see if data contains just 1 record. If so extract it and carry on. - if (Ext.isArray(data) && data.length == 1) { + if (isArray(data) && data.length == 1) { data = data.shift(); } if (this.isData(data)) { @@ -170,13 +177,13 @@ Ext.data.DataReader.prototype = { */ extractData : function(root, returnRecords) { // A bit ugly this, too bad the Record's raw data couldn't be saved in a common property named "raw" or something. - var rawName = (this instanceof Ext.data.JsonReader) ? 'json' : 'node'; + var rawName = (this.readerType === 'json') ? 'json' : 'node'; var rs = []; // Had to add Check for XmlReader, #isData returns true if root is an Xml-object. Want to check in order to re-factor // #extractData into DataReader base, since the implementations are almost identical for JsonReader, XmlReader - if (this.isData(root) && !(this instanceof Ext.data.XmlReader)) { + if (this.isData(root) && !(this.readerType === 'xml')) { root = [root]; } var f = this.recordType.prototype.fields, @@ -210,7 +217,7 @@ Ext.data.DataReader.prototype = { * @return {Boolean} */ isData : function(data) { - return (data && Ext.isObject(data) && !Ext.isEmpty(this.getId(data))) ? true : false; + return (data && isObject(data) && !isEmpty(this.getId(data))) ? true : false; }, // private function a store will createSequence upon @@ -218,28 +225,30 @@ Ext.data.DataReader.prototype = { delete this.ef; if (meta) { this.meta = meta; - this.recordType = Ext.data.Record.create(meta.fields); + this.recordType = Record.create(meta.fields); } this.buildExtractors(); } }; /** - * @class Ext.data.DataReader.Error + * @class DataReader.Error * @extends Ext.Error - * General error class for Ext.data.DataReader + * General error class for DataReader */ -Ext.data.DataReader.Error = Ext.extend(Ext.Error, { +DataReader.Error = extend(ExtError, { constructor : function(message, arg) { this.arg = arg; - Ext.Error.call(this, message); + ExtError.call(this, message); }, - name: 'Ext.data.DataReader' + name: 'DataReader' }); -Ext.apply(Ext.data.DataReader.Error.prototype, { +apply(DataReader.Error.prototype, { lang : { 'update': "#update received invalid data from server. Please see docs for DataReader#update and review your DataReader configuration.", 'realize': "#realize was called with invalid remote-data. Please see the docs for DataReader#realize and review your DataReader configuration.", 'invalid-response': "#readResponse received an invalid response from the server." } }); + +module.exports = DataReader; \ No newline at end of file diff --git a/tine20/library/ExtJS/src/data/JsonReader.js b/tine20/library/ExtJS/src/data/JsonReader.js index 952c2cf2d21..bd09458ebd2 100644 --- a/tine20/library/ExtJS/src/data/JsonReader.js +++ b/tine20/library/ExtJS/src/data/JsonReader.js @@ -4,15 +4,21 @@ * licensing@extjs.com * http://www.extjs.com/license */ + +const { applyIf, extend, isDefined, isEmpty, isArray, isFunction, apply } = require("Ext/core/core/Ext"); +const ExtError = require('Ext/core/Error'); +const DataReader = require('./DataReader'); +const Response = require('./Response'); + /** - * @class Ext.data.JsonReader + * @class JsonReader * @extends Ext.data.DataReader *Data reader class to create an Array of {@link Ext.data.Record} objects * from a JSON packet based on mappings in a provided {@link Ext.data.Record} * constructor.
*Example code:
*
-var myReader = new Ext.data.JsonReader({
+var myReader = new JsonReader({
// metadata configuration options:
{@link #idProperty}: 'id'
{@link #root}: 'rows',
@@ -51,7 +57,7 @@ var myReader = new Ext.data.JsonReader({
* Note that reconfiguring a Store potentially invalidates objects which may
* refer to Fields or Records which no longer exist.
* To use this facility you would create the JsonReader like this:
-var myReader = new Ext.data.JsonReader();
+var myReader = new JsonReader();
* The first data packet from the server would configure the reader by
* containing a metaData property and the data. For
@@ -110,7 +116,7 @@ var myReader = new Ext.data.JsonReader();
* will be passed to {@link Ext.data.Record#create}, or a {@link Ext.data.Record Record}
* constructor created from {@link Ext.data.Record#create}.
*/
-Ext.data.JsonReader = function(meta, recordType){
+const JsonReader = function(meta, recordType){
meta = meta || {};
/**
* @cfg {String} idProperty [id] Name of the property within a row object
@@ -135,15 +141,15 @@ Ext.data.JsonReader = function(meta, recordType){
* packet value for this property should be an empty array to clear the data
* or show no data.
*/
- Ext.applyIf(meta, {
+ applyIf(meta, {
idProperty: 'id',
successProperty: 'success',
totalProperty: 'total'
});
- Ext.data.JsonReader.superclass.constructor.call(this, meta, recordType || meta.fields);
+ JsonReader.superclass.constructor.call(this, meta, recordType || meta.fields);
};
-Ext.extend(Ext.data.JsonReader, Ext.data.DataReader, {
+extend(JsonReader, DataReader, {
/**
* This JsonReader's metadata as passed to the constructor, or as passed in
* the last data packet's metaData property.
@@ -158,7 +164,7 @@ Ext.extend(Ext.data.JsonReader, Ext.data.DataReader, {
*/
read : function(response){
var json = response.responseText;
- var o = Ext.decode(json);
+ var o = JSON.parse(json);
if(!o) {
throw {message: 'JsonReader.read: Json object not found'};
}
@@ -173,24 +179,24 @@ Ext.extend(Ext.data.JsonReader, Ext.data.DataReader, {
* there's ugly duplication going on due to maintaining backwards compat. with 2.0. It's time to do this.
*/
readResponse : function(action, response) {
- var o = (response.responseText !== undefined) ? Ext.decode(response.responseText) : response;
+ var o = (response.responseText !== undefined) ? JSON.parse(response.responseText) : response;
if(!o) {
- throw new Ext.data.JsonReader.Error('response');
+ throw new JsonReader.Error('response');
}
var root = this.getRoot(o);
- if (action === Ext.data.Api.actions.create) {
- var def = Ext.isDefined(root);
- if (def && Ext.isEmpty(root)) {
- throw new Ext.data.JsonReader.Error('root-empty', this.meta.root);
+ if (action === 'create') {
+ var def = isDefined(root);
+ if (def && isEmpty(root)) {
+ throw new JsonReader.Error('root-empty', this.meta.root);
}
else if (!def) {
- throw new Ext.data.JsonReader.Error('root-undefined-response', this.meta.root);
+ throw new JsonReader.Error('root-undefined-response', this.meta.root);
}
}
// instantiate response object
- var res = new Ext.data.Response({
+ var res = new Response({
action: action,
success: this.getSuccess(o),
data: (root) ? this.extractData(root, false) : [],
@@ -199,8 +205,8 @@ Ext.extend(Ext.data.JsonReader, Ext.data.DataReader, {
});
// blow up if no successProperty
- if (Ext.isEmpty(res.success)) {
- throw new Ext.data.JsonReader.Error('successProperty-response', this.meta.successProperty);
+ if (isEmpty(res.success)) {
+ throw new JsonReader.Error('successProperty-response', this.meta.successProperty);
}
return res;
},
@@ -298,10 +304,10 @@ Ext.extend(Ext.data.JsonReader, Ext.data.DataReader, {
createAccessor : function(){
var re = /[\[\.]/;
return function(expr) {
- if(Ext.isEmpty(expr)){
- return Ext.emptyFn;
+ if(isEmpty(expr)){
+ return () => {};
}
- if(Ext.isFunction(expr)){
+ if(isFunction(expr)){
return expr;
}
var i = String(expr).search(re);
@@ -310,7 +316,7 @@ Ext.extend(Ext.data.JsonReader, Ext.data.DataReader, {
}
return function(obj){
// support array as roots
- return Ext.isArray(obj) && obj.length > 0 ? obj : obj[expr];
+ return isArray(obj) && obj.length > 0 ? obj : obj[expr];
};
};
@@ -335,17 +341,17 @@ Ext.extend(Ext.data.JsonReader, Ext.data.DataReader, {
});
/**
- * @class Ext.data.JsonReader.Error
+ * @class JsonReader.Error
* Error class for JsonReader
*/
-Ext.data.JsonReader.Error = Ext.extend(Ext.Error, {
+JsonReader.Error = extend(ExtError, {
constructor : function(message, arg) {
this.arg = arg;
- Ext.Error.call(this, message);
+ ExtError.call(this, message);
},
- name : 'Ext.data.JsonReader'
+ name : 'JsonReader'
});
-Ext.apply(Ext.data.JsonReader.Error.prototype, {
+apply(JsonReader.Error.prototype, {
lang: {
'response': 'An error occurred while json-decoding your server response',
'successProperty-response': 'Could not locate your "successProperty" in your server response. Please review your JsonReader config to ensure the config-property "successProperty" matches the property in your server-response. See the JsonReader docs.',
@@ -354,3 +360,5 @@ Ext.apply(Ext.data.JsonReader.Error.prototype, {
'root-empty': 'Data was expected to be returned by the server in the "root" property of the response. Please review your JsonReader configuration to ensure the "root" property matches that returned in the server-response. See JsonReader docs.'
}
});
+
+module.exports = JsonReader;
\ No newline at end of file
diff --git a/tine20/library/ExtJS/src/data/Record.js b/tine20/library/ExtJS/src/data/Record.js
index 04696d5cb6f..20286a06de6 100644
--- a/tine20/library/ExtJS/src/data/Record.js
+++ b/tine20/library/ExtJS/src/data/Record.js
@@ -4,8 +4,14 @@
* licensing@extjs.com
* http://www.extjs.com/license
*/
+
+const { extend, isPrimitive, isEmpty } = require("Ext/core/core/Ext");
+const Field = require("Ext/data/DataField");
+const MixedCollection = require("Ext/util/MixedCollection");
+const { cloneDeep, forEach } = require('lodash');
+
/**
- * @class Ext.data.Record
+ * @class Record
* Instances of this class encapsulate both Record definition information, and Record
* value information for use in {@link Ext.data.Store} objects, or any code which needs
* to access Records cached in an {@link Ext.data.Store} object.
@@ -19,10 +25,10 @@
* properties, and also a reference to its owning Store which in turn holds references to its Records.
* This means that a whole Record may not be encoded using {@link Ext.util.JSON.encode}. Instead, use the
* {@link #data}
and {@link #id}
properties.
- * Record objects generated by this constructor inherit all the methods of Ext.data.Record listed below.
+ * Record objects generated by this constructor inherit all the methods of Record listed below.
* @constructor
* This constructor should not be used to create Record objects. Instead, use {@link #create} to
- * generate a subclass of Ext.data.Record configured with information about its constituent fields.
+ * generate a subclass of Record configured with information about its constituent fields.
*
The generated constructor has the same signature as this constructor.
* @param {Object} data (Optional) An object, the properties of which provide values for the new Record's
* fields. If not specified the {@link Ext.data.Field#defaultValue defaultValue}
@@ -33,9 +39,9 @@
* id
is not specified a {@link #phantom}
* Record will be created with an {@link #Record.id automatically generated id}.
*/
-Ext.data.Record = function(data, id){
+const Record = function(data, id){
// if no id, call the auto id method
- this.id = (id || id === 0) ? id : Ext.data.Record.id(this);
+ this.id = (id || id === 0) ? id : Record.id(this);
Object.assign(this, data.__meta || {});
delete(data.__meta);
this.data = data || {};
@@ -48,7 +54,7 @@ Ext.data.Record = function(data, id){
* object must contain properties named after the {@link Ext.data.Field field}
* {@link Ext.data.Field#name}s. Example usage:
// create a Record constructor from a description of the fields
-var TopicRecord = Ext.data.Record.create([ // creates a subclass of Ext.data.Record
+var TopicRecord = Record.create([ // creates a subclass of Record
{{@link Ext.data.Field#name name}: 'title', {@link Ext.data.Field#mapping mapping}: 'topic_title'},
{name: 'author', mapping: 'username', allowBlank: false},
{name: 'totalPosts', mapping: 'topic_replies', type: 'int'},
@@ -80,14 +86,14 @@ myStore.{@link Ext.data.Store#add add}(myNewRecord);
* to the definition. The constructor has the same signature as {@link #Record}.
* @static
*/
-Ext.data.Record.create = function(o){
- var f = Ext.extend(Ext.data.Record, {});
+Record.create = function(o){
+ var f = extend(Record, {});
var p = f.prototype;
- p.fields = new Ext.util.MixedCollection(false, function(field){
+ p.fields = new MixedCollection(false, function(field){
return field.name;
});
for(var i = 0, len = o.length; i < len; i++){
- p.fields.add(new Ext.data.Field(o[i]));
+ p.fields.add(new Field(o[i]));
}
f.getField = function(name){
return p.fields.get(name);
@@ -95,31 +101,31 @@ Ext.data.Record.create = function(o){
return f;
};
-Ext.data.Record.PREFIX = 'ext-record';
-Ext.data.Record.AUTO_ID = 1;
-Ext.data.Record.EDIT = 'edit';
-Ext.data.Record.REJECT = 'reject';
-Ext.data.Record.COMMIT = 'commit';
+Record.PREFIX = 'ext-record';
+Record.AUTO_ID = 1;
+Record.EDIT = 'edit';
+Record.REJECT = 'reject';
+Record.COMMIT = 'commit';
/**
* Generates a sequential id. This method is typically called when a record is {@link #create}d
* and {@link #Record no id has been specified}. The returned id takes the form:
* {PREFIX}-{AUTO_ID}.
- * - PREFIX : String
Ext.data.Record.PREFIX
+ *
- PREFIX : String
Record.PREFIX
* (defaults to 'ext-record')
- * - AUTO_ID : String
Ext.data.Record.AUTO_ID
+ *
- AUTO_ID : String
Record.AUTO_ID
* (defaults to 1 initially)
*
* @param {Record} rec The record being created. The record does not exist, it's a {@link #phantom}.
* @return {String} auto-generated string id, "ext-record-i++';
*/
-Ext.data.Record.id = function(rec) {
+Record.id = function(rec) {
rec.phantom = true;
- return [Ext.data.Record.PREFIX, '-', Ext.data.Record.AUTO_ID++].join('');
+ return [Record.PREFIX, '-', Record.AUTO_ID++].join('');
};
-Ext.data.Record.prototype = {
+Record.prototype = {
/**
* This property is stored in the Record definition's prototype
* A MixedCollection containing the defined {@link Ext.data.Field Field}s for this Record. Read-only.
@@ -197,9 +203,9 @@ Ext.data.Record.prototype = {
},
setData: function(data) {
- _.forEach(data, (v,k) => {
+ forEach(data, (v,k) => {
if (k === '__meta') {
- _.forEach(this.__metaFields, (m) => {
+ forEach(this.__metaFields, (m) => {
if (v.hasOwnProperty(m)) {
this[m] = v[m];
}
@@ -214,7 +220,7 @@ Ext.data.Record.prototype = {
* Set the {@link Ext.data.Field#name named field} to the specified value. For example:
*
// record has a field named 'firstname'
-var Employee = Ext.data.Record.{@link #create}([
+var Employee = Record.{@link #create}([
{name: 'firstname'},
...
]);
@@ -246,7 +252,7 @@ rec.{@link #commit}(); // updates the view
*/
set : function(name, value){
Tine.Tinebase.common.assertComparable(value);
- var encode = Ext.isPrimitive(value) ? String : Ext.encode;
+ var encode = isPrimitive(value) ? String : JSON.stringify;
if(encode(this.data[name]) == encode(value)) {
return;
}
@@ -378,7 +384,7 @@ rec.{@link #commit}(); // updates the view
getChanges : function(){
var m = this.modified, cs = {};
for(var n in m){
- const encode = Ext.isPrimitive(this.modified[n]) ? String : Ext.encode;
+ const encode = isPrimitive(this.modified[n]) ? String : JSON.stringify;
if(m.hasOwnProperty(n) && encode(this.modified[n]) !== encode(this.data[n])){
cs[n] = this.data[n];
}
@@ -402,12 +408,12 @@ rec.{@link #commit}(); // updates the view
* of the record being copied. See {@link #id}
.
* To generate a phantom record with a new id use:
var rec = record.copy(); // clone the record
-Ext.data.Record.id(rec); // automatically generate a unique sequential id
+Record.id(rec); // automatically generate a unique sequential id
*
* @return {Record}
*/
copy : function(newId) {
- return new this.constructor(_.cloneDeep(this.data), newId || this.id);
+ return new this.constructor(cloneDeep(this.data), newId || this.id);
},
/**
@@ -428,7 +434,7 @@ Ext.data.Record.id(rec); // automatically generate a unique sequential id
*/
isValid : function() {
return this.fields.find(function(f) {
- return (f.allowBlank === false && Ext.isEmpty(this.data[f.name])) ? true : false;
+ return (f.allowBlank === false && isEmpty(this.data[f.name])) ? true : false;
},this) ? false : true;
},
@@ -451,3 +457,5 @@ Ext.data.Record.id(rec); // automatically generate a unique sequential id
},this);
}
};
+
+module.exports = Record;
\ No newline at end of file
diff --git a/tine20/library/ExtJS/src/data/Response.js b/tine20/library/ExtJS/src/data/Response.js
index 83949195fcf..8b6f0748d7c 100644
--- a/tine20/library/ExtJS/src/data/Response.js
+++ b/tine20/library/ExtJS/src/data/Response.js
@@ -8,10 +8,10 @@
* @class Ext.data.Response
* A generic response class to normalize response-handling internally to the framework.
*/
-Ext.data.Response = function(params) {
- Ext.apply(this, params);
+const Response = function(params) {
+ Object.assign(this, params);
};
-Ext.data.Response.prototype = {
+Response.prototype = {
/**
* @cfg {String} action {@link Ext.data.Api#actions}
*/
@@ -37,3 +37,5 @@ Ext.data.Response.prototype = {
*/
records: undefined
};
+
+module.exports = Response;
\ No newline at end of file
diff --git a/tine20/library/ExtJS/src/data/SortTypes.js b/tine20/library/ExtJS/src/data/SortTypes.js
index 05fa285a9ce..764509f0d2b 100644
--- a/tine20/library/ExtJS/src/data/SortTypes.js
+++ b/tine20/library/ExtJS/src/data/SortTypes.js
@@ -1,16 +1,18 @@
-/*!
- * Ext JS Library 3.1.1
- * Copyright(c) 2006-2010 Ext JS, LLC
- * licensing@extjs.com
- * http://www.extjs.com/license
- */
+/*!
+ * Ext JS Library 3.1.1
+ * Copyright(c) 2006-2010 Ext JS, LLC
+ * licensing@extjs.com
+ * http://www.extjs.com/license
+ */
+
+const { isDate } = require("Ext/core/core/Ext");
/**
* @class Ext.data.SortTypes
* @singleton
* Defines the default sorting (casting?) comparison functions used when sorting data.
*/
-Ext.data.SortTypes = {
+module.exports = {
/**
* Default sort that does nothing
* @param {Mixed} s The value being converted
@@ -63,7 +65,7 @@ Ext.data.SortTypes = {
if(!s){
return 0;
}
- if(Ext.isDate(s)){
+ if(isDate(s)){
return s.getTime();
}
return Date.parse(String(s));
diff --git a/tine20/library/ExtJS/src/data/Store.js b/tine20/library/ExtJS/src/data/Store.js
index a1d98382216..913963aec8e 100644
--- a/tine20/library/ExtJS/src/data/Store.js
+++ b/tine20/library/ExtJS/src/data/Store.js
@@ -1238,8 +1238,7 @@ sortInfo: {
// protected handleException. Possibly temporary until Ext framework has an exception-handler.
handleException : function(e) {
- // @see core/Error.js
- Ext.handleError(e);
+ throw e;
},
/**
diff --git a/tine20/library/ExtJS/src/data/XmlReader.js b/tine20/library/ExtJS/src/data/XmlReader.js
index d75a37e1042..755647473aa 100644
--- a/tine20/library/ExtJS/src/data/XmlReader.js
+++ b/tine20/library/ExtJS/src/data/XmlReader.js
@@ -68,6 +68,8 @@ Ext.data.XmlReader = function(meta, recordType){
Ext.data.XmlReader.superclass.constructor.call(this, meta, recordType || meta.fields);
};
Ext.extend(Ext.data.XmlReader, Ext.data.DataReader, {
+ readerType: 'xml',
+
/**
* This method is only used by a DataProxy which has retrieved data from a remote server.
* @param {Object} response The XHR object which contains the parsed XML document. The response is expected
diff --git a/tine20/library/ExtJS/src/util/Format.js b/tine20/library/ExtJS/src/util/Format.js
index 938d14b7af4..ca7f4b31af7 100644
--- a/tine20/library/ExtJS/src/util/Format.js
+++ b/tine20/library/ExtJS/src/util/Format.js
@@ -32,7 +32,7 @@ var trimRe = /^\s+|\s+$/g,
*/
// import emojiRegex from 'emoji-regex';
-Ext.util.Format = function(){
+var Format = function(){
return {
/**
* Truncate a string and add an ellipsis ('...') to the end if it exceeds the specified length
@@ -401,3 +401,5 @@ Ext.util.Format = function(){
}
}
}();
+
+module.exports = Format
\ No newline at end of file
diff --git a/tine20/library/ExtJS/src/util/MixedCollection.js b/tine20/library/ExtJS/src/util/MixedCollection.js
index 6827facf841..20199218ba6 100644
--- a/tine20/library/ExtJS/src/util/MixedCollection.js
+++ b/tine20/library/ExtJS/src/util/MixedCollection.js
@@ -4,6 +4,14 @@
* licensing@extjs.com
* http://www.extjs.com/license
*/
+
+const { extend, isArray, isFunction, isEmpty } = require("Ext/core/core/Ext");
+const { Observable } = require("Ext/util/core/Observable");
+const { escapeRe } = require("Ext/core/Ext-more");
+const cloneDeep = require("lodash/cloneDeep");
+
+
+
/**
* @class Ext.util.MixedCollection
* @extends Ext.util.Observable
@@ -17,7 +25,7 @@
* were passed without an explicit key parameter to a MixedCollection method. Passing this parameter is
* equivalent to providing an implementation for the {@link #getKey} method.
*/
-Ext.util.MixedCollection = function(allowFunctions, keyFn, returnClones){
+const MixedCollection = function(allowFunctions, keyFn, returnClones){
this.items = [];
this.map = {};
this.keys = [];
@@ -58,10 +66,10 @@ Ext.util.MixedCollection = function(allowFunctions, keyFn, returnClones){
if(keyFn){
this.getKey = keyFn;
}
- Ext.util.MixedCollection.superclass.constructor.call(this);
+ MixedCollection.superclass.constructor.call(this);
};
-Ext.extend(Ext.util.MixedCollection, Ext.util.Observable, {
+extend(MixedCollection, Observable, {
/**
* @cfg {Boolean} allowFunctions Specify true if the {@link #addAll}
@@ -81,7 +89,7 @@ Ext.extend(Ext.util.MixedCollection, Ext.util.Observable, {
},
getAll: function() {
- return this.returnClones ? _.cloneDeep(this.map) : this.map;
+ return this.returnClones ? cloneDeep(this.map) : this.map;
},
/**
@@ -187,7 +195,7 @@ mc.add(otherEl);
* @param suppressEvent
*/
addAll : function(objs, suppressEvent){
- if(arguments.length > 2 || Ext.isArray(objs)){
+ if(arguments.length > 2 || isArray(objs)){
var args = arguments.length > 1 ? arguments : objs;
for(var i = 0, len = args.length; i < len; i++){
this.add(args[i]);
@@ -355,10 +363,10 @@ mc.add(otherEl);
item : function(key){
var mk = this.map[key],
item = mk !== undefined ? mk : (typeof key == 'number') ? this.items[key] : undefined;
- if (this.returnClones && !Ext.isFunction(item)) {
- item = _.cloneDeep(item);
+ if (this.returnClones && !isFunction(item)) {
+ item = cloneDeep(item);
}
- return !Ext.isFunction(item) || this.allowFunctions ? item : null; // for prototype!
+ return !isFunction(item) || this.allowFunctions ? item : null; // for prototype!
},
/**
@@ -368,8 +376,8 @@ mc.add(otherEl);
*/
itemAt : function(index){
let item = this.items[index];
- if (this.returnClones && !Ext.isFunction(item)) {
- item = _.cloneDeep(item);
+ if (this.returnClones && !isFunction(item)) {
+ item = cloneDeep(item);
}
return item;
},
@@ -418,8 +426,8 @@ mc.add(otherEl);
*/
first : function(){
let item = this.items[0];
- if (this.returnClones && !Ext.isFunction(item)) {
- item = _.cloneDeep(item);
+ if (this.returnClones && !isFunction(item)) {
+ item = cloneDeep(item);
}
return item;
@@ -431,8 +439,8 @@ mc.add(otherEl);
*/
last : function(){
let item = this.items[this.length-1];
- if (this.returnClones && !Ext.isFunction(item)) {
- item = _.cloneDeep(item);
+ if (this.returnClones && !isFunction(item)) {
+ item = cloneDeep(item);
}
return item;
},
@@ -517,7 +525,7 @@ mc.add(otherEl);
}
}
if (this.returnClones) {
- r = _.cloneDeep(r);
+ r = cloneDeep(r);
}
return r;
},
@@ -533,7 +541,7 @@ mc.add(otherEl);
* @return {MixedCollection} The new filtered collection
*/
filter : function(property, value, anyMatch, caseSensitive){
- if(Ext.isEmpty(value, false)){
+ if(isEmpty(value, false)){
return this.clone();
}
value = this.createValueMatcher(value, anyMatch, caseSensitive);
@@ -551,7 +559,7 @@ mc.add(otherEl);
* @return {MixedCollection} The new filtered collection
*/
filterBy : function(fn, scope){
- var r = new Ext.util.MixedCollection();
+ var r = new MixedCollection();
r.getKey = this.getKey;
var k = this.keys, it = this.items;
for(var i = 0, len = it.length; i < len; i++){
@@ -560,7 +568,7 @@ mc.add(otherEl);
}
}
if (this.returnClones) {
- r = _.cloneDeep(r);
+ r = cloneDeep(r);
}
return r;
},
@@ -576,7 +584,7 @@ mc.add(otherEl);
* @return {Number} The matched index or -1
*/
findIndex : function(property, value, start, anyMatch, caseSensitive){
- if(Ext.isEmpty(value, false)){
+ if(isEmpty(value, false)){
return -1;
}
value = this.createValueMatcher(value, anyMatch, caseSensitive);
@@ -606,7 +614,7 @@ mc.add(otherEl);
// private
createValueMatcher : function(value, anyMatch, caseSensitive, exactMatch) {
if (!value.exec) { // not a regex
- var er = Ext.escapeRe;
+ var er = escapeRe;
value = String(value);
if (anyMatch === true) {
value = er(value);
@@ -626,7 +634,7 @@ mc.add(otherEl);
* @return {MixedCollection}
*/
clone : function(){
- var r = new Ext.util.MixedCollection();
+ var r = new MixedCollection();
var k = this.keys, it = this.items;
for(var i = 0, len = it.length; i < len; i++){
r.add(k[i], it[i]);
@@ -645,4 +653,6 @@ mc.add(otherEl);
* not found, returns undefined. If an item was found, but is a Class,
* returns null.
*/
-Ext.util.MixedCollection.prototype.get = Ext.util.MixedCollection.prototype.item;
+MixedCollection.prototype.get = MixedCollection.prototype.item;
+
+module.exports = MixedCollection
\ No newline at end of file
diff --git a/tine20/library/ExtJS/src/util/core/DelayedTask.js b/tine20/library/ExtJS/src/util/core/DelayedTask.js
index 5a48a62a941..d222545cf08 100644
--- a/tine20/library/ExtJS/src/util/core/DelayedTask.js
+++ b/tine20/library/ExtJS/src/util/core/DelayedTask.js
@@ -33,7 +33,7 @@ Ext.get('myInputField').on('keypress', function(){
* function is called. If not specified, this
will refer to the browser window.
* @param {Array} args (optional) The default Array of arguments.
*/
-Ext.util.DelayedTask = function(fn, scope, args){
+const DelayedTask = function(fn, scope, args){
var me = this,
id,
call = function(){
@@ -67,4 +67,6 @@ Ext.util.DelayedTask = function(fn, scope, args){
id = null;
}
};
-};
\ No newline at end of file
+};
+
+module.exports = DelayedTask;
\ No newline at end of file
diff --git a/tine20/library/ExtJS/src/util/core/Observable.js b/tine20/library/ExtJS/src/util/core/Observable.js
index 5b7c89548fb..aa96f8b049a 100644
--- a/tine20/library/ExtJS/src/util/core/Observable.js
+++ b/tine20/library/ExtJS/src/util/core/Observable.js
@@ -4,14 +4,10 @@
* licensing@extjs.com
* http://www.extjs.com/license
*/
-(function(){
-
-var EXTUTIL = Ext.util,
- TOARRAY = Ext.toArray,
- EACH = Ext.each,
- ISOBJECT = Ext.isObject,
- TRUE = true,
- FALSE = false;
+
+const { toArray, each, isObject, isString, applyIf, isFunction, isBoolean } = require("Ext/core/core/Ext");
+const DelayedTask = require("Ext/util/core/DelayedTask");
+
/**
* @class Ext.util.Observable
* Base class that provides a common interface for publishing events. Subclasses are expected to
@@ -48,7 +44,7 @@ var newEmployee = new Employee({
});
*/
-EXTUTIL.Observable = function(){
+const Observable = function(){
/**
* @cfg {Object} listeners (optional) A config object containing one or more event handlers to be added to this
* object during initialization. This should be a valid listeners config object as specified in the
@@ -116,7 +112,7 @@ var combo = new Ext.form.ComboBox({
me.events = e || {};
};
-EXTUTIL.Observable.prototype = {
+Observable.prototype = {
// private
filterOptRe : /^(?:scope|delay|buffer|single)$/,
@@ -129,32 +125,32 @@ EXTUTIL.Observable.prototype = {
* @return {Boolean} returns false if any of the handlers return false otherwise it returns true.
*/
fireEvent : function(){
- var a = TOARRAY(arguments),
+ var a = toArray(arguments),
ename = a[0].toLowerCase(),
me = this,
- ret = TRUE,
+ ret = true,
ce = me.events[ename],
q,
c;
- if (me.eventsSuspended === TRUE) {
+ if (me.eventsSuspended === true) {
if (q = me.eventQueue) {
q.push(a);
}
}
- else if(ISOBJECT(ce) && ce.bubble){
- if(ce.fire.apply(ce, a.slice(1)) === FALSE) {
- return FALSE;
+ else if(isObject(ce) && ce.bubble){
+ if(ce.fire.apply(ce, a.slice(1)) === false) {
+ return false;
}
c = me.getBubbleTarget && me.getBubbleTarget();
if(c && c.enableBubble) {
- if(!c.events[ename] || !Ext.isObject(c.events[ename]) || !c.events[ename].bubble) {
+ if(!c.events[ename] || !isObject(c.events[ename]) || !c.events[ename].bubble) {
c.enableBubble(ename);
}
return c.fireEvent.apply(c, a);
}
}
else {
- if (ISOBJECT(ce)) {
+ if (isObject(ce)) {
a.shift();
ret = ce.fire.apply(ce, a);
}
@@ -167,7 +163,7 @@ EXTUTIL.Observable.prototype = {
ce.isAsync = true;
const r = this.fireEvent.apply(this, arguments);
ce.isAsync = false;
- return !r || r === true ? Promise.resolve() : (Ext.isFunction(r.then) ? r : Promise.reject());
+ return !r || r === true ? Promise.resolve() : (isFunction(r.then) ? r : Promise.reject());
},
/**
@@ -235,7 +231,7 @@ myGridPanel.on({
oe,
isF,
ce;
- if (ISOBJECT(eventName)) {
+ if (isObject(eventName)) {
o = eventName;
for (e in o){
oe = o[e];
@@ -245,11 +241,11 @@ myGridPanel.on({
}
} else {
eventName = eventName.toLowerCase();
- ce = me.events[eventName] || TRUE;
- if (Ext.isBoolean(ce)) {
- me.events[eventName] = ce = new EXTUTIL.Event(me, eventName);
+ ce = me.events[eventName] || true;
+ if (isBoolean(ce)) {
+ me.events[eventName] = ce = new Event(me, eventName);
}
- ce.addListener(fn, scope, ISOBJECT(o) ? o : {});
+ ce.addListener(fn, scope, isObject(o) ? o : {});
}
},
@@ -261,7 +257,7 @@ myGridPanel.on({
*/
removeListener : function(eventName, fn, scope){
var ce = this.events[eventName.toLowerCase()];
- if (ISOBJECT(ce)) {
+ if (isObject(ce)) {
ce.removeListener(fn, scope);
}
},
@@ -275,7 +271,7 @@ myGridPanel.on({
key;
for(key in events){
evt = events[key];
- if(ISOBJECT(evt)){
+ if(isObject(evt)){
evt.clearListeners();
}
}
@@ -293,14 +289,14 @@ this.addEvents('storeloaded', 'storecleared');
addEvents : function(o){
var me = this;
me.events = me.events || {};
- if (Ext.isString(o)) {
+ if (isString(o)) {
var a = arguments,
i = a.length;
while(i--) {
- me.events[a[i]] = me.events[a[i]] || TRUE;
+ me.events[a[i]] = me.events[a[i]] || true;
}
} else {
- Ext.applyIf(me.events, o);
+ applyIf(me.events, o);
}
},
@@ -311,7 +307,7 @@ this.addEvents('storeloaded', 'storecleared');
*/
hasListener : function(eventName){
var e = this.events[eventName];
- return ISOBJECT(e) && e.listeners.length > 0;
+ return isObject(e) && e.listeners.length > 0;
},
/**
@@ -320,7 +316,7 @@ this.addEvents('storeloaded', 'storecleared');
* after the {@link #resumeEvents} call instead of discarding all suspended events;
*/
suspendEvents : function(queueSuspended){
- this.eventsSuspended = TRUE;
+ this.eventsSuspended = true;
if(queueSuspended && !this.eventQueue){
this.eventQueue = [];
}
@@ -334,15 +330,14 @@ this.addEvents('storeloaded', 'storecleared');
resumeEvents : function(){
var me = this,
queued = me.eventQueue || [];
- me.eventsSuspended = FALSE;
+ me.eventsSuspended = false;
delete me.eventQueue;
- EACH(queued, function(e) {
+ each(queued, function(e) {
me.fireEvent.apply(me, e);
});
}
};
-var OBSERVABLE = EXTUTIL.Observable.prototype;
/**
* Appends an event handler to this object (shorthand for {@link #addListener}.)
* @param {String} eventName The type of event to listen for
@@ -352,7 +347,7 @@ var OBSERVABLE = EXTUTIL.Observable.prototype;
* @param {Object} options (optional) An object containing handler configuration.
* @method
*/
-OBSERVABLE.on = OBSERVABLE.addListener;
+Observable.prototype.on = Observable.prototype.addListener;
/**
* Removes an event handler (shorthand for {@link #removeListener}.)
* @param {String} eventName The type of event the handler was associated with.
@@ -360,29 +355,29 @@ OBSERVABLE.on = OBSERVABLE.addListener;
* @param {Object} scope (optional) The scope originally specified for the handler.
* @method
*/
-OBSERVABLE.un = OBSERVABLE.removeListener;
+Observable.prototype.un = Observable.prototype.removeListener;
/**
* Removes all added captures from the Observable.
* @param {Observable} o The Observable to release
* @static
*/
-EXTUTIL.Observable.releaseCapture = function(o){
- o.fireEvent = OBSERVABLE.fireEvent;
+Observable.releaseCapture = function(o){
+ o.fireEvent = Observable.prototype.fireEvent;
};
function createTargeted(h, o, scope){
return function(){
if(o.target == arguments[0]){
- h.apply(scope, TOARRAY(arguments));
+ h.apply(scope, toArray(arguments));
}
};
};
function createBuffered(h, o, l, scope){
- l.task = new EXTUTIL.DelayedTask();
+ l.task = new DelayedTask();
return function(){
- l.task.delay(o.buffer, h, scope, TOARRAY(arguments));
+ l.task.delay(o.buffer, h, scope, toArray(arguments));
};
};
@@ -395,23 +390,23 @@ function createSingle(h, e, fn, scope){
function createDelayed(h, o, l, scope){
return function(){
- var task = new EXTUTIL.DelayedTask();
+ var task = new DelayedTask();
if(!l.tasks) {
l.tasks = [];
}
l.tasks.push(task);
- task.delay(o.delay || 10, h, scope, TOARRAY(arguments));
+ task.delay(o.delay || 10, h, scope, toArray(arguments));
};
};
-EXTUTIL.Event = function(obj, name){
+const Event = function(obj, name){
this.name = name;
this.obj = obj;
this.listeners = [];
this.isAsync = false;
};
-EXTUTIL.Event.prototype = {
+Event.prototype = {
addListener : function(fn, scope, options){
var me = this,
l;
@@ -474,7 +469,7 @@ EXTUTIL.Event.prototype = {
l,
k,
me = this,
- ret = FALSE;
+ ret = false;
if((index = me.findListener(fn, scope)) != -1){
if (me.firing) {
me.listeners = me.listeners.slice(0);
@@ -492,7 +487,7 @@ EXTUTIL.Event.prototype = {
delete l.tasks;
}
me.listeners.splice(index, 1);
- ret = TRUE;
+ ret = true;
}
return ret;
},
@@ -511,31 +506,31 @@ EXTUTIL.Event.prototype = {
if (this.isAsync) return this.fireAsync.apply(this, arguments);
var me = this,
- args = TOARRAY(arguments),
+ args = toArray(arguments),
listeners = me.listeners,
len = listeners.length,
i = 0,
l;
if(len > 0){
- me.firing = TRUE;
+ me.firing = true;
for (; i < len; i++) {
l = listeners[i];
- if(l && l.fireFn.apply(l.scope || me.obj || window, args) === FALSE) {
- return (me.firing = FALSE);
+ if(l && l.fireFn.apply(l.scope || me.obj || window, args) === false) {
+ return (me.firing = false);
}
}
}
- me.firing = FALSE;
- return TRUE;
+ me.firing = false;
+ return true;
},
fireAsync : async function() {
- const args = TOARRAY(arguments);
+ const args = toArray(arguments);
let result = Promise.resolve();
if (this.listeners.length) {
- this.firing = TRUE;
+ this.firing = true;
for (let listener of this.listeners) {
try {
@@ -548,9 +543,10 @@ EXTUTIL.Event.prototype = {
}
}
- this.firing = FALSE;
+ this.firing = false;
}
return result;
}
};
-})();
+
+module.exports = { Observable, Event }
\ No newline at end of file