Question

initCardPrintForms need refresh

Hi Community,

 

I need to hide the Invoice print option on some Order Status. I override initCardPrintForms but on the first opening of the order page it appears to show the Invoice, I still need to refresh the page before it actually disappear.

after refreshing the page

 

Here is my code on Order Page Module:

initCardPrintForms: function(callback, scope) {
	debugger;
	var reportsEsq = this.getModulePrintFormsESQ();
	this.initCardPrintFormsEsqFilters(reportsEsq);
	var cachePrefix = this.initCardPrintFormsEsqFilters === this.Terrasoft.emptyFn
	? this.printFormsCachePrefix : this.customPrintFormsCachePrefix;
	reportsEsq.clientESQCacheParameters = {cacheItemName: this.getESQCacheName(cachePrefix)};
	reportsEsq.getEntityCollection(function(result) {
		if (this.destroyed) {
			return;
		}
		if (result.success && !result.collection.isEmpty()) {
			var resultCollection = result.collection;
			var printFormsMenuCollection = resultCollection.filterByFn(function(item) {
				debugger;
				if(item.get("Id") === "a1eb7090-4a9b-e1e7-d005-06cafaa7572b"){//if invoice print report
					if(this.get("Status.Id") !== "5bb20cb5-dc1a-4a11-96a9-2d2f1119b756"){// if not shipment loaded
						return false;
					}
					else return item.get("ShowInCard") === true;
				}
				else return item.get("ShowInCard") === true;
 
			}, this);
			this.preparePrintFormsMenuCollection(printFormsMenuCollection);
			printFormsMenuCollection.each(function(item) {
				item.set("Click", {bindTo: "generateCardPrintForm"});
			}, this);
			var printMenuItems = this.preparePrintButtonCollection(this.moduleCardPrintFormsCollectionName);
			printMenuItems.loadAll(printFormsMenuCollection);
			this.set(this.moduleCardPrintFormsCollectionName, printMenuItems);
			this.getCardPrintButtonVisible();
		}
		Ext.callback(callback, scope || this);
	}, this);

 

Like 0

Like

4 comments

I have an article that shows a way to do this here https://customerfx.com/article/showing-or-hiding-printables-based-on-a-…

Optionally, you could use this other approach as well to prevent running the invoice printable when needed. https://customerfx.com/article/validating-a-record-before-a-printable-c…

Ryan

Ryan Farley,

Thank you for helpful links, I have used your approach. I found that this code only works when I refresh the page. Can you please advise how can we acheive this without refreshing the page?



My findings:

this.get(this.moduleCardPrintFormsCollectionName) returns undefined untill I refreshed the page and everything will start working smoothly.

Syed Ali Hassan Shah,

The reason why it works after refreshing the page is then it's using the edit page. When you open a record from a section list it's opening in a mode called Combined mode. In combined mode, the PRINT menu is actually part of the Section, not the edit page. So, for this to also work in combined mode, you must also add the code to the Section (so it works in combined mode) as well as the edit page (so it works when in edit mode).

Ryan

Ryan Farley,

 

I have tried the combined mode as well, but I still have to reload the page in order to make it work.

 

OrderSectionV2 Code

 define("OrderSectionV2", ["PrintReportUtilities"], 
	   function(PrintReportUtilities) {
	return {
		entitySchemaName: "Order",
		attributes: {
		},
		modules: /**SCHEMA_MODULES*/{}/**SCHEMA_MODULES*/,
		businessRules: /**SCHEMA_BUSINESS_RULES*/{}/**SCHEMA_BUSINESS_RULES*/,
		methods: {
			initQueryColumns: function(esq) {
				this.callParent(arguments);
 
				if (!esq.columns.contains("UsrDocumentRepositorySubtype")) {
					esq.addColumn("UsrDocumentRepositorySubtype");
				}
			},
			initCardPrintForms: function() {
				this.callParent(arguments);
				var printMenuItems = this.get(this.moduleCardPrintFormsCollectionName);
				if (Ext.isEmpty(printMenuItems)) return;
 
				printMenuItems.each(function(item) {
					item.set("Visible", {bindTo: "getPrintMenuItemVisible"});
				}, this);
			},
			// this is the function will determine if a printable is visible
			// it is called for each printable and will return true/false to show or hide
			getPrintMenuItemVisible: function(reportId) {
				var type = this.get("Status") || { displayValue: "" },
					printMenuItems = this.get(this.moduleCardPrintFormsCollectionName),
					item = printMenuItems.find(reportId);
				if (Ext.isEmpty(item)) return;
 
				switch (item.get("Caption")) {
					case "Order - Inprocess":
						return type.displayValue === "3. In progress";
					default:
						return type.displayValue != "3. In progress";
				}
			}
		}
	};
});

 

OrderPageV2 Code

define("OrderPageV2", ["PrintReportUtilities"], 
	   function(PrintReportUtilities) {
	return {
		entitySchemaName: "Order",
		attributes: {
		},
		modules: /**SCHEMA_MODULES*/{}/**SCHEMA_MODULES*/,
		businessRules: /**SCHEMA_BUSINESS_RULES*/{}/**SCHEMA_BUSINESS_RULES*/,
		methods: {
			initCardPrintForms: function() {
				this.callParent(arguments);
				var printMenuItems = this.get(this.moduleCardPrintFormsCollectionName);
				if (Ext.isEmpty(printMenuItems)) return;
 
				printMenuItems.each(function(item) {
					item.set("Visible", {bindTo: "getPrintMenuItemVisible"});
				}, this);
			},
			// this is the function will determine if a printable is visible
			// it is called for each printable and will return true/false to show or hide
			getPrintMenuItemVisible: function(reportId) {
				var type = this.get("Status") || { displayValue: "" },
					printMenuItems = this.get(this.moduleCardPrintFormsCollectionName),
					item = printMenuItems.find(reportId);
				if (Ext.isEmpty(item)) return;
 
				switch (item.get("Caption")) {
					case "Order - Inprocess":
						return type.displayValue === "3. In progress";
					default:
						return type.displayValue != "3. In progress";
				}
			}
		}
	};
});

 

Show all comments