]> _ Git - fluidbook-v3.git/commitdiff
WIP #3641 @3.75
authorstephen@cubedesigners.com <stephen@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Thu, 14 May 2020 11:17:04 +0000 (11:17 +0000)
committerstephen@cubedesigners.com <stephen@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Thu, 14 May 2020 11:17:04 +0000 (11:17 +0000)
framework/application/Bootstrap.php
framework/application/controllers/BlogpostController.php
framework/application/forms/CMS/Sub/Blog/ContentBlock.php [new file with mode: 0644]
framework/application/forms/CMS/Sub/Blog/ContentBlocks.php [new file with mode: 0644]
framework/application/forms/CMS/Sub/Blog/Post.php
framework/application/views/helpers/BlogIndex.php
js/010-admin.js

index ebb08cdee98c03a6f197b3e85b59c616dd5f9b91..d826599709d4a29c5d504ae53b1162f88a05eb8e 100644 (file)
@@ -57,8 +57,13 @@ class Bootstrap extends CubeIT_Bootstrap {
 
         while ($r = $q->fetch()) {
 
-            $online = true;
+            $r = CubeIT_Util_Cms::unserialize($r, $locale);
+
             $pageTitle = $r->title;
+            if (empty($pageTitle)) continue;
+
+            $online = boolval($r->online);
+            if (!$online && !$isAdmin) continue;
 
             $p = new CubeIT_Navigation_Page_Locale();
             $p->setController('Blogpost');
index dcb2f7931c3d1d27c69211e5f64dc2cb54b274cd..cd32ce2dc06382c685b115de8bc8e13748c352b9 100644 (file)
@@ -25,7 +25,7 @@ class BlogpostController extends CubeIT_Controller_PageController {
         // Get the first and only array item
         $post = reset($post);
 
-        $this->view->post = $post;
+        $this->view->post = $post->unserialize();
         $this->view->headTitle($post->getTitle(), 'SET');
     }
 
diff --git a/framework/application/forms/CMS/Sub/Blog/ContentBlock.php b/framework/application/forms/CMS/Sub/Blog/ContentBlock.php
new file mode 100644 (file)
index 0000000..50d5a53
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+
+class Fluidbook_Form_CMS_Sub_Blog_ContentBlock extends CubeIT_Form_SubForm {
+
+    public function init() {
+        parent::init();
+
+        $compact_translations = false;
+
+        $select = new Zend_Form_Element_Select('content_type');
+        $select->setAttrib('data-name', 'content-type')
+               ->setMultiOptions([
+                   'text' => 'Text Block',
+                   'image' => 'Image',
+               ]);
+        $this->addElement($select);
+
+        $text = new CubeIT_Form_Element_Markitup_Basic('text');
+        $text->setLabel('Text Block')
+             ->setAttrib('data-type', 'text'); // Shown when "text" content type is selected
+        $this->addElementLocalized($text, $compact_translations);
+
+        $image = new CubeIT_Form_Element_File_Image('image');
+        $image->setLabel('Image')
+              ->setMaxItems(1)
+              ->setAttrib('data-type', 'image'); // Shown when "image" content type is selected
+        $this->addElementLocalized($image, $compact_translations);
+
+        $image_style = new Zend_Form_Element_Select('image_style');
+        $image_style->setLabel('Image Style')
+                    ->setAttrib('data-type', 'image')
+                    ->setMultiOptions([
+                        '' => 'Normal',
+                        'xl' => 'Extra Large',
+                    ]);
+        $this->addElementLocalized($image_style, $compact_translations);
+
+    }
+}
diff --git a/framework/application/forms/CMS/Sub/Blog/ContentBlocks.php b/framework/application/forms/CMS/Sub/Blog/ContentBlocks.php
new file mode 100644 (file)
index 0000000..29460f1
--- /dev/null
@@ -0,0 +1,14 @@
+<?php
+
+class Fluidbook_Form_CMS_Sub_Blog_ContentBlocks extends CubeIT_Form_Multi_SubForm {
+
+    public function init() {
+        parent::init();
+
+        $block = new Fluidbook_Form_CMS_Sub_Blog_ContentBlock();
+        $this->setBaseSubForm($block);
+        $this->setBaseLegend('Content block');
+        $this->setNewLegend('New content block');
+    }
+
+}
index 0fa5f96f0a4bb523b94245493f0194908aa1f4fe..34ccdc5305dadee2bf29749a252b4d83e296d1de 100644 (file)
@@ -6,6 +6,8 @@ class Fluidbook_Form_CMS_Sub_Blog_Post extends CubeIT_Form_List_Model
     public function init() {
         parent::init();
 
+        $compact_translations = false;
+
         $id = new CubeIT_Form_Element_Id();
         $this->addElement($id);
 
@@ -22,17 +24,20 @@ class Fluidbook_Form_CMS_Sub_Blog_Post extends CubeIT_Form_List_Model
 
         $title = new CubeIT_Form_Element_Text('title');
         $title->setLabel(__('Post Title'));
-        $this->addElement($title);
+        $this->addElementLocalized($title, $compact_translations);
 
         $excerpt = new CubeIT_Form_Element_Markitup('excerpt');
         $excerpt->setLabel(__('Excerpt'));
-        $this->addElement($excerpt);
+        $this->addElementLocalized($excerpt, $compact_translations);
 
         $thumbnail = new CubeIT_Form_Element_File_Image('thumbnail');
         $thumbnail->setLabel(__('Post Thumbnail'));
+        $thumbnail->setMaxItems(1);
         $this->addElement($thumbnail);
 
-        // TODO add content blocks (text + images) based on Cubedesigners case studies content. Also add author reference.
+        $content = new Fluidbook_Form_CMS_Sub_Blog_ContentBlocks();
+        $content->setLegend('Content Blocks');
+        $this->addSubForm($content, 'content');
 
         $this->setListTitle(__('Blog Posts'));
         $this->setNewTitle(__('New Post'));
index 383d64c30a8828d7ca6b560464b8e0ef9591266d..203100e9cbeacc65b54a239dc9037052f85c4768 100644 (file)
@@ -11,7 +11,8 @@ class Fluidbook_View_Helper_BlogIndex extends CubeIT_View_Helper_Abstract {
         $res = '';\r
 \r
         foreach ($posts as $post) {\r
-            $res .= $this->post($post);\r
+            /* @var $post Fluidbook_Model_Blog */\r
+            $res .= $this->post($post->unserialize());\r
         }\r
 \r
         return $this->htmlElement($res, 'div', ['class' => 'blog-index']);\r
index c898d2938b0d4710790654c910f4744995535e3c..2dee9c446cbb43979d04b2fbd499a056348f453b 100644 (file)
@@ -1 +1,44 @@
-// Todo: adapt code from cubedesigners-v6/js/admin.js to have the custom multi-subform with different fields shown / hidden depending on the option selected
+TO_LOAD[TO_LOAD.length] = 'load_admin();';
+
+function load_admin() {
+  initContentBlocks();
+}
+
+// Toggle visibility of fields depending on the content type in the repeater
+function initContentBlocks() {
+  $('select[data-name="content-type"]').each(function() {
+    var target = $(this).closest('fieldset');
+    displayFormTypeElements(target, this.value);
+  });
+
+  $(document).on('change', 'select[data-name="content-type"]', function() {
+    var target = $(this).closest('fieldset');
+    displayFormTypeElements(target, this.value);
+  });
+}
+
+function displayFormTypeElements(target, type) {
+
+  target.find('.legend').text('Content Block (' + type + ')');
+
+  // First hide all fields
+  target.find('[data-type]').each(function() {
+    getFieldWrapper($(this)).hide();
+  });
+
+  // Now show just the relevant fields
+  target.find('[data-type="'+ type +'"]').each(function() {
+    getFieldWrapper($(this)).show();
+  });
+
+
+}
+
+function getFieldWrapper(field) {
+  // The structure of the fields is different depending on whether or not it is localised
+  if (field.parents('.localized').length > 0) {
+    return field.parents('.localized').parent();
+  } else {
+    return field.parents('.elementwrap').parent();
+  }
+}