Snippets

Mythics SOW Approval Process - JavaScript Controls

Created by Jonathan Hult
<script type="text/javascript">
    /* <![CDATA[ */
    /* Utility function to retrieve a button element by its label */
    function getButtonElementByLabel(label) {
        var elems = parent.document.querySelectorAll('div[class~=bpm-tasklist-button]');

        for (var i = 0; i < elems.length; i++) {
            var mySpan = elems[i].querySelector('span');

            if (mySpan != null) {
                if (mySpan.textContent) {
                    if (mySpan.textContent === label) {
                        return elems[i];
                    }
                }
            }
        }

        // If we have reached this point, a button of the given label was not
        // found.
        return null;
    }

    /* Utility function to retrieve the span containing the "Reject" button */
    function getRejectButtonSpan() {
        var containingElem = getButtonElementByLabel('Reject');

        if (containingElem != null) {
            return containingElem.querySelector('span');
        } else {
            return null;
        }
    }

    /* Check that we are NOT in the Editing Mode of the Composer */
    var myLog = {};
    var isEditMode = (typeof Draggables === 'undefined') ? "NO" : "YES";
    if (isEditMode === "NO") {
        /* Hide the "Save" button */
        var saveButtonEl = getButtonElementByLabel('Save');

        if (saveButtonEl != null) {
            saveButtonEl.parentElement.removeChild(saveButtonEl);
        }

        /* Rename the "Reject" button to "Send Back to Sales Rep" */
        var rejectButtonSpan = getRejectButtonSpan();

        if (rejectButtonSpan != null) {
            rejectButtonSpan.textContent = 'Send Back to Sales Rep';
        }

        /* Hide the Conversations and Documents buttons by removing the div containing both of them */
        var documentsButtonImg = parent.document.querySelector('img[src*="DOCS-Enabled.png"]');

        if (documentsButtonImg != null) {
            var containingDiv = documentsButtonImg.parentElement.parentElement.parentElement.parentElement;
            containingDiv.parentElement.removeChild(containingDiv);
        }
    }
    /* ]]> */
</script>

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.