00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_GoogleBase_Block_Adminhtml_Types_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
00036 {
00037 public function __construct()
00038 {
00039 parent::__construct();
00040 $this->_blockGroup = 'googlebase';
00041 $this->_controller = 'adminhtml_types';
00042 $this->_mode = 'edit';
00043 $model = Mage::registry('current_item_type');
00044 $this->_removeButton('reset');
00045 $this->_updateButton('save', 'label', $this->__('Save Mapping'));
00046 $this->_updateButton('save', 'id', 'save_button');
00047 $this->_updateButton('delete', 'label', $this->__('Delete Mapping'));
00048 if(!$model->getId()) {
00049 $this->_removeButton('delete');
00050 }
00051
00052 $this->_formInitScripts[] = '
00053 var itemType = function() {
00054 return {
00055 updateAttributes: function() {
00056 if ($("select_attribute_set").value != "" && $("select_itemtype").value != "" && itemType.confirmChanges())
00057 {
00058 var elements = [$("select_attribute_set"),$("select_itemtype"),$("select_target_country")].flatten();
00059 $(\'save_button\').disabled = true;
00060 new Ajax.Updater("attributes_details", "'.$this->getUrl('*/*/loadAttributes').'",
00061 {
00062 parameters:Form.serializeElements(elements),
00063 evalScripts:true,
00064 onComplete:function(){ $(\'save_button\').disabled = false; }
00065 }
00066 );
00067 }
00068 },
00069
00070 reloadItemTypes: function() {
00071 if ($("select_target_country").value != "" && itemType.confirmChanges())
00072 {
00073 var elements = [$("select_attribute_set"),$("select_itemtype"),$("select_target_country")].flatten();
00074 new Ajax.Updater("gbase_itemtype_select", "'.$this->getUrl('*/*/loadItemTypes').'",
00075 {
00076 parameters:Form.serializeElements(elements),
00077 evalScripts:true,
00078 onComplete:function(){
00079 $(\'save_button\').disabled = false;
00080 Event.observe($("select_itemtype"), \'change\', itemType.updateAttributes);
00081 }
00082 }
00083 );
00084
00085 new Ajax.Updater("attribute_set_select", "'.$this->getUrl('*/*/loadAttributeSets').'",
00086 {
00087 parameters:Form.serializeElements(elements),
00088 evalScripts:true,
00089 onComplete:function(){
00090 $(\'save_button\').disabled = false;
00091 Event.observe($("select_attribute_set"), \'change\', itemType.updateAttributes);
00092 }
00093 }
00094 );
00095 $("attributes_details").innerHTML = "' . $this->__('Please, select Attribute Set and Google Item Type to load attributes') . '";
00096 }
00097 },
00098
00099 confirmChanges: function() {
00100 var blocksCount = Element.select($("attributes_details"), "div[id^=gbase_attribute_]").length;
00101 if (blocksCount > 0 && confirm("'.$this->__('Current Mapping will be reloaded. Continue?').'") || blocksCount == 0)
00102 {
00103 return true;
00104 }
00105 return false;
00106 }
00107 }
00108 }();
00109
00110 Event.observe(window, \'load\', function(){
00111 if ($("select_attribute_set")) {
00112 Event.observe($("select_attribute_set"), \'change\', itemType.updateAttributes);
00113 }
00114 if ($("select_itemtype")) {
00115 Event.observe($("select_itemtype"), \'change\', itemType.updateAttributes);
00116 }
00117 if ($("select_target_country")) {
00118 Event.observe($("select_target_country"), \'change\', itemType.reloadItemTypes);
00119 }
00120 });
00121 ';
00122 }
00123
00124 public function getHeaderText()
00125 {
00126 if(!is_null(Mage::registry('current_item_type')->getId())) {
00127 return $this->__('Edit Item Type "%s"', $this->htmlEscape(Mage::registry('current_item_type')->getGbaseItemtype()));
00128 } else {
00129 return $this->__('New Item Type');
00130 }
00131 }
00132
00133 public function getHeaderCssClass() {
00134 return 'icon-head head-customer-groups';
00135 }
00136
00137 }