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