Jump to:

5519 Posts in 1734 Topics by 1223 members

Customising the CMS

SilverStripe Forums » Customising the CMS » New Component on CMS

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 3473 Views
  • gilgamesh
    Avatar
    Community Member
    2 Posts

    Re: New Component on CMS Link to this post

    The problem not remedied above is the adding of new links, the passing of 'new' as an ID doesn't work as it gets caught by line 920 -> -921 on LeftAndMain.php as not record gets returned by $this->currentPage();

    I've worked around this by adding to addlink() :

    if($id == 'new')
    {
    $newlink= singleton('RandomLink');
    $newlink->LinkTitle = 'new';
    $id = $newlink->write();
    }

  • snapper
    Avatar
    Community Member
    2 Posts

    Re: New Component on CMS Link to this post

    Hi all,

    I have had similar issues with the add/edit features of the random link tutorial. I have managed to somehow store two results in the db, but now i can't edit or add a new link. stepping through the javascript using firebug i am having issues with
    $("SwitchView") is null
    on line 437 of leftandmain.js

    Anyone got any ideas how i can fix this issue?

    Thanks in advance!

  • Jarek
    Avatar
    Community Member
    30 Posts

    Re: New Component on CMS Link to this post

    Trying to show new record form in the right panel is wrong. In other existing modules (for example Security), create button doesn't open new form but creates new record (with default values) and adds new node to tree list.

    This is addlink function which creates new record in tree:

    public function addlink() {
    $newlink= singleton('RandomLinks');
    $newlink->LinkTitle = 'new link';
    $id = $newlink->write();

    $response = <<<JS
    var tree = $('sitetree');
    var newNode = tree.createTreeNode("$id", "$newlink->LinkTitle", "{$newlink->class}");
    node = tree.getTreeNodeByIdx(0);
    node.open();
    node.appendTreeNode(newNode);
    newNode.selectTreeNode();
    JS;
    FormResponse::add($response);

    return FormResponse::respond();

    }

  • Jarek
    Avatar
    Community Member
    30 Posts

    Re: New Component on CMS Link to this post

    Example of sitetree randomlinks filter - button with filter text field (can be usefull for huge number of items in tree).

    RandomLinksAdmin_left.ss:

    <div id="treepanes" style="overflow-y: auto;">
    <ul id="TreeActions">
    <li class="action" ><button id="filterlink">Filtruj</button>
           <form class="actionparams" id="filterlink_options" style="display: block" action="admin/randomlinks/filterlink">
           <input type="text" name="filter"/>
           </form>
    </li>
    <li class="action" id="addlink"><button><% _t('CREATENL','Create New Link xXx') %></button></li>
    <li class="action" id="deletelink"><button><% _t('DEL','Delete Link xXx') %></button></li>
    </ul>
    ...

    RandomLinksAdmin_left.js:

    _HANDLER_FORMS['filterlink'] = 'filterlink_options';

    filterlink = {
    button_onclick : function() {
    filterlink.form_submit();
    return false;
    },

    form_submit : function() {
    Ajax.SubmitForm('filterlink_options', null, {
    onSuccess : function(response) {
    $('sitetree').innerHTML = response.responseText;

    $$('#sitetree li').each(function(n) {
    $('sitetree').SiteSubTree.castAsTreeNode(n);
    });

    },
    onFailure : function(response) {
    errorMessage('Error filtering', response);
    }
    });

    return false;
    }
    };

    Behaviour.addLoader(function () {
    Observable.applyTo($('filterlink_options'));
    $('filterlink').onclick = filterlink.button_onclick;
    $('filterlink').getElementsByTagName('button')[0].onclick = function() {return false;};
    ...

    RandomLinksAdmin.php

    public function filterlink() {

    $filter = 'ALL';
    if (isset($_POST['filter']) && $_POST['filter'] != '')
    $filter = $_POST['filter'];

    $siteTree = $this->SiteTreeAsUL($filter);

    return $siteTree;

    }

    public function SiteTreeAsUL($filter = null) {
    $siteTree = "";

    if ($filter && $filter != 'ALL')
    $randomlinks = DataObject::get("RandomLinks", "LinkTitle LIKE '%".$filter."%'");
    else
    $randomlinks = DataObject::get("RandomLinks");

    if ($randomlinks) {
    foreach($randomlinks as $ID => $data) {
    $siteTree .= "<li id=\"record-" . $data->ID . "\" class=\"" . $data->class . " " .
    ($data->Locked ? " nodelete" : "") . "\" >" .
    "<a href=\"" . Director::link("randomlinks", "show", $data->ID) . "\" >" . $data->LinkTitle . "</a>";
    }
    }

    if ($filter)
    $siteTree =
    "<li id=\"record-0\" class=\"Root nodelete\">" .
    "<a href=\"admin/randomlinks/show/0\" ><strong>"._t('RandomLinksAdmin.CURLINKS',"Current Links xXx")."</strong></a>"
    . $siteTree .
    "</li>";
    else
    $siteTree = "<ul id=\"sitetree\" class=\"tree unformatted\">" .
    "<li id=\"record-0\" class=\"Root nodelete\">" .
    "<a href=\"admin/randomlinks/show/0\" ><strong>"._t('RandomLinksAdmin.CURLINKS',"Current Links xXx")."</strong></a>"
    . $siteTree .
    "</li>" .
    "</ul>";
    return $siteTree;
    }

    3473 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.