1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31:
32:
33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43:
44: class Eabi_Livehandler_Model_Ordergrid extends Eabi_Livehandler_Model_Adminhtml_Gridmanager {
45:
46: 47: 48: 49:
50: private static $_allowedActions;
51:
52: 53: 54: 55:
56: private static $_hasButtons = false;
57:
58: 59: 60:
61: CONST CACHE_KEY = 'eabi_livehandler_model_ordergrid';
62:
63: protected $_loadedButtons = array();
64:
65:
66: public function _construct() {
67: parent::_construct();
68: $this->_init('eabi_livehandler/ordergrid');
69: $this->_initButtons();
70: }
71:
72: 73: 74: 75: 76:
77: private function _initButtons() {
78: if (self::$_allowedActions === null) {
79:
80:
81:
82:
83: $cache = Mage::app()->getCache();
84:
85: $configStored = $cache->load(self::CACHE_KEY);
86: if ($configStored != 'true') {
87:
88:
89: $configBackend = Mage::getModel('eabi_livehandler/system_config_backend_button');
90: $configBackend->load('eabi_livehandler/admintools/buttons', 'path');
91: $configBackend->save();
92: if ($configBackend->isValueChanged() && is_array($configBackend->getValue())) {
93: $this->getEabi()->setConfigData('eabi_livehandler/admintools/buttons', serialize($configBackend->getValue()));
94: }
95:
96:
97:
98:
99:
100: $cache->save('true', self::CACHE_KEY, array(Mage_Core_Model_Config::CACHE_TAG), 0);
101:
102: }
103:
104:
105:
106: $allowedActions = @unserialize(Mage::getStoreConfig('eabi_livehandler/admintools/buttons'));
107: if (!is_array($allowedActions)) {
108:
109: $allowedActions = array();
110: }
111: self::$_allowedActions = array();
112:
113: uasort($allowedActions, array(__CLASS__, '_sortAction'));
114: foreach ($allowedActions as $allowedAction) {
115:
116: if (!(bool)$allowedAction['disabled']) {
117: self::$_allowedActions[] = $allowedAction['button_name'];
118: }
119: self::$_hasButtons = true;
120: }
121: }
122: }
123:
124:
125: public static function _sortAction($a, $b) {
126: if ((bool)$a['disabled'] && !(bool)$b['disabled']) {
127: return 1;
128: }
129: if (!(bool)$a['disabled'] && (bool)$b['disabled']) {
130: return -1;
131: }
132: if ((int)$a['sort_order'] == (int)$b['sort_order']) {
133: return 0;
134: }
135: return (int)$a['sort_order'] < (int)$b['sort_order']?-1:1;
136: }
137:
138: 139: 140: 141: 142: 143: 144: 145: 146: 147:
148: public function service($postData) {
149: $errors = array();
150: $messages = array();
151:
152: $result = array(
153: 'success' => false,
154: 'set_location' => false,
155: );
156: if (!Mage::getStoreConfig('eabi_livehandler/admintools/enabled')) {
157: return $result;
158: }
159: if (isset($postData['order_id'])) {
160: $order = Mage::getModel('sales/order')->load($postData['order_id']);
161: if ($order->getId() > 0) {
162: $isActionError = false;
163:
164:
165:
166:
167:
168:
169:
170: if (isset($postData['action']) && is_string($postData['action'])) {
171: $postData['action'] = str_replace('__', '/', $postData['action']);
172: }
173: if (isset($postData['action']) && in_array($postData['action'], self::$_allowedActions)) {
174: if (strpos($postData['action'], '/')) {
175: $actionModel = Mage::getSingleton($postData['action']);
176: } else {
177: $actionModel = Mage::getSingleton('eabi_livehandler/action_' . $postData['action']);
178: }
179:
180:
181:
182: if ($actionModel && $actionModel instanceof Eabi_Livehandler_Model_Action_Abstract
183: && $actionModel->canDisplay($order)) {
184: $data = isset($postData['extra_data'])?json_decode($postData['extra_data'], true):array();
185: if (!is_array($data)) {
186: $data = array();
187: }
188: $actionResult = $actionModel->performDesiredAction($order, $data);
189: if (isset($actionResult['errors'])) {
190: $errors = array_merge($messages, $actionResult['errors']);
191: }
192: $messages = array_merge($messages, $actionResult['messages']);
193: $isActionError = $actionResult['is_action_error'];
194: $result['needs_reload'] = $actionResult['needs_reload'];
195: if (isset($actionResult['set_location'])) {
196: $result['set_location'] = $actionResult['set_location'];
197: }
198: } else {
199: $isActionError = true;
200: }
201: } else {
202:
203: }
204: if ($isActionError) {
205: $errors[] = Mage::helper('eabi_livehandler')->__('Invalid action');
206: $result['needs_reload'] = true;
207: }
208: if ($result['set_location'] && strlen($result['set_location'])> 3) {
209: return $result;
210: }
211:
212: $address = $order->getShippingAddress();
213: if (!$address) {
214: $address = $order->getBillingAddress();
215: }
216:
217: $result['_order'] = $order->debug();
218: $result['address'] = $address->format('html');
219: $result['customer_email'] = htmlspecialchars($order->getCustomerEmail());
220: $result['total_paid'] = htmlspecialchars(Mage::helper('core')->currency($order->getBaseTotalPaid(), true, false));
221: $result['grand_total'] = htmlspecialchars(Mage::helper('core')->currency($order->getBaseGrandTotal(), true, false));
222: $result['base_shipping'] = htmlspecialchars(Mage::helper('core')->currency($order->getBaseShippingAmount(), true, false));
223: $result['base_total'] = htmlspecialchars(Mage::helper('core')->currency($order->getBaseGrandTotal() - $order->getBaseShippingAmount(), true, false));
224: $result['base_subtotal_to_refund'] = htmlspecialchars(Mage::helper('core')->currency($order->getBaseSubtotalInvoiced() - $order->getBaseSubtotalRefunded(), true, false));
225: $result['base_total_to_refund'] = htmlspecialchars(Mage::helper('core')->currency($order->getBaseTotalInvoiced() - $order->getBaseTotalRefunded(), true, false));
226: $result['payment'] = htmlspecialchars($order->getPayment()->getMethodInstance()->getTitle());
227: $result['shipping'] = htmlspecialchars($order->getShippingDescription());
228: if ($result['shipping'] == '') {
229: $result['shipping'] = Mage::helper('eabi_livehandler')->__('Not applicable');
230: }
231: $result['status_label'] = htmlspecialchars($order->getStatusLabel());
232: $result['discount_description'] = htmlspecialchars($order->getDiscountDescription());
233: if ($order->getBaseDiscountAmount() > 0) {
234: $result['discount_amount'] = htmlspecialchars(Mage::helper('core')->currency($order->getBaseDiscountAmount() * -1, true, false));
235:
236: } else {
237: $result['discount_amount'] = htmlspecialchars(Mage::helper('core')->currency($order->getBaseDiscountAmount(), true, false));
238:
239: }
240: $orderItems = $order->getAllVisibleItems();
241: $products = array();
242: foreach ($orderItems as $orderItem) {
243:
244:
245:
246: $html = <<<EOT
247: <tr>
248: <td class="a-left">%name%</td>
249: <td>%sku%</td>
250: <td>%qty%</td>
251: <td>%price%</td>
252: <td>%total%</td>
253: </tr>
254:
255: EOT;
256: $name = htmlspecialchars($orderItem->getName());
257: $options = $orderItem->getProductOptions();
258: $option = '';
259: if (isset($options['options'])) {
260: foreach ($options['options'] as $optionValues) {
261: if ($optionValues['value']) {
262: $option .= '<br/><strong><i>'. htmlspecialchars($optionValues['label']).'</i></strong>: ';
263: $_printValue = isset($optionValues['print_value']) ? $optionValues['print_value'] : strip_tags($optionValues['value']);
264: $values = explode(', ', $_printValue);
265: foreach ($values as $value) {
266: if (is_array($value)) {
267: foreach ($value as $_value) {
268: $option .= htmlspecialchars($_value);
269: }
270: } else {
271: $option .= htmlspecialchars($value);
272: }
273: $option .= '<br/>';
274: }
275: }
276: }
277: }
278: $name .= $option;
279: $basePrice = $orderItem->getBasePriceInclTax();
280: if ($basePrice == null) {
281: $basePrice = $orderItem->getBasePrice();
282: }
283:
284:
285: $toReplace = array(
286: 'name' => $name,
287: 'sku' => htmlspecialchars($orderItem->getSku()),
288: 'qty' => round($orderItem->getQtyOrdered()) .'/'.round(Mage::getModel('cataloginventory/stock_item')->loadByProduct($orderItem->getProductId())->getQty()),
289: 'price' => Mage::helper('core')->currency($basePrice, true, false),
290: 'total' => Mage::helper('core')->currency($basePrice * $orderItem->getQtyOrdered(), true, false),
291: );
292:
293: foreach ($toReplace as $key => $value) {
294: $html = str_replace('%'.$key.'%', $value, $html);
295: }
296:
297: $products[] = array(
298: 'name' => $orderItem->getName(),
299: 'base_original_price' => $orderItem->getBaseOriginalPrice(),
300: 'base_price' => $orderItem->getBasePrice(),
301: 'base_price_incl_tax' => $orderItem->getBasePriceInclTax(),
302: 'original_price' => $orderItem->getOriginalPrice(),
303: 'price' => $orderItem->getPrice(),
304: 'price_incl_tax' => $orderItem->getPriceInclTax(),
305: 'product_id' => $orderItem->getProductId(),
306: 'product_options' => $orderItem->getProductOptions(),
307: 'qty_ordered' => $orderItem->getQtyOrdered(),
308: 'row_total' => $orderItem->getRowTotal(),
309: 'row_total_incl_tax' => $orderItem->getRowTotalInclTax(),
310: 'sku' => $orderItem->getSku(),
311: 'tax_amount' => $orderItem->getTaxAmount(),
312: 'tax_percent' => $orderItem->getTaxPercent(),
313: 'html' => $html,
314: );
315:
316: }
317:
318: $buttonsHtml = '';
319: if (!self::$_hasButtons && !$this->getEabi()->getConfigData('eabi_livehandler/admintools/disable_url')) {
320: $buttonsHtml .= '<span class="eabi_commercial">'.$this->getEabi()->__('Manage the order from here by adding <a href=\'%s\' target=\'_blank\'>action buttons</a>', $this->getEabi()->__($this->getEabi()->getConfigData('eabi_livehandler/admintools/buttons_url'))).'</span>';
321: }
322:
323: foreach (self::$_allowedActions as $allowedAction) {
324: if (strpos($allowedAction, '/')) {
325: $actionButtonModel = Mage::getSingleton($allowedAction);
326: } else {
327: $actionButtonModel = Mage::getSingleton('eabi_livehandler/action_' . $allowedAction);
328: }
329:
330: if ($actionButtonModel && $actionButtonModel instanceof Eabi_Livehandler_Model_Action_Abstract && $actionButtonModel->canDisplay($order)) {
331: $buttonsHtml .= $this->__makeActionButton($actionButtonModel->getLabel(), $actionButtonModel->getOnClick(), $actionButtonModel->getCssClass(), 'eabi_' . $actionButtonModel->getCode());
332: $this->_loadedButtons = $actionButtonModel;
333: }
334: }
335:
336:
337:
338: $adminHelper = Mage::helper('adminhtml');
339: $result['success'] = true;
340: $result['header_html'] = <<<EOT
341: <div class="grid products_grid">
342: <table><thead>
343: <tr class="headings">
344: <th>{$adminHelper->__('Product')}</th>
345: <th>{$adminHelper->__('SKU')}</th>
346: <th>{$adminHelper->__('Qty')}</th>
347: <th>{$adminHelper->__('Price')}</th>
348: <th>{$adminHelper->__('Row Total')}</th>
349: </tr>
350: </thead>
351: <tbody>
352: EOT;
353: $result['footer_html'] = <<<EOT
354: </tbody>
355: </table>
356: </div>
357: EOT;
358:
359: $result['customer_address_html'] = '';
360:
361: if (count($errors) > 0 || count($messages) > 0) {
362: $result['customer_address_html'] .= '<ul class="messages">';
363:
364: if (count($messages) > 0) {
365: $result['customer_address_html'] .= '<li class="success-msg"><ul>';
366: foreach ($messages as $message) {
367: $result['customer_address_html'] .= '<li>'. htmlspecialchars($message).'</li>';
368: }
369: $result['customer_address_html'] .= '</ul></li>';
370: }
371:
372: if (count($errors) > 0) {
373: $result['customer_address_html'] .= '<li class="error-msg"><ul>';
374: foreach ($errors as $error) {
375: $result['customer_address_html'] .= '<li>'. htmlspecialchars($error).'</li>';
376: }
377: $result['customer_address_html'] .= '</ul></li>';
378: }
379:
380: $result['customer_address_html'] .= '</ul>';
381: }
382: $_blank = '';
383: if (Mage::getStoreConfig('eabi_livehandler/admintools/open_in_new')) {
384: $_blank = ' target="_blank"';
385: }
386: $orderUrl = Mage::helper('adminhtml')->getUrl('adminhtml/sales_order/view', array('order_id' => $order->getId()));
387: $result['customer_address_html'] .= <<<EOT
388: <div class="grid detail_grid">
389: <table><thead>
390: <tr class="headings">
391: <th>{$result['total_paid']}/{$result['grand_total']}</th>
392: <th class="a-right"><div class="eabi_buttons">{$buttonsHtml}</div> <a href="{$orderUrl}" title="{$adminHelper->__('View')}" {$_blank}>{$result['status_label']}</a></strong></th>
393: </tr>
394: </thead>
395: <tbody>
396: <tr>
397: <td class="a-left"><strong><a href="mailto:{$result['customer_email']}">{$result['customer_email']}</a></strong><br/>{$result['address']}</td>
398: <td>
399: <table>
400: <thead>
401: <tr>
402: <th>{$adminHelper->__('Payment Information')}</th>
403: </tr>
404: </thead>
405: <tbody>
406: <tr>
407: <td>{$result['payment']}</td>
408: </tr>
409: </tbody>
410: </table>
411: <table>
412: <thead>
413: <tr>
414: <th>{$adminHelper->__('Shipping & Handling Information')}</th>
415: </tr>
416: </thead>
417: <tbody>
418: <tr>
419: <td>{$result['shipping']}</td>
420: </tr>
421: </tbody>
422: </table>
423: </td>
424: </tr>
425: </tbody>
426: </table>
427: </div>
428:
429: EOT;
430:
431: if ($order->getBaseDiscountAmount() < 0 || $order->getBaseDiscountAmount() > 0) {
432: if ($result['discount_description'] == '') {
433: $result['discount_description'] = $order->getCouponCode();
434: }
435: $result['footer_html'] .= <<<EOT
436: <div class="grid discounts_grid">
437: <table><thead>
438: <tr class="headings">
439: <th>{$adminHelper->__('Discount')}: {$result['discount_description']}</th>
440: <th class="a-right"><strong>{$result['discount_amount']}</strong></th>
441: </tr>
442: </thead>
443: <tbody>
444: </tbody>
445: </table>
446: </div>
447:
448: EOT;
449: }
450: $date = $order->getCreatedAtFormated('medium');
451: $result['title_html'] = htmlspecialchars(sprintf(Mage::helper('sales')->__('Order #%s - %s'), $order->getIncrementId(), $date));
452: $result['products'] = $products;
453: }
454:
455: }
456: return $result;
457: }
458:
459: 460: 461: 462: 463: 464:
465: protected function _getAdditionalJs($currentJs) {
466: $js = '';
467: if (!Mage::getStoreConfig('eabi_livehandler/admintools/enabled')) {
468: return $js;
469: }
470:
471: $adminHelper = Mage::helper('adminhtml');
472: $showProductsText = Mage::helper('eabi_livehandler')->__('Show order info');
473: $showProductsText = htmlspecialchars(str_replace('\\\'', '\'', addslashes($showProductsText)));
474:
475: $additionalCssClass = '';
476: if (substr(Mage::getVersion(), 0, 3) == '1.3') {
477: $additionalCssClass = ' eabi_window_bg';
478: }
479: $longOnClicks = array();
480:
481: foreach (self::$_allowedActions as $allowedAction) {
482: if (strpos($allowedAction, '/')) {
483: $actionButtonModel = Mage::getSingleton($allowedAction);
484: } else {
485: $actionButtonModel = Mage::getSingleton('eabi_livehandler/action_' . $allowedAction);
486: }
487:
488: if ($actionButtonModel && $actionButtonModel instanceof Eabi_Livehandler_Model_Action_Abstract) {
489: if ($actionButtonModel->getLongOnClick() && strlen($actionButtonModel->getLongOnClick())) {
490: $longOnClicks[$actionButtonModel->getCode()] = $actionButtonModel->getLongOnClick();
491: }
492: }
493: }
494:
495:
496:
497:
498: $js .= <<<EOT
499:
500: var clickFirst = false, clickLast = false;
501: var eabiAdmintoolsGrid = function() {
502:
503: var position = 0,
504: filters = $$('tr.filter').first().childElements(),
505: needs_reload = false,
506: pageNum = parseInt($$('input[name=page]').first().getValue(), 10),
507: pageLimit = parseInt($$('select[name=limit]').first().getValue(), 10),
508: current_products = [];
509:
510: if (Control.Modal.current) {
511: Control.Modal.current.close();
512: }
513:
514: for (var i = 0, cnt = filters.length; i < cnt; i++) {
515: if (filters[i].select('input[name=billing_name]').length == 1) {
516: position = i;
517: break;
518: }
519: }
520:
521:
522: var rows = $$('table#sales_order_grid_table tbody tr');
523: if (rows.length == 1 && rows[0].childElements().length == 1) {
524: return;
525: }
526:
527: for (var i = 0, cnt = rows.length; i < cnt; i++) {
528: rows[i].childElements()[position].insert('<button id="eabi-order_' + rows[i].select('input[class=massaction-checkbox]').first().readAttribute('value') + '" style="float: right;" class="scalable show-hide eabi-order-products" onclick="Event.stop(event); return false;" type="button"><span><b>{$showProductsText}</b></span></button>', { position: 'bottom'})
529: }
530:
531: var style_window = function(container, options) {
532: var window_header = new Element('div', { className: 'window_header'});
533: var window_title = new Element('div', { className: 'window_title'});
534: var window_close = new Element('div', { className: 'window_close'});
535: var window_checkbox = new Element('span', { className: 'window_checkbox'});
536: var window_contents = new Element('div', { className: 'window_contents'});
537:
538: var w = new Control.Modal(container, Object.extend({
539: className: 'eabi_window{$additionalCssClass}',
540: /*closeOnClick: window_close,*/
541: draggable: window_header,
542: insertRemoteContentAt: window_contents,
543: iframeshim: false,
544: afterOpen: function() {
545: var eabi_order_products = $$('button.eabi-order-products').toArray(),
546: order_id = options.caller.readAttribute('id').split('_')[1],
547: post_params = {'order_id': order_id },
548: is_order_selected = false,
549: order_massaction_checkbox;
550: if (order_id) {
551: order_massaction_checkbox = $$('table.data input.massaction-checkbox[value=' + order_id + ']');
552: if (order_massaction_checkbox) {
553: order_massaction_checkbox = order_massaction_checkbox.first();
554: }
555: if (order_massaction_checkbox && order_massaction_checkbox.getValue()) {
556: is_order_selected = true;
557: }
558:
559: }
560: if (order_massaction_checkbox) {
561:
562: }
563: if (options.target) {
564: post_params.action = options.target;
565: }
566: if (options.extra_data) {
567: post_params.extra_data = Object.toJSON(options.extra_data);
568: }
569: // window_title.update(container.readAttribute('title'));
570: if (order_massaction_checkbox) {
571: window_checkbox.select('input').first().writeAttribute('value', order_id);
572: window_checkbox.select('input').first().observe('change', function(event) {
573: if (order_massaction_checkbox) {
574: order_massaction_checkbox.setValue(event.originalTarget.getValue());
575: sales_order_grid_massactionJsObject.setCheckbox(order_massaction_checkbox);
576: }
577: });
578: }
579:
580:
581: if (is_order_selected) {
582: window_checkbox.select('input').first().writeAttribute('checked', 'checked');
583: } else {
584: }
585: if (options.caller) {
586: window_close.observe('click', function(event) {
587: if (Control.Modal.current) {
588: Control.Modal.current.close();
589: }
590: if (needs_reload) {
591: window.location.reload();
592: }
593: });
594: new Ajax.Request(action_url, {
595: method: 'post',
596: parameters: post_params,
597: evalJSON: 'force',
598: onSuccess: function(transport) {
599: var html = '';
600: if (transport.responseJSON) {
601: var html = '', json = transport.responseJSON, longClicks = {};
602: if (json.set_location) {
603: setLocation(json.set_location);
604: return;
605: }
606: if (json.success) {
607: html += json.customer_address_html;
608: html += json.header_html;
609: json.products.each(function(item) {
610: html += item.html;
611: });
612: html += json.footer_html;
613: window_contents.update(html);
614: window_title.update(json.title_html);
615: //add the click handlers....
616:
617:
618: EOT;
619: foreach ($longOnClicks as $key => $longOnClick) {
620: $js .= <<<EOT
621: longClicks[{$this->_encode($key)}] = function(event, caller, json) {
622: {$longOnClick};
623: };
624:
625: EOT;
626: }
627:
628:
629:
630:
631: $js .= <<<EOT
632:
633: window_contents.insert({before: '<span id="eabi_previous" class="eabi_arrow" title="' + {$this->_encode($adminHelper->__('Previous'))} + '" onclick="Podium.keydown(38);"></span><span id="eabi_next" class="eabi_arrow" title="' + {$this->_encode($adminHelper->__('Next'))}+ '" onclick="Podium.keydown(40);"></span>'});
634:
635: window_contents.select('.eabi_orderview_actionbutton').each(function(item) {
636: var item_id = item.readAttribute('id'), passed = true;
637: if (item_id) {
638: item.observe('click', function(event) {
639: EOT;
640:
641: 642: 643: 644: 645: 646: 647: 648: 649: 650: 651:
652:
653: $js .= <<<EOT
654:
655: if (longClicks[item_id.replace('eabi_', '')]) {
656: passed = longClicks[item_id.replace('eabi_', '')](event, options.caller, json);
657: }
658: if (passed !== false) {
659: handleButtonClick(item_id.replace('eabi_', ''), options.caller, passed);
660: }
661: event.stop();
662: });
663: }
664: });
665: if (json.needs_reload) {
666: needs_reload = true;
667: }
668:
669: } else {
670: window.location.reload();
671: }
672: } else {
673: window.location.reload();
674: }
675: }
676: });
677: }
678: if (options.hasOwnProperty('callerIndex')) {
679: document.observe('keydown', function(event) {
680: var keyCode = event.keyCode;
681: if (keyCode == 38 || keyCode == 37) {
682: if (options.callerIndex > 0) {
683: eabi_order_products[options.callerIndex - 1].click();
684: } else {
685: if (eabi_order_products.length && pageNum > 1) {
686: sales_order_gridJsObject.setPage(pageNum - 1, false);
687: clickLast = true;
688: }
689: }
690: return event.stop();
691: } else if (keyCode == 40 || keyCode == 39) {
692: if (options.callerIndex < (eabi_order_products.length - 1)) {
693: eabi_order_products[options.callerIndex + 1].click();
694: } else {
695: if (eabi_order_products && eabi_order_products.length >= pageLimit) {
696: sales_order_gridJsObject.setPage(pageNum + 1, true);
697: clickFirst = true;
698: }
699: }
700: return event.stop();
701: } else if (keyCode == 27) {
702: //esc key
703: Control.Modal.current.close(event);
704: if (needs_reload) {
705: window.location.reload();
706: }
707: return event.stop();
708: }
709: return event;
710: });
711: }
712: },
713: afterClose: function() {
714: if (options.caller) {
715: options.caller.removeClassName('disabled');
716: }
717: if (options.hasOwnProperty('callerIndex')) {
718: document.stopObserving('keydown');
719: $$('eabi_orderview_actionbutton').each(function(item) {
720: item.stopObserving('click');
721: });
722: window_close.stopObserving('click');
723: }
724: this.destroy();
725: }
726: }, options || {}));
727:
728: w.container.insert(window_header);
729: window_header.insert(window_title);
730: window_checkbox.update('<label><input type="checkbox" value="1" onchange=""/></label>');
731: window_header.insert(window_checkbox);
732: window_header.insert(window_close);
733: w.container.insert(window_contents);
734: return w;
735: };
736: $$('button.eabi-order-products').each(function(item, index) {
737: var order_id = item.readAttribute('id').split('_')[1];
738: item.observe('click', function(event) {
739: item.addClassName('disabled');
740: var event_arguments = { title: '', caller: item, callerIndex: index};
741: if (event.memo && event.memo.target) {
742: event_arguments.target = event.memo.target;
743: }
744: var style_window_one = style_window('', event_arguments);
745: style_window_one.open();
746: event.stop();
747: });
748: item.observe('eabi:click', function(event) {
749: item.addClassName('disabled');
750: var event_arguments = { title: '', caller: item, callerIndex: index};
751: if (event.memo && event.memo.target) {
752: event_arguments.target = event.memo.target;
753: }
754: if (event.memo && event.memo.extra_data) {
755: event_arguments.extra_data = event.memo.extra_data;
756: }
757: var style_window_one = style_window('', event_arguments);
758: style_window_one.open();
759: event.stop();
760: });
761: });
762: if (clickFirst) {
763: current_products = $$('button.eabi-order-products').toArray();
764: if (current_products && current_products[0]) {
765: current_products[0].click();
766: }
767: clickFirst = false;
768: }
769: if (clickLast) {
770: current_products = $$('button.eabi-order-products').toArray();
771: if (current_products && current_products.length) {
772: current_products[current_products.length - 1].click();
773: }
774: clickLast = false;
775: }
776:
777:
778: }; //end of eabiAdminToolsGrid
779:
780: var oldInitGridRows = false;
781: if (Control && Control.Modal) {
782: eabiAdmintoolsGrid();
783: oldInitGridRows = sales_order_gridJsObject.initGridRows;
784: }
785:
786: if (oldInitGridRows) {
787: sales_order_gridJsObject.initGridRows = function() {
788: $$('button.eabi-order-products').each(function(item) {
789: item.stopObserving('click');
790: item.stopObserving('eabi:click');
791: });
792: oldInitGridRows();
793: eabiAdmintoolsGrid();
794: };
795: } else if (Control && Control.Modal) {
796: var oldInitGridRows = varienGrid.prototype.reload;
797: varienGrid.prototype.reload = function(url) {
798: $$('button.eabi-order-products').each(function(item) {
799: item.stopObserving('click');
800: item.stopObserving('eabi:click');
801: });
802:
803: if (!this.reloadParams) {
804: this.reloadParams = {form_key: FORM_KEY};
805: }
806: else {
807: this.reloadParams.form_key = FORM_KEY;
808: }
809: url = url || this.url;
810: if(this.useAjax){
811: new Ajax.Request(url + ((url.match(new RegExp('\\\\?')) ? '&ajax=true' : '?ajax=true') ), {
812: loaderArea: this.containerId,
813: parameters: this.reloadParams || {},
814: evalScripts: true,
815: onFailure: this._processFailure.bind(this),
816: onComplete: this.initGrid.bind(this),
817: onSuccess: function(transport) {
818: try {
819: if (transport.responseText.isJSON()) {
820: var response = transport.responseText.evalJSON()
821: if (response.error) {
822: alert(response.message);
823: }
824: if(response.ajaxExpired && response.ajaxRedirect) {
825: setLocation(response.ajaxRedirect);
826: }
827: } else {
828: $(this.containerId).update(transport.responseText);
829: eabiAdmintoolsGrid();
830: }
831: }
832: catch (e) {
833: $(this.containerId).update(transport.responseText);
834: }
835: }.bind(this)
836: });
837: return;
838: }
839: else{
840: if(this.reloadParams){
841: \$H(this.reloadParams).each(function(pair){
842: url = this.addVarToUrl(pair.key, pair.value);
843: }.bind(this));
844: }
845: location.href = url;
846: }
847:
848:
849: };
850:
851: }
852:
853: //handle the clicks......
854: function handleButtonClick(call_action, caller_button, passed) {
855: //make ajax request
856: caller_button.fire('eabi:click', { target: call_action, extra_data: passed});
857: }
858:
859:
860:
861:
862: EOT;
863:
864:
865: return $js;
866: }
867:
868: private function __makeActionButton($title, $onclick = '', $cssClass = '', $id = '') {
869: $html = '';
870:
871:
872: $onclick = htmlspecialchars($onclick);
873:
874: $html .= <<<EOT
875: <button class="scalable eabi_orderview_actionbutton {$cssClass}" id="{$id}" type="button" onclick="{$onclick}"><span>{$title}</span></button>
876:
877: EOT;
878: return $html;
879: }
880:
881: protected function _encode($input) {
882: return json_encode($input);
883:
884: }
885:
886: 887: 888: 889:
890: protected function getEabi() {
891: return Mage::helper('eabi');
892: }
893:
894: }
895:
896: