Mage_Adminhtml_Block_System_Convert_Profile_Run Class Reference

Inheritance diagram for Mage_Adminhtml_Block_System_Convert_Profile_Run:

Mage_Adminhtml_Block_Abstract Mage_Core_Block_Template Mage_Core_Block_Abstract Varien_Object

List of all members.

Public Member Functions

 getProfile ()

Protected Member Functions

 _toHtml ()


Detailed Description

Definition at line 34 of file Run.php.


Member Function Documentation

_toHtml (  )  [protected]

Render block HTML

Returns:
string

Reimplemented from Mage_Core_Block_Template.

Definition at line 41 of file Run.php.

00042     {
00043         $profile = $this->getProfile();
00044 
00045         echo '<html><head>';
00046         echo '<script type="text/javascript">var FORM_KEY = "'.Mage::getSingleton('core/session')->getFormKey().'";</script>';
00047 
00048         $headBlock = $this->getLayout()->createBlock('page/html_head');
00049         $headBlock->addJs('prototype/prototype.js');
00050         $headBlock->addJs('mage/adminhtml/loader.js');
00051         echo $headBlock->getCssJsHtml();
00052 
00053         echo '<style type="text/css">
00054     ul { list-style-type:none; padding:0; margin:0; }
00055     li { margin-left:0; border:1px solid #ccc; margin:2px; padding:2px 2px 2px 2px; font:normal 12px sans-serif; }
00056     img { margin-right:5px; }
00057     </style>
00058     <title>'.($profile->getId() ? $this->htmlEscape($profile->getName()) : $this->__('No profile')).'</title>
00059 </head><body>';
00060         echo '<ul>';
00061         echo '<li>';
00062         if ($profile->getId()) {
00063             echo '<img src="'.Mage::getDesign()->getSkinUrl('images/note_msg_icon.gif').'" class="v-middle" style="margin-right:5px"/>';
00064             echo $this->__("Starting profile execution, please wait...");
00065             echo '</li>';
00066             echo '<li style="background-color:#FFD;">';
00067             echo '<img src="'.Mage::getDesign()->getSkinUrl('images/fam_bullet_error.gif').'" class="v-middle" style="margin-right:5px"/>';
00068             echo $this->__("Warning: Please don't close window during importing/exporting data");
00069         } else {
00070             echo '<img src="'.Mage::getDesign()->getSkinUrl('images/error_msg_icon.gif').'" class="v-middle" style="margin-right:5px"/>';
00071             echo $this->__("No profile loaded...");
00072         }
00073         echo '</li>';
00074         echo '</ul>';
00075 
00076         if ($profile->getId()) {
00077 
00078             echo '<ul id="profileRows">';
00079 
00080             ob_implicit_flush();
00081             $profile->run();
00082             foreach ($profile->getExceptions() as $e) {
00083                 switch ($e->getLevel()) {
00084                     case Varien_Convert_Exception::FATAL:
00085                         $img = 'error_msg_icon.gif';
00086                         $liStyle = 'background-color:#FBB; ';
00087                         break;
00088                     case Varien_Convert_Exception::ERROR:
00089                         $img = 'error_msg_icon.gif';
00090                         $liStyle = 'background-color:#FDD; ';
00091                         break;
00092                     case Varien_Convert_Exception::WARNING:
00093                         $img = 'fam_bullet_error.gif';
00094                         $liStyle = 'background-color:#FFD; ';
00095                         break;
00096                     case Varien_Convert_Exception::NOTICE:
00097                         $img = 'fam_bullet_success.gif';
00098                         $liStyle = 'background-color:#DDF; ';
00099                         break;
00100                 }
00101                 echo '<li style="'.$liStyle.'">';
00102                 echo '<img src="'.Mage::getDesign()->getSkinUrl('images/'.$img).'" class="v-middle"/>';
00103                 echo $e->getMessage();
00104                 if ($e->getPosition()) {
00105                     echo " <small>(".$e->getPosition().")</small>";
00106                 }
00107                 echo "</li>";
00108             }
00109 
00110             echo '<li id="liFinished" style="display:none;">';
00111             echo '<img src="'.Mage::getDesign()->getSkinUrl('images/note_msg_icon.gif').'" class="v-middle" style="margin-right:5px"/>';
00112             echo $this->__("Finished profile execution.");
00113             echo '</li>';
00114 
00115 
00116             echo "</ul>";
00117 
00118 
00119             $showFinished = true;
00120             $batchModel = Mage::getSingleton('dataflow/batch');
00121             /* @var $batchModel Mage_Dataflow_Model_Batch */
00122             if ($batchModel->getId()) {
00123                 if ($batchModel->getAdapter()) {
00124                     $numberOfRecords = $profile->getData('gui_data/import/number_of_records');
00125                     $numberOfRecords = $numberOfRecords ? $numberOfRecords : 1;
00126 
00127                     $showFinished = false;
00128                     $batchImportModel = $batchModel->getBatchImportModel();
00129                     $importIds = $batchImportModel->getIdCollection();
00130                     $countItems = count($importIds);
00131 
00132                     $batchConfig = array(
00133                         'styles' => array(
00134                             'error' => array(
00135                                 'icon' => Mage::getDesign()->getSkinUrl('images/error_msg_icon.gif'),
00136                                 'bg'   => '#FDD'
00137                             ),
00138                             'message' => array(
00139                                 'icon' => Mage::getDesign()->getSkinUrl('images/fam_bullet_success.gif'),
00140                                 'bg'   => '#DDF'
00141                             ),
00142                             'loader'  => Mage::getDesign()->getSkinUrl('images/ajax-loader.gif')
00143                         ),
00144                         'template' => '<li style="#{style}" id="#{id}">'
00145                                     . '<img id="#{id}_img" src="#{image}" class="v-middle" style="margin-right:5px"/>'
00146                                     . '<span id="#{id}_status" class="text">#{text}</span>'
00147                                     . '</li>',
00148                         'text'     => $this->__('Processed <strong>%s%% %s/%d</strong> records', '#{percent}', '#{updated}', $countItems),
00149                         'successText'  => $this->__('Imported <strong>%s</strong> records', '#{updated}')
00150                     );
00151 echo '
00152 <script type="text/javascript">
00153 var countOfStartedProfiles = 0;
00154 var countOfUpdated = 0;
00155 var countOfError = 0;
00156 var importData = [];
00157 var totalRecords = ' . $countItems . ';
00158 var config= '.Zend_Json::encode($batchConfig).';
00159 </script>
00160 <script type="text/javascript">
00161 function addImportData(data) {
00162     importData.push(data);
00163 }
00164 
00165 function execImportData() {
00166     if (importData.length == 0) {
00167         $("updatedRows_img").src = config.styles.message.icon;
00168         $("updatedRows").style.backgroundColor = config.styles.message.bg;
00169         Element.insert($("liFinished"), {before: config.tpl.evaluate({
00170             style: "background-color:"+config.styles.message.bg,
00171             image: config.styles.message.icon,
00172             text: config.tplSccTxt.evaluate({updated:(countOfUpdated-countOfError)}),
00173             id: "updatedFinish"
00174         })});
00175         new Ajax.Request("' . $this->getUrl('*/*/batchFinish', array('id' => $batchModel->getId())) .'", {
00176             method: "post",
00177             parameters: {form_key: FORM_KEY},
00178             onComplete: function(transport) {
00179                 if (transport.responseText.isJSON()) {
00180                     var response = transport.responseText.evalJSON();
00181                     if (response.error) {
00182                         Element.insert($("liFinished"), {before: config.tpl.evaluate({
00183                             style: "background-color:"+config.styles.error.bg,
00184                             image: config.styles.error.icon,
00185                             text: response.error.escapeHTML(),
00186                             id: "error-finish"
00187                         })});
00188                     }
00189                 }
00190 
00191                 $(\'liFinished\').show();
00192             }
00193         });
00194     } else {
00195         sendImportData(importData.shift());
00196     }
00197 }
00198 
00199 function sendImportData(data) {
00200     if (!config.tpl) {
00201         config.tpl = new Template(config.template);
00202         config.tplTxt = new Template(config.text);
00203         config.tplSccTxt = new Template(config.successText);
00204     }
00205     if (!$("updatedRows")) {
00206         Element.insert($("liFinished"), {before: config.tpl.evaluate({
00207             style: "background-color: #FFD;",
00208             image: config.styles.loader,
00209             text: config.tplTxt.evaluate({updated:countOfUpdated, percent:getPercent()}),
00210             id: "updatedRows"
00211         })});
00212     }
00213     countOfStartedProfiles++;
00214     if (!data.form_key) {
00215         data.form_key = FORM_KEY;
00216     }
00217 
00218     new Ajax.Request("'.$this->getUrl('*/*/batchRun').'", {
00219       method: "post",
00220       parameters: data,
00221       onSuccess: function(transport) {
00222         countOfStartedProfiles --;
00223         countOfUpdated += data["rows[]"].length;
00224         if (transport.responseText.isJSON()) {
00225             addProfileRow(transport.responseText.evalJSON());
00226         } else {
00227             Element.insert($("updatedRows"), {before: config.tpl.evaluate({
00228                 style: "background-color:"+config.styles.error.bg,
00229                 image: config.styles.error.icon,
00230                 text: transport.responseText.escapeHTML(),
00231                 id: "error-" + countOfStartedProfiles
00232             })});
00233             countOfError += data["rows[]"].length;
00234         }
00235         execImportData();
00236       }
00237     });
00238 }
00239 
00240 function getPercent() {
00241     return Math.ceil((countOfUpdated/totalRecords)*1000)/10;
00242 }
00243 
00244 function addProfileRow(data) {
00245     if (data.errors.length > 0) {
00246         for (var i=0, length=data.errors.length; i<length; i++) {
00247             Element.insert($("updatedRows"), {before: config.tpl.evaluate({
00248                 style: "background-color:"+config.styles.error.bg,
00249                 image: config.styles.error.icon,
00250                 text: data.errors[i],
00251                 id: "id-" + (countOfUpdated + i + 1)
00252             })});
00253             countOfError ++;
00254         }
00255     }
00256     $("updatedRows_status").update(config.tplTxt.evaluate({updated:countOfUpdated, percent:getPercent()}));
00257 }
00258 </script>
00259 ';
00260 
00261 
00262                     $jsonIds = array_chunk($importIds, $numberOfRecords);
00263                     foreach ($jsonIds as $part => $ids) {
00264                         $data = array(
00265                             'batch_id'   => $batchModel->getId(),
00266                             'rows[]'     => $ids
00267                         );
00268                         echo '<script type="text/javascript">addImportData('.Zend_Json::encode($data).')</script>';
00269                     }
00270                     echo '<script type="text/javascript">execImportData()</script>';
00271                     //print $this->getUrl('*/*/batchFinish', array('id' => $batchModel->getId()));
00272                 }
00273                 else {
00274                     $batchModel->delete();
00275                 }
00276             }
00277 
00278             if ($showFinished) {
00279                 echo "<script type=\"text/javascript\">$('liFinished').show();</script>";
00280             }
00281         }
00282         /*
00283         echo '<li>';
00284         echo '<img src="'.Mage::getDesign()->getSkinUrl('images/note_msg_icon.gif').'" class="v-middle" style="margin-right:5px"/>';
00285         echo $this->__("Finished profile execution.");
00286         echo '</li>';
00287         echo "</ul>";
00288         */
00289         echo '</body></html>';
00290         exit;
00291     }

getProfile (  ) 

Definition at line 36 of file Run.php.

00037     {
00038         return Mage::registry('current_convert_profile');
00039     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:04 2009 for Magento by  doxygen 1.5.8