Skip to content

Commit 5d022aa

Browse files
maxmimaxmi
authored andcommitted
Refactoring
1 parent 73e5d14 commit 5d022aa

File tree

13 files changed

+84
-107
lines changed

13 files changed

+84
-107
lines changed

src/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Dashboard/Tab/Tickets/Grid/Abstract.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function setViewId($id = null) {
3838

3939
public function __construct($attributes = array()) {
4040
parent::__construct($attributes);
41-
41+
4242
$this->_defaultSort = Mage::getStoreConfig('zendesk/backend_features/default_sort');
4343
$this->_defaultDir = Mage::getStoreConfig('zendesk/backend_features/default_sort_dir');
4444

@@ -213,4 +213,28 @@ protected function getGridParams() {
213213
);
214214
}
215215

216+
public function getGridJavascript()
217+
{
218+
$js = $this->getJsObjectName()."= new varienGrid('".$this->getId()."', '".$this->getGridUrl()."', '".$this->getVarNamePage()."', '".$this->getVarNameSort()."', '".$this->getVarNameDir()."', '".$this->getVarNameFilter()."');";
219+
$js .= $this->getJsObjectName() .".useAjax = '".$this->getUseAjax()."';";
220+
221+
if($this->getRowClickCallback())
222+
$js .= $this->getJsObjectName() .".rowClickCallback = ".$this->getRowClickCallback().";";
223+
224+
if($this->getCheckboxCheckCallback())
225+
$js .= $this->getJsObjectName().".checkboxCheckCallback = ".$this->getCheckboxCheckCallback().";";
226+
227+
if($this->getRowInitCallback()) {
228+
$js .= $this->getJsObjectName().".initRowCallback = ".$this->getRowInitCallback().";";
229+
$js .= $this->getJsObjectName().".initGridRows();";
230+
}
231+
232+
if($this->getMassactionBlock()->isAvailable())
233+
$js .= $this->getMassactionBlock()->getJavaScript();
234+
235+
$js .= $this->getAdditionalJavaScript();
236+
237+
return $js;
238+
}
239+
216240
}

src/app/code/community/Zendesk/Zendesk/controllers/Adminhtml/ZendeskController.php

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ class Zendesk_Zendesk_Adminhtml_ZendeskController extends Mage_Adminhtml_Control
2323

2424
public function indexAction()
2525
{
26-
$domain = Mage::getStoreConfig('zendesk/general/domain');
27-
28-
if (!$domain) {
29-
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('zendesk')->__('Please set up Zendesk connection.'));
26+
if (!$this->_domainConfigured()) {
27+
return;
3028
}
3129

3230
$connection = Mage::helper('zendesk')->getConnectionStatus();
@@ -159,20 +157,10 @@ public function logoutAction()
159157

160158
public function createAction()
161159
{
162-
try {
163-
$domain = Mage::getStoreConfig('zendesk/general/domain');
164-
if(!$domain) {
165-
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('zendesk')->__('Please set up Zendesk connection.'));
166-
$this->_redirect('adminhtml/zendesk/index');
167-
return;
168-
}
169-
} catch( Exception $ex ) {
170-
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('zendesk')->__('Please set up Zendesk connection.'));
171-
$this->_redirect('adminhtml/zendesk/index');
160+
if (!$this->_domainConfigured()) {
172161
return;
173162
}
174163

175-
176164
// Check if we have been passed an order ID, in which case we can preload some of the form details
177165
if($orderId = $this->getRequest()->getParam('order_id')) {
178166
$order = Mage::getModel('sales/order')->load($orderId);
@@ -206,10 +194,8 @@ public function createAction()
206194

207195
public function launchAction()
208196
{
209-
$domain = Mage::getStoreConfig('zendesk/general/domain');
210-
if(!$domain) {
211-
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('zendesk')->__('Please set up Zendesk connection.'));
212-
$this->_redirect("adminhtml/zendesk/index");
197+
$domain = $this->_domainConfigured();
198+
if (!$domain) {
213199
return;
214200
}
215201

@@ -715,5 +701,17 @@ protected function getMassActionResponse($response, $ids, $message = '%d out of
715701
);
716702
}
717703
}
704+
705+
private function _domainConfigured()
706+
{
707+
$domain = Mage::getStoreConfig('zendesk/general/domain');
708+
if(!$domain) {
709+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('zendesk')->__('Please set up Zendesk connection.'));
710+
$this->_redirect('adminhtml/dashboard');
711+
return false;
712+
} else {
713+
return $domain;
714+
}
715+
}
718716

719717
}

src/app/design/adminhtml/default/default/template/zendesk/config/button-sync.phtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@
4040
<span><?php echo $this->escapeHtml($this->getButtonLabel()) ?></span>
4141
</button>
4242
<div id="zendesk-sync-results"></div>
43+

src/app/design/adminhtml/default/default/template/zendesk/config/button-test-magento.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@
4141
<button style="" onclick="javascript:checkApiConnection(); return false;" class="scalable" type="button" id="<?php echo $this->getHtmlId() ?>">
4242
<span><?php echo $this->escapeHtml($this->getButtonLabel()) ?></span>
4343
</button>
44-
<div id="zendesk-test-connection-results"></div>
44+
<div id="zendesk-test-connection-results"></div>

src/app/design/adminhtml/default/default/template/zendesk/config/button-test-zendesk.phtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@
3939
}
4040
</script>
4141
<div id="zendesk-api-connection-results"></div>
42+

src/app/design/adminhtml/default/default/template/zendesk/customer/tickets.phtml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,16 @@ if($customer = Mage::registry('current_customer')) {
5454
</thead>
5555
<tbody class="odd">
5656
<?php foreach($tickets as $ticket): ?>
57-
<?php $t = Mage::getModel('zendesk/api_tickets')->get($ticket['id'], true); ?>
58-
<tr class="border">
59-
<td><?php echo ucwords($ticket['priority']); ?></td>
60-
<td><?php echo Mage::helper('zendesk')->getTicketUrl($ticket); ?></td>
61-
<td><?php echo Mage::helper('core')->formatDate($ticket['created_at'], Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true); ?></td>
62-
<td><?php echo Mage::helper('core')->formatDate($ticket['updated_at'], Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true); ?></td>
63-
<td><?php echo ucwords($ticket['status']); ?></td>
64-
<td><?php echo ($ticket['group_id']) ? $t['group']['name'] : ''; ?></td>
65-
<td><?php echo ($ticket['assignee_id']) ? $t['assignee']['name'] : ''; ?></td>
66-
</tr>
57+
<?php $t = Mage::getModel('zendesk/api_tickets')->get($ticket['id'], true); ?>
58+
<tr class="border">
59+
<td><?php echo ucwords($ticket['priority']); ?></td>
60+
<td><?php echo Mage::helper('zendesk')->getTicketUrl($ticket); ?></td>
61+
<td><?php echo Mage::helper('core')->formatDate($ticket['created_at'], Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true); ?></td>
62+
<td><?php echo Mage::helper('core')->formatDate($ticket['updated_at'], Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true); ?></td>
63+
<td><?php echo ucwords($ticket['status']); ?></td>
64+
<td><?php echo ($ticket['group_id']) ? $t['group']['name'] : ''; ?></td>
65+
<td><?php echo ($ticket['assignee_id']) ? $t['assignee']['name'] : ''; ?></td>
66+
</tr>
6767
<?php endforeach; ?>
6868
</tbody>
6969
</table>

src/app/design/adminhtml/default/default/template/zendesk/dashboard/index.phtml

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,28 @@
1818
<?php if( $this->isConnected() ): ?>
1919
<?php if ($this->getIsZendeskDashboard() || Mage::getStoreConfig('zendesk/backend_features/show_on_dashboard')): ?>
2020
<?php if ($this->getIsZendeskDashboard()): ?>
21-
<div class="content-header">
22-
<table cellspacing="0">
23-
<tr>
24-
<td><h3 class="head-dashboard"><?php echo $this->__('Dashboard') ?></h3></td>
25-
</tr>
26-
</table>
27-
</div>
28-
<?php endif; ?>
29-
<div class="zendesk_dashboard_container">
30-
<?php echo $this->getChildHtml('zendesk_dashboard_grids') ?>
31-
<div id="tickets_grid_tab_content"></div>
32-
33-
<?php if (!$this->getIsZendeskDashboard()): ?>
34-
<div class="a-right" style="margin: 6px 0;">
35-
<button style="" onclick="setLocation('<?php echo $this->getUrl('adminhtml/zendesk/create'); ?>');" class="scalable" type="button" id="zendesk-create-ticket">
36-
<span><?php echo $this->__('New Support Ticket'); ?></span>
37-
</button>
38-
<button style="" onclick="setLocation('<?php echo Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/zendesk/launch'); ?>');" class="scalable" type="button" id="zendesk-view-all">
39-
<span><?php echo $this->__('View All Tickets'); ?></span>
40-
</button>
21+
<div class="content-header">
22+
<table cellspacing="0">
23+
<tr>
24+
<td><h3 class="head-dashboard"><?php echo $this->__('Dashboard') ?></h3></td>
25+
</tr>
26+
</table>
4127
</div>
4228
<?php endif; ?>
43-
</div>
44-
<?php echo $this->getChildHtml('zendesk_dashboard_empty'); ?>
45-
<?php endif; ?>
29+
<div class="zendesk_dashboard_container">
30+
<?php echo $this->getChildHtml('zendesk_dashboard_grids') ?>
31+
<div id="tickets_grid_tab_content"></div>
32+
<?php if (!$this->getIsZendeskDashboard()): ?>
33+
<div class="a-right" style="margin: 6px 0;">
34+
<button style="" onclick="setLocation('<?php echo $this->getUrl('adminhtml/zendesk/create'); ?>');" class="scalable" type="button" id="zendesk-create-ticket">
35+
<span><?php echo $this->__('New Support Ticket'); ?></span>
36+
</button>
37+
<button style="" onclick="setLocation('<?php echo Mage::getSingleton('adminhtml/url')->getUrl('adminhtml/zendesk/launch'); ?>');" class="scalable" type="button" id="zendesk-view-all">
38+
<span><?php echo $this->__('View All Tickets'); ?></span>
39+
</button>
40+
</div>
41+
<?php endif; ?>
42+
</div>
43+
<?php echo $this->getChildHtml('zendesk_dashboard_empty'); ?>
44+
<?php endif; ?>
4645
<?php endif; ?>

src/app/design/adminhtml/default/default/template/zendesk/tickets/tickets.phtml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ if($customer = Mage::registry('current_customer')) {
2828
} catch(Exception $e) {
2929
// Don't do anything, just don't show the tickets
3030
}
31-
3231
}
3332
?>
3433
<?php if($tickets): ?>

src/app/design/adminhtml/default/default/template/zendesk/widget/grid.phtml

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,11 @@ $numColumns = sizeof($this->getColumns());
111111
</tr>
112112
</table>
113113
<?php endif; ?>
114-
<?php if($this->getMassactionBlock()->isAvailable()): ?>
115-
<?php echo $this->getMassactionBlockHtml() ?>
116-
<?php endif ?>
114+
<?php
115+
if($this->getMassactionBlock()->isAvailable()){
116+
echo $this->getMassactionBlockHtml();
117+
}
118+
?>
117119
<div class="grid">
118120
<div class="hor-scroll">
119121
<table cellspacing="0" class="data" id="<?php echo $this->getId() ?>_table">
@@ -180,7 +182,7 @@ $numColumns = sizeof($this->getColumns());
180182

181183
<?php if ($this->shouldRenderSubTotal($_item)): ?>
182184
<tr class="subtotals">
183-
<?php $i = 0; foreach ($this->getSubTotalColumns() as $_column): ?>
185+
<?php $i=0;foreach ($this->getSubTotalColumns() as $_column): ?>
184186
<td class="<?php echo $_column->getCssProperty() ?> <?php echo ++$i == $numColumns ? 'last' : '' ?>">
185187
<?php echo ($_column->hasSubtotalsLabel() ? $_column->getSubtotalsLabel() :
186188
$_column->getRowField($this->getSubTotalItem($_item))
@@ -205,22 +207,7 @@ $numColumns = sizeof($this->getColumns());
205207
</div>
206208
<script type="text/javascript">
207209
//<![CDATA[
208-
<?php echo $this->getJsObjectName() ?> = new varienGrid('<?php echo $this->getId() ?>', '<?php echo $this->getGridUrl() ?>', '<?php echo $this->getVarNamePage() ?>', '<?php echo $this->getVarNameSort() ?>', '<?php echo $this->getVarNameDir() ?>', '<?php echo $this->getVarNameFilter() ?>');
209-
<?php echo $this->getJsObjectName() ?>.useAjax = '<?php echo $this->getUseAjax() ?>';
210-
<?php if($this->getRowClickCallback()): ?>
211-
<?php echo $this->getJsObjectName() ?>.rowClickCallback = <?php echo $this->getRowClickCallback() ?>;
212-
<?php endif; ?>
213-
<?php if($this->getCheckboxCheckCallback()): ?>
214-
<?php echo $this->getJsObjectName() ?>.checkboxCheckCallback = <?php echo $this->getCheckboxCheckCallback() ?>;
215-
<?php endif; ?>
216-
<?php if($this->getRowInitCallback()): ?>
217-
<?php echo $this->getJsObjectName() ?>.initRowCallback = <?php echo $this->getRowInitCallback() ?>;
218-
<?php echo $this->getJsObjectName() ?>.initGridRows();
219-
<?php endif; ?>
220-
<?php if($this->getMassactionBlock()->isAvailable()): ?>
221-
<?php echo $this->getMassactionBlock()->getJavaScript() ?>
222-
<?php endif ?>
223-
<?php echo $this->getAdditionalJavaScript(); ?>
210+
<?php echo $this->getGridJavascript() ?>
224211
//]]>
225212
</script>
226213
<?php endif; ?>

src/app/design/frontend/base/default/layout/zendesk.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,4 @@
5151
</zendesk_customer_tickets_index>
5252
<zendesk_sso_login>
5353
</zendesk_sso_login>
54-
5554
</layout>

0 commit comments

Comments
 (0)