<?php 

/**
 * 名称：数据字典控制器
 * 作者：荷塘月色
 * 邮箱：kujiw@qq.com
 * 说明：
 */

namespace Admin\Controller;
class DatadictController extends CommonController {

	public function index(){
		if (IS_POST) {
			$this -> ajaxReturn($this -> getData());
		}elseif (IS_GET) {
			$this -> display();
		}
	}

	public function add(){
		if (IS_GET) {
			$this -> display();
		}elseif (IS_POST) {
			$this -> ebAdd();
		}
	}

	public function save(){
		if (IS_GET) {
			$this -> assign(M('Datadict') -> find(I('id','','intval')));
			$this -> display();
		}elseif (IS_POST) {
			$this -> ebSave();
		}
	}

	// 修改子分类分类id
	public function _after_save(){
		if (IS_POST) {
			$category_id = I('category_id',-1,'intval');
			if ($category_id) {
				$datas = M('Datadict') -> getField('id,pid,sort',true);
				$subid = subtreeid($datas,I('id','','intval'));
				if (count($subid)) {
					M('Datadict') -> where(array('id'=>array('in',$subid))) -> setField('category_id',$category_id);
				}
			}
		}
	}
	
	public function delete(){
		if (IS_POST) {
			$this -> ebDelete();
		}
	}

	public function status(){
		if (IS_POST) {
			$this -> ebStatus();
		}
	}
}