0

I tried to mimic the functionality of sharepoint ribbon control Insert Link in my testwiki site. enter image description here

I have succesfully displayed the aspx that is currently being displayed by the 2 menu items of the original control (From sharepoint and From Address menu items)

Here is my element.xml:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction Id="Ribbon.Library.Actions.Scripts"
   Location ="ScriptLink" ScriptBlock="
      document.write('&lt;script type=&quot;text/javascript&quot; src=&quot;~site/JavascriptReferenceAssets/CustomJs.js&quot;&gt;&lt;/' + 'script&gt;');"
    Sequence="100" />


  <CustomAction   Id="Ribbon.EditingTools.CPInsert.Links.FlyoutAnchor"   Location="CommandUI.Ribbon"  Title="Link">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
        Location="Ribbon.EditingTools.CPInsert.Links.Controls._children">
          <FlyoutAnchor
          Id="Ribbon.EditingTools.CPInsert.Links.FlyoutAnchor"
          Sequence="20"
          LabelText="Link"
          Image32by32="/_layouts/15/1033/images/formatmap32x32.png"
          TemplateAlias="o1">
            <Menu Id="Ribbon.EditingTools.CPInsert.Links.FlyoutAnchor.Menu">

              <MenuSection Id="Ribbon.EditingTools.CPInsert.Links.FlyoutAnchor.Menu.MenuSection" Sequence="10" >
                <Controls Id="Ribbon.EditingTools.CPInsert.Links.FlyoutAnchor.Menu.MenuSection.Controls">
                  <Button
                  Id="Ribbon.EditingTools.CPInsert.Links.FlyoutAnchor.Menu.MenuSection.MyButton"
                  Sequence="0"
                  Command="SharepointCommand"
                  LabelText="From Sharepoint"
                  TemplateAlias="o1"/>
                </Controls>
              </MenuSection>

              <MenuSection Id="Ribbon.EditingTools.CPInsert.Links.FlyoutAnchor.Menu.MenuSection1" Sequence="20" >
                <Controls Id="Ribbon.EditingTools.CPInsert.FlyoutAnchor.Menu.MenuSection1.Controls">
                  <Button  Id="Ribbon.EditingTools.CPInsert.FlyoutAnchor.Menu.MenuSection1.EditNotification″"
                  Sequence="0" Command="AddressCommand" LabelText="From Address" TemplateAlias="o1" />
                </Controls>
              </MenuSection>


            </Menu>
          </FlyoutAnchor>
        </CommandUIDefinition>
          </CommandUIDefinitions>

      <CommandUIHandlers>
        <CommandUIHandler
         Command="SharepointCommand"
         CommandAction="javascript:FromSharepoint();"
       />


        <CommandUIHandler
        Command="AddressCommand"
        CommandAction="javascript:FromAddress();"
     />



      </CommandUIHandlers>

    </CommandUIExtension>
  </CustomAction>

</Elements>

And here is my CustomJs.js that is being accessed by my customAction:

function FromSharepoint() {

    var options = {
        url: '/_layouts/15/AssetPortalBrowser.aspx?&AssetUrl=/sites/TestWiki/&RootFolder=/sites/TestWiki/&MDWeb=dfab070b-6fbc-408f-bddf-b35193729675&AssetType=Link&IsDlg=1',
        tite: 'Select an Asset',
        allowMaximize: false,
        showClose: true,
        width: 1578,
        height: 741
    };

    SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
}


 function FromAddress() {  

     var options = {
         url: '/_layouts/15/RteDialog.aspx?UseDivDialog=true&LCID=1033&Dialog=CreateLink&IsDlg=1',
         tite: 'Select an Asset',
         allowMaximize: false,
         showClose: true,
         width: 430,
         height: 230
     };

     SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
 }

Both menu items of my new control is displaying the aspx just like what the original control does. BUT the ok button of that aspx is not working. It is supposed to get the text entered from the aspx. What am I missing here?

This is the aspx being displayed:

enter image description here

0

just add dialogReturnValueCallback as noted in msdn:

https://msdn.microsoft.com/en-us/library/office/ff410058%28v=office.14%29.aspx?f=255&MSPPError=-2147217396

function FromSharepoint() {

    var options = {
        url: '/_layouts/15/AssetPortalBrowser.aspx?&AssetUrl=/sites/TestWiki/&RootFolder=/sites/TestWiki/&MDWeb=dfab070b-6fbc-408f-bddf-b35193729675&AssetType=Link&IsDlg=1',
        tite: 'Select an Asset',
        allowMaximize: false,
        showClose: true,
        width: 1578,
        height: 741
    };

    options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);     
    SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
  }


 function FromAddress() {  

     var options = {
         url: '/_layouts/15/RteDialog.aspx?UseDivDialog=true&LCID=1033&Dialog=CreateLink&IsDlg=1',
         tite: 'Select an Asset',
         allowMaximize: false,
         showClose: true,
         width: 430,
         height: 230
     };
     options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);    
     SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
 }

   function CloseCallback(result, target) { 
        //get the click outcome from result
        if(result === SP.UI.DialogResult.OK) { 
            //do function to return data when ok button clicked
            //get data from target

        } 
        if(result === SP.UI.DialogResult.cancel) { 
           //do nothing if cancel clicked        
        } 
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy