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: class Mage_GoogleBase_Block_Adminhtml_Types_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
36: {
37: public function __construct()
38: {
39: parent::__construct();
40: $this->_blockGroup = 'googlebase';
41: $this->_controller = 'adminhtml_types';
42: $this->_mode = 'edit';
43: $model = Mage::registry('current_item_type');
44: $this->_removeButton('reset');
45: $this->_updateButton('save', 'label', $this->__('Save Mapping'));
46: $this->_updateButton('save', 'id', 'save_button');
47: $this->_updateButton('delete', 'label', $this->__('Delete Mapping'));
48: if(!$model->getId()) {
49: $this->_removeButton('delete');
50: }
51:
52: $this->_formInitScripts[] = '
53: var itemType = function() {
54: return {
55: updateAttributes: function() {
56: if ($("select_attribute_set").value != "" && $("select_itemtype").value != "" && itemType.confirmChanges())
57: {
58: var elements = [$("select_attribute_set"),$("select_itemtype"),$("select_target_country")].flatten();
59: $(\'save_button\').disabled = true;
60: new Ajax.Updater("attributes_details", "'.$this->getUrl('*/*/loadAttributes').'",
61: {
62: parameters:Form.serializeElements(elements),
63: evalScripts:true,
64: onComplete:function(){ $(\'save_button\').disabled = false; }
65: }
66: );
67: }
68: },
69:
70: reloadItemTypes: function() {
71: if ($("select_target_country").value != "" && itemType.confirmChanges())
72: {
73: var elements = [$("select_attribute_set"),$("select_itemtype"),$("select_target_country")].flatten();
74: new Ajax.Updater("gbase_itemtype_select", "'.$this->getUrl('*/*/loadItemTypes').'",
75: {
76: parameters:Form.serializeElements(elements),
77: evalScripts:true,
78: onComplete:function(){
79: $(\'save_button\').disabled = false;
80: Event.observe($("select_itemtype"), \'change\', itemType.updateAttributes);
81: }
82: }
83: );
84:
85: new Ajax.Updater("attribute_set_select", "'.$this->getUrl('*/*/loadAttributeSets').'",
86: {
87: parameters:Form.serializeElements(elements),
88: evalScripts:true,
89: onComplete:function(){
90: $(\'save_button\').disabled = false;
91: Event.observe($("select_attribute_set"), \'change\', itemType.updateAttributes);
92: }
93: }
94: );
95: $("attributes_details").innerHTML = "' . $this->__('Please, select Attribute Set and Google Item Type to load attributes') . '";
96: }
97: },
98:
99: confirmChanges: function() {
100: var blocksCount = Element.select($("attributes_details"), "div[id^=gbase_attribute_]").length;
101: if (blocksCount > 0 && confirm("'.$this->__('Current Mapping will be reloaded. Continue?').'") || blocksCount == 0)
102: {
103: return true;
104: }
105: return false;
106: }
107: }
108: }();
109:
110: Event.observe(window, \'load\', function(){
111: if ($("select_attribute_set")) {
112: Event.observe($("select_attribute_set"), \'change\', itemType.updateAttributes);
113: }
114: if ($("select_itemtype")) {
115: Event.observe($("select_itemtype"), \'change\', itemType.updateAttributes);
116: }
117: if ($("select_target_country")) {
118: Event.observe($("select_target_country"), \'change\', itemType.reloadItemTypes);
119: }
120: });
121: ';
122: }
123:
124: public function ()
125: {
126: if(!is_null(Mage::registry('current_item_type')->getId())) {
127: return $this->__('Edit Item Type "%s"', $this->htmlEscape(Mage::registry('current_item_type')->getGbaseItemtype()));
128: } else {
129: return $this->__('New Item Type');
130: }
131: }
132:
133: public function () {
134: return 'icon-head head-customer-groups';
135: }
136:
137: }
138: