Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Customising the CMS /

New Component on CMS


Go to End
Reply


12 Posts   3760 Views

Avatar
gilgamesh

Community Member, 2 Posts

9 February 2010 at 2:22pm

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();
}

Avatar
snapper

Community Member, 2 Posts

9 June 2010 at 2:25am

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!

Avatar
Jarek

Community Member, 30 Posts

19 August 2010 at 7:18pm

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();

}

Avatar
Jarek

Community Member, 30 Posts

19 August 2010 at 9:10pm

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;
}

Go to Top