<commit_before><?php // vim:ts=4:sw=4:et:fdm=marker
/*
 * Undocumented
 *
 * @link http://agiletoolkit.org/
*//*
==ATK4===================================================
   This file is part of Agile Toolkit 4
    http://agiletoolkit.org/

   (c) 2008-2013 Agile Toolkit Limited <<EMAIL>>
   Distributed under Affero General Public License v3 and
   commercial license.

   See LICENSE or LICENSE_COM for more information
 =====================================================ATK4=*/
/**
 * Implementation of abstract form's field
 *
 * @author      Romans <<EMAIL>>
 * @copyright   See file COPYING
 * @version     $Id$
 */
abstract class Form_Field extends AbstractView {
    /**
     * Description of the field shown next to it on the form
     */
    public $error_template;      // template used to put errors on the field line
    public $mandatory_template;  // template used to mark mandatory fields
    public $caption;
    protected $value=null;       // use $this->get(), ->set().
    public $short_name=null;
    public $attr=array();
    public $no_save=null;

    public $field_prepend='';
    public $field_append='';

    public $comment='&nbsp;';
    protected $disabled=false;
    protected $mandatory=false;
    public $default_value=null;

    // Field customization
    private $separator='';
    public $show_input_only;
    public $form=null;

    public $button_prepend=null;
    public $button_append=null;

    function init(){
        parent::init();
        if(@$_GET[$this->owner->name.'_cut_field']==$this->name){
            $this->api->addHook('pre-render',array($this,'_cutField'));
        }
    }
    function setForm($form){
        $form->addHook('loadPOST',$this);
        $form->addHook('validate',$this);
        $this->form=$form;
        $this->form->data[$this->short_name] = $this->value;
        $this->value =& $this->form->data[$this->short_name];
        return $this;
    }

    function _cutField(){
        // this method is used by ui.atk4_form, when doing reloadField();
        unset($_GET['cut_object']);
        $this->recursiveRender();
        if($this->api->jquery)$this->api->jquery->getJS($this);
        throw new Exception_StopRender(
            $this->template->renderRegion($this->template->tags['before_field']).
            $this->getInput().
            $this->template->renderRegion($this->template->tags['after_field'])
        );
    }
    function setMandatory($mandatory=true){
        $this->mandatory=$mandatory;
        return $this;
    }
    function setReadonly($readonly=true){
        $this->readonly=$readonly;
        return $this;
    }
    function isMandatory(){
        return $this->mandatory;
    }
    function setCaption($_caption){
        $this->caption=$this->api->_($_caption);
        return $this;
    }
    function displayFieldError($msg=null){
        if(!isset($msg))$msg='Error in field "'.$this->caption.'"';

        $this->form->js(true)
            ->atk4_form('fieldError',$this->short_name,$msg)
            ->execute();

        $this->form->errors[$this->short_name]=$msg;
    }
    function setNoSave(){
        // Field value will not be saved into defined source (such as database)
        $this->no_save=true;
        return $this;
    }
    function disable(){
        // sets 'disabled' property and setNoSave()
        $this->setAttr('disabled');
        $this->setNoSave();
        $this->disabled=true;
        return $this;
    }
    function isDisabled(){
        return $this->disabled;
    }
    function set($value){
        // Use this function when you want to assign $this->value.
        // If you use this function, your field will operate in AJAX mode.
        $this->value=$value;
        return $this;
    }
    /** Position can be either 'before' or 'after' */
    function addButton($label,$options=array()){
        $position='after';
        if(is_string($options)){
            $position=$options;
        }else{
            if(isset($options['position']))$position=$options['position'];
        }
        if($position=='after'){
            return $this->afterField()->add('Button',$options)->setLabel($label);
        }else{
            return $this->beforeField()->add('Button',$options)->setLabel($label);
        }
    }
    function beforeField(){
        if(!$this->template->hasTag('after_input')){
            $el=$this->owner->add('HtmlElement');
            $this->owner->add('Order')->move($el,'before',$this)->now();
            return $el;
        }
        if(!$this->button_prepend)return $this->button_prepend=$this
            ->add('HtmlElement',null,'before_input')->addClass('input-cell');
        return $this->button_prepend;
    }
    function afterField(){
        if(!$this->template->hasTag('after_input')){
            $el=$this->owner->add('HtmlElement');
            $this->owner->add('Order')->move($el,'after',$this)->now();
            return $el;
        }
        if(!$this->button_append)return $this->button_append=$this
            ->add('HtmlElement',null,'after_input')->addClass('input-cell');
        return $this->button_append;
    }
    function aboveField(){
        return $this->add('HtmlElement',null,'before_field');
    }
    function belowField(){
        return $this->add('HtmlElement',null,'after_field');
    }
    function setComment($text=''){
        $this->belowField()->setElement('ins')->set($text);
        return $this;
    }
    function addComment($text=''){
        return $this->belowField()->setElement('ins')->set($text);
    }
    function get(){
        return $this->value;
    }
    function setClass($class){
        $this->attr['class']=$class;
        return $this;
    }
    function addClass($class){
        $this->attr['class'].=(!empty($this->attr['class'])?' ':'').$class;
        return $this;
    }
    function setAttr($attr,$value=undefined){
        if(is_array($attr)&&$value===undefined){
            foreach($attr as $k=>$v) $this->setAttr($k,$v);
            return $this;
        }
        if($attr){<commit_msg>Form_Field: nicer :)<commit_after><?php // vim:ts=4:sw=4:et:fdm=marker
/*
 * Undocumented
 *
 * @link http://agiletoolkit.org/
*//*
==ATK4===================================================
   This file is part of Agile Toolkit 4
    http://agiletoolkit.org/

   (c) 2008-2013 Agile Toolkit Limited <<EMAIL>>
   Distributed under Affero General Public License v3 and
   commercial license.

   See LICENSE or LICENSE_COM for more information
 =====================================================ATK4=*/
/**
 * Implementation of abstract form's field
 *
 * @author      Romans <<EMAIL>>
 * @copyright   See file COPYING
 * @version     $Id$
 */
abstract class Form_Field extends AbstractView {
    /**
     * Description of the field shown next to it on the form
     */
    public $error_template;      // template used to put errors on the field line
    public $mandatory_template;  // template used to mark mandatory fields
    public $caption;
    protected $value=null;       // use $this->get(), ->set().
    public $short_name=null;
    public $attr=array();
    public $no_save=null;

    public $field_prepend='';
    public $field_append='';

    public $comment='&nbsp;';
    protected $disabled=false;
    protected $mandatory=false;
    public $default_value=null;

    // Field customization
    private $separator='';
    public $show_input_only;
    public $form=null;

    public $button_prepend=null;
    public $button_append=null;

    function init(){
        parent::init();
        if(@$_GET[$this->owner->name.'_cut_field']==$this->name){
            $this->api->addHook('pre-render',array($this,'_cutField'));
        }
    }
    function setForm($form){
        $form->addHook('loadPOST',$this);
        $form->addHook('validate',$this);
        $this->form=$form;
        $this->form->data[$this->short_name] = $this->value;
        $this->value =& $this->form->data[$this->short_name];
        return $this;
    }

    function _cutField(){
        // this method is used by ui.atk4_form, when doing reloadField();
        unset($_GET['cut_object']);
        $this->recursiveRender();
        if($this->api->jquery)$this->api->jquery->getJS($this);
        throw new Exception_StopRender(
            $this->template->renderRegion($this->template->tags['before_field']).
            $this->getInput().
            $this->template->renderRegion($this->template->tags['after_field'])
        );
    }
    function setMandatory($mandatory=true){
        $this->mandatory=$mandatory;
        return $this;
    }
    function setReadonly($readonly=true){
        $this->readonly=$readonly;
        return $this;
    }
    function isMandatory(){
        return $this->mandatory;
    }
    function setCaption($_caption){
        $this->caption=$this->api->_($_caption);
        return $this;
    }
    function displayFieldError($msg=null){
        if(!isset($msg))$msg='Error in field "'.$this->caption.'"';

        $this->form->js(true)
            ->atk4_form('fieldError',$this->short_name,$msg)
            ->execute();

        $this->form->errors[$this->short_name]=$msg;
    }
    function setNoSave(){
        // Field value will not be saved into defined source (such as database)
        $this->no_save=true;
        return $this;
    }
    function disable(){
        // sets 'disabled' property and setNoSave()
        $this->setAttr('disabled');
        $this->setNoSave();
        $this->disabled=true;
        return $this;
    }
    function isDisabled(){
        return $this->disabled;
    }
    function set($value){
        // Use this function when you want to assign $this->value.
        // If you use this function, your field will operate in AJAX mode.
        $this->value=$value;
        return $this;
    }
    /** Position can be either 'before' or 'after' */
    function addButton($label,$options=array()){
        $position='after';
        if(is_string($options)){
            $position=$options;
        }else{
            if(isset($options['position']))$position=$options['position'];
        }
        if($position=='after'){
            return $this->afterField()->add('Button',$options)->setLabel($label);
        }else{
            return $this->beforeField()->add('Button',$options)->setLabel($label);
        }
    }
    function beforeField(){
        if(!$this->template->hasTag('after_input')){
            $el=$this->owner->add('HtmlElement');
            $this->owner->add('Order')->move($el,'before',$this)->now();
            return $el;
        }
        if(!$this->button_prepend)return $this->button_prepend=$this
            ->add('HtmlElement',null,'before_input')->addClass('input-cell');
        return $this->button_prepend;
    }
    function afterField(){
        if(!$this->template->hasTag('after_input')){
            $el=$this->owner->add('HtmlElement');
            $this->owner->add('Order')->move($el,'after',$this)->now();
            return $el;
        }
        if(!$this->button_append)return $this->button_append=$this
            ->add('HtmlElement',null,'after_input')->addClass('input-cell');
        return $this->button_append;
    }
    function aboveField(){
        return $this->add('HtmlElement',null,'before_field');
    }
    function belowField(){
        return $this->add('HtmlElement',null,'after_field');
    }
    function setComment($text=''){
        $this->belowField()->setElement('ins')->set($text);
        return $this;
    }
    function addComment($text=''){
        return $this->belowField()->setElement('ins')->set($text);
    }
    function get(){
        return $this->value;
    }
    function setClass($class){
        $this->attr['class']=$class;
        return $this;
    }
    function addClass($class){
        $this->attr['class']=($this->attr['class']?:' ').$class;
        return $this;
    }
    function setAttr($attr,$value=undefined){
        if(is_array($attr)&&$value===undefined){
            foreach($attr as $k=>$v) $this->setAttr($k,$v);
            return $this;
        }
        if($attr){
{'fraction_non_alphanumeric': 0.1852863290301225, 'fraction_numerical': 0.0026481297583581596, 'mean_word_length': 2.657687651331719, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 213, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6372978', 'n_tokens_mistral': 3533, 'n_tokens_neox': 3465, 'n_words': 671}