]> _ Git - fluidbook-toolbox.git/commitdiff
wait #5940 @3
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 23 May 2023 14:32:30 +0000 (16:32 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 23 May 2023 14:32:30 +0000 (16:32 +0200)
app/Fluidbook/Compiler/Links.php
app/Fluidbook/Link/LinksData.php
app/Models/FluidbookPublication.php
app/SubForms/Link/Base.php
app/SubForms/Link/Email.php
app/SubForms/Link/Image.php
app/SubForms/Link/Multimedia.php
app/SubForms/Link/Web.php
resources/linkeditor/js/linkeditor.links.js
resources/views/fluidbook_publication/link_editor.blade.php

index e1f539efe2a920cee77864961a5a6cadc64eec15..e5c5d1331a369f81d0ed280bf9abafc859f28c27 100644 (file)
@@ -216,7 +216,7 @@ trait Links
 
             if ($linkData['type'] == Link::SHOWLINK && $linkData['target'] !== 'hide') {
                 $ids = explode(',', $linkData['to']);
-                $close = ($linkData['video_service'] && $linkData['video_service'] !== 'none');
+                $close = ($linkData['close_button'] && $linkData['close_button'] !== 'none');
                 foreach ($ids as $id) {
                     $id = trim($id);
                     if ($id === 'tabs') {
index dfb1e96dba0355f02011f23d4a152139fcf482c9..95ce5c1e0cf639181c5f632c78ee3a0c07e21b1c 100644 (file)
@@ -4,6 +4,7 @@ namespace App\Fluidbook\Link;
 
 use App\Models\FluidbookPublication;
 use App\Models\User;
+use App\SubForms\Link\Base;
 use Cubist\Util\Files\Files;
 use Cubist\Util\Gzip;
 use Cubist\Util\Str;
@@ -252,6 +253,7 @@ class LinksData
         self::_correctImageSpecialLinks($links);
         self::_fixWebVideoServices($links);
         self::_fixMultimedia($links);
+        self::_fixCloseButton($links);
     }
 
     protected static function _fixTooltips(&$links)
@@ -302,13 +304,23 @@ class LinksData
             if (isset($link['video_width'], $link['video_height']) && $link['video_width'] == 320 & $link['video_height'] == 240) {
                 $links[$k]['video_width'] = $links[$k]['video_height'] = '';
             }
-            if (isset($link['alternative']) && $link['alternative'] && $link['type'] == 6) {
+            if (isset($link['alternative']) && $link['alternative'] && $link['type'] == Link::MULTIMEDIA) {
                 $links[$k]['to'] = $link['alternative'];
                 unset($links[$k]['alternative']);
             }
         }
     }
 
+    protected static function _fixCloseButton(&$links)
+    {
+        foreach ($links as $k => $link) {
+            if ($link['type'] === Link::SHOWLINK && isset($link['video_service']) && $link['video_service'] && !isset($link['close_button'])) {
+                $links[$k]['close_button'] = $link['video_service'];
+                unset($links[$k]['video_service']);
+            }
+        }
+    }
+
     /**
      * @param $xls Spreadsheet
      * @param $links []
index def4285120380fafc5374afd792931f92fb15dae..76bf72fd7ee73d75b30a4e24e0ab495ac430e954 100644 (file)
@@ -30,6 +30,7 @@ use App\Models\Traits\CheckHash;
 use App\Models\Traits\PublicationSettings;
 use App\Models\Traits\SCORMVersionTrait;
 use App\Slack\Slack;
+use App\SubForms\Link\Base;
 use Cubist\Backpack\CubistBackpackServiceProvider;
 use Cubist\Backpack\Magic\Fields\FormBigSection;
 use Cubist\Backpack\Magic\Fields\FormSuperSection;
@@ -522,23 +523,24 @@ class FluidbookPublication extends ToolboxSettingsModel
     {
         $res = [];
         $this->getLinksAndRulers($links, $rules);
+
+        $canContainLinks = Base::typesCanContainLinks();
+
         foreach ($links as $link) {
-            if ($link['type'] != 6) {
+            $attr = $canContainLinks[$link['type']] ?? false;
+            if (!$attr) {
                 continue;
             }
 
-            if (!isset($link['to']) || !$link['to']) {
+            if (!isset($link[$attr]) || !$link[$attr]) {
                 continue;
             }
-            $file = $this->asset_path($link['to']);
+            $file = $this->asset_path($link[$attr]);
             if (!file_exists($file)) {
                 continue;
             }
-            $md5 = md5($link['to']);
-            if (isset($res[$md5])) {
-                continue;
-            }
-            $res[$md5] = ['name' => $link['to'], 'dim' => Image::getimagesize($file), 'url' => url('/fluidbook-publication/' . $this->id . '/edit/links/assets/' . $link['to'])];
+            $md5 = md5($link[$attr]);
+            $res['uid_' . $link['uid']] = $res[$md5] = ['name' => $link[$attr], 'dim' => Image::getimagesize($file), 'url' => url('/fluidbook-publication/' . $this->id . '/edit/links/assets/' . $link[$attr])];
         }
         return $res;
     }
index b2418b29dcee9c8fdbf7889c7594a1f77c168e7d..d11403940b6b956a6b4543ac476d3abdff55dee2 100644 (file)
@@ -45,6 +45,8 @@ class Base extends Form
     protected $_extra = true;
     protected $_uid = true;
 
+    protected $_canContainLinks = false;
+
     protected static $_acceptImage = ['.jpg', '.jpeg', '.png', '.svg', '.gif'];
     protected static $_acceptImageAndZip = ['.jpg', '.jpeg', '.png', '.svg', '.gif', '.zip'];
     protected static $_acceptAnimation = ['.jpg', '.jpeg', '.png', '.svg', '.gif', '.zip', '.oam', '.html', '.json', '.pdf'];
@@ -118,6 +120,27 @@ class Base extends Form
         return $res;
     }
 
+    public static function typesCanContainLinks()
+    {
+        $res = [];
+        foreach (self::types() as $l) {
+            if(!isset($l['class'])){
+                continue;
+            }
+            $class = $l['class'];
+            $i = new $class();
+            if ($c = $i->canContainLinks()) {
+                $res[$l['type']] = $c;
+            }
+        }
+        return $res;
+    }
+
+    public function canContainLinks()
+    {
+        return $this->_canContainLinks;
+    }
+
     /**
      * @return mixed
      */
index fc3b00f550eaa77786c77195dcb7c4f0d15bb01d..eff83d182d70933a80154e01919704760fee2512 100644 (file)
@@ -11,6 +11,6 @@ class Email extends Web
 
     public function addDestinationField()
     {
-        $this->addField('to', \Cubist\Backpack\Magic\Fields\Email::class, __('Adresse e-mail'));
+        $this->addField('to', \Cubist\Backpack\Magic\Fields\Text::class, __('Adresse e-mail'));
     }
 }
index 320459f8b9362c0ad8af6d8ad202afd219b68d97..6345ea5f9592e021a68320305838d05a2cf5ce40 100644 (file)
@@ -9,6 +9,8 @@ class Image extends Animated
 {
     public $type = Link::IMAGE;
 
+    protected $_canContainLinks = 'to';
+
     public function addDestinationField()
     {
         $this->addField('to', FilesOrURL::class, __('Image'), $this->getFilesOrURLEntry() + ['accept' => self::$_acceptImage]);
index f21a82e07f0ce26a885d4afb16bfee6dd63522dd..8d6ca71c8e82b0ec79b8be075ac35b84254a8e20 100644 (file)
@@ -12,6 +12,8 @@ class Multimedia extends Base
     public $_integration = true;
     public $_multimedia = true;
 
+    protected $_canContainLinks = 'to';
+
     public function addDestinationField()
     {
         $this->addField('to', FilesOrURL::class, __('Animation'), $this->getFilesOrURLEntry() + ['accept' => self::$_acceptAnimation]);
index c256b86b973c4d8f8594b1c8d8a07279e162bd6c..a49e6300440f36b0181543cfa599de0885b72739 100644 (file)
@@ -4,8 +4,6 @@ namespace App\SubForms\Link;
 
 use App\Fields\FluidbookLinkEditor\Target;
 use App\Fluidbook\Link\Link;
-use Cubist\Backpack\Magic\Fields\SelectFromArray;
-use Cubist\Backpack\Magic\Fields\URL;
 // __('!! Editeur de liens')
 class Web extends Base
 {
@@ -13,7 +11,7 @@ class Web extends Base
 
     public function addDestinationField()
     {
-        $this->addField('to', URL::class, __('Adresse'));
+        $this->addField('to', \Cubist\Backpack\Magic\Fields\Text::class, __('Adresse'));
         $this->addField('target', Target::class, __('Ouvrir le lien dans'));
     }
 }
index f67160211b72ad2537d602602ae48e977122f11b..3189020307fb94b9e6e0b957b94abe5e235dd4a5 100644 (file)
@@ -142,7 +142,6 @@ LinkeditorLinks.prototype = {
             e.preventDefault();
         }
         $(document).on('dragenter', '#linkeditor-main', function (e) {
-
             // Prevent canvas being scrolled at the begining of the drag
             $("#linkeditor-canvas").addClass('noscroll');
             setTimeout(function () {
@@ -246,7 +245,7 @@ LinkeditorLinks.prototype = {
                             },
                         }
                     });
-                    if (selection.is('[fb-type=6]')) {
+                    if (CAN_CONTAIN_LINKS[parseInt($(selection).attr('fb-type'))] !== undefined) {
                         res.items.image_link = {
                             isHtmlName: true,
                             name: TRANSLATIONS.edit_image_link + ' <kbd>Ctrl+L</kbd>', callback: function () {
@@ -463,12 +462,12 @@ LinkeditorLinks.prototype = {
 
 
     openImageLink: function () {
-        let selection = $(".link[fb-type=6].selected");
-        if (selection.length !== 1 || selection.attr('fb-alternative') == '') {
+        let selection = $(".link.selected");
+        if (undefined === CAN_CONTAIN_LINKS[parseInt($(selection).attr('fb-type'))] || selection.length !== 1) {
             this.linkeditor.notification(TRANSLATIONS.error_open_image_link, 'warning');
             return;
         }
-        this.linkeditor.changePage('link_' + MD5(selection.attr('fb-alternative')).toString());
+        this.linkeditor.changePage('link_uid_' + selection.attr('fb-uid'));
     },
 
     selectLinkAndSelectToField: function (link) {
index ca4043d91a265fb2601190af0aa5fc7cd88b2052..581a7bb4d6a2d903a8e817efc7c97bf712e9253b 100644 (file)
@@ -3,6 +3,7 @@
     $title='#'.$id.' - '.__('Editeur de liens');
     /** @var $fluidbook \App\Models\FluidbookPublication */
     $depths=\App\SubForms\Link\Base::getDepths(\App\Models\FluidbookPublication::find($fluidbook->id));
+    $canContainLinks=\App\SubForms\Link\Base::typesCanContainLinks();
     $fluidbook->getLinksAndRulers($links,$rulers);
     $fbdata=$fluidbook->getPageData()->getRawData();
     $fbdata['settings']['width']=$fbdata['width']=$fluidbook->getPageWidth();
         var SETTINGS = @json($settings);
         var THEME = @json($t);
         var ASSETS = @json($assets);
+        var CAN_CONTAIN_LINKS = @json($canContainLinks);
         var DEPTH = @json($depths);
     </script>
     <script