2

I want to add document name rename action on workflow form in alfresco share. Is there any way to do this.

Please provide the required steps and sample code snipet if possible.

Please reply is somebady did this before.

Thanks in advance.

Deepak Talape
  • 997
  • 1
  • 9
  • 35

1 Answers1

3

The first thing which you need to do is to define the form configuration for the workflow task form for which you have taken the screenshot.You can define it inside the share-config-custom.xml. Form configuration should be something like below.

    <config evaluator="task-type" condition="**NAME OF YOUR TASK**">
    <forms>
        <form>
            <field-visibility>
                <!-- **FIELDS WHICH YOU WANT TO MAKE VISIBLE** -->
                <show id="wf:requiredApprovePercent" />
                <show id="bpm:workflowDueDate" />
                <show id="bpm:workflowPriority" />
                <show id="packageItems" />
                <show id="bpm:sendEMailNotifications" />
                <show id="bpm:comment" />
            </field-visibility>
            <appearance>
                <!-- **FIELDS WHICH FOR WHICH YOU WANT TO CUSTOMIZE TEMPLATE** -->
                <field id="bpm:workflowPriority" label-id="workflow.field.priority">
                    <control template="/org/alfresco/components/form/controls/workflow/priority.ftl" />
                </field>
                <field id="bpm:sendEMailNotifications">
                    <control template="/org/alfresco/components/form/controls/workflow/email-notification.ftl" />
                </field>
                <field id="bpm:comment" label-id="workflow.field.comment">
                    <control template="/org/alfresco/components/form/controls/textarea.ftl" />
                </field>
            </appearance>
        </form>
    </forms>
</config>

Once you define this you need to customize the template for the packageItems field and create a new field template for it.You can take a reference from existing template "org\alfresco\components\form\controls\workflow\packageitems.ftl"

Above ftl template include one more ftl library, named as association.ftl.You need to create a new association.ftl and include it inside this file.

You need to make change in that file as well.Let's come to that later.

Now you need to create one javascript file which should extend object-finder.js.How to extend that file is very well explained in below link.

http://alfrescoblog.com/2014/05/28/alfresco-share-custom-object-finder-js/

Once you create the extended file , it should have content similar to below.You still need to customize below function as per your requirement.You need to add the coded for adding pencil icon and handling onclick event for it.

(function() {
var Dom = YAHOO.util.Dom, Event = YAHOO.util.Event;
   var $html = Alfresco.util.encodeHTML,
      $hasEventInterest = Alfresco.util.hasEventInterest,
      $combine = Alfresco.util.combinePaths;

Alfresco.PackageItemsObjectFinder = function Alfresco_PackageItemsObjectFinder(
        htmlId, currentValueHtmlId) {
    Alfresco.PackageItemsObjectFinder.superclass.constructor.call(this,
            htmlId, currentValueHtmlId);

    // Re-register with our own name
    this.name = "Alfresco.PackageItemsObjectFinder";
    Alfresco.util.ComponentManager.reregister(this);

    return this;
};

YAHOO.extend(Alfresco.PackageItemsObjectFinder, Alfresco.ObjectFinder, {
          fnRenderCellListItemName: function ObjectFinder_fnRenderCellListItemName()
          {
             var scope = this;

             return function ObjectFinder_fnRenderCellListItemName(elCell, oRecord, oColumn, oData)
             {
                var item = oRecord.getData(),
                   titles =  item.title ? $html(item.title) : scope.msg("label.none"),
                   modifiedOn = item.modified ? Alfresco.util.formatDate(Alfresco.util.fromISO8601(item.modified)) : null,
                   title = $html(item.name);
                if (scope.options.showLinkToTarget && scope.options.targetLinkTemplate !== null)
                {
                   var link;
                   if (YAHOO.lang.isFunction(scope.options.targetLinkTemplate))
                   {
                      link = scope.options.targetLinkTemplate.call(scope, oRecord.getData());
                   }
                   else
                   {
                      //Discard template, build link from scratch
                      var linkTemplate = (item.site) ? Alfresco.constants.URL_PAGECONTEXT + "site/{site}/document-details?nodeRef={nodeRef}" : Alfresco.constants.URL_PAGECONTEXT + "document-details?nodeRef={nodeRef}";
                      link = YAHOO.lang.substitute(linkTemplate,
                      {
                         nodeRef : item.nodeRef,
                         site : item.site
                      });
                   }
                   title = '<a href="' + link + '">' + $html(item.displayName?item.displayName:item.name) + '</a>';
                }
                var template = '<h3 class="name">' + title + '</h3>';
                template += '<div class="description">' + "Title" + ': ' + titles + '</div>';
                template += '<div class="viewmode-label">' + scope.msg("form.control.object-picker.modified-on") + ': ' + (modifiedOn ? modifiedOn : scope.msg("label.none")) + '</div>';
                elCell.innerHTML = template;
             };
          }
});

})();

Once you extend this, than you need give the reference of this extended class in the association ftl file.

The change in assiciation file will be something like below.

var ${picker} = new Alfresco.PackageItemsObjectFinder("${controlId}", "${fieldHtmlId}")

Instead of

var ${picker} = new Alfresco.ObjectFinder("${controlId}", "${fieldHtmlId}")
Krutik Jayswal
  • 3,165
  • 1
  • 15
  • 38