ListingActionHandler = Class.create(ActionHandler, { //---------------------------------- sendPartsResponses: [], //---------------------------------- // todo next (temp solution) options: {}, setOptions: function(options) { this.options = Object.extend(this.options,options); return this; }, //---------------------------------- startActions : function(title,url,selectedProductsParts) { MagentoMessageObj.clearAll(); $('listing_container_errors_summary').hide(); var self = this; new Ajax.Request( self.options.url.checkLockListing + 'id/' + self.gridHandler.listingId + '/' , { method:'get', onSuccess: function(transport) { if (transport.responseText == 'locked') { MagentoMessageObj.addError(self.options.text.listing_locked_message); } else { new Ajax.Request( self.options.url.lockListingNow + 'id/' + self.gridHandler.listingId + '/' , { method:'get', onSuccess: function(transport) { ListingProgressBarObj.reset(); ListingProgressBarObj.show(title); GridWrapperObj.lock(); $('loading-mask').setStyle({visibility: 'hidden'}); self.sendPartsOfProducts(selectedProductsParts,selectedProductsParts.length,url); } }); } } }); }, sendPartsOfProducts : function(parts,totalPartsCount,url) { var self = this; if (parts.length == totalPartsCount) { self.sendPartsResponses = new Array(); } if (parts.length == 0) { ListingProgressBarObj.setPercents(100,0); ListingProgressBarObj.setStatus(self.options.text.task_completed_message); new Ajax.Request( self.options.url.unlockListingNow + 'id/' + self.gridHandler.listingId + '/' , { method:'get', onSuccess: function(transport) { var combineResult = 'success'; for (var i=0;i 75) { temp = temp.substr(0, 75) + '...'; } partExecuteString += '"' + temp + '"'; } else { partExecuteString = part.length; break; } } } else { partExecuteString = part.length; } partExecuteString += ''; ListingProgressBarObj.setStatus(str_replace('%s', partExecuteString, self.options.text.sending_data_message)); new Ajax.Request( url + 'id/' + self.gridHandler.listingId, { method: 'post', parameters: { selected_products: partString }, onSuccess: function(transport) { if (!transport.responseText.isJSON()) { if (transport.responseText != '') { alert(transport.responseText); } ListingProgressBarObj.hide(); ListingProgressBarObj.reset(); GridWrapperObj.unlock(); $('loading-mask').setStyle({visibility: 'visible'}); self.sendPartsResponses = new Array(); self.gridHandler.unselectAllAndReload(); return; } var response = transport.responseText.evalJSON(true); if (response.error) { ListingProgressBarObj.hide(); ListingProgressBarObj.reset(); GridWrapperObj.unlock(); $('loading-mask').setStyle({visibility: 'visible'}); self.sendPartsResponses = new Array(); new Ajax.Request( self.options.url.unlockListingNow + 'id/' + self.gridHandler.listingId + '/', { method: 'get' }); alert(response.message); return; } self.sendPartsResponses[self.sendPartsResponses.length] = response; var percents = (100/totalPartsCount)*(totalPartsCount-parts.length); if (percents <= 0) { ListingProgressBarObj.setPercents(0,0); } else if (percents >= 100) { ListingProgressBarObj.setPercents(100,0); } else { ListingProgressBarObj.setPercents(percents,1); } setTimeout(function() { self.sendPartsOfProducts(parts,totalPartsCount,url); },500); } }); return; }, //---------------------------------- listAction: function() { var selectedProductsParts = this.gridHandler.getSelectedItemsParts(); if (selectedProductsParts.length == 0) { return; } this.startActions( this.options.text.listing_selected_items_message, this.options.url.runListProducts,selectedProductsParts ); }, relistAction: function() { var selectedProductsParts = this.gridHandler.getSelectedItemsParts(); if (selectedProductsParts.length == 0) { return; } this.startActions( this.options.text.relisting_selected_items_message, this.options.url.runRelistProducts,selectedProductsParts ); }, reviseAction: function() { var selectedProductsParts = this.gridHandler.getSelectedItemsParts(); if (selectedProductsParts.length == 0) { return; } this.startActions( this.options.text.revising_selected_items_message, this.options.url.runReviseProducts,selectedProductsParts ); }, stopAction: function() { var selectedProductsParts = this.gridHandler.getSelectedItemsParts(); if (selectedProductsParts.length == 0) { return; } this.startActions( this.options.text.stopping_selected_items_message, this.options.url.runStopProducts,selectedProductsParts ); }, stopAndRemoveAction: function() { var selectedProductsParts = this.gridHandler.getSelectedItemsParts(); if (selectedProductsParts.length == 0) { return; } this.startActions( this.options.text.stopping_and_removing_selected_items_message, this.options.url.runStopAndRemoveProducts,selectedProductsParts ); } //---------------------------------- });