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: class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit
35: extends Mage_Adminhtml_Block_Widget_Form_Container
36: {
37: 38: 39:
40: public function __construct()
41: {
42: $this->_objectId = 'application_id';
43: $this->_controller = 'adminhtml_mobile';
44: $this->_blockGroup = 'xmlconnect';
45: parent::__construct();
46: if ((bool)!Mage::getSingleton('adminhtml/session')->getNewApplication()) {
47: $app = Mage::helper('xmlconnect')->getApplication();
48: $this->_updateButton('save', 'label', $this->__('Save'));
49: $this->_updateButton('save', 'onclick', 'if (editForm.submit()) {disableElements(\'save\')}');
50:
51: $this->_addButton('save_and_continue', array(
52: 'label' => $this->__('Save and Continue Edit'),
53: 'onclick' => 'saveAndContinueEdit()',
54: 'class' => 'save',
55: ), -5);
56:
57: if ($app->getId()) {
58: $this->_addButton('submit_application_button', array(
59: 'label' => $this->__('Save and Submit App'),
60: 'onclick' => 'saveAndSubmitApp()',
61: 'class' => 'save'
62: ), -10);
63: }
64:
65: $this->_formScripts[] = 'function saveAndContinueEdit() {'
66: .'if (editForm.submit($(\'edit_form\').action + \'back/edit/\')) {disableElements(\'save\')};}';
67: if ($app->getId()) {
68: $this->_formScripts[] = 'function saveAndSubmitApp() {'
69: .'if (editForm.submit($(\'edit_form\').action + \'submitapp/' . $app->getId() . '\')) {'
70: .'disableElements(\'save\')};}';
71: }
72: } else {
73: $this->removeButton('save');
74: $this->removeButton('delete');
75: }
76:
77: if (isset($app) && $app->getIsSubmitted()) {
78: $this->removeButton('delete');
79: }
80: $this->removeButton('reset');
81: }
82:
83: 84: 85: 86: 87: 88:
89: protected function _prepareLayout()
90: {
91: $this->getLayout()->getBlock('head')->addJs('jscolor/jscolor.js');
92: $this->getLayout()->getBlock('head')->addJs('scriptaculous/scriptaculous.js');
93:
94: if ((bool)!Mage::getSingleton('adminhtml/session')->getNewApplication()) {
95: $deviceType = Mage::helper('xmlconnect')->getDeviceType();
96: switch ($deviceType) {
97: case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPHONE:
98: $this->getLayout()->getBlock('head')->addItem('skin_css', 'xmlconnect/mobile-home.css');
99: $this->getLayout()->getBlock('head')->addItem('skin_css', 'xmlconnect/mobile-catalog.css');
100: break;
101: case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_IPAD:
102: $this->getLayout()->getBlock('head')->addItem('skin_css', 'xmlconnect/mobile-ipad-home.css');
103: $this->getLayout()->getBlock('head')->addItem('skin_css', 'xmlconnect/mobile-ipad-catalog.css');
104: break;
105: case Mage_XmlConnect_Helper_Data::DEVICE_TYPE_ANDROID:
106: $this->getLayout()->getBlock('head')->addItem('skin_css', 'xmlconnect/mobile-android.css');
107: break;
108: default:
109: Mage::throwException(
110: $this->__('Device doesn\'t recognized: "%s". Unable to load preview model.', $deviceType)
111: );
112: break;
113: }
114: }
115:
116: return parent::_prepareLayout();
117: }
118:
119: 120: 121: 122: 123:
124: public function ()
125: {
126: if ((bool)!Mage::getSingleton('adminhtml/session')->getNewApplication()) {
127: $app = Mage::helper('xmlconnect')->getApplication();
128: }
129:
130: if (isset($app) && $app->getId()) {
131: return $this->__('Edit App "%s"', $this->escapeHtml($app->getName()));
132: } else {
133: return $this->__('New App');
134: }
135: }
136: }
137: