Skip to content

Commit

Permalink
API CHANGE Removed SideReport javascript class, replaced with concret…
Browse files Browse the repository at this point in the history
…e implementation in CMSMain.js

ENHANCEMENT Using full form for 'site reports' panel in CMSMain->ReportForm(). Removed CMSMain->ReportSelector()

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92727 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information
chillu committed Nov 21, 2009
1 parent 1760759 commit 2796a37
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 131 deletions.
59 changes: 40 additions & 19 deletions code/CMSMain.php
Expand Up @@ -56,7 +56,8 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
'getshowdeletedsubtree',
'getfilteredsubtree',
'batchactions',
'SearchTreeForm'
'SearchTreeForm',
'ReportForm'
);

public function init() {
Expand Down Expand Up @@ -605,28 +606,46 @@ public function delete($data, $form) {

/*
* Return a dropdown for selecting reports
*
* @return Form
*/
function ReportSelector() {
function ReportForm() {
$reports = ClassInfo::subclassesFor("SideReport");

// $options[""] = _t('CMSMain.CHOOSEREPORT',"(Choose a report)");
foreach($reports as $report) {
if($report != 'SideReport' && singleton($report)->canView()) {
$options[singleton($report)->group()][singleton($report)->sort()][$report] = singleton($report)->title();
}
}

$finalOptions = array();
foreach($options as $group => $weights) {
ksort($weights);
foreach($weights as $weight => $reports) {
foreach($reports as $class => $report) {
$finalOptions[$group][$class] = $report;
}
}
}
$id = $this->request->requestVar('ID');
$reportClass = $this->request->requestVar('ReportClass');
$report = ClassInfo::exists($reportClass) ? new $reportClass() : false;
$reportHtml = ($report) ? $report->getHTML() : false;

$form = new Form(
$this,
'ReportForm',
new FieldSet(
new DropdownField(
"ReportClass",
_t('CMSMain.REPORT', 'Report'),
$options,
$reportClass,
null,
_t('CMSMain.CHOOSEREPORT',"(Choose a report)")
),
new LiteralField('ReportHtml', $reportHtml),
new HiddenField('ID', false, $id),
new HiddenField('Locale', false, $this->Locale)
),
new FieldSet(
new FormAction('sidereport', _t('CMSMain_left.ss.GO','Go'))
)
);
$form->unsetValidator();

return new GroupedDropdownField("ReportSelector", _t('CMSMain.REPORT', 'Report'),$finalOptions);
return $form;
}
function ReportFormParameters() {
$reports = ClassInfo::subclassesFor("SideReport");
Expand All @@ -651,13 +670,15 @@ function ReportFormParameters() {
}

/**
* Get the content for a side report
* Get the content for a side report.
*
* @param Array $data
* @param Form $form
* @return String
*/
function sidereport() {
$reportClass = $this->urlParams['ID'];
$report = ClassInfo::exists($reportClass) ? new $reportClass() : false;
$report->setParams($this->request->requestVars());
return $report ? $report->getHTML() : false;
function sidereport($data, $form) {
$form = $this->ReportForm();
return (Director::is_ajax()) ? $form->forTemplate() : $form;
}
/**
* Get the versions of the current page
Expand Down
1 change: 0 additions & 1 deletion code/LeftAndMain.php
Expand Up @@ -232,7 +232,6 @@ function init() {
Requirements::javascript(CMS_DIR . '/javascript/LeftAndMain.EditForm.js');

Requirements::javascript(CMS_DIR . '/javascript/SideTabs.js');
Requirements::javascript(CMS_DIR . '/javascript/SideReports.js');

Requirements::themedCSS('typography');

Expand Down
16 changes: 16 additions & 0 deletions javascript/CMSMain.Tree.js
@@ -1,3 +1,19 @@
(function($) {
/**
* @class Tree panel.
* @name ss.sitetree
*/
$('#sitetree').concrete('ss', function($){
return/** @lends ss.sitetree */{
onmatch: function() {
// make sure current ID of loaded form is actually selected in tree
var id = $('#Form_EditForm :input[name=ID]').val();
if(id) this[0].setCurrentByIdx(id);
}
};
});
}(jQuery));

if(typeof SiteTreeHandlers == 'undefined') SiteTreeHandlers = {};
SiteTreeHandlers.parentChanged_url = 'admin/ajaxupdateparent';
SiteTreeHandlers.orderChanged_url = 'admin/ajaxupdatesort';
Expand Down
66 changes: 66 additions & 0 deletions javascript/CMSMain.js
Expand Up @@ -475,4 +475,70 @@ var ss_MainLayout;
};
});

/**
* @class Simple form with a page type dropdown
* which creates a new page through #Form_EditForm and adds a new tree node.
* @name ss.Form_AddPageOptionsForm
* @requires ss.i18n
* @requires ss.reports_holder
*/
$('#Form_ReportForm').concrete(function($) {
return/** @lends ss.reports_holder */{
onmatch: function() {
var self = this;

this.bind('submit', function(e) {
return self._submit(e);
});

// integrate with sitetree selection changes
jQuery('#sitetree').bind('selectionchanged', function(e, data) {
self.find(':input[name=ID]').val(data.node.getIdx());
self.trigger('submit');
});

// move submit button to the top
this.find('#ReportClass').after(this.find('.Actions'));

// links in results
this.find('ul a').bind('click', function(e) {
var $link = $(this);
$link.addClass('loading');
jQuery('#Form_EditForm').concrete('ss').loadForm(
$(this).attr('href'),
function(e) {
$link.removeClass('loading');
}
);
return false;
});
},

_submit: function(e) {
var self = this;

// dont process if no report is selected
var reportClass = this.find(':input[name=ReportClass]').val();
if(!reportClass) return false;

var button = this.find(':submit:first');
button.addClass('loading');

jQuery.ajax({
url: this.attr('action'),
data: this.serializeArray(),
dataType: 'html',
success: function(data, status) {
// replace current form
self.replaceWith(data);
},
complete: function(xmlhttp, status) {
button.removeClass('loading');
}
});

return false;
}
};
});
})(jQuery);
108 changes: 0 additions & 108 deletions javascript/SideReports.js

This file was deleted.

4 changes: 1 addition & 3 deletions templates/Includes/CMSMain_left.ss
Expand Up @@ -44,8 +44,6 @@
<a href="#"><% _t('SITEREPORTS','Site Reports') %></a>
</h3>
<div class="listpane" id="reports_holder">
<p id="ReportSelector_holder">$ReportSelector <input class="action" type="submit" id="report_select_go" value="<% _t('GO','Go') %>" /></p>
<div class="unitBody">
</div>
$ReportForm
</div>
</div>

0 comments on commit 2796a37

Please sign in to comment.