<?php
// +-------------------------------------------------+
// | 2002-2011 PMB Services / www.sigb.net pmb@sigb.net et contributeurs (voir www.sigb.net)
// +-------------------------------------------------+
// $Id: sticks_sheet.tpl.php,v 1.7 2025/10/06 14:29:29 dgoron Exp $

if (stristr($_SERVER['REQUEST_URI'], ".tpl.php")) die("no access");

global $base_path, $stick_sheet_stick_select_button, $stick_sheet_stick_select_button_script;

$stick_sheet_stick_select_button = '<input class="bouton" type="button" onclick="openSticksSheetDialog(\'!!source!!\', \'!!sticksSheetSelected!!\');" value="!!button_label!!">';

$stick_sheet_stick_select_button_script = '
		<script type="text/javascript">
			require(["apps/pmb/PMBDialog", "dijit/registry", "apps/sticks_sheet/sticks_sheet", "dojo/request/xhr"], function(Dialog, registry, sticksSheet, xhr){
				window.openSticksSheetDialog = function(source, sticksSheetSelected) {
					if(!registry.byId("sticks_sheets_stick_select_dialog")){
			        	var myDijit = new Dialog({title: "!!dialog_title!!", executeScripts:true, id:"sticks_sheets_stick_select_dialog"});
				        xhr("'.$base_path.'/ajax.php?module=ajax&categ=sticks_sheets&action=get_data", {
				        	handleAs: "json"
						}).then(function (data){
					        myDijit.set("content", "<div id=\"sticks_sheet_container\"></div>");
				        	new sticksSheet({id : "sticks_sheet_widget", data : data, source : source, sticksSheetSelected: sticksSheetSelected}, "sticks_sheet_container");
				        	myDijit.resize();
				        });
					}else{
						var myDijit = registry.byId("sticks_sheets_stick_select_dialog");
				        var sticksSheetWidget = registry.byId("sticks_sheet_widget");
				        sticksSheetWidget.setSource(source);
				        sticksSheetWidget.setSticksSheetSelected(sticksSheetSelected);
				        sticksSheetWidget.updateSticksSheet();
					}
					myDijit.show();
				}
			});
		</script>';