public function actionRootJSON() { // print_r(ShopCategoryNode::fromArray(ShopCategory::model()->language(Yii::app()->language->active)->findAllByPk(1))); $test = ShopCategoryNode::fromArray(ShopCategory::model()->language(Yii::app()->language->active)->findAllByPk(1)); echo CJSON::encode($test); die; }
/** * Example for jstree */ public function actionAjaxRoot($id) { header('Content-type: application/json; charset=UTF-8'); $d = ShopCategoryNode::fromArray(ShopCategory::model()->findAllByPk($id)); echo CJSON::encode($this->createHtmlTree($d)); die; }
<div class="grid2"> <?php echo Yii::t('ShopModule.admin', 'Поиск:'); ?> </div> <div class="grid10"> <input type="text" onkeyup='$("#ShopCategoryTree").jstree("search", $(this).val());' /> </div> <div class="clear"></div> </div> <?php // Register scripts Yii::app()->clientScript->registerScriptFile($this->module->assetsUrl . '/admin/products.js', CClientScript::POS_END); // Create jstree $this->widget('mod.shop.widgets.jstree.JsTree', array('id' => 'ShopCategoryTree', 'data' => ShopCategoryNode::fromArray(ShopCategory::model()->active()->findAllByPk(1)), 'options' => array('core' => array('initially_open' => 'ShopCategoryTreeNode_1'), 'plugins' => array('themes', 'html_data', 'ui', 'crrm', 'search', 'checkbox', 'cookies'), 'checkbox' => array('two_state' => true), 'cookies' => array('save_selected' => false)))); // Get categories preset if ($model->type) { $presetCategories = unserialize($model->type->categories_preset); if (!is_array($presetCategories)) { $presetCategories = array(); } } if (isset($_POST['categories']) && !empty($_POST['categories'])) { foreach ($_POST['categories'] as $id) { Yii::app()->getClientScript()->registerScript("checkNode{$id}", "\n\t\t\t\$('#ShopCategoryTree').checkNode({$id});\n\t\t"); } } elseif ($model->isNewRecord && empty($_POST['categories']) && isset($presetCategories)) { foreach ($presetCategories as $id) { if ($model->type && $id === $model->type->main_category) { continue;
echo CHtml::textField('search', '', array('onkeyup' => '$("#ShopCategoryTreeFilter").jstree("search", $(this).val())')); ?> </div> <?php $this->beginWidget('zii.widgets.jui.CJuiButton', array('buttonType' => 'buttonset', 'name' => 'tree-set', 'htmlOptions' => array('style' => 'padding-top:2px;'))); $this->endWidget(); ?> <div class="clear"></div> <?php // Create jstree to filter products $this->widget('ext.jstree.SJsTree', array('id' => 'ShopCategoryTreeFilter', 'data' => ShopCategoryNode::fromArray(ShopCategory::model()->findAllByPk(1), array('displayCount' => true)), 'options' => array('core' => array('initially_open' => 'ShopCategoryTreeFilterNode_1'), 'plugins' => array('themes', 'html_data', 'ui', 'crrm', 'search'), 'cookies' => array('save_selected' => false)))); // Category id to select in sidebar. $activeCategoryId = Yii::app()->request->getQuery('category', 0); if (is_array($activeCategoryId)) { $activeCategoryId = 0; } Yii::app()->getClientScript()->registerScript('insertAllCategory', ' $("#ShopCategoryTreeFilter").bind("loaded.jstree", function (event, data) { $(this).jstree("create",-1,false,{attr:{id:"ShopCategoryTreeFilterNode_0"}, data:{title:"' . Yii::t('ShopModule.admin', 'Все категории') . '"}},false,true); $(this).jstree("select_node","#ShopCategoryTreeFilterNode_' . $activeCategoryId . '"); }); '); Yii::app()->getClientScript()->registerCss("ShopCategoryTreeStyles", "\n\t#ShopCategoryTree { width:90% }\n\t#ShopCategoryTreeFilter {width: 255px}\n"); ?>
<div class="form-group"> <div class="col-sm-4"> <label class="control-label" for="tree-search"><?php echo Yii::t('ShopModule.admin', 'Поиск:'); ?> </label> </div> <div class="col-sm-8"> <input id="tree-search" class="form-control" type="text" onkeyup='$("#ShopTypeCategoryTree").jstree("search", $(this).val());' /> </div> </div> <div class="form-group clearfix"> <div class="col-sm-12"> <?php echo Yii::app()->tpl->alert('info', Yii::t('ShopModule.admin', "TYPE_PRODUCT_ALERT_INFO"), false); ?> </div> </div> <?php // Create jstree $cats = ShopCategory::model()->findByPk(1); $this->widget('mod.shop.widgets.jstree.JsTree', array('id' => 'ShopTypeCategoryTree', 'data' => ShopCategoryNode::fromArray($cats->children()->findAll()), 'options' => array("themes" => array("stripes" => true), 'core' => array('initially_open' => 'ShopTypeCategoryTreeNode_1'), 'plugins' => array('themes', 'html_data', 'ui', 'crrm', 'search', 'checkbox', 'cookies'), 'checkbox' => array('two_state' => true), 'cookies' => array('save_selected' => false), 'ui' => array('initially_select' => 'ShopTypeCategoryTreeNode_' . $model->main_category)))); // Check tree nodes $categories = unserialize($model->categories_preset); if (!is_array($categories)) { $categories = array(); } foreach ($categories as $id) { Yii::app()->getClientScript()->registerScript("checkNode{$id}", "\n\t\t\$('#ShopTypeCategoryTree').checkNode({$id});\n\t"); }
<?php $this->widget('mod.shop.widgets.jstree.JsTree', array('id' => 'CategoryAssignTreeDialog', 'data' => ShopCategoryNode::fromArray(ShopCategory::model()->active()->findAllByPk(1)))); ?> <script type="text/javascript"> $("#CategoryAssignTreeDialog").jstree(<?php echo CJavaScript::encode(array('core' => array('initially_open' => 'CategoryAssignTreeDialogNode_1'), 'plugins' => array('themes', 'html_data', 'ui', 'crrm', 'search', 'checkbox', 'cookies'), 'checkbox' => array('two_state' => true), 'cookies' => array('save_selected' => true))); ?> ); </script>
}') ), 'cookies' => array( 'save_selected' => false, ), 'ui' => array( 'initially_select' => array('#ShopCategoryTreeNode_' . (int) Yii::app()->request->getParam('id')) ), 'dnd' => array( 'drag_finish' => 'js:function(data){ //alert(data); }', ), // 'plugins' => array('themes', 'html_data', 'ui', 'dnd', 'crrm', 'search', 'cookies', 'contextmenu'), ), )); */ $this->widget('mod.shop.widgets.jstree.JsTree', array('id' => 'ShopCategoryTree', 'data' => ShopCategoryNode::fromArray(ShopCategory::model()->language(1)->findAllByPk(1), array('switch' => true)), 'options' => array("themes" => array("stripes" => true), 'core' => array('initially_open' => 'ShopCategoryTreeNode_1'), 'plugins' => array('themes', 'html_data', 'ui', 'dnd', 'crrm', 'search', 'cookies', 'contextmenu'), 'crrm' => array('move' => array('check_move' => 'js: function(m){ // Disallow categories without parent. // At least each category must have `root` category as parent. var p = this._get_parent(m.r); if (p == -1) return false; return true; }')), 'dnd' => array('drag_finish' => 'js:function(data){ //alert(data); }'), 'cookies' => array('save_selected' => false), 'ui' => array('initially_select' => array('#ShopCategoryTreeNode_' . (int) Yii::app()->request->getParam('id'))), 'contextmenu' => array('items' => array('view' => array('label' => Yii::t('ShopModule.admin', 'Перейти'), 'action' => 'js:function(obj){ CategoryRedirectToFront(obj); }'), 'products' => array('label' => Yii::t('ShopModule.admin', 'Продукты'), 'action' => 'js:function(obj){ CategoryRedirectToAdminProducts(obj); }', 'icon' => 'icon-cart-3'), 'create' => array('label' => Yii::t('app', 'CREATE', 1), 'action' => 'js:function(obj){ CategoryRedirectToParent(obj); }', 'icon' => 'icon-plus'), 'rename' => false, 'remove' => array('label' => Yii::t('app', 'DELETE'), 'icon' => 'icon-trashcan'), 'switch' => array('label' => Yii::t('app', 'SWITCH'), 'icon' => 'icon-eye'), 'ccp' => false))))); ?> </div> </div> </div> </div>