cancel
Showing results for 
Search instead for 
Did you mean: 

apply new dashlet to all user dashboards

ayubalfresco
Champ in-the-making
Champ in-the-making
Hi,

In Alfresco Enterpriese 4.2, I have created a custom dashlet and the only way to make it appear on the user dashboard is to manually customize dashboard.

When we do it manually I noticed that it executes customise-dashboard.post.json.js file. Is there a way to execute the same script using javascript extension tool and make the new dashboard to appear for all users ?

I have added my new dashlet to presets.xml however this gets executed when a new user is created.

Any clues please ?

Thank you
Ayub

3 REPLIES 3

sanket
Champ on-the-rise
Champ on-the-rise
You can either customize presets.xml or deploy your module extension file as mentioned in this forum link.

http://forums.alfresco.com/forum/developer-discussions/alfresco-share-development/how-change-default...

For module deployment, you can create your custom file (ex: alfresco-dashlet-extension.xml), put it under site-data\extensions and then deploy it using the following link.
http://localhost:8080/share/page/modules/deploy

Hope this helps.

ayubalfresco
Champ in-the-making
Champ in-the-making
I have deployed the module, however this change does not apply to existing users..only new users. Is there a script or alternate way I could use to update the preset for all existing users ?

Below is the code I have used to customize the My Documents dashlet, however I am seeing error in the logs  "A merge request was made as a root extension request. This is not allowed." Dashlet functions as normal without issues, only this error in the logs.

My Question is is there a way to replace the My Documents dashlet with my custom dashlet and apply it to all (old + new ) users ?




dashlet code


if (typeof MYCOMP == "undefined" || !MYCOMP)
{
    var MYCOMP = {};
    MYCOMP.dashlet = {};
}

(function()
{
    var $html = Alfresco.util.encodeHTML,
            $links = Alfresco.util.activateLinks,
            $userProfile = Alfresco.util.userProfileLink,
            $siteDashboard = Alfresco.util.siteDashboardLink,
            $relTime = Alfresco.util.relativeTime;


    MYCOMP.dashlet.MyDocuments = function(htmlId)
    {
        return MYCOMP.dashlet.MyDocuments.superclass.constructor.call(this, htmlId);
    };

    YAHOO.extend(MYCOMP.dashlet.MyDocuments, Alfresco.component.SimpleDocList,
          {
                PREFERENCES_MYDOCUMENTS_DASHLET_FILTER: "",
                PREFERENCES_MYDOCUMENTS_DASHLET_VIEW: "",
                /**
                 * Fired by YUI when parent element is available for scripting
                 * @method onReady
                 */
                onReady: function MyDocuments_onReady()
                {
                   /**
                    * Preferences
                    */
                   var PREFERENCES_MYDOCUMENTS_DASHLET = this.services.preferences.getDashletId(this, "mydocuments");
                      this.PREFERENCES_MYDOCUMENTS_DASHLET_FILTER = PREFERENCES_MYDOCUMENTS_DASHLET + ".filter";
                      this.PREFERENCES_MYDOCUMENTS_DASHLET_VIEW = PREFERENCES_MYDOCUMENTS_DASHLET + ".simpleView";

                   // Create Dropdown filter
                   this.widgets.filter = Alfresco.util.createYUIButton(this, "filters", this.onFilterChange,
                   {
                      type: "menu",
                      menu: "filters-menu",
                      lazyloadmenu: false
                   });

                   // Select the preferred filter in the ui
                   var filter = this.options.filter;
                   filter = Alfresco.util.arrayContains(this.options.validFilters, filter) ? filter : this.options.validFilters[0];
                   this.widgets.filter.set("label", this.msg("filter." + filter));
                   this.widgets.filter.value = filter;

                   // Detailed/Simple List button
                   this.widgets.simpleDetailed = new YAHOO.widget.ButtonGroup(this.id + "-simpleDetailed");
                   if (this.widgets.simpleDetailed !== null)
                   {
                      this.widgets.simpleDetailed.check(this.options.simpleView ? 0 : 1);
                      this.widgets.simpleDetailed.on("checkedButtonChange", this.onSimpleDetailed, this.widgets.simpleDetailed, this);
                   }

                   // Display the toolbar now that we have selected the filter
                   Dom.removeClass(Selector.query(".toolbar div", this.id, true), "hidden");

                   // DataTable can now be rendered
                   Alfresco.dashlet.MyDocuments.superclass.onReady.apply(this, arguments);
                },
               
                /**
                 * Generate base webscript url.
                 * Can be overridden.
                 *
                 * @method getWebscriptUrl
                 */
                getWebscriptUrl: function SimpleDocList_getWebscriptUrl()
                {
                   return Alfresco.constants.PROXY_URI + "slingshot/doclib/doclist/documents/node/alfresco/company/home?max=50";
                },

                /**
                 * Calculate webscript parameters
                 *
                 * @method getParameters
                 * @override
                 */
                getParameters: function MyDocuments_getParameters()
                {
                   return "filter=" + this.widgets.filter.value;
                },

                /**
                 * Filter Change menu handler
                 *
                 * @method onFilterChange
                 * @param p_sType {string} The event
                 * @param p_aArgs {array}
                 */
                onFilterChange: function MyDocuments_onFilterChange(p_sType, p_aArgs)
                {
                   var menuItem = p_aArgs[1];
                   if (menuItem)
                   {
                      this.widgets.filter.set("label", menuItem.cfg.getProperty("text"));
                      this.widgets.filter.value = menuItem.value;

                      this.services.preferences.set(this.PREFERENCES_MYDOCUMENTS_DASHLET_FILTER, this.widgets.filter.value);

                      this.reloadDataTable();
                   }
                },

                /**
                 * Show/Hide detailed list buttongroup click handler
                 *
                 * @method onSimpleDetailed
                 * @param e {object} DomEvent
                 * @param p_obj {object} Object passed back from addListener method
                 */
                onSimpleDetailed: function MyDocuments_onSimpleDetailed(e, p_obj)
                {
                   this.options.simpleView = e.newValue.index === 0;
                   this.services.preferences.set(this.PREFERENCES_MYDOCUMENTS_DASHLET_VIEW, this.options.simpleView);
                   if (e)
                   {
                     
                      //Event.preventDefault(e);
                     
                   }

                   this.reloadDataTable();
                },
               
                /**
                 * Handler to set/reset favourite for document or folder
                 *
                 * @method onFavourite
                 * @private
                 * @param row {HTMLElement} DOM reference to a TR element (or child thereof)
                 * @param prefKey {String} The preferences key
                 */
                onFavourite: function SimpleDocList_onFavourite(row)
                {
                   var record = this.widgets.alfrescoDataTable.getRecord(row),
                      file = record.getData(),
                      nodeRef = file.nodeRef;

                   file.isFavourite = !file.isFavourite;
                   this.widgets.alfrescoDataTable.getDataTable().updateRow(record, file);

                   var responseConfig =
                   {
                      failureCallback:
                      {
                         fn: function SimpleDocList_onFavourite_failure(event, p_oRow)
                         {
                            // Reset the flag to it's previous state
                            var record = this.widgets.alfrescoDataTable.getRecord(p_oRow),
                               file = record.getData();

                            file.isFavourite = !file.isFavourite;
                            this.widgets.alfrescoDataTable.getDataTable().updateRow(record, file);
                            Alfresco.util.PopupManager.displayPrompt(
                            {
                               text: this.msg("message.save.failure", file.displayName)
                            });
                         },
                         scope: this,
                         obj: row
                      }
                   };

                   if(file.isFolder){
                     
                      this.services.preferences[file.isFavourite ? "add" : "remove"].call(this.services.preferences, Alfresco.service.Preferences.FAVOURITE_FOLDERS, nodeRef, responseConfig);
                     
                   }else{
                     
                      this.services.preferences[file.isFavourite ? "add" : "remove"].call(this.services.preferences, Alfresco.service.Preferences.FAVOURITE_DOCUMENTS, nodeRef, responseConfig);
                     
                   }
                  
                }
               
             });
   
// This is the method that renders the thumbnail (i.e. icon)
    Alfresco.component.SimpleDocList.prototype.renderCellThumbnail = function SimpleFolderList_renderCellThumbnail(elCell, oRecord, oColumn, oData) {
       
            var columnWidth = 40,
                record = oRecord.getData(),
                desc = "";

            if (record.isInfo)
            {
               columnWidth = 52;
               desc = '<img src="' + Alfresco.constants.URL_RESCONTEXT + 'components/images/help-docs-bw-32.png" />';
            }
            else
            {
               var name = record.fileName,
                  extn = name.substring(name.lastIndexOf(".")),
                  locn = record.location,
                  nodeRef = new Alfresco.util.NodeRef(record.nodeRef),
                  path=locn.path,
                  folderPath="";
              
               if(path.length>1){
                  
                    folderPath=path.replace(/\//g,"%2F")
              
               }
             
                  folderDetailsUrl = Alfresco.constants.URL_PAGECONTEXT + (locn.site ? "site/" + locn.site + '/' : "") + "documentlibrary#filter=path%7C%2F" +folderPath+"%2F"+name;
                  docDetailsUrl = Alfresco.constants.URL_PAGECONTEXT + (locn.site ? "site/" + locn.site + '/' : "") + "document-details?nodeRef=" + nodeRef.toString();
              
              if (this.options.simpleView)
               {
                  /**
                   * Simple View
                   * Here is where the icon is rendered change it for the right icon
                   */
                 
                  if(record.isFolder){
                    
                
                     var id = this.id + oRecord.getId();
                       desc = '<span id="' + id + '" class="icon32"><a href="' + folderDetailsUrl + '"><img src="' + Alfresco.constants.URL_RESCONTEXT + 'components/documentlibrary/images/folder-32.png' + '" alt="' + extn + '" title="' + $html(name) + '" /></a></span>';

                     }else{
                    
                   
                     var id = this.id + '-preview-' + oRecord.getId();
                      desc = '<span id="' + id + '" class="icon32"><a href="' + docDetailsUrl + '"><img src="' + Alfresco.constants.URL_RESCONTEXT + 'components/images/filetypes/' + Alfresco.util.getFileIcon(name) + '" alt="' + extn + '" title="' + $html(name) + '" /></a></span>';
                      // Preview tooltip
                      this.previewTooltips.push(id);
                  }
                 
               }else{
                 
                   /**
                    * Detailed View
                    */
                   columnWidth = 100;
                   var url = Alfresco.constants.PROXY_URI + "api/node/" + nodeRef.uri + "/content/thumbnails/doclib?c=queue&ph=true";
                   if (record.lastThumbnailModification)
                   {
                      url = url + "&lastModified=" + record.lastThumbnailModification;
                   }
                  
                   if(record.isFolder){
                     
                      docDetailsUrl=folderDetailsUrl;
                      url=Alfresco.constants.URL_RESCONTEXT + 'components/documentlibrary/images/folder-64.png';
                   }
                  
                   desc = '<span class="thumbnail"><a href="' + docDetailsUrl + '"><img src="' + url + '" alt="' + extn + '" title="' + $html(name) + '" /></a></span>';
                }
              
            }

            oColumn.width = columnWidth;

            Dom.setStyle(elCell, "width", oColumn.width + "px");
            Dom.setStyle(elCell.parentNode, "width", oColumn.width + "px");

            elCell.innerHTML = desc;
         };
     
//Override method prototype
      Alfresco.component.SimpleDocList.prototype.renderCellDetail = function SimpleFolderList_renderCellDetail(elCell, oRecord, oColumn, oData) {
        
          var record = oRecord.getData(),
               name = record.fileName,
              desc = "";            
      
          if (record.isInfo)
          {
             desc += '<div class="empty"><h3>' + record.title + '</h3>';
             desc += '<span>' + record.description + '</span></div>';
          }
          else
          {
             var id = this.id + '-metadata-' + oRecord.getId(),
                 version = "",
                 description = '<span class="faded">' + this.msg("details.description.none") + '</span>',
                 dateLine = "",
                 canComment = record.permissions.userAccess.create,
                 locn = record.location,
                 path=locn.path,
                 folderPath="",
                 nodeRef = new Alfresco.util.NodeRef(record.nodeRef);
               
                if(path.length>1){
                      
                      folderPath=path.replace(/\//g,"%2F");
                      
                   }
                            
                folderDetailsUrl = Alfresco.constants.URL_PAGECONTEXT + (locn.site ? "site/" + locn.site + '/' : "") + "documentlibrary#filter=path%7C%2F" +folderPath+"%2F"+name;
                docDetailsUrl = Alfresco.constants.URL_PAGECONTEXT + (locn.site ? "site/" + locn.site + '/' : "") + "document-details?nodeRef=" + nodeRef.toString();

             // Description non-blank?
             if (record.description && record.description !== "")
             {
                description = $links($html(record.description));
             }

             // Version display
             if (record.version && record.version !== "")
             {
                version = '<span class="document-version">' + $html(record.version) + '</span>';
             }
            
             // Date line
             var dateI18N = "modified", dateProperty = record.modifiedOn;
            
             if (record.custom && record.custom.isWorkingCopy)
             {
                dateI18N = "editing-started";
             }
             else if (record.modifiedOn === record.createdOn)
             {
                dateI18N = "created";
                dateProperty = record.createdOn;
             }
            
             if (locn.site)
             {
                    /**
                  * Modification:
                  * Point the link to the document library of the site
                  * instead of the dashboard
                  */
                 var siteDocLibraryUrl = Alfresco.constants.URL_PAGECONTEXT +"site/" +locn.site +'/' +"documentlibrary";
                 
                 if(locn.site=="my-files")
                 {
                
                    var index = encodeURIComponent(Alfresco.constants.USERNAME).length - 2;
                   var indexFolder = encodeURIComponent(Alfresco.constants.USERNAME).substring(index);
                    siteDocLibraryUrl = siteDocLibraryUrl +"#filter=path%7C%2F" + indexFolder + "%2F" + encodeURIComponent(Alfresco.constants.USERNAME);                             
                    
                 }
                                
                 var siteDocLibraryLink = '<a href="' + siteDocLibraryUrl + '" class="site-link theme-color-1">' +locn.siteTitle +'</a>'
                 dateLine = this.msg("details." + dateI18N + "-in-site",$relTime(dateProperty),siteDocLibraryLink);
               
             }
             else
             {
                dateLine = this.msg("details." + dateI18N + "-by", $relTime(dateProperty), $userProfile(record.modifiedByUser, record.modifiedBy, 'class="theme-color-1"'));
             }

             if (this.options.simpleView)
             {
                /**
                 * Simple View
                 */
               
                if(record.isFolder){
                     
                   desc += '<h3 class="filename simple-view"><a class="theme-color-1" href="' + folderDetailsUrl + '">' + $html(record.displayName) + '</a></h3>';
                     desc += '<div class="detail"><span class="item-simple">' + dateLine + '</span></div>';

                 }else{
                   
                  
                    desc += '<h3 class="filename simple-view"><a class="theme-color-1" href="' + docDetailsUrl + '">' + $html(record.displayName) + '</a></h3>';
                      desc += '<div class="detail"><span class="item-simple">' + dateLine + '</span></div>';

                 }
             
             }
             else
             {
                /**
                 * Detailed View
                 */
               
                if(record.isFolder){
                     
                   desc += '<h3 class="filename"><a class="theme-color-1" href="' + folderDetailsUrl + '">' + $html(record.displayName) + '</a>' + version + '</h3>';   
                                                        
                 }else{
                  
                   desc += '<h3 class="filename"><a class="theme-color-1" href="' + docDetailsUrl + '">' + $html(record.displayName) + '</a></h3>';
                   
                 }
               
                desc += '<div class="detail">';
                desc += '<span class="item">' + dateLine + '</span>';
               
                if (this.options.showFileSize)
                {
                   desc +=    '<span class="item">' + Alfresco.util.formatFileSize(record.size) + '</span>';
                }
                desc += '</div>';
                desc += '<div class="detail"><span class="item">' + description + '</span></div>';

                /* Favourite / Likes / Comments */
                desc += '<div class="detail detail-social">';
                desc +=    '<span class="item item-social">' + Alfresco.component.SimpleDocList.generateFavourite(this, oRecord) + '</span>';
                desc +=    '<span class="item item-social item-separator">' + Alfresco.component.SimpleDocList.generateLikes(this, oRecord) + '</span>';
               
                if (canComment)
                {
                   desc +=    '<span class="item item-social item-separator">' + Alfresco.component.SimpleDocList.generateComments(this, oRecord) + '</span>';
                }
               
                desc += '</div>';
             }
            
             // Metadata tooltip
             this.metadataTooltips.push(id);
          }

          elCell.innerHTML = desc;
       }

})();





controller script


for ( var i=0; i<model.widgets.length; i++ )
{
  if (model.widgets.id == "MyDocuments")
  {
    model.widgets.name = "MYCOMP.dashlet.MyDocuments";
  }
}


ctan
Champ in-the-making
Champ in-the-making
I got the same error message today:

ERROR [extensibility.impl.ExtensibilityModelImpl] [http-apr-8080-exec-20] A merge request was made as a root extension request. This is not allowed.

and this was caused by not specifying an action (eg. action="after") in the overriding freemarker (.ftl) file. The following had fixed it:

<blockcode>
<@markup id="js-extend" target="js" action="after">
</blockcode>