<?php

/**
 * Description of StepsWidget
 *
 * @author Mohammed Osman  <osmancode@gmail.com>
 */
class JQueryStepsWidget extends ShortCodeWidget {

    protected $_options = array(
        array(
            'name' => 'model_id',
            'label' => 'Tabber ID',
            'value' => 0,
        ),
        array(
            'name' => 'layout',
            'label' => 'Widget Layout File',
            'value' => 'horizontal',
        ),
        array(
            'name' => 'headerTag',
            'help' => "The header tag is used to find the step button text within the declared wizard area.",
            'value' => "h1",
        ),
        array(
            'name' => 'bodyTag',
            'help' => "The body tag is used to find the step content within the declared wizard area.",
            'value' => "div",
        ),
        array(
            'name' => 'contentContainerTag',
            'help' => "The content container tag which will be used to wrap all step contents.",
            'value' => "div",
        ),
        array(
            'name' => 'actionContainerTag',
            'help' => "The action container tag which will be used to wrap the pagination navigation.",
            'value' => "div",
        ),
        array(
            'name' => 'stepsContainerTag',
            'help' => "The steps container tag which will be used to wrap the steps navigation.",
            'value' => "div",
        ),
        array(
            'name' => 'cssClass',
            'help' => "The css class which will be added to the outer component wrapper.",
            'value' => "wizard",
        ),
        array(
            'help' => "Determines whether the steps are vertically or horizontally oriented.",
            'name' => 'stepsOrientation',
            'value' => "horizontal",
        ),
        array(
            'help' => "The title template which will be used to create a step button.	",
            'name' => 'titleTemplate',
            'value' => '<span class="number">#index#.</span> #title#',
        ), array(
            'help' => "The loading template which will be used to create the loading animation.",
            'name' => 'loadingTemplate',
            'value' => '<span class="spinner"></span> #text#',
        ),
        array(
            'name' => 'autoFocus',
            'help' => 'Sets the focus to the first wizard instance in order to enable the key navigation from the begining if true.',
            'value' => 'false',
        ), array(
            'name' => 'enableAllSteps',
            'help' => 'Enables all steps from the begining if true (all steps are clickable).',
            'value' => 'false',
        ), array(
            'name' => 'enableKeyNavigation',
            'help' => 'Enables keyboard navigation if true (arrow left and arrow right).',
            'value' => 'true',
        ), array(
            'name' => 'enablePagination',
            'help' => 'Enables pagination (next, previous and finish button) if true.',
            'value' => 'true',
        ), array(
            'name' => 'suppressPaginationOnFocus',
            'help' => 'Suppresses pagination if a form field is focused.',
            'value' => 'true',
        ), array(
            'name' => 'enableContentCache',
            'help' => 'Enables cache for async loaded or iframe embedded content.',
            'value' => 'true',
        ), array(
            'name' => 'enableFinishButton',
            'help' => 'Shows the finish button if enabled.',
            'value' => 'true',
        ), array(
            'name' => 'showFinishButtonAlways',
            'help' => 'Shows the finish button always (on each step; right beside the next button) if true. Otherwise the next button will be replaced by the finish button if the last step becomes active.',
            'value' => 'false',
        ), array(
            'name' => 'forceMoveForward',
            'help' => 'Prevents jumping to a previous step.',
            'value' => 'false',
        ), array(
            'name' => 'saveState',
            'help' => 'Saves the current state (step position) to a cookie. By coming next time the last active step becomes activated.',
            'value' => 'false',
        ), array(
            'name' => 'startIndex',
            'help' => 'The position to start on (zero-based).',
            'value' => '0',
        ), array(
            'name' => 'transitionEffect',
            'help' => 'The animation effect which will be used for step transitions.',
            'type' => 'dropdownlist',
            'items' => array(
                'none' => 'None',
                'fade' => 'Fade',
                'slide' => 'Slide',
                'slideLeft' => 'Slide Left',
            ),
            'value' => '0',
        )
    );
    public $modelClass = "Tabber";
    public $registerCssFiles = true;
    public $shortCode = 'jquerysteps';

    function init() {
        parent::init();

        $cs = Yii::app()->getClientScript();
        $id = $this->getId();
        $assets = Yii::app()->getAssetManager()->publish(dirname(__FILE__) . '/assets/jquerysteps/');
        if ($this->registerCssFiles == true) {
            $cs->registerCssFile($assets . '/jquery.steps.css');
            if (Yii::app()->language == 'ar') {
                $cs->registerCssFile($assets . '/jquery.steps.rtl.css');
            }
        }
        if (YII_DEBUG) {
            $cs->registerScriptFile($assets . '/jquery.steps.js');
        } else {
            $cs->registerScriptFile($assets . '/jquery.steps.min.js');
        }

        $options = CJavaScript::encode($this->_options);
        $options = str_replace("'false'", "false", $options);

        $js = "jQuery('#{$id}').steps({$options});";

        $cs->registerScript(__CLASS__ . '#' . $id, $js);
    }

}