What do you use to minimize the js file?

Apr 1, 2011 at 2:33 PM

I tried using Packer and it didn't work right for me.  I've added the spFilterDropdown code to the 0.6.0 code and would like to have in minimized. 

Thank you,
dave

Coordinator
Apr 1, 2011 at 2:40 PM
Dave:

Check out this post:
http://sympmarc.com/2010/05/21/the-javascript-compressorrater/

M.
Apr 1, 2011 at 3:12 PM

Thank you Marc.  I appreciate the quick response. 

Coordinator
Apr 1, 2011 at 3:23 PM
Edited Apr 1, 2011 at 3:24 PM

Dave:

BTW, I'm interested in how that SPFilterDropdown code is working for you. I want to add it as a function for 0.6.1. Did you need to make any modifications or were you able to use the code from Alex here http://spservices.codeplex.com/workitem/5647 as is?

M.

Apr 1, 2011 at 3:39 PM

Hi Marc.  Yes, I did have to make a change.   I believe the only change I made was to the listName parameter in the GetList operation.  The orginal code has listNameFromUrl() and I changed that to opt.relationshipList.  Once you helped me with the DisplayName details, the function seems to work perfect.  Below is what I'm using.  Big thanks to Alex for posting the original code.

	$.fn.SPServices.SPFilterDropdowns = function(options) {
		var opt = $.extend({}, {
			relationshipWebURL: "",		// [Optional] The name of the Web (site) which contains the relationships list
			relationshipList: "",		// The name of the list which contains the parent/child relationships
			relationshipListChildColumn: "",	// The internal name of the child column in the relationship list
			relationshipListSortColumn: "",	// [Optional] If specified, sort the options in the dropdown by this column,
							// otherwise the options are sorted by relationshipListChildColumn
			childColumn: "",			// The display name of the child column in the form
			CAMLQuery: "",			// This CAML fragment will be applied to the relatedList
			promptText: "Choose {0}...",	// [Optional] Text to use as prompt. If included, {0} will be replaced with the value of childColumn
			completefunc: null,		// Function to call on completion of rendering the change.
			debug: false			// If true, show error messages; if false, run silent
		}, options);

		filterDropdown(opt);
	}; // End SPFilterDropdowns

	function filterDropdown(opt) {
		var choices = "";
		var childSelectSelected = null;
		//var parentSelectSelected = [];
		var master;
		var MultiLookupPickerdata;
		var newMultiLookupPickerdata;
		var childColumnRequired;

		// Find the child column's select (dropdown)
		var childSelect = new dropdownCtl(opt.childColumn);
		if(childSelect.Obj.html() == null && opt.debug) { errBox("SPServices.SPFilterDropdowns", "childColumn: " + opt.childColumn, "Column not found on page"); return; }

		// Get the current child column selection, if there is one
		switch(childSelect.Type) {
			case "S":
				childSelectSelected = childSelect.Obj.find("option:selected").val();
				break;
			case "C":
				childSelectSelected = childSelect.Obj.attr("value");
				break;
			case "M":
				MultiLookupPickerdata = childSelect.Obj.closest("span").find("input:[name$='MultiLookupPicker$data']");
				master = window[childSelect.Obj.closest("tr").find("button:[id$='AddButton']").attr("id").replace(/AddButton/,'MultiLookupPicker_m')];
				currentSelection = childSelect.Obj.closest("span").find("select:[Title='" + opt.childColumn + " selected values']");
				// Clear the master
				master.data = "";
				break;
			default:
				break;
		}

		// When the parent column's selected option changes, get the matching items from the relationship list
		// Get the list items which match the current selection
		var sortColumn = (opt.relationshipListSortColumn.length > 0) ? opt.relationshipListSortColumn : opt.relationshipListChildColumn;
		var camlQuery = "<Query><OrderBy><FieldRef Name='" + sortColumn + "'/></OrderBy><Where>";

		if(opt.CAMLQuery.length > 0) camlQuery += opt.CAMLQuery;
		camlQuery += "</Where></Query>";

		// Get information about the childColumn from the current list
		$().SPServices({
			operation: "GetList",
			async: false,
			listName: opt.relationshipList,
			completefunc: function(xData, Status) {
				$(xData.responseXML).find("Fields").each(function() {
					$(xData.responseXML).find("Field").each(function() {
						// Determine whether childColumn is Required
						if($(this).attr("DisplayName") == opt.childColumn) {
							childColumnRequired = ($(this).attr("Required") == "TRUE") ? true : false;
						}
					});
				});
			}
		});
	
	$().SPServices({
		operation: "GetListItems",
		// Force sync so that we have the right values for the child column onchange trigger
		async: false,
		webURL: opt.relationshipWebURL,
		listName: opt.relationshipList,
		// Filter based on the currently selected parent column's value
		CAMLQuery: camlQuery,
		// Only get the parent and child columns
		CAMLViewFields: "<ViewFields><FieldRef Name='" + opt.relationshipListChildColumn + "' /></ViewFields>",
		// Override the default view rowlimit and get all appropriate rows
		CAMLRowLimit: 0,
		completefunc: function(xData, Status) {
			$(xData.responseXML).find("faultcode").each(function() {
				alert("fault");
				if(opt.debug) errBox("SPServices.SPFilterDropdowns",
					"relationshipListChildColumn: " + opt.relationshipListChildColumn,
					"Not found in relationshipList " + opt.relationshipList + " - or CAML is incorrect");
				return;
			});
			// Add an explanatory prompt
			switch(childSelect.Type) {
				case "S":
					childSelect.Obj.attr({ length: 0 })
					// If the column is required or the promptText option is empty, don't add the "(None) option
					if(!childColumnRequired && opt.promptText.length > 0) childSelect.Obj.append("<option value='0'>" + opt.promptText.replace(/\{0\}/g, opt.childColumn) + "</option>");
					break;
				case "C":
					// If the column is required, don't add the "(None)" option
					choices = childColumnRequired ? "" : "(None)|0";
					childSelect.Obj.attr("value", "");
					break;
				case "M":
					childSelect.Obj.attr({ length: 0 });
					newMultiLookupPickerdata = "";
					break;
				default:
					break;
			}
			// Add an option for each child item
			$(xData.responseXML).find("[nodeName='z:row']").each(function() {
				// If relationshipListChildColumn is a Lookup column, then the ID should be for the Lookup value,
				// else the ID of the relationshipList item
				var thisOptionId = ($(this).attr("ows_" + opt.relationshipListChildColumn).indexOf(";#") > 0) ?
						$(this).attr("ows_" + opt.relationshipListChildColumn).split(";#")[0] :
						$(this).attr("ows_ID");
				// If the relationshipListChildColumn is a calculated column, then the value isn't preceded by the ID,
				// but by the datatype.  In this case, thisOptionId should be the ID of the relationshipList item.
				if(isNaN(thisOptionId)) thisOptionId = $(this).attr("ows_ID");
				
				// If relationshipListChildColumn is a Lookup column, then strip off the leading ID;# on the value
				var thisOptionValue = ($(this).attr("ows_" + opt.relationshipListChildColumn).indexOf(";#") > 0) ?
						$(this).attr("ows_" + opt.relationshipListChildColumn).split(";#")[1] :
						$(this).attr("ows_" + opt.relationshipListChildColumn);
				
				switch(childSelect.Type) {
					case "S":
						var selected = ($(this).attr("ows_ID") == childSelectSelected) ? " selected='selected'" : "";
						childSelect.Obj.append("<option" + selected + " value='" + thisOptionId + "'>" + thisOptionValue + "</option>");
						break;
					case "C":
						if (thisOptionValue == childSelectSelected) childSelect.Obj.attr("value", childSelectSelected);
						choices = choices + ((choices.length > 0) ? "|" : "") + thisOptionValue + "|" + thisOptionId;
						break;
					case "M":
						childSelect.Obj.append("<option value='" + thisOptionId + "'>" + thisOptionValue + "</option>");
						newMultiLookupPickerdata += thisOptionId + "|t" + thisOptionValue + "|t |t |t";
						break;
					default:
						break;
				}
			});

			switch(childSelect.Type) {
				case "S":
					childSelect.Obj.trigger("change");
					break;
				case "C":
					childSelect.Obj.attr("choices", choices);
					childSelect.Obj.trigger("propertychange");
					break;
				case "M":
					MultiLookupPickerdata.attr("value", newMultiLookupPickerdata);
					// Clear any prior selections that are no longer valid
					$(currentSelection).find("option").each(function() {
						var thisSelected = $(this);
						$(this).attr("selected", "selected");
						$(childSelect.Obj).find("option").each(function() {
							if($(this).html() == thisSelected.html()) thisSelected.attr("selected", "");
						});
					});
					GipRemoveSelectedItems(master);
					// Hide any options in the candidate list which are already selected
					$(childSelect.Obj).find("option").each(function() {
						var thisSelected = $(this);
						$(currentSelection).find("option").each(function() {
							if($(this).html() == thisSelected.html()) thisSelected.remove();
						});
					});
					GipAddSelectedItems(master);
					// Set master.data to the newly allowable values
					master.data = GipGetGroupData(newMultiLookupPickerdata);
					break;
				default:
					break;
				}
			}
		});
	
		// If present, call completefunc when all else is done
		if(opt.completefunc != null) opt.completefunc();
	} // End filterDropdown
Coordinator
Apr 1, 2011 at 4:19 PM

Awesome, thanks.

You should be able to get back onto the "production" code (whatever that means) with v0.6.1.

M.

Apr 1, 2011 at 4:41 PM

I'm looking forward to it.  Thanks for everything Marc.

Coordinator
Apr 1, 2011 at 8:55 PM

Make sure you add single quotes around z:row, like so:

    $(xData.responseXML).find("[nodeName='z:row']").each(function() {

If you use jQuery 1.5+, that's required.

M.

Coordinator
Apr 4, 2011 at 4:38 AM

Dave:

FYI: I've posted v0.6.1ALPHA2 with this function.

M.

Apr 4, 2011 at 11:17 AM

And it works great Marc.  Thank you for adding this functionality.  The only 2 things I see relate to the errBox messages. 

1. They show the original name SPFilterDropdowns and not SPFilterDropdown. 
2. The line (~1871) [notice the position of the final )] - I failed to mention this to you (sorry) in the changes I made.  The function name has already been changed in the below examples:
  errbox("SPServices.SPFilterDropdown", "relationshipListColumn: " + opt.relationshipListColumn, "Not found in relationshipList " + opt.relationshipList) + " - or CAML is incorrect"; 
be 
  errBox("SPServices.SPFilterDropdown", "relationshipListColumn: " + opt.relationshipListColumn, "Not found in relationshipList " + opt.relationshipList + " - or CAML is incorrect");

thanks again Marc.  I really appreciate the great work you do for us.

dave

Coordinator
Apr 4, 2011 at 11:20 AM

Dave:

Thanks for spotting that. I went with SPFilterDropdown without the "s" since we're only affecting one at a time. I did see your addition to the error message and thought it was a great additions.

Next step in this is to have SPCascadeDropdowns and SPFilterDropdown share some of this code.

M.