/*
This file is part of Ext JS 4
Copyright (c) 2011 Sencha Inc
Contact: http://www.sencha.com/contact
Commercial Usage
Licensees holding valid commercial licenses may use this file in accordance with the Commercial Software License Agreement provided with the Software or, alternatively, in accordance with the terms contained in a written agreement between you and Sencha.
If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
*/
/**
* @class Ext
* @singleton
*/
(function() {
var global = this,
objectPrototype = Object.prototype,
toString = objectPrototype.toString,
enumerables = true,
enumerablesTest = { toString: 1 },
i;
if (typeof Ext === 'undefined') {
global.Ext = {};
}
Ext.global = global;
for (i in enumerablesTest) {
enumerables = null;
}
if (enumerables) {
enumerables = ['hasOwnProperty', 'valueOf', 'isPrototypeOf', 'propertyIsEnumerable',
'toLocaleString', 'toString', 'constructor'];
}
/**
* An array containing extra enumerables for old browsers
* @property {String[]}
*/
Ext.enumerables = enumerables;
/**
* Copies all the properties of config to the specified object.
* Note that if recursive merging and cloning without referencing the original objects / arrays is needed, use
* {@link Ext.Object#merge} instead.
* @param {Object} object The receiver of the properties
* @param {Object} config The source of the properties
* @param {Object} defaults A different object that will also be applied for default values
* @return {Object} returns obj
*/
Ext.apply = function(object, config, defaults) {
if (defaults) {
Ext.apply(object, defaults);
}
if (object && config && typeof config === 'object') {
var i, j, k;
for (i in config) {
object[i] = config[i];
}
if (enumerables) {
for (j = enumerables.length; j--;) {
k = enumerables[j];
if (config.hasOwnProperty(k)) {
object[k] = config[k];
}
}
}
}
return object;
};
Ext.buildSettings = Ext.apply({
baseCSSPrefix: 'x-',
scopeResetCSS: false
}, Ext.buildSettings || {});
Ext.apply(Ext, {
/**
* A reusable empty function
*/
emptyFn: function() {},
baseCSSPrefix: Ext.buildSettings.baseCSSPrefix,
/**
* Copies all the properties of config to object if they don't already exist.
* @param {Object} object The receiver of the properties
* @param {Object} config The source of the properties
* @return {Object} returns obj
*/
applyIf: function(object, config) {
var property;
if (object) {
for (property in config) {
if (object[property] === undefined) {
object[property] = config[property];
}
}
}
return object;
},
/**
* Iterates either an array or an object. This method delegates to
* {@link Ext.Array#each Ext.Array.each} if the given value is iterable, and {@link Ext.Object#each Ext.Object.each} otherwise.
*
* @param {Object/Array} object The object or array to be iterated.
* @param {Function} fn The function to be called for each iteration. See and {@link Ext.Array#each Ext.Array.each} and
* {@link Ext.Object#each Ext.Object.each} for detailed lists of arguments passed to this function depending on the given object
* type that is being iterated.
* @param {Object} scope (Optional) The scope (`this` reference) in which the specified function is executed.
* Defaults to the object being iterated itself.
* @markdown
*/
iterate: function(object, fn, scope) {
if (Ext.isEmpty(object)) {
return;
}
if (scope === undefined) {
scope = object;
}
if (Ext.isIterable(object)) {
Ext.Array.each.call(Ext.Array, object, fn, scope);
}
else {
Ext.Object.each.call(Ext.Object, object, fn, scope);
}
}
});
Ext.apply(Ext, {
/**
* This method deprecated. Use {@link Ext#define Ext.define} instead.
* @method
* @param {Function} superclass
* @param {Object} overrides
* @return {Function} The subclass constructor from the overrides parameter, or a generated one if not provided.
* @deprecated 4.0.0 Use {@link Ext#define Ext.define} instead
*/
extend: function() {
// inline overrides
var objectConstructor = objectPrototype.constructor,
inlineOverrides = function(o) {
for (var m in o) {
if (!o.hasOwnProperty(m)) {
continue;
}
this[m] = o[m];
}
};
return function(subclass, superclass, overrides) {
// First we check if the user passed in just the superClass with overrides
if (Ext.isObject(superclass)) {
overrides = superclass;
superclass = subclass;
subclass = overrides.constructor !== objectConstructor ? overrides.constructor : function() {
superclass.apply(this, arguments);
};
}
// We create a new temporary class
var F = function() {},
subclassProto, superclassProto = superclass.prototype;
F.prototype = superclassProto;
subclassProto = subclass.prototype = new F();
subclassProto.constructor = subclass;
subclass.superclass = superclassProto;
if (superclassProto.constructor === objectConstructor) {
superclassProto.constructor = superclass;
}
subclass.override = function(overrides) {
Ext.override(subclass, overrides);
};
subclassProto.override = inlineOverrides;
subclassProto.proto = subclassProto;
subclass.override(overrides);
subclass.extend = function(o) {
return Ext.extend(subclass, o);
};
return subclass;
};
}(),
/**
* Proxy to {@link Ext.Base#override}. Please refer {@link Ext.Base#override} for further details.
Ext.define('My.cool.Class', {
sayHi: function() {
alert('Hi!');
}
}
Ext.override(My.cool.Class, {
sayHi: function() {
alert('About to say...');
this.callOverridden();
}
});
var cool = new My.cool.Class();
cool.sayHi(); // alerts 'About to say...'
// alerts 'Hi!'
* Please note that `this.callOverridden()` only works if the class was previously
* created with {@link Ext#define)
*
* @param {Object} cls The class to override
* @param {Object} overrides The list of functions to add to origClass. This should be specified as an object literal
* containing one or more methods.
* @method override
* @markdown
*/
override: function(cls, overrides) {
if (cls.prototype.$className) {
return cls.override(overrides);
}
else {
Ext.apply(cls.prototype, overrides);
}
}
});
// A full set of static methods to do type checking
Ext.apply(Ext, {
/**
* Returns the given value itself if it's not empty, as described in {@link Ext#isEmpty}; returns the default
* value (second argument) otherwise.
*
* @param {Object} value The value to test
* @param {Object} defaultValue The value to return if the original value is empty
* @param {Boolean} allowBlank (optional) true to allow zero length strings to qualify as non-empty (defaults to false)
* @return {Object} value, if non-empty, else defaultValue
*/
valueFrom: function(value, defaultValue, allowBlank){
return Ext.isEmpty(value, allowBlank) ? defaultValue : value;
},
/**
* Returns the type of the given variable in string format. List of possible values are:
*
* - `undefined`: If the given value is `undefined`
* - `null`: If the given value is `null`
* - `string`: If the given value is a string
* - `number`: If the given value is a number
* - `boolean`: If the given value is a boolean value
* - `date`: If the given value is a `Date` object
* - `function`: If the given value is a function reference
* - `object`: If the given value is an object
* - `array`: If the given value is an array
* - `regexp`: If the given value is a regular expression
* - `element`: If the given value is a DOM Element
* - `textnode`: If the given value is a DOM text node and contains something other than whitespace
* - `whitespace`: If the given value is a DOM text node and contains only whitespace
*
* @param {Object} value
* @return {String}
* @markdown
*/
typeOf: function(value) {
if (value === null) {
return 'null';
}
var type = typeof value;
if (type === 'undefined' || type === 'string' || type === 'number' || type === 'boolean') {
return type;
}
var typeToString = toString.call(value);
switch(typeToString) {
case '[object Array]':
return 'array';
case '[object Date]':
return 'date';
case '[object Boolean]':
return 'boolean';
case '[object Number]':
return 'number';
case '[object RegExp]':
return 'regexp';
}
if (type === 'function') {
return 'function';
}
if (type === 'object') {
if (value.nodeType !== undefined) {
if (value.nodeType === 3) {
return (/\S/).test(value.nodeValue) ? 'textnode' : 'whitespace';
}
else {
return 'element';
}
}
return 'object';
}
},
/**
* Returns true if the passed value is empty, false otherwise. The value is deemed to be empty if it is either:
*
* - `null`
* - `undefined`
* - a zero-length array
* - a zero-length string (Unless the `allowEmptyString` parameter is set to `true`)
*
* @param {Object} value The value to test
* @param {Boolean} allowEmptyString (optional) true to allow empty strings (defaults to false)
* @return {Boolean}
* @markdown
*/
isEmpty: function(value, allowEmptyString) {
return (value === null) || (value === undefined) || (!allowEmptyString ? value === '' : false) || (Ext.isArray(value) && value.length === 0);
},
/**
* Returns true if the passed value is a JavaScript Array, false otherwise.
*
* @param {Object} target The target to test
* @return {Boolean}
* @method
*/
isArray: ('isArray' in Array) ? Array.isArray : function(value) {
return toString.call(value) === '[object Array]';
},
/**
* Returns true if the passed value is a JavaScript Date object, false otherwise.
* @param {Object} object The object to test
* @return {Boolean}
*/
isDate: function(value) {
return toString.call(value) === '[object Date]';
},
/**
* Returns true if the passed value is a JavaScript Object, false otherwise.
* @param {Object} value The value to test
* @return {Boolean}
* @method
*/
isObject: (toString.call(null) === '[object Object]') ?
function(value) {
// check ownerDocument here as well to exclude DOM nodes
return value !== null && value !== undefined && toString.call(value) === '[object Object]' && value.ownerDocument === undefined;
} :
function(value) {
return toString.call(value) === '[object Object]';
},
/**
* Returns true if the passed value is a JavaScript 'primitive', a string, number or boolean.
* @param {Object} value The value to test
* @return {Boolean}
*/
isPrimitive: function(value) {
var type = typeof value;
return type === 'string' || type === 'number' || type === 'boolean';
},
/**
* Returns true if the passed value is a JavaScript Function, false otherwise.
* @param {Object} value The value to test
* @return {Boolean}
* @method
*/
isFunction:
// Safari 3.x and 4.x returns 'function' for typeof Developer-written, custom formats may be used by supplying both a formatting and a parsing function
* which perform to specialized requirements. The functions are stored in {@link #parseFunctions} and {@link #formatFunctions}. An object hash in which each property is a date parsing function. The property name is the
* format string which that function parses. This object is automatically populated with date parsing functions as
* date formats are requested for Ext standard formatting strings. Custom parsing functions may be inserted into this object, keyed by a name which from then on
* may be used as a format string to {@link #parse}.
* Example: A parsing function should return a Date object, and is passed the following parameters:
* @param {String/Number} target The version to compare with
* @return {Boolean} True if this version matches the target, false otherwise
*/
match: function(target) {
target = String(target);
return this.version.substr(0, target.length) === target;
},
/**
* Returns this format: [major, minor, patch, build, release]. Useful for comparison
* @return {Number[]}
*/
toArray: function() {
return [this.getMajor(), this.getMinor(), this.getPatch(), this.getBuild(), this.getRelease()];
},
/**
* Returns shortVersion version without dots and release
* @return {String}
*/
getShortVersion: function() {
return this.shortVersion;
}
});
Ext.apply(Version, {
// @private
releaseValueMap: {
'dev': -6,
'alpha': -5,
'a': -5,
'beta': -4,
'b': -4,
'rc': -3,
'#': -2,
'p': -1,
'pl': -1
},
/**
* Converts a version component to a comparable value
*
* @static
* @param {Object} value The value to convert
* @return {Object}
*/
getComponentValue: function(value) {
return !value ? 0 : (isNaN(value) ? this.releaseValueMap[value] || value : parseInt(value, 10));
},
/**
* Compare 2 specified versions, starting from left to right. If a part contains special version strings,
* they are handled in the following order:
* 'dev' < 'alpha' = 'a' < 'beta' = 'b' < 'RC' = 'rc' < '#' < 'pl' = 'p' < 'anything else'
*
* @static
* @param {String} current The current version to compare to
* @param {String} target The target version to compare to
* @return {Number} Returns -1 if the current version is smaller than the target version, 1 if greater, and 0 if they're equivalent
*/
compare: function(current, target) {
var currentValue, targetValue, i;
current = new Version(current).toArray();
target = new Version(target).toArray();
for (i = 0; i < Math.max(current.length, target.length); i++) {
currentValue = this.getComponentValue(current[i]);
targetValue = this.getComponentValue(target[i]);
if (currentValue < targetValue) {
return -1;
} else if (currentValue > targetValue) {
return 1;
}
}
return 0;
}
});
Ext.apply(Ext, {
/**
* @private
*/
versions: {},
/**
* @private
*/
lastRegisteredVersion: null,
/**
* Set version number for the given package name.
*
* @param {String} packageName The package name, for example: 'core', 'touch', 'extjs'
* @param {String/Ext.Version} version The version, for example: '1.2.3alpha', '2.4.0-dev'
* @return {Ext}
*/
setVersion: function(packageName, version) {
Ext.versions[packageName] = new Version(version);
Ext.lastRegisteredVersion = Ext.versions[packageName];
return this;
},
/**
* Get the version number of the supplied package name; will return the last registered version
* (last Ext.setVersion call) if there's no package name given.
*
* @param {String} packageName (Optional) The package name, for example: 'core', 'touch', 'extjs'
* @return {Ext.Version} The version
*/
getVersion: function(packageName) {
if (packageName === undefined) {
return Ext.lastRegisteredVersion;
}
return Ext.versions[packageName];
},
/**
* Create a closure for deprecated code.
*
// This means Ext.oldMethod is only supported in 4.0.0beta and older.
// If Ext.getVersion('extjs') returns a version that is later than '4.0.0beta', for example '4.0.0RC',
// the closure will not be invoked
Ext.deprecate('extjs', '4.0.0beta', function() {
Ext.oldMethod = Ext.newMethod;
...
});
* @param {String} packageName The package name
* @param {String} since The last version before it's deprecated
* @param {Function} closure The callback function to be executed with the specified version is less than the current version
* @param {Object} scope The execution scope (this) if the closure
* @markdown
*/
deprecate: function(packageName, since, closure, scope) {
if (Version.compare(Ext.getVersion(packageName), since) < 1) {
closure.call(scope);
}
}
}); // End Versioning
Ext.setVersion('core', version);
})();
/**
* @class Ext.String
*
* A collection of useful static methods to deal with strings
* @singleton
*/
Ext.String = {
trimRegex: /^[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000]+|[\x09\x0a\x0b\x0c\x0d\x20\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000]+$/g,
escapeRe: /('|\\)/g,
formatRe: /\{(\d+)\}/g,
escapeRegexRe: /([-.*+?^${}()|[\]\/\\])/g,
/**
* Convert certain characters (&, <, >, and ") to their HTML character equivalents for literal display in web pages.
* @param {String} value The string to encode
* @return {String} The encoded text
* @method
*/
htmlEncode: (function() {
var entities = {
'&': '&',
'>': '>',
'<': '<',
'"': '"'
}, keys = [], p, regex;
for (p in entities) {
keys.push(p);
}
regex = new RegExp('(' + keys.join('|') + ')', 'g');
return function(value) {
return (!value) ? value : String(value).replace(regex, function(match, capture) {
return entities[capture];
});
};
})(),
/**
* Convert certain characters (&, <, >, and ") from their HTML character equivalents.
* @param {String} value The string to decode
* @return {String} The decoded text
* @method
*/
htmlDecode: (function() {
var entities = {
'&': '&',
'>': '>',
'<': '<',
'"': '"'
}, keys = [], p, regex;
for (p in entities) {
keys.push(p);
}
regex = new RegExp('(' + keys.join('|') + '|[0-9]{1,5};' + ')', 'g');
return function(value) {
return (!value) ? value : String(value).replace(regex, function(match, capture) {
if (capture in entities) {
return entities[capture];
} else {
return String.fromCharCode(parseInt(capture.substr(2), 10));
}
});
};
})(),
/**
* Appends content to the query string of a URL, handling logic for whether to place
* a question mark or ampersand.
* @param {String} url The URL to append to.
* @param {String} string The content to append to the URL.
* @return (String) The resulting URL
*/
urlAppend : function(url, string) {
if (!Ext.isEmpty(string)) {
return url + (url.indexOf('?') === -1 ? '?' : '&') + string;
}
return url;
},
/**
* Trims whitespace from either end of a string, leaving spaces within the string intact. Example:
* @example
var s = ' foo bar ';
alert('-' + s + '-'); //alerts "- foo bar -"
alert('-' + Ext.String.trim(s) + '-'); //alerts "-foo bar-"
* @param {String} string The string to escape
* @return {String} The trimmed string
*/
trim: function(string) {
return string.replace(Ext.String.trimRegex, "");
},
/**
* Capitalize the given string
* @param {String} string
* @return {String}
*/
capitalize: function(string) {
return string.charAt(0).toUpperCase() + string.substr(1);
},
/**
* Truncate a string and add an ellipsis ('...') to the end if it exceeds the specified length
* @param {String} value The string to truncate
* @param {Number} length The maximum length to allow before truncating
* @param {Boolean} word True to try to find a common word break
* @return {String} The converted text
*/
ellipsis: function(value, len, word) {
if (value && value.length > len) {
if (word) {
var vs = value.substr(0, len - 2),
index = Math.max(vs.lastIndexOf(' '), vs.lastIndexOf('.'), vs.lastIndexOf('!'), vs.lastIndexOf('?'));
if (index !== -1 && index >= (len - 15)) {
return vs.substr(0, index) + "...";
}
}
return value.substr(0, len - 3) + "...";
}
return value;
},
/**
* Escapes the passed string for use in a regular expression
* @param {String} string
* @return {String}
*/
escapeRegex: function(string) {
return string.replace(Ext.String.escapeRegexRe, "\\$1");
},
/**
* Escapes the passed string for ' and \
* @param {String} string The string to escape
* @return {String} The escaped string
*/
escape: function(string) {
return string.replace(Ext.String.escapeRe, "\\$1");
},
/**
* Utility function that allows you to easily switch a string between two alternating values. The passed value
* is compared to the current string, and if they are equal, the other value that was passed in is returned. If
* they are already different, the first value passed in is returned. Note that this method returns the new value
* but does not change the current string.
*
* var version = new Ext.Version('1.0.2beta');
* console.log(version.match(1)); // True
* console.log(version.match(1.0)); // True
* console.log(version.match('1.0.2')); // True
* console.log(version.match('1.0.2RC')); // False
*
* @param {String} string The current string
* @param {String} value The value to compare to the current string
* @param {String} other The new value to use if the string already equals the first value passed in
* @return {String} The new value
*/
toggle: function(string, value, other) {
return string === value ? other : value;
},
/**
* Pads the left side of a string with a specified character. This is especially useful
* for normalizing number and date strings. Example usage:
*
*
// alternate sort directions
sort = Ext.String.toggle(sort, 'ASC', 'DESC');
// instead of conditional logic:
sort = (sort == 'ASC' ? 'DESC' : 'ASC');
* @param {String} string The original string
* @param {Number} size The total length of the output string
* @param {String} character (optional) The character with which to pad the original string (defaults to empty string " ")
* @return {String} The padded string
*/
leftPad: function(string, size, character) {
var result = String(string);
character = character || " ";
while (result.length < size) {
result = character + result;
}
return result;
},
/**
* Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each
* token must be unique, and must increment in the format {0}, {1}, etc. Example usage:
*
var s = Ext.String.leftPad('123', 5, '0');
// s now contains the string: '00123'
* @param {String} string The tokenized string to be formatted
* @param {String} value1 The value to replace token {0}
* @param {String} value2 Etc...
* @return {String} The formatted string
*/
format: function(format) {
var args = Ext.Array.toArray(arguments, 1);
return format.replace(Ext.String.formatRe, function(m, i) {
return args[i];
});
},
/**
* Returns a string with a specified number of repititions a given string pattern.
* The pattern be separated by a different string.
*
* var s = Ext.String.repeat('---', 4); // = '------------'
* var t = Ext.String.repeat('--', 3, '/'); // = '--/--/--'
*
* @param {String} pattern The pattern to repeat.
* @param {Number} count The number of times to repeat the pattern (may be 0).
* @param {String} sep An option string to separate each pattern.
*/
repeat: function(pattern, count, sep) {
for (var buf = [], i = count; i--; ) {
buf.push(pattern);
}
return buf.join(sep || '');
}
};
/**
* @class Ext.Number
*
* A collection of useful static methods to deal with numbers
* @singleton
*/
(function() {
var isToFixedBroken = (0.9).toFixed() !== '1';
Ext.Number = {
/**
* Checks whether or not the passed number is within a desired range. If the number is already within the
* range it is returned, otherwise the min or max value is returned depending on which side of the range is
* exceeded. Note that this method returns the constrained value but does not change the current number.
* @param {Number} number The number to check
* @param {Number} min The minimum number in the range
* @param {Number} max The maximum number in the range
* @return {Number} The constrained value if outside the range, otherwise the current value
*/
constrain: function(number, min, max) {
number = parseFloat(number);
if (!isNaN(min)) {
number = Math.max(number, min);
}
if (!isNaN(max)) {
number = Math.min(number, max);
}
return number;
},
/**
* Snaps the passed number between stopping points based upon a passed increment value.
* @param {Number} value The unsnapped value.
* @param {Number} increment The increment by which the value must move.
* @param {Number} minValue The minimum value to which the returned value must be constrained. Overrides the increment..
* @param {Number} maxValue The maximum value to which the returned value must be constrained. Overrides the increment..
* @return {Number} The value of the nearest snap target.
*/
snap : function(value, increment, minValue, maxValue) {
var newValue = value,
m;
if (!(increment && value)) {
return value;
}
m = value % increment;
if (m !== 0) {
newValue -= m;
if (m * 2 >= increment) {
newValue += increment;
} else if (m * 2 < -increment) {
newValue -= increment;
}
}
return Ext.Number.constrain(newValue, minValue, maxValue);
},
/**
* Formats a number using fixed-point notation
* @param {Number} value The number to format
* @param {Number} precision The number of digits to show after the decimal point
*/
toFixed: function(value, precision) {
if (isToFixedBroken) {
precision = precision || 0;
var pow = Math.pow(10, precision);
return (Math.round(value * pow) / pow).toFixed(precision);
}
return value.toFixed(precision);
},
/**
* Validate that a value is numeric and convert it to a number if necessary. Returns the specified default value if
* it is not.
Ext.Number.from('1.23', 1); // returns 1.23
Ext.Number.from('abc', 1); // returns 1
* @param {Object} value
* @param {Number} defaultValue The value to return if the original value is non-numeric
* @return {Number} value, if numeric, defaultValue otherwise
*/
from: function(value, defaultValue) {
if (isFinite(value)) {
value = parseFloat(value);
}
return !isNaN(value) ? value : defaultValue;
}
};
})();
/**
* @deprecated 4.0.0 Please use {@link Ext.Number#from} instead.
* @member Ext
* @method num
* @alias Ext.Number#from
*/
Ext.num = function() {
return Ext.Number.from.apply(this, arguments);
};
/**
* @class Ext.Array
* @singleton
* @author Jacky Nguyen
var cls = 'my-class', text = 'Some text';
var s = Ext.String.format('<div class="{0}">{1}</div>', cls, text);
// s now contains the string: '<div class="my-class">Some text</div>'
Format Description Example returned values
------ ----------------------------------------------------------------------- -----------------------
d Day of the month, 2 digits with leading zeros 01 to 31
D A short textual representation of the day of the week Mon to Sun
j Day of the month without leading zeros 1 to 31
l A full textual representation of the day of the week Sunday to Saturday
N ISO-8601 numeric representation of the day of the week 1 (for Monday) through 7 (for Sunday)
S English ordinal suffix for the day of the month, 2 characters st, nd, rd or th. Works well with j
w Numeric representation of the day of the week 0 (for Sunday) to 6 (for Saturday)
z The day of the year (starting from 0) 0 to 364 (365 in leap years)
W ISO-8601 week number of year, weeks starting on Monday 01 to 53
F A full textual representation of a month, such as January or March January to December
m Numeric representation of a month, with leading zeros 01 to 12
M A short textual representation of a month Jan to Dec
n Numeric representation of a month, without leading zeros 1 to 12
t Number of days in the given month 28 to 31
L Whether it's a leap year 1 if it is a leap year, 0 otherwise.
o ISO-8601 year number (identical to (Y), but if the ISO week number (W) Examples: 1998 or 2004
belongs to the previous or next year, that year is used instead)
Y A full numeric representation of a year, 4 digits Examples: 1999 or 2003
y A two digit representation of a year Examples: 99 or 03
a Lowercase Ante meridiem and Post meridiem am or pm
A Uppercase Ante meridiem and Post meridiem AM or PM
g 12-hour format of an hour without leading zeros 1 to 12
G 24-hour format of an hour without leading zeros 0 to 23
h 12-hour format of an hour with leading zeros 01 to 12
H 24-hour format of an hour with leading zeros 00 to 23
i Minutes, with leading zeros 00 to 59
s Seconds, with leading zeros 00 to 59
u Decimal fraction of a second Examples:
(minimum 1 digit, arbitrary number of digits allowed) 001 (i.e. 0.001s) or
100 (i.e. 0.100s) or
999 (i.e. 0.999s) or
999876543210 (i.e. 0.999876543210s)
O Difference to Greenwich time (GMT) in hours and minutes Example: +1030
P Difference to Greenwich time (GMT) with colon between hours and minutes Example: -08:00
T Timezone abbreviation of the machine running the code Examples: EST, MDT, PDT ...
Z Timezone offset in seconds (negative if west of UTC, positive if east) -43200 to 50400
c ISO 8601 date
Notes: Examples:
1) If unspecified, the month / day defaults to the current month / day, 1991 or
the time defaults to midnight, while the timezone defaults to the 1992-10 or
browser's timezone. If a time is specified, it must include both hours 1993-09-20 or
and minutes. The "T" delimiter, seconds, milliseconds and timezone 1994-08-19T16:20+01:00 or
are optional. 1995-07-18T17:21:28-02:00 or
2) The decimal fraction of a second, if specified, must contain at 1996-06-17T18:22:29.98765+03:00 or
least 1 digit (there is no limit to the maximum number 1997-05-16T19:23:30,12345-0400 or
of digits allowed), and may be delimited by either a '.' or a ',' 1998-04-15T20:24:31.2468Z or
Refer to the examples on the right for the various levels of 1999-03-14T20:24:32Z or
date-time granularity which are supported, or see 2000-02-13T21:25:33
http://www.w3.org/TR/NOTE-datetime for more info. 2001-01-12 22:26:34
U Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) 1193432466 or -2138434463
MS Microsoft AJAX serialized dates \/Date(1238606590509)\/ (i.e. UTC milliseconds since epoch) or
\/Date(1238606590509+0800)\/
*
* Example usage (note that you must escape format specifiers with '\\' to render them as character literals):
*
*
* Here are some standard date/time patterns that you might find helpful. They
* are not part of the source of Ext.Date, but to use them you can simply copy this
* block of code into any script that is included after Ext.Date and they will also become
* globally available on the Date object. Feel free to add or remove patterns as needed in your code.
*
// Sample date:
// 'Wed Jan 10 2007 15:05:01 GMT-0600 (Central Standard Time)'
var dt = new Date('1/10/2007 03:05:01 PM GMT-0600');
console.log(Ext.Date.format(dt, 'Y-m-d')); // 2007-01-10
console.log(Ext.Date.format(dt, 'F j, Y, g:i a')); // January 10, 2007, 3:05 pm
console.log(Ext.Date.format(dt, 'l, \\t\\he jS \\of F Y h:i:s A')); // Wednesday, the 10th of January 2007 03:05:01 PM
*
* Example usage:
*
Ext.Date.patterns = {
ISO8601Long:"Y-m-d H:i:s",
ISO8601Short:"Y-m-d",
ShortDate: "n/j/Y",
LongDate: "l, F d, Y",
FullDateTime: "l, F d, Y g:i:s A",
MonthDay: "F d",
ShortTime: "g:i A",
LongTime: "g:i:s A",
SortableDateTime: "Y-m-d\\TH:i:s",
UniversalSortableDateTime: "Y-m-d H:i:sO",
YearMonth: "F, Y"
};
*
var dt = new Date();
console.log(Ext.Date.format(dt, Ext.Date.patterns.ShortDate));
*
Ext.Date.parseFunctions['x-date-format'] = myDateParser;
*
date
: Stringstrict
: Boolean
To enable Dates to also be formatted according to that format, a corresponding * formatting function must be placed into the {@link #formatFunctions} property. * @property parseFunctions * @type Object */ parseFunctions: { "MS": function(input, strict) { // note: the timezone offset is ignored since the MS Ajax server sends // a UTC milliseconds-since-Unix-epoch value (negative values are allowed) var re = new RegExp('\\/Date\\(([-+])?(\\d+)(?:[+-]\\d{4})?\\)\\/'); var r = (input || '').match(re); return r? new Date(((r[1] || '') + r[2]) * 1) : null; } }, parseRegexes: [], /** *
An object hash in which each property is a date formatting function. The property name is the * format string which corresponds to the produced formatted date string.
*This object is automatically populated with date formatting functions as * date formats are requested for Ext standard formatting strings.
*Custom formatting functions may be inserted into this object, keyed by a name which from then on * may be used as a format string to {@link #format}. Example:
Ext.Date.formatFunctions['x-date-format'] = myDateFormatter;
* A formatting function should return a string representation of the passed Date object, and is passed the following parameters:
date
: DateTo enable date strings to also be parsed according to that format, a corresponding * parsing function must be placed into the {@link #parseFunctions} property. * @property formatFunctions * @type Object */ formatFunctions: { "MS": function() { // UTC milliseconds since Unix epoch (MS-AJAX serialized date format (MRSF)) return '\\/Date(' + this.getTime() + ')\\/'; } }, y2kYear : 50, /** * Date interval constant * @type String */ MILLI : "ms", /** * Date interval constant * @type String */ SECOND : "s", /** * Date interval constant * @type String */ MINUTE : "mi", /** Date interval constant * @type String */ HOUR : "h", /** * Date interval constant * @type String */ DAY : "d", /** * Date interval constant * @type String */ MONTH : "mo", /** * Date interval constant * @type String */ YEAR : "y", /** *
An object hash containing default date values used during date parsing.
*The following properties are available:
y
: Numberm
: Numberd
: Numberh
: Numberi
: Numbers
: Numberms
: NumberOverride these properties to customize the default date values used by the {@link #parse} method.
*Note: In countries which experience Daylight Saving Time (i.e. DST), the h, i, s * and ms properties may coincide with the exact time in which DST takes effect. * It is the responsiblity of the developer to account for this.
* Example Usage: *
// set default day value to the first day of the month
Ext.Date.defaults.d = 1;
// parse a February date string containing only year and month values.
// setting the default day value to 1 prevents weird date rollover issues
// when attempting to parse the following date string on, for example, March 31st 2009.
Ext.Date.parse('2009-02', 'Y-m'); // returns a Date object representing February 1st 2009
* @property defaults
* @type Object
*/
defaults: {},
/**
* @property {String[]} dayNames
* An array of textual day names.
* Override these values for international dates.
* Example:
*
Ext.Date.dayNames = [
'SundayInYourLang',
'MondayInYourLang',
...
];
*/
dayNames : [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
],
/**
* @property {String[]} monthNames
* An array of textual month names.
* Override these values for international dates.
* Example:
*
Ext.Date.monthNames = [
'JanInYourLang',
'FebInYourLang',
...
];
*/
monthNames : [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
],
/**
* @property {Object} monthNumbers
* An object hash of zero-based javascript month numbers (with short month names as keys. note: keys are case-sensitive).
* Override these values for international dates.
* Example:
*
Ext.Date.monthNumbers = {
'ShortJanNameInYourLang':0,
'ShortFebNameInYourLang':1,
...
};
*/
monthNumbers : {
Jan:0,
Feb:1,
Mar:2,
Apr:3,
May:4,
Jun:5,
Jul:6,
Aug:7,
Sep:8,
Oct:9,
Nov:10,
Dec:11
},
/**
* @property {String} defaultFormat
* The date format string that the {@link Ext.util.Format#dateRenderer} * and {@link Ext.util.Format#date} functions use. See {@link Ext.Date} for details.
*This may be overridden in a locale file.
*/ defaultFormat : "m/d/Y", /** * Get the short month name for the given month number. * Override this function for international dates. * @param {Number} month A zero-based javascript month number. * @return {String} The short month name. */ getShortMonthName : function(month) { return utilDate.monthNames[month].substring(0, 3); }, /** * Get the short day name for the given day number. * Override this function for international dates. * @param {Number} day A zero-based javascript day number. * @return {String} The short day name. */ getShortDayName : function(day) { return utilDate.dayNames[day].substring(0, 3); }, /** * Get the zero-based javascript month number for the given short/full month name. * Override this function for international dates. * @param {String} name The short/full month name. * @return {Number} The zero-based javascript month number. */ getMonthNumber : function(name) { // handle camel casing for english month names (since the keys for the Ext.Date.monthNumbers hash are case sensitive) return utilDate.monthNumbers[name.substring(0, 1).toUpperCase() + name.substring(1, 3).toLowerCase()]; }, /** * Checks if the specified format contains hour information * @param {String} format The format to check * @return {Boolean} True if the format contains hour information * @method */ formatContainsHourInfo : (function(){ var stripEscapeRe = /(\\.)/g, hourInfoRe = /([gGhHisucUOPZ]|MS)/; return function(format){ return hourInfoRe.test(format.replace(stripEscapeRe, '')); }; })(), /** * Checks if the specified format contains information about * anything other than the time. * @param {String} format The format to check * @return {Boolean} True if the format contains information about * date/day information. * @method */ formatContainsDateInfo : (function(){ var stripEscapeRe = /(\\.)/g, dateInfoRe = /([djzmnYycU]|MS)/; return function(format){ return dateInfoRe.test(format.replace(stripEscapeRe, '')); }; })(), /** * The base format-code to formatting-function hashmap used by the {@link #format} method. * Formatting functions are strings (or functions which return strings) which * will return the appropriate value when evaluated in the context of the Date object * from which the {@link #format} method is called. * Add to / override these mappings for custom date formatting. * Note: Ext.Date.format() treats characters as literals if an appropriate mapping cannot be found. * Example: *
Ext.Date.formatCodes.x = "Ext.util.Format.leftPad(this.getDate(), 2, '0')";
console.log(Ext.Date.format(new Date(), 'X'); // returns the current day of the month
* @type Object
*/
formatCodes : {
d: "Ext.String.leftPad(this.getDate(), 2, '0')",
D: "Ext.Date.getShortDayName(this.getDay())", // get localised short day name
j: "this.getDate()",
l: "Ext.Date.dayNames[this.getDay()]",
N: "(this.getDay() ? this.getDay() : 7)",
S: "Ext.Date.getSuffix(this)",
w: "this.getDay()",
z: "Ext.Date.getDayOfYear(this)",
W: "Ext.String.leftPad(Ext.Date.getWeekOfYear(this), 2, '0')",
F: "Ext.Date.monthNames[this.getMonth()]",
m: "Ext.String.leftPad(this.getMonth() + 1, 2, '0')",
M: "Ext.Date.getShortMonthName(this.getMonth())", // get localised short month name
n: "(this.getMonth() + 1)",
t: "Ext.Date.getDaysInMonth(this)",
L: "(Ext.Date.isLeapYear(this) ? 1 : 0)",
o: "(this.getFullYear() + (Ext.Date.getWeekOfYear(this) == 1 && this.getMonth() > 0 ? +1 : (Ext.Date.getWeekOfYear(this) >= 52 && this.getMonth() < 11 ? -1 : 0)))",
Y: "Ext.String.leftPad(this.getFullYear(), 4, '0')",
y: "('' + this.getFullYear()).substring(2, 4)",
a: "(this.getHours() < 12 ? 'am' : 'pm')",
A: "(this.getHours() < 12 ? 'AM' : 'PM')",
g: "((this.getHours() % 12) ? this.getHours() % 12 : 12)",
G: "this.getHours()",
h: "Ext.String.leftPad((this.getHours() % 12) ? this.getHours() % 12 : 12, 2, '0')",
H: "Ext.String.leftPad(this.getHours(), 2, '0')",
i: "Ext.String.leftPad(this.getMinutes(), 2, '0')",
s: "Ext.String.leftPad(this.getSeconds(), 2, '0')",
u: "Ext.String.leftPad(this.getMilliseconds(), 3, '0')",
O: "Ext.Date.getGMTOffset(this)",
P: "Ext.Date.getGMTOffset(this, true)",
T: "Ext.Date.getTimezone(this)",
Z: "(this.getTimezoneOffset() * -60)",
c: function() { // ISO-8601 -- GMT format
for (var c = "Y-m-dTH:i:sP", code = [], i = 0, l = c.length; i < l; ++i) {
var e = c.charAt(i);
code.push(e == "T" ? "'T'" : utilDate.getFormatCode(e)); // treat T as a character literal
}
return code.join(" + ");
},
/*
c: function() { // ISO-8601 -- UTC format
return [
"this.getUTCFullYear()", "'-'",
"Ext.util.Format.leftPad(this.getUTCMonth() + 1, 2, '0')", "'-'",
"Ext.util.Format.leftPad(this.getUTCDate(), 2, '0')",
"'T'",
"Ext.util.Format.leftPad(this.getUTCHours(), 2, '0')", "':'",
"Ext.util.Format.leftPad(this.getUTCMinutes(), 2, '0')", "':'",
"Ext.util.Format.leftPad(this.getUTCSeconds(), 2, '0')",
"'Z'"
].join(" + ");
},
*/
U: "Math.round(this.getTime() / 1000)"
},
/**
* Checks if the passed Date parameters will cause a javascript Date "rollover".
* @param {Number} year 4-digit year
* @param {Number} month 1-based month-of-year
* @param {Number} day Day of month
* @param {Number} hour (optional) Hour
* @param {Number} minute (optional) Minute
* @param {Number} second (optional) Second
* @param {Number} millisecond (optional) Millisecond
* @return {Boolean} true if the passed parameters do not cause a Date "rollover", false otherwise.
*/
isValid : function(y, m, d, h, i, s, ms) {
// setup defaults
h = h || 0;
i = i || 0;
s = s || 0;
ms = ms || 0;
// Special handling for year < 100
var dt = utilDate.add(new Date(y < 100 ? 100 : y, m - 1, d, h, i, s, ms), utilDate.YEAR, y < 100 ? y - 100 : 0);
return y == dt.getFullYear() &&
m == dt.getMonth() + 1 &&
d == dt.getDate() &&
h == dt.getHours() &&
i == dt.getMinutes() &&
s == dt.getSeconds() &&
ms == dt.getMilliseconds();
},
/**
* Parses the passed string using the specified date format.
* Note that this function expects normal calendar dates, meaning that months are 1-based (i.e. 1 = January).
* The {@link #defaults} hash will be used for any date value (i.e. year, month, day, hour, minute, second or millisecond)
* which cannot be found in the passed string. If a corresponding default date value has not been specified in the {@link #defaults} hash,
* the current date's year, month, day or DST-adjusted zero-hour time value will be used instead.
* Keep in mind that the input date string must precisely match the specified format string
* in order for the parse operation to be successful (failed parse operations return a null value).
* Example:
//dt = Fri May 25 2007 (current date)
var dt = new Date();
//dt = Thu May 25 2006 (today's month/day in 2006)
dt = Ext.Date.parse("2006", "Y");
//dt = Sun Jan 15 2006 (all date parts specified)
dt = Ext.Date.parse("2006-01-15", "Y-m-d");
//dt = Sun Jan 15 2006 15:20:01
dt = Ext.Date.parse("2006-01-15 3:20:01 PM", "Y-m-d g:i:s A");
// attempt to parse Sun Feb 29 2006 03:20:01 in strict mode
dt = Ext.Date.parse("2006-02-29 03:20:01", "Y-m-d H:i:s", true); // returns null
* @param {String} input The raw date string.
* @param {String} format The expected date string format.
* @param {Boolean} strict (optional) True to validate date strings while parsing (i.e. prevents javascript Date "rollover")
(defaults to false). Invalid date strings will return null when parsed.
* @return {Date} The parsed Date.
*/
parse : function(input, format, strict) {
var p = utilDate.parseFunctions;
if (p[format] == null) {
utilDate.createParser(format);
}
return p[format](input, Ext.isDefined(strict) ? strict : utilDate.useStrict);
},
// Backwards compat
parseDate: function(input, format, strict){
return utilDate.parse(input, format, strict);
},
// private
getFormatCode : function(character) {
var f = utilDate.formatCodes[character];
if (f) {
f = typeof f == 'function'? f() : f;
utilDate.formatCodes[character] = f; // reassign function result to prevent repeated execution
}
// note: unknown characters are treated as literals
return f || ("'" + Ext.String.escape(character) + "'");
},
// private
createFormat : function(format) {
var code = [],
special = false,
ch = '';
for (var i = 0; i < format.length; ++i) {
ch = format.charAt(i);
if (!special && ch == "\\") {
special = true;
} else if (special) {
special = false;
code.push("'" + Ext.String.escape(ch) + "'");
} else {
code.push(utilDate.getFormatCode(ch));
}
}
utilDate.formatFunctions[format] = Ext.functionFactory("return " + code.join('+'));
},
// private
createParser : (function() {
var code = [
"var dt, y, m, d, h, i, s, ms, o, z, zz, u, v,",
"def = Ext.Date.defaults,",
"results = String(input).match(Ext.Date.parseRegexes[{0}]);", // either null, or an array of matched strings
"if(results){",
"{1}",
"if(u != null){", // i.e. unix time is defined
"v = new Date(u * 1000);", // give top priority to UNIX time
"}else{",
// create Date object representing midnight of the current day;
// this will provide us with our date defaults
// (note: clearTime() handles Daylight Saving Time automatically)
"dt = Ext.Date.clearTime(new Date);",
// date calculations (note: these calculations create a dependency on Ext.Number.from())
"y = Ext.Number.from(y, Ext.Number.from(def.y, dt.getFullYear()));",
"m = Ext.Number.from(m, Ext.Number.from(def.m - 1, dt.getMonth()));",
"d = Ext.Number.from(d, Ext.Number.from(def.d, dt.getDate()));",
// time calculations (note: these calculations create a dependency on Ext.Number.from())
"h = Ext.Number.from(h, Ext.Number.from(def.h, dt.getHours()));",
"i = Ext.Number.from(i, Ext.Number.from(def.i, dt.getMinutes()));",
"s = Ext.Number.from(s, Ext.Number.from(def.s, dt.getSeconds()));",
"ms = Ext.Number.from(ms, Ext.Number.from(def.ms, dt.getMilliseconds()));",
"if(z >= 0 && y >= 0){",
// both the year and zero-based day of year are defined and >= 0.
// these 2 values alone provide sufficient info to create a full date object
// create Date object representing January 1st for the given year
// handle years < 100 appropriately
"v = Ext.Date.add(new Date(y < 100 ? 100 : y, 0, 1, h, i, s, ms), Ext.Date.YEAR, y < 100 ? y - 100 : 0);",
// then add day of year, checking for Date "rollover" if necessary
"v = !strict? v : (strict === true && (z <= 364 || (Ext.Date.isLeapYear(v) && z <= 365))? Ext.Date.add(v, Ext.Date.DAY, z) : null);",
"}else if(strict === true && !Ext.Date.isValid(y, m + 1, d, h, i, s, ms)){", // check for Date "rollover"
"v = null;", // invalid date, so return null
"}else{",
// plain old Date object
// handle years < 100 properly
"v = Ext.Date.add(new Date(y < 100 ? 100 : y, m, d, h, i, s, ms), Ext.Date.YEAR, y < 100 ? y - 100 : 0);",
"}",
"}",
"}",
"if(v){",
// favour UTC offset over GMT offset
"if(zz != null){",
// reset to UTC, then add offset
"v = Ext.Date.add(v, Ext.Date.SECOND, -v.getTimezoneOffset() * 60 - zz);",
"}else if(o){",
// reset to GMT, then add offset
"v = Ext.Date.add(v, Ext.Date.MINUTE, -v.getTimezoneOffset() + (sn == '+'? -1 : 1) * (hr * 60 + mn));",
"}",
"}",
"return v;"
].join('\n');
return function(format) {
var regexNum = utilDate.parseRegexes.length,
currentGroup = 1,
calc = [],
regex = [],
special = false,
ch = "";
for (var i = 0; i < format.length; ++i) {
ch = format.charAt(i);
if (!special && ch == "\\") {
special = true;
} else if (special) {
special = false;
regex.push(Ext.String.escape(ch));
} else {
var obj = utilDate.formatCodeToRegex(ch, currentGroup);
currentGroup += obj.g;
regex.push(obj.s);
if (obj.g && obj.c) {
calc.push(obj.c);
}
}
}
utilDate.parseRegexes[regexNum] = new RegExp("^" + regex.join('') + "$", 'i');
utilDate.parseFunctions[format] = Ext.functionFactory("input", "strict", xf(code, regexNum, calc.join('')));
};
})(),
// private
parseCodes : {
/*
* Notes:
* g = {Number} calculation group (0 or 1. only group 1 contributes to date calculations.)
* c = {String} calculation method (required for group 1. null for group 0. {0} = currentGroup - position in regex result array)
* s = {String} regex pattern. all matches are stored in results[], and are accessible by the calculation mapped to 'c'
*/
d: {
g:1,
c:"d = parseInt(results[{0}], 10);\n",
s:"(\\d{2})" // day of month with leading zeroes (01 - 31)
},
j: {
g:1,
c:"d = parseInt(results[{0}], 10);\n",
s:"(\\d{1,2})" // day of month without leading zeroes (1 - 31)
},
D: function() {
for (var a = [], i = 0; i < 7; a.push(utilDate.getShortDayName(i)), ++i); // get localised short day names
return {
g:0,
c:null,
s:"(?:" + a.join("|") +")"
};
},
l: function() {
return {
g:0,
c:null,
s:"(?:" + utilDate.dayNames.join("|") + ")"
};
},
N: {
g:0,
c:null,
s:"[1-7]" // ISO-8601 day number (1 (monday) - 7 (sunday))
},
S: {
g:0,
c:null,
s:"(?:st|nd|rd|th)"
},
w: {
g:0,
c:null,
s:"[0-6]" // javascript day number (0 (sunday) - 6 (saturday))
},
z: {
g:1,
c:"z = parseInt(results[{0}], 10);\n",
s:"(\\d{1,3})" // day of the year (0 - 364 (365 in leap years))
},
W: {
g:0,
c:null,
s:"(?:\\d{2})" // ISO-8601 week number (with leading zero)
},
F: function() {
return {
g:1,
c:"m = parseInt(Ext.Date.getMonthNumber(results[{0}]), 10);\n", // get localised month number
s:"(" + utilDate.monthNames.join("|") + ")"
};
},
M: function() {
for (var a = [], i = 0; i < 12; a.push(utilDate.getShortMonthName(i)), ++i); // get localised short month names
return Ext.applyIf({
s:"(" + a.join("|") + ")"
}, utilDate.formatCodeToRegex("F"));
},
m: {
g:1,
c:"m = parseInt(results[{0}], 10) - 1;\n",
s:"(\\d{2})" // month number with leading zeros (01 - 12)
},
n: {
g:1,
c:"m = parseInt(results[{0}], 10) - 1;\n",
s:"(\\d{1,2})" // month number without leading zeros (1 - 12)
},
t: {
g:0,
c:null,
s:"(?:\\d{2})" // no. of days in the month (28 - 31)
},
L: {
g:0,
c:null,
s:"(?:1|0)"
},
o: function() {
return utilDate.formatCodeToRegex("Y");
},
Y: {
g:1,
c:"y = parseInt(results[{0}], 10);\n",
s:"(\\d{4})" // 4-digit year
},
y: {
g:1,
c:"var ty = parseInt(results[{0}], 10);\n"
+ "y = ty > Ext.Date.y2kYear ? 1900 + ty : 2000 + ty;\n", // 2-digit year
s:"(\\d{1,2})"
},
/*
* In the am/pm parsing routines, we allow both upper and lower case
* even though it doesn't exactly match the spec. It gives much more flexibility
* in being able to specify case insensitive regexes.
*/
a: {
g:1,
c:"if (/(am)/i.test(results[{0}])) {\n"
+ "if (!h || h == 12) { h = 0; }\n"
+ "} else { if (!h || h < 12) { h = (h || 0) + 12; }}",
s:"(am|pm|AM|PM)"
},
A: {
g:1,
c:"if (/(am)/i.test(results[{0}])) {\n"
+ "if (!h || h == 12) { h = 0; }\n"
+ "} else { if (!h || h < 12) { h = (h || 0) + 12; }}",
s:"(AM|PM|am|pm)"
},
g: function() {
return utilDate.formatCodeToRegex("G");
},
G: {
g:1,
c:"h = parseInt(results[{0}], 10);\n",
s:"(\\d{1,2})" // 24-hr format of an hour without leading zeroes (0 - 23)
},
h: function() {
return utilDate.formatCodeToRegex("H");
},
H: {
g:1,
c:"h = parseInt(results[{0}], 10);\n",
s:"(\\d{2})" // 24-hr format of an hour with leading zeroes (00 - 23)
},
i: {
g:1,
c:"i = parseInt(results[{0}], 10);\n",
s:"(\\d{2})" // minutes with leading zeros (00 - 59)
},
s: {
g:1,
c:"s = parseInt(results[{0}], 10);\n",
s:"(\\d{2})" // seconds with leading zeros (00 - 59)
},
u: {
g:1,
c:"ms = results[{0}]; ms = parseInt(ms, 10)/Math.pow(10, ms.length - 3);\n",
s:"(\\d+)" // decimal fraction of a second (minimum = 1 digit, maximum = unlimited)
},
O: {
g:1,
c:[
"o = results[{0}];",
"var sn = o.substring(0,1),", // get + / - sign
"hr = o.substring(1,3)*1 + Math.floor(o.substring(3,5) / 60),", // get hours (performs minutes-to-hour conversion also, just in case)
"mn = o.substring(3,5) % 60;", // get minutes
"o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))? (sn + Ext.String.leftPad(hr, 2, '0') + Ext.String.leftPad(mn, 2, '0')) : null;\n" // -12hrs <= GMT offset <= 14hrs
].join("\n"),
s: "([+\-]\\d{4})" // GMT offset in hrs and mins
},
P: {
g:1,
c:[
"o = results[{0}];",
"var sn = o.substring(0,1),", // get + / - sign
"hr = o.substring(1,3)*1 + Math.floor(o.substring(4,6) / 60),", // get hours (performs minutes-to-hour conversion also, just in case)
"mn = o.substring(4,6) % 60;", // get minutes
"o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))? (sn + Ext.String.leftPad(hr, 2, '0') + Ext.String.leftPad(mn, 2, '0')) : null;\n" // -12hrs <= GMT offset <= 14hrs
].join("\n"),
s: "([+\-]\\d{2}:\\d{2})" // GMT offset in hrs and mins (with colon separator)
},
T: {
g:0,
c:null,
s:"[A-Z]{1,4}" // timezone abbrev. may be between 1 - 4 chars
},
Z: {
g:1,
c:"zz = results[{0}] * 1;\n" // -43200 <= UTC offset <= 50400
+ "zz = (-43200 <= zz && zz <= 50400)? zz : null;\n",
s:"([+\-]?\\d{1,5})" // leading '+' sign is optional for UTC offset
},
c: function() {
var calc = [],
arr = [
utilDate.formatCodeToRegex("Y", 1), // year
utilDate.formatCodeToRegex("m", 2), // month
utilDate.formatCodeToRegex("d", 3), // day
utilDate.formatCodeToRegex("h", 4), // hour
utilDate.formatCodeToRegex("i", 5), // minute
utilDate.formatCodeToRegex("s", 6), // second
{c:"ms = results[7] || '0'; ms = parseInt(ms, 10)/Math.pow(10, ms.length - 3);\n"}, // decimal fraction of a second (minimum = 1 digit, maximum = unlimited)
{c:[ // allow either "Z" (i.e. UTC) or "-0530" or "+08:00" (i.e. UTC offset) timezone delimiters. assumes local timezone if no timezone is specified
"if(results[8]) {", // timezone specified
"if(results[8] == 'Z'){",
"zz = 0;", // UTC
"}else if (results[8].indexOf(':') > -1){",
utilDate.formatCodeToRegex("P", 8).c, // timezone offset with colon separator
"}else{",
utilDate.formatCodeToRegex("O", 8).c, // timezone offset without colon separator
"}",
"}"
].join('\n')}
];
for (var i = 0, l = arr.length; i < l; ++i) {
calc.push(arr[i].c);
}
return {
g:1,
c:calc.join(""),
s:[
arr[0].s, // year (required)
"(?:", "-", arr[1].s, // month (optional)
"(?:", "-", arr[2].s, // day (optional)
"(?:",
"(?:T| )?", // time delimiter -- either a "T" or a single blank space
arr[3].s, ":", arr[4].s, // hour AND minute, delimited by a single colon (optional). MUST be preceded by either a "T" or a single blank space
"(?::", arr[5].s, ")?", // seconds (optional)
"(?:(?:\\.|,)(\\d+))?", // decimal fraction of a second (e.g. ",12345" or ".98765") (optional)
"(Z|(?:[-+]\\d{2}(?::)?\\d{2}))?", // "Z" (UTC) or "-0530" (UTC offset without colon delimiter) or "+08:00" (UTC offset with colon delimiter) (optional)
")?",
")?",
")?"
].join("")
};
},
U: {
g:1,
c:"u = parseInt(results[{0}], 10);\n",
s:"(-?\\d+)" // leading minus sign indicates seconds before UNIX epoch
}
},
//Old Ext.Date prototype methods.
// private
dateFormat: function(date, format) {
return utilDate.format(date, format);
},
/**
* Formats a date given the supplied format string.
* @param {Date} date The date to format
* @param {String} format The format string
* @return {String} The formatted date
*/
format: function(date, format) {
if (utilDate.formatFunctions[format] == null) {
utilDate.createFormat(format);
}
var result = utilDate.formatFunctions[format].call(date);
return result + '';
},
/**
* Get the timezone abbreviation of the current date (equivalent to the format specifier 'T').
*
* Note: The date string returned by the javascript Date object's toString() method varies
* between browsers (e.g. FF vs IE) and system region settings (e.g. IE in Asia vs IE in America).
* For a given date string e.g. "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)",
* getTimezone() first tries to get the timezone abbreviation from between a pair of parentheses
* (which may or may not be present), failing which it proceeds to get the timezone abbreviation
* from the GMT offset portion of the date string.
* @param {Date} date The date
* @return {String} The abbreviated timezone name (e.g. 'CST', 'PDT', 'EDT', 'MPST' ...).
*/
getTimezone : function(date) {
// the following list shows the differences between date strings from different browsers on a WinXP SP2 machine from an Asian locale:
//
// Opera : "Thu, 25 Oct 2007 22:53:45 GMT+0800" -- shortest (weirdest) date string of the lot
// Safari : "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)" -- value in parentheses always gives the correct timezone (same as FF)
// FF : "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)" -- value in parentheses always gives the correct timezone
// IE : "Thu Oct 25 22:54:35 UTC+0800 2007" -- (Asian system setting) look for 3-4 letter timezone abbrev
// IE : "Thu Oct 25 17:06:37 PDT 2007" -- (American system setting) look for 3-4 letter timezone abbrev
//
// this crazy regex attempts to guess the correct timezone abbreviation despite these differences.
// step 1: (?:\((.*)\) -- find timezone in parentheses
// step 2: ([A-Z]{1,4})(?:[\-+][0-9]{4})?(?: -?\d+)?) -- if nothing was found in step 1, find timezone from timezone offset portion of date string
// step 3: remove all non uppercase characters found in step 1 and 2
return date.toString().replace(/^.* (?:\((.*)\)|([A-Z]{1,4})(?:[\-+][0-9]{4})?(?: -?\d+)?)$/, "$1$2").replace(/[^A-Z]/g, "");
},
/**
* Get the offset from GMT of the current date (equivalent to the format specifier 'O').
* @param {Date} date The date
* @param {Boolean} colon (optional) true to separate the hours and minutes with a colon (defaults to false).
* @return {String} The 4-character offset string prefixed with + or - (e.g. '-0600').
*/
getGMTOffset : function(date, colon) {
var offset = date.getTimezoneOffset();
return (offset > 0 ? "-" : "+")
+ Ext.String.leftPad(Math.floor(Math.abs(offset) / 60), 2, "0")
+ (colon ? ":" : "")
+ Ext.String.leftPad(Math.abs(offset % 60), 2, "0");
},
/**
* Get the numeric day number of the year, adjusted for leap year.
* @param {Date} date The date
* @return {Number} 0 to 364 (365 in leap years).
*/
getDayOfYear: function(date) {
var num = 0,
d = Ext.Date.clone(date),
m = date.getMonth(),
i;
for (i = 0, d.setDate(1), d.setMonth(0); i < m; d.setMonth(++i)) {
num += utilDate.getDaysInMonth(d);
}
return num + date.getDate() - 1;
},
/**
* Get the numeric ISO-8601 week number of the year.
* (equivalent to the format specifier 'W', but without a leading zero).
* @param {Date} date The date
* @return {Number} 1 to 53
* @method
*/
getWeekOfYear : (function() {
// adapted from http://www.merlyn.demon.co.uk/weekcalc.htm
var ms1d = 864e5, // milliseconds in a day
ms7d = 7 * ms1d; // milliseconds in a week
return function(date) { // return a closure so constants get calculated only once
var DC3 = Date.UTC(date.getFullYear(), date.getMonth(), date.getDate() + 3) / ms1d, // an Absolute Day Number
AWN = Math.floor(DC3 / 7), // an Absolute Week Number
Wyr = new Date(AWN * ms7d).getUTCFullYear();
return AWN - Math.floor(Date.UTC(Wyr, 0, 7) / ms7d) + 1;
};
})(),
/**
* Checks if the current date falls within a leap year.
* @param {Date} date The date
* @return {Boolean} True if the current date falls within a leap year, false otherwise.
*/
isLeapYear : function(date) {
var year = date.getFullYear();
return !!((year & 3) == 0 && (year % 100 || (year % 400 == 0 && year)));
},
/**
* Get the first day of the current month, adjusted for leap year. The returned value
* is the numeric day index within the week (0-6) which can be used in conjunction with
* the {@link #monthNames} array to retrieve the textual day name.
* Example:
*
var dt = new Date('1/10/2007'),
firstDay = Ext.Date.getFirstDayOfMonth(dt);
console.log(Ext.Date.dayNames[firstDay]); //output: 'Monday'
*
* @param {Date} date The date
* @return {Number} The day number (0-6).
*/
getFirstDayOfMonth : function(date) {
var day = (date.getDay() - (date.getDate() - 1)) % 7;
return (day < 0) ? (day + 7) : day;
},
/**
* Get the last day of the current month, adjusted for leap year. The returned value
* is the numeric day index within the week (0-6) which can be used in conjunction with
* the {@link #monthNames} array to retrieve the textual day name.
* Example:
*
var dt = new Date('1/10/2007'),
lastDay = Ext.Date.getLastDayOfMonth(dt);
console.log(Ext.Date.dayNames[lastDay]); //output: 'Wednesday'
*
* @param {Date} date The date
* @return {Number} The day number (0-6).
*/
getLastDayOfMonth : function(date) {
return utilDate.getLastDateOfMonth(date).getDay();
},
/**
* Get the date of the first day of the month in which this date resides.
* @param {Date} date The date
* @return {Date}
*/
getFirstDateOfMonth : function(date) {
return new Date(date.getFullYear(), date.getMonth(), 1);
},
/**
* Get the date of the last day of the month in which this date resides.
* @param {Date} date The date
* @return {Date}
*/
getLastDateOfMonth : function(date) {
return new Date(date.getFullYear(), date.getMonth(), utilDate.getDaysInMonth(date));
},
/**
* Get the number of days in the current month, adjusted for leap year.
* @param {Date} date The date
* @return {Number} The number of days in the month.
* @method
*/
getDaysInMonth: (function() {
var daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
return function(date) { // return a closure for efficiency
var m = date.getMonth();
return m == 1 && utilDate.isLeapYear(date) ? 29 : daysInMonth[m];
};
})(),
/**
* Get the English ordinal suffix of the current day (equivalent to the format specifier 'S').
* @param {Date} date The date
* @return {String} 'st, 'nd', 'rd' or 'th'.
*/
getSuffix : function(date) {
switch (date.getDate()) {
case 1:
case 21:
case 31:
return "st";
case 2:
case 22:
return "nd";
case 3:
case 23:
return "rd";
default:
return "th";
}
},
/**
* Creates and returns a new Date instance with the exact same date value as the called instance.
* Dates are copied and passed by reference, so if a copied date variable is modified later, the original
* variable will also be changed. When the intention is to create a new variable that will not
* modify the original instance, you should create a clone.
*
* Example of correctly cloning a date:
*
//wrong way:
var orig = new Date('10/1/2006');
var copy = orig;
copy.setDate(5);
console.log(orig); //returns 'Thu Oct 05 2006'!
//correct way:
var orig = new Date('10/1/2006'),
copy = Ext.Date.clone(orig);
copy.setDate(5);
console.log(orig); //returns 'Thu Oct 01 2006'
*
* @param {Date} date The date
* @return {Date} The new Date instance.
*/
clone : function(date) {
return new Date(date.getTime());
},
/**
* Checks if the current date is affected by Daylight Saving Time (DST).
* @param {Date} date The date
* @return {Boolean} True if the current date is affected by DST.
*/
isDST : function(date) {
// adapted from http://sencha.com/forum/showthread.php?p=247172#post247172
// courtesy of @geoffrey.mcgill
return new Date(date.getFullYear(), 0, 1).getTimezoneOffset() != date.getTimezoneOffset();
},
/**
* Attempts to clear all time information from this Date by setting the time to midnight of the same day,
* automatically adjusting for Daylight Saving Time (DST) where applicable.
* (note: DST timezone information for the browser's host operating system is assumed to be up-to-date)
* @param {Date} date The date
* @param {Boolean} clone true to create a clone of this date, clear the time and return it (defaults to false).
* @return {Date} this or the clone.
*/
clearTime : function(date, clone) {
if (clone) {
return Ext.Date.clearTime(Ext.Date.clone(date));
}
// get current date before clearing time
var d = date.getDate();
// clear time
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);
date.setMilliseconds(0);
if (date.getDate() != d) { // account for DST (i.e. day of month changed when setting hour = 0)
// note: DST adjustments are assumed to occur in multiples of 1 hour (this is almost always the case)
// refer to http://www.timeanddate.com/time/aboutdst.html for the (rare) exceptions to this rule
// increment hour until cloned date == current date
for (var hr = 1, c = utilDate.add(date, Ext.Date.HOUR, hr); c.getDate() != d; hr++, c = utilDate.add(date, Ext.Date.HOUR, hr));
date.setDate(d);
date.setHours(c.getHours());
}
return date;
},
/**
* Provides a convenient method for performing basic date arithmetic. This method
* does not modify the Date instance being called - it creates and returns
* a new Date instance containing the resulting date value.
*
* Examples:
*
// Basic usage:
var dt = Ext.Date.add(new Date('10/29/2006'), Ext.Date.DAY, 5);
console.log(dt); //returns 'Fri Nov 03 2006 00:00:00'
// Negative values will be subtracted:
var dt2 = Ext.Date.add(new Date('10/1/2006'), Ext.Date.DAY, -5);
console.log(dt2); //returns 'Tue Sep 26 2006 00:00:00'
*
*
* @param {Date} date The date to modify
* @param {String} interval A valid date interval enum value.
* @param {Number} value The amount to add to the current date.
* @return {Date} The new Date instance.
*/
add : function(date, interval, value) {
var d = Ext.Date.clone(date),
Date = Ext.Date;
if (!interval || value === 0) return d;
switch(interval.toLowerCase()) {
case Ext.Date.MILLI:
d.setMilliseconds(d.getMilliseconds() + value);
break;
case Ext.Date.SECOND:
d.setSeconds(d.getSeconds() + value);
break;
case Ext.Date.MINUTE:
d.setMinutes(d.getMinutes() + value);
break;
case Ext.Date.HOUR:
d.setHours(d.getHours() + value);
break;
case Ext.Date.DAY:
d.setDate(d.getDate() + value);
break;
case Ext.Date.MONTH:
var day = date.getDate();
if (day > 28) {
day = Math.min(day, Ext.Date.getLastDateOfMonth(Ext.Date.add(Ext.Date.getFirstDateOfMonth(date), 'mo', value)).getDate());
}
d.setDate(day);
d.setMonth(date.getMonth() + value);
break;
case Ext.Date.YEAR:
d.setFullYear(date.getFullYear() + value);
break;
}
return d;
},
/**
* Checks if a date falls on or between the given start and end dates.
* @param {Date} date The date to check
* @param {Date} start Start date
* @param {Date} end End date
* @return {Boolean} true if this date falls on or between the given start and end dates.
*/
between : function(date, start, end) {
var t = date.getTime();
return start.getTime() <= t && t <= end.getTime();
},
//Maintains compatibility with old static and prototype window.Date methods.
compat: function() {
var nativeDate = window.Date,
p, u,
statics = ['useStrict', 'formatCodeToRegex', 'parseFunctions', 'parseRegexes', 'formatFunctions', 'y2kYear', 'MILLI', 'SECOND', 'MINUTE', 'HOUR', 'DAY', 'MONTH', 'YEAR', 'defaults', 'dayNames', 'monthNames', 'monthNumbers', 'getShortMonthName', 'getShortDayName', 'getMonthNumber', 'formatCodes', 'isValid', 'parseDate', 'getFormatCode', 'createFormat', 'createParser', 'parseCodes'],
proto = ['dateFormat', 'format', 'getTimezone', 'getGMTOffset', 'getDayOfYear', 'getWeekOfYear', 'isLeapYear', 'getFirstDayOfMonth', 'getLastDayOfMonth', 'getDaysInMonth', 'getSuffix', 'clone', 'isDST', 'clearTime', 'add', 'between'];
//Append statics
Ext.Array.forEach(statics, function(s) {
nativeDate[s] = utilDate[s];
});
//Append to prototype
Ext.Array.forEach(proto, function(s) {
nativeDate.prototype[s] = function() {
var args = Array.prototype.slice.call(arguments);
args.unshift(this);
return utilDate[s].apply(utilDate, args);
};
});
}
};
var utilDate = Ext.Date;
})();
/**
* @author Jacky Nguyen Encodes a Date. This returns the actual string which is inserted into the JSON string as the literal expression. * The returned value includes enclosing double quotation marks.
*The default return format is "yyyy-mm-ddThh:mm:ss".
*To override this:
Ext.JSON.encodeDate = function(d) {
return Ext.Date.format(d, '"Y-m-d"');
};
* @param {Date} d The Date to encode
* @return {String} The string literal to use in a JSON string.
*/
this.encodeDate = function(o) {
return '"' + o.getFullYear() + "-"
+ pad(o.getMonth() + 1) + "-"
+ pad(o.getDate()) + "T"
+ pad(o.getHours()) + ":"
+ pad(o.getMinutes()) + ":"
+ pad(o.getSeconds()) + '"';
};
/**
* Encodes an Object, Array or other value
* @param {Object} o The variable to encode
* @return {String} The JSON string
*/
this.encode = function() {
var ec;
return function(o) {
if (!ec) {
// setup encoding function on first access
ec = isNative() ? JSON.stringify : doEncode;
}
return ec(o);
};
}();
/**
* Decodes (parses) a JSON string to an object. If the JSON is invalid, this function throws a SyntaxError unless the safe option is set.
* @param {String} json The JSON string
* @param {Boolean} safe (optional) Whether to return null or throw an exception if the JSON is invalid.
* @return {Object} The resulting object
*/
this.decode = function() {
var dc;
return function(json, safe) {
if (!dc) {
// setup decoding function on first access
dc = isNative() ? JSON.parse : doDecode;
}
try {
return dc(json);
} catch (e) {
if (safe === true) {
return null;
}
Ext.Error.raise({
sourceClass: "Ext.JSON",
sourceMethod: "decode",
msg: "You're trying to decode an invalid JSON String: " + json
});
}
};
}();
})();
/**
* Shorthand for {@link Ext.JSON#encode}
* @member Ext
* @method encode
* @alias Ext.JSON#encode
*/
Ext.encode = Ext.JSON.encode;
/**
* Shorthand for {@link Ext.JSON#decode}
* @member Ext
* @method decode
* @alias Ext.JSON#decode
*/
Ext.decode = Ext.JSON.decode;
/**
* @class Ext
The Ext namespace (global object) encapsulates all classes, singletons, and utility methods provided by Sencha's libraries.
Most user interface Components are at a lower level of nesting in the namespace, but many common utility functions are provided
as direct properties of the Ext namespace.
Also many frequently used methods from other classes are provided as shortcuts within the Ext namespace.
For example {@link Ext#getCmp Ext.getCmp} aliases {@link Ext.ComponentManager#get Ext.ComponentManager.get}.
Many applications are initiated with {@link Ext#onReady Ext.onReady} which is called once the DOM is ready.
This ensures all scripts have been loaded, preventing dependency issues. For example
Ext.onReady(function(){
new Ext.Component({
renderTo: document.body,
html: 'DOM ready!'
});
});
For more information about how to use the Ext classes, see
- The Learning Center
- The FAQ
- The forums
* @singleton
* @markdown
*/
Ext.apply(Ext, {
userAgent: navigator.userAgent.toLowerCase(),
cache: {},
idSeed: 1000,
windowId: 'ext-window',
documentId: 'ext-document',
/**
* True when the document is fully initialized and ready for action
* @type Boolean
*/
isReady: false,
/**
* True to automatically uncache orphaned Ext.Elements periodically
* @type Boolean
*/
enableGarbageCollector: true,
/**
* True to automatically purge event listeners during garbageCollection.
* @type Boolean
*/
enableListenerCollection: true,
/**
* Generates unique ids. If the element already has an id, it is unchanged
* @param {HTMLElement/Ext.Element} el (optional) The element to generate an id for
* @param {String} prefix (optional) Id prefix (defaults "ext-gen")
* @return {String} The generated Id.
*/
id: function(el, prefix) {
var me = this,
sandboxPrefix = '';
el = Ext.getDom(el, true) || {};
if (el === document) {
el.id = me.documentId;
}
else if (el === window) {
el.id = me.windowId;
}
if (!el.id) {
if (me.isSandboxed) {
if (!me.uniqueGlobalNamespace) {
me.getUniqueGlobalNamespace();
}
sandboxPrefix = me.uniqueGlobalNamespace + '-';
}
el.id = sandboxPrefix + (prefix || "ext-gen") + (++Ext.idSeed);
}
return el.id;
},
/**
* Returns the current document body as an {@link Ext.Element}.
* @return Ext.Element The document body
*/
getBody: function() {
return Ext.get(document.body || false);
},
/**
* Returns the current document head as an {@link Ext.Element}.
* @return Ext.Element The document head
* @method
*/
getHead: function() {
var head;
return function() {
if (head == undefined) {
head = Ext.get(document.getElementsByTagName("head")[0]);
}
return head;
};
}(),
/**
* Returns the current HTML document object as an {@link Ext.Element}.
* @return Ext.Element The document
*/
getDoc: function() {
return Ext.get(document);
},
/**
* This is shorthand reference to {@link Ext.ComponentManager#get}.
* Looks up an existing {@link Ext.Component Component} by {@link Ext.Component#id id}
* @param {String} id The component {@link Ext.Component#id id}
* @return Ext.Component The Component, undefined if not found, or null if a
* Class was found.
*/
getCmp: function(id) {
return Ext.ComponentManager.get(id);
},
/**
* Returns the current orientation of the mobile device
* @return {String} Either 'portrait' or 'landscape'
*/
getOrientation: function() {
return window.innerHeight > window.innerWidth ? 'portrait' : 'landscape';
},
/**
* Attempts to destroy any objects passed to it by removing all event listeners, removing them from the
* DOM (if applicable) and calling their destroy functions (if available). This method is primarily
* intended for arguments of type {@link Ext.Element} and {@link Ext.Component}, but any subclass of
* {@link Ext.util.Observable} can be passed in. Any number of elements and/or components can be
* passed into this function in a single call as separate arguments.
* @param {Ext.Element/Ext.Component/Ext.Element[]/Ext.Component[]...} arg1
* An {@link Ext.Element}, {@link Ext.Component}, or an Array of either of these to destroy
*/
destroy: function() {
var ln = arguments.length,
i, arg;
for (i = 0; i < ln; i++) {
arg = arguments[i];
if (arg) {
if (Ext.isArray(arg)) {
this.destroy.apply(this, arg);
}
else if (Ext.isFunction(arg.destroy)) {
arg.destroy();
}
else if (arg.dom) {
arg.remove();
}
}
}
},
/**
* Execute a callback function in a particular scope. If no function is passed the call is ignored.
*
* For example, these lines are equivalent:
*
* Ext.callback(myFunc, this, [arg1, arg2]);
* Ext.isFunction(myFunc) && myFunc.apply(this, [arg1, arg2]);
*
* @param {Function} callback The callback to execute
* @param {Object} scope (optional) The scope to execute in
* @param {Array} args (optional) The arguments to pass to the function
* @param {Number} delay (optional) Pass a number to delay the call by a number of milliseconds.
*/
callback: function(callback, scope, args, delay){
if(Ext.isFunction(callback)){
args = args || [];
scope = scope || window;
if (delay) {
Ext.defer(callback, delay, scope, args);
} else {
callback.apply(scope, args);
}
}
},
/**
* Convert certain characters (&, <, >, and ') to their HTML character equivalents for literal display in web pages.
* @param {String} value The string to encode
* @return {String} The encoded text
*/
htmlEncode : function(value) {
return Ext.String.htmlEncode(value);
},
/**
* Convert certain characters (&, <, >, and ') from their HTML character equivalents.
* @param {String} value The string to decode
* @return {String} The decoded text
*/
htmlDecode : function(value) {
return Ext.String.htmlDecode(value);
},
/**
* Appends content to the query string of a URL, handling logic for whether to place
* a question mark or ampersand.
* @param {String} url The URL to append to.
* @param {String} s The content to append to the URL.
* @return (String) The resulting URL
*/
urlAppend : function(url, s) {
if (!Ext.isEmpty(s)) {
return url + (url.indexOf('?') === -1 ? '?' : '&') + s;
}
return url;
}
});
Ext.ns = Ext.namespace;
// for old browsers
window.undefined = window.undefined;
/**
* @class Ext
* Ext core utilities and functions.
* @singleton
*/
(function(){
/*
FF 3.6 - Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110420 Firefox/3.6.17
FF 4.0.1 - Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
FF 5.0 - Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0
IE6 - Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;)
IE7 - Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1;)
IE8 - Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)
IE9 - Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)
Chrome 11 - Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.60 Safari/534.24
Safari 5 - Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1
Opera 11.11 - Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11
*/
var check = function(regex){
return regex.test(Ext.userAgent);
},
isStrict = document.compatMode == "CSS1Compat",
version = function (is, regex) {
var m;
return (is && (m = regex.exec(Ext.userAgent))) ? parseFloat(m[1]) : 0;
},
docMode = document.documentMode,
isOpera = check(/opera/),
isOpera10_5 = isOpera && check(/version\/10\.5/),
isChrome = check(/\bchrome\b/),
isWebKit = check(/webkit/),
isSafari = !isChrome && check(/safari/),
isSafari2 = isSafari && check(/applewebkit\/4/), // unique to Safari 2
isSafari3 = isSafari && check(/version\/3/),
isSafari4 = isSafari && check(/version\/4/),
isSafari5 = isSafari && check(/version\/5/),
isIE = !isOpera && check(/msie/),
isIE7 = isIE && (check(/msie 7/) || docMode == 7),
isIE8 = isIE && (check(/msie 8/) && docMode != 7 && docMode != 9 || docMode == 8),
isIE9 = isIE && (check(/msie 9/) && docMode != 7 && docMode != 8 || docMode == 9),
isIE6 = isIE && check(/msie 6/),
isGecko = !isWebKit && check(/gecko/),
isGecko3 = isGecko && check(/rv:1\.9/),
isGecko4 = isGecko && check(/rv:2\.0/),
isGecko5 = isGecko && check(/rv:5\./),
isFF3_0 = isGecko3 && check(/rv:1\.9\.0/),
isFF3_5 = isGecko3 && check(/rv:1\.9\.1/),
isFF3_6 = isGecko3 && check(/rv:1\.9\.2/),
isWindows = check(/windows|win32/),
isMac = check(/macintosh|mac os x/),
isLinux = check(/linux/),
scrollbarSize = null,
chromeVersion = version(true, /\bchrome\/(\d+\.\d+)/),
firefoxVersion = version(true, /\bfirefox\/(\d+\.\d+)/),
ieVersion = version(isIE, /msie (\d+\.\d+)/),
operaVersion = version(isOpera, /version\/(\d+\.\d+)/),
safariVersion = version(isSafari, /version\/(\d+\.\d+)/),
webKitVersion = version(isWebKit, /webkit\/(\d+\.\d+)/),
isSecure = /^https/i.test(window.location.protocol);
// remove css image flicker
try {
document.execCommand("BackgroundImageCache", false, true);
} catch(e) {}
Ext.setVersion('extjs', '4.0.7');
Ext.apply(Ext, {
/**
* URL to a blank file used by Ext when in secure mode for iframe src and onReady src to prevent
* the IE insecure content warning ('about:blank', except for IE in secure mode, which is 'javascript:""').
* @type String
*/
SSL_SECURE_URL : isSecure && isIE ? 'javascript:""' : 'about:blank',
/**
* True if the {@link Ext.fx.Anim} Class is available
* @type Boolean
* @property enableFx
*/
/**
* True to scope the reset CSS to be just applied to Ext components. Note that this wraps root containers
* with an additional element. Also remember that when you turn on this option, you have to use ext-all-scoped {
* unless you use the bootstrap.js to load your javascript, in which case it will be handled for you.
* @type Boolean
*/
scopeResetCSS : Ext.buildSettings.scopeResetCSS,
/**
* EXPERIMENTAL - True to cascade listener removal to child elements when an element is removed.
* Currently not optimized for performance.
* @type Boolean
*/
enableNestedListenerRemoval : false,
/**
* Indicates whether to use native browser parsing for JSON methods.
* This option is ignored if the browser does not support native JSON methods.
* Note: Native JSON methods will not work with objects that have functions.
* Also, property names must be quoted, otherwise the data will not parse. (Defaults to false)
* @type Boolean
*/
USE_NATIVE_JSON : false,
/**
* Return the dom node for the passed String (id), dom node, or Ext.Element.
* Optional 'strict' flag is needed for IE since it can return 'name' and
* 'id' elements by using getElementById.
* Here are some examples:
*
// gets dom node based on id
var elDom = Ext.getDom('elId');
// gets dom node based on the dom node
var elDom1 = Ext.getDom(elDom);
// If we don't know if we are working with an
// Ext.Element or a dom node use Ext.getDom
function(el){
var dom = Ext.getDom(el);
// do something with the dom node
}
*
* Note: the dom node to be found actually needs to exist (be rendered, etc)
* when this method is called to be successful.
* @param {String/HTMLElement/Ext.Element} el
* @return HTMLElement
*/
getDom : function(el, strict) {
if (!el || !document) {
return null;
}
if (el.dom) {
return el.dom;
} else {
if (typeof el == 'string') {
var e = document.getElementById(el);
// IE returns elements with the 'name' and 'id' attribute.
// we do a strict check to return the element with only the id attribute
if (e && isIE && strict) {
if (el == e.getAttribute('id')) {
return e;
} else {
return null;
}
}
return e;
} else {
return el;
}
}
},
/**
* Removes a DOM node from the document.
* Removes this element from the document, removes all DOM event listeners, and deletes the cache reference.
* All DOM event listeners are removed from this element. If {@link Ext#enableNestedListenerRemoval Ext.enableNestedListenerRemoval} is
* true
, then DOM event listeners are also removed from all child nodes. The body node
* will be ignored if passed in.
Utility method for returning a default value if the passed value is empty.
*The value is deemed to be empty if it is
Ext.addBehaviors({
// add a listener for click on all anchors in element with id foo
'#foo a@click' : function(e, t){
// do something
},
// add the same listener to multiple selectors (separated by comma BEFORE the @)
'#foo a, #bar span.some-class@mouseover' : function(){
// do something
}
});
*
* @param {Object} obj The list of behaviors to apply
*/
addBehaviors : function(o){
if(!Ext.isReady){
Ext.onReady(function(){
Ext.addBehaviors(o);
});
} else {
var cache = {}, // simple cache for applying multiple behaviors to same selector does query multiple times
parts,
b,
s;
for (b in o) {
if ((parts = b.split('@'))[1]) { // for Object prototype breakers
s = parts[0];
if(!cache[s]){
cache[s] = Ext.select(s);
}
cache[s].on(parts[1], o[b]);
}
}
cache = null;
}
},
/**
* Returns the size of the browser scrollbars. This can differ depending on
* operating system settings, such as the theme or font size.
* @param {Boolean} force (optional) true to force a recalculation of the value.
* @return {Object} An object containing the width of a vertical scrollbar and the
* height of a horizontal scrollbar.
*/
getScrollbarSize: function (force) {
if(!Ext.isReady){
return 0;
}
if(force === true || scrollbarSize === null){
// BrowserBug: IE9
// When IE9 positions an element offscreen via offsets, the offsetWidth is
// inaccurately reported. For IE9 only, we render on screen before removing.
var cssClass = Ext.isIE9 ? '' : Ext.baseCSSPrefix + 'hide-offsets',
// Append our div, do our calculation and then remove it
div = Ext.getBody().createChild(' '),
child = div.child('div', true),
w1 = child.offsetWidth;
div.setStyle('overflow', (Ext.isWebKit || Ext.isGecko) ? 'auto' : 'scroll');
var w2 = child.offsetWidth, width = w1 - w2;
div.remove();
// We assume width == height for now. TODO: is this always true?
scrollbarSize = { width: width, height: width };
}
return scrollbarSize;
},
/**
* Utility method for getting the width of the browser's vertical scrollbar. This
* can differ depending on operating system settings, such as the theme or font size.
*
* This method is deprected in favor of {@link #getScrollbarSize}.
*
* @param {Boolean} force (optional) true to force a recalculation of the value.
* @return {Number} The width of a vertical scrollbar.
* @deprecated
*/
getScrollBarWidth: function(force){
var size = Ext.getScrollbarSize(force);
return size.width + 2; // legacy fudge factor
},
/**
* Copies a set of named properties fom the source object to the destination object.
*
* Example:
*
* ImageComponent = Ext.extend(Ext.Component, {
* initComponent: function() {
* this.autoEl = { tag: 'img' };
* MyComponent.superclass.initComponent.apply(this, arguments);
* this.initialBox = Ext.copyTo({}, this.initialConfig, 'x,y,width,height');
* }
* });
*
* Important note: To borrow class prototype methods, use {@link Ext.Base#borrow} instead.
*
* @param {Object} dest The destination object.
* @param {Object} source The source object.
* @param {String/String[]} names Either an Array of property names, or a comma-delimited list
* of property names to copy.
* @param {Boolean} usePrototypeKeys (Optional) Defaults to false. Pass true to copy keys off of the prototype as well as the instance.
* @return {Object} The modified object.
*/
copyTo : function(dest, source, names, usePrototypeKeys){
if(typeof names == 'string'){
names = names.split(/[,;\s]/);
}
Ext.each(names, function(name){
if(usePrototypeKeys || source.hasOwnProperty(name)){
dest[name] = source[name];
}
}, this);
return dest;
},
/**
* Attempts to destroy and then remove a set of named properties of the passed object.
* @param {Object} o The object (most likely a Component) who's properties you wish to destroy.
* @param {String...} args One or more names of the properties to destroy and remove from the object.
*/
destroyMembers : function(o){
for (var i = 1, a = arguments, len = a.length; i < len; i++) {
Ext.destroy(o[a[i]]);
delete o[a[i]];
}
},
/**
* Logs a message. If a console is present it will be used. On Opera, the method
* "opera.postError" is called. In other cases, the message is logged to an array
* "Ext.log.out". An attached debugger can watch this array and view the log. The
* log buffer is limited to a maximum of "Ext.log.max" entries (defaults to 250).
* The `Ext.log.out` array can also be written to a popup window by entering the
* following in the URL bar (a "bookmarklet"):
*
* javascript:void(Ext.log.show());
*
* If additional parameters are passed, they are joined and appended to the message.
* A technique for tracing entry and exit of a function is this:
*
* function foo () {
* Ext.log({ indent: 1 }, '>> foo');
*
* // log statements in here or methods called from here will be indented
* // by one step
*
* Ext.log({ outdent: 1 }, '<< foo');
* }
*
* This method does nothing in a release build.
*
* @param {String/Object} message The message to log or an options object with any
* of the following properties:
*
* - `msg`: The message to log (required).
* - `level`: One of: "error", "warn", "info" or "log" (the default is "log").
* - `dump`: An object to dump to the log as part of the message.
* - `stack`: True to include a stack trace in the log.
* - `indent`: Cause subsequent log statements to be indented one step.
* - `outdent`: Cause this and following statements to be one step less indented.
* @markdown
*/
log :
Ext.emptyFn,
/**
* Partitions the set into two sets: a true set and a false set.
* Example:
* Example2:
*
// Example 1:
Ext.partition([true, false, true, true, false]); // [[true, true, true], [false, false]]
// Example 2:
Ext.partition(
Ext.query("p"),
function(val){
return val.className == "class1"
}
);
// true are those paragraph elements with a className of "class1",
// false set are those that do not have that className.
*
* @param {Array/NodeList} arr The array to partition
* @param {Function} truth (optional) a function to determine truth. If this is omitted the element
* itself must be able to be evaluated for its truthfulness.
* @return {Array} [array of truish values, array of falsy values]
* @deprecated 4.0.0 Will be removed in the next major version
*/
partition : function(arr, truth){
var ret = [[],[]];
Ext.each(arr, function(v, i, a) {
ret[ (truth && truth(v, i, a)) || (!truth && v) ? 0 : 1].push(v);
});
return ret;
},
/**
* Invokes a method on each item in an Array.
*
// Example:
Ext.invoke(Ext.query("p"), "getAttribute", "id");
// [el1.getAttribute("id"), el2.getAttribute("id"), ..., elN.getAttribute("id")]
*
* @param {Array/NodeList} arr The Array of items to invoke the method on.
* @param {String} methodName The method name to invoke.
* @param {Object...} args Arguments to send into the method invocation.
* @return {Array} The results of invoking the method on each item in the array.
* @deprecated 4.0.0 Will be removed in the next major version
*/
invoke : function(arr, methodName){
var ret = [],
args = Array.prototype.slice.call(arguments, 2);
Ext.each(arr, function(v,i) {
if (v && typeof v[methodName] == 'function') {
ret.push(v[methodName].apply(v, args));
} else {
ret.push(undefined);
}
});
return ret;
},
/**
* Zips N sets together.
*
// Example 1:
Ext.zip([1,2,3],[4,5,6]); // [[1,4],[2,5],[3,6]]
// Example 2:
Ext.zip(
[ "+", "-", "+"],
[ 12, 10, 22],
[ 43, 15, 96],
function(a, b, c){
return "$" + a + "" + b + "." + c
}
); // ["$+12.43", "$-10.15", "$+22.96"]
*
* @param {Array/NodeList...} arr This argument may be repeated. Array(s) to contribute values.
* @param {Function} zipper (optional) The last item in the argument list. This will drive how the items are zipped together.
* @return {Array} The zipped set.
* @deprecated 4.0.0 Will be removed in the next major version
*/
zip : function(){
var parts = Ext.partition(arguments, function( val ){ return typeof val != 'function'; }),
arrs = parts[0],
fn = parts[1][0],
len = Ext.max(Ext.pluck(arrs, "length")),
ret = [];
for (var i = 0; i < len; i++) {
ret[i] = [];
if(fn){
ret[i] = fn.apply(fn, Ext.pluck(arrs, i));
}else{
for (var j = 0, aLen = arrs.length; j < aLen; j++){
ret[i].push( arrs[j][i] );
}
}
}
return ret;
},
/**
* Turns an array into a sentence, joined by a specified connector - e.g.:
* Ext.toSentence(['Adama', 'Tigh', 'Roslin']); //'Adama, Tigh and Roslin'
* Ext.toSentence(['Adama', 'Tigh', 'Roslin'], 'or'); //'Adama, Tigh or Roslin'
* @param {String[]} items The array to create a sentence from
* @param {String} connector The string to use to connect the last two words. Usually 'and' or 'or' - defaults to 'and'.
* @return {String} The sentence string
* @deprecated 4.0.0 Will be removed in the next major version
*/
toSentence: function(items, connector) {
var length = items.length;
if (length <= 1) {
return items[0];
} else {
var head = items.slice(0, length - 1),
tail = items[length - 1];
return Ext.util.Format.format("{0} {1} {2}", head.join(", "), connector || 'and', tail);
}
},
/**
* By default, Ext intelligently decides whether floating elements should be shimmed. If you are using flash,
* you may want to set this to true.
* @type Boolean
*/
useShims: isIE6
});
})();
/**
* Loads Ext.app.Application class and starts it up with given configuration after the page is ready.
*
* See Ext.app.Application for details.
*
* @param {Object} config
*/
Ext.application = function(config) {
Ext.require('Ext.app.Application');
Ext.onReady(function() {
Ext.create('Ext.app.Application', config);
});
};
/**
* @class Ext.util.Format
This class is a centralized place for formatting functions. It includes
functions to format various different types of data, such as text, dates and numeric values.
__Localization__
This class contains several options for localization. These can be set once the library has loaded,
all calls to the functions from that point will use the locale settings that were specified.
Options include:
- thousandSeparator
- decimalSeparator
- currenyPrecision
- currencySign
- currencyAtEnd
This class also uses the default date format defined here: {@link Ext.Date#defaultFormat}.
__Using with renderers__
There are two helper functions that return a new function that can be used in conjunction with
grid renderers:
columns: [{
dataIndex: 'date',
renderer: Ext.util.Format.dateRenderer('Y-m-d')
}, {
dataIndex: 'time',
renderer: Ext.util.Format.numberRenderer('0.000')
}]
Functions that only take a single argument can also be passed directly:
columns: [{
dataIndex: 'cost',
renderer: Ext.util.Format.usMoney
}, {
dataIndex: 'productCode',
renderer: Ext.util.Format.uppercase
}]
__Using with XTemplates__
XTemplates can also directly use Ext.util.Format functions:
new Ext.XTemplate([
'Date: {startDate:date("Y-m-d")}',
'Cost: {cost:usMoney}'
]);
* @markdown
* @singleton
*/
(function() {
Ext.ns('Ext.util');
Ext.util.Format = {};
var UtilFormat = Ext.util.Format,
stripTagsRE = /<\/?[^>]+>/gi,
stripScriptsRe = /(?:The character that the {@link #number} function uses as a thousand separator.
*This may be overridden in a locale file.
*/ thousandSeparator: ',', /** * @property {String} decimalSeparator *The character that the {@link #number} function uses as a decimal point.
*This may be overridden in a locale file.
*/ decimalSeparator: '.', /** * @property {Number} currencyPrecision *The number of decimal places that the {@link #currency} function displays.
*This may be overridden in a locale file.
*/ currencyPrecision: 2, /** * @property {String} currencySign *The currency sign that the {@link #currency} function displays.
*This may be overridden in a locale file.
*/ currencySign: '$', /** * @property {Boolean} currencyAtEnd *This may be set to true
to make the {@link #currency} function
* append the currency sign to the formatted value.
This may be overridden in a locale file.
*/ currencyAtEnd: false, /** * Checks a reference and converts it to empty string if it is undefined * @param {Object} value Reference to check * @return {Object} Empty string if converted, otherwise the original value */ undef : function(value) { return value !== undefined ? value : ""; }, /** * Checks a reference and converts it to the default value if it's empty * @param {Object} value Reference to check * @param {String} defaultValue The value to insert of it's undefined (defaults to "") * @return {String} */ defaultValue : function(value, defaultValue) { return value !== undefined && value !== '' ? value : defaultValue; }, /** * Returns a substring from within an original string * @param {String} value The original text * @param {Number} start The start index of the substring * @param {Number} length The length of the substring * @return {String} The substring */ substr : function(value, start, length) { return String(value).substr(start, length); }, /** * Converts a string to all lower case letters * @param {String} value The text to convert * @return {String} The converted text */ lowercase : function(value) { return String(value).toLowerCase(); }, /** * Converts a string to all upper case letters * @param {String} value The text to convert * @return {String} The converted text */ uppercase : function(value) { return String(value).toUpperCase(); }, /** * Format a number as US currency * @param {Number/String} value The numeric value to format * @return {String} The formatted currency string */ usMoney : function(v) { return UtilFormat.currency(v, '$', 2); }, /** * Format a number as a currency * @param {Number/String} value The numeric value to format * @param {String} sign The currency sign to use (defaults to {@link #currencySign}) * @param {Number} decimals The number of decimals to use for the currency (defaults to {@link #currencyPrecision}) * @param {Boolean} end True if the currency sign should be at the end of the string (defaults to {@link #currencyAtEnd}) * @return {String} The formatted currency string */ currency: function(v, currencySign, decimals, end) { var negativeSign = '', format = ",0", i = 0; v = v - 0; if (v < 0) { v = -v; negativeSign = '-'; } decimals = decimals || UtilFormat.currencyPrecision; format += format + (decimals > 0 ? '.' : ''); for (; i < decimals; i++) { format += '0'; } v = UtilFormat.number(v, format); if ((end || UtilFormat.currencyAtEnd) === true) { return Ext.String.format("{0}{1}{2}", negativeSign, v, currencySign || UtilFormat.currencySign); } else { return Ext.String.format("{0}{1}{2}", negativeSign, currencySign || UtilFormat.currencySign, v); } }, /** * Formats the passed date using the specified format pattern. * @param {String/Date} value The value to format. If a string is passed, it is converted to a Date by the Javascript * Date object's parse() method. * @param {String} format (Optional) Any valid date format string. Defaults to {@link Ext.Date#defaultFormat}. * @return {String} The formatted date string. */ date: function(v, format) { if (!v) { return ""; } if (!Ext.isDate(v)) { v = new Date(Date.parse(v)); } return Ext.Date.dateFormat(v, format || Ext.Date.defaultFormat); }, /** * Returns a date rendering function that can be reused to apply a date format multiple times efficiently * @param {String} format Any valid date format string. Defaults to {@link Ext.Date#defaultFormat}. * @return {Function} The date formatting function */ dateRenderer : function(format) { return function(v) { return UtilFormat.date(v, format); }; }, /** * Strips all HTML tags * @param {Object} value The text from which to strip tags * @return {String} The stripped text */ stripTags : function(v) { return !v ? v : String(v).replace(stripTagsRE, ""); }, /** * Strips all script tags * @param {Object} value The text from which to strip script tags * @return {String} The stripped text */ stripScripts : function(v) { return !v ? v : String(v).replace(stripScriptsRe, ""); }, /** * Simple format for a file size (xxx bytes, xxx KB, xxx MB) * @param {Number/String} size The numeric value to format * @return {String} The formatted file size */ fileSize : function(size) { if (size < 1024) { return size + " bytes"; } else if (size < 1048576) { return (Math.round(((size*10) / 1024))/10) + " KB"; } else { return (Math.round(((size*10) / 1048576))/10) + " MB"; } }, /** * It does simple math for use in a template, for example:
* var tpl = new Ext.Template('{value} * 10 = {value:math("* 10")}');
*
* @return {Function} A function that operates on the passed value.
* @method
*/
math : function(){
var fns = {};
return function(v, a){
if (!fns[a]) {
fns[a] = Ext.functionFactory('v', 'return v ' + a + ';');
}
return fns[a](v);
};
}(),
/**
* Rounds the passed number to the required decimal precision.
* @param {Number/String} value The numeric value to round.
* @param {Number} precision The number of decimal places to which to round the first parameter's value.
* @return {Number} The rounded value.
*/
round : function(value, precision) {
var result = Number(value);
if (typeof precision == 'number') {
precision = Math.pow(10, precision);
result = Math.round(value * precision) / precision;
}
return result;
},
/**
* Formats the passed number according to the passed format string.
*The number of digits after the decimal separator character specifies the number of * decimal places in the resulting string. The local-specific decimal character is used in the result.
*The presence of a thousand separator character in the format string specifies that * the locale-specific thousand separator (if any) is inserted separating thousand groups.
*By default, "," is expected as the thousand separator, and "." is expected as the decimal separator.
*New to Ext JS 4
*Locale-specific characters are always used in the formatted output when inserting * thousand and decimal separators.
*The format string must specify separator characters according to US/UK conventions ("," as the * thousand separator, and "." as the decimal separator)
*To allow specification of format strings according to local conventions for separator characters, add
* the string /i
to the end of the format string.
// Start a simple clock task that updates a div once per second
var updateClock = function(){
Ext.fly('clock').update(new Date().format('g:i:s A'));
}
var task = {
run: updateClock,
interval: 1000 //1 second
}
var runner = new Ext.util.TaskRunner();
runner.start(task);
// equivalent using TaskManager
Ext.TaskManager.start({
run: updateClock,
interval: 1000
});
*
* See the {@link #start} method for details about how to configure a task object.
* Also see {@link Ext.util.DelayedTask}. * * @constructor * @param {Number} [interval=10] The minimum precision in milliseconds supported by this TaskRunner instance */ Ext.ns('Ext.util'); Ext.util.TaskRunner = function(interval) { interval = interval || 10; var tasks = [], removeQueue = [], id = 0, running = false, // private stopThread = function() { running = false; clearInterval(id); id = 0; }, // private startThread = function() { if (!running) { running = true; id = setInterval(runTasks, interval); } }, // private removeTask = function(t) { removeQueue.push(t); if (t.onStop) { t.onStop.apply(t.scope || t); } }, // private runTasks = function() { var rqLen = removeQueue.length, now = new Date().getTime(), i; if (rqLen > 0) { for (i = 0; i < rqLen; i++) { Ext.Array.remove(tasks, removeQueue[i]); } removeQueue = []; if (tasks.length < 1) { stopThread(); return; } } i = 0; var t, itime, rt, len = tasks.length; for (; i < len; ++i) { t = tasks[i]; itime = now - t.taskRunTime; if (t.interval <= itime) { rt = t.run.apply(t.scope || t, t.args || [++t.taskRunCount]); t.taskRunTime = now; if (rt === false || t.taskRunCount === t.repeat) { removeTask(t); return; } } if (t.duration && t.duration <= (now - t.taskStartTime)) { removeTask(t); } } }; /** * Starts a new task. * @method start * @param {Object} taskA config object that supports the following properties:
run
: FunctionThe function to execute each time the task is invoked. The
* function will be called at each interval and passed the args
argument if specified, and the
* current invocation count if not.
If a particular scope (this
reference) is required, be sure to specify it using the scope
argument.
Return false
from this function to terminate the task.
interval
: Numberargs
: Arrayrun
. If not specified, the current invocation count is passed.scope
: Objectrun
function. Defaults to the task config object.duration
: Numberrepeat
: NumberBefore each invocation, Ext injects the property taskRunCount
into the task object so
* that calculations based on the repeat count can be performed.
// Start a simple clock task that updates a div once per second
var task = {
run: function(){
Ext.fly('clock').update(new Date().format('g:i:s A'));
},
interval: 1000 //1 second
}
Ext.TaskManager.start(task);
* See the {@link #start} method for details about how to configure a task object.
* @singleton */ Ext.TaskManager = Ext.create('Ext.util.TaskRunner'); /** * @class Ext.is * * Determines information about the current platform the application is running on. * * @singleton */ Ext.is = { init : function(navigator) { var platforms = this.platforms, ln = platforms.length, i, platform; navigator = navigator || window.navigator; for (i = 0; i < ln; i++) { platform = platforms[i]; this[platform.identity] = platform.regex.test(navigator[platform.property]); } /** * @property Desktop True if the browser is running on a desktop machine * @type {Boolean} */ this.Desktop = this.Mac || this.Windows || (this.Linux && !this.Android); /** * @property Tablet True if the browser is running on a tablet (iPad) */ this.Tablet = this.iPad; /** * @property Phone True if the browser is running on a phone. * @type {Boolean} */ this.Phone = !this.Desktop && !this.Tablet; /** * @property iOS True if the browser is running on iOS * @type {Boolean} */ this.iOS = this.iPhone || this.iPad || this.iPod; /** * @property Standalone Detects when application has been saved to homescreen. * @type {Boolean} */ this.Standalone = !!window.navigator.standalone; }, /** * @property iPhone True when the browser is running on a iPhone * @type {Boolean} */ platforms: [{ property: 'platform', regex: /iPhone/i, identity: 'iPhone' }, /** * @property iPod True when the browser is running on a iPod * @type {Boolean} */ { property: 'platform', regex: /iPod/i, identity: 'iPod' }, /** * @property iPad True when the browser is running on a iPad * @type {Boolean} */ { property: 'userAgent', regex: /iPad/i, identity: 'iPad' }, /** * @property Blackberry True when the browser is running on a Blackberry * @type {Boolean} */ { property: 'userAgent', regex: /Blackberry/i, identity: 'Blackberry' }, /** * @property Android True when the browser is running on an Android device * @type {Boolean} */ { property: 'userAgent', regex: /Android/i, identity: 'Android' }, /** * @property Mac True when the browser is running on a Mac * @type {Boolean} */ { property: 'platform', regex: /Mac/i, identity: 'Mac' }, /** * @property Windows True when the browser is running on Windows * @type {Boolean} */ { property: 'platform', regex: /Win/i, identity: 'Windows' }, /** * @property Linux True when the browser is running on Linux * @type {Boolean} */ { property: 'platform', regex: /Linux/i, identity: 'Linux' }] }; Ext.is.init(); /** * @class Ext.supports * * Determines information about features are supported in the current environment * * @singleton */ Ext.supports = { init : function() { var doc = document, div = doc.createElement('div'), tests = this.tests, ln = tests.length, i, test; div.innerHTML = [ 'The DomHelper class provides a layer of abstraction from DOM and transparently supports creating * elements via DOM or using HTML fragments. It also has the ability to create HTML fragment templates * from your DOM building code.
* *DomHelper element specification object
*A specification object is used when creating elements. Attributes of this object * are assumed to be element attributes, except for 4 special attributes: *
NOTE: For other arbitrary attributes, the value will currently not be automatically * HTML-escaped prior to building the element's HTML string. This means that if your attribute value * contains special characters that would not normally be allowed in a double-quoted attribute value, * you must manually HTML-encode it beforehand (see {@link Ext.String#htmlEncode}) or risk * malformed HTML being created. This behavior may change in a future release.
* *Insertion methods
*Commonly used insertion methods: *
Example
*This is an example, where an unordered list with 3 children items is appended to an existing
* element with id 'my-div':
var dh = Ext.DomHelper; // create shorthand alias
// specification object
var spec = {
id: 'my-ul',
tag: 'ul',
cls: 'my-list',
// append children after creating
children: [ // may also specify 'cn' instead of 'children'
{tag: 'li', id: 'item0', html: 'List Item 0'},
{tag: 'li', id: 'item1', html: 'List Item 1'},
{tag: 'li', id: 'item2', html: 'List Item 2'}
]
};
var list = dh.append(
'my-div', // the context element 'my-div' can either be the id or the actual node
spec // the specification object
);
* Element creation specification parameters in this class may also be passed as an Array of * specification objects. This can be used to insert multiple sibling nodes into an existing * container very efficiently. For example, to add more list items to the example above:
dh.append('my-ul', [
{tag: 'li', id: 'item3', html: 'List Item 3'},
{tag: 'li', id: 'item4', html: 'List Item 4'}
]);
*
*
* Templating
*The real power is in the built-in templating. Instead of creating or appending any elements, * {@link #createTemplate} returns a Template object which can be used over and over to * insert new elements. Revisiting the example above, we could utilize templating this time: *
// create the node
var list = dh.append('my-div', {tag: 'ul', cls: 'my-list'});
// get template
var tpl = dh.createTemplate({tag: 'li', id: 'item{0}', html: 'List Item {0}'});
for(var i = 0; i < 5, i++){
tpl.append(list, [i]); // use template to append to the actual node
}
*
* An example using a template:
var html = '{2}';
var tpl = new Ext.DomHelper.createTemplate(html);
tpl.append('blog-roll', ['link1', 'http://www.edspencer.net/', "Ed's Site"]);
tpl.append('blog-roll', ['link2', 'http://www.dustindiaz.com/', "Dustin's Site"]);
*
*
* The same example using named parameters:
var html = '{text}';
var tpl = new Ext.DomHelper.createTemplate(html);
tpl.append('blog-roll', {
id: 'link1',
url: 'http://www.edspencer.net/',
text: "Ed's Site"
});
tpl.append('blog-roll', {
id: 'link2',
url: 'http://www.dustindiaz.com/',
text: "Dustin's Site"
});
*
*
* Compiling Templates
*Templates are applied using regular expressions. The performance is great, but if * you are adding a bunch of DOM elements using the same template, you can increase * performance even further by {@link Ext.Template#compile "compiling"} the template. * The way "{@link Ext.Template#compile compile()}" works is the template is parsed and * broken up at the different variable points and a dynamic function is created and eval'ed. * The generated function performs string concatenation of these parts and the passed * variables instead of using regular expressions. *
var html = '{text}';
var tpl = new Ext.DomHelper.createTemplate(html);
tpl.compile();
//... use template like normal
*
*
* Performance Boost
*DomHelper will transparently create HTML fragments when it can. Using HTML fragments instead * of DOM can significantly boost performance.
*Element creation specification parameters may also be strings. If {@link #useDom} is false, * then the string is used as innerHTML. If {@link #useDom} is true, a string specification * results in the creation of a text node. Usage:
*
Ext.DomHelper.useDom = true; // force it to use DOM; reduces performance
*
* @singleton
*/
Ext.ns('Ext.core');
Ext.core.DomHelper = Ext.DomHelper = function(){
var tempTableEl = null,
emptyTags = /^(?:br|frame|hr|img|input|link|meta|range|spacer|wbr|area|param|col)$/i,
tableRe = /^table|tbody|tr|td$/i,
confRe = /tag|children|cn|html$/i,
tableElRe = /td|tr|tbody/i,
endRe = /end/i,
pub,
// kill repeat to save bytes
afterbegin = 'afterbegin',
afterend = 'afterend',
beforebegin = 'beforebegin',
beforeend = 'beforeend',
ts = 'DomQuery supports most of the CSS3 selectors spec, along with some custom selectors and basic XPath.
All selectors, attribute filters and pseudos below can be combined infinitely in any order. For example "div.foo:nth-child(odd)[@foo=bar].bar:first" would be a perfectly valid selector. Node filters are processed in the order in which they appear, which allows you to optimize your queries for your document structure.
The use of @ and quotes are optional. For example, div[@foo='bar'] is also a valid attribute selector.
paragraph one
*paragraph two
*paragraph three
*
// change the height to 200px and animate with default configuration
Ext.fly('elementId').setHeight(200, true);
// change the height to 150px and animate with a custom configuration
Ext.fly('elId').setHeight(150, {
duration : .5, // animation will have a duration of .5 seconds
// will change the content to "finished"
callback: function(){ this.{@link #update}("finished"); }
});
*
* @param {Number/String} height The new height. This may be one of:Wraps the specified element with a special 9 element markup/CSS block that renders by default as * a gray container with a gradient background, rounded corners and a 4-way shadow.
*This special markup is used throughout Ext when box wrapping elements ({@link Ext.button.Button}, * {@link Ext.panel.Panel} when {@link Ext.panel.Panel#frame frame=true}, {@link Ext.window.Window}). The markup * is of this form:
*
Ext.Element.boxMarkup =
'<div class="{0}-tl"><div class="{0}-tr"><div class="{0}-tc"></div></div></div>
<div class="{0}-ml"><div class="{0}-mr"><div class="{0}-mc"></div></div></div>
<div class="{0}-bl"><div class="{0}-br"><div class="{0}-bc"></div></div></div>';
*
* Example usage:
*
// Basic box wrap
Ext.get("foo").boxWrap();
// You can also add a custom class and use CSS inheritance rules to customize the box look.
// 'x-box-blue' is a built-in alternative -- look at the related CSS definitions as an example
// for how to create a custom box wrap style.
Ext.get("foo").boxWrap().addCls("x-box-blue");
*
* @param {String} class (optional) A base CSS class to apply to the containing wrapper element
* (defaults to 'x-box'). Note that there are a number of CSS rules that are dependent on
* this name to make the overall effect work, so if you supply an alternate base class, make sure you
* also supply all of the necessary rules.
* @return {Ext.Element} The outermost wrapping element of the created box structure.
*/
boxWrap : function(cls){
cls = cls || Ext.baseCSSPrefix + 'box';
var el = Ext.get(this.insertHtml("beforeBegin", "{width: widthValue, height: heightValue}
.Returns the dimensions of the element available to lay content out in.
*
If the element (or any ancestor element) has CSS style display : none
, the dimensions will be zero.
var vpSize = Ext.getBody().getViewSize();
// all Windows created afterwards will have a default value of 90% height and 95% width
Ext.Window.override({
width: vpSize.width * 0.9,
height: vpSize.height * 0.95
});
// To handle window resizing you would have to hook onto onWindowResize.
*
*
* getViewSize utilizes clientHeight/clientWidth which excludes sizing of scrollbars.
* To obtain the size including scrollbars, use getStyleSize
*
* Sizing of the document body is handled at the adapter level which handles special cases for IE and strict modes, etc.
*/
getViewSize : function(){
var me = this,
dom = me.dom,
isDoc = (dom == Ext.getDoc().dom || dom == Ext.getBody().dom),
style, overflow, ret;
// If the body, use static methods
if (isDoc) {
ret = {
width : ELEMENT.getViewWidth(),
height : ELEMENT.getViewHeight()
};
// Else use clientHeight/clientWidth
}
else {
// IE 6 & IE Quirks mode acts more like a max-size measurement unless overflow is hidden during measurement.
// We will put the overflow back to it's original value when we are done measuring.
if (Ext.isIE6 || Ext.isIEQuirks) {
style = dom.style;
overflow = style.overflow;
me.setStyle({ overflow: 'hidden'});
}
ret = {
width : dom.clientWidth,
height : dom.clientHeight
};
if (Ext.isIE6 || Ext.isIEQuirks) {
me.setStyle({ overflow: overflow });
}
}
return ret;
},
/**
* Returns the dimensions of the element available to lay content out in.
* * getStyleSize utilizes prefers style sizing if present, otherwise it chooses the larger of offsetHeight/clientHeight and offsetWidth/clientWidth. * To obtain the size excluding scrollbars, use getViewSize * * Sizing of the document body is handled at the adapter level which handles special cases for IE and strict modes, etc. */ getStyleSize : function(){ var me = this, doc = document, d = this.dom, isDoc = (d == doc || d == doc.body), s = d.style, w, h; // If the body, use static methods if (isDoc) { return { width : ELEMENT.getViewWidth(), height : ELEMENT.getViewHeight() }; } // Use Styles if they are set if(s.width && s.width != 'auto'){ w = parseFloat(s.width); if(me.isBorderBox()){ w -= me.getFrameWidth('lr'); } } // Use Styles if they are set if(s.height && s.height != 'auto'){ h = parseFloat(s.height); if(me.isBorderBox()){ h -= me.getFrameWidth('tb'); } } // Use getWidth/getHeight if style not set. return {width: w || me.getWidth(true), height: h || me.getHeight(true)}; }, /** * Returns the size of the element. * @param {Boolean} contentSize (optional) true to get the width/size minus borders and padding * @return {Object} An object containing the element's size {width: (element width), height: (element height)} */ getSize : function(contentSize){ return {width: this.getWidth(contentSize), height: this.getHeight(contentSize)}; }, /** * Forces the browser to repaint this element * @return {Ext.Element} this */ repaint : function(){ var dom = this.dom; this.addCls(Ext.baseCSSPrefix + 'repaint'); setTimeout(function(){ Ext.fly(dom).removeCls(Ext.baseCSSPrefix + 'repaint'); }, 1); return this; }, /** * Enable text selection for this element (normalized across browsers) * @return {Ext.Element} this */ selectable : function() { var me = this; me.dom.unselectable = "off"; // Prevent it from bubles up and enables it to be selectable me.on('selectstart', function (e) { e.stopPropagation(); return true; }); me.applyStyles("-moz-user-select: text; -khtml-user-select: text;"); me.removeCls(Ext.baseCSSPrefix + 'unselectable'); return me; }, /** * Disables text selection for this element (normalized across browsers) * @return {Ext.Element} this */ unselectable : function(){ var me = this; me.dom.unselectable = "on"; me.swallowEvent("selectstart", true); me.applyStyles("-moz-user-select:-moz-none;-khtml-user-select:none;"); me.addCls(Ext.baseCSSPrefix + 'unselectable'); return me; }, /** * Returns an object with properties top, left, right and bottom representing the margins of this element unless sides is passed, * then it returns the calculated width of the sides (see getPadding) * @param {String} sides (optional) Any combination of l, r, t, b to get the sum of those sides * @return {Object/Number} */ getMargin : function(side){ var me = this, hash = {t:"top", l:"left", r:"right", b: "bottom"}, o = {}, key; if (!side) { for (key in me.margins){ o[hash[key]] = parseFloat(me.getStyle(me.margins[key])) || 0; } return o; } else { return me.addStyles.call(me, side, me.margins); } } }); })(); /** * @class Ext.Element */ /** * Visibility mode constant for use with {@link #setVisibilityMode}. Use visibility to hide element * @static * @type Number */ Ext.Element.VISIBILITY = 1; /** * Visibility mode constant for use with {@link #setVisibilityMode}. Use display to hide element * @static * @type Number */ Ext.Element.DISPLAY = 2; /** * Visibility mode constant for use with {@link #setVisibilityMode}. Use offsets (x and y positioning offscreen) * to hide element. * @static * @type Number */ Ext.Element.OFFSETS = 3; Ext.Element.ASCLASS = 4; /** * Defaults to 'x-hide-nosize' * @static * @type String */ Ext.Element.visibilityCls = Ext.baseCSSPrefix + 'hide-nosize'; Ext.Element.addMethods(function(){ var El = Ext.Element, OPACITY = "opacity", VISIBILITY = "visibility", DISPLAY = "display", HIDDEN = "hidden", OFFSETS = "offsets", ASCLASS = "asclass", NONE = "none", NOSIZE = 'nosize', ORIGINALDISPLAY = 'originalDisplay', VISMODE = 'visibilityMode', ISVISIBLE = 'isVisible', data = El.data, getDisplay = function(dom){ var d = data(dom, ORIGINALDISPLAY); if(d === undefined){ data(dom, ORIGINALDISPLAY, d = ''); } return d; }, getVisMode = function(dom){ var m = data(dom, VISMODE); if(m === undefined){ data(dom, VISMODE, m = 1); } return m; }; return { /** * @property {String} originalDisplay * The element's default display mode */ originalDisplay : "", visibilityMode : 1, /** * Sets the element's visibility mode. When setVisible() is called it * will use this to determine whether to set the visibility or the display property. * @param {Number} visMode Ext.Element.VISIBILITY or Ext.Element.DISPLAY * @return {Ext.Element} this */ setVisibilityMode : function(visMode){ data(this.dom, VISMODE, visMode); return this; }, /** * Checks whether the element is currently visible using both visibility and display properties. * @return {Boolean} True if the element is currently visible, else false */ isVisible : function() { var me = this, dom = me.dom, visible = data(dom, ISVISIBLE); if(typeof visible == 'boolean'){ //return the cached value if registered return visible; } //Determine the current state based on display states visible = !me.isStyle(VISIBILITY, HIDDEN) && !me.isStyle(DISPLAY, NONE) && !((getVisMode(dom) == El.ASCLASS) && me.hasCls(me.visibilityCls || El.visibilityCls)); data(dom, ISVISIBLE, visible); return visible; }, /** * Sets the visibility of the element (see details). If the visibilityMode is set to Element.DISPLAY, it will use * the display property to hide the element, otherwise it uses visibility. The default is to hide and show using the visibility property. * @param {Boolean} visible Whether the element is visible * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object * @return {Ext.Element} this */ setVisible : function(visible, animate){ var me = this, isDisplay, isVisibility, isOffsets, isNosize, dom = me.dom, visMode = getVisMode(dom); // hideMode string override if (typeof animate == 'string'){ switch (animate) { case DISPLAY: visMode = El.DISPLAY; break; case VISIBILITY: visMode = El.VISIBILITY; break; case OFFSETS: visMode = El.OFFSETS; break; case NOSIZE: case ASCLASS: visMode = El.ASCLASS; break; } me.setVisibilityMode(visMode); animate = false; } if (!animate || !me.anim) { if(visMode == El.ASCLASS ){ me[visible?'removeCls':'addCls'](me.visibilityCls || El.visibilityCls); } else if (visMode == El.DISPLAY){ return me.setDisplayed(visible); } else if (visMode == El.OFFSETS){ if (!visible){ // Remember position for restoring, if we are not already hidden by offsets. if (!me.hideModeStyles) { me.hideModeStyles = { position: me.getStyle('position'), top: me.getStyle('top'), left: me.getStyle('left') }; } me.applyStyles({position: 'absolute', top: '-10000px', left: '-10000px'}); } // Only "restore" as position if we have actually been hidden using offsets. // Calling setVisible(true) on a positioned element should not reposition it. else if (me.hideModeStyles) { me.applyStyles(me.hideModeStyles || {position: '', top: '', left: ''}); delete me.hideModeStyles; } }else{ me.fixDisplay(); // Show by clearing visibility style. Explicitly setting to "visible" overrides parent visibility setting. dom.style.visibility = visible ? '' : HIDDEN; } }else{ // closure for composites if(visible){ me.setOpacity(0.01); me.setVisible(true); } if (!Ext.isObject(animate)) { animate = { duration: 350, easing: 'ease-in' }; } me.animate(Ext.applyIf({ callback: function() { visible || me.setVisible(false).setOpacity(1); }, to: { opacity: (visible) ? 1 : 0 } }, animate)); } data(dom, ISVISIBLE, visible); //set logical visibility state return me; }, /** * @private * Determine if the Element has a relevant height and width available based * upon current logical visibility state */ hasMetrics : function(){ var dom = this.dom; return this.isVisible() || (getVisMode(dom) == El.OFFSETS) || (getVisMode(dom) == El.VISIBILITY); }, /** * Toggles the element's visibility or display, depending on visibility mode. * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object * @return {Ext.Element} this */ toggle : function(animate){ var me = this; me.setVisible(!me.isVisible(), me.anim(animate)); return me; }, /** * Sets the CSS display property. Uses originalDisplay if the specified value is a boolean true. * @param {Boolean/String} value Boolean value to display the element using its default display, or a string to set the display directly. * @return {Ext.Element} this */ setDisplayed : function(value) { if(typeof value == "boolean"){ value = value ? getDisplay(this.dom) : NONE; } this.setStyle(DISPLAY, value); return this; }, // private fixDisplay : function(){ var me = this; if (me.isStyle(DISPLAY, NONE)) { me.setStyle(VISIBILITY, HIDDEN); me.setStyle(DISPLAY, getDisplay(this.dom)); // first try reverting to default if (me.isStyle(DISPLAY, NONE)) { // if that fails, default to block me.setStyle(DISPLAY, "block"); } } }, /** * Hide this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object * @return {Ext.Element} this */ hide : function(animate){ // hideMode override if (typeof animate == 'string'){ this.setVisible(false, animate); return this; } this.setVisible(false, this.anim(animate)); return this; }, /** * Show this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object * @return {Ext.Element} this */ show : function(animate){ // hideMode override if (typeof animate == 'string'){ this.setVisible(true, animate); return this; } this.setVisible(true, this.anim(animate)); return this; } }; }()); /** * @class Ext.Element */ Ext.applyIf(Ext.Element.prototype, { // @private override base Ext.util.Animate mixin for animate for backwards compatibility animate: function(config) { var me = this; if (!me.id) { me = Ext.get(me.dom); } if (Ext.fx.Manager.hasFxBlock(me.id)) { return me; } Ext.fx.Manager.queueFx(Ext.create('Ext.fx.Anim', me.anim(config))); return this; }, // @private override base Ext.util.Animate mixin for animate for backwards compatibility anim: function(config) { if (!Ext.isObject(config)) { return (config) ? {} : false; } var me = this, duration = config.duration || Ext.fx.Anim.prototype.duration, easing = config.easing || 'ease', animConfig; if (config.stopAnimation) { me.stopAnimation(); } Ext.applyIf(config, Ext.fx.Manager.getFxDefaults(me.id)); // Clear any 'paused' defaults. Ext.fx.Manager.setFxDefaults(me.id, { delay: 0 }); animConfig = { target: me, remove: config.remove, alternate: config.alternate || false, duration: duration, easing: easing, callback: config.callback, listeners: config.listeners, iterations: config.iterations || 1, scope: config.scope, block: config.block, concurrent: config.concurrent, delay: config.delay || 0, paused: true, keyframes: config.keyframes, from: config.from || {}, to: Ext.apply({}, config) }; Ext.apply(animConfig.to, config.to); // Anim API properties - backward compat delete animConfig.to.to; delete animConfig.to.from; delete animConfig.to.remove; delete animConfig.to.alternate; delete animConfig.to.keyframes; delete animConfig.to.iterations; delete animConfig.to.listeners; delete animConfig.to.target; delete animConfig.to.paused; delete animConfig.to.callback; delete animConfig.to.scope; delete animConfig.to.duration; delete animConfig.to.easing; delete animConfig.to.concurrent; delete animConfig.to.block; delete animConfig.to.stopAnimation; delete animConfig.to.delay; return animConfig; }, /** * Slides the element into view. An anchor point can be optionally passed to set the point of origin for the slide * effect. This function automatically handles wrapping the element with a fixed-size container if needed. See the * Fx class overview for valid anchor point options. Usage: * * // default: slide the element in from the top * el.slideIn(); * * // custom: slide the element in from the right with a 2-second duration * el.slideIn('r', { duration: 2000 }); * * // common config options shown with default values * el.slideIn('t', { * easing: 'easeOut', * duration: 500 * }); * * @param {String} [anchor='t'] One of the valid Fx anchor positions * @param {Object} [options] Object literal with any of the Fx config options * @return {Ext.Element} The Element */ slideIn: function(anchor, obj, slideOut) { var me = this, elStyle = me.dom.style, beforeAnim, wrapAnim; anchor = anchor || "t"; obj = obj || {}; beforeAnim = function() { var animScope = this, listeners = obj.listeners, box, position, restoreSize, wrap, anim; if (!slideOut) { me.fixDisplay(); } box = me.getBox(); if ((anchor == 't' || anchor == 'b') && box.height === 0) { box.height = me.dom.scrollHeight; } else if ((anchor == 'l' || anchor == 'r') && box.width === 0) { box.width = me.dom.scrollWidth; } position = me.getPositioning(); me.setSize(box.width, box.height); wrap = me.wrap({ style: { visibility: slideOut ? 'visible' : 'hidden' } }); wrap.setPositioning(position); if (wrap.isStyle('position', 'static')) { wrap.position('relative'); } me.clearPositioning('auto'); wrap.clip(); // This element is temporarily positioned absolute within its wrapper. // Restore to its default, CSS-inherited visibility setting. // We cannot explicitly poke visibility:visible into its style because that overrides the visibility of the wrap. me.setStyle({ visibility: '', position: 'absolute' }); if (slideOut) { wrap.setSize(box.width, box.height); } switch (anchor) { case 't': anim = { from: { width: box.width + 'px', height: '0px' }, to: { width: box.width + 'px', height: box.height + 'px' } }; elStyle.bottom = '0px'; break; case 'l': anim = { from: { width: '0px', height: box.height + 'px' }, to: { width: box.width + 'px', height: box.height + 'px' } }; elStyle.right = '0px'; break; case 'r': anim = { from: { x: box.x + box.width, width: '0px', height: box.height + 'px' }, to: { x: box.x, width: box.width + 'px', height: box.height + 'px' } }; break; case 'b': anim = { from: { y: box.y + box.height, width: box.width + 'px', height: '0px' }, to: { y: box.y, width: box.width + 'px', height: box.height + 'px' } }; break; case 'tl': anim = { from: { x: box.x, y: box.y, width: '0px', height: '0px' }, to: { width: box.width + 'px', height: box.height + 'px' } }; elStyle.bottom = '0px'; elStyle.right = '0px'; break; case 'bl': anim = { from: { x: box.x + box.width, width: '0px', height: '0px' }, to: { x: box.x, width: box.width + 'px', height: box.height + 'px' } }; elStyle.right = '0px'; break; case 'br': anim = { from: { x: box.x + box.width, y: box.y + box.height, width: '0px', height: '0px' }, to: { x: box.x, y: box.y, width: box.width + 'px', height: box.height + 'px' } }; break; case 'tr': anim = { from: { y: box.y + box.height, width: '0px', height: '0px' }, to: { y: box.y, width: box.width + 'px', height: box.height + 'px' } }; elStyle.bottom = '0px'; break; } wrap.show(); wrapAnim = Ext.apply({}, obj); delete wrapAnim.listeners; wrapAnim = Ext.create('Ext.fx.Anim', Ext.applyIf(wrapAnim, { target: wrap, duration: 500, easing: 'ease-out', from: slideOut ? anim.to : anim.from, to: slideOut ? anim.from : anim.to })); // In the absence of a callback, this listener MUST be added first wrapAnim.on('afteranimate', function() { if (slideOut) { me.setPositioning(position); if (obj.useDisplay) { me.setDisplayed(false); } else { me.hide(); } } else { me.clearPositioning(); me.setPositioning(position); } if (wrap.dom) { wrap.dom.parentNode.insertBefore(me.dom, wrap.dom); wrap.remove(); } me.setSize(box.width, box.height); animScope.end(); }); // Add configured listeners after if (listeners) { wrapAnim.on(listeners); } }; me.animate({ duration: obj.duration ? obj.duration * 2 : 1000, listeners: { beforeanimate: { fn: beforeAnim }, afteranimate: { fn: function() { if (wrapAnim && wrapAnim.running) { wrapAnim.end(); } } } } }); return me; }, /** * Slides the element out of view. An anchor point can be optionally passed to set the end point for the slide * effect. When the effect is completed, the element will be hidden (visibility = 'hidden') but block elements will * still take up space in the document. The element must be removed from the DOM using the 'remove' config option if * desired. This function automatically handles wrapping the element with a fixed-size container if needed. See the * Fx class overview for valid anchor point options. Usage: * * // default: slide the element out to the top * el.slideOut(); * * // custom: slide the element out to the right with a 2-second duration * el.slideOut('r', { duration: 2000 }); * * // common config options shown with default values * el.slideOut('t', { * easing: 'easeOut', * duration: 500, * remove: false, * useDisplay: false * }); * * @param {String} [anchor='t'] One of the valid Fx anchor positions * @param {Object} [options] Object literal with any of the Fx config options * @return {Ext.Element} The Element */ slideOut: function(anchor, o) { return this.slideIn(anchor, o, true); }, /** * Fades the element out while slowly expanding it in all directions. When the effect is completed, the element will * be hidden (visibility = 'hidden') but block elements will still take up space in the document. Usage: * * // default * el.puff(); * * // common config options shown with default values * el.puff({ * easing: 'easeOut', * duration: 500, * useDisplay: false * }); * * @param {Object} options (optional) Object literal with any of the Fx config options * @return {Ext.Element} The Element */ puff: function(obj) { var me = this, beforeAnim; obj = Ext.applyIf(obj || {}, { easing: 'ease-out', duration: 500, useDisplay: false }); beforeAnim = function() { me.clearOpacity(); me.show(); var box = me.getBox(), fontSize = me.getStyle('fontSize'), position = me.getPositioning(); this.to = { width: box.width * 2, height: box.height * 2, x: box.x - (box.width / 2), y: box.y - (box.height /2), opacity: 0, fontSize: '200%' }; this.on('afteranimate',function() { if (me.dom) { if (obj.useDisplay) { me.setDisplayed(false); } else { me.hide(); } me.clearOpacity(); me.setPositioning(position); me.setStyle({fontSize: fontSize}); } }); }; me.animate({ duration: obj.duration, easing: obj.easing, listeners: { beforeanimate: { fn: beforeAnim } } }); return me; }, /** * Blinks the element as if it was clicked and then collapses on its center (similar to switching off a television). * When the effect is completed, the element will be hidden (visibility = 'hidden') but block elements will still * take up space in the document. The element must be removed from the DOM using the 'remove' config option if * desired. Usage: * * // default * el.switchOff(); * * // all config options shown with default values * el.switchOff({ * easing: 'easeIn', * duration: .3, * remove: false, * useDisplay: false * }); * * @param {Object} options (optional) Object literal with any of the Fx config options * @return {Ext.Element} The Element */ switchOff: function(obj) { var me = this, beforeAnim; obj = Ext.applyIf(obj || {}, { easing: 'ease-in', duration: 500, remove: false, useDisplay: false }); beforeAnim = function() { var animScope = this, size = me.getSize(), xy = me.getXY(), keyframe, position; me.clearOpacity(); me.clip(); position = me.getPositioning(); keyframe = Ext.create('Ext.fx.Animator', { target: me, duration: obj.duration, easing: obj.easing, keyframes: { 33: { opacity: 0.3 }, 66: { height: 1, y: xy[1] + size.height / 2 }, 100: { width: 1, x: xy[0] + size.width / 2 } } }); keyframe.on('afteranimate', function() { if (obj.useDisplay) { me.setDisplayed(false); } else { me.hide(); } me.clearOpacity(); me.setPositioning(position); me.setSize(size); animScope.end(); }); }; me.animate({ duration: (obj.duration * 2), listeners: { beforeanimate: { fn: beforeAnim } } }); return me; }, /** * Shows a ripple of exploding, attenuating borders to draw attention to an Element. Usage: * * // default: a single light blue ripple * el.frame(); * * // custom: 3 red ripples lasting 3 seconds total * el.frame("#ff0000", 3, { duration: 3 }); * * // common config options shown with default values * el.frame("#C3DAF9", 1, { * duration: 1 //duration of each individual ripple. * // Note: Easing is not configurable and will be ignored if included * }); * * @param {String} [color='C3DAF9'] The color of the border. Should be a 6 char hex color without the leading # * (defaults to light blue). * @param {Number} [count=1] The number of ripples to display * @param {Object} [options] Object literal with any of the Fx config options * @return {Ext.Element} The Element */ frame : function(color, count, obj){ var me = this, beforeAnim; color = color || '#C3DAF9'; count = count || 1; obj = obj || {}; beforeAnim = function() { me.show(); var animScope = this, box = me.getBox(), proxy = Ext.getBody().createChild({ style: { position : 'absolute', 'pointer-events': 'none', 'z-index': 35000, border : '0px solid ' + color } }), proxyAnim; proxyAnim = Ext.create('Ext.fx.Anim', { target: proxy, duration: obj.duration || 1000, iterations: count, from: { top: box.y, left: box.x, borderWidth: 0, opacity: 1, height: box.height, width: box.width }, to: { top: box.y - 20, left: box.x - 20, borderWidth: 10, opacity: 0, height: box.height + 40, width: box.width + 40 } }); proxyAnim.on('afteranimate', function() { proxy.remove(); animScope.end(); }); }; me.animate({ duration: (obj.duration * 2) || 2000, listeners: { beforeanimate: { fn: beforeAnim } } }); return me; }, /** * Slides the element while fading it out of view. An anchor point can be optionally passed to set the ending point * of the effect. Usage: * * // default: slide the element downward while fading out * el.ghost(); * * // custom: slide the element out to the right with a 2-second duration * el.ghost('r', { duration: 2000 }); * * // common config options shown with default values * el.ghost('b', { * easing: 'easeOut', * duration: 500 * }); * * @param {String} [anchor='b'] One of the valid Fx anchor positions * @param {Object} [options] Object literal with any of the Fx config options * @return {Ext.Element} The Element */ ghost: function(anchor, obj) { var me = this, beforeAnim; anchor = anchor || "b"; beforeAnim = function() { var width = me.getWidth(), height = me.getHeight(), xy = me.getXY(), position = me.getPositioning(), to = { opacity: 0 }; switch (anchor) { case 't': to.y = xy[1] - height; break; case 'l': to.x = xy[0] - width; break; case 'r': to.x = xy[0] + width; break; case 'b': to.y = xy[1] + height; break; case 'tl': to.x = xy[0] - width; to.y = xy[1] - height; break; case 'bl': to.x = xy[0] - width; to.y = xy[1] + height; break; case 'br': to.x = xy[0] + width; to.y = xy[1] + height; break; case 'tr': to.x = xy[0] + width; to.y = xy[1] - height; break; } this.to = to; this.on('afteranimate', function () { if (me.dom) { me.hide(); me.clearOpacity(); me.setPositioning(position); } }); }; me.animate(Ext.applyIf(obj || {}, { duration: 500, easing: 'ease-out', listeners: { beforeanimate: { fn: beforeAnim } } })); return me; }, /** * Highlights the Element by setting a color (applies to the background-color by default, but can be changed using * the "attr" config option) and then fading back to the original color. If no original color is available, you * should provide the "endColor" config option which will be cleared after the animation. Usage: * * // default: highlight background to yellow * el.highlight(); * * // custom: highlight foreground text to blue for 2 seconds * el.highlight("0000ff", { attr: 'color', duration: 2000 }); * * // common config options shown with default values * el.highlight("ffff9c", { * attr: "backgroundColor", //can be any valid CSS property (attribute) that supports a color value * endColor: (current color) or "ffffff", * easing: 'easeIn', * duration: 1000 * }); * * @param {String} [color='ffff9c'] The highlight color. Should be a 6 char hex color without the leading # * @param {Object} [options] Object literal with any of the Fx config options * @return {Ext.Element} The Element */ highlight: function(color, o) { var me = this, dom = me.dom, from = {}, restore, to, attr, lns, event, fn; o = o || {}; lns = o.listeners || {}; attr = o.attr || 'backgroundColor'; from[attr] = color || 'ffff9c'; if (!o.to) { to = {}; to[attr] = o.endColor || me.getColor(attr, 'ffffff', ''); } else { to = o.to; } // Don't apply directly on lns, since we reference it in our own callbacks below o.listeners = Ext.apply(Ext.apply({}, lns), { beforeanimate: function() { restore = dom.style[attr]; me.clearOpacity(); me.show(); event = lns.beforeanimate; if (event) { fn = event.fn || event; return fn.apply(event.scope || lns.scope || window, arguments); } }, afteranimate: function() { if (dom) { dom.style[attr] = restore; } event = lns.afteranimate; if (event) { fn = event.fn || event; fn.apply(event.scope || lns.scope || window, arguments); } } }); me.animate(Ext.apply({}, o, { duration: 1000, easing: 'ease-in', from: from, to: to })); return me; }, /** * @deprecated 4.0 * Creates a pause before any subsequent queued effects begin. If there are no effects queued after the pause it will * have no effect. Usage: * * el.pause(1); * * @param {Number} seconds The length of time to pause (in seconds) * @return {Ext.Element} The Element */ pause: function(ms) { var me = this; Ext.fx.Manager.setFxDefaults(me.id, { delay: ms }); return me; }, /** * Fade an element in (from transparent to opaque). The ending opacity can be specified using the `opacity` * config option. Usage: * * // default: fade in from opacity 0 to 100% * el.fadeIn(); * * // custom: fade in from opacity 0 to 75% over 2 seconds * el.fadeIn({ opacity: .75, duration: 2000}); * * // common config options shown with default values * el.fadeIn({ * opacity: 1, //can be any value between 0 and 1 (e.g. .5) * easing: 'easeOut', * duration: 500 * }); * * @param {Object} options (optional) Object literal with any of the Fx config options * @return {Ext.Element} The Element */ fadeIn: function(o) { this.animate(Ext.apply({}, o, { opacity: 1 })); return this; }, /** * Fade an element out (from opaque to transparent). The ending opacity can be specified using the `opacity` * config option. Note that IE may require `useDisplay:true` in order to redisplay correctly. * Usage: * * // default: fade out from the element's current opacity to 0 * el.fadeOut(); * * // custom: fade out from the element's current opacity to 25% over 2 seconds * el.fadeOut({ opacity: .25, duration: 2000}); * * // common config options shown with default values * el.fadeOut({ * opacity: 0, //can be any value between 0 and 1 (e.g. .5) * easing: 'easeOut', * duration: 500, * remove: false, * useDisplay: false * }); * * @param {Object} options (optional) Object literal with any of the Fx config options * @return {Ext.Element} The Element */ fadeOut: function(o) { this.animate(Ext.apply({}, o, { opacity: 0 })); return this; }, /** * @deprecated 4.0 * Animates the transition of an element's dimensions from a starting height/width to an ending height/width. This * method is a convenience implementation of {@link #shift}. Usage: * * // change height and width to 100x100 pixels * el.scale(100, 100); * * // common config options shown with default values. The height and width will default to * // the element's existing values if passed as null. * el.scale( * [element's width], * [element's height], { * easing: 'easeOut', * duration: .35 * } * ); * * @param {Number} width The new width (pass undefined to keep the original width) * @param {Number} height The new height (pass undefined to keep the original height) * @param {Object} options (optional) Object literal with any of the Fx config options * @return {Ext.Element} The Element */ scale: function(w, h, o) { this.animate(Ext.apply({}, o, { width: w, height: h })); return this; }, /** * @deprecated 4.0 * Animates the transition of any combination of an element's dimensions, xy position and/or opacity. Any of these * properties not specified in the config object will not be changed. This effect requires that at least one new * dimension, position or opacity setting must be passed in on the config object in order for the function to have * any effect. Usage: * * // slide the element horizontally to x position 200 while changing the height and opacity * el.shift({ x: 200, height: 50, opacity: .8 }); * * // common config options shown with default values. * el.shift({ * width: [element's width], * height: [element's height], * x: [element's x position], * y: [element's y position], * opacity: [element's opacity], * easing: 'easeOut', * duration: .35 * }); * * @param {Object} options Object literal with any of the Fx config options * @return {Ext.Element} The Element */ shift: function(config) { this.animate(config); return this; } }); /** * @class Ext.Element */ Ext.applyIf(Ext.Element, { unitRe: /\d+(px|em|%|en|ex|pt|in|cm|mm|pc)$/i, camelRe: /(-[a-z])/gi, opacityRe: /alpha\(opacity=(.*)\)/i, cssRe: /([a-z0-9-]+)\s*:\s*([^;\s]+(?:\s*[^;\s]+)*);?/gi, propertyCache: {}, defaultUnit : "px", borders: {l: 'border-left-width', r: 'border-right-width', t: 'border-top-width', b: 'border-bottom-width'}, paddings: {l: 'padding-left', r: 'padding-right', t: 'padding-top', b: 'padding-bottom'}, margins: {l: 'margin-left', r: 'margin-right', t: 'margin-top', b: 'margin-bottom'}, // Reference the prototype's version of the method. Signatures are identical. addUnits : Ext.Element.prototype.addUnits, /** * Parses a number or string representing margin sizes into an object. Supports CSS-style margin declarations * (e.g. 10, "10", "10 10", "10 10 10" and "10 10 10 10" are all valid options and would return the same result) * @static * @param {Number/String} box The encoded margins * @return {Object} An object with margin sizes for top, right, bottom and left */ parseBox : function(box) { if (Ext.isObject(box)) { return { top: box.top || 0, right: box.right || 0, bottom: box.bottom || 0, left: box.left || 0 }; } else { if (typeof box != 'string') { box = box.toString(); } var parts = box.split(' '), ln = parts.length; if (ln == 1) { parts[1] = parts[2] = parts[3] = parts[0]; } else if (ln == 2) { parts[2] = parts[0]; parts[3] = parts[1]; } else if (ln == 3) { parts[3] = parts[1]; } return { top :parseFloat(parts[0]) || 0, right :parseFloat(parts[1]) || 0, bottom:parseFloat(parts[2]) || 0, left :parseFloat(parts[3]) || 0 }; } }, /** * Parses a number or string representing margin sizes into an object. Supports CSS-style margin declarations * (e.g. 10, "10", "10 10", "10 10 10" and "10 10 10 10" are all valid options and would return the same result) * @static * @param {Number/String} box The encoded margins * @param {String} units The type of units to add * @return {String} An string with unitized (px if units is not specified) metrics for top, right, bottom and left */ unitizeBox : function(box, units) { var A = this.addUnits, B = this.parseBox(box); return A(B.top, units) + ' ' + A(B.right, units) + ' ' + A(B.bottom, units) + ' ' + A(B.left, units); }, // private camelReplaceFn : function(m, a) { return a.charAt(1).toUpperCase(); }, /** * Normalizes CSS property keys from dash delimited to camel case JavaScript Syntax. * For example: *
* The sample code below would return an object with 2 properties, one * for background-color and one for color.
*
var css = 'background-color: red;color: blue; ';
console.log(Ext.Element.parseStyles(css));
*
* @static
* @param {String} styles A CSS string
* @return {Object} styles
*/
parseStyles: function(styles){
var out = {},
cssRe = this.cssRe,
matches;
if (styles) {
// Since we're using the g flag on the regex, we need to set the lastIndex.
// This automatically happens on some implementations, but not others, see:
// http://stackoverflow.com/questions/2645273/javascript-regular-expression-literal-persists-between-function-calls
// http://blog.stevenlevithan.com/archives/fixing-javascript-regexp
cssRe.lastIndex = 0;
while ((matches = cssRe.exec(styles))) {
out[matches[1]] = matches[2];
}
}
return out;
}
});
/**
* @class Ext.CompositeElementLite
* This class encapsulates a collection of DOM elements, providing methods to filter * members, or to perform collective actions upon the whole set.
*Although they are not listed, this class supports all of the methods of {@link Ext.Element} and * {@link Ext.fx.Anim}. The methods from these classes will be performed on all the elements in this collection.
* Example:
var els = Ext.select("#some-el div.some-class");
// or select directly from an existing element
var el = Ext.get('some-el');
el.select('div.some-class');
els.setWidth(100); // all elements become 100 width
els.hide(true); // all elements fade out and hide
// or
els.setWidth(100).hide(true);
*/
Ext.CompositeElementLite = function(els, root){
/**
* The Array of DOM elements which this CompositeElement encapsulates. Read-only.
*This will not usually be accessed in developers' code, but developers wishing * to augment the capabilities of the CompositeElementLite class may use it when adding * methods to the class.
*For example to add the nextAll
method to the class to add all
* following siblings of selected elements, the code would be
Ext.override(Ext.CompositeElementLite, {
nextAll: function() {
var els = this.elements, i, l = els.length, n, r = [], ri = -1;
// Loop through all elements in this Composite, accumulating
// an Array of all siblings.
for (i = 0; i < l; i++) {
for (n = els[i].nextSibling; n; n = n.nextSibling) {
r[++ri] = n;
}
}
// Add all found siblings to this Composite
return this.add(r);
}
});
* @property {HTMLElement} elements
*/
this.elements = [];
this.add(els, root);
this.el = new Ext.Element.Flyweight();
};
Ext.CompositeElementLite.prototype = {
isComposite: true,
// private
getElement : function(el){
// Set the shared flyweight dom property to the current element
var e = this.el;
e.dom = el;
e.id = el.id;
return e;
},
// private
transformElement : function(el){
return Ext.getDom(el);
},
/**
* Returns the number of elements in this Composite.
* @return Number
*/
getCount : function(){
return this.elements.length;
},
/**
* Adds elements to this Composite object.
* @param {HTMLElement[]/Ext.CompositeElement} els Either an Array of DOM elements to add, or another Composite object who's elements should be added.
* @return {Ext.CompositeElement} This Composite object.
*/
add : function(els, root){
var me = this,
elements = me.elements;
if(!els){
return this;
}
if(typeof els == "string"){
els = Ext.Element.selectorFunction(els, root);
}else if(els.isComposite){
els = els.elements;
}else if(!Ext.isIterable(els)){
els = [els];
}
for(var i = 0, len = els.length; i < len; ++i){
elements.push(me.transformElement(els[i]));
}
return me;
},
invoke : function(fn, args){
var me = this,
els = me.elements,
len = els.length,
e,
i;
for(i = 0; i < len; i++) {
e = els[i];
if(e){
Ext.Element.prototype[fn].apply(me.getElement(e), args);
}
}
return me;
},
/**
* Returns a flyweight Element of the dom element object at the specified index
* @param {Number} index
* @return {Ext.Element}
*/
item : function(index){
var me = this,
el = me.elements[index],
out = null;
if(el){
out = me.getElement(el);
}
return out;
},
// fixes scope with flyweight
addListener : function(eventName, handler, scope, opt){
var els = this.elements,
len = els.length,
i, e;
for(i = 0; iel
: Ext.Elementindex
: Numberthis
reference) in which the
* 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) {
var me = this,
id,
call = function() {
clearInterval(id);
id = null;
fn.apply(scope, args || []);
};
/**
* Cancels any pending timeout and queues a new one
* @param {Number} delay The milliseconds to delay
* @param {Function} newFn (optional) Overrides function passed to constructor
* @param {Object} newScope (optional) Overrides scope passed to constructor. Remember that if no scope
* is specified, this
will refer to the browser window.
* @param {Array} newArgs (optional) Overrides args passed to constructor
*/
this.delay = function(delay, newFn, newScope, newArgs) {
me.cancel();
fn = newFn || fn;
scope = newScope || scope;
args = newArgs || args;
id = setInterval(call, delay);
};
/**
* Cancel the last queued timeout
*/
this.cancel = function(){
if (id) {
clearInterval(id);
id = null;
}
};
};
Ext.require('Ext.util.DelayedTask', function() {
Ext.util.Event = Ext.extend(Object, (function() {
function createBuffered(handler, listener, o, scope) {
listener.task = new Ext.util.DelayedTask();
return function() {
listener.task.delay(o.buffer, handler, scope, Ext.Array.toArray(arguments));
};
}
function createDelayed(handler, listener, o, scope) {
return function() {
var task = new Ext.util.DelayedTask();
if (!listener.tasks) {
listener.tasks = [];
}
listener.tasks.push(task);
task.delay(o.delay || 10, handler, scope, Ext.Array.toArray(arguments));
};
}
function createSingle(handler, listener, o, scope) {
return function() {
listener.ev.removeListener(listener.fn, scope);
return handler.apply(scope, arguments);
};
}
return {
isEvent: true,
constructor: function(observable, name) {
this.name = name;
this.observable = observable;
this.listeners = [];
},
addListener: function(fn, scope, options) {
var me = this,
listener;
scope = scope || me.observable;
if (!me.isListening(fn, scope)) {
listener = me.createListener(fn, scope, options);
if (me.firing) {
// if we are currently firing this event, don't disturb the listener loop
me.listeners = me.listeners.slice(0);
}
me.listeners.push(listener);
}
},
createListener: function(fn, scope, o) {
o = o || {};
scope = scope || this.observable;
var listener = {
fn: fn,
scope: scope,
o: o,
ev: this
},
handler = fn;
// The order is important. The 'single' wrapper must be wrapped by the 'buffer' and 'delayed' wrapper
// because the event removal that the single listener does destroys the listener's DelayedTask(s)
if (o.single) {
handler = createSingle(handler, listener, o, scope);
}
if (o.delay) {
handler = createDelayed(handler, listener, o, scope);
}
if (o.buffer) {
handler = createBuffered(handler, listener, o, scope);
}
listener.fireFn = handler;
return listener;
},
findListener: function(fn, scope) {
var listeners = this.listeners,
i = listeners.length,
listener,
s;
while (i--) {
listener = listeners[i];
if (listener) {
s = listener.scope;
if (listener.fn == fn && (s == scope || s == this.observable)) {
return i;
}
}
}
return - 1;
},
isListening: function(fn, scope) {
return this.findListener(fn, scope) !== -1;
},
removeListener: function(fn, scope) {
var me = this,
index,
listener,
k;
index = me.findListener(fn, scope);
if (index != -1) {
listener = me.listeners[index];
if (me.firing) {
me.listeners = me.listeners.slice(0);
}
// cancel and remove a buffered handler that hasn't fired yet
if (listener.task) {
listener.task.cancel();
delete listener.task;
}
// cancel and remove all delayed handlers that haven't fired yet
k = listener.tasks && listener.tasks.length;
if (k) {
while (k--) {
listener.tasks[k].cancel();
}
delete listener.tasks;
}
// remove this listener from the listeners array
Ext.Array.erase(me.listeners, index, 1);
return true;
}
return false;
},
// Iterate to stop any buffered/delayed events
clearListeners: function() {
var listeners = this.listeners,
i = listeners.length;
while (i--) {
this.removeListener(listeners[i].fn, listeners[i].scope);
}
},
fire: function() {
var me = this,
listeners = me.listeners,
count = listeners.length,
i,
args,
listener;
if (count > 0) {
me.firing = true;
for (i = 0; i < count; i++) {
listener = listeners[i];
args = arguments.length ? Array.prototype.slice.call(arguments, 0) : [];
if (listener.o) {
args.push(listener.o);
}
if (listener && listener.fireFn.apply(listener.scope || me.observable, args) === false) {
return (me.firing = false);
}
}
}
me.firing = false;
return true;
}
};
})());
});
/**
* @class Ext.EventManager
* Registers event handlers that want to receive a normalized EventObject instead of the standard browser event and provides
* several useful events directly.
* See {@link Ext.EventObject} for more details on normalized event objects.
* @singleton
*/
Ext.EventManager = {
// --------------------- onReady ---------------------
/**
* Check if we have bound our global onReady listener
* @private
*/
hasBoundOnReady: false,
/**
* Check if fireDocReady has been called
* @private
*/
hasFiredReady: false,
/**
* Timer for the document ready event in old IE versions
* @private
*/
readyTimeout: null,
/**
* Checks if we have bound an onreadystatechange event
* @private
*/
hasOnReadyStateChange: false,
/**
* Holds references to any onReady functions
* @private
*/
readyEvent: new Ext.util.Event(),
/**
* Check the ready state for old IE versions
* @private
* @return {Boolean} True if the document is ready
*/
checkReadyState: function(){
var me = Ext.EventManager;
if(window.attachEvent){
// See here for reference: http://javascript.nwbox.com/IEContentLoaded/
// licensed courtesy of http://developer.yahoo.com/yui/license.html
if (window != top) {
return false;
}
try{
document.documentElement.doScroll('left');
}catch(e){
return false;
}
me.fireDocReady();
return true;
}
if (document.readyState == 'complete') {
me.fireDocReady();
return true;
}
me.readyTimeout = setTimeout(arguments.callee, 2);
return false;
},
/**
* Binds the appropriate browser event for checking if the DOM has loaded.
* @private
*/
bindReadyEvent: function(){
var me = Ext.EventManager;
if (me.hasBoundOnReady) {
return;
}
if (document.addEventListener) {
document.addEventListener('DOMContentLoaded', me.fireDocReady, false);
// fallback, load will ~always~ fire
window.addEventListener('load', me.fireDocReady, false);
} else {
// check if the document is ready, this will also kick off the scroll checking timer
if (!me.checkReadyState()) {
document.attachEvent('onreadystatechange', me.checkReadyState);
me.hasOnReadyStateChange = true;
}
// fallback, onload will ~always~ fire
window.attachEvent('onload', me.fireDocReady, false);
}
me.hasBoundOnReady = true;
},
/**
* We know the document is loaded, so trigger any onReady events.
* @private
*/
fireDocReady: function(){
var me = Ext.EventManager;
// only unbind these events once
if (!me.hasFiredReady) {
me.hasFiredReady = true;
if (document.addEventListener) {
document.removeEventListener('DOMContentLoaded', me.fireDocReady, false);
window.removeEventListener('load', me.fireDocReady, false);
} else {
if (me.readyTimeout !== null) {
clearTimeout(me.readyTimeout);
}
if (me.hasOnReadyStateChange) {
document.detachEvent('onreadystatechange', me.checkReadyState);
}
window.detachEvent('onload', me.fireDocReady);
}
Ext.supports.init();
}
if (!Ext.isReady) {
Ext.isReady = true;
me.onWindowUnload();
me.readyEvent.fire();
}
},
/**
* Adds a listener to be notified when the document is ready (before onload and before images are loaded). Can be
* accessed shorthanded as Ext.onReady().
* @param {Function} fn The method the event invokes.
* @param {Object} scope (optional) The scope (this
reference) in which the handler function executes. Defaults to the browser window.
* @param {Boolean} options (optional) Options object as passed to {@link Ext.Element#addListener}.
*/
onDocumentReady: function(fn, scope, options){
options = options || {};
var me = Ext.EventManager,
readyEvent = me.readyEvent;
// force single to be true so our event is only ever fired once.
options.single = true;
// Document already loaded, let's just fire it
if (Ext.isReady) {
readyEvent.addListener(fn, scope, options);
readyEvent.fire();
} else {
options.delay = options.delay || 1;
readyEvent.addListener(fn, scope, options);
me.bindReadyEvent();
}
},
// --------------------- event binding ---------------------
/**
* Contains a list of all document mouse downs, so we can ensure they fire even when stopEvent is called.
* @private
*/
stoppedMouseDownEvent: new Ext.util.Event(),
/**
* Options to parse for the 4th argument to addListener.
* @private
*/
propRe: /^(?:scope|delay|buffer|single|stopEvent|preventDefault|stopPropagation|normalized|args|delegate|freezeEvent)$/,
/**
* Get the id of the element. If one has not been assigned, automatically assign it.
* @param {HTMLElement/Ext.Element} element The element to get the id for.
* @return {String} id
*/
getId : function(element) {
var skipGarbageCollection = false,
id;
element = Ext.getDom(element);
if (element === document || element === window) {
id = element === document ? Ext.documentId : Ext.windowId;
}
else {
id = Ext.id(element);
}
// skip garbage collection for special elements (window, document, iframes)
if (element && (element.getElementById || element.navigator)) {
skipGarbageCollection = true;
}
if (!Ext.cache[id]){
Ext.Element.addToCache(new Ext.Element(element), id);
if (skipGarbageCollection) {
Ext.cache[id].skipGarbageCollection = true;
}
}
return id;
},
/**
* Convert a "config style" listener into a set of flat arguments so they can be passed to addListener
* @private
* @param {Object} element The element the event is for
* @param {Object} event The event configuration
* @param {Object} isRemove True if a removal should be performed, otherwise an add will be done.
*/
prepareListenerConfig: function(element, config, isRemove){
var me = this,
propRe = me.propRe,
key, value, args;
// loop over all the keys in the object
for (key in config) {
if (config.hasOwnProperty(key)) {
// if the key is something else then an event option
if (!propRe.test(key)) {
value = config[key];
// if the value is a function it must be something like click: function(){}, scope: this
// which means that there might be multiple event listeners with shared options
if (Ext.isFunction(value)) {
// shared options
args = [element, key, value, config.scope, config];
} else {
// if its not a function, it must be an object like click: {fn: function(){}, scope: this}
args = [element, key, value.fn, value.scope, value];
}
if (isRemove === true) {
me.removeListener.apply(this, args);
} else {
me.addListener.apply(me, args);
}
}
}
}
},
/**
* Normalize cross browser event differences
* @private
* @param {Object} eventName The event name
* @param {Object} fn The function to execute
* @return {Object} The new event name/function
*/
normalizeEvent: function(eventName, fn){
if (/mouseenter|mouseleave/.test(eventName) && !Ext.supports.MouseEnterLeave) {
if (fn) {
fn = Ext.Function.createInterceptor(fn, this.contains, this);
}
eventName = eventName == 'mouseenter' ? 'mouseover' : 'mouseout';
} else if (eventName == 'mousewheel' && !Ext.supports.MouseWheel && !Ext.isOpera){
eventName = 'DOMMouseScroll';
}
return {
eventName: eventName,
fn: fn
};
},
/**
* Checks whether the event's relatedTarget is contained inside (or is) the element.
* @private
* @param {Object} event
*/
contains: function(event){
var parent = event.browserEvent.currentTarget,
child = this.getRelatedTarget(event);
if (parent && parent.firstChild) {
while (child) {
if (child === parent) {
return false;
}
child = child.parentNode;
if (child && (child.nodeType != 1)) {
child = null;
}
}
}
return true;
},
/**
* Appends an event handler to an element. The shorthand version {@link #on} is equivalent. Typically you will
* use {@link Ext.Element#addListener} directly on an Element in favor of calling this version.
* @param {String/HTMLElement} el The html element or id to assign the event handler to.
* @param {String} eventName The name of the event to listen for.
* @param {Function} handler The handler function the event invokes. This function is passed
* the following parameters:this
reference) in which the handler function is executed. Defaults to the Element.
* @param {Object} options (optional) An object containing handler configuration properties.
* This may contain any of the following properties:this
reference) in which the handler function is executed. Defaults to the Element.See {@link Ext.Element#addListener} for examples of how to use these options.
*/ addListener: function(element, eventName, fn, scope, options){ // Check if we've been passed a "config style" event. if (typeof eventName !== 'string') { this.prepareListenerConfig(element, eventName); return; } var dom = Ext.getDom(element), bind, wrap; // create the wrapper function options = options || {}; bind = this.normalizeEvent(eventName, fn); wrap = this.createListenerWrap(dom, eventName, bind.fn, scope, options); if (dom.attachEvent) { dom.attachEvent('on' + bind.eventName, wrap); } else { dom.addEventListener(bind.eventName, wrap, options.capture || false); } if (dom == document && eventName == 'mousedown') { this.stoppedMouseDownEvent.addListener(wrap); } // add all required data into the event cache this.getEventListenerCache(dom, eventName).push({ fn: fn, wrap: wrap, scope: scope }); }, /** * Removes an event handler from an element. The shorthand version {@link #un} is equivalent. Typically * you will use {@link Ext.Element#removeListener} directly on an Element in favor of calling this version. * @param {String/HTMLElement} el The id or html element from which to remove the listener. * @param {String} eventName The name of the event. * @param {Function} fn The handler function to remove. This must be a reference to the function passed into the {@link #addListener} call. * @param {Object} scope If a scope (this
reference) was specified when the listener was added,
* then this must refer to the same object.
*/
removeListener : function(element, eventName, fn, scope) {
// handle our listener config object syntax
if (typeof eventName !== 'string') {
this.prepareListenerConfig(element, eventName, true);
return;
}
var dom = Ext.getDom(element),
cache = this.getEventListenerCache(dom, eventName),
bindName = this.normalizeEvent(eventName).eventName,
i = cache.length, j,
listener, wrap, tasks;
while (i--) {
listener = cache[i];
if (listener && (!fn || listener.fn == fn) && (!scope || listener.scope === scope)) {
wrap = listener.wrap;
// clear buffered calls
if (wrap.task) {
clearTimeout(wrap.task);
delete wrap.task;
}
// clear delayed calls
j = wrap.tasks && wrap.tasks.length;
if (j) {
while (j--) {
clearTimeout(wrap.tasks[j]);
}
delete wrap.tasks;
}
if (dom.detachEvent) {
dom.detachEvent('on' + bindName, wrap);
} else {
dom.removeEventListener(bindName, wrap, false);
}
if (wrap && dom == document && eventName == 'mousedown') {
this.stoppedMouseDownEvent.removeListener(wrap);
}
// remove listener from cache
Ext.Array.erase(cache, i, 1);
}
}
},
/**
* Removes all event handers from an element. Typically you will use {@link Ext.Element#removeAllListeners}
* directly on an Element in favor of calling this version.
* @param {String/HTMLElement} el The id or html element from which to remove all event handlers.
*/
removeAll : function(element){
var dom = Ext.getDom(element),
cache, ev;
if (!dom) {
return;
}
cache = this.getElementEventCache(dom);
for (ev in cache) {
if (cache.hasOwnProperty(ev)) {
this.removeListener(dom, ev);
}
}
Ext.cache[dom.id].events = {};
},
/**
* Recursively removes all previous added listeners from an element and its children. Typically you will use {@link Ext.Element#purgeAllListeners}
* directly on an Element in favor of calling this version.
* @param {String/HTMLElement} el The id or html element from which to remove all event handlers.
* @param {String} eventName (optional) The name of the event.
*/
purgeElement : function(element, eventName) {
var dom = Ext.getDom(element),
i = 0, len;
if(eventName) {
this.removeListener(dom, eventName);
}
else {
this.removeAll(dom);
}
if(dom && dom.childNodes) {
for(len = element.childNodes.length; i < len; i++) {
this.purgeElement(element.childNodes[i], eventName);
}
}
},
/**
* Create the wrapper function for the event
* @private
* @param {HTMLElement} dom The dom element
* @param {String} ename The event name
* @param {Function} fn The function to execute
* @param {Object} scope The scope to execute callback in
* @param {Object} options The options
* @return {Function} the wrapper function
*/
createListenerWrap : function(dom, ename, fn, scope, options) {
options = options || {};
var f, gen;
return function wrap(e, args) {
// Compile the implementation upon first firing
if (!gen) {
f = ['if(!Ext) {return;}'];
if(options.buffer || options.delay || options.freezeEvent) {
f.push('e = new Ext.EventObjectImpl(e, ' + (options.freezeEvent ? 'true' : 'false' ) + ');');
} else {
f.push('e = Ext.EventObject.setEvent(e);');
}
if (options.delegate) {
f.push('var t = e.getTarget("' + options.delegate + '", this);');
f.push('if(!t) {return;}');
} else {
f.push('var t = e.target;');
}
if (options.target) {
f.push('if(e.target !== options.target) {return;}');
}
if(options.stopEvent) {
f.push('e.stopEvent();');
} else {
if(options.preventDefault) {
f.push('e.preventDefault();');
}
if(options.stopPropagation) {
f.push('e.stopPropagation();');
}
}
if(options.normalized === false) {
f.push('e = e.browserEvent;');
}
if(options.buffer) {
f.push('(wrap.task && clearTimeout(wrap.task));');
f.push('wrap.task = setTimeout(function(){');
}
if(options.delay) {
f.push('wrap.tasks = wrap.tasks || [];');
f.push('wrap.tasks.push(setTimeout(function(){');
}
// finally call the actual handler fn
f.push('fn.call(scope || dom, e, t, options);');
if(options.single) {
f.push('Ext.EventManager.removeListener(dom, ename, fn, scope);');
}
if(options.delay) {
f.push('}, ' + options.delay + '));');
}
if(options.buffer) {
f.push('}, ' + options.buffer + ');');
}
gen = Ext.functionFactory('e', 'options', 'fn', 'scope', 'ename', 'dom', 'wrap', 'args', f.join('\n'));
}
gen.call(dom, e, options, fn, scope, ename, dom, wrap, args);
};
},
/**
* Get the event cache for a particular element for a particular event
* @private
* @param {HTMLElement} element The element
* @param {Object} eventName The event name
* @return {Array} The events for the element
*/
getEventListenerCache : function(element, eventName) {
if (!element) {
return [];
}
var eventCache = this.getElementEventCache(element);
return eventCache[eventName] || (eventCache[eventName] = []);
},
/**
* Gets the event cache for the object
* @private
* @param {HTMLElement} element The element
* @return {Object} The event cache for the object
*/
getElementEventCache : function(element) {
if (!element) {
return {};
}
var elementCache = Ext.cache[this.getId(element)];
return elementCache.events || (elementCache.events = {});
},
// --------------------- utility methods ---------------------
mouseLeaveRe: /(mouseout|mouseleave)/,
mouseEnterRe: /(mouseover|mouseenter)/,
/**
* Stop the event (preventDefault and stopPropagation)
* @param {Event} The event to stop
*/
stopEvent: function(event) {
this.stopPropagation(event);
this.preventDefault(event);
},
/**
* Cancels bubbling of the event.
* @param {Event} The event to stop bubbling.
*/
stopPropagation: function(event) {
event = event.browserEvent || event;
if (event.stopPropagation) {
event.stopPropagation();
} else {
event.cancelBubble = true;
}
},
/**
* Prevents the browsers default handling of the event.
* @param {Event} The event to prevent the default
*/
preventDefault: function(event) {
event = event.browserEvent || event;
if (event.preventDefault) {
event.preventDefault();
} else {
event.returnValue = false;
// Some keys events require setting the keyCode to -1 to be prevented
try {
// all ctrl + X and F1 -> F12
if (event.ctrlKey || event.keyCode > 111 && event.keyCode < 124) {
event.keyCode = -1;
}
} catch (e) {
// see this outdated document http://support.microsoft.com/kb/934364/en-us for more info
}
}
},
/**
* Gets the related target from the event.
* @param {Object} event The event
* @return {HTMLElement} The related target.
*/
getRelatedTarget: function(event) {
event = event.browserEvent || event;
var target = event.relatedTarget;
if (!target) {
if (this.mouseLeaveRe.test(event.type)) {
target = event.toElement;
} else if (this.mouseEnterRe.test(event.type)) {
target = event.fromElement;
}
}
return this.resolveTextNode(target);
},
/**
* Gets the x coordinate from the event
* @param {Object} event The event
* @return {Number} The x coordinate
*/
getPageX: function(event) {
return this.getXY(event)[0];
},
/**
* Gets the y coordinate from the event
* @param {Object} event The event
* @return {Number} The y coordinate
*/
getPageY: function(event) {
return this.getXY(event)[1];
},
/**
* Gets the x & y coordinate from the event
* @param {Object} event The event
* @return {Number[]} The x/y coordinate
*/
getPageXY: function(event) {
event = event.browserEvent || event;
var x = event.pageX,
y = event.pageY,
doc = document.documentElement,
body = document.body;
// pageX/pageY not available (undefined, not null), use clientX/clientY instead
if (!x && x !== 0) {
x = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc && doc.clientLeft || body && body.clientLeft || 0);
y = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc && doc.clientTop || body && body.clientTop || 0);
}
return [x, y];
},
/**
* Gets the target of the event.
* @param {Object} event The event
* @return {HTMLElement} target
*/
getTarget: function(event) {
event = event.browserEvent || event;
return this.resolveTextNode(event.target || event.srcElement);
},
/**
* Resolve any text nodes accounting for browser differences.
* @private
* @param {HTMLElement} node The node
* @return {HTMLElement} The resolved node
*/
// technically no need to browser sniff this, however it makes no sense to check this every time, for every event, whether the string is equal.
resolveTextNode: Ext.isGecko ?
function(node) {
if (!node) {
return;
}
// work around firefox bug, https://bugzilla.mozilla.org/show_bug.cgi?id=101197
var s = HTMLElement.prototype.toString.call(node);
if (s == '[xpconnect wrapped native prototype]' || s == '[object XULElement]') {
return;
}
return node.nodeType == 3 ? node.parentNode: node;
}: function(node) {
return node && node.nodeType == 3 ? node.parentNode: node;
},
// --------------------- custom event binding ---------------------
// Keep track of the current width/height
curWidth: 0,
curHeight: 0,
/**
* Adds a listener to be notified when the browser window is resized and provides resize event buffering (100 milliseconds),
* passes new viewport width and height to handlers.
* @param {Function} fn The handler function the window resize event invokes.
* @param {Object} scope The scope (this
reference) in which the handler function executes. Defaults to the browser window.
* @param {Boolean} options Options object as passed to {@link Ext.Element#addListener}
*/
onWindowResize: function(fn, scope, options){
var resize = this.resizeEvent;
if(!resize){
this.resizeEvent = resize = new Ext.util.Event();
this.on(window, 'resize', this.fireResize, this, {buffer: 100});
}
resize.addListener(fn, scope, options);
},
/**
* Fire the resize event.
* @private
*/
fireResize: function(){
var me = this,
w = Ext.Element.getViewWidth(),
h = Ext.Element.getViewHeight();
//whacky problem in IE where the resize event will sometimes fire even though the w/h are the same.
if(me.curHeight != h || me.curWidth != w){
me.curHeight = h;
me.curWidth = w;
me.resizeEvent.fire(w, h);
}
},
/**
* Removes the passed window resize listener.
* @param {Function} fn The method the event invokes
* @param {Object} scope The scope of handler
*/
removeResizeListener: function(fn, scope){
if (this.resizeEvent) {
this.resizeEvent.removeListener(fn, scope);
}
},
onWindowUnload: function() {
var unload = this.unloadEvent;
if (!unload) {
this.unloadEvent = unload = new Ext.util.Event();
this.addListener(window, 'unload', this.fireUnload, this);
}
},
/**
* Fires the unload event for items bound with onWindowUnload
* @private
*/
fireUnload: function() {
// wrap in a try catch, could have some problems during unload
try {
this.removeUnloadListener();
// Work around FF3 remembering the last scroll position when refreshing the grid and then losing grid view
if (Ext.isGecko3) {
var gridviews = Ext.ComponentQuery.query('gridview'),
i = 0,
ln = gridviews.length;
for (; i < ln; i++) {
gridviews[i].scrollToTop();
}
}
// Purge all elements in the cache
var el,
cache = Ext.cache;
for (el in cache) {
if (cache.hasOwnProperty(el)) {
Ext.EventManager.removeAll(el);
}
}
} catch(e) {
}
},
/**
* Removes the passed window unload listener.
* @param {Function} fn The method the event invokes
* @param {Object} scope The scope of handler
*/
removeUnloadListener: function(){
if (this.unloadEvent) {
this.removeListener(window, 'unload', this.fireUnload);
}
},
/**
* note 1: IE fires ONLY the keydown event on specialkey autorepeat
* note 2: Safari < 3.1, Gecko (Mac/Linux) & Opera fire only the keypress event on specialkey autorepeat
* (research done by Jan Wolter at http://unixpapa.com/js/key.html)
* @private
*/
useKeyDown: Ext.isWebKit ?
parseInt(navigator.userAgent.match(/AppleWebKit\/(\d+)/)[1], 10) >= 525 :
!((Ext.isGecko && !Ext.isWindows) || Ext.isOpera),
/**
* Indicates which event to use for getting key presses.
* @return {String} The appropriate event name.
*/
getKeyEvent: function(){
return this.useKeyDown ? 'keydown' : 'keypress';
}
};
/**
* Alias for {@link Ext.Loader#onReady Ext.Loader.onReady} with withDomReady set to true
* @member Ext
* @method onReady
*/
Ext.onReady = function(fn, scope, options) {
Ext.Loader.onReady(fn, scope, true, options);
};
/**
* Alias for {@link Ext.EventManager#onDocumentReady Ext.EventManager.onDocumentReady}
* @member Ext
* @method onDocumentReady
*/
Ext.onDocumentReady = Ext.EventManager.onDocumentReady;
/**
* Alias for {@link Ext.EventManager#addListener Ext.EventManager.addListener}
* @member Ext.EventManager
* @method on
*/
Ext.EventManager.on = Ext.EventManager.addListener;
/**
* Alias for {@link Ext.EventManager#removeListener Ext.EventManager.removeListener}
* @member Ext.EventManager
* @method un
*/
Ext.EventManager.un = Ext.EventManager.removeListener;
(function(){
var initExtCss = function() {
// find the body element
var bd = document.body || document.getElementsByTagName('body')[0],
baseCSSPrefix = Ext.baseCSSPrefix,
cls = [baseCSSPrefix + 'body'],
htmlCls = [],
html;
if (!bd) {
return false;
}
html = bd.parentNode;
function add (c) {
cls.push(baseCSSPrefix + c);
}
//Let's keep this human readable!
if (Ext.isIE) {
add('ie');
// very often CSS needs to do checks like "IE7+" or "IE6 or 7". To help
// reduce the clutter (since CSS/SCSS cannot do these tests), we add some
// additional classes:
//
// x-ie7p : IE7+ : 7 <= ieVer
// x-ie7m : IE7- : ieVer <= 7
// x-ie8p : IE8+ : 8 <= ieVer
// x-ie8m : IE8- : ieVer <= 8
// x-ie9p : IE9+ : 9 <= ieVer
// x-ie78 : IE7 or 8 : 7 <= ieVer <= 8
//
if (Ext.isIE6) {
add('ie6');
} else { // ignore pre-IE6 :)
add('ie7p');
if (Ext.isIE7) {
add('ie7');
} else {
add('ie8p');
if (Ext.isIE8) {
add('ie8');
} else {
add('ie9p');
if (Ext.isIE9) {
add('ie9');
}
}
}
}
if (Ext.isIE6 || Ext.isIE7) {
add('ie7m');
}
if (Ext.isIE6 || Ext.isIE7 || Ext.isIE8) {
add('ie8m');
}
if (Ext.isIE7 || Ext.isIE8) {
add('ie78');
}
}
if (Ext.isGecko) {
add('gecko');
if (Ext.isGecko3) {
add('gecko3');
}
if (Ext.isGecko4) {
add('gecko4');
}
if (Ext.isGecko5) {
add('gecko5');
}
}
if (Ext.isOpera) {
add('opera');
}
if (Ext.isWebKit) {
add('webkit');
}
if (Ext.isSafari) {
add('safari');
if (Ext.isSafari2) {
add('safari2');
}
if (Ext.isSafari3) {
add('safari3');
}
if (Ext.isSafari4) {
add('safari4');
}
if (Ext.isSafari5) {
add('safari5');
}
}
if (Ext.isChrome) {
add('chrome');
}
if (Ext.isMac) {
add('mac');
}
if (Ext.isLinux) {
add('linux');
}
if (!Ext.supports.CSS3BorderRadius) {
add('nbr');
}
if (!Ext.supports.CSS3LinearGradient) {
add('nlg');
}
if (!Ext.scopeResetCSS) {
add('reset');
}
// add to the parent to allow for selectors x-strict x-border-box, also set the isBorderBox property correctly
if (html) {
if (Ext.isStrict && (Ext.isIE6 || Ext.isIE7)) {
Ext.isBorderBox = false;
}
else {
Ext.isBorderBox = true;
}
htmlCls.push(baseCSSPrefix + (Ext.isBorderBox ? 'border-box' : 'strict'));
if (!Ext.isStrict) {
htmlCls.push(baseCSSPrefix + 'quirks');
}
Ext.fly(html, '_internal').addCls(htmlCls);
}
Ext.fly(bd, '_internal').addCls(cls);
return true;
};
Ext.onReady(initExtCss);
})();
/**
* @class Ext.EventObject
Just as {@link Ext.Element} wraps around a native DOM node, Ext.EventObject
wraps the browser's native event-object normalizing cross-browser differences,
such as which mouse button is clicked, keys pressed, mechanisms to stop
event-propagation along with a method to prevent default actions from taking place.
For example:
function handleClick(e, t){ // e is not a standard event object, it is a Ext.EventObject
e.preventDefault();
var target = e.getTarget(); // same as t (the target HTMLElement)
...
}
var myDiv = {@link Ext#get Ext.get}("myDiv"); // get reference to an {@link Ext.Element}
myDiv.on( // 'on' is shorthand for addListener
"click", // perform an action on click of myDiv
handleClick // reference to the action handler
);
// other methods to do the same:
Ext.EventManager.on("myDiv", 'click', handleClick);
Ext.EventManager.addListener("myDiv", 'click', handleClick);
* @singleton
* @markdown
*/
Ext.define('Ext.EventObjectImpl', {
uses: ['Ext.util.Point'],
/** Key constant @type Number */
BACKSPACE: 8,
/** Key constant @type Number */
TAB: 9,
/** Key constant @type Number */
NUM_CENTER: 12,
/** Key constant @type Number */
ENTER: 13,
/** Key constant @type Number */
RETURN: 13,
/** Key constant @type Number */
SHIFT: 16,
/** Key constant @type Number */
CTRL: 17,
/** Key constant @type Number */
ALT: 18,
/** Key constant @type Number */
PAUSE: 19,
/** Key constant @type Number */
CAPS_LOCK: 20,
/** Key constant @type Number */
ESC: 27,
/** Key constant @type Number */
SPACE: 32,
/** Key constant @type Number */
PAGE_UP: 33,
/** Key constant @type Number */
PAGE_DOWN: 34,
/** Key constant @type Number */
END: 35,
/** Key constant @type Number */
HOME: 36,
/** Key constant @type Number */
LEFT: 37,
/** Key constant @type Number */
UP: 38,
/** Key constant @type Number */
RIGHT: 39,
/** Key constant @type Number */
DOWN: 40,
/** Key constant @type Number */
PRINT_SCREEN: 44,
/** Key constant @type Number */
INSERT: 45,
/** Key constant @type Number */
DELETE: 46,
/** Key constant @type Number */
ZERO: 48,
/** Key constant @type Number */
ONE: 49,
/** Key constant @type Number */
TWO: 50,
/** Key constant @type Number */
THREE: 51,
/** Key constant @type Number */
FOUR: 52,
/** Key constant @type Number */
FIVE: 53,
/** Key constant @type Number */
SIX: 54,
/** Key constant @type Number */
SEVEN: 55,
/** Key constant @type Number */
EIGHT: 56,
/** Key constant @type Number */
NINE: 57,
/** Key constant @type Number */
A: 65,
/** Key constant @type Number */
B: 66,
/** Key constant @type Number */
C: 67,
/** Key constant @type Number */
D: 68,
/** Key constant @type Number */
E: 69,
/** Key constant @type Number */
F: 70,
/** Key constant @type Number */
G: 71,
/** Key constant @type Number */
H: 72,
/** Key constant @type Number */
I: 73,
/** Key constant @type Number */
J: 74,
/** Key constant @type Number */
K: 75,
/** Key constant @type Number */
L: 76,
/** Key constant @type Number */
M: 77,
/** Key constant @type Number */
N: 78,
/** Key constant @type Number */
O: 79,
/** Key constant @type Number */
P: 80,
/** Key constant @type Number */
Q: 81,
/** Key constant @type Number */
R: 82,
/** Key constant @type Number */
S: 83,
/** Key constant @type Number */
T: 84,
/** Key constant @type Number */
U: 85,
/** Key constant @type Number */
V: 86,
/** Key constant @type Number */
W: 87,
/** Key constant @type Number */
X: 88,
/** Key constant @type Number */
Y: 89,
/** Key constant @type Number */
Z: 90,
/** Key constant @type Number */
CONTEXT_MENU: 93,
/** Key constant @type Number */
NUM_ZERO: 96,
/** Key constant @type Number */
NUM_ONE: 97,
/** Key constant @type Number */
NUM_TWO: 98,
/** Key constant @type Number */
NUM_THREE: 99,
/** Key constant @type Number */
NUM_FOUR: 100,
/** Key constant @type Number */
NUM_FIVE: 101,
/** Key constant @type Number */
NUM_SIX: 102,
/** Key constant @type Number */
NUM_SEVEN: 103,
/** Key constant @type Number */
NUM_EIGHT: 104,
/** Key constant @type Number */
NUM_NINE: 105,
/** Key constant @type Number */
NUM_MULTIPLY: 106,
/** Key constant @type Number */
NUM_PLUS: 107,
/** Key constant @type Number */
NUM_MINUS: 109,
/** Key constant @type Number */
NUM_PERIOD: 110,
/** Key constant @type Number */
NUM_DIVISION: 111,
/** Key constant @type Number */
F1: 112,
/** Key constant @type Number */
F2: 113,
/** Key constant @type Number */
F3: 114,
/** Key constant @type Number */
F4: 115,
/** Key constant @type Number */
F5: 116,
/** Key constant @type Number */
F6: 117,
/** Key constant @type Number */
F7: 118,
/** Key constant @type Number */
F8: 119,
/** Key constant @type Number */
F9: 120,
/** Key constant @type Number */
F10: 121,
/** Key constant @type Number */
F11: 122,
/** Key constant @type Number */
F12: 123,
/**
* The mouse wheel delta scaling factor. This value depends on browser version and OS and
* attempts to produce a similar scrolling experience across all platforms and browsers.
*
* To change this value:
*
* Ext.EventObjectImpl.prototype.WHEEL_SCALE = 72;
*
* @type Number
* @markdown
*/
WHEEL_SCALE: (function () {
var scale;
if (Ext.isGecko) {
// Firefox uses 3 on all platforms
scale = 3;
} else if (Ext.isMac) {
// Continuous scrolling devices have momentum and produce much more scroll than
// discrete devices on the same OS and browser. To make things exciting, Safari
// (and not Chrome) changed from small values to 120 (like IE).
if (Ext.isSafari && Ext.webKitVersion >= 532.0) {
// Safari changed the scrolling factor to match IE (for details see
// https://bugs.webkit.org/show_bug.cgi?id=24368). The WebKit version where this
// change was introduced was 532.0
// Detailed discussion:
// https://bugs.webkit.org/show_bug.cgi?id=29601
// http://trac.webkit.org/browser/trunk/WebKit/chromium/src/mac/WebInputEventFactory.mm#L1063
scale = 120;
} else {
// MS optical wheel mouse produces multiples of 12 which is close enough
// to help tame the speed of the continuous mice...
scale = 12;
}
// Momentum scrolling produces very fast scrolling, so increase the scale factor
// to help produce similar results cross platform. This could be even larger and
// it would help those mice, but other mice would become almost unusable as a
// result (since we cannot tell which device type is in use).
scale *= 3;
} else {
// IE, Opera and other Windows browsers use 120.
scale = 120;
}
return scale;
})(),
/**
* Simple click regex
* @private
*/
clickRe: /(dbl)?click/,
// safari keypress events for special keys return bad keycodes
safariKeys: {
3: 13, // enter
63234: 37, // left
63235: 39, // right
63232: 38, // up
63233: 40, // down
63276: 33, // page up
63277: 34, // page down
63272: 46, // delete
63273: 36, // home
63275: 35 // end
},
// normalize button clicks, don't see any way to feature detect this.
btnMap: Ext.isIE ? {
1: 0,
4: 1,
2: 2
} : {
0: 0,
1: 1,
2: 2
},
constructor: function(event, freezeEvent){
if (event) {
this.setEvent(event.browserEvent || event, freezeEvent);
}
},
setEvent: function(event, freezeEvent){
var me = this, button, options;
if (event == me || (event && event.browserEvent)) { // already wrapped
return event;
}
me.browserEvent = event;
if (event) {
// normalize buttons
button = event.button ? me.btnMap[event.button] : (event.which ? event.which - 1 : -1);
if (me.clickRe.test(event.type) && button == -1) {
button = 0;
}
options = {
type: event.type,
button: button,
shiftKey: event.shiftKey,
// mac metaKey behaves like ctrlKey
ctrlKey: event.ctrlKey || event.metaKey || false,
altKey: event.altKey,
// in getKey these will be normalized for the mac
keyCode: event.keyCode,
charCode: event.charCode,
// cache the targets for the delayed and or buffered events
target: Ext.EventManager.getTarget(event),
relatedTarget: Ext.EventManager.getRelatedTarget(event),
currentTarget: event.currentTarget,
xy: (freezeEvent ? me.getXY() : null)
};
} else {
options = {
button: -1,
shiftKey: false,
ctrlKey: false,
altKey: false,
keyCode: 0,
charCode: 0,
target: null,
xy: [0, 0]
};
}
Ext.apply(me, options);
return me;
},
/**
* Stop the event (preventDefault and stopPropagation)
*/
stopEvent: function(){
this.stopPropagation();
this.preventDefault();
},
/**
* Prevents the browsers default handling of the event.
*/
preventDefault: function(){
if (this.browserEvent) {
Ext.EventManager.preventDefault(this.browserEvent);
}
},
/**
* Cancels bubbling of the event.
*/
stopPropagation: function(){
var browserEvent = this.browserEvent;
if (browserEvent) {
if (browserEvent.type == 'mousedown') {
Ext.EventManager.stoppedMouseDownEvent.fire(this);
}
Ext.EventManager.stopPropagation(browserEvent);
}
},
/**
* Gets the character code for the event.
* @return {Number}
*/
getCharCode: function(){
return this.charCode || this.keyCode;
},
/**
* Returns a normalized keyCode for the event.
* @return {Number} The key code
*/
getKey: function(){
return this.normalizeKey(this.keyCode || this.charCode);
},
/**
* Normalize key codes across browsers
* @private
* @param {Number} key The key code
* @return {Number} The normalized code
*/
normalizeKey: function(key){
// can't feature detect this
return Ext.isWebKit ? (this.safariKeys[key] || key) : key;
},
/**
* Gets the x coordinate of the event.
* @return {Number}
* @deprecated 4.0 Replaced by {@link #getX}
*/
getPageX: function(){
return this.getX();
},
/**
* Gets the y coordinate of the event.
* @return {Number}
* @deprecated 4.0 Replaced by {@link #getY}
*/
getPageY: function(){
return this.getY();
},
/**
* Gets the x coordinate of the event.
* @return {Number}
*/
getX: function() {
return this.getXY()[0];
},
/**
* Gets the y coordinate of the event.
* @return {Number}
*/
getY: function() {
return this.getXY()[1];
},
/**
* Gets the page coordinates of the event.
* @return {Number[]} The xy values like [x, y]
*/
getXY: function() {
if (!this.xy) {
// same for XY
this.xy = Ext.EventManager.getPageXY(this.browserEvent);
}
return this.xy;
},
/**
* Gets the target for the event.
* @param {String} selector (optional) A simple selector to filter the target or look for an ancestor of the target
* @param {Number/HTMLElement} maxDepth (optional) The max depth to search as a number or element (defaults to 10 || document.body)
* @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node
* @return {HTMLElement}
*/
getTarget : function(selector, maxDepth, returnEl){
if (selector) {
return Ext.fly(this.target).findParent(selector, maxDepth, returnEl);
}
return returnEl ? Ext.get(this.target) : this.target;
},
/**
* Gets the related target.
* @param {String} selector (optional) A simple selector to filter the target or look for an ancestor of the target
* @param {Number/HTMLElement} maxDepth (optional) The max depth to search as a number or element (defaults to 10 || document.body)
* @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node
* @return {HTMLElement}
*/
getRelatedTarget : function(selector, maxDepth, returnEl){
if (selector) {
return Ext.fly(this.relatedTarget).findParent(selector, maxDepth, returnEl);
}
return returnEl ? Ext.get(this.relatedTarget) : this.relatedTarget;
},
/**
* Correctly scales a given wheel delta.
* @param {Number} delta The delta value.
*/
correctWheelDelta : function (delta) {
var scale = this.WHEEL_SCALE,
ret = Math.round(delta / scale);
if (!ret && delta) {
ret = (delta < 0) ? -1 : 1; // don't allow non-zero deltas to go to zero!
}
return ret;
},
/**
* Returns the mouse wheel deltas for this event.
* @return {Object} An object with "x" and "y" properties holding the mouse wheel deltas.
*/
getWheelDeltas : function () {
var me = this,
event = me.browserEvent,
dx = 0, dy = 0; // the deltas
if (Ext.isDefined(event.wheelDeltaX)) { // WebKit has both dimensions
dx = event.wheelDeltaX;
dy = event.wheelDeltaY;
} else if (event.wheelDelta) { // old WebKit and IE
dy = event.wheelDelta;
} else if (event.detail) { // Gecko
dy = -event.detail; // gecko is backwards
// Gecko sometimes returns really big values if the user changes settings to
// scroll a whole page per scroll
if (dy > 100) {
dy = 3;
} else if (dy < -100) {
dy = -3;
}
// Firefox 3.1 adds an axis field to the event to indicate direction of
// scroll. See https://developer.mozilla.org/en/Gecko-Specific_DOM_Events
if (Ext.isDefined(event.axis) && event.axis === event.HORIZONTAL_AXIS) {
dx = dy;
dy = 0;
}
}
return {
x: me.correctWheelDelta(dx),
y: me.correctWheelDelta(dy)
};
},
/**
* Normalizes mouse wheel y-delta across browsers. To get x-delta information, use
* {@link #getWheelDeltas} instead.
* @return {Number} The mouse wheel y-delta
*/
getWheelDelta : function(){
var deltas = this.getWheelDeltas();
return deltas.y;
},
/**
* Returns true if the target of this event is a child of el. Unless the allowEl parameter is set, it will return false if if the target is el.
* Example usage:
// Handle click on any child of an element
Ext.getBody().on('click', function(e){
if(e.within('some-el')){
alert('Clicked on a child of some-el!');
}
});
// Handle click directly on an element, ignoring clicks on child nodes
Ext.getBody().on('click', function(e,t){
if((t.id == 'some-el') && !e.within(t, true)){
alert('Clicked directly on some-el!');
}
});
* @param {String/HTMLElement/Ext.Element} el The id, DOM element or Ext.Element to check
* @param {Boolean} related (optional) true to test if the related target is within el instead of the target
* @param {Boolean} allowEl (optional) true to also check if the passed element is the target or related target
* @return {Boolean}
*/
within : function(el, related, allowEl){
if(el){
var t = related ? this.getRelatedTarget() : this.getTarget(),
result;
if (t) {
result = Ext.fly(el).contains(t);
if (!result && allowEl) {
result = t == Ext.getDom(el);
}
return result;
}
}
return false;
},
/**
* Checks if the key pressed was a "navigation" key
* @return {Boolean} True if the press is a navigation keypress
*/
isNavKeyPress : function(){
var me = this,
k = this.normalizeKey(me.keyCode);
return (k >= 33 && k <= 40) || // Page Up/Down, End, Home, Left, Up, Right, Down
k == me.RETURN ||
k == me.TAB ||
k == me.ESC;
},
/**
* Checks if the key pressed was a "special" key
* @return {Boolean} True if the press is a special keypress
*/
isSpecialKey : function(){
var k = this.normalizeKey(this.keyCode);
return (this.type == 'keypress' && this.ctrlKey) ||
this.isNavKeyPress() ||
(k == this.BACKSPACE) || // Backspace
(k >= 16 && k <= 20) || // Shift, Ctrl, Alt, Pause, Caps Lock
(k >= 44 && k <= 46); // Print Screen, Insert, Delete
},
/**
* Returns a point object that consists of the object coordinates.
* @return {Ext.util.Point} point
*/
getPoint : function(){
var xy = this.getXY();
return Ext.create('Ext.util.Point', xy[0], xy[1]);
},
/**
* Returns true if the control, meta, shift or alt key was pressed during this event.
* @return {Boolean}
*/
hasModifier : function(){
return this.ctrlKey || this.altKey || this.shiftKey || this.metaKey;
},
/**
* Injects a DOM event using the data in this object and (optionally) a new target.
* This is a low-level technique and not likely to be used by application code. The
* currently supported event types are:
* HTMLEvents
*MouseEvents
*UIEvents
*this
reference) in which the handler function executes. Defaults to this Element.
* @return {Object} The listeners object which was added to this element so that monitoring can be stopped. Example usage:
// Hide the menu if the mouse moves out for 250ms or more
this.mouseLeaveMonitor = this.menuEl.monitorMouseLeave(250, this.hideMenu, this);
...
// Remove mouseleave monitor on menu destroy
this.menuEl.un(this.mouseLeaveMonitor);
*/
monitorMouseLeave: function(delay, handler, scope) {
var me = this,
timer,
listeners = {
mouseleave: function(e) {
timer = setTimeout(Ext.Function.bind(handler, scope||me, [e]), delay);
},
mouseenter: function() {
clearTimeout(timer);
},
freezeEvent: true
};
me.on(listeners);
return listeners;
},
/**
* Stops the specified event(s) from bubbling and optionally prevents the default action
* @param {String/String[]} eventName an event / array of events to stop from bubbling
* @param {Boolean} preventDefault (optional) true to prevent the default action too
* @return {Ext.Element} this
*/
swallowEvent : function(eventName, preventDefault) {
var me = this;
function fn(e) {
e.stopPropagation();
if (preventDefault) {
e.preventDefault();
}
}
if (Ext.isArray(eventName)) {
Ext.each(eventName, function(e) {
me.on(e, fn);
});
return me;
}
me.on(eventName, fn);
return me;
},
/**
* Create an event handler on this element such that when the event fires and is handled by this element,
* it will be relayed to another object (i.e., fired again as if it originated from that object instead).
* @param {String} eventName The type of event to relay
* @param {Object} object Any object that extends {@link Ext.util.Observable} that will provide the context
* for firing the relayed event
*/
relayEvent : function(eventName, observable) {
this.on(eventName, function(e) {
observable.fireEvent(eventName, e);
});
},
/**
* Removes Empty, or whitespace filled text nodes. Combines adjacent text nodes.
* @param {Boolean} forceReclean (optional) By default the element
* keeps track if it has been cleaned already so
* you can call this over and over. However, if you update the element and
* need to force a reclean, you can pass true.
*/
clean : function(forceReclean) {
var me = this,
dom = me.dom,
n = dom.firstChild,
nx,
ni = -1;
if (Ext.Element.data(dom, 'isCleaned') && forceReclean !== true) {
return me;
}
while (n) {
nx = n.nextSibling;
if (n.nodeType == 3) {
// Remove empty/whitespace text nodes
if (!(/\S/.test(n.nodeValue))) {
dom.removeChild(n);
// Combine adjacent text nodes
} else if (nx && nx.nodeType == 3) {
n.appendData(Ext.String.trim(nx.data));
dom.removeChild(nx);
nx = n.nextSibling;
n.nodeIndex = ++ni;
}
} else {
// Recursively clean
Ext.fly(n).clean();
n.nodeIndex = ++ni;
}
n = nx;
}
Ext.Element.data(dom, 'isCleaned', true);
return me;
},
/**
* Direct access to the Ext.ElementLoader {@link Ext.ElementLoader#load} method. The method takes the same object
* parameter as {@link Ext.ElementLoader#load}
* @return {Ext.Element} this
*/
load : function(options) {
this.getLoader().load(options);
return this;
},
/**
* Gets this element's {@link Ext.ElementLoader ElementLoader}
* @return {Ext.ElementLoader} The loader
*/
getLoader : function() {
var dom = this.dom,
data = Ext.Element.data,
loader = data(dom, 'loader');
if (!loader) {
loader = Ext.create('Ext.ElementLoader', {
target: this
});
data(dom, 'loader', loader);
}
return loader;
},
/**
* Update the innerHTML of this element, optionally searching for and processing scripts
* @param {String} html The new HTML
* @param {Boolean} [loadScripts=false] True to look for and process scripts
* @param {Function} [callback] For async script loading you can be notified when the update completes
* @return {Ext.Element} this
*/
update : function(html, loadScripts, callback) {
var me = this,
id,
dom,
interval;
if (!me.dom) {
return me;
}
html = html || '';
dom = me.dom;
if (loadScripts !== true) {
dom.innerHTML = html;
Ext.callback(callback, me);
return me;
}
id = Ext.id();
html += '';
interval = setInterval(function(){
if (!document.getElementById(id)) {
return false;
}
clearInterval(interval);
var DOC = document,
hd = DOC.getElementsByTagName("head")[0],
re = /(?:
*
* When we inject the tag above, the browser makes a request to that url and includes the response as if it was any
* other type of JavaScript include. By passing a callback in the url above, we're telling domainB's server that we want
* to be notified when the result comes in and that it should call our callback function with the data it sends back. So
* long as the server formats the response to look like this, everything will work:
*
* someCallback({
* users: [
* {
* id: 1,
* name: "Ed Spencer",
* email: "ed@sencha.com"
* }
* ]
* });
*
* As soon as the script finishes loading, the 'someCallback' function that we passed in the url is called with the JSON
* object that the server returned.
*
* JsonP proxy takes care of all of this automatically. It formats the url you pass, adding the callback parameter
* automatically. It even creates a temporary callback function, waits for it to be called and then puts the data into
* the Proxy making it look just like you loaded it through a normal {@link Ext.data.proxy.Ajax AjaxProxy}. Here's how
* we might set that up:
*
* Ext.define('User', {
* extend: 'Ext.data.Model',
* fields: ['id', 'name', 'email']
* });
*
* var store = Ext.create('Ext.data.Store', {
* model: 'User',
* proxy: {
* type: 'jsonp',
* url : 'http://domainB.com/users'
* }
* });
*
* store.load();
*
* That's all we need to do - JsonP proxy takes care of the rest. In this case the Proxy will have injected a script tag
* like this:
*
*
*
* # Customization
*
* This script tag can be customized using the {@link #callbackKey} configuration. For example:
*
* var store = Ext.create('Ext.data.Store', {
* model: 'User',
* proxy: {
* type: 'jsonp',
* url : 'http://domainB.com/users',
* callbackKey: 'theCallbackFunction'
* }
* });
*
* store.load();
*
* Would inject a script tag like this:
*
*
*
* # Implementing on the server side
*
* The remote server side needs to be configured to return data in this format. Here are suggestions for how you might
* achieve this using Java, PHP and ASP.net:
*
* Java:
*
* boolean jsonP = false;
* String cb = request.getParameter("callback");
* if (cb != null) {
* jsonP = true;
* response.setContentType("text/javascript");
* } else {
* response.setContentType("application/x-json");
* }
* Writer out = response.getWriter();
* if (jsonP) {
* out.write(cb + "(");
* }
* out.print(dataBlock.toJsonString());
* if (jsonP) {
* out.write(");");
* }
*
* PHP:
*
* $callback = $_REQUEST['callback'];
*
* // Create the output object.
* $output = array('a' => 'Apple', 'b' => 'Banana');
*
* //start output
* if ($callback) {
* header('Content-Type: text/javascript');
* echo $callback . '(' . json_encode($output) . ');';
* } else {
* header('Content-Type: application/x-json');
* echo json_encode($output);
* }
*
* ASP.net:
*
* String jsonString = "{success: true}";
* String cb = Request.Params.Get("callback");
* String responseString = "";
* if (!String.IsNullOrEmpty(cb)) {
* responseString = cb + "(" + jsonString + ")";
* } else {
* responseString = jsonString;
* }
* Response.Write(responseString);
*/
Ext.define('Ext.data.proxy.JsonP', {
extend: 'Ext.data.proxy.Server',
alternateClassName: 'Ext.data.ScriptTagProxy',
alias: ['proxy.jsonp', 'proxy.scripttag'],
requires: ['Ext.data.JsonP'],
defaultWriterType: 'base',
/**
* @cfg {String} callbackKey
* See {@link Ext.data.JsonP#callbackKey}.
*/
callbackKey : 'callback',
/**
* @cfg {String} recordParam
* The param name to use when passing records to the server (e.g. 'records=someEncodedRecordString'). Defaults to
* 'records'
*/
recordParam: 'records',
/**
* @cfg {Boolean} autoAppendParams
* True to automatically append the request's params to the generated url. Defaults to true
*/
autoAppendParams: true,
constructor: function(){
this.addEvents(
/**
* @event
* Fires when the server returns an exception
* @param {Ext.data.proxy.Proxy} this
* @param {Ext.data.Request} request The request that was sent
* @param {Ext.data.Operation} operation The operation that triggered the request
*/
'exception'
);
this.callParent(arguments);
},
/**
* @private
* Performs the read request to the remote domain. JsonP proxy does not actually create an Ajax request,
* instead we write out a
*
* ## Configuration
*
* This component allows several options for configuring how the target Flash movie is embedded. The most
* important is the required {@link #url} which points to the location of the Flash movie to load. Other
* configurations include:
*
* - {@link #backgroundColor}
* - {@link #wmode}
* - {@link #flashVars}
* - {@link #flashParams}
* - {@link #flashAttributes}
*
* ## Example usage:
*
* var win = Ext.widget('window', {
* title: "It's a tiger!",
* layout: 'fit',
* width: 300,
* height: 300,
* x: 20,
* y: 20,
* resizable: true,
* items: {
* xtype: 'flash',
* url: 'tiger.swf'
* }
* });
* win.show();
*
* ## Express Install
*
* Adobe provides a tool called [Express Install](http://www.adobe.com/devnet/flashplayer/articles/express_install.html)
* that offers users an easy way to upgrade their Flash player. If you wish to make use of this, you should set
* the static EXPRESS\_INSTALL\_URL property to the location of your Express Install SWF file:
*
* Ext.flash.Component.EXPRESS_INSTALL_URL = 'path/to/local/expressInstall.swf';
*
* @docauthor Jason Johnston The subclasses of this class provide actions to perform upon {@link Ext.form.Basic Form}s.
*Instances of this class are only created by a {@link Ext.form.Basic Form} when * the Form needs to perform an action such as submit or load. The Configuration options * listed for this class are set through the Form's action methods: {@link Ext.form.Basic#submit submit}, * {@link Ext.form.Basic#load load} and {@link Ext.form.Basic#doAction doAction}
*The instance of Action which performed the action is passed to the success * and failure callbacks of the Form's action methods ({@link Ext.form.Basic#submit submit}, * {@link Ext.form.Basic#load load} and {@link Ext.form.Basic#doAction doAction}), * and to the {@link Ext.form.Basic#actioncomplete actioncomplete} and * {@link Ext.form.Basic#actionfailed actionfailed} event handlers.
*/ Ext.define('Ext.form.action.Action', { alternateClassName: 'Ext.form.Action', /** * @cfg {Ext.form.Basic} form The {@link Ext.form.Basic BasicForm} instance that * is invoking this Action. Required. */ /** * @cfg {String} url The URL that the Action is to invoke. Will default to the {@link Ext.form.Basic#url url} * configured on the {@link #form}. */ /** * @cfg {Boolean} reset When set to true, causes the Form to be * {@link Ext.form.Basic#reset reset} on Action success. If specified, this happens * before the {@link #success} callback is called and before the Form's * {@link Ext.form.Basic#actioncomplete actioncomplete} event fires. */ /** * @cfg {String} method The HTTP method to use to access the requested URL. Defaults to the * {@link Ext.form.Basic#method BasicForm's method}, or 'POST' if not specified. */ /** * @cfg {Object/String} paramsExtra parameter values to pass. These are added to the Form's * {@link Ext.form.Basic#baseParams} and passed to the specified URL along with the Form's * input fields.
*Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode Ext.Object.toQueryString}.
*/ /** * @cfg {Object} headersExtra headers to be sent in the AJAX request for submit and load actions. See * {@link Ext.data.proxy.Ajax#headers}.
*/ /** * @cfg {Number} timeout The number of seconds to wait for a server response before * failing with the {@link #failureType} as {@link Ext.form.action.Action#CONNECT_FAILURE}. If not specified, * defaults to the configured {@link Ext.form.Basic#timeout timeout} of the * {@link #form}. */ /** * @cfg {Function} success The function to call when a valid success return packet is received. * The function is passed the following parameters:
var fp = new Ext.form.Panel({
...
buttons: [{
text: 'Save',
formBind: true,
handler: function(){
if(fp.getForm().isValid()){
fp.getForm().submit({
url: 'form-submit.php',
waitMsg: 'Submitting your data...',
success: function(form, action){
// server responded with success = true
var result = action.{@link #result};
},
failure: function(form, action){
if (action.{@link #failureType} === {@link Ext.form.action.Action#CONNECT_FAILURE}) {
Ext.Msg.alert('Error',
'Status:'+action.{@link #response}.status+': '+
action.{@link #response}.statusText);
}
if (action.failureType === {@link Ext.form.action.Action#SERVER_INVALID}){
// server responded with success = false
Ext.Msg.alert('Invalid', action.{@link #result}.errormsg);
}
}
});
}
}
},{
text: 'Reset',
handler: function(){
fp.getForm().reset();
}
}]
*
* @property failureType
* @type {String}
*/
/**
* The raw XMLHttpRequest object used to perform the action.
* @property response
* @type {Object}
*/
/**
* The decoded response object containing a boolean success property and
* other, action-specific properties.
* @property result
* @type {Object}
*/
/**
* Creates new Action.
* @param {Object} config (optional) Config object.
*/
constructor: function(config) {
if (config) {
Ext.apply(this, config);
}
// Normalize the params option to an Object
var params = config.params;
if (Ext.isString(params)) {
this.params = Ext.Object.fromQueryString(params);
}
},
/**
* Invokes this action using the current configuration.
*/
run: Ext.emptyFn,
/**
* @private
* @method onSuccess
* Callback method that gets invoked when the action completes successfully. Must be implemented by subclasses.
* @param {Object} response
*/
/**
* @private
* @method handleResponse
* Handles the raw response and builds a result object from it. Must be implemented by subclasses.
* @param {Object} response
*/
/**
* @private
* Handles a failure response.
* @param {Object} response
*/
onFailure : function(response){
this.response = response;
this.failureType = Ext.form.action.Action.CONNECT_FAILURE;
this.form.afterAction(this, false);
},
/**
* @private
* Validates that a response contains either responseText or responseXML and invokes
* {@link #handleResponse} to build the result object.
* @param {Object} response The raw response object.
* @return {Object/Boolean} result The result object as built by handleResponse, or true if
* the response had empty responseText and responseXML.
*/
processResponse : function(response){
this.response = response;
if (!response.responseText && !response.responseXML) {
return true;
}
return (this.result = this.handleResponse(response));
},
/**
* @private
* Build the URL for the AJAX request. Used by the standard AJAX submit and load actions.
* @return {String} The URL.
*/
getUrl: function() {
return this.url || this.form.url;
},
/**
* @private
* Determine the HTTP method to be used for the request.
* @return {String} The HTTP method
*/
getMethod: function() {
return (this.method || this.form.method || 'POST').toUpperCase();
},
/**
* @private
* Get the set of parameters specified in the BasicForm's baseParams and/or the params option.
* Items in params override items of the same name in baseParams.
* @return {Object} the full set of parameters
*/
getParams: function() {
return Ext.apply({}, this.params, this.form.baseParams);
},
/**
* @private
* Creates a callback object.
*/
createCallback: function() {
var me = this,
undef,
form = me.form;
return {
success: me.onSuccess,
failure: me.onFailure,
scope: me,
timeout: (this.timeout * 1000) || (form.timeout * 1000),
upload: form.fileUpload ? me.onSuccess : undef
};
},
statics: {
/**
* @property CLIENT_INVALID
* Failure type returned when client side validation of the Form fails
* thus aborting a submit action. Client side validation is performed unless
* {@link Ext.form.action.Submit#clientValidation} is explicitly set to false.
* @type {String}
* @static
*/
CLIENT_INVALID: 'client',
/**
* @property SERVER_INVALID
* Failure type returned when server side processing fails and the {@link #result}'s * success property is set to false.
*In the case of a form submission, field-specific error messages may be returned in the * {@link #result}'s errors property.
* @type {String} * @static */ SERVER_INVALID: 'server', /** * @property CONNECT_FAILURE * Failure type returned when a communication error happens when attempting * to send a request to the remote server. The {@link #response} may be examined to * provide further information. * @type {String} * @static */ CONNECT_FAILURE: 'connect', /** * @property LOAD_FAILURE * Failure type returned when the response's success * property is set to false, or no field values are returned in the response's * data property. * @type {String} * @static */ LOAD_FAILURE: 'load' } }); /** * @class Ext.form.action.Submit * @extends Ext.form.action.Action *A class which handles submission of data from {@link Ext.form.Basic Form}s * and processes the returned response.
*Instances of this class are only created by a {@link Ext.form.Basic Form} when * {@link Ext.form.Basic#submit submit}ting.
*Response Packet Criteria
*A response packet may contain: *
success
property : Boolean
* success
property is required.errors
property : Object
* errors
property,
* which is optional, contains error messages for invalid fields.JSON Packets
*By default, response packets are assumed to be JSON, so a typical response * packet may look like this:
{
success: false,
errors: {
clientCode: "Client not found",
portOfLoading: "This field must not be null"
}
}
* Other data may be placed into the response for processing by the {@link Ext.form.Basic}'s callback * or event handler methods. The object decoded from this JSON is available in the * {@link Ext.form.action.Action#result result} property.
*Alternatively, if an {@link Ext.form.Basic#errorReader errorReader} is specified as an {@link Ext.data.reader.Xml XmlReader}:
errorReader: new Ext.data.reader.Xml({
record : 'field',
success: '@success'
}, [
'id', 'msg'
]
)
* then the results may be sent back in XML format:
<?xml version="1.0" encoding="UTF-8"?>
<message success="false">
<errors>
<field>
<id>clientCode</id>
<msg><![CDATA[Code not found. <br /><i>This is a test validation message from the server </i>]]></msg>
</field>
<field>
<id>portOfLoading</id>
<msg><![CDATA[Port not found. <br /><i>This is a test validation message from the server </i>]]></msg>
</field>
</errors>
</message>
* Other elements may be placed into the response XML for processing by the {@link Ext.form.Basic}'s callback * or event handler methods. The XML document is available in the {@link Ext.form.Basic#errorReader errorReader}'s * {@link Ext.data.reader.Xml#xmlData xmlData} property.
*/ Ext.define('Ext.form.action.Submit', { extend:'Ext.form.action.Action', alternateClassName: 'Ext.form.Action.Submit', alias: 'formaction.submit', type: 'submit', /** * @cfg {Boolean} clientValidation Determines whether a Form's fields are validated * in a final call to {@link Ext.form.Basic#isValid isValid} prior to submission. * Pass false in the Form's submit options to prevent this. Defaults to true. */ // inherit docs run : function(){ var form = this.form; if (this.clientValidation === false || form.isValid()) { this.doSubmit(); } else { // client validation failed this.failureType = Ext.form.action.Action.CLIENT_INVALID; form.afterAction(this, false); } }, /** * @private * Perform the submit of the form data. */ doSubmit: function() { var formEl, ajaxOptions = Ext.apply(this.createCallback(), { url: this.getUrl(), method: this.getMethod(), headers: this.headers }); // For uploads we need to create an actual form that contains the file upload fields, // and pass that to the ajax call so it can do its iframe-based submit method. if (this.form.hasUpload()) { formEl = ajaxOptions.form = this.buildForm(); ajaxOptions.isUpload = true; } else { ajaxOptions.params = this.getParams(); } Ext.Ajax.request(ajaxOptions); if (formEl) { Ext.removeNode(formEl); } }, /** * @private * Build the full set of parameters from the field values plus any additional configured params. */ getParams: function() { var nope = false, configParams = this.callParent(), fieldParams = this.form.getValues(nope, nope, this.submitEmptyText !== nope); return Ext.apply({}, fieldParams, configParams); }, /** * @private * Build a form element containing fields corresponding to all the parameters to be * submitted (everything returned by {@link #getParams}. * NOTE: the form element is automatically added to the DOM, so any code that uses * it must remove it from the DOM after finishing with it. * @return HTMLFormElement */ buildForm: function() { var fieldsSpec = [], formSpec, formEl, basicForm = this.form, params = this.getParams(), uploadFields = []; basicForm.getFields().each(function(field) { if (field.isFileUpload()) { uploadFields.push(field); } }); function addField(name, val) { fieldsSpec.push({ tag: 'input', type: 'hidden', name: name, value: Ext.String.htmlEncode(val) }); } // Add the form field values Ext.iterate(params, function(key, val) { if (Ext.isArray(val)) { Ext.each(val, function(v) { addField(key, v); }); } else { addField(key, val); } }); formSpec = { tag: 'form', action: this.getUrl(), method: this.getMethod(), target: this.target || '_self', style: 'display:none', cn: fieldsSpec }; // Set the proper encoding for file uploads if (uploadFields.length) { formSpec.encoding = formSpec.enctype = 'multipart/form-data'; } // Create the form formEl = Ext.DomHelper.append(Ext.getBody(), formSpec); // Special handling for file upload fields: since browser security measures prevent setting // their values programatically, and prevent carrying their selected values over when cloning, // we have to move the actual field instances out of their components and into the form. Ext.Array.each(uploadFields, function(field) { if (field.rendered) { // can only have a selected file value after being rendered formEl.appendChild(field.extractFileInput()); } }); return formEl; }, /** * @private */ onSuccess: function(response) { var form = this.form, success = true, result = this.processResponse(response); if (result !== true && !result.success) { if (result.errors) { form.markInvalid(result.errors); } this.failureType = Ext.form.action.Action.SERVER_INVALID; success = false; } form.afterAction(this, success); }, /** * @private */ handleResponse: function(response) { var form = this.form, errorReader = form.errorReader, rs, errors, i, len, records; if (errorReader) { rs = errorReader.read(response); records = rs.records; errors = []; if (records) { for(i = 0, len = records.length; i < len; i++) { errors[i] = records[i].data; } } if (errors.length < 1) { errors = null; } return { success : rs.success, errors : errors }; } return Ext.decode(response.responseText); } }); /** * @class Ext.util.ComponentDragger * @extends Ext.dd.DragTracker *A subclass of Ext.dd.DragTracker which handles dragging any Component.
*This is configured with a Component to be made draggable, and a config object for the * {@link Ext.dd.DragTracker} class.
*A {@link #delegate} may be provided which may be either the element to use as the mousedown target * or a {@link Ext.DomQuery} selector to activate multiple mousedown targets.
*/ Ext.define('Ext.util.ComponentDragger', { /** * @cfg {Boolean} constrain * Specify astrue
to constrain the Component to within the bounds of the {@link #constrainTo} region.
*/
/**
* @cfg {String/Ext.Element} delegate
* Optional. A {@link Ext.DomQuery DomQuery} selector which identifies child elements within the Component's encapsulating * Element which are the drag handles. This limits dragging to only begin when the matching elements are mousedowned.
*This may also be a specific child element within the Component's encapsulating element to use as the drag handle.
*/ /** * @cfg {Boolean} constrainDelegate * Specify astrue
to constrain the drag handles within the {@link #constrainTo} region.
*/
extend: 'Ext.dd.DragTracker',
autoStart: 500,
/**
* Creates new ComponentDragger.
* @param {Object} comp The Component to provide dragging for.
* @param {Object} config (optional) Config object
*/
constructor: function(comp, config) {
this.comp = comp;
this.initialConstrainTo = config.constrainTo;
this.callParent([ config ]);
},
onStart: function(e) {
var me = this,
comp = me.comp;
// Cache the start [X, Y] array
this.startPosition = comp.getPosition();
// If client Component has a ghost method to show a lightweight version of itself
// then use that as a drag proxy unless configured to liveDrag.
if (comp.ghost && !comp.liveDrag) {
me.proxy = comp.ghost();
me.dragTarget = me.proxy.header.el;
}
// Set the constrainTo Region before we start dragging.
if (me.constrain || me.constrainDelegate) {
me.constrainTo = me.calculateConstrainRegion();
}
},
calculateConstrainRegion: function() {
var me = this,
comp = me.comp,
c = me.initialConstrainTo,
delegateRegion,
elRegion,
shadowSize = comp.el.shadow ? comp.el.shadow.offset : 0;
// The configured constrainTo might be a Region or an element
if (!(c instanceof Ext.util.Region)) {
c = Ext.fly(c).getViewRegion();
}
// Reduce the constrain region to allow for shadow
if (shadowSize) {
c.adjust(0, -shadowSize, -shadowSize, shadowSize);
}
// If they only want to constrain the *delegate* to within the constrain region,
// adjust the region to be larger based on the insets of the delegate from the outer
// edges of the Component.
if (!me.constrainDelegate) {
delegateRegion = Ext.fly(me.dragTarget).getRegion();
elRegion = me.proxy ? me.proxy.el.getRegion() : comp.el.getRegion();
c.adjust(
delegateRegion.top - elRegion.top,
delegateRegion.right - elRegion.right,
delegateRegion.bottom - elRegion.bottom,
delegateRegion.left - elRegion.left
);
}
return c;
},
// Move either the ghost Component or the target Component to its new position on drag
onDrag: function(e) {
var me = this,
comp = (me.proxy && !me.comp.liveDrag) ? me.proxy : me.comp,
offset = me.getOffset(me.constrain || me.constrainDelegate ? 'dragTarget' : null);
comp.setPosition(me.startPosition[0] + offset[0], me.startPosition[1] + offset[1]);
},
onEnd: function(e) {
if (this.proxy && !this.comp.liveDrag) {
this.comp.unghost();
}
}
});
/**
* A mixin which allows a component to be configured and decorated with a label and/or error message as is
* common for form fields. This is used by e.g. Ext.form.field.Base and Ext.form.FieldContainer
* to let them be managed by the Field layout.
*
* NOTE: This mixin is mainly for internal library use and most users should not need to use it directly. It
* is more likely you will want to use one of the component classes that import this mixin, such as
* Ext.form.field.Base or Ext.form.FieldContainer.
*
* Use of this mixin does not make a component a field in the logical sense, meaning it does not provide any
* logic or state related to values or validation; that is handled by the related Ext.form.field.Field
* mixin. These two mixins may be used separately (for example Ext.form.FieldContainer is Labelable but not a
* Field), or in combination (for example Ext.form.field.Base implements both and has logic for connecting the
* two.)
*
* Component classes which use this mixin should use the Field layout
* or a derivation thereof to properly size and position the label and message according to the component config.
* They must also call the {@link #initLabelable} method during component initialization to ensure the mixin gets
* set up correctly.
*
* @docauthor Jason Johnston Controls the position and alignment of the {@link #fieldLabel}. Valid values are:
*When set to true, the label element ({@link #fieldLabel} and {@link #labelSeparator}) will be * automatically hidden if the {@link #fieldLabel} is empty. Setting this to false will cause the empty * label element to be rendered and space to be reserved for it; this is useful if you want a field without a label * to line up with other labeled fields in the same form.
*If you wish to unconditionall hide the label even if a non-empty fieldLabel is configured, then set * the {@link #hideLabel} config to true.
*/ hideEmptyLabel: true, /** * @cfg {Boolean} preventMark * true to disable displaying any {@link #setActiveError error message} set on this object. */ preventMark: false, /** * @cfg {Boolean} autoFitErrors * Whether to adjust the component's body area to make room for 'side' or 'under' * {@link #msgTarget error messages}. */ autoFitErrors: true, /** * @cfg {String} msgTargetThe location where the error message text should display. * Must be one of the following values:
*qtip
Display a quick tip containing the message when the user hovers over the field. This is the default.
* title
Display the message in a default browser title attribute popup.under
Add a block div beneath the field containing the error message.side
Add an error icon to the right of the field, displaying the message in a popup on hover.none
Don't display any error message. This might be useful if you are implementing custom error display.[element id]
Add the error message directly to the innerHTML of the specified element.A class which handles loading of data from a server into the Fields of an {@link Ext.form.Basic}.
*Instances of this class are only created by a {@link Ext.form.Basic Form} when * {@link Ext.form.Basic#load load}ing.
*Response Packet Criteria
*A response packet must contain: *
success
property : Booleandata
property : Objectdata
property contains the values of Fields to load.
* The individual value object for each Field is passed to the Field's
* {@link Ext.form.field.Field#setValue setValue} method.JSON Packets
*By default, response packets are assumed to be JSON, so for the following form load call:
var myFormPanel = new Ext.form.Panel({
title: 'Client and routing info',
items: [{
fieldLabel: 'Client',
name: 'clientName'
}, {
fieldLabel: 'Port of loading',
name: 'portOfLoading'
}, {
fieldLabel: 'Port of discharge',
name: 'portOfDischarge'
}]
});
myFormPanel.{@link Ext.form.Panel#getForm getForm}().{@link Ext.form.Basic#load load}({
url: '/getRoutingInfo.php',
params: {
consignmentRef: myConsignmentRef
},
failure: function(form, action) {
Ext.Msg.alert("Load failed", action.result.errorMessage);
}
});
* a success response packet may look like this:
{
success: true,
data: {
clientName: "Fred. Olsen Lines",
portOfLoading: "FXT",
portOfDischarge: "OSL"
}
}
* while a failure response packet may look like this:
{
success: false,
errorMessage: "Consignment reference not found"
}
* Other data may be placed into the response for processing the {@link Ext.form.Basic Form}'s * callback or event handler methods. The object decoded from this JSON is available in the * {@link Ext.form.action.Action#result result} property.
*/ Ext.define('Ext.form.action.Load', { extend:'Ext.form.action.Action', requires: ['Ext.data.Connection'], alternateClassName: 'Ext.form.Action.Load', alias: 'formaction.load', type: 'load', /** * @private */ run: function() { Ext.Ajax.request(Ext.apply( this.createCallback(), { method: this.getMethod(), url: this.getUrl(), headers: this.headers, params: this.getParams() } )); }, /** * @private */ onSuccess: function(response){ var result = this.processResponse(response), form = this.form; if (result === true || !result.success || !result.data) { this.failureType = Ext.form.action.Action.LOAD_FAILURE; form.afterAction(this, false); return; } form.clearInvalid(); form.setValues(result.data); form.afterAction(this, true); }, /** * @private */ handleResponse: function(response) { var reader = this.form.reader, rs, data; if (reader) { rs = reader.read(response); data = rs.records && rs.records[0] ? rs.records[0].data : null; return { success : rs.success, data : data }; } return Ext.decode(response.responseText); } }); /** * A specialized panel intended for use as an application window. Windows are floated, {@link #resizable}, and * {@link #draggable} by default. Windows can be {@link #maximizable maximized} to fill the viewport, restored to * their prior size, and can be {@link #minimize}d. * * Windows can also be linked to a {@link Ext.ZIndexManager} or managed by the {@link Ext.WindowManager} to provide * grouping, activation, to front, to back and other application-specific behavior. * * By default, Windows will be rendered to document.body. To {@link #constrain} a Window to another element specify * {@link Ext.Component#renderTo renderTo}. * * **As with all {@link Ext.container.Container Container}s, it is important to consider how you want the Window to size * and arrange any child Components. Choose an appropriate {@link #layout} configuration which lays out child Components * in the required manner.** * * @example * Ext.create('Ext.window.Window', { * title: 'Hello', * height: 200, * width: 400, * layout: 'fit', * items: { // Let's put an empty grid in just to illustrate fit layout * xtype: 'grid', * border: false, * columns: [{header: 'World'}], // One header just for show. There's no data, * store: Ext.create('Ext.data.ArrayStore', {}) // A dummy empty data store * } * }).show(); */ Ext.define('Ext.window.Window', { extend: 'Ext.panel.Panel', alternateClassName: 'Ext.Window', requires: ['Ext.util.ComponentDragger', 'Ext.util.Region', 'Ext.EventManager'], alias: 'widget.window', /** * @cfg {Number} x * The X position of the left edge of the window on initial showing. Defaults to centering the Window within the * width of the Window's container {@link Ext.Element Element} (The Element that the Window is rendered to). */ /** * @cfg {Number} y * The Y position of the top edge of the window on initial showing. Defaults to centering the Window within the * height of the Window's container {@link Ext.Element Element} (The Element that the Window is rendered to). */ /** * @cfg {Boolean} [modal=false] * True to make the window modal and mask everything behind it when displayed, false to display it without * restricting access to other UI elements. */ /** * @cfg {String/Ext.Element} [animateTarget=null] * Id or element from which the window should animate while opening. */ /** * @cfg {String/Number/Ext.Component} defaultFocus * Specifies a Component to receive focus when this Window is focused. * * This may be one of: * * - The index of a footer Button. * - The id or {@link Ext.AbstractComponent#itemId} of a descendant Component. * - A Component. */ /** * @cfg {Function} onEsc * Allows override of the built-in processing for the escape key. Default action is to close the Window (performing * whatever action is specified in {@link #closeAction}. To prevent the Window closing when the escape key is * pressed, specify this as {@link Ext#emptyFn Ext.emptyFn}. */ /** * @cfg {Boolean} [collapsed=false] * True to render the window collapsed, false to render it expanded. Note that if {@link #expandOnShow} * is true (the default) it will override the `collapsed` config and the window will always be * expanded when shown. */ /** * @cfg {Boolean} [maximized=false] * True to initially display the window in a maximized state. */ /** * @cfg {String} [baseCls='x-window'] * The base CSS class to apply to this panel's element. */ baseCls: Ext.baseCSSPrefix + 'window', /** * @cfg {Boolean/Object} resizable * Specify as `true` to allow user resizing at each edge and corner of the window, false to disable resizing. * * This may also be specified as a config object to Ext.resizer.Resizer */ resizable: true, /** * @cfg {Boolean} draggable * True to allow the window to be dragged by the header bar, false to disable dragging. Note that * by default the window will be centered in the viewport, so if dragging is disabled the window may need to be * positioned programmatically after render (e.g., myWindow.setPosition(100, 100);). */ draggable: true, /** * @cfg {Boolean} constrain * True to constrain the window within its containing element, false to allow it to fall outside of its containing * element. By default the window will be rendered to document.body. To render and constrain the window within * another element specify {@link #renderTo}. Optionally the header only can be constrained * using {@link #constrainHeader}. */ constrain: false, /** * @cfg {Boolean} constrainHeader * True to constrain the window header within its containing element (allowing the window body to fall outside of * its containing element) or false to allow the header to fall outside its containing element. * Optionally the entire window can be constrained using {@link #constrain}. */ constrainHeader: false, /** * @cfg {Boolean} plain * True to render the window body with a transparent background so that it will blend into the framing elements, * false to add a lighter background color to visually highlight the body element and separate it more distinctly * from the surrounding frame. */ plain: false, /** * @cfg {Boolean} minimizable * True to display the 'minimize' tool button and allow the user to minimize the window, false to hide the button * and disallow minimizing the window. Note that this button provides no implementation -- the * behavior of minimizing a window is implementation-specific, so the minimize event must be handled and a custom * minimize behavior implemented for this option to be useful. */ minimizable: false, /** * @cfg {Boolean} maximizable * True to display the 'maximize' tool button and allow the user to maximize the window, false to hide the button * and disallow maximizing the window. Note that when a window is maximized, the tool button * will automatically change to a 'restore' button with the appropriate behavior already built-in that will restore * the window to its previous size. */ maximizable: false, // inherit docs minHeight: 100, // inherit docs minWidth: 200, /** * @cfg {Boolean} expandOnShow * True to always expand the window when it is displayed, false to keep it in its current state (which may be * {@link #collapsed}) when displayed. */ expandOnShow: true, // inherited docs, same default collapsible: false, /** * @cfg {Boolean} closable * True to display the 'close' tool button and allow the user to close the window, false to hide the button and * disallow closing the window. * * By default, when close is requested by either clicking the close button in the header or pressing ESC when the * Window has focus, the {@link #close} method will be called. This will _{@link Ext.Component#destroy destroy}_ the * Window and its content meaning that it may not be reused. * * To make closing a Window _hide_ the Window so that it may be reused, set {@link #closeAction} to 'hide'. */ closable: true, /** * @cfg {Boolean} hidden * Render this Window hidden. If `true`, the {@link #hide} method will be called internally. */ hidden: true, // Inherit docs from Component. Windows render to the body on first show. autoRender: true, // Inherit docs from Component. Windows hide using visibility. hideMode: 'visibility', /** @cfg {Boolean} floating @hide Windows are always floating*/ floating: true, ariaRole: 'alertdialog', itemCls: 'x-window-item', overlapHeader: true, ignoreHeaderBorderManagement: true, // private initComponent: function() { var me = this; me.callParent(); me.addEvents( /** * @event activate * Fires after the window has been visually activated via {@link #setActive}. * @param {Ext.window.Window} this */ /** * @event deactivate * Fires after the window has been visually deactivated via {@link #setActive}. * @param {Ext.window.Window} this */ /** * @event resize * Fires after the window has been resized. * @param {Ext.window.Window} this * @param {Number} width The window's new width * @param {Number} height The window's new height */ 'resize', /** * @event maximize * Fires after the window has been maximized. * @param {Ext.window.Window} this */ 'maximize', /** * @event minimize * Fires after the window has been minimized. * @param {Ext.window.Window} this */ 'minimize', /** * @event restore * Fires after the window has been restored to its original size after being maximized. * @param {Ext.window.Window} this */ 'restore' ); if (me.plain) { me.addClsWithUI('plain'); } if (me.modal) { me.ariaRole = 'dialog'; } }, // State Management // private initStateEvents: function(){ var events = this.stateEvents; // push on stateEvents if they don't exist Ext.each(['maximize', 'restore', 'resize', 'dragend'], function(event){ if (Ext.Array.indexOf(events, event)) { events.push(event); } }); this.callParent(); }, getState: function() { var me = this, state = me.callParent() || {}, maximized = !!me.maximized; state.maximized = maximized; Ext.apply(state, { size: maximized ? me.restoreSize : me.getSize(), pos: maximized ? me.restorePos : me.getPosition() }); return state; }, applyState: function(state){ var me = this; if (state) { me.maximized = state.maximized; if (me.maximized) { me.hasSavedRestore = true; me.restoreSize = state.size; me.restorePos = state.pos; } else { Ext.apply(me, { width: state.size.width, height: state.size.height, x: state.pos[0], y: state.pos[1] }); } } }, // private onMouseDown: function (e) { var preventFocus; if (this.floating) { if (Ext.fly(e.getTarget()).focusable()) { preventFocus = true; } this.toFront(preventFocus); } }, // private onRender: function(ct, position) { var me = this; me.callParent(arguments); me.focusEl = me.el; // Double clicking a header will toggleMaximize if (me.maximizable) { me.header.on({ dblclick: { fn: me.toggleMaximize, element: 'el', scope: me } }); } }, // private afterRender: function() { var me = this, hidden = me.hidden, keyMap; me.hidden = false; // Component's afterRender sizes and positions the Component me.callParent(); me.hidden = hidden; // Create the proxy after the size has been applied in Component.afterRender me.proxy = me.getProxy(); // clickToRaise me.mon(me.el, 'mousedown', me.onMouseDown, me); // allow the element to be focusable me.el.set({ tabIndex: -1 }); // Initialize if (me.maximized) { me.maximized = false; me.maximize(); } if (me.closable) { keyMap = me.getKeyMap(); keyMap.on(27, me.onEsc, me); //if (hidden) { ? would be consistent w/before/afterShow... keyMap.disable(); //} } if (!hidden) { me.syncMonitorWindowResize(); me.doConstrain(); } }, /** * @private * @override * Override Component.initDraggable. * Window uses the header element as the delegate. */ initDraggable: function() { var me = this, ddConfig; if (!me.header) { me.updateHeader(true); } /* * Check the header here again. If for whatever reason it wasn't created in * updateHeader (preventHeader) then we'll just ignore the rest since the * header acts as the drag handle. */ if (me.header) { ddConfig = Ext.applyIf({ el: me.el, delegate: '#' + me.header.id }, me.draggable); // Add extra configs if Window is specified to be constrained if (me.constrain || me.constrainHeader) { ddConfig.constrain = me.constrain; ddConfig.constrainDelegate = me.constrainHeader; ddConfig.constrainTo = me.constrainTo || me.container; } /** * @property {Ext.util.ComponentDragger} dd * If this Window is configured {@link #draggable}, this property will contain an instance of * {@link Ext.util.ComponentDragger} (A subclass of {@link Ext.dd.DragTracker DragTracker}) which handles dragging * the Window's DOM Element, and constraining according to the {@link #constrain} and {@link #constrainHeader} . * * This has implementations of `onBeforeStart`, `onDrag` and `onEnd` which perform the dragging action. If * extra logic is needed at these points, use {@link Ext.Function#createInterceptor createInterceptor} or * {@link Ext.Function#createSequence createSequence} to augment the existing implementations. */ me.dd = Ext.create('Ext.util.ComponentDragger', this, ddConfig); me.relayEvents(me.dd, ['dragstart', 'drag', 'dragend']); } }, // private onEsc: function(k, e) { e.stopEvent(); this[this.closeAction](); }, // private beforeDestroy: function() { var me = this; if (me.rendered) { delete this.animateTarget; me.hide(); Ext.destroy( me.keyMap ); } me.callParent(); }, /** * @private * @override * Contribute class-specific tools to the header. * Called by Panel's initTools. */ addTools: function() { var me = this; // Call Panel's initTools me.callParent(); if (me.minimizable) { me.addTool({ type: 'minimize', handler: Ext.Function.bind(me.minimize, me, []) }); } if (me.maximizable) { me.addTool({ type: 'maximize', handler: Ext.Function.bind(me.maximize, me, []) }); me.addTool({ type: 'restore', handler: Ext.Function.bind(me.restore, me, []), hidden: true }); } }, /** * Gets the configured default focus item. If a {@link #defaultFocus} is set, it will receive focus, otherwise the * Container itself will receive focus. */ getFocusEl: function() { var me = this, f = me.focusEl, defaultComp = me.defaultButton || me.defaultFocus, t = typeof db, el, ct; if (Ext.isDefined(defaultComp)) { if (Ext.isNumber(defaultComp)) { f = me.query('button')[defaultComp]; } else if (Ext.isString(defaultComp)) { f = me.down('#' + defaultComp); } else { f = defaultComp; } } return f || me.focusEl; }, // private beforeShow: function() { this.callParent(); if (this.expandOnShow) { this.expand(false); } }, // private afterShow: function(animateTarget) { var me = this, animating = animateTarget || me.animateTarget; // No constraining code needs to go here. // Component.onShow constrains the Component. *If the constrain config is true* // Perform superclass's afterShow tasks // Which might include animating a proxy from an animateTarget me.callParent(arguments); if (me.maximized) { me.fitContainer(); } me.syncMonitorWindowResize(); if (!animating) { me.doConstrain(); } if (me.keyMap) { me.keyMap.enable(); } }, // private doClose: function() { var me = this; // Being called as callback after going through the hide call below if (me.hidden) { me.fireEvent('close', me); if (me.closeAction == 'destroy') { this.destroy(); } } else { // close after hiding me.hide(me.animateTarget, me.doClose, me); } }, // private afterHide: function() { var me = this; // No longer subscribe to resizing now that we're hidden me.syncMonitorWindowResize(); // Turn off keyboard handling once window is hidden if (me.keyMap) { me.keyMap.disable(); } // Perform superclass's afterHide tasks. me.callParent(arguments); }, // private onWindowResize: function() { if (this.maximized) { this.fitContainer(); } this.doConstrain(); }, /** * Placeholder method for minimizing the window. By default, this method simply fires the {@link #minimize} event * since the behavior of minimizing a window is application-specific. To implement custom minimize behavior, either * the minimize event can be handled or this method can be overridden. * @return {Ext.window.Window} this */ minimize: function() { this.fireEvent('minimize', this); return this; }, afterCollapse: function() { var me = this; if (me.maximizable) { me.tools.maximize.hide(); me.tools.restore.hide(); } if (me.resizer) { me.resizer.disable(); } me.callParent(arguments); }, afterExpand: function() { var me = this; if (me.maximized) { me.tools.restore.show(); } else if (me.maximizable) { me.tools.maximize.show(); } if (me.resizer) { me.resizer.enable(); } me.callParent(arguments); }, /** * Fits the window within its current container and automatically replaces the {@link #maximizable 'maximize' tool * button} with the 'restore' tool button. Also see {@link #toggleMaximize}. * @return {Ext.window.Window} this */ maximize: function() { var me = this; if (!me.maximized) { me.expand(false); if (!me.hasSavedRestore) { me.restoreSize = me.getSize(); me.restorePos = me.getPosition(true); } if (me.maximizable) { me.tools.maximize.hide(); me.tools.restore.show(); } me.maximized = true; me.el.disableShadow(); if (me.dd) { me.dd.disable(); } if (me.collapseTool) { me.collapseTool.hide(); } me.el.addCls(Ext.baseCSSPrefix + 'window-maximized'); me.container.addCls(Ext.baseCSSPrefix + 'window-maximized-ct'); me.syncMonitorWindowResize(); me.setPosition(0, 0); me.fitContainer(); me.fireEvent('maximize', me); } return me; }, /** * Restores a {@link #maximizable maximized} window back to its original size and position prior to being maximized * and also replaces the 'restore' tool button with the 'maximize' tool button. Also see {@link #toggleMaximize}. * @return {Ext.window.Window} this */ restore: function() { var me = this, tools = me.tools; if (me.maximized) { delete me.hasSavedRestore; me.removeCls(Ext.baseCSSPrefix + 'window-maximized'); // Toggle tool visibility if (tools.restore) { tools.restore.hide(); } if (tools.maximize) { tools.maximize.show(); } if (me.collapseTool) { me.collapseTool.show(); } // Restore the position/sizing me.setPosition(me.restorePos); me.setSize(me.restoreSize); // Unset old position/sizing delete me.restorePos; delete me.restoreSize; me.maximized = false; me.el.enableShadow(true); // Allow users to drag and drop again if (me.dd) { me.dd.enable(); } me.container.removeCls(Ext.baseCSSPrefix + 'window-maximized-ct'); me.syncMonitorWindowResize(); me.doConstrain(); me.fireEvent('restore', me); } return me; }, /** * Synchronizes the presence of our listener for window resize events. This method * should be called whenever this status might change. * @private */ syncMonitorWindowResize: function () { var me = this, currentlyMonitoring = me._monitoringResize, // all the states where we should be listening to window resize: yes = me.monitorResize || me.constrain || me.constrainHeader || me.maximized, // all the states where we veto this: veto = me.hidden || me.destroying || me.isDestroyed; if (yes && !veto) { // we should be listening... if (!currentlyMonitoring) { // but we aren't, so set it up Ext.EventManager.onWindowResize(me.onWindowResize, me); me._monitoringResize = true; } } else if (currentlyMonitoring) { // we should not be listening, but we are, so tear it down Ext.EventManager.removeResizeListener(me.onWindowResize, me); me._monitoringResize = false; } }, /** * A shortcut method for toggling between {@link #maximize} and {@link #restore} based on the current maximized * state of the window. * @return {Ext.window.Window} this */ toggleMaximize: function() { return this[this.maximized ? 'restore': 'maximize'](); } /** * @cfg {Boolean} autoWidth @hide * Absolute positioned element and therefore cannot support autoWidth. * A width is a required configuration. **/ }); /** * @docauthor Jason Johnston{@link #regex}
test will be processed.
* The invalid message for this test is configured with `{@link #regexText}`
*
* @param {Object} value The value to validate. The processed raw value will be used if nothing is passed.
* @return {String[]} Array of any validation errors
*/
getErrors: function(value) {
var me = this,
errors = me.callParent(arguments),
validator = me.validator,
emptyText = me.emptyText,
allowBlank = me.allowBlank,
vtype = me.vtype,
vtypes = Ext.form.field.VTypes,
regex = me.regex,
format = Ext.String.format,
msg;
value = value || me.processRawValue(me.getRawValue());
if (Ext.isFunction(validator)) {
msg = validator.call(me, value);
if (msg !== true) {
errors.push(msg);
}
}
if (value.length < 1 || value === emptyText) {
if (!allowBlank) {
errors.push(me.blankText);
}
//if value is blank, there cannot be any additional errors
return errors;
}
if (value.length < me.minLength) {
errors.push(format(me.minLengthText, me.minLength));
}
if (value.length > me.maxLength) {
errors.push(format(me.maxLengthText, me.maxLength));
}
if (vtype) {
if(!vtypes[vtype](value, me)){
errors.push(me.vtypeText || vtypes[vtype +'Text']);
}
}
if (regex && !regex.test(value)) {
errors.push(me.regexText || me.invalidText);
}
return errors;
},
/**
* Selects text in this field
* @param {Number} [start=0] The index where the selection should start
* @param {Number} [end] The index where the selection should end (defaults to the text length)
*/
selectText : function(start, end){
var me = this,
v = me.getRawValue(),
doFocus = true,
el = me.inputEl.dom,
undef,
range;
if (v.length > 0) {
start = start === undef ? 0 : start;
end = end === undef ? v.length : end;
if (el.setSelectionRange) {
el.setSelectionRange(start, end);
}
else if(el.createTextRange) {
range = el.createTextRange();
range.moveStart('character', start);
range.moveEnd('character', end - v.length);
range.select();
}
doFocus = Ext.isGecko || Ext.isOpera;
}
if (doFocus) {
me.focus();
}
},
/**
* Automatically grows the field to accomodate the width of the text up to the maximum field width allowed. This
* only takes effect if {@link #grow} = true, and fires the {@link #autosize} event if the width changes.
*/
autoSize: function() {
var me = this,
width;
if (me.grow && me.rendered) {
me.doComponentLayout();
width = me.inputEl.getWidth();
if (width !== me.lastInputWidth) {
me.fireEvent('autosize', width);
me.lastInputWidth = width;
}
}
},
initAria: function() {
this.callParent();
this.getActionEl().dom.setAttribute('aria-required', this.allowBlank === false);
},
/**
* To get the natural width of the inputEl, we do a simple calculation based on the 'size' config. We use
* hard-coded numbers to approximate what browsers do natively, to avoid having to read any styles which would hurt
* performance. Overrides Labelable method.
* @protected
*/
getBodyNaturalWidth: function() {
return Math.round(this.size * 6.5) + 20;
}
});
/**
* @docauthor Robert Dougan Progress and wait dialogs will ignore this option since they do not respond to user * actions and can only be closed programmatically, so any required function should be called * by the same code after it closes the dialog. Parameters passed:
this
reference) in which the function will be executed.
Ext.Msg.show({
title: 'Address',
msg: 'Please enter your address:',
width: 300,
buttons: Ext.Msg.OKCANCEL,
multiline: true,
fn: saveAddress,
animateTarget: 'addAddressBtn',
icon: Ext.window.MessageBox.INFO
});
* @return {Ext.window.MessageBox} this
*/
show: function(cfg) {
var me = this;
me.reconfigure(cfg);
me.addCls(cfg.cls);
if (cfg.animateTarget) {
me.doAutoSize(true);
me.callParent();
} else {
me.callParent();
me.doAutoSize(true);
}
return me;
},
afterShow: function(){
if (this.animateTarget) {
this.center();
}
this.callParent(arguments);
},
doAutoSize: function(center) {
var me = this,
icon = me.iconComponent,
iconHeight = me.iconHeight;
if (!Ext.isDefined(me.frameWidth)) {
me.frameWidth = me.el.getWidth() - me.body.getWidth();
}
// reset to the original dimensions
icon.setHeight(iconHeight);
// Allow per-invocation override of minWidth
me.minWidth = me.cfg.minWidth || Ext.getClass(this).prototype.minWidth;
// Set best possible size based upon allowing the text to wrap in the maximized Window, and
// then constraining it to within the max with. Then adding up constituent element heights.
me.topContainer.doLayout();
if (Ext.isIE6 || Ext.isIEQuirks) {
// In IE quirks, the initial full width of the prompt fields will prevent the container element
// from collapsing once sized down, so temporarily force them to a small width. They'll get
// layed out to their final width later when setting the final window size.
me.textField.setCalculatedSize(9);
me.textArea.setCalculatedSize(9);
}
var width = me.cfg.width || me.msg.getWidth() + icon.getWidth() + 25, /* topContainer's layout padding */
height = (me.header.rendered ? me.header.getHeight() : 0) +
Math.max(me.promptContainer.getHeight(), icon.getHeight()) +
me.progressBar.getHeight() +
(me.bottomTb.rendered ? me.bottomTb.getHeight() : 0) + 20 ;/* topContainer's layout padding */
// Update to the size of the content, this way the text won't wrap under the icon.
icon.setHeight(Math.max(iconHeight, me.msg.getHeight()));
me.setSize(width + me.frameWidth, height + me.frameWidth);
if (center) {
me.center();
}
return me;
},
updateText: function(text) {
this.msg.update(text);
return this.doAutoSize(true);
},
/**
* Adds the specified icon to the dialog. By default, the class 'ext-mb-icon' is applied for default
* styling, and the class passed in is expected to supply the background image url. Pass in empty string ('')
* to clear any existing icon. This method must be called before the MessageBox is shown.
* The following built-in icon classes are supported, but you can also pass in a custom class name:
* Ext.window.MessageBox.INFO Ext.window.MessageBox.WARNING Ext.window.MessageBox.QUESTION Ext.window.MessageBox.ERROR ** @param {String} icon A CSS classname specifying the icon's background image url, or empty string to clear the icon * @return {Ext.window.MessageBox} this */ setIcon : function(icon) { var me = this; me.iconComponent.removeCls(me.iconCls); if (icon) { me.iconComponent.show(); me.iconComponent.addCls(Ext.baseCSSPrefix + 'dlg-icon'); me.iconComponent.addCls(me.iconCls = icon); } else { me.iconComponent.removeCls(Ext.baseCSSPrefix + 'dlg-icon'); me.iconComponent.hide(); } return me; }, /** * Updates a progress-style message box's text and progress bar. Only relevant on message boxes * initiated via {@link Ext.window.MessageBox#progress} or {@link Ext.window.MessageBox#wait}, * or by calling {@link Ext.window.MessageBox#show} with progress: true. * @param {Number} [value=0] Any number between 0 and 1 (e.g., .5) * @param {String} [progressText=''] The progress text to display inside the progress bar. * @param {String} [msg] The message box's body text is replaced with the specified string (defaults to undefined * so that any existing body text will not get overwritten by default unless a new value is passed in) * @return {Ext.window.MessageBox} this */ updateProgress : function(value, progressText, msg){ this.progressBar.updateProgress(value, progressText); if (msg){ this.updateText(msg); } return this; }, onEsc: function() { if (this.closable !== false) { this.callParent(arguments); } }, /** * Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's confirm). * If a callback function is passed it will be called after the user clicks either button, * and the id of the button that was clicked will be passed as the only parameter to the callback * (could also be the top-right close button). * @param {String} title The title bar text * @param {String} msg The message box body text * @param {Function} fn (optional) The callback function invoked after the message box is closed * @param {Object} scope (optional) The scope (
this
reference) in which the callback is executed. Defaults to the browser wnidow.
* @return {Ext.window.MessageBox} this
*/
confirm: function(cfg, msg, fn, scope) {
if (Ext.isString(cfg)) {
cfg = {
title: cfg,
icon: 'ext-mb-question',
msg: msg,
buttons: this.YESNO,
callback: fn,
scope: scope
};
}
return this.show(cfg);
},
/**
* Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to JavaScript's prompt).
* The prompt can be a single-line or multi-line textbox. If a callback function is passed it will be called after the user
* clicks either button, and the id of the button that was clicked (could also be the top-right
* close button) and the text that was entered will be passed as the two parameters to the callback.
* @param {String} title The title bar text
* @param {String} msg The message box body text
* @param {Function} [fn] The callback function invoked after the message box is closed
* @param {Object} [scope] The scope (this
reference) in which the callback is executed. Defaults to the browser wnidow.
* @param {Boolean/Number} [multiline=false] True to create a multiline textbox using the defaultTextHeight
* property, or the height in pixels to create the textbox/
* @param {String} [value=''] Default value of the text input element
* @return {Ext.window.MessageBox} this
*/
prompt : function(cfg, msg, fn, scope, multiline, value){
if (Ext.isString(cfg)) {
cfg = {
prompt: true,
title: cfg,
minWidth: this.minPromptWidth,
msg: msg,
buttons: this.OKCANCEL,
callback: fn,
scope: scope,
multiline: multiline,
value: value
};
}
return this.show(cfg);
},
/**
* Displays a message box with an infinitely auto-updating progress bar. This can be used to block user
* interaction while waiting for a long-running process to complete that does not have defined intervals.
* You are responsible for closing the message box when the process is complete.
* @param {String} msg The message box body text
* @param {String} title (optional) The title bar text
* @param {Object} config (optional) A {@link Ext.ProgressBar#wait} config object
* @return {Ext.window.MessageBox} this
*/
wait : function(cfg, title, config){
if (Ext.isString(cfg)) {
cfg = {
title : title,
msg : cfg,
closable: false,
wait: true,
modal: true,
minWidth: this.minProgressWidth,
waitConfig: config
};
}
return this.show(cfg);
},
/**
* Displays a standard read-only message box with an OK button (comparable to the basic JavaScript alert prompt).
* If a callback function is passed it will be called after the user clicks the button, and the
* id of the button that was clicked will be passed as the only parameter to the callback
* (could also be the top-right close button).
* @param {String} title The title bar text
* @param {String} msg The message box body text
* @param {Function} fn (optional) The callback function invoked after the message box is closed
* @param {Object} scope (optional) The scope (this
reference) in which the callback is executed. Defaults to the browser wnidow.
* @return {Ext.window.MessageBox} this
*/
alert: function(cfg, msg, fn, scope) {
if (Ext.isString(cfg)) {
cfg = {
title : cfg,
msg : msg,
buttons: this.OK,
fn: fn,
scope : scope,
minWidth: this.minWidth
};
}
return this.show(cfg);
},
/**
* Displays a message box with a progress bar. This message box has no buttons and is not closeable by
* the user. You are responsible for updating the progress bar as needed via {@link Ext.window.MessageBox#updateProgress}
* and closing the message box when the process is complete.
* @param {String} title The title bar text
* @param {String} msg The message box body text
* @param {String} [progressText=''] The text to display inside the progress bar
* @return {Ext.window.MessageBox} this
*/
progress : function(cfg, msg, progressText){
if (Ext.isString(cfg)) {
cfg = {
title: cfg,
msg: msg,
progress: true,
progressText: progressText
};
}
return this.show(cfg);
}
}, function() {
/**
* @class Ext.MessageBox
* @alternateClassName Ext.Msg
* @extends Ext.window.MessageBox
* @singleton
* Singleton instance of {@link Ext.window.MessageBox}.
*/
Ext.MessageBox = Ext.Msg = new this();
});
/**
* @class Ext.form.Basic
* @extends Ext.util.Observable
*
* Provides input field management, validation, submission, and form loading services for the collection
* of {@link Ext.form.field.Field Field} instances within a {@link Ext.container.Container}. It is recommended
* that you use a {@link Ext.form.Panel} as the form container, as that has logic to automatically
* hook up an instance of {@link Ext.form.Basic} (plus other conveniences related to field configuration.)
*
* ## Form Actions
*
* The Basic class delegates the handling of form loads and submits to instances of {@link Ext.form.action.Action}.
* See the various Action implementations for specific details of each one's functionality, as well as the
* documentation for {@link #doAction} which details the configuration options that can be specified in
* each action call.
*
* The default submit Action is {@link Ext.form.action.Submit}, which uses an Ajax request to submit the
* form's values to a configured URL. To enable normal browser submission of an Ext form, use the
* {@link #standardSubmit} config option.
*
* ## File uploads
*
* File uploads are not performed using normal 'Ajax' techniques; see the description for
* {@link #hasUpload} for details. If you're using file uploads you should read the method description.
*
* ## Example usage:
*
* Ext.create('Ext.form.Panel', {
* title: 'Basic Form',
* renderTo: Ext.getBody(),
* bodyPadding: 5,
* width: 350,
*
* // Any configuration items here will be automatically passed along to
* // the Ext.form.Basic instance when it gets created.
*
* // The form will submit an AJAX request to this URL when submitted
* url: 'save-form.php',
*
* items: [{
* fieldLabel: 'Field',
* name: 'theField'
* }],
*
* buttons: [{
* text: 'Submit',
* handler: function() {
* // The getForm() method returns the Ext.form.Basic instance:
* var form = this.up('form').getForm();
* if (form.isValid()) {
* // Submit the Ajax request and handle the response
* form.submit({
* success: function(form, action) {
* Ext.Msg.alert('Success', action.result.msg);
* },
* failure: function(form, action) {
* Ext.Msg.alert('Failed', action.result.msg);
* }
* });
* }
* }
* }]
* });
*
* @docauthor Jason Johnston An Ext.data.DataReader (e.g. {@link Ext.data.reader.Xml}) to be used to * read field error messages returned from 'submit' actions. This is optional * as there is built-in support for processing JSON responses.
*The Records which provide messages for the invalid Fields must use the * Field name (or id) as the Record ID, and must contain a field called 'msg' * which contains the error message.
*The errorReader does not have to be a full-blown implementation of a * Reader. It simply needs to implement a read(xhr) function * which returns an Array of Records in an object with the following * structure:
{
records: recordArray
}
*/
/**
* @cfg {String} url
* The URL to use for form actions if one isn't supplied in the
* {@link #doAction doAction} options.
*/
/**
* @cfg {Object} baseParams
* Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.
*Parameters are encoded as standard HTTP parameters using {@link Ext.Object#toQueryString}.
*/ /** * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds). */ timeout: 30, /** * @cfg {Object} api (Optional) If specified, load and submit actions will be handled * with {@link Ext.form.action.DirectLoad} and {@link Ext.form.action.DirectLoad}. * Methods which have been imported by {@link Ext.direct.Manager} can be specified here to load and submit * forms. * Such as the following:
api: {
load: App.ss.MyProfile.load,
submit: App.ss.MyProfile.submit
}
* Load actions can use {@link #paramOrder}
or {@link #paramsAsHash}
* to customize how the load method is invoked.
* Submit actions will always use a standard form submit. The formHandler configuration must
* be set on the associated server-side method which has been imported by {@link Ext.direct.Manager}.
A list of params to be executed server side.
* Defaults to undefined. Only used for the {@link #api}
* load
configuration.
Specify the params in the order in which they must be executed on the * server-side as either (1) an Array of String values, or (2) a String of params * delimited by either whitespace, comma, or pipe. For example, * any of the following would be acceptable:
paramOrder: ['param1','param2','param3']
paramOrder: 'param1 param2 param3'
paramOrder: 'param1,param2,param3'
paramOrder: 'param1|param2|param'
*/
/**
* @cfg {Boolean} paramsAsHash
* Only used for the {@link #api}
* load
configuration. If true, parameters will be sent as a
* single hash collection of named arguments. Providing a
* {@link #paramOrder} nullifies this configuration.
*/
paramsAsHash: false,
/**
* @cfg {String} waitTitle
* The default title to show for the waiting message box
*/
waitTitle: 'Please Wait...',
/**
* @cfg {Boolean} trackResetOnLoad
* If set to true, {@link #reset}() resets to the last loaded or {@link #setValues}() data instead of
* when the form was first created.
*/
trackResetOnLoad: false,
/**
* @cfg {Boolean} standardSubmit
* If set to true, a standard HTML form submit is used instead of a XHR (Ajax) style form submission.
* All of the field values, plus any additional params configured via {@link #baseParams}
* and/or the `options` to {@link #submit}, will be included in the values submitted in the form.
*/
/**
* @cfg {String/HTMLElement/Ext.Element} waitMsgTarget
* By default wait messages are displayed with Ext.MessageBox.wait. You can target a specific
* element by passing it or its id or mask the form itself by passing in true.
*/
// Private
wasDirty: false,
/**
* Destroys this object.
*/
destroy: function() {
this.clearListeners();
this.checkValidityTask.cancel();
},
/**
* @private
* Handle addition or removal of descendant items. Invalidates the cached list of fields
* so that {@link #getFields} will do a fresh query next time it is called. Also adds listeners
* for state change events on added fields, and tracks components with formBind=true.
*/
onItemAddOrRemove: function(parent, child) {
var me = this,
isAdding = !!child.ownerCt,
isContainer = child.isContainer;
function handleField(field) {
// Listen for state change events on fields
me[isAdding ? 'mon' : 'mun'](field, {
validitychange: me.checkValidity,
dirtychange: me.checkDirty,
scope: me,
buffer: 100 //batch up sequential calls to avoid excessive full-form validation
});
// Flush the cached list of fields
delete me._fields;
}
if (child.isFormField) {
handleField(child);
} else if (isContainer) {
// Walk down
if (child.isDestroyed) {
// the container is destroyed, this means we may have child fields, so here
// we just invalidate all the fields to be sure.
delete me._fields;
} else {
Ext.Array.forEach(child.query('[isFormField]'), handleField);
}
}
// Flush the cached list of formBind components
delete this._boundItems;
// Check form bind, but only after initial add. Batch it to prevent excessive validation
// calls when many fields are being added at once.
if (me.initialized) {
me.checkValidityTask.delay(10);
}
},
/**
* Return all the {@link Ext.form.field.Field} components in the owner container.
* @return {Ext.util.MixedCollection} Collection of the Field objects
*/
getFields: function() {
var fields = this._fields;
if (!fields) {
fields = this._fields = Ext.create('Ext.util.MixedCollection');
fields.addAll(this.owner.query('[isFormField]'));
}
return fields;
},
/**
* @private
* Finds and returns the set of all items bound to fields inside this form
* @return {Ext.util.MixedCollection} The set of all bound form field items
*/
getBoundItems: function() {
var boundItems = this._boundItems;
if (!boundItems || boundItems.getCount() === 0) {
boundItems = this._boundItems = Ext.create('Ext.util.MixedCollection');
boundItems.addAll(this.owner.query('[formBind]'));
}
return boundItems;
},
/**
* Returns true if the form contains any invalid fields. No fields will be marked as invalid
* as a result of calling this; to trigger marking of fields use {@link #isValid} instead.
*/
hasInvalidField: function() {
return !!this.getFields().findBy(function(field) {
var preventMark = field.preventMark,
isValid;
field.preventMark = true;
isValid = field.isValid();
field.preventMark = preventMark;
return !isValid;
});
},
/**
* Returns true if client-side validation on the form is successful. Any invalid fields will be
* marked as invalid. If you only want to determine overall form validity without marking anything,
* use {@link #hasInvalidField} instead.
* @return Boolean
*/
isValid: function() {
var me = this,
invalid;
me.batchLayouts(function() {
invalid = me.getFields().filterBy(function(field) {
return !field.validate();
});
});
return invalid.length < 1;
},
/**
* Check whether the validity of the entire form has changed since it was last checked, and
* if so fire the {@link #validitychange validitychange} event. This is automatically invoked
* when an individual field's validity changes.
*/
checkValidity: function() {
var me = this,
valid = !me.hasInvalidField();
if (valid !== me.wasValid) {
me.onValidityChange(valid);
me.fireEvent('validitychange', me, valid);
me.wasValid = valid;
}
},
/**
* @private
* Handle changes in the form's validity. If there are any sub components with
* formBind=true then they are enabled/disabled based on the new validity.
* @param {Boolean} valid
*/
onValidityChange: function(valid) {
var boundItems = this.getBoundItems();
if (boundItems) {
boundItems.each(function(cmp) {
if (cmp.disabled === valid) {
cmp.setDisabled(!valid);
}
});
}
},
/**
* Returns true if any fields in this form have changed from their original values.
*Note that if this BasicForm was configured with {@link #trackResetOnLoad} then the * Fields' original values are updated when the values are loaded by {@link #setValues} * or {@link #loadRecord}.
* @return Boolean */ isDirty: function() { return !!this.getFields().findBy(function(f) { return f.isDirty(); }); }, /** * Check whether the dirty state of the entire form has changed since it was last checked, and * if so fire the {@link #dirtychange dirtychange} event. This is automatically invoked * when an individual field's dirty state changes. */ checkDirty: function() { var dirty = this.isDirty(); if (dirty !== this.wasDirty) { this.fireEvent('dirtychange', this, dirty); this.wasDirty = dirty; } }, /** *Returns true if the form contains a file upload field. This is used to determine the * method for submitting the form: File uploads are not performed using normal 'Ajax' techniques, * that is they are not performed using XMLHttpRequests. Instead a hidden <form> * element containing all the fields is created temporarily and submitted with its * target set to refer * to a dynamically generated, hidden <iframe> which is inserted into the document * but removed after the return data has been gathered.
*The server response is parsed by the browser to create the document for the IFRAME. If the * server is using JSON to send the return object, then the * Content-Type header * must be set to "text/html" in order to tell the browser to insert the text unchanged into the document body.
*Characters which are significant to an HTML parser must be sent as HTML entities, so encode * "<" as "<", "&" as "&" etc.
*The response text is retrieved from the document, and a fake XMLHttpRequest object * is created containing a responseText property in order to conform to the * requirements of event handlers and callbacks.
*Be aware that file upload packets are sent with the content type multipart/form * and some server technologies (notably JEE) may require some custom processing in order to * retrieve parameter names and parameter values from the packet content.
* @return Boolean */ hasUpload: function() { return !!this.getFields().findBy(function(f) { return f.isFileUpload(); }); }, /** * Performs a predefined action (an implementation of {@link Ext.form.action.Action}) * to perform application-specific processing. * @param {String/Ext.form.action.Action} action The name of the predefined action type, * or instance of {@link Ext.form.action.Action} to perform. * @param {Object} options (optional) The options to pass to the {@link Ext.form.action.Action} * that will get created, if the action argument is a String. *All of the config options listed below are supported by both the * {@link Ext.form.action.Submit submit} and {@link Ext.form.action.Load load} * actions unless otherwise noted (custom actions could also accept * other config options):
The params to pass * (defaults to the form's baseParams, or none if not defined)
*Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode Ext.Object.toQueryString}.
The following code:
myFormPanel.getForm().submit({
clientValidation: true,
url: 'updateConsignment.php',
params: {
newStatus: 'delivered'
},
success: function(form, action) {
Ext.Msg.alert('Success', action.result.msg);
},
failure: function(form, action) {
switch (action.failureType) {
case Ext.form.action.Action.CLIENT_INVALID:
Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values');
break;
case Ext.form.action.Action.CONNECT_FAILURE:
Ext.Msg.alert('Failure', 'Ajax communication failed');
break;
case Ext.form.action.Action.SERVER_INVALID:
Ext.Msg.alert('Failure', action.result.msg);
}
}
});
* would process the following server response for a successful submission:
{
"success":true, // note this is Boolean, not string
"msg":"Consignment updated"
}
* and the following server response for a failed submission:
{
"success":false, // note this is Boolean, not string
"msg":"You do not have permission to perform this operation"
}
* @return {Ext.form.Basic} this
*/
submit: function(options) {
return this.doAction(this.standardSubmit ? 'standardsubmit' : this.api ? 'directsubmit' : 'submit', options);
},
/**
* Shortcut to {@link #doAction do} a {@link Ext.form.action.Load load action}.
* @param {Object} options The options to pass to the action (see {@link #doAction} for details)
* @return {Ext.form.Basic} this
*/
load: function(options) {
return this.doAction(this.api ? 'directload' : 'load', options);
},
/**
* Persists the values in this form into the passed {@link Ext.data.Model} object in a beginEdit/endEdit block.
* @param {Ext.data.Model} record The record to edit
* @return {Ext.form.Basic} this
*/
updateRecord: function(record) {
var fields = record.fields,
values = this.getFieldValues(),
name,
obj = {};
fields.each(function(f) {
name = f.name;
if (name in values) {
obj[name] = values[name];
}
});
record.beginEdit();
record.set(obj);
record.endEdit();
return this;
},
/**
* Loads an {@link Ext.data.Model} into this form by calling {@link #setValues} with the
* {@link Ext.data.Model#raw record data}.
* See also {@link #trackResetOnLoad}.
* @param {Ext.data.Model} record The record to load
* @return {Ext.form.Basic} this
*/
loadRecord: function(record) {
this._record = record;
return this.setValues(record.data);
},
/**
* Returns the last Ext.data.Model instance that was loaded via {@link #loadRecord}
* @return {Ext.data.Model} The record
*/
getRecord: function() {
return this._record;
},
/**
* @private
* Called before an action is performed via {@link #doAction}.
* @param {Ext.form.action.Action} action The Action instance that was invoked
*/
beforeAction: function(action) {
var waitMsg = action.waitMsg,
maskCls = Ext.baseCSSPrefix + 'mask-loading',
waitMsgTarget;
// Call HtmlEditor's syncValue before actions
this.getFields().each(function(f) {
if (f.isFormField && f.syncValue) {
f.syncValue();
}
});
if (waitMsg) {
waitMsgTarget = this.waitMsgTarget;
if (waitMsgTarget === true) {
this.owner.el.mask(waitMsg, maskCls);
} else if (waitMsgTarget) {
waitMsgTarget = this.waitMsgTarget = Ext.get(waitMsgTarget);
waitMsgTarget.mask(waitMsg, maskCls);
} else {
Ext.MessageBox.wait(waitMsg, action.waitTitle || this.waitTitle);
}
}
},
/**
* @private
* Called after an action is performed via {@link #doAction}.
* @param {Ext.form.action.Action} action The Action instance that was invoked
* @param {Boolean} success True if the action completed successfully, false, otherwise.
*/
afterAction: function(action, success) {
if (action.waitMsg) {
var MessageBox = Ext.MessageBox,
waitMsgTarget = this.waitMsgTarget;
if (waitMsgTarget === true) {
this.owner.el.unmask();
} else if (waitMsgTarget) {
waitMsgTarget.unmask();
} else {
MessageBox.updateProgress(1);
MessageBox.hide();
}
}
if (success) {
if (action.reset) {
this.reset();
}
Ext.callback(action.success, action.scope || action, [this, action]);
this.fireEvent('actioncomplete', this, action);
} else {
Ext.callback(action.failure, action.scope || action, [this, action]);
this.fireEvent('actionfailed', this, action);
}
},
/**
* Find a specific {@link Ext.form.field.Field} in this form by id or name.
* @param {String} id The value to search for (specify either a {@link Ext.Component#id id} or
* {@link Ext.form.field.Field#getName name or hiddenName}).
* @return Ext.form.field.Field The first matching field, or null if none was found.
*/
findField: function(id) {
return this.getFields().findBy(function(f) {
return f.id === id || f.getName() === id;
});
},
/**
* Mark fields in this form invalid in bulk.
* @param {Object/Object[]/Ext.data.Errors} errors
* Either an array in the form [{id:'fieldId', msg:'The message'}, ...]
,
* an object hash of {id: msg, id2: msg2}
, or a {@link Ext.data.Errors} object.
* @return {Ext.form.Basic} this
*/
markInvalid: function(errors) {
var me = this;
function mark(fieldId, msg) {
var field = me.findField(fieldId);
if (field) {
field.markInvalid(msg);
}
}
if (Ext.isArray(errors)) {
Ext.each(errors, function(err) {
mark(err.id, err.msg);
});
}
else if (errors instanceof Ext.data.Errors) {
errors.each(function(err) {
mark(err.field, err.message);
});
}
else {
Ext.iterate(errors, mark);
}
return this;
},
/**
* Set values for fields in this form in bulk.
* @param {Object/Object[]} values Either an array in the form:
[{id:'clientName', value:'Fred. Olsen Lines'},
{id:'portOfLoading', value:'FXT'},
{id:'portOfDischarge', value:'OSL'} ]
* or an object hash of the form:
{
clientName: 'Fred. Olsen Lines',
portOfLoading: 'FXT',
portOfDischarge: 'OSL'
}
* @return {Ext.form.Basic} this
*/
setValues: function(values) {
var me = this;
function setVal(fieldId, val) {
var field = me.findField(fieldId);
if (field) {
field.setValue(val);
if (me.trackResetOnLoad) {
field.resetOriginalValue();
}
}
}
if (Ext.isArray(values)) {
// array of objects
Ext.each(values, function(val) {
setVal(val.id, val.value);
});
} else {
// object hash
Ext.iterate(values, setVal);
}
return this;
},
/**
* Retrieves the fields in the form as a set of key/value pairs, using their
* {@link Ext.form.field.Field#getSubmitData getSubmitData()} method to collect the values.
* If multiple fields return values under the same name those values will be combined into an Array.
* This is similar to {@link #getFieldValues} except that this method collects only String values for
* submission, while getFieldValues collects type-specific data values (e.g. Date objects for date fields.)
* @param {Boolean} asString (optional) If true, will return the key/value collection as a single
* URL-encoded param string. Defaults to false.
* @param {Boolean} dirtyOnly (optional) If true, only fields that are dirty will be included in the result.
* Defaults to false.
* @param {Boolean} includeEmptyText (optional) If true, the configured emptyText of empty fields will be used.
* Defaults to false.
* @return {String/Object}
*/
getValues: function(asString, dirtyOnly, includeEmptyText, useDataValues) {
var values = {};
this.getFields().each(function(field) {
if (!dirtyOnly || field.isDirty()) {
var data = field[useDataValues ? 'getModelData' : 'getSubmitData'](includeEmptyText);
if (Ext.isObject(data)) {
Ext.iterate(data, function(name, val) {
if (includeEmptyText && val === '') {
val = field.emptyText || '';
}
if (name in values) {
var bucket = values[name],
isArray = Ext.isArray;
if (!isArray(bucket)) {
bucket = values[name] = [bucket];
}
if (isArray(val)) {
values[name] = bucket.concat(val);
} else {
bucket.push(val);
}
} else {
values[name] = val;
}
});
}
}
});
if (asString) {
values = Ext.Object.toQueryString(values);
}
return values;
},
/**
* Retrieves the fields in the form as a set of key/value pairs, using their
* {@link Ext.form.field.Field#getModelData getModelData()} method to collect the values.
* If multiple fields return values under the same name those values will be combined into an Array.
* This is similar to {@link #getValues} except that this method collects type-specific data values
* (e.g. Date objects for date fields) while getValues returns only String values for submission.
* @param {Boolean} dirtyOnly (optional) If true, only fields that are dirty will be included in the result.
* Defaults to false.
* @return {Object}
*/
getFieldValues: function(dirtyOnly) {
return this.getValues(false, dirtyOnly, false, true);
},
/**
* Clears all invalid field messages in this form.
* @return {Ext.form.Basic} this
*/
clearInvalid: function() {
var me = this;
me.batchLayouts(function() {
me.getFields().each(function(f) {
f.clearInvalid();
});
});
return me;
},
/**
* Resets all fields in this form.
* @return {Ext.form.Basic} this
*/
reset: function() {
var me = this;
me.batchLayouts(function() {
me.getFields().each(function(f) {
f.reset();
});
});
return me;
},
/**
* Calls {@link Ext#apply Ext.apply} for all fields in this form with the passed object.
* @param {Object} obj The object to be applied
* @return {Ext.form.Basic} this
*/
applyToFields: function(obj) {
this.getFields().each(function(f) {
Ext.apply(f, obj);
});
return this;
},
/**
* Calls {@link Ext#applyIf Ext.applyIf} for all field in this form with the passed object.
* @param {Object} obj The object to be applied
* @return {Ext.form.Basic} this
*/
applyIfToFields: function(obj) {
this.getFields().each(function(f) {
Ext.applyIf(f, obj);
});
return this;
},
/**
* @private
* Utility wrapper that suspends layouts of all field parent containers for the duration of a given
* function. Used during full-form validation and resets to prevent huge numbers of layouts.
* @param {Function} fn
*/
batchLayouts: function(fn) {
var me = this,
suspended = new Ext.util.HashMap();
// Temporarily suspend layout on each field's immediate owner so we don't get a huge layout cascade
me.getFields().each(function(field) {
var ownerCt = field.ownerCt;
if (!suspended.contains(ownerCt)) {
suspended.add(ownerCt);
ownerCt.oldSuspendLayout = ownerCt.suspendLayout;
ownerCt.suspendLayout = true;
}
});
// Invoke the function
fn();
// Un-suspend the container layouts
suspended.each(function(id, ct) {
ct.suspendLayout = ct.oldSuspendLayout;
delete ct.oldSuspendLayout;
});
// Trigger a single layout
me.owner.doComponentLayout();
}
});
/**
* @class Ext.form.FieldAncestor
A mixin for {@link Ext.container.Container} components that are likely to have form fields in their
items subtree. Adds the following capabilities:
- Methods for handling the addition and removal of {@link Ext.form.Labelable} and {@link Ext.form.field.Field}
instances at any depth within the container.
- Events ({@link #fieldvaliditychange} and {@link #fielderrorchange}) for handling changes to the state
of individual fields at the container level.
- Automatic application of {@link #fieldDefaults} config properties to each field added within the
container, to facilitate uniform configuration of all fields.
This mixin is primarily for internal use by {@link Ext.form.Panel} and {@link Ext.form.FieldContainer},
and should not normally need to be used directly.
* @markdown
* @docauthor Jason Johnston If specified, the properties in this object are used as default config values for each * {@link Ext.form.Labelable} instance (e.g. {@link Ext.form.field.Base} or {@link Ext.form.FieldContainer}) * that is added as a descendant of this container. Corresponding values specified in an individual field's * own configuration, or from the {@link Ext.container.Container#defaults defaults config} of its parent container, * will take precedence. See the documentation for {@link Ext.form.Labelable} to see what config * options may be specified in the fieldDefaults.
*Example:
*new Ext.form.Panel({
fieldDefaults: {
labelAlign: 'left',
labelWidth: 100
},
items: [{
xtype: 'fieldset',
defaults: {
labelAlign: 'top'
},
items: [{
name: 'field1'
}, {
name: 'field2'
}]
}, {
xtype: 'fieldset',
items: [{
name: 'field3',
labelWidth: 150
}, {
name: 'field4'
}]
}]
});
* In this example, field1 and field2 will get labelAlign:'top' (from the fieldset's defaults) * and labelWidth:100 (from fieldDefaults), field3 and field4 will both get labelAlign:'left' (from * fieldDefaults and field3 will use the labelWidth:150 from its own config.
*/ /** * @protected Initializes the FieldAncestor's state; this must be called from the initComponent method * of any components importing this mixin. */ initFieldAncestor: function() { var me = this, onSubtreeChange = me.onFieldAncestorSubtreeChange; me.addEvents( /** * @event fieldvaliditychange * Fires when the validity state of any one of the {@link Ext.form.field.Field} instances within this * container changes. * @param {Ext.form.FieldAncestor} this * @param {Ext.form.Labelable} The Field instance whose validity changed * @param {String} isValid The field's new validity state */ 'fieldvaliditychange', /** * @event fielderrorchange * Fires when the active error message is changed for any one of the {@link Ext.form.Labelable} * instances within this container. * @param {Ext.form.FieldAncestor} this * @param {Ext.form.Labelable} The Labelable instance whose active error was changed * @param {String} error The active error message */ 'fielderrorchange' ); // Catch addition and removal of descendant fields me.on('add', onSubtreeChange, me); me.on('remove', onSubtreeChange, me); me.initFieldDefaults(); }, /** * @private Initialize the {@link #fieldDefaults} object */ initFieldDefaults: function() { if (!this.fieldDefaults) { this.fieldDefaults = {}; } }, /** * @private * Handle the addition and removal of components in the FieldAncestor component's child tree. */ onFieldAncestorSubtreeChange: function(parent, child) { var me = this, isAdding = !!child.ownerCt; function handleCmp(cmp) { var isLabelable = cmp.isFieldLabelable, isField = cmp.isFormField; if (isLabelable || isField) { if (isLabelable) { me['onLabelable' + (isAdding ? 'Added' : 'Removed')](cmp); } if (isField) { me['onField' + (isAdding ? 'Added' : 'Removed')](cmp); } } else if (cmp.isContainer) { Ext.Array.forEach(cmp.getRefItems(), handleCmp); } } handleCmp(child); }, /** * @protected Called when a {@link Ext.form.Labelable} instance is added to the container's subtree. * @param {Ext.form.Labelable} labelable The instance that was added */ onLabelableAdded: function(labelable) { var me = this; // buffer slightly to avoid excessive firing while sub-fields are changing en masse me.mon(labelable, 'errorchange', me.handleFieldErrorChange, me, {buffer: 10}); labelable.setFieldDefaults(me.fieldDefaults); }, /** * @protected Called when a {@link Ext.form.field.Field} instance is added to the container's subtree. * @param {Ext.form.field.Field} field The field which was added */ onFieldAdded: function(field) { var me = this; me.mon(field, 'validitychange', me.handleFieldValidityChange, me); }, /** * @protected Called when a {@link Ext.form.Labelable} instance is removed from the container's subtree. * @param {Ext.form.Labelable} labelable The instance that was removed */ onLabelableRemoved: function(labelable) { var me = this; me.mun(labelable, 'errorchange', me.handleFieldErrorChange, me); }, /** * @protected Called when a {@link Ext.form.field.Field} instance is removed from the container's subtree. * @param {Ext.form.field.Field} field The field which was removed */ onFieldRemoved: function(field) { var me = this; me.mun(field, 'validitychange', me.handleFieldValidityChange, me); }, /** * @private Handle validitychange events on sub-fields; invoke the aggregated event and method */ handleFieldValidityChange: function(field, isValid) { var me = this; me.fireEvent('fieldvaliditychange', me, field, isValid); me.onFieldValidityChange(); }, /** * @private Handle errorchange events on sub-fields; invoke the aggregated event and method */ handleFieldErrorChange: function(labelable, activeError) { var me = this; me.fireEvent('fielderrorchange', me, labelable, activeError); me.onFieldErrorChange(); }, /** * @protected Fired when the validity of any field within the container changes. * @param {Ext.form.field.Field} The sub-field whose validity changed * @param {String} The new validity state */ onFieldValidityChange: Ext.emptyFn, /** * @protected Fired when the error message of any field within the container changes. * @param {Ext.form.Labelable} The sub-field whose active error changed * @param {String} The new active error message */ onFieldErrorChange: Ext.emptyFn }); /** * @class Ext.layout.container.CheckboxGroup * @extends Ext.layout.container.Container *This layout implements the column arrangement for {@link Ext.form.CheckboxGroup} and {@link Ext.form.RadioGroup}. * It groups the component's sub-items into columns based on the component's * {@link Ext.form.CheckboxGroup#columns columns} and {@link Ext.form.CheckboxGroup#vertical} config properties.
* */ Ext.define('Ext.layout.container.CheckboxGroup', { extend: 'Ext.layout.container.Container', alias: ['layout.checkboxgroup'], onLayout: function() { var numCols = this.getColCount(), shadowCt = this.getShadowCt(), owner = this.owner, items = owner.items, shadowItems = shadowCt.items, numItems = items.length, colIndex = 0, i, numRows; // Distribute the items into the appropriate column containers. We add directly to the // containers' items collection rather than calling container.add(), because we need the // checkboxes to maintain their original ownerCt. The distribution is done on each layout // in case items have been added, removed, or reordered. shadowItems.each(function(col) { col.items.clear(); }); // If columns="auto", then the number of required columns may change as checkboxes are added/removed // from the CheckboxGroup; adjust to match. while (shadowItems.length > numCols) { shadowCt.remove(shadowItems.last()); } while (shadowItems.length < numCols) { shadowCt.add({ xtype: 'container', cls: owner.groupCls, flex: 1 }); } if (owner.vertical) { numRows = Math.ceil(numItems / numCols); for (i = 0; i < numItems; i++) { if (i > 0 && i % numRows === 0) { colIndex++; } shadowItems.getAt(colIndex).items.add(items.getAt(i)); } } else { for (i = 0; i < numItems; i++) { colIndex = i % numCols; shadowItems.getAt(colIndex).items.add(items.getAt(i)); } } if (!shadowCt.rendered) { shadowCt.render(this.getRenderTarget()); } else { // Ensure all items are rendered in the correct place in the correct column - this won't // get done by the column containers themselves if their dimensions are not changing. shadowItems.each(function(col) { var layout = col.getLayout(); layout.renderItems(layout.getLayoutItems(), layout.getRenderTarget()); }); } shadowCt.doComponentLayout(); }, // We don't want to render any items to the owner directly, that gets handled by each column's own layout renderItems: Ext.emptyFn, /** * @private * Creates and returns the shadow hbox container that will be used to arrange the owner's items * into columns. */ getShadowCt: function() { var me = this, shadowCt = me.shadowCt, owner, items, item, columns, columnsIsArray, numCols, i; if (!shadowCt) { // Create the column containers based on the owner's 'columns' config owner = me.owner; columns = owner.columns; columnsIsArray = Ext.isArray(columns); numCols = me.getColCount(); items = []; for(i = 0; i < numCols; i++) { item = { xtype: 'container', cls: owner.groupCls }; if (columnsIsArray) { // Array can contain mixture of whole numbers, used as fixed pixel widths, and fractional // numbers, used as relative flex values. if (columns[i] < 1) { item.flex = columns[i]; } else { item.width = columns[i]; } } else { // All columns the same width item.flex = 1; } items.push(item); } // Create the shadow container; delay rendering until after items are added to the columns shadowCt = me.shadowCt = Ext.createWidget('container', { layout: 'hbox', items: items, ownerCt: owner }); } return shadowCt; }, /** * @private Get the number of columns in the checkbox group */ getColCount: function() { var owner = this.owner, colsCfg = owner.columns; return Ext.isArray(colsCfg) ? colsCfg.length : (Ext.isNumber(colsCfg) ? colsCfg : owner.items.length); } }); /** * FieldContainer is a derivation of {@link Ext.container.Container Container} that implements the * {@link Ext.form.Labelable Labelable} mixin. This allows it to be configured so that it is rendered with * a {@link #fieldLabel field label} and optional {@link #msgTarget error message} around its sub-items. * This is useful for arranging a group of fields or other components within a single item in a form, so * that it lines up nicely with other fields. A common use is for grouping a set of related fields under * a single label in a form. * * The container's configured {@link #items} will be layed out within the field body area according to the * configured {@link #layout} type. The default layout is `'autocontainer'`. * * Like regular fields, FieldContainer can inherit its decoration configuration from the * {@link Ext.form.Panel#fieldDefaults fieldDefaults} of an enclosing FormPanel. In addition, * FieldContainer itself can pass {@link #fieldDefaults} to any {@link Ext.form.Labelable fields} * it may itself contain. * * If you are grouping a set of {@link Ext.form.field.Checkbox Checkbox} or {@link Ext.form.field.Radio Radio} * fields in a single labeled container, consider using a {@link Ext.form.CheckboxGroup} * or {@link Ext.form.RadioGroup} instead as they are specialized for handling those types. * * # Example * * @example * Ext.create('Ext.form.Panel', { * title: 'FieldContainer Example', * width: 550, * bodyPadding: 10, * * items: [{ * xtype: 'fieldcontainer', * fieldLabel: 'Last Three Jobs', * labelWidth: 100, * * // The body area will contain three text fields, arranged * // horizontally, separated by draggable splitters. * layout: 'hbox', * items: [{ * xtype: 'textfield', * flex: 1 * }, { * xtype: 'splitter' * }, { * xtype: 'textfield', * flex: 1 * }, { * xtype: 'splitter' * }, { * xtype: 'textfield', * flex: 1 * }] * }], * renderTo: Ext.getBody() * }); * * # Usage of fieldDefaults * * @example * Ext.create('Ext.form.Panel', { * title: 'FieldContainer Example', * width: 350, * bodyPadding: 10, * * items: [{ * xtype: 'fieldcontainer', * fieldLabel: 'Your Name', * labelWidth: 75, * defaultType: 'textfield', * * // Arrange fields vertically, stretched to full width * layout: 'anchor', * defaults: { * layout: '100%' * }, * * // These config values will be applied to both sub-fields, except * // for Last Name which will use its own msgTarget. * fieldDefaults: { * msgTarget: 'under', * labelAlign: 'top' * }, * * items: [{ * fieldLabel: 'First Name', * name: 'firstName' * }, { * fieldLabel: 'Last Name', * name: 'lastName', * msgTarget: 'under' * }] * }], * renderTo: Ext.getBody() * }); * * @docauthor Jason Johnston