none
ECMAScript For Approval Center RRS feed

  • Question

  • Hi,

    I am adding a button in Approval Center Page. i want to show the GUID of the Selected Assignment inside a popup. somethis like the http://msdn.microsoft.com/en-us/library/office/ff535984(v=office.14).aspx#pj14_CustomizeProjectCenter_Testing instead of project center i want inside approval center.

    Following is my code, but unfortunately i am not able to fire the event on button click:

    /// <reference name="MicrosoftAjax.js"/>
    /// <reference path="~/_layouts/inc/pwa/library/Utility.debug.js"/>
    /// <reference path="~/_layouts/inc/pwa/library/WebMethodManager.debug.js"/>
    /// <reference path="~/_layouts/inc/pwa/library/shell.debug.js"/>
    /// <reference path="~/_layouts/inc/pwa/library/TimesheetSatellite.js"/>
    /// <reference path="~/_layouts/inc/pwa/library/StatusApprovalsSatellite.js"/>
    /// <reference path="~/_layouts/inc/pwa/library/RemoteTextConv.debug.js"/>
    /// <reference path="~/_layouts/inc/pwa/library/ProjectFramework.debug.js"/>
    /// <reference path="~/_layouts/inc/pwa/library/GridSatellite.debug.js"/>
    /// <reference path="~/_layouts/inc/pwa/library/projectserverscripts.debug.js"/>
    /// <reference path="~/_layouts/inc/pwa/library/pagepropertymgr.debug.js"/>
    /// <reference path="~/_layouts/SP.core.debug.js"/>
    /// <reference path="~/_layouts/JsGrid.debug.js"/>
    /// <reference path="~/_layouts/JsGrid.Gantt.debug.js"/>
    var pc;             // Contains the Project Center extension object.
    var toggleMode;     // Maintains state of the toggle button.
    _spBodyOnLoadFunctionNames.push("ApprovalCenterMain");
    function ApprovalCenterMain() {
        pc = new ApprovalCenterExtension();
        //toggleMode = false;
    }
    function ApprovalCenterExtension() {
        var _grid;          // Display surface (a view) of the JS Grid.
        var _satellite;     // Control wrapper for the JS Grid.
        // Prevent ECMAScript errors if PJ or the AddGridSatellite function are not defined.
        // If the page is from Project Server, the PJ namespace is defined.
        // If the Project page includes JS Grid, the AddGridSatelliteInitializationNotifier 
        // function is defined.
        if (window.PJ == null || PJ.AddGridSatelliteInitializationNotifier == null) {
            return;
        }
        // Use the PJ.AddGridSatelliteInitializationNotifier function to get an instance 
        // of the satellite.
        PJ.AddGridSatelliteInitializationNotifier
        (
            function (satellite) {
                if (PJ.ProjectCenterSatellite != null) {
                    /*** Satellite override: Project code should pass in "satellite" instead of "this". ***/
                    satellite = PJ._NotifySatelliteInitComplete.arguments[0];
                    _satellite = satellite;
                    /***End Satellite override***/
                    _grid = satellite.GetJsGridControlInstance();
                    _grid.AttachEvent(SP.JsGrid.EventType.OnRowFocusChanged, RowChanged);
                }
            }
        );
        this.DisplaySelectedRecords = function () {
            var selection = _grid.GetSelectedRecordKeys(false);
            var url = "~/_layouts/CustomizeApprovalCenter/SelectedItems.aspx?ProjUIDS=";
            for (var i = 0; i < selection.length; i++) {
                url += selection[i] + "|";
            }
            ShowSPDialog(url);
        }
        function ShowSPDialog(pageToLoad) {
            var options = {
                url: pageToLoad,
                title: 'GUIDs of Selected Tasks',
                showClose: true,
                width: 700,
                height: 250,
                allowMaximize: false,
                dialogReturnValueCallback: NotifyCallBack
            };
            SP.UI.ModalDialog.showModalDialog(options);
        }
        // Show a notification when the modal dialog box is closed.
        function NotifyCallBack(dialogResult, returnValue) {
            SP.UI.Notify.addNotification('Successfully showed selected project GUIDs.');
        }
        // Event handler for the OnRowFocusChanged event in the JS Grid.
        function RowChanged(eventArgs) {
            if (toggleMode) {
                var array = new Array(1);
                array[0] = eventArgs.newRecordKey;
                _satellite._tableCache.GetRecordsByKey(array, GridDataCallBack);
            }
        }
        // Callback function for the RowChanged event handler, which shows an alert dialog box 
        // with the project name.
        function GridDataCallBack(arrayofKeys, arrayofRecords, bSucceeded) {
            alert(arrayofRecords[0].properties["PROJ_NAME"].GetLocalized());
        }
    //    this.ToggleMode = function () {
    //        if (toggleMode) {
    //            toggleMode = false;
    //        }
    //        else {
    //            toggleMode = true;
    //        }
    //    }
    }


    Thanks, Parth

    Monday, January 28, 2013 8:13 AM

Answers

  • Override of the satellite is not required  for the approval center.

    following is the changes i made in the js.

     PJ.AddGridSatelliteInitializationNotifier
        (
            function (satellite) {
                if (PJ.StatusApprovalsSatellite != null) {
                    /*** Satellite override: Project code should pass in "sat" instead of "this" ***/
                    try {
                        satellite = PJ._NotifySatelliteInitComplete.arguments[0];
                        //_satellite = satellite;
                        /***End Satellite override***/
                        _grid = satellite.GetJsGridControlInstance();
                        _grid.AttachEvent(SP.JsGrid.EventType.OnRowFocusChanged, RowChanged);
                    }
                    catch (e)
                    { }
                }
            }
        );


    Thanks, Parth

    • Marked as answer by Parth Rawal Wednesday, January 30, 2013 7:23 AM
    Wednesday, January 30, 2013 7:23 AM

All replies

  • Parth,

    Since the sample code referenced is for a Project Center Extension, you will need to change the references to relate to the corresponding components of the Approval Center.

    For example, the reference to PJ.ProjectCenterSatellite should be changed to reference the JSGrid on the Approval Center page, which I think is PJ.StatusApprovalsSatellite. References to UIDs or field names need to focus on the fields used in the Approval Center grid.

    Jim P.

    Tuesday, January 29, 2013 8:58 AM
  • thanks a zillion can you please let me know if i can access AssN_UID or something like that to access the JSGrid. Pleaase. help with sample code if possible.

    Thanks again


    Thanks, Parth

    Tuesday, January 29, 2013 10:14 AM
  • Hi,

    Can you suggest from the below mentioned Elements File, that what is wrong with this.

    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <CustomAction Id="ApprovalCenterPage.AdditionalScript"
          Location="ScriptLink"
          ScriptSrc="CustomizeApprovalCenter/CustomizeApprovalCenter.js"/>
      <!--Add two buttons to the ribbon in the Project Center view. -->
      <CustomAction 
        Id="Ribbon.ContextualTabs.TaskUpdates.Home.Share.CustonRibbon" 
        Location="CommandUI.Ribbon" 
        Title="Add custom buttons to the approval Center">
        <CommandUIExtension>
          <CommandUIDefinitions>
            <CommandUIDefinition Location="Ribbon.ContextualTabs.TaskUpdates.Home.Share.Controls._children">
              <Button Id="Ribbon.ContextualTabs.TaskUpdates.Home.Share.ProjectCenterShowSelected"
                Sequence="40"
                Command="ProjectCenterShowSelected"
                LabelText="Show Selected Dcoument"
                Alt="Show Selected Documents"
                ToolTipTitle="Show Selected Documents"
                ToolTipDescription="Show the GUID and project name for the selected projects."
                Image16by16="/_layouts/images/CustomizeProjectCenter/LookupInfo_16x16.png"
                Image32by32="/_layouts/images/CustomizeProjectCenter/LookupInfo_32x32.png"
                TemplateAlias="o1" />
            </CommandUIDefinition>
            <CommandUIDefinition Location="Ribbon.ContextualTabs.TaskUpdates.Home.Share.Controls._children">
              <ToggleButton Id="Ribbon.ContextualTabs.TaskUpdates.Home.Share.ProjectCenterToggleRowMonitor"
                Sequence="50"
                Command="ProjectCenterToggleRowMonitor"
                LabelText="Toggle Row Events"
                Alt="Toggle Row Events"
                ToolTipTitle="Toggle Row Events"
                ToolTipDescription="Enable or disable monitoring of row change events."
                Image16by16="/_layouts/images/CustomizeProjectCenter/AddEventHandler_16x16.png"
                Image32by32="/_layouts/images/CustomizeProjectCenter/AddEventHandler_32x32.png"
                TemplateAlias="o1" />
            </CommandUIDefinition>
          </CommandUIDefinitions>
          <CommandUIHandlers>
            <CommandUIHandler
              Command="ProjectCenterShowSelected"
              CommandAction="javascript:window.pc.DisplaySelectedRecords();"
              EnabledScript="javascript: function AlwaysTrue(){return true;} AlwaysTrue();"/>
            <CommandUIHandler
              Command="ProjectCenterToggleRowMonitor"
              CommandAction="javascript:window.pc.ToggleMode();"
              EnabledScript="javascript: function AlwaysTrue(){return true;} AlwaysTrue();"/>
          </CommandUIHandlers>
        </CommandUIExtension>
      </CustomAction>
    </Elements>


    Thanks, Parth

    Tuesday, January 29, 2013 11:43 AM
  • Override of the satellite is not required  for the approval center.

    following is the changes i made in the js.

     PJ.AddGridSatelliteInitializationNotifier
        (
            function (satellite) {
                if (PJ.StatusApprovalsSatellite != null) {
                    /*** Satellite override: Project code should pass in "sat" instead of "this" ***/
                    try {
                        satellite = PJ._NotifySatelliteInitComplete.arguments[0];
                        //_satellite = satellite;
                        /***End Satellite override***/
                        _grid = satellite.GetJsGridControlInstance();
                        _grid.AttachEvent(SP.JsGrid.EventType.OnRowFocusChanged, RowChanged);
                    }
                    catch (e)
                    { }
                }
            }
        );


    Thanks, Parth

    • Marked as answer by Parth Rawal Wednesday, January 30, 2013 7:23 AM
    Wednesday, January 30, 2013 7:23 AM