public function run()
 {
     $tree = $this->getTree();
     # заплатка
     $tree = $tree[0]['children'];
     echo CJavaScript::jsonEncode($tree);
 }
Пример #2
0
 /**
  * Register Script
  */
 public function registerScript()
 {
     $basePath = Yii::getPathOfAlias('application.modules.user.views.asset');
     $baseUrl = Yii::app()->getAssetManager()->publish($basePath);
     $cs = Yii::app()->getClientScript();
     $cs->registerCoreScript('jquery');
     $cs->registerCssFile($baseUrl . '/css/redmond/jquery-ui.css');
     $cs->registerCssFile($baseUrl . '/css/style.css');
     $cs->registerScriptFile($baseUrl . '/js/jquery-ui.min.js');
     $cs->registerScriptFile($baseUrl . '/js/form.js');
     $cs->registerScriptFile($baseUrl . '/js/jquery.json.js');
     $widgets = self::getWidgets();
     $wgByTypes = ProfileField::itemAlias('field_type');
     foreach ($wgByTypes as $k => $v) {
         $wgByTypes[$k] = array();
     }
     foreach ($widgets[1] as $widget) {
         if (isset($widget['fieldType']) && count($widget['fieldType'])) {
             foreach ($widget['fieldType'] as $type) {
                 array_push($wgByTypes[$type], $widget['name']);
             }
         }
     }
     //echo '<pre>'; print_r($widgets[1]); die();
     $js = "\n\n\tvar name = \$('#name'),\n\tvalue = \$('#value'),\n\tallFields = \$([]).add(name).add(value),\n\ttips = \$('.validateTips');\n\t\n\tvar listWidgets = jQuery.parseJSON('" . str_replace("'", "\\'", CJavaScript::jsonEncode($widgets[0])) . "');\n\tvar widgets = jQuery.parseJSON('" . str_replace("'", "\\'", CJavaScript::jsonEncode($widgets[1])) . "');\n\tvar wgByType = jQuery.parseJSON('" . str_replace("'", "\\'", CJavaScript::jsonEncode($wgByTypes)) . "');\n\t\n\tvar fieldType = {\n\t\t\t'INTEGER':{\n\t\t\t\t'hide':['match','other_validator','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':10,\n\t\t\t\t\t'default':'0',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'VARCHAR':{\n\t\t\t\t'hide':['widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':255,\n\t\t\t\t\t'default':'',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'TEXT':{\n\t\t\t\t'hide':['field_size','range','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':0,\n\t\t\t\t\t'default':'',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'DATE':{\n\t\t\t\t'hide':['field_size','field_size_min','match','range','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':0,\n\t\t\t\t\t'default':'0000-00-00',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'FLOAT':{\n\t\t\t\t'hide':['match','other_validator','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':'10.2',\n\t\t\t\t\t'default':'0.00',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'DECIMAL':{\n\t\t\t\t'hide':['match','other_validator','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':'10,2',\n\t\t\t\t\t'default':'0',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'BOOL':{\n\t\t\t\t'hide':['field_size','field_size_min','match','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':0,\n\t\t\t\t\t'default':0,\n\t\t\t\t\t'range':'1==" . UserModule::t('Yes') . ";0==" . UserModule::t('No') . "',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'BLOB':{\n\t\t\t\t'hide':['field_size','field_size_min','match','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':0,\n\t\t\t\t\t'default':'',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t},\n\t\t\t'BINARY':{\n\t\t\t\t'hide':['field_size','field_size_min','match','widgetparams'],\n\t\t\t\t'val':{\n\t\t\t\t\t'field_size':0,\n\t\t\t\t\t'default':'',\n\t\t\t\t\t'range':'',\n\t\t\t\t\t'widgetparams':''\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\t\t\n\tfunction showWidgetList(type) {\n\t\t\$('div.widget select').empty();\n\t\t\$('div.widget select').append('<option value=\"\">" . UserModule::t('No') . "</option>');\n\t\tif (wgByType[type]) {\n\t\t\tfor (var k in wgByType[type]) {\n\t\t\t\t\$('div.widget select').append('<option value=\"'+wgByType[type][k]+'\">'+widgets[wgByType[type][k]]['label']+'</option>');\n\t\t\t}\n\t\t}\n\t}\n\t\t\n\tfunction setFields(type) {\n\t\tif (fieldType[type]) {\n\t\t\tif (" . (isset($_GET['id']) ? 0 : 1) . ") {\n\t\t\t\tshowWidgetList(type);\n\t\t\t\t\$('#widgetlist option:first').attr('selected', 'selected');\n\t\t\t}\n\t\t\t\n\t\t\t\$('div.row').addClass('toshow').removeClass('tohide');\n\t\t\tif (fieldType[type].hide.length) \$('div.'+fieldType[type].hide.join(', div.')).addClass('tohide').removeClass('toshow');\n\t\t\tif (\$('div.widget select').val()) {\n\t\t\t\t\$('div.widgetparams').removeClass('tohide');\n\t\t\t}\n\t\t\t\$('div.toshow').show(500);\n\t\t\t\$('div.tohide').hide(500);\n\t\t\t" . (!isset($_GET['id']) ? "\n\t\t\tfor (var k in fieldType[type].val) { \n\t\t\t\t\$('div.'+k+' input').val(fieldType[type].val[k]);\n\t\t\t}" : '') . "\n\t\t}\n\t}\n\t\n\tfunction isArray(obj) {\n\t\tif (obj.constructor.toString().indexOf('Array') == -1)\n\t\t\treturn false;\n\t\telse\n\t\t\treturn true;\n\t}\n\t\t\n\t\$('#dialog-form').dialog({\n\t\tautoOpen: false,\n\t\theight: 400,\n\t\twidth: 400,\n\t\tmodal: true,\n\t\tbuttons: {\n\t\t\t'" . UserModule::t('Save') . "': function() {\n\t\t\t\tvar wparam = {};\n\t\t\t\tvar fparam = {};\n\t\t\t\t\$('#dialog-form fieldset .wparam').each(function(){\n\t\t\t\t\tif (\$(this).val()) wparam[\$(this).attr('name')] = \$(this).val();\n\t\t\t\t});\n\t\t\t\t\n\t\t\t\tvar tab = \$('#tabs ul li.ui-tabs-selected').text();\n\t\t\t\tfparam[tab] = {};\n\t\t\t\t\$('#dialog-form fieldset .tab-'+tab).each(function(){\n\t\t\t\t\tif (\$(this).val()) fparam[tab][\$(this).attr('name')] = \$(this).val();\n\t\t\t\t});\n\t\t\t\t\n\t\t\t\tif (\$.JSON.encode(wparam)!='{}') \$('div.widgetparams input').val(\$.JSON.encode(wparam));\n\t\t\t\tif (\$.JSON.encode(fparam[tab])!='{}') \$('div.other_validator input').val(\$.JSON.encode(fparam)); \n\t\t\t\t\n\t\t\t\t\$(this).dialog('close');\n\t\t\t},\n\t\t\t'" . UserModule::t('Cancel') . "': function() {\n\t\t\t\t\$(this).dialog('close');\n\t\t\t}\n\t\t},\n\t\tclose: function() {\n\t\t}\n\t});\n\n\n\t\$('#widgetparams').focus(function() {\n\t\tvar widget = widgets[\$('#widgetlist').val()];\n\t\tvar html = '';\n\t\tvar wparam = (\$('div.widgetparams input').val())?\$.JSON.decode(\$('div.widgetparams input').val()):{};\n\t\tvar fparam = (\$('div.other_validator input').val())?\$.JSON.decode(\$('div.other_validator input').val()):{};\n\t\t\n\t\t// Class params\n\t\tfor (var k in widget.params) {\n\t\t\thtml += '<label for=\"name\">'+((widget.paramsLabels[k])?widget.paramsLabels[k]:k)+'</label>';\n\t\t\thtml += '<input type=\"text\" name=\"'+k+'\" id=\"widget_'+k+'\" class=\"text wparam ui-widget-content ui-corner-all\" value=\"'+((wparam[k])?wparam[k]:widget.params[k])+'\" />';\n\t\t}\n\t\t// Validator params\t\t\n\t\tif (widget.other_validator) {\n\t\t\tvar tabs = '';\n\t\t\tvar li = '';\n\t\t\tfor (var t in widget.other_validator) {\n\t\t\t\ttabs += '<div id=\"tab-'+t+'\" class=\"tab\">';\n\t\t\t\tli += '<li'+((fparam[t])?' class=\"ui-tabs-selected\"':'')+'><a href=\"#tab-'+t+'\">'+t+'</a></li>';\n\t\t\t\t\n\t\t\t\tfor (var k in widget.other_validator[t]) {\n\t\t\t\t\ttabs += '<label for=\"name\">'+((widget.paramsLabels[k])?widget.paramsLabels[k]:k)+'</label>';\n\t\t\t\t\tif (isArray(widget.other_validator[t][k])) {\n\t\t\t\t\t\ttabs += '<select type=\"text\" name=\"'+k+'\" id=\"filter_'+k+'\" class=\"text fparam ui-widget-content ui-corner-all tab-'+t+'\">';\n\t\t\t\t\t\tfor (var i in widget.other_validator[t][k]) {\n\t\t\t\t\t\t\ttabs += '<option value=\"'+widget.other_validator[t][k][i]+'\"'+((fparam[t]&&fparam[t][k])?' selected=\"selected\"':'')+'>'+widget.other_validator[t][k][i]+'</option>';\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttabs += '</select>';\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttabs += '<input type=\"text\" name=\"'+k+'\" id=\"filter_'+k+'\" class=\"text fparam ui-widget-content ui-corner-all tab-'+t+'\" value=\"'+((fparam[t]&&fparam[t][k])?fparam[t][k]:widget.other_validator[t][k])+'\" />';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\ttabs += '</div>';\n\t\t\t}\n\t\t\thtml += '<div id=\"tabs\"><ul>'+li+'</ul>'+tabs+'</div>';\n\t\t}\n\t\t\n\t\t\$('#dialog-form fieldset').html(html);\n\t\t\n\t\t\$('#tabs').tabs();\n\t\t\n\t\t// Show form\n\t\t\$('#dialog-form').dialog('open');\n\t});\n\t\n\t\$('#field_type').change(function() {\n\t\tsetFields(\$(this).val());\n\t});\n\t\n\t\$('#widgetlist').change(function() {\n\t\tif (\$(this).val()) {\n\t\t\t\$('div.widgetparams').show(500);\n\t\t} else {\n\t\t\t\$('div.widgetparams').hide(500);\n\t\t}\n\t\t\n\t});\n\t\n\t// show all function \n\t\$('div.form p.note').append('<br/><a href=\"#\" id=\"showAll\">" . UserModule::t('Show all') . "</a>');\n \t\$('#showAll').click(function(){\n\t\t\$('div.row').show(500);\n\t\treturn false;\n\t});\n\t\n\t// init\n\tsetFields(\$('#field_type').val());\n\t\n\t";
     $cs->registerScript(__CLASS__ . '#dialog', $js);
 }
Пример #3
0
 protected function _returnJson($data)
 {
     $this->layout = false;
     header('Content-type: application/json');
     echo \CJavaScript::jsonEncode($data);
     \Yii::app()->end();
 }
 /**
  * Displays a particular model.
  * @param integer $id the ID of the model to be displayed
  */
 public function actionAdditem($item_id)
 {
     $user_id = Yii::app()->user->id;
     // find the users cart
     $user = User::model()->find(array('condition' => 'id=:user_id', 'params' => array(':user_id' => $user_id)));
     // find the users cart
     $cart = Cart::model()->find(array('condition' => 'cart_owner=:cart_owner', 'params' => array(':cart_owner' => $user_id)));
     // find the item being reffered to by item_id
     $item = Item::model()->find(array('condition' => 'id=:item_id', 'params' => array(':item_id' => $item_id)));
     if (is_null($cart)) {
         // if the cart is not found. create a cart for the user.
         $cart = new Cart();
         $cart->cart_owner = $user->id;
         $cart->save();
     }
     // check if the same order was already made & increment else, create new
     $order = Order::model()->find(array('condition' => 'item_id=:item_id AND cart_id=:cart_id AND order_by=:order_by', 'params' => array(':item_id' => $item_id, ':cart_id' => $cart->id, ':order_by' => $user->id)));
     if (is_null($order)) {
         $order = new Order();
         $order->create_time = time();
         $order->quantity = 1;
         $order->item_id = $item->id;
         $order->cart_id = $cart->id;
         $order->order_by = $user->id;
     } else {
         $order->quantity = 1 + $order->quantity;
         $order->update_time = time();
     }
     $order->save();
     // find all orders by this user.
     $orders = Order::model()->findAll('cart_id=:cart_id AND order_by=:order_by', array(':cart_id' => $cart->id, ':order_by' => $user->id));
     $return = array('success' => true, 'data' => $orders);
     echo CJavaScript::jsonEncode($return);
     Yii::app()->end();
 }
 public function run()
 {
     Yii::import($this->import);
     $data = CHtml::listData(Brand::model()->findAll(array('order' => 'title')), 'id', 'title');
     $data[0] = '';
     ksort($data);
     echo CJavaScript::jsonEncode($data);
 }
 public function actionGetJsonList()
 {
     // $professores = Professor::model()->findAll();
     // echo CJavaScript::jsonEncode($professores);
     $list = Yii::app()->db->createCommand('SELECT professor.id_professor, nome, aprovado, foto, AVG(voto) as nota FROM professor INNER JOIN voto ON voto.id_professor = professor.id_professor GROUP BY professor.id_professor')->queryAll();
     echo CJavaScript::jsonEncode($list);
     exit;
 }
 public function init()
 {
     $options = CJavaScript::jsonEncode($this->options);
     $this->htmlOptions['onclick'] = strtr('WdatePicker({options});', array('{options}' => $options));
     $dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'source';
     $this->baseUrl = Yii::app()->getAssetManager()->publish($dir);
     $cs = Yii::app()->getClientScript();
     $cs->registerScriptFile($this->baseUrl . '/WdatePicker.js');
 }
Пример #8
0
 public function actionUserList()
 {
     $data = Jobs::model()->findAll(array('select' => 'uid', 'distinct' => true));
     $just_users = array();
     foreach ($data as $key => $value) {
         $just_users[] = $value["uid"];
     }
     echo CJavaScript::jsonEncode($just_users);
     Yii::app()->end();
 }
Пример #9
0
 /**
  * This is the action to handle external exceptions.
  */
 public function actionError()
 {
     if ($error = Yii::app()->errorHandler->error) {
         if (Yii::app()->request->isAjaxRequest) {
             header('Content-type: application/json');
             echo CJavaScript::jsonEncode(array('result' => 0, 'error' => $error));
         } else {
             $this->render('error', $error);
         }
     }
 }
 public function run()
 {
     if (Yii::app()->request->isAjaxRequest) {
         // this was set with the "max" attribute of the CAutoComplete widget
         $limit = Yii::app()->request->getParam('limit', 50);
         $limit = min($limit, 50);
         $criteria = new CDbCriteria();
         $criteria->limit = $limit;
         $criteria->order = 'title';
         echo CJavaScript::jsonEncode(CHtml::listData(DiskProducers::model()->findAll($criteria), 'id', 'title'));
     }
 }
Пример #11
0
 /**
  * Registers required scripts
  */
 public function registerClientScript()
 {
     $id = $this->options['id'];
     $jsData = \CJavaScript::jsonEncode($this->data);
     $jsOptions = \CJavaScript::jsonEncode($this->options);
     $script = "\n\t\t\tgoogle.setOnLoadCallback(drawChart{$id});\n\t\t\tvar {$id}=null;\n\t\t\tfunction drawChart{$id}() {\n\t\t\t\tvar data = google.visualization.arrayToDataTable({$jsData});\n\n\t\t\t\tvar options = {$jsOptions};\n\n\t\t\t\t{$id} = new google.visualization.{$this->visualization}(document.getElementById('{$this->containerId}'));\n\t\t\t\t{$id}.draw(data, options);\n\t\t\t}";
     /** @var $cs \CClientScript */
     $cs = \Yii::app()->getClientScript();
     $cs->registerScriptFile('https://www.google.com/jsapi');
     $cs->registerScript(__CLASS__, 'google.load("visualization", "1", {packages:["corechart"]});', \CClientScript::POST_END);
     $cs->registerScript(md5($script), $script, \CClientScript::POS_END);
 }
Пример #12
0
 public function actionDetails()
 {
     if (!isset($_REQUEST['name'])) {
         echo CJavaScript::jsonEncode(false);
     } else {
         $disorder = Disorder::model()->find('fully_specified_name = ? OR term = ?', array($_REQUEST['name'], $_REQUEST['name']));
         if ($disorder) {
             echo $disorder->id;
         } else {
             echo CJavaScript::jsonEncode(false);
         }
     }
 }
 public function init()
 {
     parent::init();
     if ($this->enable) {
         $cs = Yii::app()->clientScript;
         $params = array('BASEURL' => Yii::app()->request->baseUrl, 'HTTPHOST' => $_SERVER['HTTP_HOST']);
         $script = 'var PARAMS = eval(' . CJavaScript::jsonEncode($params) . ');';
         $cs->registerScript('widget-params', $script, CClientScript::POS_BEGIN);
         $cs->registerScriptFile(Yii::app()->request->baseUrl . '/js/persist.js', CClientScript::POS_HEAD);
         $script = implode('', file(Yii::app()->basePath . '/../js/widget-collapse.min.js'));
         $cs->registerScript('widget-collapse', $script, CClientScript::POS_READY);
     }
 }
Пример #14
0
 public function actionDeleteComment()
 {
     $return['status'] = 0;
     $id = Yii::app()->request->getPost('id');
     $model = $this->loadModel($id);
     if (!$model || $model->owner_id != Yii::app()->user->id && !Yii::app()->user->checkAccess('backend_access')) {
         $return['message'] = tt('commentNotFound', 'comments');
     } else {
         $model->delete();
         $return['status'] = 1;
     }
     echo CJavaScript::jsonEncode($return);
 }
 public function run()
 {
     Yii::import($this->import);
     $id = Yii::app()->request->getParam('id', 0);
     if ($id <= 0) {
         echo '{}';
     } else {
         $data = CHtml::listData(Modification::model()->findAll(array('condition' => 'model_id=' . $id, 'order' => 'title')), 'id', 'title');
         $data[0] = '';
         ksort($data);
         echo CJavaScript::jsonEncode($data);
     }
 }
Пример #16
0
 /**
  * Publishes and registers the necessary script files.
  */
 protected function registerClientScript()
 {
     Yii::app()->bootstrap->registerAssetJs('highcharts/highcharts.js');
     $this->options = CMap::mergeArray(array('exporting' => array('enabled' => true)), $this->options);
     if (isset($this->options['exporting']) && @$this->options['exporting']['enabled']) {
         Yii::app()->bootstrap->registerAssetJs('highcharts/modules/exporting.js');
     }
     if (isset($this->options['theme'])) {
         Yii::app()->bootstrap->registerAssetJs('highcharts/themes/' . $this->options['theme'] . '.js');
     }
     $options = CJavaScript::jsonEncode($this->options);
     Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $this->getId(), "var highchart{$this->getId()} = new Highcharts.Chart({$options});");
 }
 /**
  * @see TbOperation
  * @return mixed|void
  */
 public function displaySummary()
 {
     $this->data[] = array('Label', 'Percent');
     foreach ($this->types as $type) {
         if (!isset($type['value'])) {
             $type['value'] = 0;
         }
         $this->data[] = $this->getTotal() ? array($type['label'], (double) number_format($type['value'] / $this->getTotal() * 100, 1)) : 0;
     }
     $data = CJavaScript::jsonEncode($this->data);
     $options = CJavaScript::jsonEncode($this->chartOptions);
     echo "<div id='{$this->id}' class='{$this->chartCssClass}' data-data='{$data}' data-options='{$options}'></div>";
     $this->registerClientScript();
 }
 public function run()
 {
     Yii::import($this->import);
     $id = Yii::app()->request->getParam('id', 0);
     if ($id <= 0) {
         echo '{}';
     } else {
         $models = Car::model()->findAll(array('condition' => 'brand_id=' . $id, 'order' => 'title'));
         $data = array('');
         foreach ($models as $m) {
             $data[$m->id] = $m->title . ' ' . EString::getYear($m->manufacture_start) . (empty($m->manufacture_end) ? '...' : ' - ' . EString::getYear($m->manufacture_end));
         }
         echo CJavaScript::jsonEncode($data);
     }
 }
 public function run()
 {
     if (Yii::app()->request->isAjaxRequest && isset($_GET['producer_id'])) {
         $producer_id = Yii::app()->request->getParam('producer_id');
         // this was set with the "max" attribute of the CAutoComplete widget
         $limit = Yii::app()->request->getParam('limit', 50);
         $limit = min($limit, 50);
         $criteria = new CDbCriteria();
         $criteria->condition = "producer_id = :sterm";
         $criteria->params = array(":sterm" => $producer_id);
         $criteria->limit = $limit;
         $criteria->order = 'title';
         echo CJavaScript::jsonEncode(CHtml::listData(Disk::model()->findAll($criteria), 'id', 'title'));
     }
 }
Пример #20
0
 public function init()
 {
     $path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'source';
     $baseUrl = Yii::app()->getAssetManager()->publish($path);
     $cs = Yii::app()->getClientScript();
     $cs->registerScriptFile($baseUrl . '/WdatePicker.js');
     $options = CJavaScript::jsonEncode($this->options);
     $this->htmlOptions['onclick'] = strtr('WdatePicker({options});', array('{options}' => $options));
     if ($this->hasModel()) {
         echo CHtml::activeTextField($this->model, $this->attribute, $this->htmlOptions);
     } else {
         list($name, $id) = $this->resolveNameID();
         echo CHtml::textField($name, $this->value, $this->htmlOptions);
     }
 }
Пример #21
0
 private function generateTimelineEvents()
 {
     $tour = array();
     $tourFlights = $this->tourModel->flightItems;
     foreach ($tourFlights as $flight) {
         $element = array('dayStart' => $flight->departureDate, 'dayEnd' => $flight->departureDate, 'type' => 'flight', 'color' => 'red', 'description' => $this->generateFlightDescription($flight));
         $tour[] = $element;
     }
     $tourHotels = $this->tourModel->hotelItems;
     foreach ($tourHotels as $hotel) {
         $element = array('dayStart' => $hotel->checkIn, 'dayEnd' => $hotel->checkOut, 'type' => 'hotel', 'color' => 'yellow', 'description' => $this->generateHotelDescription($hotel));
         $tour[] = $element;
     }
     $jsTour = CJavaScript::jsonEncode($tour);
     return $jsTour;
 }
Пример #22
0
    public function registerClientScript()
    {
        if (true !== $this->scriptRegistered) {
            $params = ['onload' => 'recaptchaLoadCallback', 'render' => 'explicit'];
            if (!empty($this->lang)) {
                $params['hl'] = $this->lang;
            }
            $widgetParams = ['sitekey' => $this->publicKey];
            if (!empty($this->size)) {
                $widgetParams['size'] = $this->size;
            }
            if (!empty($this->theme)) {
                $widgetParams['theme'] = $this->theme;
            }
            $widgetParams = \CJavaScript::jsonEncode($widgetParams);
            $jsCallback = <<<EOT
(function(g){
\t'use strict';
\tvar ReCaptchaComponent = function () {
\t    var self, defaultParams = {$widgetParams}, dfd = \$.Deferred();
\t    self = {
\t        init: function () {
\t            return dfd.resolve(self);
\t        },
\t        promise: function () {
\t            return dfd.promise();
\t        },
\t        recaptcha: function () {
\t            return grecaptcha;
\t        },
\t        widget: function (id, params) {
\t\t\t\tparams = \$.extend({}, defaultParams, params || {});
\t            return grecaptcha.render(id, params);
\t        }
\t    };
        return self;
\t};
\tg.recaptchaLoadCallback = (g.window.reCaptchaComponent = new ReCaptchaComponent()).init
})(this);
EOT;
            $cs = \Yii::app()->clientScript;
            $cs->registerPackage('jquery');
            $cs->registerScript('ReCaptchaComponent', $jsCallback, \CClientScript::POS_END);
            $cs->registerScriptFile($this->apiUrl . ([] !== $params ? '?' . http_build_query($params) : ''), \CClientScript::POS_END);
        }
    }
Пример #23
0
 public function actionCreate()
 {
     if ($_REQUEST['class_name']) {
         $className = $_REQUEST['class_name'];
         if (method_exists($className, 'defaultObject')) {
             $model = call_user_func(array($className, 'defaultObject'));
         } else {
             $model = new $className();
         }
         if ($_REQUEST['foreign_attribute'] && $_REQUEST['sectionId'] && $model->hasAttribute($_REQUEST['foreign_attribute'])) {
             $model->{$_REQUEST['foreign_attribute']} = intval($_REQUEST['sectionId']);
         }
         $model->save(false);
         echo CJavaScript::jsonEncode(array('id' => $model->id));
     } else {
         echo '0';
     }
 }
    /**
     * Registers required scripts
     */
    public function registerClientScript()
    {
        $id = $this->getId();
        $jsData = CJavaScript::jsonEncode($this->data);
        $jsOptions = CJavaScript::jsonEncode($this->options);
        $script = '
            google.setOnLoadCallback(drawChart' . $id . ');
            var ' . $id . '=null;
            function drawChart' . $id . '() {
                var data = google.visualization.arrayToDataTable(' . $jsData . ');

                var options = ' . $jsOptions . ';

                ' . $id . ' = new google.visualization.' . $this->visualization . '(document.getElementById("' . $this->containerId . '"));
                ' . $id . '.draw(data, options);
            }';
        $cs = Yii::app()->getClientScript();
        $cs->registerScriptFile("https://www.google.com/jsapi");
        $cs->registerScript(__CLASS__ . '#' . $id, 'google.load("visualization", "1", {packages:["corechart"]});', CClientScript::POS_HEAD);
        $cs->registerScript($id, $script, CClientScript::POS_HEAD);
    }
Пример #25
0
 protected function getClientOptions()
 {
     //允许被定义的属性
     static $properties = array('toolbar', 'toolbarSet', 'height', 'width', 'skin');
     $options = $this->options;
     foreach ($properties as $property) {
         if (isset($this->{$property}) && $this->{$property} !== null) {
             $options[$property] = $this->{$property};
         }
     }
     $_options = array();
     foreach ($options as $key => $value) {
         if ($key == 'toolbarSet' && is_string($options['toolbar']) && is_array($value)) {
             $_options[] = 'toolbar_' . $this->toolbar . ':' . CJavaScript::jsonEncode($value);
         } else {
             $_options[] = $key . ':' . CJavaScript::encode($value);
         }
     }
     unset($_options['toolbarSet']);
     return "{" . implode(',', $_options) . "}";
 }
Пример #26
0
 protected function processLogs($logs)
 {
     if (Yii::app()->getRequest()->getIsAjaxRequest()) {
         return false;
     }
     $DBLogs = $this->getCallstack($logs);
     $mem = round(Yii::getLogger()->getMemoryUsage() / 1024 / 1024, 3);
     $time = round(Yii::getLogger()->getExecutionTime(), 3);
     $queryTime = 0;
     foreach ($DBLogs as $l) {
         $queryTime += $l[1];
     }
     $DB = Yii::t('QtzPanel.app', '{driver}: {n} query in {s} s.|{driver}: {n} queries in {s} s.', array(count($DBLogs), '{driver}' => Yii::app()->db->getDriverName(), '{s}' => vsprintf('%0.4F', $queryTime)));
     $flogs = $logs;
     foreach ($flogs as &$l) {
         $t = explode('.', $l[3]);
         $l[3] = Yii::app()->getDateFormatter()->format('h:m:s', $l[3]) . ' ' . $t[1];
     }
     $js = 'QtzPanelHelper.setLogs(' . CJavaScript::jsonEncode($flogs) . ');' . 'QtzPanelHelper.setDBStat(' . CJavaScript::jsonEncode($DB) . ');' . 'QtzPanelHelper.setDBLogs(' . CJavaScript::jsonEncode($DBLogs) . ');' . 'QtzPanelHelper.setMemory(' . CJavaScript::jsonEncode($mem) . ');' . 'QtzPanelHelper.setTime(' . CJavaScript::jsonEncode($time) . ');';
     echo CHtml::script($js);
 }
Пример #27
0
 /**
  * Reterns a JSON screen refresh, update the keep alive of the screen.
  */
 public function actionScreenAlive()
 {
     if (isset($_POST['screen_id'])) {
         $screen_id = $_POST['screen_id'];
         $model = ScreenAjax::model()->findByPk($screen_id);
         if (!$model) {
             $model = new ScreenAjax();
             $model->screen_id = $screen_id;
             $refresh = 0;
         } else {
             $refresh = $model->refresh;
         }
         $model->last_date = new CDbExpression('NOW()');
         $model->refresh = 0;
         if (isset($_POST['screen_ip'])) {
             $model->screen_ip = $_POST['screen_ip'];
         }
         $model->save();
         echo CJavaScript::jsonEncode($refresh);
     }
     Yii::app()->end();
 }
 public function init()
 {
     parent::init();
     if ($this->enable) {
         // js
         $cs = Yii::app()->clientScript;
         $cs->registerCoreScript('jquery');
         $cs->registerScriptFile(Yii::app()->request->baseUrl . '/js/highslide/highslide.js', CClientScript::POS_HEAD);
         $cs->registerScriptFile(Yii::app()->request->baseUrl . '/js/highslide/highslide_eh.js', CClientScript::POS_HEAD);
         $params = array('BASEURL' => Yii::app()->request->baseUrl, 'HTTPHOST' => $_SERVER['HTTP_HOST']);
         $script = 'var PARAMS = eval(' . CJavaScript::jsonEncode($params) . ');';
         $cs->registerScript('widget-params', $script, CClientScript::POS_BEGIN);
         $script = 'hs.graphicsDir = PARAMS.BASEURL+\'/js/highslide/graphics/\';' . "\n";
         $script .= 'hs.outlineType = \'rounded-white\';' . "\n";
         $script .= 'hs.showCredits = false;';
         $cs->registerScript('hislide-middle', $script, CClientScript::POS_BEGIN);
         $script = 'addHighSlideAttribute();';
         $cs->registerScript('hislide-end', $script, CClientScript::POS_END);
         // css
         $cs->registerCSSFile(Yii::app()->request->baseUrl . '/js/highslide/highslide.css');
     }
 }
 /**
  * Used for ajax call to save user portlets settings.
  */
 public function actionSave()
 {
     if (isset($_POST['portlets']) && !empty($_POST['portlets'])) {
         $portlets = CJavaScript::jsonDecode($_POST['portlets']);
         $transaction = Yii::app()->db->beginTransaction();
         try {
             // Delete outdated user settings.
             DashboardPortlet::model()->deleteAll('uid=:uid', array(':uid' => Yii::app()->user->id));
             // Save user new settings.
             $model = new DashboardPortlet();
             $model->settings = serialize($portlets);
             $model->save();
             $transaction->commit();
             echo CJavaScript::jsonEncode(array('message' => 'Save Successfully'));
         } catch (Exception $e) {
             $transaction->rollBack();
             echo CJavaScript::jsonEncode(array('message' => 'Transaction Failed'));
         }
     } else {
         echo CJavaScript::jsonEncode(array('message' => 'Incorrect arguments'));
     }
     Yii::app()->end();
 }
Пример #30
0
 /**
  * Update order
  * @param bool $new
  * @throws CHttpException
  */
 public function actionUpdate($new = false)
 {
     Yii::app()->clientScript->registerScriptFile($this->module->assetsUrl . '/admin/orders.update.js', CClientScript::POS_END);
     if ($new === true) {
         $model = new Order();
         $model->unsetAttributes();
     } else {
         $model = $this->_loadModel($_GET['id']);
     }
     if (!$model->isNewRecord) {
         $update = Yii::t('CartModule.admin', 'UPDATE_ORDER', array('{order_id}' => CHtml::encode($model->id)));
     }
     $this->pageName = $model->isNewRecord ? Yii::t('CartModule.admin', 'Создание заказа') : Yii::t('CartModule.admin', 'ORDER', 0);
     $this->breadcrumbs = array(Yii::t('CartModule.admin', 'ORDER', 0) => $this->createUrl('index'), $model->isNewRecord ? Yii::t('CartModule.admin', 'Создание заказа') : $update);
     if (Yii::app()->request->isPostRequest) {
         $model->attributes = $_POST['Order'];
         if ($model->validate()) {
             $model->save();
             // Update quantities
             if (sizeof(Yii::app()->request->getPost('quantity', array()))) {
                 $model->setProductQuantities(Yii::app()->request->getPost('quantity'));
             }
             $model->updateDeliveryPrice();
             $model->updateTotalPrice();
             if ($model->isNewRecord === false) {
                 $template[] = 'delete';
             }
             // register all delivery methods to recalculate prices
             Yii::app()->clientScript->registerScript('deliveryMetohds', strtr('var deliveryMethods = {data};', array('{data}' => CJavaScript::jsonEncode($deliveryMethods))), CClientScript::POS_END);
             ///  if ($new) {
             //      $this->setFlashMessage(Yii::t('core', 'Теперь Вы можете добавить товары.'));
             //}
             $this->redirect(array('update', 'id' => $model->id));
         }
     }
     $this->render('update', array('deliveryMethods' => ShopDeliveryMethod::model()->applyTranslateCriteria()->orderByName()->findAll(), 'paymentMethods' => ShopPaymentMethod::model()->findAll(), 'statuses' => OrderStatus::model()->orderByPosition()->findAll(), 'model' => $model));
 }