Application Delivery Management
Application Modernization & Connectivity
CyberRes
IT Operations Management
<div>
<juice:UIControlGWT id='ResourceAssignmentsTable' fieldname='ResourceAssignmentsTable' controlType='ResourceAssignmentsTable' required='false' readOnly='false' suppressMetaDiv='false' />
</div>
function loadScript(url, callback)
{
// Adding the script tag to the head as suggested before
var body = document.getElementsByTagName('fieldset')[0];
var script = document.createElement('script');
//script.type = 'text/javascript';
script.src = url;
// Then bind the event to the callback function.
// There are several events for cross browser compatibility.
script.onreadystatechange = callback;
script.onload = callback;
// Fire the loading
console.log("prepending");
body.insertBefore(script, body.firstChild);
}
function callGTWHeaderOnInjectDone(){
try{
var body = document.getElementsByTagName('body')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.setAttribute("defer", "defer");
script.innerHTML="com_novell_srvprv_impl_gwt_header_header.onInjectionDone('com.novell.srvprv.impl.gwt.header.header')";
body.appendChild(script);
}
catch (e){
console.log("error on appending GWT headers");
}
}
function callGTWControlsOnInjectDone(){
try{
var body = $('div.detaildialog')[0];
var script2 = document.createElement('script');
script2.type = 'text/javascript';
script2.setAttribute("defer","defer");
script2.innerHTML="com_novell_srvprv_impl_gwt_gwtControls.onInjectionDone('com.novell.srvprv.impl.gwt.gwtControls')";
body.appendChild(script2);
}
catch(e){
console.log("error on appenging second script");
}
}
function setGWTControls(){
var myFieldSet = $("fieldset");
if (myFieldSet != undefined && (!loadedModule)){
loadScript("/IDM/com.novell.srvprv.impl.gwt.header.header/com.novell.srvprv.impl.gwt.header.header.nocache.js",console.log("gwt header loaded"));
loadScript("/IDM/com.novell.srvprv.impl.gwt.gwtControls/com.novell.srvprv.impl.gwt.gwtControls.nocache.js",console.log("gwt controls loaded"));
loadedModule = true;
}
var mycontrol = $("#AssignResourcAction");
if (mycontrol.attr('id') == 'AssignResourcAction'){
console.log("GWT ready");
stopTimer();
} else {
console.log("waiting for gwt to fill up controls...");
callGTWHeaderOnInjectDone();
callGTWControlsOnInjectDone();
if (typeof com_novell_srvprv_impl_gwt_header_header !== 'undefined') {
console.log("header: exist");
}
else { console.log("header: not exist");}
console.log("control: " com_novell_srvprv_impl_gwt_gwtControls);
}
}
function stopTimer(){
clearInterval(myTimer);
gwtready = true;
}
var loadedModule = false;
var myTimer = setInterval(setGWTControls,500);
// start the resource lookup specifying three parameters
// 1) the resource name, took from the text field
// 2) the fieldname of the caller, in our example the field is named “SelectResourceName”
// 3) optional: the picklist name where return the selected entitlement values
// return a boolean value -> true when the lookup starts, false if GWT is not yet available
// when a lookup starts, the arrays entValues and entDisplay are filled
var startedSearch = searchResource(field.getValue(),'SelectResourceName','Result');
//timer to wait for results
var aTimer = undefined;
//boolen to trace the state of gwt framework
var gwtready = false;
//entitlement values selected with the widget
var entValues = new Array();
//entitlement display values selected with the widget
var entDisplay = new Array();
function searchResource(resname, callingfield,bagfield){
var result = false;
// if the GWT framework was loaded by the other inline script
if (gwtready){
bagfield = bagfield || "";
//show the “Assign Resource” popupt
$("#AssignResourcAction").click();
//remove the assign button
$('#AssignRevokeDialog').find('.ua-Button').first().remove();
//move the dialog near the caller field
var Xpos = $('#_' callingfield).position().left;
var Ypos = $('#_' callingfield).position().top;
$('#AssignRevokeDialog').css({top: Xpos, left: Ypos});
//add the "ok" button to confirm the entitlment values selection
var btnstring = "";
$('#AssignRevokeDialog').find('.ua-Button').parent().prepend(btnstring);
//remove the “”initial request description” field from the user interface
$("#initialRequestDescription").closest("tr").remove();
//remove the menu left as leftover from any call done previously (fix for a widget bug)
$("ul.dijitMenu").remove();
//call the dialog to show directly the entitlement values
aTimer = setInterval(controlSearchDialog,20,resname);
result = true;
} else console.log("gwt not ready yet, try again in a while");
return result;
}
function controlSearchDialog(resname){
var id = $("div[id^='widget__Resource']").attr("widgetid");
console.log("div.dijit widgetid=" id);
var myWidget = dijit.byId(id);
//if we found the instantiated widget...
if (myWidget != undefined){
console.log("This is the resource we look for" resname);
clearInterval(aTimer);
//call a widget juice method _startSearch using the name written on the caller text field
myWidget._startSearch(resname);
aTimer = setInterval(confirmSearch,20);
}
}
//this method is able to autoselect the resource we looked up for and fire the entitlement values request
function confirmSearch(){
var idMenu = $("ul.dijitMenu").attr("widgetid");
if (idMenu != undefined){
clearInterval(aTimer);
//console.log("ul.dijitMenu widgetid=" idMenu);
var myWidget = dijit.byId(idMenu);
myWidget.highlightFirstOption();
var option = myWidget.getHighlightedOption();
myWidget._setValueAttr({ target: option }, true);
}
}
//the function designed to bring back the selected entitlement values to your PRD request form
function getEntValues(bagfield){
// empty the arrays containing values and display values
entValues = [];
entDisplay=[];
$('#entParamValueListBox option').each(function(name, val) { entValues.push(val.value); entDisplay.push(val.text); });
//close the dialog
console.log($('#AssignRevokeDialog').find('.ua-Button').text());
//jquery click does not work, so we do a domelement click
$('#AssignRevokeDialog').find('.ua-Button')[0].click();
//if the parameter bagfield is present, set the values on that field
if (bagfield != ""){
var bag=JUICE.UICtrlUtil.getControl(bagfield);
bag.setValues(entValues,entDisplay,false);
}
}
window.inv=function(invocation){
//this script replace the standard invocation.proceed() of an interceptor, so we can avoid to validate the required fields
var cU = JUICE.UICtrlUtil;
var evt=cU.prepareSubmit(evt);
var submitAction = SubmitAction1Click.prototype.constructor.toString();
submitAction = submitAction.split(",")[1].replace('"','');
submitAction = submitAction.replace('"','');
$('#uiform').attr("action", submitAction);
$('#uiform')[0].submit();
}
form.interceptAction( "SubmitAction", "around", window.inv)
window.inv=function(invocation){
var cU = JUICE.UICtrlUtil;
var evt=cU.prepareSubmit(evt);
$('#uiaction').attr("value","ApprovalAction1");
submitThenParent('JUICE.getControl(2)','" form.getValue("taskId") "','approve');
};
form.interceptAction( "ApprovalAction", "around", window.inv);