Hi,
I am trying to get a simple new Module into the CMS (to edit several tables of data, maybe more in the future). I have been reading the example in the silverstripe book and I would like to create something very similar (with as little code as possible) to maintain the data in several reference tables. I'd like to be using ModelAdmin, but due to 2.2.2 I think using GenericDataAdmin is the best option.
At the moment I have a new DataObject called PromoCodes and a module called myadmin. The CMS display the new module in the top menu bar... but the left and right main sections are not close to my desire yet. Currently the left area shows a search form that when submitted shows the results, but not into the right area. And the right area shows the contents of the table (SELECT * FROM) but when a record is clicked it just refresehs the screen.
The left area I would like (if you have the book I am looking at 6.3 Using ModelAdmin for Data Management) to show this table/dataobject as part of a list or one of a set of tabs. Then selecting that table updates the right side with the 'search results' (select from table), then from this view a row could be viewed, editted or deleted. In the case of a view/edit I would like to have the right area become a single generic record editor. This is a wish, but anything that would accomplish maintaining this required data in the simplist code possible would be greatly appreciated.
I have included my current code and ask very politely if someone could please help me with this :-)
mysite/code/PromoCodes.php
class PromoCodes extends DataObject
{
static $db = array(
'ID' => 'Int',
'PromoCode' => 'Text',
'ExipryDate' => 'Date',
'IsLimted' => 'Boolean',
'Limit' => 'Int',
'Type' => "Enum(array('Percent', 'Fixed Value'))",
'DiscountAmount' => 'Int'
);
}
myadmin/_config.php
Object::addStaticVars('LeftAndMain', array('extra_menu_items' => array('Admin' => 'admin/myadmin/')));
Director::addRules(100, array('admin/myadmin/$Action/$ID' => 'MyAdmin'));
myadmin/code/MyAdmin.php
class MyAdmin extends GenericDataAdmin
{
public static $data_type = 'PromoCodes';
public static $result_columns = array('Promotional Code' => 'PromoCode',
'Exipry Date' => 'ExipryDate',
'Is Limted?' => 'IsLimted',
'Limit' => 'Limit',
'Type' => 'Type',
'Discount Amount' => 'DiscountAmount');
function performSearch()
{
return DataObject::get('PromoCodes');
}
function getSearchFields()
{
return new FieldSet(
new TextField('PromoCode', "PromoCode", "test"),
new CurrencyField('ExipryDate', "ExipryDate", "test")
);
}
function getLink()
{
if (!isset($action))
$action="";
return "admin/myadmin/$action";
}
}
myadmin/templates/MyAdmin_right.ss
<% if EditForm %>
$EditForm
<% else %>
$Results
<% end_if %>
<p id="statusMessage" style="visibility:hidden"></p>
myadmin/templates/MyAdmin_left.ss
<h2>Admin</h2>
<div id="treepanes" style="overflow-y: auto;">
<div id="sitetree_holder">
<div id="sitetree_ul">
$SearchForm
</div>
</div>
</div>