SilverStripe 3.4 Custom Reports - Set filenames as links in custom report to allow for easy editing - reporting

I'm new to SilverStripe reports but I haven't been able to find anything related to this particular issue so far.
I have a custom report that lists all images and files on the site in a gridview, however, I would like to make it so that people can either click on the filename and go to the image or file to edit it, or have an edit button for each image and file. Right now, if anyone wants to edit a file or image, they have to leave the report, go the Files tab, search for said file/image, and click to edit. That's rather tedious.
I know there is a way to make page titles clickable in reports based on the existing report examples in cms/code/reports. But I don't see anything that relates to linking to uploaded images and files.
Is there is a way to do this?
Here is the code for my custom report:
<?php
class CustomSideReport_ListofImagesAndFiles extends SS_Report {
// the name of the report
public function title() {
return 'All Images and Files';
}
// what we want the report to return
public function sourceRecords($params = null)
{
return File::get()
->sort('Title');
}
// which fields on that object we want to show
public function columns() {
return array(
"Title" => 'Image Title',
'Filename' => array(
"Filename" => "Filename",
"link" => true,
),
);
}
}
using "link" => true doesn't work -- it tries to create a page link, which isn't right. I've tried "edit" and "CanEdit."

Ok, I came up with this from referencing the setup for the Broken Links report:
// which fields on that object we want to show
public function columns()
{
$linkBase = singleton('CMSFileAddController')->Link('EditForm/field/File/item');
$linkBaseEditLink = str_replace("/add","",$linkBase);
$fields = array(
'Title' => 'Title',
'AbsoluteLink' => array(
'title' => _t('CustomSideReport_ListofImagesAndFiles.ColumnFilename', 'Filename'),
'formatting' => function($value, $item) use ($linkBaseEditLink) {
return sprintf('%s',
Controller::join_links($linkBaseEditLink, $item->ID."/edit"),
strstr($value, '/assets/', false)
);
}
)
);
return $fields;
}
I don't know if this is the best solution ever--it works, and I can't find anything else that relates to this kind of report creation for SilverStripe (everything I've found deals with getting Pages for reports, not images or files.
I had to make some tweaks because there is no CMSFileEditController like there is a CMSPageEditController, but I made due with what I had.
If anyone has a better solution then by all means, please share!

Related

How can I change the background color of columns in Laravel-admin?

I'm currently working on Laravel-admin project with laravel9.
For instance, If the value = 'error', I want to change the background color of the column.
Something like this pic:
My code is this:
$grid->column('title')->display(function ($title, $column) {
if ($title !== 'error') {
return $title;
}
return $column->setAttributes(['style' => 'background-color:red;']);
});
But seems like I can't use setAttributes() method on $column.
Also If I use setAttributes(['style' => 'background-color:red;']) the column name(In this case title) become red as well.
Any advice would be appreciated.
I read the Laravel-admin document and searched for a solution for hours but I couldn't find any good info.

How put kendo template to js file and use in html

I want to dynamically change and load templates.How put kendo template to js file and use in html.
#(Html.Kendo().TileLayout()
.Name("tilelayout")
.Columns(100)
.RowsHeight("100%")
.Height("100%")
.ColumnsWidth("100%")
.Containers(c => {
if(#Model==1)
{
c.Add().Header(h => h.Text("Входящие документы")).BodyTemplateId("inboxdocuments1").ColSpan(75).RowSpan(2);
}
else
{
c.Add().Header(h => h.Text("Входящие документы")).BodyTemplateId("inboxdocuments2").ColSpan(75).RowSpan(2);
}
c.Add().Header(h => h.Text("Прикрепленные документы")).BodyTemplateId("attachments").ColSpan(25).RowSpan(1);
c.Add().Header(h => h.Text("Рассылка")).BodyTemplateId("distributions").ColSpan(25).RowSpan(1);
})
.Reorderable()
.Resizable()
.Events(e=>e.Resize("onTileResize"))
)
The following article is a detailed explanation of what you can do. Basically, put the templates in external files and load them as needed (say, with Ajax), and put them in the DOM. Make sure they are loaded before using them in a widget initialization though.
https://docs.telerik.com/kendo-ui/framework/templates/load-remote

Laravel Nova. Using Image field, is it possible to make "Download" link appear on "update/edit" views?

"Download" link like that appears only on images on view page. Is it possible to also get it on "update/edit" page?
It seems to be impossible using out of the box Nova field methods.
Is making a custom tool the proper way to achieve this?
You can do it.
public function fields(Request $request)
{
$href = $this->modelsHref; // Or however you want to build the link
return [
Text::make('Download Link')->asHtml(function () use ($href) {
return '<i class="icon"></i> Download';
})->onlyOnForms(),
];
}

Magento select field disables row in related products

I have added a tab with functionality similar to related products, I have added a column with a dropdown like this:
$this->addColumn('mycolumn', array(
'name' => 'mycolumn',
'header' => Mage::helper('catalog')->__('Display on current child page'),
'index' => 'mycolumn',
'type' => 'select',
'width' => '1',
'align' => 'center',
'options' => array(
1 => Mage::helper('catalog')->__('Yes'),
0 => Mage::helper('catalog')->__('No'),
),
'editable' => true
));
Everytime i change the selection my product gets unchecked and the row is disabled.
I found that this line was commented in magento:
bindFieldsChange : function(){
if (!$(this.containerId)) {
return;
}
---> // var dataElements = $(this.containerId+this.tableSufix).down('.data tbody').select('input', 'select');
var dataElements = $(this.containerId+this.tableSufix).down('tbody').select('input', 'select');
for(var i=0; i<dataElements.length;i++){
Event.observe(dataElements[i], 'change', dataElements[i].setHasChanges.bind(dataElements[i]));
}
}
I found this code in js/mage/adminhtml/grid.js.
When I uncommented this line my dropdown worked like a charm...
I have 2 questions regarding this matter, the first one would be if it's safe to uncomment this (Magento must've had a reason to change this).
My second question is how I could avoid this behaviour without adjusting the grid.js file. I dislike editing corefiles in any way but am unable to figure out how to rewrite this functionality or how to add my column in a manner that the behaviour does not apply itself.
The row click event uses a function called 'openGridRow'
Include some javascript with your grid, and add this function with some custom code to cancel the event if certain conditions are met.
Also then set the checkbox back to checked.
Example will be
function openGridRow(grid, event){
var element = Event.findElement(event, 'tr');
//alert(Event.element(event).tagName.toLowerCase());
if(Event.element(event).type != 'checkbox'){
if(['img', 'a', 'input', 'select', 'option', 'img'].indexOf(Event.element(event).tagName.toLowerCase())!=-1) {
// re-enable the checkbox
var checkbox = Element.select(element, 'input');
if(checkbox[0] && !checkbox[0].disabled){
grid.setCheckboxChecked(checkbox[0], true);
}
return;
}
}
if(element.title){
setLocation(element.title);
}
}
The above example will do nothing, if the element type clicked is a, input, select or option
Anything else will continue as per normal.

Setting custom toolbarset of FCKeditor in CodeIgniter

I really need Ur help here
I’m using fckEditor 2.6.5 with CI 1.7.2
I used this steps to pluged it into my project : http://codeigniter.com/forums/viewthread/107642/
I want to ask, how to set custom toolbarset in fckeditor???
some of articles said to doing that is by editing fckconfig.js with adding new custom toolbarset over there, than we can call it when we need. it’s about like this :
//fckconfig.js.
//add this sample codes..
FCKConfig.ToolbarSets["Custom"] = [
['Bold','Italic','-','OrderedList','UnorderedList','-','Link','Unlink','-']
],['JustifyLeft','JustifyCenter','JustifyRight','JustifyFull'] ;
then we call in controller
$fckeditorConfig = array(
'instanceName' => 'message',
'BasePath' => base_url().'system/plugins/fckeditor/',
'ToolbarSet' => 'Custom', //here we go
'Width' => '100%',
'Height' => '400',
'Value' => ''
);
$this->load->library('fckeditor', $fckeditorConfig);
but when I load the page, its warned there, that no Custom toolbarset exists.
how to make it???
even, when I tried to only change the option of Default Toolbarset (by removing some options toolbar), not adding custom toolbarset in fckeditor, there is no effect on my page. it still completely show the default toolbar (full toolbar)
It's probably just cache. FCKEditor is heavy with cache and I've seen the same thing first-hand.
Your code looks correct.

Resources