Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a document library which has two custom types linked to it. From UI I have two buttons to add that items..

I have two simple "ribbon button" and I want to use that to create the new Item from Content Type 1 and Content Type 2...

What's the Command I must associate? Is it possile to create this by Javascript?

Another question... If I want to make some button visible ONLY in certain conditions (like I'm in folder XXX so I can create only Content Type XXX elements), how can I do?

EDIT: According with Ren Hoek's answer, I create this code:

<CustomAction
Id="AggiungiCliente"
RegistrationType="List"
RegistrationId="101"
Location="CommandUI.Ribbon">
<CommandUIExtension>
  <CommandUIDefinitions>
    <CommandUIDefinition
     Location="Ribbon.Documents.New.Controls._children">
      <Button
       Id="Ribbon.Documents.New.Controls.AggiungiCliente"
       Alt="Aggiungi Cliente Ribbon Button"
       Sequence="10"
       Image32by32="/_layouts/images/PeoplePermissions.png"
       Command="AggiungiClienteCMD"
       LabelText="Aggiungi Cliente"
       TemplateAlias="o2"/>
    </CommandUIDefinition>
  </CommandUIDefinitions>
  <CommandUIHandlers>
    <CommandUIHandler
     EnabledScript="true"
     Command="AggiungiClienteCMD"
     CommandAction="javascript:var PAGETYPE = { ItemDisplay: 4, ItemEdit: 6, ItemNew: 8 }; 
                    var baseListFormUrl = '/_layouts/listform.aspx?'; 
                    var FolderConTypeID = '0x01200016274670493a402ab037bb0597921f54'; 
                    function NewFolder() { 
                    alert('done');
                        openPopup( baseListFormUrl + 
                                   'ListId=' + escapeProperly(listid) + 
                                   '%26PageType=' + PAGETYPE.ItemNew + 
                                   '%26RoorFolder=' + escapeProperly(L_Menu_BaseUrl + '/' + folderpath) + 
                                   '%26ContentTypeId=' + FolderConTypeID  
                                   ); 
                    } 

                    function openPopup(popUpUrl) { 
                    alert('called');
                        var options = { 
                            url: popUpUrl, 
                            title: 'title', 
                            allowMaximize: false, 
                            showClose: true, 
                            width: 600, 
                            height: 500, 
                            dialogReturnValueCallback: refreshCallback 
                        } 
                    alert('invoking showModalDialog')
                        SP.UI.ModalDialog.showModalDialog(options); 
                    alert('invoked');
                    }  " />
  </CommandUIHandlers>
</CommandUIExtension>

The button appears, but no one of the "alert" is hitted. If I change my code and put only "javascript:alert("...")" it works...

Any suggestion?

Thank you very much!

share|improve this question
2  
Your CommandAction create a funtion NewFolder which calls openPopup, but nowhere is NewFolder called. Regarding hiding the button, you should never do that with ribbon buttons but use EnabledScript to enable/disable it –  Per Jakobsen May 28 '12 at 19:23

1 Answer 1

up vote 2 down vote accepted

best way is to call the Form for it. Here is an JS example for a Folder (call Newfolder() as Ribbon command) Maybe add a callback for refreshing:

var PAGETYPE = { ItemDisplay: 4, ItemEdit: 6, ItemNew: 8 };
var baseListFormUrl = "/_layouts/listform.aspx?";
var FolderConTypeID = "0x0120003128620337CAC849BF2F80A5409ED9C300660E3D59C0C720448BF2EC9937D387A6";
function NewFolder() {
    openPopup( baseListFormUrl +
               "ListId=" + escapeProperly(listid) +
               "&PageType=" + PAGETYPE.ItemNew +
               "&RoorFolder=" + escapeProperly(L_Menu_BaseUrl + "/" + folderpath) +
               "&ContentTypeId=" + FolderConTypeID 
               );
}

function openPopup(popUpUrl) {

    var options = {
        url: popUpUrl,
        title: 'title',
        allowMaximize: false,
        showClose: true,
        width: 600,
        height: 500,
        dialogReturnValueCallback: refreshCallback
    }
    SP.UI.ModalDialog.showModalDialog(options);
}
share|improve this answer
    
When I try to use this, it reveals me a missing ")"... It's right to put it in escapeProperly(L_Menu_BaseUrl + "/" + folderpath) ? The code doesn't work as expected.. –  Ziba Leah May 28 '12 at 8:16
    
added the missing ")". What is not working? –  Ren Hoek May 29 '12 at 5:23
1  
The key is the Enabled Script. Here you can Add a Js script file to to enable the Button.You have to Create a Button for every CT and a script checking which folder You are in return true for enabling,false for Disabling) The craete a Js file on the page which does an RefreshCommandUI() on every Document ready to reevaluate every Enabled Script –  Ren Hoek May 29 '12 at 5:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.