PageRenderTime 62ms CodeModel.GetById 13ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 2ms

/protected/test.txt

http://github.com/phpnode/YiiJS
Plain Text | 13930 lines | 13545 code | 385 blank | 0 comment | 0 complexity | 29c971761f8a835f00acf162c4fa918b MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1/*global php, $, jQuery, alert, clearInterval, clearTimeout, document, event, frames, history, Image, location, name, navigator, Option, parent, screen, setInterval, setTimeout, window, XMLHttpRequest */
   2/**
   3 * Yii is a helper class serving common framework functionalities.
   4 * 
   5 * It encapsulates {@link YiiBase} which provides the actual implementation.
   6 * By writing your own Yii class, you can customize some functionalities of YiiBase.
   7 * 
   8 * @originalAuthor Qiang Xue <qiang.xue@gmail.com>
   9 * @version $Id: yii.js 2799 2011-01-01 19:31:13Z qiang.xue $
  10 * @package system
  11 * @since 1.0
  12 * @author Charles Pick
  13 * @class
  14 * @extends Yii.YiiBase
  15 */
  16var YII_DEBUG = true, YII_TRACE_LEVEL = 3, YII_BEGIN_TIME = new Date().getTime() / 1000, Yii = /** @lends Yii.prototype */{
  17	/**	
  18	 * @property {Array} class map used by the Yii autoloading mechanism.
  19	 * The array keys are the class names and the array values are the corresponding class file paths.
  20	 * @since 1.1.5
  21	 */
  22	classMap: {},
  23	_aliases: {},
  24	_imports: {},
  25	_includePaths: {},
  26	_app: null,
  27	_logger: null,
  28	/**	
  29	 * @property {Array} class map for core Yii classes.
  30	 * NOTE, DO NOT MODIFY THIS ARRAY MANUALLY. IF YOU CHANGE OR ADD SOME CORE CLASSES,
  31	 * PLEASE RUN 'build autoload' COMMAND TO UPDATE THIS ARRAY.
  32	 */
  33	_coreClasses: {'CApplication':'/base/CApplication.js','CApplicationComponent':'/base/CApplicationComponent.js','CBehavior':'/base/CBehavior.js','CComponent':'/base/CComponent.js','CErrorEvent':'/base/CErrorEvent.js','CErrorHandler':'/base/CErrorHandler.js','CException':'/base/CException.js','CExceptionEvent':'/base/CExceptionEvent.js','CHttpException':'/base/CHttpException.js','CModel':'/base/CModel.js','CModelBehavior':'/base/CModelBehavior.js','CModelEvent':'/base/CModelEvent.js','CModule':'/base/CModule.js','CSecurityManager':'/base/CSecurityManager.js','CStatePersister':'/base/CStatePersister.js','CApcCache':'/caching/CApcCache.js','CCache':'/caching/CCache.js','CDbCache':'/caching/CDbCache.js','CDummyCache':'/caching/CDummyCache.js','CEAcceleratorCache':'/caching/CEAcceleratorCache.js','CFileCache':'/caching/CFileCache.js','CMemCache':'/caching/CMemCache.js','CWinCache':'/caching/CWinCache.js','CXCache':'/caching/CXCache.js','CZendDataCache':'/caching/CZendDataCache.js','CCacheDependency':'/caching/dependencies/CCacheDependency.js','CChainedCacheDependency':'/caching/dependencies/CChainedCacheDependency.js','CDbCacheDependency':'/caching/dependencies/CDbCacheDependency.js','CDirectoryCacheDependency':'/caching/dependencies/CDirectoryCacheDependency.js','CExpressionDependency':'/caching/dependencies/CExpressionDependency.js','CFileCacheDependency':'/caching/dependencies/CFileCacheDependency.js','CGlobalStateCacheDependency':'/caching/dependencies/CGlobalStateCacheDependency.js','CAttributeCollection':'/collections/CAttributeCollection.js','CConfiguration':'/collections/CConfiguration.js','CList':'/collections/CList.js','CListIterator':'/collections/CListIterator.js','CMap':'/collections/CMap.js','CMapIterator':'/collections/CMapIterator.js','CQueue':'/collections/CQueue.js','CQueueIterator':'/collections/CQueueIterator.js','CStack':'/collections/CStack.js','CStackIterator':'/collections/CStackIterator.js','CTypedList':'/collections/CTypedList.js','CTypedMap':'/collections/CTypedMap.js','CConsoleApplication':'/console/CConsoleApplication.js','CConsoleCommand':'/console/CConsoleCommand.js','CConsoleCommandRunner':'/console/CConsoleCommandRunner.js','CHelpCommand':'/console/CHelpCommand.js','CDbCommand':'/db/CDbCommand.js','CDbConnection':'/db/CDbConnection.js','CDbDataReader':'/db/CDbDataReader.js','CDbException':'/db/CDbException.js','CDbMigration':'/db/CDbMigration.js','CDbTransaction':'/db/CDbTransaction.js','CActiveFinder':'/db/ar/CActiveFinder.js','CActiveRecord':'/db/ar/CActiveRecord.js','CActiveRecordBehavior':'/db/ar/CActiveRecordBehavior.js','CDbColumnSchema':'/db/schema/CDbColumnSchema.js','CDbCommandBuilder':'/db/schema/CDbCommandBuilder.js','CDbCriteria':'/db/schema/CDbCriteria.js','CDbExpression':'/db/schema/CDbExpression.js','CDbSchema':'/db/schema/CDbSchema.js','CDbTableSchema':'/db/schema/CDbTableSchema.js','CMssqlColumnSchema':'/db/schema/mssql/CMssqlColumnSchema.js','CMssqlCommandBuilder':'/db/schema/mssql/CMssqlCommandBuilder.js','CMssqlPdoAdapter':'/db/schema/mssql/CMssqlPdoAdapter.js','CMssqlSchema':'/db/schema/mssql/CMssqlSchema.js','CMssqlTableSchema':'/db/schema/mssql/CMssqlTableSchema.js','CMysqlColumnSchema':'/db/schema/mysql/CMysqlColumnSchema.js','CMysqlSchema':'/db/schema/mysql/CMysqlSchema.js','CMysqlTableSchema':'/db/schema/mysql/CMysqlTableSchema.js','COciColumnSchema':'/db/schema/oci/COciColumnSchema.js','COciCommandBuilder':'/db/schema/oci/COciCommandBuilder.js','COciSchema':'/db/schema/oci/COciSchema.js','COciTableSchema':'/db/schema/oci/COciTableSchema.js','CPgsqlColumnSchema':'/db/schema/pgsql/CPgsqlColumnSchema.js','CPgsqlSchema':'/db/schema/pgsql/CPgsqlSchema.js','CPgsqlTableSchema':'/db/schema/pgsql/CPgsqlTableSchema.js','CSqliteColumnSchema':'/db/schema/sqlite/CSqliteColumnSchema.js','CSqliteCommandBuilder':'/db/schema/sqlite/CSqliteCommandBuilder.js','CSqliteSchema':'/db/schema/sqlite/CSqliteSchema.js','CChoiceFormat':'/i18n/CChoiceFormat.js','CDateFormatter':'/i18n/CDateFormatter.js','CDbMessageSource':'/i18n/CDbMessageSource.js','CGettextMessageSource':'/i18n/CGettextMessageSource.js','CLocale':'/i18n/CLocale.js','CMessageSource':'/i18n/CMessageSource.js','CNumberFormatter':'/i18n/CNumberFormatter.js','CPhpMessageSource':'/i18n/CPhpMessageSource.js','CGettextFile':'/i18n/gettext/CGettextFile.js','CGettextMoFile':'/i18n/gettext/CGettextMoFile.js','CGettextPoFile':'/i18n/gettext/CGettextPoFile.js','CDbLogRoute':'/logging/CDbLogRoute.js','CEmailLogRoute':'/logging/CEmailLogRoute.js','CFileLogRoute':'/logging/CFileLogRoute.js','CLogFilter':'/logging/CLogFilter.js','CLogRoute':'/logging/CLogRoute.js','CLogRouter':'/logging/CLogRouter.js','CLogger':'/logging/CLogger.js','CProfileLogRoute':'/logging/CProfileLogRoute.js','CWebLogRoute':'/logging/CWebLogRoute.js','CDateTimeParser':'/utils/CDateTimeParser.js','CFileHelper':'/utils/CFileHelper.js','CFormatter':'/utils/CFormatter.js','CMarkdownParser':'/utils/CMarkdownParser.js','CPropertyValue':'/utils/CPropertyValue.js','CTimestamp':'/utils/CTimestamp.js','CVarDumper':'/utils/CVarDumper.js','CBooleanValidator':'/validators/CBooleanValidator.js','CCaptchaValidator':'/validators/CCaptchaValidator.js','CCompareValidator':'/validators/CCompareValidator.js','CDateValidator':'/validators/CDateValidator.js','CDefaultValueValidator':'/validators/CDefaultValueValidator.js','CEmailValidator':'/validators/CEmailValidator.js','CExistValidator':'/validators/CExistValidator.js','CFileValidator':'/validators/CFileValidator.js','CFilterValidator':'/validators/CFilterValidator.js','CInlineValidator':'/validators/CInlineValidator.js','CNumberValidator':'/validators/CNumberValidator.js','CRangeValidator':'/validators/CRangeValidator.js','CRegularExpressionValidator':'/validators/CRegularExpressionValidator.js','CRequiredValidator':'/validators/CRequiredValidator.js','CSafeValidator':'/validators/CSafeValidator.js','CStringValidator':'/validators/CStringValidator.js','CTypeValidator':'/validators/CTypeValidator.js','CUniqueValidator':'/validators/CUniqueValidator.js','CUnsafeValidator':'/validators/CUnsafeValidator.js','CUrlValidator':'/validators/CUrlValidator.js','CValidator':'/validators/CValidator.js','CActiveDataProvider':'/web/CActiveDataProvider.js','CArrayDataProvider':'/web/CArrayDataProvider.js','CAssetManager':'/web/CAssetManager.js','CBaseController':'/web/CBaseController.js','CCacheHttpSession':'/web/CCacheHttpSession.js','CClientScript':'/web/CClientScript.js','CController':'/web/CController.js','CDataProvider':'/web/CDataProvider.js','CDbHttpSession':'/web/CDbHttpSession.js','CExtController':'/web/CExtController.js','CFormModel':'/web/CFormModel.js','CHttpCookie':'/web/CHttpCookie.js','CHttpRequest':'/web/CHttpRequest.js','CHttpSession':'/web/CHttpSession.js','CHttpSessionIterator':'/web/CHttpSessionIterator.js','COutputEvent':'/web/COutputEvent.js','CPagination':'/web/CPagination.js','CSort':'/web/CSort.js','CSqlDataProvider':'/web/CSqlDataProvider.js','CTheme':'/web/CTheme.js','CThemeManager':'/web/CThemeManager.js','CUploadedFile':'/web/CUploadedFile.js','CUrlManager':'/web/CUrlManager.js','CWebApplication':'/web/CWebApplication.js','CWebModule':'/web/CWebModule.js','CWidgetFactory':'/web/CWidgetFactory.js','CAction':'/web/actions/CAction.js','CInlineAction':'/web/actions/CInlineAction.js','CViewAction':'/web/actions/CViewAction.js','CAccessControlFilter':'/web/auth/CAccessControlFilter.js','CAuthAssignment':'/web/auth/CAuthAssignment.js','CAuthItem':'/web/auth/CAuthItem.js','CAuthManager':'/web/auth/CAuthManager.js','CBaseUserIdentity':'/web/auth/CBaseUserIdentity.js','CDbAuthManager':'/web/auth/CDbAuthManager.js','CPhpAuthManager':'/web/auth/CPhpAuthManager.js','CUserIdentity':'/web/auth/CUserIdentity.js','CWebUser':'/web/auth/CWebUser.js','CFilter':'/web/filters/CFilter.js','CFilterChain':'/web/filters/CFilterChain.js','CInlineFilter':'/web/filters/CInlineFilter.js','CForm':'/web/form/CForm.js','CFormButtonElement':'/web/form/CFormButtonElement.js','CFormElement':'/web/form/CFormElement.js','CFormElementCollection':'/web/form/CFormElementCollection.js','CFormInputElement':'/web/form/CFormInputElement.js','CFormStringElement':'/web/form/CFormStringElement.js','CGoogleApi':'/web/helpers/CGoogleApi.js','CHtml':'/web/helpers/CHtml.js','CJSON':'/web/helpers/CJSON.js','CJavaScript':'/web/helpers/CJavaScript.js','CPradoViewRenderer':'/web/renderers/CPradoViewRenderer.js','CViewRenderer':'/web/renderers/CViewRenderer.js','CWebService':'/web/services/CWebService.js','CWebServiceAction':'/web/services/CWebServiceAction.js','CWsdlGenerator':'/web/services/CWsdlGenerator.js','CActiveForm':'/web/widgets/CActiveForm.js','CAutoComplete':'/web/widgets/CAutoComplete.js','CClipWidget':'/web/widgets/CClipWidget.js','CContentDecorator':'/web/widgets/CContentDecorator.js','CFilterWidget':'/web/widgets/CFilterWidget.js','CFlexWidget':'/web/widgets/CFlexWidget.js','CHtmlPurifier':'/web/widgets/CHtmlPurifier.js','CInputWidget':'/web/widgets/CInputWidget.js','CMarkdown':'/web/widgets/CMarkdown.js','CMaskedTextField':'/web/widgets/CMaskedTextField.js','CMultiFileUpload':'/web/widgets/CMultiFileUpload.js','COutputCache':'/web/widgets/COutputCache.js','COutputProcessor':'/web/widgets/COutputProcessor.js','CStarRating':'/web/widgets/CStarRating.js','CTabView':'/web/widgets/CTabView.js','CTextHighlighter':'/web/widgets/CTextHighlighter.js','CTreeView':'/web/widgets/CTreeView.js','CWidget':'/web/widgets/CWidget.js','CCaptcha':'/web/widgets/captcha/CCaptcha.js','CCaptchaAction':'/web/widgets/captcha/CCaptchaAction.js','CBasePager':'/web/widgets/pagers/CBasePager.js','CLinkPager':'/web/widgets/pagers/CLinkPager.js','CListPager':'/web/widgets/pagers/CListPager.js'},
  34	/**
  35	 * Augments a class with properties from another class
  36	 * @param {Object} receivingClass The class that should be augmented
  37	 * @param {Object} givingClass The class that donates the properties
  38	 */
  39	augment: function (receivingClass, givingClass) {
  40		var methodName;
  41		for (methodName in givingClass.prototype) {
  42			if(!receivingClass.prototype[methodName]) {
  43				receivingClass.prototype[methodName] = givingClass.prototype[methodName];
  44			}
  45		}
  46	},
  47	
  48	/**	
  49	 * @returns {String} the version of Yii framework
  50	 */
  51	getVersion: function () {
  52		return '1.1.8-dev';
  53	},
  54	/**	
  55	 * Creates a Web application instance.
  56	 * @param {Mixed} config application configuration.
  57	 * If a string, it is treated as the path of the file that contains the configuration;
  58	 * If an array, it is the actual configuration information.
  59	 * Please make sure you specify the {@link CApplication::basePath basePath} property in the configuration,
  60	 * which should point to the directory containing all application logic, template and data.
  61	 * If not, the directory will be defaulted to 'protected'.
  62	 */
  63	createWebApplication: function (config) {
  64		if (config === undefined) {
  65			config = null;
  66		}
  67		return Yii.createApplication('CWebApplication',config);
  68	},
  69	/**	
  70	 * Creates a console application instance.
  71	 * @param {Mixed} config application configuration.
  72	 * If a string, it is treated as the path of the file that contains the configuration;
  73	 * If an array, it is the actual configuration information.
  74	 * Please make sure you specify the {@link CApplication::basePath basePath} property in the configuration,
  75	 * which should point to the directory containing all application logic, template and data.
  76	 * If not, the directory will be defaulted to 'protected'.
  77	 */
  78	createConsoleApplication: function (config) {
  79		if (config === undefined) {
  80			config = null;
  81		}
  82		return Yii.createApplication('CConsoleApplication',config);
  83	},
  84	/**	
  85	 * Creates an application of the specified class.
  86	 * @param {String} classVar the application class name
  87	 * @param {Mixed} config application configuration. This parameter will be passed as the parameter
  88	 * to the constructor of the application class.
  89	 * @returns {Mixed} the application instance
  90	 * @since 1.0.10
  91	 */
  92	createApplication: function (classVar, config) {
  93		if (config === undefined) {
  94			config = null;
  95		}
  96		
  97		return new Yii[classVar](config);
  98		
  99	},
 100	/**	
 101	 * Returns the application singleton, null if the singleton has not been created yet.
 102	 * @returns {Yii.CApplication} the application singleton, null if the singleton has not been created yet.
 103	 */
 104	app: function () {
 105		return Yii._app;
 106	},
 107	/**	
 108	 * Stores the application instance in the class static member.
 109	 * This method helps implement a singleton pattern for CApplication.
 110	 * Repeated invocation of this method or the CApplication constructor
 111	 * will cause the throw of an exception.
 112	 * To retrieve the application instance, use {@link app()}.
 113	 * @param {Yii.CApplication} app the application instance. If this is null, the existing
 114	 * application singleton will be removed.
 115	 * @throws {Yii.CException} if multiple application instances are registered.
 116	 */
 117	setApplication: function (app) {
 118		var _app;
 119		if(Yii._app===null || app===null) {
 120			Yii._app=app;
 121		}
 122		else {
 123			throw new Yii.CException(Yii.t('yii','Yii application can only be created once.'));
 124		}
 125	},
 126	/**	
 127	 * @returns {String} the path of the framework
 128	 */
 129	getFrameworkPath: function () {
 130		return YII_PATH;
 131	},
 132	/**	
 133	 * Creates an object and initializes it based on the given configuration.
 134	 * 
 135	 * The specified configuration can be either a string or an array.
 136	 * If the former, the string is treated as the object type which can
 137	 * be either the class name or {@link Yii::getPathOfAlias class path alias}.
 138	 * If the latter, the 'class' element is treated as the object type,
 139	 * and the rest name-value pairs in the array are used to initialize
 140	 * the corresponding object properties.
 141	 * 
 142	 * Any additional parameters passed to this method will be
 143	 * passed to the constructor of the object being created.
 144	 * 
 145	 * NOTE: the array-typed configuration has been supported since version 1.0.1.
 146	 * 
 147	 * @param {Mixed} config the configuration. It can be either a string or an array.
 148	 * @returns {Mixed} the created object
 149	 * @throws {Yii.CException} if the configuration does not have a 'class' element.
 150	 */
 151	createComponent: function (config) {
 152		var type, n, args, object, classVar, key, value;
 153		
 154		if(typeof(config) === 'string') {
 155			type=config;
 156			config=[];
 157		}
 158		else if(config['class'] !== undefined) {
 159			type=config['class'];
 160			delete config['class'];
 161		}
 162		else {
 163			throw new Yii.CException(Yii.t('yii','Object configuration must be an array containing a "class" element.'));
 164		}
 165		if(!Yii[type]) {
 166			type=Yii.imports(type,true);
 167		}
 168		if((n=arguments.length)>1) {
 169			args=arguments;
 170			if(n===2) {
 171				object=new Yii[type](args[1]);
 172			}
 173			else if(n===3) {
 174				object=new Yii[type](args[1],args[2]);
 175			}
 176			else if(n===4) {
 177				object=new Yii[type](args[1],args[2],args[3]);
 178			}
 179			else if(n===4) {
 180				object=new Yii[type](args[1],args[2],args[3]);
 181			}
 182			else if(n===5) {
 183				object=new Yii[type](args[1],args[2],args[3],args[4]);
 184			}
 185		}
 186		else {
 187			object=new Yii[type]();
 188		}
 189		
 190		for (key in config) {
 191			if (config.hasOwnProperty(key)) {
 192				
 193				value = config[key];
 194				object.set(key,value);
 195			}
 196		}
 197		
 198		return object;
 199	},
 200	/**	
 201	 * Imports a class or a directory.
 202	 * 
 203	 * Importing a class is like including the corresponding class file.
 204	 * The main difference is that importing a class is much lighter because it only
 205	 * includes the class file when the class is referenced the first time.
 206	 * 
 207	 * Importing a directory is equivalent to adding a directory into the PHP include path.
 208	 * If multiple directories are imported, the directories imported later will take
 209	 * precedence in class file searching (i.e., they are added to the front of the PHP include path).
 210	 * 
 211	 * Path aliases are used to import a class or directory. For example,
 212	 * <ul>
 213	 *   <li><code>application.components.GoogleMap</code>: import the <code>GoogleMap</code> class.</li>
 214	 *   <li><code>application.components.*</code>: import the <code>components</code> directory.</li>
 215	 * </ul>
 216	 * 
 217	 * The same path alias can be imported multiple times, but only the first time is effective.
 218	 * Importing a directory does not import any of its subdirectories.
 219	 * 
 220	 * Starting from version 1.1.5, this method can also be used to import a class in namespace format
 221	 * (available for PHP 5.3 or above only). It is similar to importing a class in path alias format,
 222	 * except that the dot separator is replaced by the backslash separator. For example, importing
 223	 * <code>application\components\GoogleMap</code> is similar to importing <code>application.components.GoogleMap</code>.
 224	 * The difference is that the former class is using qualified name, while the latter unqualified.
 225	 * 
 226	 * Note, importing a class in namespace format requires that the namespace is corresponding to
 227	 * a valid path alias if we replace the backslash characters with dot characters.
 228	 * For example, the namespace <code>application\components</code> must correspond to a valid
 229	 * path alias <code>application.components</code>.
 230	 * 
 231	 * @param {String} alias path alias to be imported
 232	 * @param {Boolean} forceInclude whether to include the class file immediately. If false, the class file
 233	 * will be included only when the class is being used. This parameter is used only when
 234	 * the path alias refers to a class.
 235	 * @returns {String} the class name or the directory that this alias refers to
 236	 * @throws {Yii.CException} if the alias is invalid
 237	 */
 238	imports: function (alias, forceInclude) {
 239		var result, _imports, pos, namespace, path, classFile, classMap, className, isClass, _includePaths;
 240		if (forceInclude === undefined) {
 241			forceInclude = true;
 242		}
 243		if(Yii._imports[alias] !== undefined) {  // previously imported
 244			
 245			return Yii._imports[alias];
 246		}
 247		
 248		if(Yii[alias] !== undefined) {
 249			return (Yii._imports[alias]=alias);
 250		}
 251		if ((pos = alias.indexOf("/")) !== -1) {
 252			className = String(alias.split("/").pop());
 253			
 254			if (className.slice(-3) == ".js") {
 255				
 256				className = className.slice(0,-3);
 257			}
 258		
 259			if (Yii[className] !== undefined) {
 260				return (Yii._imports[alias] = className);
 261			}
 262			Yii.include(alias,!forceInclude);
 263			Yii.classMap[className] = alias;
 264			Yii._imports[alias] = className;
 265			
 266			return className; 
 267		}
 268		if((pos=alias.indexOf('.'))===-1) { // a simple class name
 269			result = Yii.autoload(alias, !forceInclude);
 270			if(forceInclude && !result) {
 271				throw new Yii.CException(Yii.t('yii','Alias "{alias}" is invalid. Make sure it points to an existing directory or file.',
 272				{'{alias}':alias}));				
 273			}
 274			Yii._imports[alias]=alias;
 275			return alias;
 276		}
 277		className=String(alias.split(".").pop());
 278		
 279		isClass=className!=='*';
 280		if (!isClass) {
 281			throw new Yii.CException("YiiJS does not support importing directories");
 282		}
 283		if(Yii[className] !== undefined) {
 284			return (Yii._imports[alias]=className);
 285		}
 286		
 287		else if((path=Yii.getPathOfAlias(alias))!==false) {
 288			Yii.include(path + ".js",!forceInclude);
 289			Yii.classMap[className]=path+'.js';
 290			return className;
 291		}
 292		else {
 293			throw new Yii.CException(Yii.t('yii','Alias "{alias}" is invalid. Make sure it points to an existing directory or file.',
 294				{'{alias}':alias}));
 295		}
 296	},
 297	/**	
 298	 * Translates an alias into a file path.
 299	 * Note, this method does not ensure the existence of the resulting file path.
 300	 * It only checks if the root alias is valid or not.
 301	 * @param {String} alias alias (e.g. system.web.CController)
 302	 * @returns {Mixed} file path corresponding to the alias, false if the alias is invalid.
 303	 */
 304	getPathOfAlias: function (alias) {
 305		var _aliases, pos, rootAlias, _app;
 306		if(Yii._aliases[alias] !== undefined) {
 307			return Yii._aliases[alias];
 308		}
 309		else if((pos=php.strpos(alias,'.'))!==false) {
 310			rootAlias=alias.slice(0, pos);
 311			if(Yii._aliases[rootAlias] !== undefined) {
 312				return (Yii._aliases[alias]=php.rtrim(Yii._aliases[rootAlias]+'/'+php.str_replace('.','/',alias.slice(pos+1)),'*'+'/'));
 313			}
 314			else if(Yii._app !== null && Yii._app instanceof Yii.CWebApplication){
 315				if(Yii._app.findModule(rootAlias)!==null) {
 316					return Yii.getPathOfAlias(alias);
 317				}
 318			}
 319		}
 320		return false;
 321	},
 322	/**	
 323	 * Create a path alias.
 324	 * Note, this method neither checks the existence of the path nor normalizes the path.
 325	 * @param {String} alias alias to the path
 326	 * @param {String} path the path corresponding to the alias. If this is null, the corresponding
 327	 * path alias will be removed.
 328	 */
 329	setPathOfAlias: function (alias, path) {
 330		var _aliases;
 331		if(php.empty(path)) {
 332			delete Yii._aliases[alias];
 333		}
 334		else {
 335			Yii._aliases[alias]=php.rtrim(path,'\\/');
 336		}
 337	},
 338	/**	
 339	 * Class autoload loader.
 340	 * @param {String} className class name
 341	 * @param {Boolean} async Whether to load this class
 342	 * via an asynchronous AJAX request, otherwise a blocking request is used, defaults to false.
 343	 * @returns {Boolean} whether the class has been loaded successfully
 344	 */
 345	autoload: function (className, async) {
 346		var _coreClasses, classMap, namespace, path, result;
 347		if (async === undefined) {
 348			async = true;
 349		}
 350		
 351		if(Yii._coreClasses[className] !== undefined) {
 352			if (Yii[className] !== undefined) {
 353				return true;
 354			}
 355		
 356			result = Yii.include(YII_PATH+Yii._coreClasses[className], async);
 357			if (!async) {
 358				return result;
 359			}
 360		}
 361		else if(Yii.classMap[className] !== undefined) {
 362			if (Yii[className] !== undefined) {
 363				return true;
 364			}
 365			result = Yii.include(Yii.classMap[className], async);
 366			if (!async) {
 367				return result;
 368			}
 369		}
 370		else {
 371			return Yii[className] !== undefined;
 372		}
 373		return true;
 374	},
 375	
 376	/**
 377	 * Includes a remote file, this will be evaled!
 378	 * @param {String} url The URL to load the file from
 379	 * @param {Boolean} async Whether to perform an asynchronous request or not, defaults to true.
 380	 * @param {Function} callback The callback to execute after the included file is evaled
 381	 * @returns {Mixed} either the jQuery ajax request if this is async, or
 382	 * if this is a blocking request returns the content or false depending on whether
 383	 * it succeeded or not.
 384	 */
 385	include: function (url, async, callback) {
 386		var options = {}, request;
 387		if (async === undefined) {
 388			async = true;
 389		}
 390		if (callback === undefined) {
 391			callback = function () {};
 392		}
 393		if(Yii._includePaths[url] !== undefined) {  // previously imported
 394			return Yii._includePaths[url];
 395		}
 396		options.url = url;
 397		options.async = async;
 398		options.cache = false;
 399		if (async) {
 400			options.success = function (res) {
 401				Yii._includePaths[url] = eval(res);
 402				callback(Yii._includePaths[url]);
 403			};
 404			options.error = function () {
 405				throw new Yii.CHttpException(404, Yii.t("system", "No such file"));
 406			};
 407			return jQuery.ajax(options);
 408		}
 409		else {
 410			
 411			request = jQuery.ajax(options);
 412			if (request.status > 399) {
 413				return false;
 414			}
 415			Yii._includePaths[url] = eval(request.responseText);
 416			callback(Yii._includePaths[url]);
 417			return Yii._includePaths[url];
 418			
 419			
 420		}
 421	},
 422	
 423	
 424	/**	
 425	 * Writes a trace message.
 426	 * This method will only log a message when the application is in debug mode.
 427	 * @param {String} msg message to be logged
 428	 * @param {String} category category of the message
 429	 * @see log
 430	 */
 431	trace: function (msg, category) {
 432		if (category === undefined) {
 433			category = 'application';
 434		}
 435		if(YII_DEBUG) {
 436			Yii.log(msg,Yii.CLogger.prototype.LEVEL_TRACE,category);
 437		}
 438	},
 439	/**	
 440	 * Logs a message.
 441	 * Messages logged by this method may be retrieved via {@link CLogger::getLogs}
 442	 * and may be recorded in different media, such as file, email, database, using
 443	 * {@link CLogRouter}.
 444	 * @param {String} msg message to be logged
 445	 * @param {String} level level of the message (e.g. 'trace', 'warning', 'error'). It is case-insensitive.
 446	 * @param {String} category category of the message (e.g. 'system.web'). It is case-insensitive.
 447	 */
 448	log: function (msg, level, category) {
 449		var _logger, traces, count, i, limit, trace, cmd;
 450		if (level === undefined) {
 451			level = 'info';
 452		}
 453		if (category === undefined) {
 454			category = 'application';
 455		}
 456		if(Yii._logger===null) {
 457			Yii._logger=new Yii.CLogger();
 458		}
 459		if(window['console'] !== undefined && YII_DEBUG && YII_TRACE_LEVEL>0 && level!==Yii.CLogger.prototype.LEVEL_PROFILE)	{
 460			cmd = "log";
 461			if (level === Yii.CLogger.prototype.LEVEL_ERROR) {
 462				cmd = "error";
 463			}
 464			else if (level === Yii.CLogger.prototype.LEVEL_WARNING) {
 465				cmd = "warn";
 466			}
 467			console[cmd](level + "\t" + php.str_pad(category,30," ") + "\t" + msg);
 468		}
 469		Yii._logger.log(msg,level,category);
 470	},
 471	/**	
 472	 * Marks the begin of a code block for profiling.
 473	 * This has to be matched with a call to {@link endProfile()} with the same token.
 474	 * The begin- and end- calls must also be properly nested, e.g.,
 475	 * <pre>
 476	 * Yii.beginProfile('block1');
 477	 * Yii.beginProfile('block2');
 478	 * Yii.endProfile('block2');
 479	 * Yii.endProfile('block1');
 480	 * </pre>
 481	 * The following sequence is not valid:
 482	 * <pre>
 483	 * Yii.beginProfile('block1');
 484	 * Yii.beginProfile('block2');
 485	 * Yii.endProfile('block1');
 486	 * Yii.endProfile('block2');
 487	 * </pre>
 488	 * @param {String} token token for the code block
 489	 * @param {String} category the category of this log message
 490	 * @see endProfile
 491	 */
 492	beginProfile: function (token, category) {
 493		if (category === undefined) {
 494			category = 'application';
 495		}
 496		Yii.log('begin:'+token,Yii.CLogger.prototype.LEVEL_PROFILE,category);
 497	},
 498	/**	
 499	 * Marks the end of a code block for profiling.
 500	 * This has to be matched with a previous call to {@link beginProfile()} with the same token.
 501	 * @param {String} token token for the code block
 502	 * @param {String} category the category of this log message
 503	 * @see beginProfile
 504	 */
 505	endProfile: function (token, category) {
 506		if (category === undefined) {
 507			category = 'application';
 508		}
 509		Yii.log('end:'+token,Yii.CLogger.prototype.LEVEL_PROFILE,category);
 510	},
 511	/**	
 512	 * @returns {Yii.CLogger} message logger
 513	 */
 514	getLogger: function () {
 515		var _logger;
 516		if(Yii._logger!==null) {
 517			return Yii._logger;
 518		}
 519		else {
 520			return (Yii._logger=new Yii.CLogger);
 521		}
 522	},
 523	/**	
 524	 * Returns a string that can be displayed on your Web page showing Powered-by-Yii information
 525	 * @returns {String} a string that can be displayed on your Web page showing Powered-by-Yii information
 526	 */
 527	powered: function () {
 528		return 'Powered by <a href="http://www.yiiframework.com/" rel="external">Yii Framework</a>.';
 529	},
 530	/**	
 531	 * Translates a message to the specified language.
 532	 * Starting from version 1.0.2, this method supports choice format (see {@link CChoiceFormat}),
 533	 * i.e., the message returned will be chosen from a few candidates according to the given
 534	 * number value. This feature is mainly used to solve plural format issue in case
 535	 * a message has different plural forms in some languages.
 536	 * @param {String} category message category. Please use only word letters. Note, category 'yii' is
 537	 * reserved for Yii framework core code use. See {@link CPhpMessageSource} for
 538	 * more interpretation about message category.
 539	 * @param {String} message the original message
 540	 * @param {Array} params parameters to be applied to the message using <code>strtr</code>.
 541	 * Starting from version 1.0.2, the first parameter can be a number without key.
 542	 * And in this case, the method will call {@link CChoiceFormat::format} to choose
 543	 * an appropriate message translation.
 544	 * Starting from version 1.1.6 you can pass parameter for {@link CChoiceFormat::format}
 545	 * or plural forms format without wrapping it with array.
 546	 * @param {String} source which message source application component to use.
 547	 * Defaults to null, meaning using 'coreMessages' for messages belonging to
 548	 * the 'yii' category and using 'messages' for the rest messages.
 549	 * @param {String} language the target language. If null (default), the {@link CApplication::getLanguage application language} will be used.
 550	 * This parameter has been available since version 1.0.3.
 551	 * @returns {String} the translated message
 552	 * @see CMessageSource
 553	 */
 554	t: function (category, message, params, source, language) {
 555		var _app, chunks, expressions, n, i;
 556		if (params === undefined) {
 557			params = {};
 558		}
 559		if (source === undefined) {
 560			source = null;
 561		}
 562		if (language === undefined) {
 563			language = null;
 564		}
 565		
 566		
 567		if(Yii._app!==null) {
 568			if(source===null) {
 569				source=(category==='yii'||category==='zii')?'coreMessages':'messages';
 570			}
 571			if((source=Yii._app.getComponent(source))!==null && source !== undefined) {
 572				message=source.translate(category,message,language);
 573			}
 574		}
 575		
 576		if(params==={} || params === []) {
 577			return message;
 578		}
 579		
 580		if(params[0] !== undefined) {
 581			// number choice
 582			if(php.strpos(message,'|')!==false) {
 583				if(php.strpos(message,'#')===false) {
 584					chunks=message.split('|');
 585					expressions=Yii._app.getLocale(language).getPluralRules();
 586					n=php.min(php.count(chunks),php.count(expressions));
 587					if(n) {
 588						for(i=0;i<n;i++) {
 589							chunks[i]=expressions[i]+'#'+chunks[i];
 590						}
 591						message=chunks.join('|');
 592					}
 593				}
 594				message=Yii.CChoiceFormat.format(message,params[0]);
 595			}
 596			if(params['{n}'] === undefined) {
 597				params['{n}']=params[0];
 598			}
 599			delete params[0];
 600		}
 601		if (params !== {}) {
 602			return php.strtr(message,params);
 603		}
 604		return message;
 605	},
 606	/**	
 607	 * Registers a new class autoloader.
 608	 * The new autoloader will be placed before {@link autoload} and after
 609	 * any other existing autoloaders.
 610	 * @param {Function} callback a valid PHP callback (function name or array($className,$methodName)).
 611	 * @since 1.0.10
 612	 */
 613	registerAutoloader: function (callback) {
 614		
 615	},
 616	/**
 617	 * Removes JSDoc comments from a string
 618	 * TODO: move this somewhere else
 619	 * @param {String} str the string to strip
 620	 * @returns {String} the stripped string
 621	 */
 622	removeComments: function (str) {
 623 
 624	    var uid = '_' + (new Date()),
 625	        primatives = [],
 626	        primIndex = 0;
 627	 
 628	    return (
 629	        str
 630	        .replace(/(['"])(\\\1|.)+?\1/g, function(match){
 631	            primatives[primIndex] = match;
 632	            return (uid + '') + primIndex++;
 633	        })
 634	        .replace(/([^\/])(\/(?!\*|\/)(\\\/|.)+?\/[gim]{0,3})/g, function(match, $1, $2){
 635	            primatives[primIndex] = $2;
 636	            return $1 + (uid + '') + primIndex++;
 637	        })
 638	        .replace(/\/\/.*?\/?\*.+?(?=\n|\r|$)|\/\*[\s\S]*?\/\/[\s\S]*?\*\//g, '')
 639	        .replace(/\/\/.+?(?=\n|\r|$)|\/\*[\s\S]+?\*\//g, '')
 640	        .replace(RegExp('\\/\\*[\\s\\S]+' + uid + '\\d+', 'g'), '')
 641	        .replace(RegExp(uid + '(\\d+)', 'g'), function(match, n){
 642	            return primatives[n];
 643	        })
 644	    );
 645	},
 646	/**
 647	 * Similar to PHP's preg_match_all
 648	 * @param {RegExp} regex The regular expression to match against
 649	 * @param {String} haystack The string to perform the regex on
 650	 * @returns {Array} an array of matches
 651	 */
 652	matchAll:  function (regex, haystack) {
 653		var matches = [], i, match;
 654		match = regex.exec(haystack);
 655			
 656		while (match !== null) {
 657			matches.push(match);
 658			match = regex.exec(haystack);
 659		}
 660		return matches;
 661	},
 662	/**
 663	 * Extends a class
 664	 */
 665	extend: function (childClass, parentClass, properties) {
 666		childClass.prototype = new Yii[parentClass](false);
 667		childClass.prototype.constructor = childClass; 
 668		if (properties !== undefined) {
 669			Yii.forEach(properties, function(name, value) {
 670				childClass.prototype[name] = value;
 671			});
 672		}
 673	},
 674	
 675	/**
 676	 * Implements foreach in JavaScript
 677	 * @param {Mixed} itemList a list of items to iterate through
 678	 * @param {Function} callback The callback function, it will recieve 2 parameters, key and value
 679	 * if the callback returns false, the loop will break.
 680	 */
 681	forEach: function (itemList, callback) {
 682		var i, limit;
 683		if (typeof itemList === "function") {
 684			return Yii.forEach(itemList(), callback);
 685		}
 686		if (Object.prototype.toString.call(itemList) === '[object Array]' || itemList instanceof Yii.CList || itemList instanceof Yii.CStack) {
 687			limit = itemList.length;
 688			for (i = 0; i < limit; i++) {
 689				if (i === "forEach") {
 690					continue;
 691				}
 692				else if (callback(i, itemList[i]) === false) {
 693					break;
 694				}
 695			}
 696		}
 697		else {
 698			for (i in itemList) {
 699				if (itemList.hasOwnProperty(i)) {
 700					if (i === "forEach") {
 701						continue;
 702					}
 703					else if (callback(i, itemList[i]) === false) {
 704						break;
 705					}	
 706				}
 707			}
 708		}
 709		return itemList;
 710	},
 711	
 712	/**
 713	 * Filter an array of items
 714	 */
 715	filter: function (items, block) {
 716        var values = [];
 717        var thisp = arguments[1];
 718        for (var i = 0; i < items.length; i++)
 719            if (block.call(thisp, items[i]))
 720                values.push(items[i]);
 721        return values;
 722    }
 723};
 724/**
 725 * A shortcut to application properties.
 726 * Supports virtual getters and setters, e.g:
 727 * <pre>
 728 * $app("securityManager.validationKey") === Yii.app().getSecurityManager().getValidationKey();
 729 * </pre>
 730 */
 731var $app = function(selector, setVal) {
 732	var stack, parts, i, limit, item, getter, last;
 733	if (selector === undefined || php.trim(selector).length === 0) {
 734		return Yii.app();
 735	}
 736	parts = selector.split(".");
 737	
 738	limit = parts.length;
 739	last = limit - 1;
 740	stack = Yii.app();
 741	for (i = 0; i < limit; i++) {
 742		
 743		if (stack instanceof Yii.CComponent) {
 744			if (setVal !== undefined) {
 745				return stack.set(parts.join("."),setVal);
 746			}
 747			return stack.get(parts.join("."));
 748		}
 749		item = parts.shift();
 750		if (i === last && setVal !== undefined) {
 751			if (stack[item] !== undefined) {
 752				stack[item] = setVal;
 753				return setVal;
 754			}
 755			else if (stack.get !== undefined) {
 756				stack = stack.set.call(stack, item, setVal);
 757				return setVal;
 758			}
 759			else {
 760				throw new Yii.CException("No such property: " + item);
 761			}
 762		}
 763		else {
 764			if (stack[item] !== undefined) {
 765				stack = stack[item];
 766			}
 767			else if (stack.get !== undefined) {
 768				stack = stack.get.call(stack, item);
 769			}
 770			else {
 771				throw new Yii.CException("No such property: " + item);
 772			}
 773		}
 774	}
 775	
 776	return stack;
 777};/*global Yii, php, $, jQuery, alert, clearInterval, clearTimeout, document, event, frames, history, Image, location, name, navigator, Option, parent, screen, setInterval, setTimeout, window, XMLHttpRequest */
 778/**
 779 * CComponent is the base class for all components.
 780 * 
 781 * CComponent implements the protocol of defining, using properties and events.
 782 * 
 783 * A property is defined by a getter method, and/or a setter method.
 784 * Properties can be accessed in the way like accessing normal object members.
 785 * Reading or writing a property will cause the invocation of the corresponding
 786 * getter or setter method, e.g
 787 * <pre>
 788 * a=component.text;     // equivalent to $a=$component->getText();
 789 * component.text='abc';  // equivalent to $component->setText('abc');
 790 * </pre>
 791 * The signatures of getter and setter methods are as follows,
 792 * <pre>
 793 * // getter, defines a readable property 'text'
 794 * public function getText() { +++ }
 795 * // setter, defines a writable property 'text' with $value to be set to the property
 796 * public function setText(value) { +++ }
 797 * </pre>
 798 * 
 799 * An event is defined by the presence of a method whose name starts with 'on'.
 800 * The event name is the method name. When an event is raised, functions
 801 * (called event handlers) attached to the event will be invoked automatically.
 802 * 
 803 * An event can be raised by calling {@link raiseEvent} method, upon which
 804 * the attached event handlers will be invoked automatically in the order they
 805 * are attached to the event. Event handlers must have the following signature,
 806 * <pre>
 807 * function eventHandler(event) { +++ }
 808 * </pre>
 809 * where $event includes parameters associated with the event.
 810 * 
 811 * To attach an event handler to an event, see {@link attachEventHandler}.
 812 * You can also use the following syntax:
 813 * <pre>
 814 * component.onClick=callback;    // or $component->onClick->add($callback);
 815 * </pre>
 816 * where $callback refers to a valid PHP callback. Below we show some callback examples:
 817 * <pre>
 818 * 'handleOnClick'                   // handleOnClick() is a global function
 819 * [object,'handleOnClick']    // using $object->handleOnClick()
 820 * ['Page','handleOnClick']     // using Page::handleOnClick()
 821 * </pre>
 822 * 
 823 * To raise an event, use {@link raiseEvent}. The on-method defining an event is
 824 * commonly written like the following:
 825 * <pre>
 826 * public function onClick(event)
 827 * {
 828 *     this.raiseEvent('onClick',event);
 829 * }
 830 * </pre>
 831 * where <code>$event</code> is an instance of {@link CEvent} or its child class.
 832 * One can then raise the event by calling the on-method instead of {@link raiseEvent} directly.
 833 * 
 834 * Both property names and event names are case-insensitive.
 835 * 
 836 * Starting from version 1.0.2, CComponent supports behaviors. A behavior is an
 837 * instance of {@link IBehavior} which is attached to a component. The methods of
 838 * the behavior can be invoked as if they belong to the component. Multiple behaviors
 839 * can be attached to the same component.
 840 * 
 841 * To attach a behavior to a component, call {@link attachBehavior}; and to detach the behavior
 842 * from the component, call {@link detachBehavior}.
 843 * 
 844 * A behavior can be temporarily enabled or disabled by calling {@link enableBehavior}
 845 * or {@link disableBehavior}, respectively. When disabled, the behavior methods cannot
 846 * be invoked via the component.
 847 * 
 848 * Starting from version 1.1.0, a behavior's properties (either its public member variables or
 849 * its properties defined via getters and/or setters) can be accessed through the component it
 850 * is attached to.
 851 * 
 852 * @originalAuthor Qiang Xue <qiang.xue@gmail.com>
 853 * @version $Id: CComponent.php 3066 2011-03-13 14:22:55Z qiang.xue $
 854 * @package system.base
 855 * @since 1.0
 856 * @author Charles Pick
 857 * @class
 858 */
 859Yii.CComponent = function CComponent() {
 860};
 861Yii.CComponent.prototype._e = null;
 862Yii.CComponent.prototype._m = null;
 863/**
 864 * Gets the class name for this item.
 865 * Since JavaScript doesn't really support this we 
 866 * abuse function declarations to implement it,
 867 * for example instead of:
 868 * <pre>
 869 * Yii.Blah = function() { ... }
 870 * </pre>
 871 * we use:
 872 * <pre>
 873 * Yii.Blah = function Blah() { ... }
 874 * </pre>
 875 * We can now retrieve the name of the class by inspecting the constructor.
 876 */
 877Yii.CComponent.prototype.getClassName = function() {
 878	var matches, className;
 879	
 880	matches = /function(.*)\((.*)\)/.exec((this).constructor);
 881	if (matches) {
 882		return php.trim(matches[1]);
 883	}
 884};
 885/**
 886 * Returns a property value, an event handler list or a behavior based on its name.
 887 * Do not call this method. This is a PHP magic method that we override
 888 * to allow using the following syntax to read a property or obtain event handlers:
 889 * <pre>
 890 * value=component.propertyName;
 891 * handlers=component.eventName;
 892 * </pre>
 893 * @param {String} name the property name or event name
 894 * @returns {Mixed} the property value, event handlers attached to the event, or the named behavior (since version 1.0.2)
 895 * @throws {Yii.CException} if the property or event is not defined
 896 * @see __set
 897 */
 898Yii.CComponent.prototype.get = function (name) {
 899		var getter, i, object, nameParts = [], limit;
 900		
 901		if (name.indexOf !== undefined && name.indexOf(".") !== -1) {
 902			nameParts = name.split(".");
 903			name = nameParts.shift();
 904		}
 905		if (this[name] !== undefined) {
 906			object = this[name];
 907			if (nameParts.length > 0) {
 908				if (object instanceof Yii.CComponent) {
 909					return object.get(nameParts.join("."));
 910				}
 911				limit = nameParts.length;
 912				for (i = 0; i < limit; i++) {
 913					name = nameParts.shift();
 914					object = object[name];
 915					if (nameParts.length === 0) {
 916						return object;
 917					}
 918					
 919					if (object instanceof Yii.CComponent) {
 920						return object.get(nameParts.join("."));
 921					}
 922				}
 923			}
 924			return object;
 925		}
 926		getter='get'+php.ucfirst(name);
 927		if(php.method_exists(this,getter)) {
 928			object = this[getter]();
 929			if (nameParts.length > 0) {
 930				if (object instanceof Yii.CComponent) {
 931					return object.get(nameParts.join("."));
 932				}
 933				limit = nameParts.length;
 934				for (i = 0; i < limit; i++) {
 935					name = nameParts.shift();
 936					object = object[name];
 937					if (nameParts.length === 0) {
 938						return object;
 939					}
 940					
 941					if (object instanceof Yii.CComponent) {
 942						return object.get(nameParts.join("."));
 943					}
 944					
 945				}
 946			}
 947			return object;
 948		}
 949		else if(php.strncasecmp(name,'on',2)===0 && php.method_exists(this,name)) {
 950			// duplicating getEventHandlers() here for performance
 951			name=name.toLowerCase();
 952			if(this._e[name] === undefined) {
 953				this._e[name]=new Yii.CList();
 954			}
 955			return this._e[name];
 956		}
 957		else if(this._m !== null && this._m[name] !== undefined) {
 958			return this._m[name];
 959		}
 960		else if(this._m !== null) {
 961			for (i in this._m) {
 962				if (this._m.hasOwnProperty(i)) {
 963					
 964					object = this._m[i];
 965					try {
 966						if(object.getEnabled() && (php.property_exists(object,name) || object.canGetProperty(name))) {
 967							if (nameParts.length > 0) {
 968								return object.get(nameParts.join("."));
 969							}
 970							return object.get(name);
 971						}
 972					}
 973					catch (e) {
 974						console.log(e);
 975					}
 976				}
 977			}
 978		}
 979		console.log(this.getClassName() + " : " + name);
 980		throw new Yii.CException(Yii.t('yii','Property "{class}.{property}" is not defined.',
 981			{'{class}':this.getClassName(), '{property}':name}));
 982	};
 983/**
 984 * Sets value of a component property.
 985 * Do not call this method. This is a PHP magic method that we override
 986 * to allow using the following syntax to set a property or attach an event handler
 987 * <pre>
 988 * this.propertyName=value;
 989 * this.eventName=callback;
 990 * </pre>
 991 * @param {String} name the property name or the event name
 992 * @param {Mixed} value the property value or callback
 993 * @throws {Yii.CException} if the property/event is not defined or the property is read only.
 994 * @see __get
 995 */
 996Yii.CComponent.prototype.set = function (name, value) {
 997		var setter, i, object, nameParts = [];
 998		if (name.indexOf(".") !== -1) {
 999			nameParts = name.split(".");
1000			name = nameParts.pop();
1001			return (this.get(nameParts.join("."))[name] = value);
1002		}
1003		if (this[name] !== undefined) {
1004			return (this[name] = value);
1005		}
1006		
1007		setter='set'+php.ucfirst(name);
1008		if(php.method_exists(this,setter)) {
1009			return this[setter](value);
1010		}
1011		else if(php.strncasecmp(name,'on',2)===0 && php.method_exists(this,name)) {
1012			// duplicating getEventHandlers() here for performance
1013			name=name.toLowerCase();
1014			if(this._e[name] === undefined) {
1015				this._e[name]=new Yii.CList();
1016			}
1017			return this._e[name].add(value);
1018		}
1019		else if(this._m !== null) {
1020			for (i in this._m) {
1021				if (this._m.hasOwnProperty(i)) {
1022					
1023					object = this._m[i];
1024					
1025					if(object.getEnabled() && (php.property_exists(object,name) || object.canSetProperty(name))) {
1026						return (object.set(name,value));
1027					}
1028				}
1029			}
1030		}
1031		if(php.method_exists(this,'get'+php.ucfirst(name))) {
1032			throw new Yii.CException(Yii.t('yii','Property "{class}.{property}" is read only.',
1033				{'{class}':this.getClassName(), '{property}':name}));
1034		}
1035		else {
1036			throw new Yii.CException(Yii.t('yii','Property "{class}.{property}" is not defined.',
1037				{'{class}':this.getClassName(), '{property}':name}));
1038		}
1039	};
1040/**
1041 * Checks if a property value is null.
1042 * Do not call this method. This is a PHP magic method that we override
1043 * to allow using isset() to detect if a component property is set or not.
1044 * @param {String} name the property name or the event name
1045 * @since 1.0.1
1046 */
1047Yii.CComponent.prototype.isset = function (name) {
1048		var getter, i, object, nameParts = [], value;
1049		if (name.indexOf(".") !== -1) {
1050			nameParts = name.split(".");
1051			name = nameParts.pop();
1052			try {
1053				value = this.get(nameParts.join("."))[name];
1054				if (value !== undefined && value !== null) {
1055					return true;
1056				}
1057				return false;
1058			}
1059			catch (e) {
1060				return false;
1061			}
1062		}
1063		if (this[name] !== undefined) {
1064			return true;
1065		}
1066		getter='get'+php.ucfirst(name);
1067		if(php.method_exists(this,getter)) {
1068			return (this[getter]()!==null);
1069		}
1070		else if(php.strncasecmp(name,'on',2)===0 && php.method_exists(this,name))
1071		{
1072			name=name.toLowerCase();
1073			return this._e !== null && this._e[name] !== undefined && this._e[name].getCount();
1074		}
1075		else if(this._m !== null) {
1076			if(this._m[name] !== undefined) {
1077				return true;
1078			}
1079			for (i in this._m) {
1080				if (this._m.hasOwnProperty(i)) {
1081					object = this._m[i];
1082					if(object.getEnabled() && (php.property_exists(object,name) || object.canGetProperty(name))) {
1083						return true;
1084					}
1085				}
1086			}
1087		}
1088		return false;
1089	};
1090/**
1091 * Sets a component property to be null.
1092 * Do not call this method. This is a PHP magic method that we override
1093 * to allow using unset() to set a component property to be null.
1094 * @param {String} name the property name or the event name
1095 * @throws {Yii.CException} if the property is read only.
1096 * @since 1.0.1
1097 */
1098Yii.CComponent.prototype.unset = function (name) {
1099		var setter, i, object, nameParts = [];
1100		if (name.indexOf(".") !== -1) {
1101			nameParts = name.split(".");
1102			name = nameParts.pop();
1103			object = this.get(nameParts.join("."))[name];
1104			if (object.unset !== undefined) {
1105				return object.unset(name);
1106			} 
1107			return (this.get(nameParts.join("."))[name] = null);
1108		}
1109		setter='set'+php.ucfirst(name);
1110		if (this[name] !== undefined) {
1111			this[name] = null; 
1112			return;
1113		}
1114		else if(php.method_exists(this,setter)) {
1115			this[setter](null);
1116		}
1117		else if(php.strncasecmp(name,'on',2)===0 && php.method_exists(this,name)) {
1118			delete this._e[name.toLowerCase()];
1119		}
1120		else if(this._m !== null)
1121		{
1122			if(this._m[name] !== undefined) {
1123				this.detachBehavior(name);
1124			}
1125			else
1126			{
1127				for (i in this._m) {
1128					if (this._m.hasOwnProperty(i)) {
1129						object = this._m[i];
1130						if(object.getEnabled())	{
1131							if(php.property_exists(object,name)) {
1132								return (object[name]=null);
1133							}
1134							else if(object.canSetProperty(name)) {
1135								return object[setter](null);
1136							}
1137						}
1138					}
1139				}
1140			}
1141		}
1142		else if(php.method_exists(this,'get'+name)) {
1143			throw new Yii.CException(Yii.t('yii','Property "{class}.{property}" is read only.',
1144				{'{class}':this.getClassName(), '{property}':name}));
1145		}
1146	};
1147/**
1148 * Calls the named method which is not a class method.
1149 * Do not call this method. This is a PHP magic method that we override
1150 * to implement the behavior feature.
1151 * @param {String} name the method name
1152 * @param {Array} parameters method parameters
1153 * @returns {Mixed} the method return value
1154 * @since 1.0.2
1155 */
1156Yii.CComponent.prototype.call = function (name, parameters) {
1157		var i, object;
1158		if (this[name] !== undefined) {
1159			return php.call_user_func_array([this,name],parameters);
1160		}
1161		else if(this._m!==null) {
1162			for (i in this._m) {
1163				if (this._m.hasOwnProperty(i)) {
1164					object = this._m[i];
1165					if(object.getEnabled() && php.method_exists(object,name)) {
1166						return php.call_user_func_array([object,name],parameters);
1167					}
1168				}
1169			}
1170		}
1171		
1172		throw new Yii.CException(Yii.t('yii','{class} does not have a method named "{name}".',
1173			{'{class}':this.getClassName(), '{name}':name}));
1174	};
1175/**
1176 * Returns the named behavior object.
1177 * The name 'asa' stands for 'as a'.
1178 * @param {String} behavior the behavior name
1179 * @returns {IBehavior} the behavior object, or null if the behavior does not exist
1180 * @since 1.0.2
1181 */
1182Yii.CComponent.prototype.asa = function (behavior) {
1183		return this._m !== null && this._m[behavior] !== undefined ? this._m[behavior] : null;
1184	};
1185/**
1186 * Attaches a list of behaviors to the component.
1187 * Each behavior is indexed by its name and should be an instance of
1188 * {@link IBehavior}, a string specifying the behavior class, or an
1189 * array of the following structure:
1190 * <pre>
1191 * {
1192 *     'class':'path.to.BehaviorClass',
1193 *     'property1':'value1',
1194 *     'property2':'value2',
1195 * }
1196 * </pre>
1197 * @param {Array} behaviors list of behaviors to be attached to the component
1198 * @since 1.0.2
1199 */
1200Yii.CComponent.prototype.attachBehaviors = function (behaviors) {
1201		var name, behavior;
1202		for (name in behaviors) {
1203			if (behaviors.hasOwnProperty(name)) {
1204				behavior = behaviors[name];
1205				this.attachBehavior(name,behavior);
1206			}
1207		}
1208	};
1209/**
1210 * Detaches all behaviors from the component.
1211 * @since 1.0.2
1212 */
1213Yii.CComponent.prototype.detachBehaviors = function () {
1214		var name, behavior;
1215		if(this._m!==null) {
1216			for (name in this._m) {
1217				if (this._m.hasOwnProperty(name)) {
1218					behavior = this._m[name];
1219					this.detachBehavior(name);
1220				}
1221			}
1222			this._m=null;
1223		}
1224	};
1225/**
1226 * Attaches a behavior to this component.
1227 * This method will create the behavior object based on the given
1228 * configuration. After that, the behavior object will be initialized
1229 * by calling its {@link IBehavior::attach} method.
1230 * @par…

Large files files are truncated, but you can click here to view the full file