Ejemplo n.º 1
0
 /**
  * Override to allow for optional live binding of yiiactiveform. @see $bindAsLive.
  */
 public function run()
 {
     if (is_array($this->focus)) {
         $this->focus = "#" . ZurmoHtml::activeId($this->focus[0], $this->focus[1]);
     }
     echo ZurmoHtml::endForm();
     $cs = Yii::app()->clientScript;
     $cs->registerScriptFile(Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('ext.zurmoinc.framework.views.assets')) . '/FormUtils.js', CClientScript::POS_END);
     if (!$this->enableAjaxValidation && !$this->enableClientValidation || empty($this->attributes)) {
         if ($this->focus !== null) {
             $cs->registerCoreScript('jquery');
             $cs->registerScript('CActiveForm#focus', "\n                        if (!window.location.hash)\n                            { \$('" . $this->focus . "').focus(); }\n                    ");
         }
         return;
     }
     $options = $this->clientOptions;
     if (isset($this->clientOptions['validationUrl']) && is_array($this->clientOptions['validationUrl'])) {
         $options['validationUrl'] = ZurmoHtml::normalizeUrl($this->clientOptions['validationUrl']);
     }
     $options['attributes'] = array_values($this->attributes);
     if ($this->summaryID !== null) {
         $options['summaryID'] = $this->summaryID;
     }
     if ($this->focus !== null) {
         $options['focus'] = $this->focus;
     }
     $options = CJavaScript::encode($options);
     //Not registering via coreScript because it does not properly register when using ajax non-minified
     //on home page myList config view.  Needs a better solution
     $cs->registerScriptFile(Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('system.web.js.source')) . '/jquery.yii.js', CClientScript::POS_END);
     $cs->registerScriptFile(Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('system.web.js.source')) . '/jquery.yiiactiveform.js', CClientScript::POS_END);
     $id = $this->id;
     if ($this->bindAsLive) {
         $cs->registerScript(__CLASS__ . '#' . $id, "\$('#{$id}').live('focus', function(e)\n                {\n                    if (\$(this).data('settings') == undefined)\n                    {\n                        \$(this).yiiactiveform({$options});\n                    }\n                });\n                ");
     } else {
         $cs->registerScript(__CLASS__ . '#' . $id, "\$('#{$id}').yiiactiveform({$options});");
     }
 }