/** * Instantiates a subclass of X2Chart, passing it a function which allows it to save widget * settings. */ public function getSetupScript() { if (!isset($this->_setupScript)) { $widgetClass = get_called_class(); $chartData = $this->getInitialChartData(); $userNames = User::getNames(); $eventTypes = array('all' => Yii::t('app', 'All Events')) + Events::$eventLabels; $socialSubtypes = json_decode(Dropdowns::model()->findByPk(113)->options, true); $visibilityFilters = array('1' => 'Public', '0' => 'Private'); $chartSettingsData = self::getChartSettingsProvider($this->chartType)->data; $this->_setupScript = parent::getSetupScript() . "\n \$(function () {\n var chartUID = '{$this->chartType}{$this->widgetUID}';\n x2[chartUID] = {};\n x2[chartUID].chart = X2Chart.instantiateTemporarySubtype (\n X2UsersChart, {\n " . (isset($chartData) ? "chartData :" . CJSON::encode($chartData) . "," : '') . "\n actionParams: " . CJSON::encode(array('widgetType' => get_called_class())) . ",\n socialSubtypes:" . CJSON::encode(array_keys($socialSubtypes)) . ",\n visibilityTypes:" . CJSON::encode(array_keys($visibilityFilters)) . ",\n eventTypes:" . CJSON::encode(array_keys($eventTypes)) . ", \n translations: " . CJSON::encode($this->getTranslations()) . ",\n getChartDataActionName: 'getEventsBetween',\n saveChartSetting: function (key, value, callback) {\n this.lastChartSettings[key] = value;\n x2.{$widgetClass}{$this->widgetUID}.setProperty (\n 'chartSettings', this.lastChartSettings, callback);\n },\n suppressDateRangeSelector: false,\n suppressChartSettings: false,\n lastChartSettings: " . CJSON::encode($this->getChartSettings()) . ",\n widgetUID: '{$this->widgetUID}',\n chartType: '{$this->chartType}',\n chartSubtype: '" . self::getJSONProperty($this->profile, 'chartSubtype', $this->widgetType, $this->widgetUID) . "',\n chartSettings: " . CJSON::encode(count($chartSettingsData) ? array_combine(array_map(function ($setting) { return $setting->name; }, $chartSettingsData), $chartSettingsData) : array()) . "\n });\n \$(document).trigger ('{$this->chartType}' + 'Ready');\n });\n "; } return $this->_setupScript; }