PAT: "gm_Work Order gm_PATSrc"
LockedById: "locked_by_id",
var unlockDialogParameter = function (dialogTitle, dialogMessage, callback) {
params.title = dialogTitle;
params.message = dialogMessage;
btnUnlock: aras.getResource("", "common.unlock"),
btnCancel: aras.getResource("", "common.cancel")
params.callback = callback;
params.defaultButton = "btnCancel";
params.dialogHeight = 150;
params.dialogWidth = 450;
params.content = "groupChgsDialog.html";
var showLockItemDialog = function (dialogTitle, dialogMessage, callback) {
var unlockDlgParams = unlockDialogParameter(dialogTitle, dialogMessage, callback);
var win = aras.getMostTopWindowWithAras(window);
var dialog = (win.main || win).ArasModules.MaximazableDialog.show("iframe", unlockDlgParams);
dialog.promise.then(callback);
var unlockItem = function (id, type) {
var win = aras.uiFindWindowEx(id);
return win.document.frames["tearoff_menu"].onClickMenuItem("unlock");
var item = aras.unlockItem(id, type);
var promoteCallback = function (ecrId, newState, unlockLuckedItems, spinnerAsync) {
aras.browserHelper.toggleSpinner(document, true);
return setTimeout(function () {
promoteCallback(ecrId, newState, unlockLuckedItems, true);
var body = "<work_order_id>" + ecrId + "</work_order_id><new_state>" + newState + "</new_state>";
if (unlockLuckedItems === true) {
body = body + "<unlocked_locked_items>true</unlocked_locked_items>";
var result = aras.newIOMInnovator().applyMethod("gm_Promote PIC PAT", body);
if (result.getErrorCode() === "PICPATLockedByCurrentUser") {
var dialogTitle = "Item should be unlocked"
var dialogMessage = result.getErrorString() + " Would you like to unlock it now?";
showLockItemDialog(dialogTitle, dialogMessage, function (action) {
if (action === "btnUnlock" && unlockItem(ecrId, CONSTANTS.ItemTypeNames.ECR)) {
promoteCallback(ecrId, newState, true);
else if (action === "btnUnlock") {
top.aras.AlertError("Unable to unlock the items. Please contact the Adminstrator.");
top.aras.AlertError(result.getErrorString());
top.aras.AlertSuccess('Successfully toggled PAT Edit/Locked.');
aras.browserHelper.toggleSpinner(document, false);
var ecrId = currentECR.getID();
var lockedById = currentECR.getProperty(CONSTANTS.PropertyNames.LockedById, "");
var currentUserId = currentECR.getInnovator().getUserID();
if (currentECR && currentECR.getAttribute("isDirty") === "1") {
return top.aras.AlertError("ECR must be saved.");
var cachedPATs = currentECR.getRelationships(CONSTANTS.ItemTypeNames.PAT);
var patsCount = cachedPATs.getItemCount();
currentECR.fetchRelationships(CONSTANTS.ItemTypeNames.PAT);
cachedPATs = currentECR.getRelationships(CONSTANTS.ItemTypeNames.PAT);
patsCount = cachedPATs.getItemCount();
return top.aras.AlertError("There are no PAT rows.");
var currentState = cachedPATs.getItemByIndex(0).getProperty("state", "");
var newState = currentState.toLowerCase() === "edit" ? "Locked" : "Edit";
promoteCallback(ecrId, newState);
else if (lockedById !== "" && lockedById.toLowerCase() === currentUserId.toLowerCase()) {
var dialogTitle = "ECR should be unlocked";
var dialogMessage = "Cannot toggle PAT Edit/Locked state while the ECR is locked. Would you like to unlock it now?";
showLockItemDialog(dialogTitle, dialogMessage, function (action) {
if (action === "btnUnlock" && unlockItem(ecrId, CONSTANTS.ItemTypeNames.ECR)) {
currentECR.setProperty("locked_by_id", "");
promoteCallback(ecrId, newState);
else if (action === "btnUnlock") {
top.aras.AlertError("Unable to unlock the ECR. Please contact the Adminstrator.");
top.aras.AlertError("ECR " + currentECR.getProperty("keyed_name", "") + " is locked by '" + currentECR.getPropertyAttribute("locked_by_id", "keyed_name", "some other user") +
"'. Please ask the user to unlock the ECR before toggling PAT Edit/Locked.");
return top.aras.AlertError(exception);
function gm_ARAS_Tab_Utilities() {
var gmARASTabUtilitiesNS = gmARASTabUtilitiesNS || function () {
var allTabIdsBeforeUpdate = [];
var parentContext = parent;
var setParentContext = function (currentParentContext) {
if (currentParentContext) {
parentContext = currentParentContext;
var sortNumber = function (a, b) {
var compareIndex = function (a, b) {
return sortNumber(a.Index, b.Index);
var updateAllTabs = function (action) {
if (!parentContext || !parentContext.relationships ||
!parentContext.relationships.relTabbarReady ||
parentContext.relationships.relTabbar.GetTabOrder("|") === "") {
var tabbar = parentContext.relationships.relTabbar;
var allTabIds = tabbar.GetTabOrder("|").split("|");
if (allTabIdsBeforeUpdate.length === 0) {
allTabIdsBeforeUpdate = tabbar.GetTabOrder("|").split("|");
tabbar._hiddentabs.forEach(function (item, index) { item._hiddenIndex = allTabIdsBeforeUpdate.indexOf(item.tabID) });
var allHiddenTabs = tabbar._hiddentabs.map(function (t) { return { TabID: t.tabID, Index: t._hiddenIndex }; });
var sortedHiddenTabIds = allHiddenTabs.sort(compareIndex).map(function (t) { return t.TabID; });
for (var i = 0; i < sortedHiddenTabIds.length; i++) {
if (allTabIdsBeforeUpdate.indexOf(sortedHiddenTabIds[i]) !== -1) {
allTabIds.push(sortedHiddenTabIds[i]);
for (var i = 0; i < allTabIds.length; i++) {
switch (action.toLowerCase()) {
if (!tabHidden(allTabIds[i])) {
tabbar.SetTabVisible(allTabIds[i], false);
if (tabHidden(allTabIds[i])) {
tabbar.SetTabVisible(allTabIds[i], true);
tabbar.SetTabEnabled(allTabIds[i], false);
tabbar.SetTabEnabled(allTabIds[i], true);
var updateTab = function (tabName, action) {
if (!tabName || !action) {
if (!parentContext || !parentContext.relationships ||
!parentContext.relationships.relTabbarReady ||
parentContext.relationships.relTabbar.GetTabOrder("|") === "") {
updateTab(tabName, action);
var tabbar = parentContext.relationships.relTabbar;
var tabID = tabbar.GetTabId(tabName);
if (allTabIdsBeforeUpdate.length === 0) {
allTabIdsBeforeUpdate = tabbar.GetTabOrder("|").split("|");
if (!tabID && action === "show") {
var result = document.thisItem.getInnovator().applyAML("<AML><Item action='get' type='RelationshipType'><label>" + tabName + "</label></Item></AML>");
console.log("Cannot Access Tab");
switch (action.toLowerCase()) {
tabbar.SetTabVisible(tabID, false);
tabbar.SetTabVisible(tabID, true);
tabbar.SetTabEnabled(tabID, false);
tabbar.SetTabEnabled(tabID, true);
if (parentContext.relationships.iframesCollection[tabID]) {
parentContext.relationships.iframesCollection[tabID].contentWindow.doSearch();
var tabHidden = function (tabID) {
for (var i = 0; i < parentContext.relationships.relTabbar._hiddentabs.length; i++) {
if (parentContext.relationships.relTabbar._hiddentabs[i].tabID === tabID) {
var hideTab = function (tabName) {
var tabNames = tabName.split(",");
for (var i = 0; i < tabNames.length; i++) {
updateTab(tabNames[i], "hide");
var showTab = function (tabName) {
var tabNames = tabName.split(",");
for (var i = 0; i < tabNames.length; i++) {
updateTab(tabNames[i], "show");
var disableTab = function (tabName) {
var tabNames = tabName.split(",");
for (var i = 0; i < tabNames.length; i++) {
updateTab(tabNames[i], "disable");
var enableTab = function (tabName) {
var tabNames = tabName.split(",");
for (var i = 0; i < tabNames.length; i++) {
updateTab(tabNames[i], "enable");
var selectTab = function (tabName) {
updateTab(tabName, "select");
var reloadTab = function (tabName) {
updateTab(tabName, "reload");
var showAllTabs = function () {
var hideAllTabs = function () {
var enableAllTabs = function () {
var disableAllTabs = function () {
updateAllTabs("disable");
var getSelectedTabId = function () {
if (!parentContext.relationships ||
!parentContext.relationships.relTabbarReady) {
var tabbar = parentContext.relationships.relTabbar;
return tabbar.GetSelectedTab();
var getSelectedTabLabel = function () {
var selectedTabId = getSelectedTabId();
return parentContext.relationships.relTabbar.GetTabLabel(selectedTabId);
setParentContext: setParentContext,
showAllTabs: showAllTabs,
hideAllTabs: hideAllTabs,
enableAllTabs: enableAllTabs,
disableAllTabs: disableAllTabs,
getSelectedTabId: getSelectedTabId,
getSelectedTabLabel: getSelectedTabLabel
function end_of_method() {
function gm_Comments_Dialog() {
var gmArasContextUtilityNS = top[parent.thisItem.getID() + 'gmArasContextUtilityNS'];
var currentContext = gmArasContextUtilityNS.getParentContext(grid, parent);
if (!gmArasContextUtilityNS.isEditableLifecycleState(currentContext, relationshipID)) {
var getHeaderName = function(grid, propertyName) {
var columnIndex = grid.GetColumnIndex(propertyName + "_D");
headerName = grid.columns_Experimental.grid.layout.cells[columnIndex].name;
if (typeof (propertyName) !== "undefined" && typeof (gridApplet) !== "undefined" && typeof (relationshipID) !== "undefined" && typeof (colNumber) !== "undefined") {
var dialogTitle = getHeaderName(gridApplet, propertyName) || "Comments";
var args = [gridApplet, relationshipID, colNumber, propertyName, dialogTitle];
top.aras.evalMethod("gm_display_comment_dialog", parent.thisItem, args);
return top.aras.AlertError(exception);
function gm_Comments_Form_Utility() {
var gmCommentsDialogUtilityNS = gmCommentsDialogUtilityNS ||
DefaultPopup: "DefaultPopup",
DialogHtmlName: "ShowFormAsADialog.html",
CommentPropertyName: "CommentsPropertyName",
FormName: "gm_Comments_dialog"
var innovator = aras.newIOMInnovator();
var getForm = function () {
var form = innovator.newItem(CONSTANTS.ItemTypeNames.Form, CONSTANTS.Attributes.Get);
form.setAttribute(CONSTANTS.Attributes.Select, "id,width,height");
form.setProperty(CONSTANTS.PropertyNames.Name, CONSTANTS.FormName);
var createParam = function (dialogTitle) {
var currentItem = document.thisItem;
currentItem.setProperty(CONSTANTS.CommentPropertyName, propertyName);
dialogWidth: form.getProperty(CONSTANTS.PropertyNames.Width, "600"),
dialogHeight: form.getProperty(CONSTANTS.PropertyNames.Height, "600"),
content: 'ShowFormAsADialog.html',
var callback = function (result) {
handleItemChange(propertyName, result);
var show = function (dialogTitle) {
var params = createParam(dialogTitle);
var win = aras.getMostTopWindowWithAras(window);
var dialog = (win.main || win).ArasModules.MaximazableDialog.show("iframe", params);
dialog.promise.then(callback);
var showDialog = function (property, dialogTitle) {
dialogTitle = dialogTitle || "Comments";
var isEditable = function () {
var selectedRowId = parent.thisItem.getID();
var gmArasContextUtilityNS = top[parent.thisItem.getProperty(CONSTANTS.PropertyNames.SourceId) + 'gmArasContextUtilityNS'];
var ecrContext = gmArasContextUtilityNS.getParentContext(false, parent);
if (selectedRowId && !gmArasContextUtilityNS.isEditableLifecycleState(ecrContext, selectedRowId)) {
var showDialogUsingEvent = function (event) {
var property = event.srcElement.propNm;
if (event.path && event.path.length > 4 && event.path[4]) {
dialogTitle = event.path[4].innerText;
} else if (event.target &&
event.target.parentNode &&
event.target.parentNode.parentNode &&
event.target.parentNode.parentNode.parentNode &&
event.target.parentNode.parentNode.parentNode.parentNode) {
var parentTable = event.target.parentNode.parentNode.parentNode.parentNode;
var childNodes = parentTable.childNodes;
if (childNodes && childNodes.length > 1) {
dialogTitle = childNodes[1].innerText;
showDialog(property, dialogTitle);
var addFocusInListener = function (property) {
var control = gmUIUtilitiesNS.getControl(property);
control.addEventListener("focusin", showDialogUsingEvent, true);
showDialogUsingEvent: showDialogUsingEvent,
addFocusInListener: addFocusInListener
function end_of_method() {
function gm_Disable_Typing_in_Item_Prop() {
if (typeof (gridApplet) !== "undefined") {
relshipsGrid_showInputHelperDialog(relationshipID, gridApplet.GetColumnIndex(propertyName + "_D"));
if (srcElement && srcElement.nextElementSibling && !srcElement.disabled) {
srcElement.setAttribute("readonly", "readonly");
if (srcElement.nextElementSibling.attributes.onclick) {
srcElement.nextElementSibling.onclick();
function gm_display_comment_dialog() {
var relationshipID = inArgs[1];
var colNumber = inArgs[2];
var propertyName = inArgs[3];
var dialogTitle = inArgs.length > 4 ? inArgs[4] : "Comments";
var rel = ecr.getItemsByXPath("//Relationships/Item[@id='" + relationshipID + "']");
var changeAction = rel.getProperty("_change_action", "");
if (!changeAction && (rel.getType()==="Part Action Tab" || rel.getType() === "Pre-Prod Part Action Tab")) {
rel.setProperty("CommentsPropertyName", propertyName);
var win = top.aras.getMostTopWindowWithAras(window);
var torqNotesPropertyName ="_torque_notes";
var formName = "gm_Comments_dialog";
var formNd = top.aras.getItemByName('Form', formName);
var formWidth = top.aras.getItemProperty(formNd, 'width');
var formHeight = top.aras.getItemProperty(formNd, 'height');
formId: formNd.getAttribute('id'),
content:'ShowFormAsADialog.html',
var self = [inDom, inArgs];
(win.main || win).ArasModules.Dialog.show('iframe', param).promise.then(
callbackFunction(this, dialogResult);
var callbackFunction = function(obj, result){
var relationshipID = inArgs[1];
var colNumber = inArgs[2];
var propertyName = inArgs[3];
var rel = inDom.getItemsByXPath("//Item[@id='" + relationshipID + "']");
rel.setProperty(propertyName, result);
rel.setAttribute("isDirty", "1");
if ( rel.getAction() != "add" && rel.getAction() != "update" && rel.getAction() != "delete" )
g.cells(relationshipID, colNumber).setValue(result);
if(propertyName === torqNotesPropertyName)
var onCellValArgs = [propertyName,colNumber,rel.getId() ,ecr,rel,result, g];
top.aras.evalMethod("gm_PAT OnCellValueChange", rel, onCellValArgs);