Last active
September 11, 2020 06:17
-
-
Save JiBrok/28232b1fee05ef8c45490ea91444a5ef to your computer and use it in GitHub Desktop.
JiBrok, message field, JavaScript Example: update message on Service Desk Portal(create request) with bundled select from app "Extensions for Jira Service Desk"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(['jquery'], function($) { | |
var lastSelectedOption = null; | |
function setMessage(message){ | |
message.jibrokMessageKey = true //Require for Service Desk | |
AJS.$('#' + CF_ID_MESSAGE).text(JSON.stringify(message)).trigger('change')//Service Desk create request | |
} | |
//edit here -> | |
var CF_ID_MESSAGE = 'customfield_10200' | |
var bundledFieldId = 10201; | |
var bundledSelectFieldName = "example select"; | |
var optionName1 = "test option 1"; | |
var optionName2 = "test option 2"; | |
var optionName3 = "test option 3"; | |
var optionName4 = ""; | |
var defaultMessage = { | |
title: 'DEFAULT TITLE', | |
body: 'DEFAULT MESSAGE', | |
messageType: 'info' | |
}; | |
var messageForOption1 = { | |
title: 'first', | |
body: '<a>test option 1 </a>', | |
messageType: 'error' | |
}; | |
var messageForOption2 = { | |
title: '2', | |
body: 'test option 2', | |
messageType: 'success' | |
}; | |
var messageForOption3_4 = { | |
title: 'Simple title', | |
body: 'message', | |
messageType: 'warning' | |
}; | |
function updateMessage(){ | |
var selectedValue = getBundledSelectText() | |
if(selectedValue == lastSelectedOption){ | |
return; | |
} | |
if(optionName1 == selectedValue){ | |
setMessage(messageForOption1) | |
return | |
} else if(optionName2 == selectedValue){ | |
setMessage(messageForOption2) | |
return | |
} else if([optionName3, optionName4].indexOf(selectedValue) > -1){ | |
setMessage(messageForOption3_4) | |
return | |
} | |
setMessage(defaultMessage) | |
lastSelectedOption = selectedValue; | |
return | |
} | |
//edit here <- | |
if(JIBROK_MESSAGE_FIELD_CONTEXT == 'CREATE_SD'){ | |
function getBundledSelectField(){ | |
return AJS.$('#jsdbundled-' + bundledFieldId).find('label:contains(' + bundledSelectFieldName + ')').parent().find('select'); | |
} | |
function getBundledSelectText(){ | |
return getBundledSelectField().find('option:selected').text(); | |
} | |
setInterval(function(){ | |
updateMessage() | |
}, 1000) | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment