<commit_before><?php
/**
 * EditableField class file.
 * 
 * @author <NAME> <<EMAIL>>
 * @link https://github.com/vitalets/x-editable-yii
 * @copyright Copyright &copy; <NAME> 2012
 * @version 0.1.0
*/

/**
* EditableField widget makes editable single attribute of model. 
* 
* @package widgets
*/
class EditableField extends CWidget
{
    //note: only most usefull options are on first config level. 
    
    // --- start of X-editable options ----
    
    /**
    * @var CActiveRecord model of attribute to edit.
    */
    public $model = null;
    /**
    * @var string attribute name.
    */
    public $attribute = null;
    /**
    * @var string type of editable widget. Can be 'text', 'textarea', 'select' etc.
    */
    public $type = null;
    /**
    * @var string url to submit value
    */
    public $url = null;
    /**
    * @var array additional params to send on server
    */
    public $params = null;
    /**
    * @var string css class of input
    */
    public $inputclass = null;    
    /**
    * @var string text to be shown as element content
    */
    public $text = null;
    /**
    * @var mixed initial value. If not set - will be take from text
    */
    public $value = null;
    /**
    * @var string placement of popup. Can be 'left', 'top', 'right', 'bottom'
    */
    public $placement = 'top';
    
    /**
    * @var string text shown on empty field
    */
    public $emptytext;
    
    /**
    * @var boolean will editable be initially disabled. It means editable plugin will be applied to element anyway.
    * To disable applying 'editable' to element use 'apply' option
    */
    public $disabled = false;
   
    //list
    /**
    * @var mixed source data for 'select', 'checklist'. Can be url or php array.
    */
    public $source = null;

    //date
    /**
    * @var string format to send date on server
    */
    public $format = 'yyyy-mm-dd';
    /**
    * @var string format to display date in element
    */
    public $viewformat = null;

    //methods
    /**
    * @var string a javascript function that will be invoked to validate value.
    */
    public $validate = null;
    /**
    * @var string a javascript function that will be invoked to process successful server respone.
    */
    public $success = null;
    /**
    * @var string a javascript function that will be invoked to custom display value.
    */
    public $display = null;
    
    
    // --- X-editable events ---
    /**
    * @var string a javascript function that will be invoked when editable element is initializd
    */    
    public $onInit;
    /**
    * @var string a javascript function that will be invoked when editable form is shown
    */    
    public $onShown;
    /**
    * @var string a javascript function that will be invoked when new value is saved
    */    
    public $onSave;
    /**
    * @var string a javascript function that will be invoked when editable form is hidden
    */    
    public $onHidden;
    
    /**
    * @var array all config options of x-editable
    */
    public $options = array();
    
    /**
    * @var array HTML options of element
    */
    public $htmlOptions = array();

    /**
    * @var boolean whether to HTML encode text on output
    */
    public $encode = true;
    
    /**
    * @var boolean whether to apply 'editable' to element. 
    * If null will be automatically set to true for safe attributes and false for unsafe.
    */
    public $apply = null; 
    
    /**
    * @var string title of popup. If null will be generated automatically from attribute label.
    * Can have token {label} inside that will be replaced with actual attribute label.
    */
    public $title = null;

    //themeUrl, theme and cssFile copied from CJuiWidget to allow include custom theme for jQuery UI
    /**
     * @var string the root URL that contains all JUI theme folders.
     * If this property is not set (default), Yii will publish the JUI package included in the zii release and use
     * that to infer the root theme URL. You should set this property if you intend to use
     * a theme that is not found in the JUI package included in zii.
     * Note that under this URL, there must be a directory whose name is specified by {@link theme}.
     * Do not append any slash character to the URL.
     */
    public $themeUrl;
    /**
     * @var string the JUI theme name. Defaults to 'base'. Make sure that under {@link themeUrl} there
     * is a directory whose name is the same as this property value (case-sensitive).
     */
    public $theme='base';  
    /**
     * @var mixed the theme CSS file name. Defaults to 'jquery-ui.css'.
     * Note the file must exist under the URL specified by {@link themeUrl}/{@link theme}.
     * If you need to include multiple theme CSS files (e.g. during development, you want to include individual
     * plugin CSS files), you may set this property as an array of the CSS file names.
     * This property can also be set as false, which means the widget will not include any theme CSS file,
     * and it is your responsibility to explicitly include it somewhere else.
     */
    public $cssFile='jquery-ui.css';
    
    private $_prepareToAutotext = false; 
    
    /**
    * initialization of widget
    * 
    */
    public function init()
    {   
        parent::init();
        
        if (!$this->model) {
            throw new CException('Parameter "model" should be provided for Editable');
        }
        
        if (!$this->attribute) {
            throw new CException('Parameter "attribute" should be provided for Editable');
        }
        
        $originalText = CHtml::value($this->model, $this->attribute);
        if($this->apply === false) {
            $this->text = $originalText;
            return;
        }
        
        
        //resolve model and attribute for related model
        $resolved = self::resolveModel($this->model, $this->attribute);    
        if($resolved === false) {
            $this->apply = false;
            return;
        } else {<commit_msg>show text if apply = false from config<commit_after><?php
/**
 * EditableField class file.
 * 
 * @author <NAME> <<EMAIL>>
 * @link https://github.com/vitalets/x-editable-yii
 * @copyright Copyright &copy; <NAME> 2012
 * @version 0.1.0
*/

/**
* EditableField widget makes editable single attribute of model. 
* 
* @package widgets
*/
class EditableField extends CWidget
{
    //note: only most usefull options are on first config level. 
    
    // --- start of X-editable options ----
    
    /**
    * @var CActiveRecord model of attribute to edit.
    */
    public $model = null;
    /**
    * @var string attribute name.
    */
    public $attribute = null;
    /**
    * @var string type of editable widget. Can be 'text', 'textarea', 'select' etc.
    */
    public $type = null;
    /**
    * @var string url to submit value
    */
    public $url = null;
    /**
    * @var array additional params to send on server
    */
    public $params = null;
    /**
    * @var string css class of input
    */
    public $inputclass = null;    
    /**
    * @var string text to be shown as element content
    */
    public $text = null;
    /**
    * @var mixed initial value. If not set - will be take from text
    */
    public $value = null;
    /**
    * @var string placement of popup. Can be 'left', 'top', 'right', 'bottom'
    */
    public $placement = 'top';
    
    /**
    * @var string text shown on empty field
    */
    public $emptytext;
    
    /**
    * @var boolean will editable be initially disabled. It means editable plugin will be applied to element anyway.
    * To disable applying 'editable' to element use 'apply' option
    */
    public $disabled = false;
   
    //list
    /**
    * @var mixed source data for 'select', 'checklist'. Can be url or php array.
    */
    public $source = null;

    //date
    /**
    * @var string format to send date on server
    */
    public $format = 'yyyy-mm-dd';
    /**
    * @var string format to display date in element
    */
    public $viewformat = null;

    //methods
    /**
    * @var string a javascript function that will be invoked to validate value.
    */
    public $validate = null;
    /**
    * @var string a javascript function that will be invoked to process successful server respone.
    */
    public $success = null;
    /**
    * @var string a javascript function that will be invoked to custom display value.
    */
    public $display = null;
    
    
    // --- X-editable events ---
    /**
    * @var string a javascript function that will be invoked when editable element is initializd
    */    
    public $onInit;
    /**
    * @var string a javascript function that will be invoked when editable form is shown
    */    
    public $onShown;
    /**
    * @var string a javascript function that will be invoked when new value is saved
    */    
    public $onSave;
    /**
    * @var string a javascript function that will be invoked when editable form is hidden
    */    
    public $onHidden;
    
    /**
    * @var array all config options of x-editable
    */
    public $options = array();
    
    /**
    * @var array HTML options of element
    */
    public $htmlOptions = array();

    /**
    * @var boolean whether to HTML encode text on output
    */
    public $encode = true;
    
    /**
    * @var boolean whether to apply 'editable' to element. 
    * If null will be automatically set to true for safe attributes and false for unsafe.
    */
    public $apply = null; 
    
    /**
    * @var string title of popup. If null will be generated automatically from attribute label.
    * Can have token {label} inside that will be replaced with actual attribute label.
    */
    public $title = null;

    //themeUrl, theme and cssFile copied from CJuiWidget to allow include custom theme for jQuery UI
    /**
     * @var string the root URL that contains all JUI theme folders.
     * If this property is not set (default), Yii will publish the JUI package included in the zii release and use
     * that to infer the root theme URL. You should set this property if you intend to use
     * a theme that is not found in the JUI package included in zii.
     * Note that under this URL, there must be a directory whose name is specified by {@link theme}.
     * Do not append any slash character to the URL.
     */
    public $themeUrl;
    /**
     * @var string the JUI theme name. Defaults to 'base'. Make sure that under {@link themeUrl} there
     * is a directory whose name is the same as this property value (case-sensitive).
     */
    public $theme='base';  
    /**
     * @var mixed the theme CSS file name. Defaults to 'jquery-ui.css'.
     * Note the file must exist under the URL specified by {@link themeUrl}/{@link theme}.
     * If you need to include multiple theme CSS files (e.g. during development, you want to include individual
     * plugin CSS files), you may set this property as an array of the CSS file names.
     * This property can also be set as false, which means the widget will not include any theme CSS file,
     * and it is your responsibility to explicitly include it somewhere else.
     */
    public $cssFile='jquery-ui.css';
    
    private $_prepareToAutotext = false; 
    
    /**
    * initialization of widget
    * 
    */
    public function init()
    {   
        parent::init();
        
        if (!$this->model) {
            throw new CException('Parameter "model" should be provided for Editable');
        }
        
        if (!$this->attribute) {
            throw new CException('Parameter "attribute" should be provided for Editable');
        }
        
        //if apply set to false --> just print text
        $originalText = CHtml::value($this->model, $this->attribute);
        if($this->apply === false) {
            $this->text = $originalText;
            return;
        }
        
        
        //resolve model and attribute for related model
        $resolved = self::resolveModel($this->model, $this->attribute);    
        if($resolved === false) {
            $this->apply = false;
            $this->text = $originalText;
            return;
        } else {
{'fraction_non_alphanumeric': 0.10004896360372123, 'fraction_numerical': 0.0011424840868287905, 'mean_word_length': 2.1143583227445997, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 31, 'https://': 2, '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': '2592959', 'n_tokens_mistral': 3371, 'n_tokens_neox': 3302, 'n_words': 1426}