HusseyCoding_Sirportly - Version 1.0.0

Version Notes

Initial release

Download this release

Release Info

Developer Hussey Coding
Extension HusseyCoding_Sirportly
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/HusseyCoding/Common/etc/system.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <husseycoding translate="label">
5
+ <label>Hussey Coding</label>
6
+ <sort_order>500</sort_order>
7
+ </husseycoding>
8
+ </tabs>
9
+ </config>
app/code/community/HusseyCoding/Sirportly/Helper/Data.php ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class HusseyCoding_Sirportly_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ private $_verified;
5
+
6
+ public function verifyCredentials($token = null, $secret = null)
7
+ {
8
+ if (!isset($this->_verified)):
9
+ $client = $this->_getRequestObject('/api/v2/tickets/all', null, $token, $secret);
10
+ $this->_verified = $this->_sendRequest($client);
11
+ endif;
12
+
13
+ return $this->_verified;
14
+ }
15
+
16
+ public function createTicket($data = array())
17
+ {
18
+ if ($this->_canSend($data)):
19
+ $params = array(
20
+ 'name' => $data['name'],
21
+ 'email' => $data['email'],
22
+ 'subject' => $data['subject'],
23
+ 'message' => $data['comment'],
24
+ 'status' => Mage::getStoreConfig('sirportly/ticketassign/status'),
25
+ 'priority' => Mage::getStoreConfig('sirportly/ticketassign/priority'),
26
+ 'team' => Mage::getStoreConfig('sirportly/ticketassign/team'),
27
+ 'department' => Mage::getStoreConfig('sirportly/ticketassign/department')
28
+ );
29
+
30
+ $client = $this->_getRequestObject('/api/v2/tickets/submit', $params);
31
+ return $this->_sendRequest($client);
32
+ endif;
33
+
34
+ return false;
35
+ }
36
+
37
+ private function _getRequestObject($url, $params = null, $token = null, $secret = null)
38
+ {
39
+ if (!isset($token)):
40
+ $token = Mage::getStoreConfig('sirportly/api/token');
41
+ endif;
42
+
43
+ if (!isset($secret)):
44
+ $secret = Mage::getStoreConfig('sirportly/api/secret');
45
+ endif;
46
+
47
+ if (isset($url)):
48
+ $url = '/' . trim($url, '/');
49
+ $url = $this->_getApiUrl() . $url;
50
+ else:
51
+ $url = $this->_getApiUrl();
52
+ endif;
53
+
54
+ $client = new Zend_Http_Client();
55
+ $client
56
+ ->setUri($url)
57
+ ->setMethod(Zend_Http_Client::POST)
58
+ ->setHeaders(array(
59
+ 'X-Auth-Token' => $token,
60
+ 'X-Auth-Secret' => $secret
61
+ ));
62
+
63
+ $client
64
+ ->setConfig(array(
65
+ 'timeout' => 5
66
+ ));
67
+
68
+ $params = isset($params) ? $params : array();
69
+
70
+ foreach ($params as $key => $value):
71
+ $client->setParameterPost($key, $value);
72
+ endforeach;
73
+
74
+ return $client;
75
+ }
76
+
77
+ private function _getApiUrl()
78
+ {
79
+ return 'https://api.sirportly.com';
80
+ }
81
+
82
+ private function _sendRequest($client, $sendbody = false)
83
+ {
84
+ try {
85
+ $result = $client->request();
86
+ } catch (Exception $e) {
87
+ return false;
88
+ }
89
+ $body = $result->getBody();
90
+ $body = Zend_Json::decode($body);
91
+
92
+ if (array_key_exists('error', $body) || array_key_exists('errors', $body)):
93
+ return false;
94
+ endif;
95
+
96
+ return $sendbody ? $body : true;
97
+ }
98
+
99
+ public function getSelectOptions($url, $optgroup = false)
100
+ {
101
+ if (!$this->verifyCredentials()):
102
+ return array(
103
+ array('value' => '', 'label' => $this->__('Invalid API Credentials'))
104
+ );
105
+ else:
106
+ $client = $this->_getRequestObject($url);
107
+ if ($result = $this->_sendRequest($client, true)):
108
+ $return = array();
109
+ if ($result):
110
+ if ($optgroup):
111
+ $return = $this->_getOptGroups($result, $optgroup);
112
+ else:
113
+ foreach ($result as $option):
114
+ if (!empty($option['name']) && !empty($option['id'])):
115
+ $return[] = array('value' => $option['id'], 'label' => $option['name']);
116
+ endif;
117
+ endforeach;
118
+ endif;
119
+ endif;
120
+
121
+ if ($return):
122
+ array_unshift($return, array('value' => '', 'label' => $this->__('--Please Select--')));
123
+ return $return;
124
+ endif;
125
+ endif;
126
+
127
+ return array(
128
+ array('value' => '', 'label' => $this->__('No Options Found'))
129
+ );
130
+ endif;
131
+ }
132
+
133
+ private function _getOptGroups($options, $optgroup)
134
+ {
135
+ $groups = array();
136
+ foreach ($options as $option):
137
+ if (!empty($option['name']) && !empty($option['id'])):
138
+ if (isset($option[$optgroup]) && is_array($option[$optgroup])):
139
+ if (!empty($option[$optgroup]['name']) && !empty($option[$optgroup]['id'])):
140
+ $id = $option[$optgroup]['id'];
141
+ $value = $option[$optgroup]['name'];
142
+ if (!isset($groups[$id]['value'])):
143
+ $groups[$id]['value'] = array();
144
+ endif;
145
+ if (!isset($groups[$id]['label'])):
146
+ $groups[$id]['label'] = $value;
147
+ endif;
148
+ $groups[$id]['value'][] = array('value' => $option['id'], 'label' => $option['name']);
149
+ endif;
150
+ endif;
151
+ endif;
152
+ endforeach;
153
+
154
+ return $groups;
155
+ }
156
+
157
+ private function _canSend($data)
158
+ {
159
+ if (!empty($data['name']) && !empty($data['email']) && !empty($data['subject']) && !empty($data['comment'])):
160
+ if (Mage::getStoreConfig('sirportly/ticketassign/status') && Mage::getStoreConfig('sirportly/ticketassign/priority') && Mage::getStoreConfig('sirportly/ticketassign/team') && Mage::getStoreConfig('sirportly/ticketassign/department')):
161
+ return true;
162
+ endif;
163
+ endif;
164
+
165
+ return false;
166
+ }
167
+ }
app/code/community/HusseyCoding/Sirportly/Model/Observer.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class HusseyCoding_Sirportly_Model_Observer
3
+ {
4
+ private $_token;
5
+ private $_secret;
6
+ private $_informed = false;
7
+
8
+ public function adminhtmlCoreConfigDataSaveAfter($observer)
9
+ {
10
+ $data = $observer->getConfigData();
11
+ if ($data->getPath() == 'sirportly/api/token'):
12
+ $this->_token = $data->getValue();
13
+ elseif ($data->getPath() == 'sirportly/api/secret'):
14
+ $this->_secret = $data->getValue();
15
+ endif;
16
+
17
+ if (isset($this->_token) && isset($this->_secret) && !$this->_informed):
18
+ $this->_informed = true;
19
+ if (Mage::helper('sirportly')->verifyCredentials($this->_token, $this->_secret)):
20
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('sirportly')->__('Successfully verified Sirportly API credentials.'));
21
+ else:
22
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('sirportly')->__('Failed to verify Sirportly API credentials.'));
23
+ endif;
24
+ endif;
25
+ }
26
+ }
app/code/community/HusseyCoding/Sirportly/Model/System/Config/Source/Department.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class HusseyCoding_Sirportly_Model_System_Config_Source_Department
3
+ {
4
+ public function toOptionArray()
5
+ {
6
+ return Mage::helper('sirportly')->getSelectOptions('/api/v2/objects/departments', 'brand');
7
+ }
8
+ }
app/code/community/HusseyCoding/Sirportly/Model/System/Config/Source/Priority.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class HusseyCoding_Sirportly_Model_System_Config_Source_Priority
3
+ {
4
+ public function toOptionArray()
5
+ {
6
+ return Mage::helper('sirportly')->getSelectOptions('/api/v2/objects/priorities');
7
+ }
8
+ }
app/code/community/HusseyCoding/Sirportly/Model/System/Config/Source/Status.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class HusseyCoding_Sirportly_Model_System_Config_Source_Status
3
+ {
4
+ public function toOptionArray()
5
+ {
6
+ return Mage::helper('sirportly')->getSelectOptions('/api/v2/objects/statuses');
7
+ }
8
+ }
app/code/community/HusseyCoding/Sirportly/Model/System/Config/Source/Team.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class HusseyCoding_Sirportly_Model_System_Config_Source_Team
3
+ {
4
+ public function toOptionArray()
5
+ {
6
+ return Mage::helper('sirportly')->getSelectOptions('/api/v2/objects/teams');
7
+ }
8
+ }
app/code/community/HusseyCoding/Sirportly/controllers/TicketController.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class HusseyCoding_Sirportly_TicketController extends Mage_Core_Controller_Front_Action
3
+ {
4
+ public function createAction()
5
+ {
6
+ if (Mage::helper('sirportly')->createTicket($this->getRequest()->getPost())):
7
+ Mage::getSingleton('customer/session')->addSuccess(Mage::helper('sirportly')->__('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.'));
8
+ $response = Zend_Json::encode(array('status' => 'success'));
9
+ else:
10
+ $response = Zend_Json::encode(array('status' => 'failed'));
11
+ endif;
12
+
13
+ $this->getResponse()->setBody($response);
14
+ }
15
+ }
app/code/community/HusseyCoding/Sirportly/etc/adminhtml.xml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <acl>
4
+ <resources>
5
+ <all>
6
+ <title>Allow Everything</title>
7
+ </all>
8
+ <admin>
9
+ <children>
10
+ <system>
11
+ <children>
12
+ <config>
13
+ <children>
14
+ <sirportly module="sirportly">
15
+ <title>Sirportly</title>
16
+ </sirportly>
17
+ </children>
18
+ </config>
19
+ </children>
20
+ </system>
21
+ </children>
22
+ </admin>
23
+ </resources>
24
+ </acl>
25
+ </config>
app/code/community/HusseyCoding/Sirportly/etc/config.xml ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <HusseyCoding_Sirportly>
5
+ <version>1.0.0</version>
6
+ </HusseyCoding_Sirportly>
7
+ </modules>
8
+ <global>
9
+ <helpers>
10
+ <sirportly>
11
+ <class>HusseyCoding_Sirportly_Helper</class>
12
+ </sirportly>
13
+ </helpers>
14
+ <models>
15
+ <sirportly>
16
+ <class>HusseyCoding_Sirportly_Model</class>
17
+ </sirportly>
18
+ </models>
19
+ </global>
20
+ <frontend>
21
+ <routers>
22
+ <sirportly>
23
+ <use>standard</use>
24
+ <args>
25
+ <module>HusseyCoding_Sirportly</module>
26
+ <frontName>sirportly</frontName>
27
+ </args>
28
+ </sirportly>
29
+ </routers>
30
+ <layout>
31
+ <updates>
32
+ <sirportly>
33
+ <file>sirportly.xml</file>
34
+ </sirportly>
35
+ </updates>
36
+ </layout>
37
+ </frontend>
38
+ <adminhtml>
39
+ <events>
40
+ <core_config_data_save_after>
41
+ <observers>
42
+ <adminhtml_core_config_data_save_after_sirportly>
43
+ <class>sirportly/observer</class>
44
+ <method>adminhtmlCoreConfigDataSaveAfter</method>
45
+ </adminhtml_core_config_data_save_after_sirportly>
46
+ </observers>
47
+ </core_config_data_save_after>
48
+ </events>
49
+ </adminhtml>
50
+ </config>
app/code/community/HusseyCoding/Sirportly/etc/system.xml ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <sirportly translate="label" module="sirportly">
5
+ <label>Sirportly</label>
6
+ <tab>husseycoding</tab>
7
+ <frontend_type>text</frontend_type>
8
+ <sort_order>1500</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>1</show_in_website>
11
+ <show_in_store>1</show_in_store>
12
+ <groups>
13
+ <api translate="label">
14
+ <label>API Credentials</label>
15
+ <frontend_type>text</frontend_type>
16
+ <sort_order>1</sort_order>
17
+ <show_in_default>1</show_in_default>
18
+ <show_in_website>1</show_in_website>
19
+ <show_in_store>1</show_in_store>
20
+ <comment><![CDATA[Enter the API token and secret from the Sirportly API Access configuration. You can create an API token under Admin &rarr; API Access when logged in to Sirportly.]]></comment>
21
+ <fields>
22
+ <token>
23
+ <label>Token</label>
24
+ <frontend_type>text</frontend_type>
25
+ <sort_order>1</sort_order>
26
+ <show_in_default>1</show_in_default>
27
+ <show_in_website>1</show_in_website>
28
+ <show_in_store>1</show_in_store>
29
+ <comment>Required</comment>
30
+ </token>
31
+ <secret>
32
+ <label>Secret</label>
33
+ <frontend_type>text</frontend_type>
34
+ <sort_order>2</sort_order>
35
+ <show_in_default>1</show_in_default>
36
+ <show_in_website>1</show_in_website>
37
+ <show_in_store>1</show_in_store>
38
+ <comment>Required</comment>
39
+ </secret>
40
+ </fields>
41
+ </api>
42
+ <ticketassign translate="label">
43
+ <label>Ticket Defaults</label>
44
+ <frontend_type>text</frontend_type>
45
+ <sort_order>2</sort_order>
46
+ <show_in_default>1</show_in_default>
47
+ <show_in_website>1</show_in_website>
48
+ <show_in_store>1</show_in_store>
49
+ <comment>Here you can define a status, priority, team and department to assign new tickets to in Sirportly.</comment>
50
+ <fields>
51
+ <status>
52
+ <label>Status</label>
53
+ <frontend_type>select</frontend_type>
54
+ <sort_order>1</sort_order>
55
+ <show_in_default>1</show_in_default>
56
+ <show_in_website>1</show_in_website>
57
+ <show_in_store>1</show_in_store>
58
+ <source_model>sirportly/system_config_source_status</source_model>
59
+ <comment>Required</comment>
60
+ </status>
61
+ <priority>
62
+ <label>Priority</label>
63
+ <frontend_type>select</frontend_type>
64
+ <sort_order>2</sort_order>
65
+ <show_in_default>1</show_in_default>
66
+ <show_in_website>1</show_in_website>
67
+ <show_in_store>1</show_in_store>
68
+ <source_model>sirportly/system_config_source_priority</source_model>
69
+ <comment>Required</comment>
70
+ </priority>
71
+ <team>
72
+ <label>Team</label>
73
+ <frontend_type>select</frontend_type>
74
+ <sort_order>3</sort_order>
75
+ <show_in_default>1</show_in_default>
76
+ <show_in_website>1</show_in_website>
77
+ <show_in_store>1</show_in_store>
78
+ <source_model>sirportly/system_config_source_team</source_model>
79
+ <comment>Required</comment>
80
+ </team>
81
+ <department>
82
+ <label>Department</label>
83
+ <frontend_type>select</frontend_type>
84
+ <sort_order>4</sort_order>
85
+ <show_in_default>1</show_in_default>
86
+ <show_in_website>1</show_in_website>
87
+ <show_in_store>1</show_in_store>
88
+ <source_model>sirportly/system_config_source_department</source_model>
89
+ <comment>Required</comment>
90
+ </department>
91
+ </fields>
92
+ </ticketassign>
93
+ <contact translate="label">
94
+ <label>Contact Form Integration</label>
95
+ <frontend_type>text</frontend_type>
96
+ <sort_order>3</sort_order>
97
+ <show_in_default>1</show_in_default>
98
+ <show_in_website>1</show_in_website>
99
+ <show_in_store>1</show_in_store>
100
+ <fields>
101
+ <enabled>
102
+ <label>Enabled</label>
103
+ <frontend_type>select</frontend_type>
104
+ <sort_order>1</sort_order>
105
+ <show_in_default>1</show_in_default>
106
+ <show_in_website>1</show_in_website>
107
+ <show_in_store>1</show_in_store>
108
+ <source_model>adminhtml/system_config_source_yesno</source_model>
109
+ <comment>Enable or disable Sirportly contact form integration. When disabled, contact form requests will be processed by Magento as normal.</comment>
110
+ </enabled>
111
+ </fields>
112
+ </contact>
113
+ </groups>
114
+ </sirportly>
115
+ </sections>
116
+ </config>
app/design/frontend/base/default/layout/sirportly.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <contacts_index_index>
4
+ <reference name="head">
5
+ <action method="addItem">
6
+ <type>skin_js</type>
7
+ <name>js/sirportlysubmit.js</name>
8
+ </action>
9
+ </reference>
10
+ <block type="core/template" name="sirportly_contact" template="sirportly/contact.phtml" after="-" parent="content" />
11
+ </contacts_index_index>
12
+ </layout>
app/design/frontend/base/default/template/sirportly/contact.phtml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php if (Mage::getStoreConfig('sirportly/contact/enabled')): ?>
2
+ <script type="text/javascript">
3
+ //<![CDATA[
4
+ var thissirportlysubmit = new sirportlysubmit();
5
+ //]]>
6
+ </script>
7
+ <?php endif; ?>
app/etc/modules/HusseyCoding_Common.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <HusseyCoding_Common>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </HusseyCoding_Common>
8
+ </modules>
9
+ </config>
app/etc/modules/HusseyCoding_Sirportly.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <HusseyCoding_Sirportly>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </HusseyCoding_Sirportly>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>HusseyCoding_Sirportly</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">OSL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Magento to Sirportly integration.</summary>
10
+ <description>Create Sirportly helpdesk tickets via the Magento contact form.</description>
11
+ <notes>Initial release</notes>
12
+ <authors><author><name>Hussey Coding</name><user>husseycoding</user><email>info@husseycoding.co.uk</email></author></authors>
13
+ <date>2013-08-08</date>
14
+ <time>16:30:03</time>
15
+ <contents><target name="magecommunity"><dir name="HusseyCoding"><dir name="Sirportly"><dir name="controllers"><file name="TicketController.php" hash="14efda4f1d8f1eebf688df018709323d"/></dir><dir name="etc"><file name="adminhtml.xml" hash="31ce0056778c58c2430b0b2cccb9b1a5"/><file name="config.xml" hash="b81e21675f2495fb45d0305608fb534c"/><file name="system.xml" hash="04052a159deb9b5762cfebda49107eee"/></dir><dir name="Helper"><file name="Data.php" hash="67aaabcb7c8390f6dff0759b91a1106d"/></dir><dir name="Model"><file name="Observer.php" hash="a14e57ea58ba025f62483efd650b55fa"/><dir name="System"><dir name="Config"><dir name="Source"><file name="Department.php" hash="f8a708f2e042365bd892bfd1f392fec3"/><file name="Priority.php" hash="682065ee3cdcab991e5fd252730c8640"/><file name="Status.php" hash="60fd06d1743463ad345afa2cb1827e9d"/><file name="Team.php" hash="1b1fc5cfb6c50a74a57aba2252f43874"/></dir></dir></dir></dir></dir><dir name="Common"><dir name="etc"><file name="system.xml" hash="6c9ba9f227b9adfc9abf97f17b46fdbf"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="HusseyCoding_Sirportly.xml" hash="a92236145783da6931bf04a2028ae285"/><file name="HusseyCoding_Common.xml" hash="31e82d3d9b3179c2fa9e002f9669da47"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="sirportly.xml" hash="60e4095bd8f1dcf51c3ae0c2daa70147"/></dir><dir name="template"><dir name="sirportly"><file name="contact.phtml" hash="4225d9efe951991fb3a21a276be0f6c7"/></dir></dir></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="js"><file name="sirportlysubmit.js" hash="d6a80d54715f19ff7811a6d9d69daa9a"/></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>
skin/frontend/base/default/js/sirportlysubmit.js ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var sirportlysubmit = Class.create({
2
+ afterInit: function() {
3
+ this.addSubject();
4
+ this.scrollToTop();
5
+ this.form = $("contactForm");
6
+ this.form.observe("submit", function(e) {
7
+ Event.stop(e);
8
+ if (contactForm.validator && contactForm.validator.validate()) {
9
+ this.disableButton();
10
+ var parameters = this.form.serialize(true);
11
+ new Ajax.Request("/sirportly/ticket/create", {
12
+ parameters: parameters,
13
+ onSuccess: function(response) {
14
+ var contentarray = response.responseText.evalJSON();
15
+ if (typeof(contentarray) == "object") {
16
+ var status = contentarray.status;
17
+ if (status == "success") {
18
+ window.location.reload();
19
+ } else {
20
+ this.enableButton();
21
+ this.failedSubmit();
22
+ }
23
+ } else {
24
+ this.enableButton();
25
+ this.failedSubmit();
26
+ }
27
+ }.bind(this)
28
+ });
29
+ }
30
+ }.bindAsEventListener(this));
31
+ },
32
+ disableButton: function() {
33
+ this.form.down("button").disable();
34
+ this.form.down("button").setStyle({
35
+ opacity: 0.5,
36
+ cursor: "default"
37
+ });
38
+ },
39
+ enableButton: function() {
40
+ this.form.down("button").enable();
41
+ this.form.down("button").setStyle({
42
+ opacity: 1,
43
+ cursor: "pointer"
44
+ });
45
+ },
46
+ scrollToTop: function() {
47
+ if ($$("ul.messages")[0]) {
48
+ $$("body")[0].scrollTo();
49
+ }
50
+ },
51
+ failedSubmit: function() {
52
+ this.form.stopObserving("submit");
53
+ this.form.submit();
54
+ },
55
+ addSubject: function() {
56
+ var el = new Element("li", {"class":"wide"}).update(
57
+ new Element("label", {"for":"subject", "class":"required"}).update("<em>*</em>Subject")
58
+ );
59
+ el.insert({
60
+ bottom:new Element("div", {"class":"input-box"}).update(
61
+ new Element("input", {"class":"input-text required-entry", "type":"text", "value":"", "id":"subject", "name":"subject", "title":"Subject"})
62
+ )
63
+ });
64
+
65
+ $("comment").up("li").insert({
66
+ before:el
67
+ });
68
+ }
69
+ });
70
+
71
+ document.observe("dom:loaded", function() {
72
+ if (typeof(thissirportlysubmit) == "object") {
73
+ thissirportlysubmit.afterInit();
74
+ }
75
+ });