From 2d3365f7b27f6a3e4bd26353a35304f8d7342e9d Mon Sep 17 00:00:00 2001 From: Tom Rix Date: Mon, 14 Dec 2009 01:26:49 +0000 Subject: [PATCH] MINOR make widgetarea/editor more suitable for generic use git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.4@95086 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/WidgetAreaEditor.php | 27 ++++++++++++++++++++++----- javascript/lang/en_US.js | 3 ++- templates/WidgetAreaEditor.ss | 8 ++++---- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/code/WidgetAreaEditor.php b/code/WidgetAreaEditor.php index c862df48..035d6e07 100644 --- a/code/WidgetAreaEditor.php +++ b/code/WidgetAreaEditor.php @@ -5,7 +5,21 @@ * @subpackage content */ class WidgetAreaEditor extends FormField { - function __construct($name) { + /** + * 3 variables to hold titles for the template + */ + public $InUseTitle; + public $AvailableTitle; + public $ToAddTitle; + + function __construct($name, $widgetClasses = array('Widget'), $maxWidgets = 0) { + $this->InUseTitle = _t('WidgetAreaEditor.ss', 'INUSE'); + $this->AvailableTitle = _t('WidgetAreaEditor.ss', 'AVAILABLE'); + $this->ToAddTitle = _t('WidgetAreaEditor.ss', 'TOADD'); + $this->MaxWidgets = $maxWidgets; + + $this->widgetClasses = $widgetClasses; + parent::__construct($name); } @@ -17,12 +31,15 @@ class WidgetAreaEditor extends FormField { } function AvailableWidgets() { - $classes = ClassInfo::subclassesFor('Widget'); - array_shift($classes); + $widgets= new DataObjectSet(); - foreach($classes as $class) { - $widgets->push(singleton($class)); + foreach($this->widgetClasses as $widgetClass) { + $classes = ClassInfo::subclassesFor($widgetClass); + array_shift($classes); + foreach($classes as $class) { + $widgets->push(singleton($class)); + } } return $widgets; diff --git a/javascript/lang/en_US.js b/javascript/lang/en_US.js index 8464316e..9b0e6118 100644 --- a/javascript/lang/en_US.js +++ b/javascript/lang/en_US.js @@ -24,6 +24,7 @@ if(typeof(ss) == 'undefined' || typeof(ss.i18n) == 'undefined') { 'ModelAdmin.DELETED': "Deleted", 'ModelAdmin.VALIDATIONERROR': "Validation Error", 'LeftAndMain.PAGEWASDELETED': "This page was deleted. To edit a page, select it from the left.", - 'LeftAndMain.CONFIRMUNSAVED': "Are you sure you want to navigate away from this page?\n\nWARNING: Your changes have not been saved.\n\nPress OK to continue, or Cancel to stay on the current page." + 'LeftAndMain.CONFIRMUNSAVED': "Are you sure you want to navigate away from this page?\n\nWARNING: Your changes have not been saved.\n\nPress OK to continue, or Cancel to stay on the current page.", + 'WidgetAreaEditor.TOOMANY': 'Sorry, you have reached the maximum number of widgets in this area' }); } \ No newline at end of file diff --git a/templates/WidgetAreaEditor.ss b/templates/WidgetAreaEditor.ss index 6b1989f6..450386d3 100644 --- a/templates/WidgetAreaEditor.ss +++ b/templates/WidgetAreaEditor.ss @@ -1,7 +1,7 @@ -
+
maxwidgets="$MaxWidgets"<% end_if %>>
-

<% _t('AVAILABLE', 'Available Widgets') %>

+

$AvailableTitle

 

<% if AvailableWidgets %> @@ -16,8 +16,8 @@
-

<% _t('INUSE', 'Widgets currently used') %>

-

<% _t('TOADD', 'To add widgets, click on the purple header on the left') %>

+

$InUseTitle

+

$ToAddTitle

<% if UsedWidgets %>