From 06c4b0811d09591a44bfbee1671ae851446f4ba2 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 7 Nov 2022 18:44:41 +0100 Subject: [PATCH] wip #5468 @3 --- app/Fields/FluidbookLinkEditor/Target.php | 3 ++ app/SubForms/Link/Base.php | 46 +++++++++++++++++-- app/SubForms/Link/Web.php | 3 ++ package-lock.json | 11 +++++ package.json | 1 + resources/linkeditor/js/linkeditor.js | 4 -- .../link_editor.blade.php | 17 ++++--- 7 files changed, 69 insertions(+), 16 deletions(-) diff --git a/app/Fields/FluidbookLinkEditor/Target.php b/app/Fields/FluidbookLinkEditor/Target.php index 0e82f1595..c702e2601 100644 --- a/app/Fields/FluidbookLinkEditor/Target.php +++ b/app/Fields/FluidbookLinkEditor/Target.php @@ -6,6 +6,9 @@ use Cubist\Backpack\Magic\Fields\SelectFromArray; class Target extends SelectFromArray { + protected $_ajax=false; + protected $_allowNull=false; + public function getOptions() { return [ diff --git a/app/SubForms/Link/Base.php b/app/SubForms/Link/Base.php index 7cc4eb6bd..dd6034aa0 100644 --- a/app/SubForms/Link/Base.php +++ b/app/SubForms/Link/Base.php @@ -5,10 +5,11 @@ namespace App\SubForms\Link; use App\Fields\FluidbookLinkEditor\Depth; use App\Fields\FluidbookLinkEditor\LinkType; use App\Fields\FluidbookLinkEditor\MultimediaIntegration; +use App\Models\FluidbookPublication; use Cubist\Backpack\Magic\Fields\Checkbox; -use Cubist\Backpack\Magic\Fields\Code; use Cubist\Backpack\Magic\Fields\FieldGroupEnd; use Cubist\Backpack\Magic\Fields\FieldGroupStart; +use Cubist\Backpack\Magic\Fields\FilesOrURL; use Cubist\Backpack\Magic\Fields\FormSection; use Cubist\Backpack\Magic\Fields\Text; use Cubist\Backpack\Magic\Fields\Textarea; @@ -62,9 +63,15 @@ class Base extends Form const ANCHOR = 40; const FLIPCARD = 41; + /** + * @var int + */ + protected $fluidbook_id; + protected $_displayedOnFluidbook = true; protected $_integration = false; protected $_multimedia = false; + protected $_addedContents = true; protected $_tooltip = true; /** @@ -128,9 +135,24 @@ class Base extends Form return $res; } - public function init() + /** + * @return mixed + */ + public function getFluidbookId() + { + return $this->fluidbook_id; + } + + /** + * @param int|string $fluidbook_id + */ + public function setFluidbookId(int|string $fluidbook_id = '0'): void + { + $this->fluidbook_id = $fluidbook_id; + } + + public function initForm() { - parent::init(); $this->addTypeField(); $this->addSettingsFields(); $this->addAppearanceFields(); @@ -156,7 +178,7 @@ class Base extends Form public function addDestinationField() { - $this->addField('to', Text::class, __('Destination')); + } public function addUIDField() @@ -174,6 +196,11 @@ class Base extends Form public function addBasicSettingsFields() { + if ($this->_addedContents) { + $this->addField('header_contents', FormSection::class, __('Contenus superposés')); + $this->addField('image', FilesOrURL::class, __('Image'), array_merge($this->getFilesOrURLEntry(), ['accept' => ['.jpg', '.jpeg', '.png', '.svg', '.gif']])); + $this->addField('animation', FilesOrURL::class, __('Animation'), array_merge($this->getFilesOrURLEntry(), ['accept' => ['.html']])); + } if ($this->_integration) { $this->addField('inline', MultimediaIntegration::class, __('Intégration'), ['default' => 'inline']); } @@ -182,6 +209,15 @@ class Base extends Form } } + /** + * @return array + */ + public function getFilesOrURLEntry() + { + $res = ['entry_class' => FluidbookPublication::class, 'entry_id' => $this->getFluidbookId()]; + return $res; + } + public function addMultimediaFields() { $this->addField('header_video', FormSection::class, __('Paramètres multimedia')); @@ -216,7 +252,7 @@ class Base extends Form public function addExtraFields() { $this->addField('header_extra', FormSection::class, __('Autres paramètres')); - $this->addField('extra', Code::class, '', ['language' => 'properties']); + $this->addField('extra', Textarea::class, ''); } public function getType() diff --git a/app/SubForms/Link/Web.php b/app/SubForms/Link/Web.php index 034f40661..a98904383 100644 --- a/app/SubForms/Link/Web.php +++ b/app/SubForms/Link/Web.php @@ -2,6 +2,8 @@ namespace App\SubForms\Link; +use App\Fields\FluidbookLinkEditor\Target; +use Cubist\Backpack\Magic\Fields\SelectFromArray; use Cubist\Backpack\Magic\Fields\URL; class Web extends Base @@ -11,5 +13,6 @@ class Web extends Base public function addDestinationField() { $this->addField('to', URL::class, __('Adresse')); + $this->addField('target', Target::class, __('Ouvrir le lien dans')); } } diff --git a/package-lock.json b/package-lock.json index 299d80d38..07b2bb013 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "packages": { "": { "dependencies": { + "ace-builds": "^1.12.5", "codemirror": "^5", "command-line-args": "^5.2.1", "jquery-contextmenu": "^2.9.2", @@ -2138,6 +2139,11 @@ "node": ">= 0.6" } }, + "node_modules/ace-builds": { + "version": "1.12.5", + "resolved": "https://registry.npmjs.org/ace-builds/-/ace-builds-1.12.5.tgz", + "integrity": "sha512-2OTOZZdXVqWHfsV63n/bWLJ4uGnGNm9uwEQSECbEzMpKF2RKxD04lWu7s+eRBTZoEbqPXziyI1qamJH2OAwdwA==" + }, "node_modules/acorn": { "version": "6.4.2", "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.4.2.tgz", @@ -16966,6 +16972,11 @@ "negotiator": "0.6.3" } }, + "ace-builds": { + "version": "1.12.5", + "resolved": "https://registry.npmjs.org/ace-builds/-/ace-builds-1.12.5.tgz", + "integrity": "sha512-2OTOZZdXVqWHfsV63n/bWLJ4uGnGNm9uwEQSECbEzMpKF2RKxD04lWu7s+eRBTZoEbqPXziyI1qamJH2OAwdwA==" + }, "acorn": { "version": "6.4.2", "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.4.2.tgz", diff --git a/package.json b/package.json index 893565966..37fb2e692 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "webfont": "^11.2.26" }, "dependencies": { + "ace-builds": "^1.12.5", "codemirror": "^5", "command-line-args": "^5.2.1", "jquery-contextmenu": "^2.9.2", diff --git a/resources/linkeditor/js/linkeditor.js b/resources/linkeditor/js/linkeditor.js index 60930ba22..5256dcd83 100644 --- a/resources/linkeditor/js/linkeditor.js +++ b/resources/linkeditor/js/linkeditor.js @@ -1,10 +1,6 @@ import tippy from 'tippy.js'; import 'tippy.js/dist/tippy.css'; -import CodeMirror from "codemirror"; -window.CodeMirror=CodeMirror; -import 'codemirror/lib/codemirror.css'; - import Noty from "noty"; import 'noty/lib/noty.css'; import 'noty/lib/themes/mint.css'; diff --git a/resources/views/fluidbook_publication/link_editor.blade.php b/resources/views/fluidbook_publication/link_editor.blade.php index 774b76a8f..579a9b34c 100644 --- a/resources/views/fluidbook_publication/link_editor.blade.php +++ b/resources/views/fluidbook_publication/link_editor.blade.php @@ -123,7 +123,10 @@ @continue; @endif @php + /** @var \App\SubForms\Link\Base $instance */ $instance=new $f['class'](); + $instance->setFluidbookId($id); + $instance->initForm(); $instance->setValue('type',$f['type']); echo $instance->render(); @endphp @@ -148,14 +151,14 @@ @foreach(\App\SubForms\Link\Base::types() as $type) @if(isset($type['color'])) .link[fb-type="{{$type['type']}}"] { - color: {{$type['color']}}; - background-color: {{\Cubist\Util\Graphics\Color::colorToCSS($type['color'],0.25)}}; - } + color: {{$type['color']}}; + background-color: {{\Cubist\Util\Graphics\Color::colorToCSS($type['color'],0.25)}}; + } - .linkeditor-linktype[data-type="{{$type['type']}}"]::before { - background-color: {{$type['color']}}; - } - @endif + .linkeditor-linktype[data-type="{{$type['type']}}"]::before { + background-color: {{$type['color']}}; + } + @endif @endforeach