Create Project HTML Snapshot Document

From C3 Wiki

Jump to: navigation, search

[edit] Summary

This CustomUtils method will create a document object of the Printer Version of the passed in project allowing you to add it to a document or set of documents on any entity you like, such as the project itself to be used as a snapshot.

Note: If you use "Hide/Show or any other Javascript in your views, you may need to get an updated version of EntityViewUtils.renderViewLayoutAsHtml from Click Commerce, one that doesn't strip out all the JavaScript.

CustomUtils.createProjectPrintableDoc a per type JScript

function createProjectPrintableDoc(project)
{
//The call to CustomUtils.CreateProjectPrintableDoc(this); is the function
//that actually generates the HTML based on the current read-only state of the smartform.
//a.      Note: this function will throw an exception if the smartform
//        branching criteria refers to an attribute that has been deleted from the project.
//b.      Note: if any uncaught exception occurs during snapshot generation, the entire 
//        activity + the invoking activity + the state transition will be rolled back.  

	//wom.log("CustomUtils.createProjectPrintableDoc: started");
	try {
           wom.putContext("_Project", project, true);
           // this is a Click Commerce provided view, so it should be the same for all installations... but who knows...
           var printProjectView = EntityView.getView("VIEW45DA56A0D8800");
 
           //We have to pre+post pend html to the document because 
           //it is stripped out by the renderViewLayoutAsHTML call
           var html = "<HTML XMLNS:webr><head>";
           html += "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">";
           html += "<title>"+ project.ID + " - " + project.name+"</title>";
           html += "<link rel=\"stylesheet\" type=\"text/css\" HREF=\"" + UrlUtils.fullUrlFromAssetUrl("/default.css") + "\">\n";
           html += "<link rel=\"stylesheet\" type=\"text/css\" HREF=\"" + UrlUtils.fullUrlFromAssetUrl("/custom.css") + "\">\n";
           html = html +
                "\n<STYLE>\n" +
                ".help { display: none; }\n"+
                ".sectionBreakAfterCell { page-break-after: always; }\n" +
                "</STYLE>\n";
           html += "\n<link rel=\"stylesheet\" type=\"text\/css\" HREF=\"" + UrlUtils.fullUrlFromAssetUrl("/print.css") + "\">\n";
           html += "</head><body class=\"htmlPage\">";
           html += EntityViewUtils.renderViewLayoutAsHtml(printProjectView, project, false);
           html += "</body></html>";
           var resource = wom.createTransientEntity("Resource");
           return resource.docContentFromString(html, "html");
	}
	catch (e) {
		wom.log("EXCEPTION CustomUtils.createProjectPrintableDoc: " + e.description);
		throw(e);
	}
}

Washington University in Saint Louis