We all like to develop based on the best practices and that is what I recommend as well. However, sometimes in the interest of time, we may have to go for a quick solution considering the practical situation. For example, think of a scenario where you are preparing for a demo and at last moment you realize that you need to take care of some specific use case. I am sure, you must be looking forward to know how quickly and easily you can achieve it. That's where quick solutions would be very helpful. Here I am going to share with you one such quick trick which may be helpful to you somewhere sometime.
While working on Alfresco you may have come across a use case that, you want to disable upload file button in Alfresco Share for some specific folder and all folders under it.
Here is how you can have it working just in 5 minutes for your Alfresco Community 5.1 installation.
1. In your Alfresco installed directory, copy code from toolbar.js to toolbar-min.js at the location tomcat/webapps/share/components/documentlibrary/
[Note : It is always recommended to have your client side JS files minified for having a better page load performance. Although we are knowing that, however in order to get the things ready in the interest of time, we are not minifying the JS here]
2. Add following code snippet under onFilterChanged function in toolbar-min.js.Provide the folder name for which you want to hide the upload button.
//Custom start
if(this.doclistMetadata.parent.properties["cm:name"] == "Folder Name" || this.currentPath.indexOf("Folde Name") !== -1) {
this.widgets.fileUpload.set("disabled", true);
} else {
this.widgets.fileUpload.set("disabled", false);
}
//Custom end
Above change in toolbar-min.js, will appear as shown in the following screenprint. Highlighted in blue is the custom code we have added to disable the upload file button for a folder named MyFolder and all its subfolder.
Hope this would be helpful.
While working on Alfresco you may have come across a use case that, you want to disable upload file button in Alfresco Share for some specific folder and all folders under it.
Here is how you can have it working just in 5 minutes for your Alfresco Community 5.1 installation.
1. In your Alfresco installed directory, copy code from toolbar.js to toolbar-min.js at the location tomcat/webapps/share/components/documentlibrary/
[Note : It is always recommended to have your client side JS files minified for having a better page load performance. Although we are knowing that, however in order to get the things ready in the interest of time, we are not minifying the JS here]
2. Add following code snippet under onFilterChanged function in toolbar-min.js.Provide the folder name for which you want to hide the upload button.
//Custom start
if(this.doclistMetadata.parent.properties["cm:name"] == "Folder Name" || this.currentPath.indexOf("Folde Name") !== -1) {
this.widgets.fileUpload.set("disabled", true);
} else {
this.widgets.fileUpload.set("disabled", false);
}
//Custom end
Above change in toolbar-min.js, will appear as shown in the following screenprint. Highlighted in blue is the custom code we have added to disable the upload file button for a folder named MyFolder and all its subfolder.
code snippet to disable upload file button for a specific folder and its subfolders |
Hi Ramesh,
ReplyDeleteThis is an interesting use case but except the upload button all other ways to upload a file is still enable.
Following Steps I tried:
1. Drag and drop (Working)
2. I created a new folder and I could see the upload file option in the pane.
Hi Owais,
DeleteYes, you are correct. This quick work around is for disabling the upload button only. The other ways of uploading files would work as it is. However, if you want to disable them as well then you may have to tweak them to handle this scenario. If you are going to look into it then would appreciate if you could share how you accomplished it once you complete it.
Thanks,
Ramesh
Hi Ramesh,
ReplyDeleteExcellent article. Can you please let me know how can I do the same for drag and drop feature. I want to fully disable the upload when the user is in a particular folder