simpletree SimpleTree generates a drag'n'drop tree-view from ActiveRecords

  1. Requirements
  2. Usage
  3. Changelog
  4. Resources

SimpleTree provides tree-view for ActiveRecords with drag'n'drop support for quick table manipulation. It uses the jsTree jQuery plugin from jstree.com.

Requirements

Yii 1.1 or above. Could possibly run on Yii 1.0 as well.

Usage

Unpack to your extension folder.

Make sure the Model you're using has properties/columns for the following: ID, parent ID, name and position. By default, these are respectively called id, id_parent, title and position.

/**
* Quick setup
**/
$this->widget('application.extensions.SimpleTreeWidget',array(
    'model'=>'MyModel',
));
/**
* Customized setup
**/
$this->widget('application.extensions.SimpleTreeWidget',array(
    'model'=>Folder::model()->findByPk(43),
    'modelPropertyParentId' => 'parent_id',
    'modelPropertyName' => 'name',
    'ajaxUrl' => '/ajax/simpletree',
    'onSelect'=>'
        var id = data.inst.get_selected().attr("id").replace("node_","");
        $("#contentBox").load("/ajax/getContent/id/"+id);
    '
));

//ajaxController
public function actionsimpletree()
{
    Yii::import('application.extensions.SimpleTreeWidget');    
    SimpleTreeWidget::performAjax();
}
/**
 * Parameters and defaults
 **/
 $ajaxUrl; //it is recommended that you use your own url
 $id = 'simpletree_widget';
 $model; //this can be the name of a model, an empty model or a loaded model
 $modelPropertyName = 'title'; //name of the name property in your model
 $modelPropertyId = 'id'; //name of the ID property in your model
 $modelPropertyParentId = 'id_parent'; //name of the parent ID property in your model
 $modelPropertyPosition = 'position'; //name of the position property in your model
 $theme = 'default'; //apple, classic, default
 $onSelect; //javascript
 $onCreate; //javascript
 $onMove; //javascript
 $onRemove; //javascript
 $onRename; //javascript

Changelog

January 27, 2011

  • Release 0.6
  • FEATURE: It is now possible to write protect a model with $Model->readonly = true;. Write protected models are not protected from indirect deletion in case one of its ancestors is deleted.
  • CHANGE: Models are now loaded via Ajax to accommodate large tables
  • FIX: It's no longer possible to drag folders outside the root folder(s)
  • FIX: Copied models now show correct IDs instead of "unidentified"
  • FIX: It's now possible to copy a copied model without the need to refresh first

  • Release 0.5b
  • CHANGE: onFocus has been renamed to onSelect and calls select_node() instead of on_focus()
  • FIX: calling data.inst._get_node() from onSelect (formerly onFocus) now returns the selected node rather than the previous selected node

January 26, 2011

  • Release 0.5
  • Initial release

Resources

jstree.com

jstree documentation

21 3
41 followers
4 373 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: User Interface
Developed by: JayRoe
Created on: Jan 26, 2011
Last updated: 7 years ago

Downloads

show all

Related Extensions