<apex:pageblockTable value="{!myaccounts}" var="a">
<apex:column width="50%" >
<span id="spanid">
<apex:inputHidden value="{!a.id}" id="targetid"/>
</span><apex:page standardController="Case" extensions="CIAssignProjectController2" name="Assign Project">
<apex:includeScript value="/support/console/34.0/integration.js"/>
<script type="text/javascript">
function setBeforeUnloadEvent(flag) {
console.log('getting primary tab id');
sforce.console.getEnclosingPrimaryTabId(getPrimaryTabId);
console.log('getting current subtab id');
sforce.console.getEnclosingTabId(getSubtabId);
if(flag){
//First find the ID of the current tab to close it
console.log('refreshing');
refreshTabsAfterSave();
//setTimeout(function(){doCloseTab();},5000)
}
}
function refreshTabsAfterSave () {
console.log('getting link');
sforce.console.getTabLink(sforce.console.TabLink.PARENT_AND_CHILDREN, currentPrimaryTabId, refreshPrimaryTab);
}
var refreshPrimaryTab = function refreshPrimaryTab (res) {
console.log('tab link is: ', res);
sforce.console.openConsoleUrl(currentPrimaryTabId, res.tabLink, true, [], [], afterRefresh);
}
var currentSubTabId; // set on page load
var currentPrimaryTabId; // set on page load
var getPrimaryTabId = function getPrimaryTabId (result) {
console.log('primary tab id is: ', result.id);
currentPrimaryTabId = result.id;
}
var getSubtabId = function getSubtabId (result) {
console.log('sub tab id is: ', result.id);
currentSubTabId = result.id;
}
var afterRefresh = function afterRefresh (res) {
console.log('after refresh, get enclosing tab');
sforce.console.getEnclosingTabId(getEnclosingTab);
}
var getEnclosingTab = function getEnclosingTab (res) {
console.log('enclosing tab is: ', res.id);
sforce.console.closeTab(res.id);
}
function doCloseTab() {
sforce.console.getEnclosingTabId(closeSubtab);
}
var closeSubtab = function closeSubtab(result) {
var tabId = result.id;
sforce.console.closeTab(tabId);
};
</script>
<apex:form >
<apex:pageMessages />
<apex:pageBlock title="Work Assignment">
<apex:pageBlockSection Title="User Data" columns="1" >
<apex:pageBlockTable id="UserSkillsTable" value="{!MatchingUserSkills}" var="ms" rendered="{!IF(AND(NOT(ISBLANK(MatchingUserSkillsdata)),MatchingUserSkillsdata.size > 0), true, false)}" >
<!-- A number of columns goes here -->
<apex:column style="width:7%">
<apex:facet name="header">Assign Project</apex:facet>
<!-- This is where i Update the Owner of the Case field -->
<apex:commandLink status="loadingStatus" immediate="true" action="{!Assignrecord}" oncomplete="setBeforeUnloadEvent('{!
}');" value="Assign">
<apex:param name="Assignrowid" value="{!ms.MatchingUserId}"/>
</apex:commandLink>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
<apex:pageBlockButtons location="bottom">
<apex:commandButton status="loadingStatus" action="{!AutoAssignrecord}" value="Auto Assignment" oncomplete="setBeforeUnloadEvent('{!pageswitch}');" />
<apex:commandButton status="loadingStatus" onclick="doCloseTab();" value="Back" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
<apex:commandlink styleclass="mylink" onclick="opentab('{!$Component.targetid}','{!$Component.name}');return false">
<apex:outputField value="{!a.name}" id="name" />
</apex:commandLink>
</apex:column>
</apex:pageblockTable>
<apex:page standardController="Case">
<A HREF="#" onClick="testOpenPrimaryTab();return false">
Click here to open a new primary tab</A>
<apex:includeScript value="/support/console/45.0/integration.js"/>
<script type="text/javascript">
function testOpenPrimaryTab() {
//Open a new primary tab with the salesforce.com home page in it
sforce.console.openPrimaryTab(null, 'http://www.salesforce.com', false,
'salesforce', openSuccess, 'salesforceTab');
}
var openSuccess = function openSuccess(result) {
//Report whether opening the new tab was successful
if (result.success == true) {
alert('Primary tab successfully opened');
} else {
alert('Primary tab cannot be opened');
}
};
</script>
</apex:page>