SetConfiguration E GetConfiguration
SetConfiguration
e GetConfiguration
podem ser usados sem itens de dados ou widgets para preencher os campos de uma interface do usuário concluídas da ferramenta XML.
Essa abordagem requer duas funções:
janela. Alteryx. gui. SetConfiguration
: executa quando a janela de configuração da ferramenta é clicada para exibir a interface do usuário com todos os campos concluídos.janela. Alteryx. gui. GetConfiguration
: executa quando a janela de configuração da ferramenta fecha para transferir os dados de configuração da interface do usuário para o fluxo de trabalho.
Criar uma GUI de ferramenta
Definir Window. Alteryx. gui
igual a um objeto. Este objeto contém as funções SetConfiguration e GetConfiguration.
Janela. Alteryx.Gui = {}
Defina a função SetConfiguration e passe o XML de configuração atual como um parâmetro. Dentro da função, verifique a configuração XML e verifique se a configuração da ferramenta está confirmada.
Configuração: função (currentToolConfiguration) { se (currentToolConfiguration && currentToolConfiguration.IsFirstConfig === falso) { }
Dentro do colchete final da função SetConfiguration, chame:
Janela. Alteryx.JsEvent(JSON.stringify({Evento: 'SetConfiguration'}))
Essa chamada informa ao designer que a configuração é definida e pode começar a processar a função GetConfiguration.
Dentro da janela. Objeto alteryx. gui, chame a função GetConfiguration
, que não requer nenhum parâmetro. Separe as funções set e GetConfiguration com uma vírgula.
Janela. Alteryx.Gui = { SetConfiguration: função (currentToolConfiguration) { ... }, GetConfiguration: function () {... } }
Dentro da função GetConfiguration, chame o Window. Função alteryx. JSEvent
para passar um objeto de configuração de para designer.
Janela. Alteryx.JsEvent(JSON.stringify({ Evento: 'GetConfiguration', Configuração: { Configuração: { X: xVal, Y: yVal }, Anotação: 'X:' + xVal + '\nY:' + yVal }}}))
Exemplo executável
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Location tool</title>
</head>
<body>
<h1>Location:</h1>
<br />
<label>X:</label><input type="text" id="locationXValue" />
<br />
<label>Y:</label><input type="text" id="locationYValue" />
<script type="text/javascript">
window.Alteryx.Gui = {
SetConfiguration: function (currentToolConfiguration) {
// Grab the values from the incoming tool configuration, and set the UI
var xVal = currentToolConfiguration.Configuration.Configuration.X
var yVal = currentToolConfiguration.Configuration.Configuration.Y
document.getElementById('locationXValue').value = xVal
document.getElementById('locationYValue').value = yVal
// Notify the Alteryx Designer you are done handling SetConfiguration
// If you don’t do this, the GetConfiguration will not be called
window.Alteryx.JsEvent(JSON.stringify({Event: 'SetConfiguration'}))
},
GetConfiguration: function () {
var xVal = document.getElementById('locationXValue').value
var yVal = document.getElementById('locationYValue').value
// The Alteryx Designer has requested the tools configuration
// Provide the configuration to the Alteryx Designer with
// a call back through JsEvent like this:
window.Alteryx.JsEvent(JSON.stringify({
Event: 'GetConfiguration',
Configuration: {
Configuration: {
X: xVal,
Y: yVal
},
Annotation: 'X:' + xVal + '\nY:' + yVal
}
}))
}
}
</script>
</body>
</html>