cancel
Showing results for 
Search instead for 
Did you mean: 

Add an archive action

morganp1
Confirmed Champ
Confirmed Champ
Hi,

I am currently working on Alfresco 4.2 and I have to add an 'Archive' action (simply a move to a folder that the user can't choose) to the list 'Document Actions' just below the other as 'Download', 'Copy to …', 'Move to …', etc.

I started by adding a button in a 'share/WEB-INF/classes/alfresco/web-extension/share-config-custom.xml' (actually two buttons, the second is to test the java code):


<config evaluator="string-compare" condition="DocLibActions">
        <actions>
            <action id="document-archive" type="javascript" label="actions.<myCompany>.archive">
                <param name="function">onActionArchive</param>
                <param name="successMessage">message.archive.success</param>
                <param name="failureMessage">message.archive.failure</param>
                <evaluator negate="true">evaluator.doclib.action.isLocked</evaluator>
            </action>
            <action id="document-execute-script" type="javascript" label="actions.document.archive.by.script"></action>
        </actions>
       
        <actionGroups>
            <actionGroup id="document-browse">
                <action index="264" id="document-archive"/>
                <action index="266" id="document-execute-script"/>
            </actionGroup>
        </actionGroups>
    </config>

    <config evaluator="string-compare" condition="DocLibCustom">

        <dependencies>
            <!– <css src="my-custom-action.css" /> –>
            <js src="components/documentlibrary/archive.js"/>
        </dependencies>

        <dependencies/>
    </config>


From there, I have a file in the same place 'custom-slingshot-application-context.xml' to define a Bean whose value is 'alfresco.messages.custom'. So then I change the text displayed on the buttons to a file 'messages/custom.properties'.

I also have a file 'share/components/DocumentLibrary/archive.js' which automatically generate a -min.js and an image 'share/components/documentlibrary/actions/document-archive-16.png' for my button. Until then, everything works exactly as I expected.


So now we have to add an action behind the button and that's where the trouble begins. Alfresco side this time, I created a class 'ArchiveActionExecuter' that extends 'ActionExecuterAbstractBase' and does what I want. As for custom.properties I have a Bean that allows me to reference this class:


<bean id="archive" class="org.alfresco.module.<myCompanyAmp>.ArchiveActionExecuter" parent="action-executer">
        <property name="serviceRegistry">
            <ref bean="ServiceRegistry"/>
        </property>
        <property name="repository">
            <ref bean="repositoryHelper"/>
        </property>
    </bean>


What should I do to call my java class when I press my 'Archive' button? What should be put in the file 'archive.js' I mentioned above?

Currently, I'm sure my java class is good because if I add a file archive-action.js, for example, in the repository under 'Company Home/Data Dictionary/Scripts' with:


var archiveAction = actions.create("archive");
archiveAction.execute(document);


If I click on my second button and I choose the script I just added (archive-action.js), then my java class is called and the action is done the way I want.

Now, if I click on the 'Archive' button, nothing happens.


Currently, in the file 'share/components/DocumentLibrary/archive.js' I have the following code:


(function() {
    YAHOO.Bubbling.fire("registerAction",
    {
        actionName: "onActionArchive",
        fn: function <myCompany>_onActionArchive(file) {
           var archiveAction = actions.create("archive");
           archiveAction.execute(document);
        }
    });
})();



I think the problem come from that file but I'm a little confused and do not really see what's missing for the action to be launched when a user click on the button, so if someone could help me it would be very nice!


Thank you for reading and for your help

Edit: I would also say that my action 'archive' appears and could be used as a 'Content rule' (can be added to a file so that as soon as someone uploads a document, this action is called for example).
3 REPLIES 3

zladuric
Champ on-the-rise
Champ on-the-rise
Well does your event fire?

Hi,

I think my event fire. I just wrote a java-backed web script and changed the content of my 'fn: function <myCompany>_onActionArchive(record)' to call it and it works…

zladuric
Champ on-the-rise
Champ on-the-rise
Ok, glad you got it to work.