Edit buttons for most boxes
authorAlexander Ebert <ebert@woltlab.com>
Wed, 20 Jun 2018 11:40:55 +0000 (13:40 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 20 Jun 2018 11:40:55 +0000 (13:40 +0200)
See #2575

com.woltlab.wcf/templates/__box.tpl
wcfsetup/install/files/lib/data/box/Box.class.php
wcfsetup/install/files/style/layout/box.scss

index 6987ec4ddb7264cc06573fb09b9081a7f6a9fda3..1369d3983013c7f4cb667f6d16236d857c2c3ae8 100644 (file)
@@ -1,4 +1,7 @@
-<{if $box->showHeader}section{else}div{/if} class="box{if $box->getImage()} boxWithImage{/if}{if $box->cssClassName} {$box->cssClassName}{/if}" data-box-identifier="{@$box->identifier}">
+<{if $box->showHeader}section{else}div{/if} class="box{if $box->getImage()} boxWithImage{/if}{if $box->showEditButton()} boxWithEditButton{/if}{if $box->cssClassName} {$box->cssClassName}{/if}" data-box-identifier="{@$box->identifier}">
+       {if $box->showEditButton()}
+               <a href="{link controller='Box' id=$box->boxID isACP=true}{/link}" class="boxEditButton"><span class="icon icon16 fa-pencil-square-o"></span></a>
+       {/if}
        {if $box->getImage()}
                <div class="boxImage">
                        {if $box->hasLink()}
index 0750694d8d563f8f4d0956fdcbd49c6b47d83995..87fda493e80d42628cb8837bf94e40c1f0def21f 100644 (file)
@@ -117,6 +117,12 @@ class Box extends DatabaseObject {
         */
        public $virtualShowOrder = -1;
        
+       /**
+        * list of positions that support the edit button
+        * @var string[]
+        */
+       public $editButtonPositions = ['headerBoxes', 'sidebarLeft', 'contentTop', 'sidebarRight', 'contentBottom', 'footerBoxes', 'footer'];
+       
        /**
         * @inheritDoc
         */
@@ -507,6 +513,20 @@ class Box extends DatabaseObject {
                $this->virtualShowOrder = $virtualShowOrder;
        }
        
+       /**
+        * Returns true if an edit button should be displayed for this box.
+        * 
+        * @return      boolean
+        * @since       3.2
+        */
+       public function showEditButton() {
+               if (WCF::getSession()->getPermission('admin.content.cms.canManageBox') && in_array($this->position, $this->editButtonPositions)) {
+                       return true;
+               }
+               
+               return false;
+       }
+       
        /**
         * Returns the box with the given identifier.
         *
index e961b160690e4c240b57c45f418889e0ddb85506..f15b0c5e81db1f3f57b2566669894c3890cae456 100644 (file)
                }
        }
 }
+
+.boxWithEditButton {
+       position: relative;
+       
+       &:hover .boxEditButton {
+               opacity: 1;
+       }
+       
+       .boxEditButton {
+               color: inherit;
+               opacity: 0;
+               position: absolute;
+               top: 4px;
+               transition: opacity .12s ease-in-out;
+               right: 4px;
+               
+               &:hover {
+                       color: inherit;
+               }
+               
+               > .icon {
+                       color: inherit;
+               }
+       }
+}