PageRenderTime 222ms CodeModel.GetById 120ms app.highlight 3ms RepoModel.GetById 98ms app.codeStats 0ms

/atk4/lib/View/Tabs/jUItabs.php

https://github.com/mahimarathore/mahi
PHP | 79 lines | 44 code | 5 blank | 30 comment | 1 complexity | 95c8298f621abfcdb4d81116704e8f0a MD5 | raw file
 1<?php // vim:ts=4:sw=4:et:fdm=marker
 2/*
 3 * Undocumented
 4 *
 5 * @link http://agiletoolkit.org/
 6*//*
 7==ATK4===================================================
 8   This file is part of Agile Toolkit 4
 9    http://agiletoolkit.org/
10
11   (c) 2008-2013 Agile Toolkit Limited <info@agiletoolkit.org>
12   Distributed under Affero General Public License v3 and
13   commercial license.
14
15   See LICENSE or LICENSE_COM for more information
16 =====================================================ATK4=*/
17/**
18 * Implementation of jQuery UI Tabs
19 *
20 * Use: 
21 *  $tabs=$this->add('Tabs');
22 *  $tabs->addTab('Tab1')->add('LoremIpsum');
23 *
24 *  $tabs->addTabURL('./details','Details');    // AJAX tab
25 *
26 * @license See http://agiletoolkit.org/about/license
27 * 
28**/
29class View_Tabs_jUItabs extends View_Tabs {
30    public $tab_template=null;
31    public $options=array('cache'=>false);
32
33    function init(){
34        parent::init();
35        $this->tab_template=$this->template->cloneRegion('tabs');
36        $this->template->del('tabs');
37    }
38    /* Set tabs option, for example, 'selected'=>'zero-based index of tab */
39    function setOption($key,$value){
40        $this->options[$key]=$value;
41        return $this;
42    }
43    function render(){
44        $this->js(true)
45            ->tabs($this->options);
46
47        return parent::render();
48    }
49    /* Add tab and returns it so that you can add static content */
50    function addTab($title,$name=null){
51
52        $container=$this->add('View_HtmlElement',$name);
53
54        $this->tab_template->set(array(
55                    'url'=>'#'.$container->name,
56                    'tab_name'=>$title,
57                    'tab_id'=>$container->short_name,
58                    ));
59        $this->template->appendHTML('tabs',$this->tab_template->render());
60        return $container;
61    }
62    /* Add tab which loads dynamically. Returns $this for chaining */
63    function addTabURL($page,$title=null){
64        if(is_null($title)){
65            $title=ucwords(preg_replace('/[_\/\.]+/',' ',$page));
66        }
67        $this->tab_template->set(array(
68                    'url'=>$this->api->url($page,array('cut_page'=>1)),
69                    'tab_name'=>$title,
70                    'tab_id'=>basename($page),
71                    ));
72        $this->template->appendHTML('tabs',$this->tab_template->render());
73        return $this;
74    }
75    function defaultTemplate(){
76        return array('tabs');
77
78    }
79}