﻿$(document).ready(function() {
	$(".ms-rteCustom-MotGlossaire").bind("click", afficherDefinition);
});

function afficherDefinition(event) {
	var mot = $(this).text();

	// on remarque ici ViewFields dans viewFields, QueryOptions dans queryOptions, .. tsé, des fois que ce serait pas le même tag!
	var soapEnv =
		"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
			<soapenv:Body> \
				<GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
					<listName>Liste des Termes du glossaire du Portail de ITA</listName> \
					<viewFields> \
						<ViewFields> \
							<FieldRef Name='Definition' /> \
						</ViewFields> \
					</viewFields> \
					<rowLimit>1</rowLimit> \
					<queryOptions> \
						<QueryOptions> \
							<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns> \
						</QueryOptions> \
					</queryOptions> \
					<query> \
						<Query> \
							<Where> \
								<Eq> \
									<FieldRef Name='Mot' /> \
									<Value Type='Text'>" + mot + "</Value> \
								</Eq> \
							</Where> \
						</Query> \
					</query> \
				</GetListItems> \
			</soapenv:Body> \
		</soapenv:Envelope>";

	$.ajax({
		url: "/_vti_bin/lists.asmx",
		type: "POST",
		dataType: "xml",
		data: soapEnv,
		complete: afficherDefinition_Complete,
		contentType: "text/xml; charset=\"utf-8\""
	});
}

function afficherDefinition_Complete(xData, status) {
	$(xData.responseXML).find("z\\:row").each(
		function() {
			var definition = $(this).attr("ows_Definition");

			$("#dlgGlossaire").html(definition);

			// http://docs.jquery.com/UI/Dialog
			$("#dlgGlossaire").dialog({ modal: true, resizable: false });
		}
	);
}
