cancel
Showing results for 
Search instead for 
Did you mean: 

Document Library toolbar button to run script

ddvorak
Champ in-the-making
Champ in-the-making
Hello,

We are running Community Edition 3.2r2 on tomcat6 server (Ubuntu 9.04). I have a script that runs correctly on the Alfresco side that builds a set of freemind map files. Following the tutorial at the following link, I have been able to add a button to the tool bar in the Document Library. I have not been able, however, to make the button do anything:
http://edlovesjava.blogspot.com/2008/10/surf-4-modifying-share-documentlibrary.html

What I would like to do is get the button to run the script, or, better yet…get the button to run the script from the Share side (including dynamically finding the site url and description currently being entered manually to the script). Here are the files I have modified for the button:
/etc/lib/tomcat6/webapps/share/components/documentlibrary/toolbar.css (added css for button images)
/etc/lib/tomcat6/webapps/share/components/documentlibrary/toolbar.js (added button to onReady method to initialize and instantiate the button)
/etc/lib/tomcat6/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/documentlibrary/toolbar.get.html.ftl (added button in div)
/etc/lib/tomcat6/webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/documentlibrary/toolbar.get.properties (added button label as msg)

Can someone help me figure it out from here? I can post modifications I made to files if needed. Thanks in advance…

Deb
3 REPLIES 3

zaizi
Champ in-the-making
Champ in-the-making
In /etc/lib/tomcat6/webapps/share/components/documentlibrary/toolbar.js you need to add javascript to do something when the button is clicked.

See other example buttons to get an idea of what you need to do. There are examples in the JavaScript files of calling back to Alfresco webscripts. Have a look at the code.

Ainga

ddvorak
Champ in-the-making
Champ in-the-making
In an attempt to get the button to do anything, I copied the code to create a new folder in the toolbar.js file. Here are the parts of the code that I changed:

      /**
       * Fired by YUI when parent element is available for scripting.
       * Component initialisation, including instantiation of YUI widgets and event listener binding.
       *
       * @method onReady
       */
      onReady: function DLTB_onReady()
      {
         // New Folder button: user needs "create" access
         this.widgets.newFolder = Alfresco.util.createYUIButton(this, "newFolder-button", this.onNewFolder,
         {
            disabled: true,
            value: "create"
         });
      
       // ADDED by DAD 2010_05_07
       // genMaps button: user needs "create" access
         this.widgets.genMaps = Alfresco.util.createYUIButton(this, "genMaps-button", this.onGenMaps,
         {
            disabled: true,
            value: "create"
         });
      
       //END OF ADD
        
         // File Upload button: user needs  "create" access
         this.widgets.fileUpload = Alfresco.util.createYUIButton(this, "fileUpload-button", this.onFileUpload,
         {
            disabled: true,
            value: "create"
         });


and:
       /**
       * Generate Maps button click handler
       *
       * @method onGenMaps
       * @param e {object} DomEvent
       * @param p_obj {object} Object passed back from addListener method
       */
      onGenMaps: function DLTB_onGenMaps(e, p_obj)
           {
         var actionUrl = Alfresco.constants.PROXY_URI + $combine("slingshot/doclib/action/folder/site", this.options.siteId, this.options.containerId, Alfresco.util.encodeURIPath(this.currentPath));

         var doSetupFormsValidation = function DLTB_oNF_doSetupFormsValidation(p_form)
         {
            // Validation
            p_form.addValidation(this.id + "-createFolder-name", Alfresco.forms.validation.mandatory, null, "blur");
            p_form.addValidation(this.id + "-createFolder-name", Alfresco.forms.validation.nodeName, null, "keyup");
            p_form.addValidation(this.id + "-createFolder-name", Alfresco.forms.validation.length,
            {
               max: 256,
               crop: true
            }, "keyup");
            p_form.addValidation(this.id + "-createFolder-title", Alfresco.forms.validation.length,
            {
               max: 256,
               crop: true
            }, "keyup");
            p_form.addValidation(this.id + "-createFolder-description", Alfresco.forms.validation.length,
            {
               max: 512,
               crop: true
            }, "keyup");
            p_form.setShowSubmitStateDynamically(true, false);
         };

         if (!this.modules.createFolder)
         {
            this.modules.createFolder = new Alfresco.module.SimpleDialog(this.id + "-createFolder").setOptions(
            {
               width: "30em",
               templateUrl: Alfresco.constants.URL_SERVICECONTEXT + "modules/documentlibrary/create-folder",
               actionUrl: actionUrl,
               doSetupFormsValidation:
               {
                  fn: doSetupFormsValidation,
                  scope: this
               },
               firstFocus: this.id + "-createFolder-name",
               onSuccess:
               {
                  fn: function DLTB_onNewFolder_callback(response)
                  {
                     var folder = response.json.results[0];
                     YAHOO.Bubbling.fire("folderCreated",
                     {
                        name: folder.name,
                        parentPath: folder.parentPath,
                        nodeRef: folder.nodeRef
                     });
                     Alfresco.util.PopupManager.displayMessage(
                     {
                        text: this.msg("message.new-folder.success", folder.name)
                     });
                  },
                  scope: this
               }
            });
         }
         else
         {
            this.modules.createFolder.setOptions(
            {
               actionUrl: actionUrl,
               clearForm: true
            });
         }
         this.modules.createFolder.show();
      },

      /**
       * File Upload button click handler

The button is generated on the page, and the images are loaded….I must be missing something either in above code or in another file.

Thanks in advance for any help.

rachana
Champ in-the-making
Champ in-the-making
I am also facing same problem.. Button is added in toolbar but its not working. Please help me.I already tried above tutorial.