2323import com .logicaldoc .gui .common .client .services .SecurityService ;
2424import com .logicaldoc .gui .common .client .util .AwesomeFactory ;
2525import com .logicaldoc .gui .common .client .util .DocUtil ;
26+ import com .logicaldoc .gui .common .client .util .SecurityUtil ;
2627import com .logicaldoc .gui .common .client .util .Util ;
2728import com .logicaldoc .gui .common .client .widgets .DropSpotPopup ;
2829import com .logicaldoc .gui .frontend .client .calendar .CalendarEventDialog ;
3334import com .logicaldoc .gui .frontend .client .document .stamp .StampDialog ;
3435import com .logicaldoc .gui .frontend .client .document .update .UpdateDialog ;
3536import com .logicaldoc .gui .frontend .client .folder .FolderNavigator ;
36- import com .logicaldoc .gui .frontend .client .services . DocumentService ;
37+ import com .logicaldoc .gui .frontend .client .onlyoffice . OnlyOfficeEditor ;
3738import com .logicaldoc .gui .frontend .client .subscription .SubscriptionDialog ;
3839import com .smartgwt .client .types .SelectionType ;
3940import com .smartgwt .client .util .SC ;
@@ -80,6 +81,8 @@ public class DocumentToolbar extends ToolStrip implements FolderObserver {
8081
8182 protected ToolStripButton office = AwesomeFactory .newToolStripButton ("windows" , "editwithoffice" );
8283
84+ protected ToolStripButton onlyoffice = AwesomeFactory .newToolStripButton ("windows" , "editwithonlyoffice" );
85+
8386 protected ToolStripButton bulkUpdate = AwesomeFactory .newToolStripButton ("edit" , "bulkupdate" );
8487
8588 protected ToolStripButton stamp = AwesomeFactory .newToolStripButton ("tint" , "stamp" );
@@ -133,6 +136,8 @@ protected void prepareButtons() {
133136
134137 addOffice ();
135138
139+ addOnlyOffice ();
140+
136141 addSeparator ();
137142
138143 addUpload ();
@@ -431,7 +436,7 @@ private void addForm() {
431436 if (!Feature .enabled (Feature .FORM ))
432437 setFeatureDisabled (addForm );
433438
434- addForm .addClickHandler (event -> new AddDocumentUsingForm ().show ());
439+ addForm .addClickHandler (click -> new AddDocumentUsingForm ().show ());
435440 }
436441 }
437442
@@ -441,7 +446,7 @@ private void addScan() {
441446 if (!Feature .enabled (Feature .SCAN ))
442447 setFeatureDisabled (scan );
443448
444- scan .addClickHandler (event -> Util .openScan ());
449+ scan .addClickHandler (click -> Util .openScan ());
445450 }
446451 }
447452
@@ -459,7 +464,7 @@ private void addDropSpot() {
459464 if (!Feature .enabled (Feature .DROP_SPOT ))
460465 setFeatureDisabled (dropSpot );
461466
462- dropSpot .addClickHandler (event -> DropSpotPopup .openDropSpot ());
467+ dropSpot .addClickHandler (click -> DropSpotPopup .openDropSpot ());
463468 }
464469 }
465470
@@ -471,22 +476,36 @@ private void addOffice() {
471476 if (!Feature .enabled (Feature .OFFICE ))
472477 setFeatureDisabled (office );
473478
474- office .addClickHandler (event -> checkPermissionsAndRun (
479+ office .addClickHandler (click -> checkPermissionsAndRun (
475480 new String [] { GUIAccessControlEntry .PERMISSION_DOWNLOAD , GUIAccessControlEntry .PERMISSION_WRITE },
476481 () -> Util .openEditWithOffice (document .getId ())));
477482 }
478483 }
479484
485+ private void addOnlyOffice () {
486+ if (Feature .visible (Feature .ONLYOFFICE ) && Menu .enabled (Menu .ONLYOFFICE )) {
487+ addButton (onlyoffice );
488+ onlyoffice .setTooltip (I18N .message ("editwithonlyoffice" ));
489+ onlyoffice .setTitle ("<i class='fab fa-briefcase fa-lg fa-lg' aria-hidden='true'></i>" );
490+ if (!Feature .enabled (Feature .OFFICE ))
491+ setFeatureDisabled (office );
492+
493+ onlyoffice .addClickHandler (click -> checkPermissionsAndRun (
494+ new String [] { GUIAccessControlEntry .PERMISSION_DOWNLOAD , GUIAccessControlEntry .PERMISSION_WRITE },
495+ () -> new OnlyOfficeEditor (document ).show ()));
496+ }
497+ }
498+
480499 private void addConvert () {
481500 if (Feature .visible (Feature .FORMAT_CONVERSION )) {
482501 addButton (convert );
483502 convert .setTooltip (I18N .message ("convert" ));
484503 if (!Feature .enabled (Feature .PDF ))
485504 setFeatureDisabled (convert );
486505
487- convert .addClickHandler (event -> {
506+ convert .addClickHandler (click -> {
488507 new ConversionDialog (document ).show ();
489- event .cancel ();
508+ click .cancel ();
490509 });
491510 }
492511 }
@@ -499,7 +518,7 @@ private void addPdf() {
499518 setFeatureDisabled (pdf );
500519
501520 pdf .addClickHandler (
502- event -> checkPermissionsAndRun (new String [] { GUIAccessControlEntry .PERMISSION_DOWNLOAD }, () -> {
521+ click -> checkPermissionsAndRun (new String [] { GUIAccessControlEntry .PERMISSION_DOWNLOAD }, () -> {
503522 List <Long > selection = DocumentsPanel .get ().getDocumentsGrid ().getSelectedIds ();
504523 if (selection .size () == 1 ) {
505524 DocUtil .downloadPdfConversion (document .getId (), document .getVersion ());
@@ -549,28 +568,8 @@ private void addDownload() {
549568 * @param task The task to run
550569 */
551570 private void checkPermissionsAndRun (String [] requiredPermissions , Runnable task ) {
552- DocumentsGrid grid = DocumentsPanel .get ().getDocumentsGrid ();
553- if (grid .getSelectedCount () == 0 )
554- return ;
555-
556- DocumentService .Instance .get ().getAllowedPermissions (grid .getSelectedIds (),
557- new AsyncCallback <>() {
558- @ Override
559- public void onFailure (Throwable caught ) {
560- GuiLog .serverError (caught );
561- }
562-
563- @ Override
564- public void onSuccess (GUIAccessControlEntry grantedPermissions ) {
565- for (String permission : requiredPermissions ) {
566- if (!grantedPermissions .isPermissionAllowed (permission .toLowerCase ())) {
567- GuiLog .warn (I18N .message ("somedocsdonothaveperm" , permission .toUpperCase ()), null );
568- return ;
569- }
570- }
571- task .run ();
572- }
573- });
571+ SecurityUtil .checkPermissionsAndRun (DocumentsPanel .get ().getDocumentsGrid ().getSelectedIds (),
572+ requiredPermissions , task );
574573 }
575574
576575 private void addRefresh () {
@@ -610,6 +609,7 @@ public void update(GUIDocument document, GUIFolder folder) {
610609 stamp .setDisabled (true );
611610 sign .setDisabled (true );
612611 office .setDisabled (true );
612+ onlyoffice .setDisabled (true );
613613 addForm .setDisabled (true );
614614 readingRequest .setDisabled (true );
615615 }
@@ -693,10 +693,14 @@ else if (document.getType() != null)
693693
694694 office .setDisabled (
695695 !Feature .enabled (Feature .OFFICE ) || !isOfficeFile || !document .isDownload () || !document .isWrite ());
696+ onlyoffice .setDisabled (!Feature .enabled (Feature .OFFICE ) || !Menu .enabled (Menu .ONLYOFFICE )
697+ || !document .isDownload () || !document .isWrite ());
696698 if (document .getStatus () != Constants .DOC_UNLOCKED && !Session .get ().getUser ().isMemberOf (Constants .GROUP_ADMIN )
697699 && document .getLockUserId () != null
698- && Session .get ().getUser ().getId () != document .getLockUserId ().longValue ())
700+ && Session .get ().getUser ().getId () != document .getLockUserId ().longValue ()) {
699701 office .setDisabled (true );
702+ onlyoffice .setDisabled (true );
703+ }
700704 }
701705
702706 @ Override
0 commit comments