Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • None
  • system
    • base
    • caching
    • console
    • db
      • ar
      • schema
    • validators
    • web
      • actions
      • auth
      • helpers
      • widgets
        • captcha
        • pagers
  • zii
    • widgets
      • grid

Classes

  • ActionFormModel
  • ArrayUtil
  • ArrayValidator
  • AssociatedMediaBehavior
  • AuxLib
  • Changelog
  • DetailView
  • EncryptUtilTmp
  • EventsWidgetFieldFormatter
  • FailedLogins
  • FieldFormatter
  • FieldFormatterBase
  • FieldInputRenderer
  • FileFieldBehavior
  • FiltersForm
  • FilterUtil
  • FineDiff
  • FineDiffCopyOp
  • FineDiffDeleteOp
  • FineDiffInsertOp
  • FineDiffOp
  • FineDiffOps
  • FineDiffReplaceOp
  • GlobalCSSFormModel
  • GlobalImportFormModel
  • GoogleAuthenticator
  • JSONFieldsBehavior
  • JSONResponse
  • MediaFieldFormatter
  • MediaSelector
  • MobileActiveRecordFieldFormatter
  • MobileActivityFeed
  • MobileChartDashboard
  • MobileFieldFormatter
  • MobileFieldInputRenderer
  • ModuleModelNameValidator
  • MultiChildNode
  • MultiTypeAutocomplete
  • PasswordUtil
  • ProductFeature
  • ProfileWidgetLayout
  • QueryParamGenerator
  • RecordLimitBehavior
  • RecordView
  • RecordViewWidgetLayout
  • RelationshipsGridModel
  • RelationshipsJoin
  • RepairUserDataCommand
  • RequestUtil
  • RequiredIfNotSetValidator
  • ResponseUtil
  • RunMigrationScriptCommand
  • ServiceWebFormDesigner
  • Settings
  • StringUtil
  • TestEmailAction
  • TestEmailActionForm
  • ThemeGenerator
  • TimerUtil
  • TopicsFieldFormatter
  • TopicsWidgetLayout
  • TransactionalViewFieldFormatter
  • UrlUtil
  • ValidLinkValidator
  • WebFormDesigner
  • WebLeadFormDesigner
  • X2ActiveRecordBehavior
  • X2ActiveRecordFieldFormatter
  • X2ButtonColumn
  • X2ConditionList
  • X2ConsoleCommand
  • X2ControllerBehavior
  • X2DataColumn
  • X2DuplicateBehavior
  • X2Flashes
  • X2GridViewFieldFormatter
  • X2IPAddress
  • X2LeadsDataColumn
  • X2MergeableBehavior
  • X2MessageSource
  • X2MobileControllerBehavior
  • X2MobileProfileControllerBehavior
  • X2MobileQuotesControllerBehavior
  • X2MobileSiteControllerBehavior
  • X2MobileTopicsControllerBehavior
  • X2ModelConversionBehavior
  • X2ModelConversionWidget
  • X2ModelForeignKeyValidator
  • X2ModelUniqueIndexValidator
  • X2NonWebUser
  • X2StaticDropdown
  • X2StaticField
  • X2StaticFieldsBehavior
  • X2UrlManager
  • X2Validator
  • X2WidgetBehavior

Interfaces

  • AdminOwnedCredentials

Exceptions

  • CampaignMailingException
  • CodeExchangeException
  • GetCredentialsException
  • NoRefreshTokenException
  • NoUserIdException
  • StringUtilException

Functions

  • checkCurrency
  • checkDNS
  • checkServerVar
  • checkTimezone
  • decodeQuotes
  • echoIcons
  • encodeQuotes
  • exceptionForError
  • getField
  • getLanguageName
  • getModuleTitle
  • handleReqError
  • handleReqException
  • installer_t
  • installer_tr
  • isAllowedDir
  • mediaMigrationRrmdir
  • migrateMediaDir
  • printGraph
  • printR
  • renderFields
  • reqShutdown
  • RIP
  • translateOptions
  • tryGetRemote
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /*****************************************************************************************
  3:  * X2Engine Open Source Edition is a customer relationship management program developed by
  4:  * X2Engine, Inc. Copyright (C) 2011-2016 X2Engine Inc.
  5:  * 
  6:  * This program is free software; you can redistribute it and/or modify it under
  7:  * the terms of the GNU Affero General Public License version 3 as published by the
  8:  * Free Software Foundation with the addition of the following permission added
  9:  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
 10:  * IN WHICH THE COPYRIGHT IS OWNED BY X2ENGINE, X2ENGINE DISCLAIMS THE WARRANTY
 11:  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
 12:  * 
 13:  * This program is distributed in the hope that it will be useful, but WITHOUT
 14:  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 15:  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
 16:  * details.
 17:  * 
 18:  * You should have received a copy of the GNU Affero General Public License along with
 19:  * this program; if not, see http://www.gnu.org/licenses or write to the Free
 20:  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 21:  * 02110-1301 USA.
 22:  * 
 23:  * You can contact X2Engine, Inc. P.O. Box 66752, Scotts Valley,
 24:  * California 95067, USA. or at email address contact@x2engine.com.
 25:  * 
 26:  * The interactive user interfaces in modified source and object code versions
 27:  * of this program must display Appropriate Legal Notices, as required under
 28:  * Section 5 of the GNU Affero General Public License version 3.
 29:  * 
 30:  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
 31:  * these Appropriate Legal Notices must retain the display of the "Powered by
 32:  * X2Engine" logo. If the display of the logo is not reasonably feasible for
 33:  * technical reasons, the Appropriate Legal Notices must display the words
 34:  * "Powered by X2Engine".
 35:  *****************************************************************************************/
 36: 
 37: /**
 38:  * Adds namespace mechanism, packages, and JS class instantiation to children of CWidget 
 39:  */
 40: 
 41: class X2WidgetBehavior extends CBehavior {
 42: 
 43:     const NAMESPACE_KEY = '_x2widget_namespace';
 44: 
 45:     /**
 46:      * @var string $element
 47:      */
 48:     public $element; 
 49: 
 50:     /**
 51:      * @var string $JSClass
 52:      */
 53:     public $JSClass = 'Widget'; 
 54: 
 55:     /**
 56:      * @var bool $instantiateJSClassOnInit
 57:      */
 58:     public $instantiateJSClassOnInit = false;
 59: 
 60:     public $checkIfJSClassIsDefined = false;
 61: 
 62:     /**
 63:      * @var string $namespace
 64:      */
 65:     public $namespace = ''; 
 66: 
 67:     public function __construct () {
 68:     }
 69: 
 70:     public function attach ($owner) {
 71:         if (!($owner instanceof CWidget)) {
 72:             throw new CException ('owner must be an instance of CWidget'); 
 73:         }
 74:         return parent::attach ($owner);
 75:     }
 76: 
 77:     public function initNamespace () {
 78:         if ($this->owner->namespace === '' && isset ($_POST[self::NAMESPACE_KEY])) {
 79:             $this->owner->namespace = $_POST[self::NAMESPACE_KEY];
 80:         }
 81:     }
 82: 
 83:     public function resolveIds ($selector) {
 84:         return preg_replace ('/#/', '#'.$this->owner->namespace, $selector);
 85:     }
 86: 
 87:     public function resolveId ($id) {
 88:         return $this->owner->namespace.$id;
 89:     }
 90: 
 91:     public function getJSObjectName () {
 92:         return "x2.".$this->owner->namespace.lcfirst ($this->owner->JSClass);
 93:     }
 94: 
 95:     public function registerPackages () {
 96:         Yii::app()->clientScript->registerPackages ($this->owner->getPackages (), true);
 97:     }
 98: 
 99:     protected $_packages;
100:     public function getPackages () {
101:         if (!isset ($this->_packages)) {
102:             $this->_packages = array (
103:                 'X2Widget' => array(
104:                     'baseUrl' => Yii::app()->request->baseUrl,
105:                     'js' => array(
106:                         'js/X2Widget.js',
107:                     ),
108:                 ),
109:             );
110:         }
111:         return $this->_packages;
112:     }
113: 
114:     public function prepareJSParams ($args, array $functions=array ()) {
115:         foreach ($args as $key => &$val) {
116:             if (is_array ($val)) {
117:             } else if (is_string ($val) && preg_match ('/^js:/', $val)) {
118:                 $val = preg_replace ('/^js:/', '', $val);
119:                 $functions[$key] = $val;
120:                 unset ($args[$key]);
121:             }
122:         }
123:         unset ($val);
124: 
125:         $paramStr = '';
126:         if (count ($functions)) {
127:             $fnStr = '';
128:             foreach ($functions as $key => $val) {
129:                 $fnStr .= $key . ': ' . $val . ',';
130:             }
131:             $fnStr = preg_replace ('/,$/', '', $fnStr);
132:             $paramStr = '$.extend ('.CJSON::encode ($args).', {'.
133:                 $fnStr.
134:             '})';
135:         } else {
136:             $paramStr = CJSON::encode ($args);
137:         }
138: 
139:         return $paramStr;
140:     }
141: 
142:     /**
143:      * @param bool $onReady whether or not JS class should be instantiated after page is ready
144:      */
145:     public function instantiateJSClass ($onReady=true) {
146:         $jsObjName = $this->owner->getJSObjectName ();
147: 
148:         $args = $this->prepareJSParams ($this->owner->getJSClassParams ());
149: 
150:         $js = ($this->checkIfJSClassIsDefined ? "if (typeof $jsObjName === 'undefined') {" : '').
151:             "$jsObjName = new x2.{$this->owner->JSClass} (".
152:                     $args.
153:                 ");".
154:             ($this->checkIfJSClassIsDefined ? "}" : '');
155:         $scriptName = $this->owner->getId ().get_class ($this->owner).'JSClassInstantiation';
156: 
157:         if (Yii::app()->params->isMobileApp) {
158:             Yii::app()->controller->onPageLoad ($js, $scriptName);  
159:         } else {
160:             Yii::app()->clientScript->registerScript (
161:                 $scriptName,
162:                 ($onReady ? "$(function () {" : "").
163:                     $js.
164:                 ($onReady ? "});" : ""), CClientScript::POS_END);
165:         }
166: 
167:         Yii::app()->clientScript->registerScript('X2WidgetSetup',"
168:         x2.Widget.NAMESPACE_KEY = '".self::NAMESPACE_KEY."';
169:         ", CClientScript::POS_READY);
170:     }
171: 
172:     protected $_translations;
173:     protected function getTranslations () {
174:         if (!isset ($this->_translations)) {
175:             $this->_translations = array ();
176:         }
177:         return $this->_translations;
178:     }
179: 
180:     protected $_JSClassParams;
181:     public function getJSClassParams () {
182:         if (!isset ($this->_JSClassParams)) {
183:             $this->_JSClassParams = array (
184:                 'element' => isset ($this->owner->element) ? 
185:                     $this->owner->element : '#'.$this->owner->id,
186:                 'translations' => $this->owner->getTranslations (),
187:                 'namespace' => $this->owner->namespace,
188:             );
189:         }
190:         return $this->_JSClassParams;
191:     }
192: 
193:     public function setJSClassParams ($jSClassParams) {
194:         $this->_JSClassParams = array_merge ($this->getJSClassParams (), $jSClassParams);
195:     }
196: 
197: }
198: 
199: ?>
200: 
X2CRM Documentation API documentation generated by ApiGen 2.8.0