From: Vincent Vanwaelscappel Date: Tue, 23 May 2023 14:32:30 +0000 (+0200) Subject: wait #5940 @3 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=974e4ce022ceae728dd15a7296566d7020f92fe5;p=fluidbook-toolbox.git wait #5940 @3 --- diff --git a/app/Fluidbook/Compiler/Links.php b/app/Fluidbook/Compiler/Links.php index e1f539efe..e5c5d1331 100644 --- a/app/Fluidbook/Compiler/Links.php +++ b/app/Fluidbook/Compiler/Links.php @@ -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') { diff --git a/app/Fluidbook/Link/LinksData.php b/app/Fluidbook/Link/LinksData.php index dfb1e96db..95ce5c1e0 100644 --- a/app/Fluidbook/Link/LinksData.php +++ b/app/Fluidbook/Link/LinksData.php @@ -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 [] diff --git a/app/Models/FluidbookPublication.php b/app/Models/FluidbookPublication.php index def428512..76bf72fd7 100644 --- a/app/Models/FluidbookPublication.php +++ b/app/Models/FluidbookPublication.php @@ -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; } diff --git a/app/SubForms/Link/Base.php b/app/SubForms/Link/Base.php index b2418b29d..d11403940 100644 --- a/app/SubForms/Link/Base.php +++ b/app/SubForms/Link/Base.php @@ -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 */ diff --git a/app/SubForms/Link/Email.php b/app/SubForms/Link/Email.php index fc3b00f55..eff83d182 100644 --- a/app/SubForms/Link/Email.php +++ b/app/SubForms/Link/Email.php @@ -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')); } } diff --git a/app/SubForms/Link/Image.php b/app/SubForms/Link/Image.php index 320459f8b..6345ea5f9 100644 --- a/app/SubForms/Link/Image.php +++ b/app/SubForms/Link/Image.php @@ -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]); diff --git a/app/SubForms/Link/Multimedia.php b/app/SubForms/Link/Multimedia.php index f21a82e07..8d6ca71c8 100644 --- a/app/SubForms/Link/Multimedia.php +++ b/app/SubForms/Link/Multimedia.php @@ -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]); diff --git a/app/SubForms/Link/Web.php b/app/SubForms/Link/Web.php index c256b86b9..a49e63004 100644 --- a/app/SubForms/Link/Web.php +++ b/app/SubForms/Link/Web.php @@ -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')); } } diff --git a/resources/linkeditor/js/linkeditor.links.js b/resources/linkeditor/js/linkeditor.links.js index f67160211..318902030 100644 --- a/resources/linkeditor/js/linkeditor.links.js +++ b/resources/linkeditor/js/linkeditor.links.js @@ -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 + ' Ctrl+L', 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) { diff --git a/resources/views/fluidbook_publication/link_editor.blade.php b/resources/views/fluidbook_publication/link_editor.blade.php index ca4043d91..581a7bb4d 100644 --- a/resources/views/fluidbook_publication/link_editor.blade.php +++ b/resources/views/fluidbook_publication/link_editor.blade.php @@ -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(); @@ -326,6 +327,7 @@ var SETTINGS = @json($settings); var THEME = @json($t); var ASSETS = @json($assets); + var CAN_CONTAIN_LINKS = @json($canContainLinks); var DEPTH = @json($depths);