1: <?php
2:
3: namespace Zippy\Html\Form;
4:
5: use Zippy\WebApplication;
6: use Zippy\Event;
7: use Zippy\Html\HtmlComponent;
8: use Zippy\Interfaces\ClickListener;
9: use Zippy\Interfaces\Requestable;
10: use Zippy\Interfaces\EventReceiver;
11:
12: /**
13: * Компонент тэга &lt;input type=&quot;submit&quot;&gt; для отправки формы
14: */
15: class SubmitButton extends HtmlComponent implements ClickListener, Requestable
16: {
17: private $event;
18:
19: public function __construct($id) {
20: parent::__construct($id);
21:
22: $this->setAttribute("name", $this->id);
23: }
24:
25: /**
26: * @see HtmlComponent
27: */
28: public function RenderImpl() {
29:
30: if ($this->getFormOwner() == null) {
31: throw new \Zippy\Exception("Element '" . $this->id . "' outside FORM tag");
32: }
33: if ($this->event != null) {
34: $formid = $this->getFormOwner()->id;
35: // $this->attributes["onclick"]="javascript:{ $('#".$formattr["id"]."_hf').val('submit1') ; $('#".$formattr["id"]."').submit();}";
36: $url = $this->owner->getURLNode() . '::' . $this->id;
37: $url = substr($url, 2 + strpos($url, 'q='));
38: if ($this->event->isajax == false) {
39: $this->setAttribute("onclick", "javascript:{if(beforeZippy('{$this->id}') ==false) return false; $('#" . $formid . "_q').attr('value','" . $url . "'); $('#" . $formid . "_s').trigger('click');event.returnValue=false; return false;}");
40: } else {
41: $_BASEURL = WebApplication::$app->getResponse()->getHostUrl();
42: $this->setAttribute("onclick", "if(beforeZippy('{$this->id}') ==false) return false; $('#" . $formid . "_q').attr('value','" . $url . "'); submitForm('{$formid}','{$_BASEURL}/?ajax=true');");
43: }
44: }
45: $this->setAttribute("type", 'button');
46: }
47:
48: /**
49: * @see Requestable
50: */
51: public function RequestHandle() {
52: $this->OnEvent();
53: }
54:
55: /**
56: * @see ClickListener
57: */
58: public function onClick(EventReceiver $receiver, $handler, $ajax = false) {
59: $this->event = new Event($receiver, $handler);
60: $this->event->isajax = $ajax;
61: }
62:
63: /**
64: * @see ClickListener
65: */
66: public function OnEvent() {
67: if ($this->event != null && strlen($this->getAttribute('disabled')) == 0) {
68: $this->event->onEvent($this);
69: }
70: }
71:
72: }
73:
74: /**
75: * @todo возмоджность вставки в оnclick обработчика отмены
76: */
77: